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 | ||
5f700d83 KS |
111 | static void create_sals_from_location_default (char **, |
112 | struct linespec_result *, | |
113 | enum bptype, char *, | |
114 | char **); | |
983af33b SDJ |
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 | 123 | |
5f700d83 | 124 | static void decode_location_default (struct breakpoint *, char **, |
983af33b SDJ |
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 | { | |
372316f1 PA |
471 | struct thread_info *tp; |
472 | ||
a25a5a45 PA |
473 | if (always_inserted_mode) |
474 | { | |
475 | /* The user wants breakpoints inserted even if all threads | |
476 | are stopped. */ | |
477 | return 1; | |
478 | } | |
479 | ||
b57bacec PA |
480 | if (threads_are_executing ()) |
481 | return 1; | |
372316f1 PA |
482 | |
483 | /* Don't remove breakpoints yet if, even though all threads are | |
484 | stopped, we still have events to process. */ | |
485 | ALL_NON_EXITED_THREADS (tp) | |
486 | if (tp->resumed | |
487 | && tp->suspend.waitstatus_pending_p) | |
488 | return 1; | |
a25a5a45 PA |
489 | } |
490 | return 0; | |
33e5cbd6 | 491 | } |
765dc015 | 492 | |
b775012e LM |
493 | static const char condition_evaluation_both[] = "host or target"; |
494 | ||
495 | /* Modes for breakpoint condition evaluation. */ | |
496 | static const char condition_evaluation_auto[] = "auto"; | |
497 | static const char condition_evaluation_host[] = "host"; | |
498 | static const char condition_evaluation_target[] = "target"; | |
499 | static const char *const condition_evaluation_enums[] = { | |
500 | condition_evaluation_auto, | |
501 | condition_evaluation_host, | |
502 | condition_evaluation_target, | |
503 | NULL | |
504 | }; | |
505 | ||
506 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
507 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
508 | ||
509 | /* Global that we use to display information to the user (gets its value from | |
510 | condition_evaluation_mode_1. */ | |
511 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
512 | ||
513 | /* Translate a condition evaluation mode MODE into either "host" | |
514 | or "target". This is used mostly to translate from "auto" to the | |
515 | real setting that is being used. It returns the translated | |
516 | evaluation mode. */ | |
517 | ||
518 | static const char * | |
519 | translate_condition_evaluation_mode (const char *mode) | |
520 | { | |
521 | if (mode == condition_evaluation_auto) | |
522 | { | |
523 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
524 | return condition_evaluation_target; | |
525 | else | |
526 | return condition_evaluation_host; | |
527 | } | |
528 | else | |
529 | return mode; | |
530 | } | |
531 | ||
532 | /* Discovers what condition_evaluation_auto translates to. */ | |
533 | ||
534 | static const char * | |
535 | breakpoint_condition_evaluation_mode (void) | |
536 | { | |
537 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
538 | } | |
539 | ||
540 | /* Return true if GDB should evaluate breakpoint conditions or false | |
541 | otherwise. */ | |
542 | ||
543 | static int | |
544 | gdb_evaluates_breakpoint_condition_p (void) | |
545 | { | |
546 | const char *mode = breakpoint_condition_evaluation_mode (); | |
547 | ||
548 | return (mode == condition_evaluation_host); | |
549 | } | |
550 | ||
a14ed312 | 551 | void _initialize_breakpoint (void); |
c906108c | 552 | |
c906108c SS |
553 | /* Are we executing breakpoint commands? */ |
554 | static int executing_breakpoint_commands; | |
555 | ||
c02f5703 MS |
556 | /* Are overlay event breakpoints enabled? */ |
557 | static int overlay_events_enabled; | |
558 | ||
e09342b5 TJB |
559 | /* See description in breakpoint.h. */ |
560 | int target_exact_watchpoints = 0; | |
561 | ||
c906108c | 562 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 563 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 564 | current breakpoint. */ |
c906108c | 565 | |
5c44784c | 566 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 567 | |
5c44784c JM |
568 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
569 | for (B = breakpoint_chain; \ | |
570 | B ? (TMP=B->next, 1): 0; \ | |
571 | B = TMP) | |
c906108c | 572 | |
4a64f543 MS |
573 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
574 | not provided so update_global_location_list must not be called | |
575 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 576 | |
876fa593 JK |
577 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
578 | for (BP_TMP = bp_location; \ | |
579 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
580 | BP_TMP++) | |
7cc221ef | 581 | |
b775012e LM |
582 | /* Iterates through locations with address ADDRESS for the currently selected |
583 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
584 | to where the loop should start from. | |
585 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
586 | appropriate location to start with. */ | |
587 | ||
588 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
589 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
590 | BP_LOCP_TMP = BP_LOCP_START; \ | |
591 | BP_LOCP_START \ | |
592 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
593 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
594 | BP_LOCP_TMP++) | |
595 | ||
1042e4c0 SS |
596 | /* Iterator for tracepoints only. */ |
597 | ||
598 | #define ALL_TRACEPOINTS(B) \ | |
599 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 600 | if (is_tracepoint (B)) |
1042e4c0 | 601 | |
7cc221ef | 602 | /* Chains of all breakpoints defined. */ |
c906108c SS |
603 | |
604 | struct breakpoint *breakpoint_chain; | |
605 | ||
876fa593 JK |
606 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
607 | ||
608 | static struct bp_location **bp_location; | |
609 | ||
610 | /* Number of elements of BP_LOCATION. */ | |
611 | ||
612 | static unsigned bp_location_count; | |
613 | ||
4a64f543 MS |
614 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
615 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
616 | result from bp_location_has_shadow. You can use it for roughly | |
617 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
618 | an address you need to read. */ | |
876fa593 JK |
619 | |
620 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
621 | ||
4a64f543 MS |
622 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
623 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
624 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
625 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
626 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
627 | |
628 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 629 | |
4a64f543 MS |
630 | /* The locations that no longer correspond to any breakpoint, unlinked |
631 | from bp_location array, but for which a hit may still be reported | |
632 | by a target. */ | |
20874c92 VP |
633 | VEC(bp_location_p) *moribund_locations = NULL; |
634 | ||
c906108c SS |
635 | /* Number of last breakpoint made. */ |
636 | ||
95a42b64 TT |
637 | static int breakpoint_count; |
638 | ||
86b17b60 PA |
639 | /* The value of `breakpoint_count' before the last command that |
640 | created breakpoints. If the last (break-like) command created more | |
641 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
642 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
643 | static int prev_breakpoint_count; | |
c906108c | 644 | |
1042e4c0 SS |
645 | /* Number of last tracepoint made. */ |
646 | ||
95a42b64 | 647 | static int tracepoint_count; |
1042e4c0 | 648 | |
6149aea9 PA |
649 | static struct cmd_list_element *breakpoint_set_cmdlist; |
650 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 651 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 652 | |
badd37ce SDJ |
653 | /* See declaration at breakpoint.h. */ |
654 | ||
655 | struct breakpoint * | |
656 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
657 | void *user_data) | |
658 | { | |
659 | struct breakpoint *b = NULL; | |
660 | ||
661 | ALL_BREAKPOINTS (b) | |
662 | { | |
663 | if (func (b, user_data) != 0) | |
664 | break; | |
665 | } | |
666 | ||
667 | return b; | |
668 | } | |
669 | ||
468d015d JJ |
670 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
671 | static int | |
672 | breakpoint_enabled (struct breakpoint *b) | |
673 | { | |
0d381245 | 674 | return (b->enable_state == bp_enabled); |
468d015d JJ |
675 | } |
676 | ||
c906108c SS |
677 | /* Set breakpoint count to NUM. */ |
678 | ||
95a42b64 | 679 | static void |
fba45db2 | 680 | set_breakpoint_count (int num) |
c906108c | 681 | { |
86b17b60 | 682 | prev_breakpoint_count = breakpoint_count; |
c906108c | 683 | breakpoint_count = num; |
4fa62494 | 684 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
685 | } |
686 | ||
86b17b60 PA |
687 | /* Used by `start_rbreak_breakpoints' below, to record the current |
688 | breakpoint count before "rbreak" creates any breakpoint. */ | |
689 | static int rbreak_start_breakpoint_count; | |
690 | ||
95a42b64 TT |
691 | /* Called at the start an "rbreak" command to record the first |
692 | breakpoint made. */ | |
86b17b60 | 693 | |
95a42b64 TT |
694 | void |
695 | start_rbreak_breakpoints (void) | |
696 | { | |
86b17b60 | 697 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
698 | } |
699 | ||
700 | /* Called at the end of an "rbreak" command to record the last | |
701 | breakpoint made. */ | |
86b17b60 | 702 | |
95a42b64 TT |
703 | void |
704 | end_rbreak_breakpoints (void) | |
705 | { | |
86b17b60 | 706 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
707 | } |
708 | ||
4a64f543 | 709 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
710 | |
711 | void | |
fba45db2 | 712 | clear_breakpoint_hit_counts (void) |
c906108c SS |
713 | { |
714 | struct breakpoint *b; | |
715 | ||
716 | ALL_BREAKPOINTS (b) | |
717 | b->hit_count = 0; | |
718 | } | |
719 | ||
9add0f1b TT |
720 | /* Allocate a new counted_command_line with reference count of 1. |
721 | The new structure owns COMMANDS. */ | |
722 | ||
723 | static struct counted_command_line * | |
724 | alloc_counted_command_line (struct command_line *commands) | |
725 | { | |
726 | struct counted_command_line *result | |
727 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 728 | |
9add0f1b TT |
729 | result->refc = 1; |
730 | result->commands = commands; | |
731 | return result; | |
732 | } | |
733 | ||
734 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
735 | ||
736 | static void | |
737 | incref_counted_command_line (struct counted_command_line *cmd) | |
738 | { | |
739 | if (cmd) | |
740 | ++cmd->refc; | |
741 | } | |
742 | ||
743 | /* Decrement reference count. If the reference count reaches 0, | |
744 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
745 | nothing if *CMDP is NULL. */ | |
746 | ||
747 | static void | |
748 | decref_counted_command_line (struct counted_command_line **cmdp) | |
749 | { | |
750 | if (*cmdp) | |
751 | { | |
752 | if (--(*cmdp)->refc == 0) | |
753 | { | |
754 | free_command_lines (&(*cmdp)->commands); | |
755 | xfree (*cmdp); | |
756 | } | |
757 | *cmdp = NULL; | |
758 | } | |
759 | } | |
760 | ||
761 | /* A cleanup function that calls decref_counted_command_line. */ | |
762 | ||
763 | static void | |
764 | do_cleanup_counted_command_line (void *arg) | |
765 | { | |
766 | decref_counted_command_line (arg); | |
767 | } | |
768 | ||
769 | /* Create a cleanup that calls decref_counted_command_line on the | |
770 | argument. */ | |
771 | ||
772 | static struct cleanup * | |
773 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
774 | { | |
775 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
776 | } | |
777 | ||
c906108c | 778 | \f |
48cb2d85 VP |
779 | /* Return the breakpoint with the specified number, or NULL |
780 | if the number does not refer to an existing breakpoint. */ | |
781 | ||
782 | struct breakpoint * | |
783 | get_breakpoint (int num) | |
784 | { | |
785 | struct breakpoint *b; | |
786 | ||
787 | ALL_BREAKPOINTS (b) | |
788 | if (b->number == num) | |
789 | return b; | |
790 | ||
791 | return NULL; | |
792 | } | |
5c44784c | 793 | |
c906108c | 794 | \f |
adc36818 | 795 | |
b775012e LM |
796 | /* Mark locations as "conditions have changed" in case the target supports |
797 | evaluating conditions on its side. */ | |
798 | ||
799 | static void | |
800 | mark_breakpoint_modified (struct breakpoint *b) | |
801 | { | |
802 | struct bp_location *loc; | |
803 | ||
804 | /* This is only meaningful if the target is | |
805 | evaluating conditions and if the user has | |
806 | opted for condition evaluation on the target's | |
807 | side. */ | |
808 | if (gdb_evaluates_breakpoint_condition_p () | |
809 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
810 | return; | |
811 | ||
812 | if (!is_breakpoint (b)) | |
813 | return; | |
814 | ||
815 | for (loc = b->loc; loc; loc = loc->next) | |
816 | loc->condition_changed = condition_modified; | |
817 | } | |
818 | ||
819 | /* Mark location as "conditions have changed" in case the target supports | |
820 | evaluating conditions on its side. */ | |
821 | ||
822 | static void | |
823 | mark_breakpoint_location_modified (struct bp_location *loc) | |
824 | { | |
825 | /* This is only meaningful if the target is | |
826 | evaluating conditions and if the user has | |
827 | opted for condition evaluation on the target's | |
828 | side. */ | |
829 | if (gdb_evaluates_breakpoint_condition_p () | |
830 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
831 | ||
832 | return; | |
833 | ||
834 | if (!is_breakpoint (loc->owner)) | |
835 | return; | |
836 | ||
837 | loc->condition_changed = condition_modified; | |
838 | } | |
839 | ||
840 | /* Sets the condition-evaluation mode using the static global | |
841 | condition_evaluation_mode. */ | |
842 | ||
843 | static void | |
844 | set_condition_evaluation_mode (char *args, int from_tty, | |
845 | struct cmd_list_element *c) | |
846 | { | |
b775012e LM |
847 | const char *old_mode, *new_mode; |
848 | ||
849 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
850 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
851 | { | |
852 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
853 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
854 | "Using host evaluation mode instead.")); | |
855 | return; | |
856 | } | |
857 | ||
858 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
859 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
860 | ||
abf1152a JK |
861 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
862 | settings was "auto". */ | |
863 | condition_evaluation_mode = condition_evaluation_mode_1; | |
864 | ||
b775012e LM |
865 | /* Only update the mode if the user picked a different one. */ |
866 | if (new_mode != old_mode) | |
867 | { | |
868 | struct bp_location *loc, **loc_tmp; | |
869 | /* If the user switched to a different evaluation mode, we | |
870 | need to synch the changes with the target as follows: | |
871 | ||
872 | "host" -> "target": Send all (valid) conditions to the target. | |
873 | "target" -> "host": Remove all the conditions from the target. | |
874 | */ | |
875 | ||
b775012e LM |
876 | if (new_mode == condition_evaluation_target) |
877 | { | |
878 | /* Mark everything modified and synch conditions with the | |
879 | target. */ | |
880 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
881 | mark_breakpoint_location_modified (loc); | |
882 | } | |
883 | else | |
884 | { | |
885 | /* Manually mark non-duplicate locations to synch conditions | |
886 | with the target. We do this to remove all the conditions the | |
887 | target knows about. */ | |
888 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
889 | if (is_breakpoint (loc->owner) && loc->inserted) | |
890 | loc->needs_update = 1; | |
891 | } | |
892 | ||
893 | /* Do the update. */ | |
44702360 | 894 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
895 | } |
896 | ||
897 | return; | |
898 | } | |
899 | ||
900 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
901 | what "auto" is translating to. */ | |
902 | ||
903 | static void | |
904 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
905 | struct cmd_list_element *c, const char *value) | |
906 | { | |
907 | if (condition_evaluation_mode == condition_evaluation_auto) | |
908 | fprintf_filtered (file, | |
909 | _("Breakpoint condition evaluation " | |
910 | "mode is %s (currently %s).\n"), | |
911 | value, | |
912 | breakpoint_condition_evaluation_mode ()); | |
913 | else | |
914 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
915 | value); | |
916 | } | |
917 | ||
918 | /* A comparison function for bp_location AP and BP that is used by | |
919 | bsearch. This comparison function only cares about addresses, unlike | |
920 | the more general bp_location_compare function. */ | |
921 | ||
922 | static int | |
923 | bp_location_compare_addrs (const void *ap, const void *bp) | |
924 | { | |
925 | struct bp_location *a = *(void **) ap; | |
926 | struct bp_location *b = *(void **) bp; | |
927 | ||
928 | if (a->address == b->address) | |
929 | return 0; | |
930 | else | |
931 | return ((a->address > b->address) - (a->address < b->address)); | |
932 | } | |
933 | ||
934 | /* Helper function to skip all bp_locations with addresses | |
935 | less than ADDRESS. It returns the first bp_location that | |
936 | is greater than or equal to ADDRESS. If none is found, just | |
937 | return NULL. */ | |
938 | ||
939 | static struct bp_location ** | |
940 | get_first_locp_gte_addr (CORE_ADDR address) | |
941 | { | |
942 | struct bp_location dummy_loc; | |
943 | struct bp_location *dummy_locp = &dummy_loc; | |
944 | struct bp_location **locp_found = NULL; | |
945 | ||
946 | /* Initialize the dummy location's address field. */ | |
947 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
948 | dummy_loc.address = address; | |
949 | ||
950 | /* Find a close match to the first location at ADDRESS. */ | |
951 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, | |
952 | sizeof (struct bp_location **), | |
953 | bp_location_compare_addrs); | |
954 | ||
955 | /* Nothing was found, nothing left to do. */ | |
956 | if (locp_found == NULL) | |
957 | return NULL; | |
958 | ||
959 | /* We may have found a location that is at ADDRESS but is not the first in the | |
960 | location's list. Go backwards (if possible) and locate the first one. */ | |
961 | while ((locp_found - 1) >= bp_location | |
962 | && (*(locp_found - 1))->address == address) | |
963 | locp_found--; | |
964 | ||
965 | return locp_found; | |
966 | } | |
967 | ||
adc36818 | 968 | void |
7a26bd4d | 969 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
970 | int from_tty) |
971 | { | |
3a5c3e22 PA |
972 | xfree (b->cond_string); |
973 | b->cond_string = NULL; | |
adc36818 | 974 | |
3a5c3e22 | 975 | if (is_watchpoint (b)) |
adc36818 | 976 | { |
3a5c3e22 PA |
977 | struct watchpoint *w = (struct watchpoint *) b; |
978 | ||
979 | xfree (w->cond_exp); | |
980 | w->cond_exp = NULL; | |
981 | } | |
982 | else | |
983 | { | |
984 | struct bp_location *loc; | |
985 | ||
986 | for (loc = b->loc; loc; loc = loc->next) | |
987 | { | |
988 | xfree (loc->cond); | |
989 | loc->cond = NULL; | |
b775012e LM |
990 | |
991 | /* No need to free the condition agent expression | |
992 | bytecode (if we have one). We will handle this | |
993 | when we go through update_global_location_list. */ | |
3a5c3e22 | 994 | } |
adc36818 | 995 | } |
adc36818 PM |
996 | |
997 | if (*exp == 0) | |
998 | { | |
999 | if (from_tty) | |
1000 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
1001 | } | |
1002 | else | |
1003 | { | |
bbc13ae3 | 1004 | const char *arg = exp; |
cc59ec59 | 1005 | |
adc36818 PM |
1006 | /* I don't know if it matters whether this is the string the user |
1007 | typed in or the decompiled expression. */ | |
1008 | b->cond_string = xstrdup (arg); | |
1009 | b->condition_not_parsed = 0; | |
1010 | ||
1011 | if (is_watchpoint (b)) | |
1012 | { | |
3a5c3e22 PA |
1013 | struct watchpoint *w = (struct watchpoint *) b; |
1014 | ||
adc36818 PM |
1015 | innermost_block = NULL; |
1016 | arg = exp; | |
1bb9788d | 1017 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1018 | if (*arg) |
1019 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1020 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1021 | } |
1022 | else | |
1023 | { | |
3a5c3e22 PA |
1024 | struct bp_location *loc; |
1025 | ||
adc36818 PM |
1026 | for (loc = b->loc; loc; loc = loc->next) |
1027 | { | |
1028 | arg = exp; | |
1029 | loc->cond = | |
1bb9788d TT |
1030 | parse_exp_1 (&arg, loc->address, |
1031 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1032 | if (*arg) |
1033 | error (_("Junk at end of expression")); | |
1034 | } | |
1035 | } | |
1036 | } | |
b775012e LM |
1037 | mark_breakpoint_modified (b); |
1038 | ||
8d3788bd | 1039 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1040 | } |
1041 | ||
d55637df TT |
1042 | /* Completion for the "condition" command. */ |
1043 | ||
1044 | static VEC (char_ptr) * | |
6f937416 PA |
1045 | condition_completer (struct cmd_list_element *cmd, |
1046 | const char *text, const char *word) | |
d55637df | 1047 | { |
6f937416 | 1048 | const char *space; |
d55637df | 1049 | |
6f937416 PA |
1050 | text = skip_spaces_const (text); |
1051 | space = skip_to_space_const (text); | |
d55637df TT |
1052 | if (*space == '\0') |
1053 | { | |
1054 | int len; | |
1055 | struct breakpoint *b; | |
1056 | VEC (char_ptr) *result = NULL; | |
1057 | ||
1058 | if (text[0] == '$') | |
1059 | { | |
1060 | /* We don't support completion of history indices. */ | |
1061 | if (isdigit (text[1])) | |
1062 | return NULL; | |
1063 | return complete_internalvar (&text[1]); | |
1064 | } | |
1065 | ||
1066 | /* We're completing the breakpoint number. */ | |
1067 | len = strlen (text); | |
1068 | ||
1069 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1070 | { |
1071 | char number[50]; | |
1072 | ||
1073 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1074 | ||
1075 | if (strncmp (number, text, len) == 0) | |
1076 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1077 | } | |
d55637df TT |
1078 | |
1079 | return result; | |
1080 | } | |
1081 | ||
1082 | /* We're completing the expression part. */ | |
6f937416 | 1083 | text = skip_spaces_const (space); |
d55637df TT |
1084 | return expression_completer (cmd, text, word); |
1085 | } | |
1086 | ||
c906108c SS |
1087 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1088 | ||
1089 | static void | |
fba45db2 | 1090 | condition_command (char *arg, int from_tty) |
c906108c | 1091 | { |
52f0bd74 | 1092 | struct breakpoint *b; |
c906108c | 1093 | char *p; |
52f0bd74 | 1094 | int bnum; |
c906108c SS |
1095 | |
1096 | if (arg == 0) | |
e2e0b3e5 | 1097 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1098 | |
1099 | p = arg; | |
1100 | bnum = get_number (&p); | |
5c44784c | 1101 | if (bnum == 0) |
8a3fe4f8 | 1102 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1103 | |
1104 | ALL_BREAKPOINTS (b) | |
1105 | if (b->number == bnum) | |
2f069f6f | 1106 | { |
6dddc817 DE |
1107 | /* Check if this breakpoint has a "stop" method implemented in an |
1108 | extension language. This method and conditions entered into GDB | |
1109 | from the CLI are mutually exclusive. */ | |
1110 | const struct extension_language_defn *extlang | |
1111 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1112 | ||
1113 | if (extlang != NULL) | |
1114 | { | |
1115 | error (_("Only one stop condition allowed. There is currently" | |
1116 | " a %s stop condition defined for this breakpoint."), | |
1117 | ext_lang_capitalized_name (extlang)); | |
1118 | } | |
2566ad2d | 1119 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1120 | |
1121 | if (is_breakpoint (b)) | |
44702360 | 1122 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1123 | |
2f069f6f JB |
1124 | return; |
1125 | } | |
c906108c | 1126 | |
8a3fe4f8 | 1127 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1128 | } |
1129 | ||
a7bdde9e VP |
1130 | /* Check that COMMAND do not contain commands that are suitable |
1131 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1132 | Throw if any such commands is found. */ |
1133 | ||
a7bdde9e VP |
1134 | static void |
1135 | check_no_tracepoint_commands (struct command_line *commands) | |
1136 | { | |
1137 | struct command_line *c; | |
cc59ec59 | 1138 | |
a7bdde9e VP |
1139 | for (c = commands; c; c = c->next) |
1140 | { | |
1141 | int i; | |
1142 | ||
1143 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1144 | error (_("The 'while-stepping' command can " |
1145 | "only be used for tracepoints")); | |
a7bdde9e VP |
1146 | |
1147 | for (i = 0; i < c->body_count; ++i) | |
1148 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1149 | ||
1150 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1151 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1152 | command directly. */ |
1153 | if (strstr (c->line, "collect ") == c->line) | |
1154 | error (_("The 'collect' command can only be used for tracepoints")); | |
1155 | ||
51661e93 VP |
1156 | if (strstr (c->line, "teval ") == c->line) |
1157 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1158 | } |
1159 | } | |
1160 | ||
d77f58be SS |
1161 | /* Encapsulate tests for different types of tracepoints. */ |
1162 | ||
d9b3f62e PA |
1163 | static int |
1164 | is_tracepoint_type (enum bptype type) | |
1165 | { | |
1166 | return (type == bp_tracepoint | |
1167 | || type == bp_fast_tracepoint | |
1168 | || type == bp_static_tracepoint); | |
1169 | } | |
1170 | ||
a7bdde9e | 1171 | int |
d77f58be | 1172 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1173 | { |
d9b3f62e | 1174 | return is_tracepoint_type (b->type); |
a7bdde9e | 1175 | } |
d9b3f62e | 1176 | |
e5dd4106 | 1177 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1178 | breakpoint. This function will throw an exception if a problem is |
1179 | found. */ | |
48cb2d85 | 1180 | |
95a42b64 TT |
1181 | static void |
1182 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1183 | struct command_line *commands) | |
48cb2d85 | 1184 | { |
d77f58be | 1185 | if (is_tracepoint (b)) |
a7bdde9e | 1186 | { |
c9a6ce02 | 1187 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1188 | struct command_line *c; |
1189 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1190 | |
1191 | /* Reset the while-stepping step count. The previous commands | |
1192 | might have included a while-stepping action, while the new | |
1193 | ones might not. */ | |
1194 | t->step_count = 0; | |
1195 | ||
1196 | /* We need to verify that each top-level element of commands is | |
1197 | valid for tracepoints, that there's at most one | |
1198 | while-stepping element, and that the while-stepping's body | |
1199 | has valid tracing commands excluding nested while-stepping. | |
1200 | We also need to validate the tracepoint action line in the | |
1201 | context of the tracepoint --- validate_actionline actually | |
1202 | has side effects, like setting the tracepoint's | |
1203 | while-stepping STEP_COUNT, in addition to checking if the | |
1204 | collect/teval actions parse and make sense in the | |
1205 | tracepoint's context. */ | |
a7bdde9e VP |
1206 | for (c = commands; c; c = c->next) |
1207 | { | |
a7bdde9e VP |
1208 | if (c->control_type == while_stepping_control) |
1209 | { | |
1210 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1211 | error (_("The 'while-stepping' command " |
1212 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1213 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1214 | error (_("The 'while-stepping' command " |
1215 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1216 | |
1217 | if (while_stepping) | |
3e43a32a MS |
1218 | error (_("The 'while-stepping' command " |
1219 | "can be used only once")); | |
a7bdde9e VP |
1220 | else |
1221 | while_stepping = c; | |
1222 | } | |
c9a6ce02 PA |
1223 | |
1224 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1225 | } |
1226 | if (while_stepping) | |
1227 | { | |
1228 | struct command_line *c2; | |
1229 | ||
1230 | gdb_assert (while_stepping->body_count == 1); | |
1231 | c2 = while_stepping->body_list[0]; | |
1232 | for (; c2; c2 = c2->next) | |
1233 | { | |
a7bdde9e VP |
1234 | if (c2->control_type == while_stepping_control) |
1235 | error (_("The 'while-stepping' command cannot be nested")); | |
1236 | } | |
1237 | } | |
1238 | } | |
1239 | else | |
1240 | { | |
1241 | check_no_tracepoint_commands (commands); | |
1242 | } | |
95a42b64 TT |
1243 | } |
1244 | ||
0fb4aa4b PA |
1245 | /* Return a vector of all the static tracepoints set at ADDR. The |
1246 | caller is responsible for releasing the vector. */ | |
1247 | ||
1248 | VEC(breakpoint_p) * | |
1249 | static_tracepoints_here (CORE_ADDR addr) | |
1250 | { | |
1251 | struct breakpoint *b; | |
1252 | VEC(breakpoint_p) *found = 0; | |
1253 | struct bp_location *loc; | |
1254 | ||
1255 | ALL_BREAKPOINTS (b) | |
1256 | if (b->type == bp_static_tracepoint) | |
1257 | { | |
1258 | for (loc = b->loc; loc; loc = loc->next) | |
1259 | if (loc->address == addr) | |
1260 | VEC_safe_push(breakpoint_p, found, b); | |
1261 | } | |
1262 | ||
1263 | return found; | |
1264 | } | |
1265 | ||
95a42b64 | 1266 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1267 | validate that only allowed commands are included. */ |
95a42b64 TT |
1268 | |
1269 | void | |
4a64f543 MS |
1270 | breakpoint_set_commands (struct breakpoint *b, |
1271 | struct command_line *commands) | |
95a42b64 TT |
1272 | { |
1273 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1274 | |
9add0f1b TT |
1275 | decref_counted_command_line (&b->commands); |
1276 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1277 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1278 | } |
1279 | ||
45a43567 TT |
1280 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1281 | is not the same as the "silent" that may appear in the breakpoint's | |
1282 | commands. */ | |
1283 | ||
1284 | void | |
1285 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1286 | { | |
1287 | int old_silent = b->silent; | |
1288 | ||
1289 | b->silent = silent; | |
1290 | if (old_silent != silent) | |
8d3788bd | 1291 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1292 | } |
1293 | ||
1294 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1295 | breakpoint work for any thread. */ | |
1296 | ||
1297 | void | |
1298 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1299 | { | |
1300 | int old_thread = b->thread; | |
1301 | ||
1302 | b->thread = thread; | |
1303 | if (old_thread != thread) | |
8d3788bd | 1304 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1305 | } |
1306 | ||
1307 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1308 | breakpoint work for any task. */ | |
1309 | ||
1310 | void | |
1311 | breakpoint_set_task (struct breakpoint *b, int task) | |
1312 | { | |
1313 | int old_task = b->task; | |
1314 | ||
1315 | b->task = task; | |
1316 | if (old_task != task) | |
8d3788bd | 1317 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1318 | } |
1319 | ||
95a42b64 TT |
1320 | void |
1321 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1322 | { |
1323 | struct breakpoint *b = closure; | |
cc59ec59 | 1324 | |
6f937416 | 1325 | validate_actionline (line, b); |
a7bdde9e VP |
1326 | } |
1327 | ||
95a42b64 TT |
1328 | /* A structure used to pass information through |
1329 | map_breakpoint_numbers. */ | |
1330 | ||
1331 | struct commands_info | |
1332 | { | |
1333 | /* True if the command was typed at a tty. */ | |
1334 | int from_tty; | |
86b17b60 PA |
1335 | |
1336 | /* The breakpoint range spec. */ | |
1337 | char *arg; | |
1338 | ||
95a42b64 TT |
1339 | /* Non-NULL if the body of the commands are being read from this |
1340 | already-parsed command. */ | |
1341 | struct command_line *control; | |
86b17b60 | 1342 | |
95a42b64 TT |
1343 | /* The command lines read from the user, or NULL if they have not |
1344 | yet been read. */ | |
1345 | struct counted_command_line *cmd; | |
1346 | }; | |
1347 | ||
1348 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1349 | commands_command. */ | |
1350 | ||
c906108c | 1351 | static void |
95a42b64 | 1352 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1353 | { |
95a42b64 | 1354 | struct commands_info *info = data; |
c906108c | 1355 | |
95a42b64 TT |
1356 | if (info->cmd == NULL) |
1357 | { | |
1358 | struct command_line *l; | |
5c44784c | 1359 | |
95a42b64 TT |
1360 | if (info->control != NULL) |
1361 | l = copy_command_lines (info->control->body_list[0]); | |
1362 | else | |
86b17b60 PA |
1363 | { |
1364 | struct cleanup *old_chain; | |
1365 | char *str; | |
c5aa993b | 1366 | |
3e43a32a MS |
1367 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1368 | "%s, one per line."), | |
86b17b60 PA |
1369 | info->arg); |
1370 | ||
1371 | old_chain = make_cleanup (xfree, str); | |
1372 | ||
1373 | l = read_command_lines (str, | |
1374 | info->from_tty, 1, | |
d77f58be | 1375 | (is_tracepoint (b) |
86b17b60 PA |
1376 | ? check_tracepoint_command : 0), |
1377 | b); | |
1378 | ||
1379 | do_cleanups (old_chain); | |
1380 | } | |
a7bdde9e | 1381 | |
95a42b64 TT |
1382 | info->cmd = alloc_counted_command_line (l); |
1383 | } | |
1384 | ||
1385 | /* If a breakpoint was on the list more than once, we don't need to | |
1386 | do anything. */ | |
1387 | if (b->commands != info->cmd) | |
1388 | { | |
1389 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1390 | incref_counted_command_line (info->cmd); | |
1391 | decref_counted_command_line (&b->commands); | |
1392 | b->commands = info->cmd; | |
8d3788bd | 1393 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1394 | } |
95a42b64 TT |
1395 | } |
1396 | ||
1397 | static void | |
4a64f543 MS |
1398 | commands_command_1 (char *arg, int from_tty, |
1399 | struct command_line *control) | |
95a42b64 TT |
1400 | { |
1401 | struct cleanup *cleanups; | |
1402 | struct commands_info info; | |
1403 | ||
1404 | info.from_tty = from_tty; | |
1405 | info.control = control; | |
1406 | info.cmd = NULL; | |
1407 | /* If we read command lines from the user, then `info' will hold an | |
1408 | extra reference to the commands that we must clean up. */ | |
1409 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1410 | ||
1411 | if (arg == NULL || !*arg) | |
1412 | { | |
86b17b60 | 1413 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1414 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1415 | breakpoint_count); | |
95a42b64 TT |
1416 | else if (breakpoint_count > 0) |
1417 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1418 | else |
1419 | { | |
1420 | /* So that we don't try to free the incoming non-NULL | |
1421 | argument in the cleanup below. Mapping breakpoint | |
1422 | numbers will fail in this case. */ | |
1423 | arg = NULL; | |
1424 | } | |
95a42b64 | 1425 | } |
9766ced4 SS |
1426 | else |
1427 | /* The command loop has some static state, so we need to preserve | |
1428 | our argument. */ | |
1429 | arg = xstrdup (arg); | |
86b17b60 PA |
1430 | |
1431 | if (arg != NULL) | |
1432 | make_cleanup (xfree, arg); | |
1433 | ||
1434 | info.arg = arg; | |
95a42b64 TT |
1435 | |
1436 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1437 | ||
1438 | if (info.cmd == NULL) | |
1439 | error (_("No breakpoints specified.")); | |
1440 | ||
1441 | do_cleanups (cleanups); | |
1442 | } | |
1443 | ||
1444 | static void | |
1445 | commands_command (char *arg, int from_tty) | |
1446 | { | |
1447 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1448 | } |
40c03ae8 EZ |
1449 | |
1450 | /* Like commands_command, but instead of reading the commands from | |
1451 | input stream, takes them from an already parsed command structure. | |
1452 | ||
1453 | This is used by cli-script.c to DTRT with breakpoint commands | |
1454 | that are part of if and while bodies. */ | |
1455 | enum command_control_type | |
1456 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1457 | { | |
95a42b64 TT |
1458 | commands_command_1 (arg, 0, cmd); |
1459 | return simple_control; | |
40c03ae8 | 1460 | } |
876fa593 JK |
1461 | |
1462 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1463 | ||
1464 | static int | |
1465 | bp_location_has_shadow (struct bp_location *bl) | |
1466 | { | |
1467 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1468 | return 0; | |
1469 | if (!bl->inserted) | |
1470 | return 0; | |
1471 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1472 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1473 | return 0; |
1474 | return 1; | |
1475 | } | |
1476 | ||
9d497a19 PA |
1477 | /* Update BUF, which is LEN bytes read from the target address |
1478 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1479 | contents. | |
1480 | ||
1481 | If READBUF is not NULL, this buffer must not overlap with the of | |
1482 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1483 | failed assertion internal error will be raised. */ | |
1484 | ||
1485 | static void | |
1486 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1487 | const gdb_byte *writebuf_org, | |
1488 | ULONGEST memaddr, LONGEST len, | |
1489 | struct bp_target_info *target_info, | |
1490 | struct gdbarch *gdbarch) | |
1491 | { | |
1492 | /* Now do full processing of the found relevant range of elements. */ | |
1493 | CORE_ADDR bp_addr = 0; | |
1494 | int bp_size = 0; | |
1495 | int bptoffset = 0; | |
1496 | ||
1497 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1498 | current_program_space->aspace, 0)) | |
1499 | { | |
1500 | /* The breakpoint is inserted in a different address space. */ | |
1501 | return; | |
1502 | } | |
1503 | ||
1504 | /* Addresses and length of the part of the breakpoint that | |
1505 | we need to copy. */ | |
1506 | bp_addr = target_info->placed_address; | |
1507 | bp_size = target_info->shadow_len; | |
1508 | ||
1509 | if (bp_addr + bp_size <= memaddr) | |
1510 | { | |
1511 | /* The breakpoint is entirely before the chunk of memory we are | |
1512 | reading. */ | |
1513 | return; | |
1514 | } | |
1515 | ||
1516 | if (bp_addr >= memaddr + len) | |
1517 | { | |
1518 | /* The breakpoint is entirely after the chunk of memory we are | |
1519 | reading. */ | |
1520 | return; | |
1521 | } | |
1522 | ||
1523 | /* Offset within shadow_contents. */ | |
1524 | if (bp_addr < memaddr) | |
1525 | { | |
1526 | /* Only copy the second part of the breakpoint. */ | |
1527 | bp_size -= memaddr - bp_addr; | |
1528 | bptoffset = memaddr - bp_addr; | |
1529 | bp_addr = memaddr; | |
1530 | } | |
1531 | ||
1532 | if (bp_addr + bp_size > memaddr + len) | |
1533 | { | |
1534 | /* Only copy the first part of the breakpoint. */ | |
1535 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1536 | } | |
1537 | ||
1538 | if (readbuf != NULL) | |
1539 | { | |
1540 | /* Verify that the readbuf buffer does not overlap with the | |
1541 | shadow_contents buffer. */ | |
1542 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1543 | || readbuf >= (target_info->shadow_contents | |
1544 | + target_info->shadow_len)); | |
1545 | ||
1546 | /* Update the read buffer with this inserted breakpoint's | |
1547 | shadow. */ | |
1548 | memcpy (readbuf + bp_addr - memaddr, | |
1549 | target_info->shadow_contents + bptoffset, bp_size); | |
1550 | } | |
1551 | else | |
1552 | { | |
1553 | const unsigned char *bp; | |
0d5ed153 MR |
1554 | CORE_ADDR addr = target_info->reqstd_address; |
1555 | int placed_size; | |
9d497a19 PA |
1556 | |
1557 | /* Update the shadow with what we want to write to memory. */ | |
1558 | memcpy (target_info->shadow_contents + bptoffset, | |
1559 | writebuf_org + bp_addr - memaddr, bp_size); | |
1560 | ||
1561 | /* Determine appropriate breakpoint contents and size for this | |
1562 | address. */ | |
0d5ed153 | 1563 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1564 | |
1565 | /* Update the final write buffer with this inserted | |
1566 | breakpoint's INSN. */ | |
1567 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1568 | } | |
1569 | } | |
1570 | ||
8defab1a | 1571 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1572 | by replacing any memory breakpoints with their shadowed contents. |
1573 | ||
35c63cd8 JB |
1574 | If READBUF is not NULL, this buffer must not overlap with any of |
1575 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1576 | a failed assertion internal error will be raised. | |
1577 | ||
876fa593 | 1578 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1579 | bl->address - bp_location_placed_address_before_address_max |
1580 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1581 | The range we were requested to resolve shadows for is: |
1582 | memaddr ... memaddr + len | |
1583 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1584 | memaddr + len <= (bl->address |
1585 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1586 | and: |
35df4500 | 1587 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1588 | |
8defab1a | 1589 | void |
f0ba3972 PA |
1590 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1591 | const gdb_byte *writebuf_org, | |
1592 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1593 | { |
4a64f543 MS |
1594 | /* Left boundary, right boundary and median element of our binary |
1595 | search. */ | |
876fa593 | 1596 | unsigned bc_l, bc_r, bc; |
9d497a19 | 1597 | size_t i; |
876fa593 | 1598 | |
4a64f543 MS |
1599 | /* Find BC_L which is a leftmost element which may affect BUF |
1600 | content. It is safe to report lower value but a failure to | |
1601 | report higher one. */ | |
876fa593 JK |
1602 | |
1603 | bc_l = 0; | |
1604 | bc_r = bp_location_count; | |
1605 | while (bc_l + 1 < bc_r) | |
1606 | { | |
35df4500 | 1607 | struct bp_location *bl; |
876fa593 JK |
1608 | |
1609 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1610 | bl = bp_location[bc]; |
876fa593 | 1611 | |
4a64f543 MS |
1612 | /* Check first BL->ADDRESS will not overflow due to the added |
1613 | constant. Then advance the left boundary only if we are sure | |
1614 | the BC element can in no way affect the BUF content (MEMADDR | |
1615 | to MEMADDR + LEN range). | |
876fa593 | 1616 | |
4a64f543 MS |
1617 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1618 | offset so that we cannot miss a breakpoint with its shadow | |
1619 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1620 | |
35df4500 TJB |
1621 | if ((bl->address + bp_location_shadow_len_after_address_max |
1622 | >= bl->address) | |
1623 | && (bl->address + bp_location_shadow_len_after_address_max | |
1624 | <= memaddr)) | |
876fa593 JK |
1625 | bc_l = bc; |
1626 | else | |
1627 | bc_r = bc; | |
1628 | } | |
1629 | ||
128070bb PA |
1630 | /* Due to the binary search above, we need to make sure we pick the |
1631 | first location that's at BC_L's address. E.g., if there are | |
1632 | multiple locations at the same address, BC_L may end up pointing | |
1633 | at a duplicate location, and miss the "master"/"inserted" | |
1634 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1635 | B: | |
1636 | ||
1637 | L1@A, L2@A, L3@B, ... | |
1638 | ||
1639 | BC_L could end up pointing at location L2, while the "master" | |
1640 | location could be L1. Since the `loc->inserted' flag is only set | |
1641 | on "master" locations, we'd forget to restore the shadow of L1 | |
1642 | and L2. */ | |
1643 | while (bc_l > 0 | |
1644 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1645 | bc_l--; | |
1646 | ||
876fa593 JK |
1647 | /* Now do full processing of the found relevant range of elements. */ |
1648 | ||
1649 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1650 | { |
35df4500 | 1651 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1652 | CORE_ADDR bp_addr = 0; |
1653 | int bp_size = 0; | |
1654 | int bptoffset = 0; | |
1655 | ||
35df4500 TJB |
1656 | /* bp_location array has BL->OWNER always non-NULL. */ |
1657 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1658 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1659 | bl->owner->number); |
ffce0d52 | 1660 | |
e5dd4106 | 1661 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1662 | content. */ |
1663 | ||
35df4500 TJB |
1664 | if (bl->address >= bp_location_placed_address_before_address_max |
1665 | && memaddr + len <= (bl->address | |
1666 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1667 | break; |
1668 | ||
35df4500 | 1669 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1670 | continue; |
6c95b8df | 1671 | |
9d497a19 PA |
1672 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1673 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1674 | } | |
c906108c | 1675 | } |
9d497a19 | 1676 | |
c906108c | 1677 | \f |
c5aa993b | 1678 | |
b775012e LM |
1679 | /* Return true if BPT is either a software breakpoint or a hardware |
1680 | breakpoint. */ | |
1681 | ||
1682 | int | |
1683 | is_breakpoint (const struct breakpoint *bpt) | |
1684 | { | |
1685 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1686 | || bpt->type == bp_hardware_breakpoint |
1687 | || bpt->type == bp_dprintf); | |
b775012e LM |
1688 | } |
1689 | ||
60e1c644 PA |
1690 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1691 | ||
a5606eee | 1692 | static int |
d77f58be | 1693 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1694 | { |
1695 | return (bpt->type == bp_hardware_watchpoint | |
1696 | || bpt->type == bp_read_watchpoint | |
1697 | || bpt->type == bp_access_watchpoint); | |
1698 | } | |
7270d8f2 | 1699 | |
60e1c644 PA |
1700 | /* Return true if BPT is of any watchpoint kind, hardware or |
1701 | software. */ | |
1702 | ||
3a5c3e22 | 1703 | int |
d77f58be | 1704 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1705 | { |
1706 | return (is_hardware_watchpoint (bpt) | |
1707 | || bpt->type == bp_watchpoint); | |
1708 | } | |
1709 | ||
3a5c3e22 PA |
1710 | /* Returns true if the current thread and its running state are safe |
1711 | to evaluate or update watchpoint B. Watchpoints on local | |
1712 | expressions need to be evaluated in the context of the thread that | |
1713 | was current when the watchpoint was created, and, that thread needs | |
1714 | to be stopped to be able to select the correct frame context. | |
1715 | Watchpoints on global expressions can be evaluated on any thread, | |
1716 | and in any state. It is presently left to the target allowing | |
1717 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1718 | |
1719 | static int | |
3a5c3e22 | 1720 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1721 | { |
d0d8b0c6 JK |
1722 | return (b->base.pspace == current_program_space |
1723 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1724 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1725 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1726 | } |
1727 | ||
d0fb5eae JK |
1728 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1729 | associated bp_watchpoint_scope breakpoint. */ | |
1730 | ||
1731 | static void | |
3a5c3e22 | 1732 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1733 | { |
3a5c3e22 | 1734 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1735 | |
1736 | if (b->related_breakpoint != b) | |
1737 | { | |
1738 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1739 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1740 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1741 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1742 | b->related_breakpoint = b; | |
1743 | } | |
1744 | b->disposition = disp_del_at_next_stop; | |
1745 | } | |
1746 | ||
bb9d5f81 PP |
1747 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1748 | watchpoint W. */ | |
1749 | ||
1750 | static struct value * | |
1751 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1752 | { | |
1753 | struct value *bit_val; | |
1754 | ||
1755 | if (val == NULL) | |
1756 | return NULL; | |
1757 | ||
1758 | bit_val = allocate_value (value_type (val)); | |
1759 | ||
1760 | unpack_value_bitfield (bit_val, | |
1761 | w->val_bitpos, | |
1762 | w->val_bitsize, | |
1763 | value_contents_for_printing (val), | |
1764 | value_offset (val), | |
1765 | val); | |
1766 | ||
1767 | return bit_val; | |
1768 | } | |
1769 | ||
567e1b4e JB |
1770 | /* Assuming that B is a watchpoint: |
1771 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1772 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1773 | - Evaluate the condition if there is one, and store the result |
1774 | in b->loc->cond. | |
a5606eee VP |
1775 | - Update the list of values that must be watched in B->loc. |
1776 | ||
4a64f543 MS |
1777 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1778 | nothing. If this is local watchpoint that is out of scope, delete | |
1779 | it. | |
1780 | ||
1781 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1782 | removed + inserted on each stop here. Normal breakpoints must | |
1783 | never be removed because they might be missed by a running thread | |
1784 | when debugging in non-stop mode. On the other hand, hardware | |
1785 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1786 | to each LWP since they are stored in each LWP's hardware debug | |
1787 | registers. Therefore, such LWP must be stopped first in order to | |
1788 | be able to modify its hardware watchpoints. | |
1789 | ||
1790 | Hardware watchpoints must be reset exactly once after being | |
1791 | presented to the user. It cannot be done sooner, because it would | |
1792 | reset the data used to present the watchpoint hit to the user. And | |
1793 | it must not be done later because it could display the same single | |
1794 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1795 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1796 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1797 | not user-visible - its hit is suppressed if the memory content has | |
1798 | not changed. | |
1799 | ||
1800 | The following constraints influence the location where we can reset | |
1801 | hardware watchpoints: | |
1802 | ||
1803 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1804 | called several times when GDB stops. | |
1805 | ||
1806 | [linux] | |
1807 | * Multiple hardware watchpoints can be hit at the same time, | |
1808 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1809 | hit at a time as the reason for stopping, and all the other hits | |
1810 | are presented later, one after the other, each time the user | |
1811 | requests the execution to be resumed. Execution is not resumed | |
1812 | for the threads still having pending hit event stored in | |
1813 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1814 | the inferior on the first stop the thread hit event is kept being | |
1815 | reported from its cached value by linux_nat_stopped_data_address | |
1816 | until the real thread resume happens after the watchpoint gets | |
1817 | presented and thus its LWP_INFO->STATUS gets reset. | |
1818 | ||
1819 | Therefore the hardware watchpoint hit can get safely reset on the | |
1820 | watchpoint removal from inferior. */ | |
a79d3c27 | 1821 | |
b40ce68a | 1822 | static void |
3a5c3e22 | 1823 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1824 | { |
a5606eee | 1825 | int within_current_scope; |
a5606eee | 1826 | struct frame_id saved_frame_id; |
66076460 | 1827 | int frame_saved; |
a5606eee | 1828 | |
f6bc2008 PA |
1829 | /* If this is a local watchpoint, we only want to check if the |
1830 | watchpoint frame is in scope if the current thread is the thread | |
1831 | that was used to create the watchpoint. */ | |
1832 | if (!watchpoint_in_thread_scope (b)) | |
1833 | return; | |
1834 | ||
3a5c3e22 | 1835 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1836 | return; |
1837 | ||
66076460 | 1838 | frame_saved = 0; |
a5606eee VP |
1839 | |
1840 | /* Determine if the watchpoint is within scope. */ | |
1841 | if (b->exp_valid_block == NULL) | |
1842 | within_current_scope = 1; | |
1843 | else | |
1844 | { | |
b5db5dfc UW |
1845 | struct frame_info *fi = get_current_frame (); |
1846 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1847 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1848 | ||
c9cf6e20 MG |
1849 | /* If we're at a point where the stack has been destroyed |
1850 | (e.g. in a function epilogue), unwinding may not work | |
1851 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1852 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1853 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1854 | return; |
66076460 DJ |
1855 | |
1856 | /* Save the current frame's ID so we can restore it after | |
1857 | evaluating the watchpoint expression on its own frame. */ | |
1858 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1859 | took a frame parameter, so that we didn't have to change the | |
1860 | selected frame. */ | |
1861 | frame_saved = 1; | |
1862 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1863 | ||
a5606eee VP |
1864 | fi = frame_find_by_id (b->watchpoint_frame); |
1865 | within_current_scope = (fi != NULL); | |
1866 | if (within_current_scope) | |
1867 | select_frame (fi); | |
1868 | } | |
1869 | ||
b5db5dfc UW |
1870 | /* We don't free locations. They are stored in the bp_location array |
1871 | and update_global_location_list will eventually delete them and | |
1872 | remove breakpoints if needed. */ | |
3a5c3e22 | 1873 | b->base.loc = NULL; |
b5db5dfc | 1874 | |
a5606eee VP |
1875 | if (within_current_scope && reparse) |
1876 | { | |
bbc13ae3 | 1877 | const char *s; |
d63d0675 | 1878 | |
a5606eee VP |
1879 | if (b->exp) |
1880 | { | |
1881 | xfree (b->exp); | |
1882 | b->exp = NULL; | |
1883 | } | |
d63d0675 | 1884 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1885 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1886 | /* If the meaning of expression itself changed, the old value is |
1887 | no longer relevant. We don't want to report a watchpoint hit | |
1888 | to the user when the old value and the new value may actually | |
1889 | be completely different objects. */ | |
1890 | value_free (b->val); | |
fa4727a6 DJ |
1891 | b->val = NULL; |
1892 | b->val_valid = 0; | |
60e1c644 PA |
1893 | |
1894 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1895 | expression is stored in the breakpoint object, not in the | |
1896 | locations (re)created below. */ | |
3a5c3e22 | 1897 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1898 | { |
1899 | if (b->cond_exp != NULL) | |
1900 | { | |
1901 | xfree (b->cond_exp); | |
1902 | b->cond_exp = NULL; | |
1903 | } | |
1904 | ||
3a5c3e22 | 1905 | s = b->base.cond_string; |
1bb9788d | 1906 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1907 | } |
a5606eee | 1908 | } |
a5606eee VP |
1909 | |
1910 | /* If we failed to parse the expression, for example because | |
1911 | it refers to a global variable in a not-yet-loaded shared library, | |
1912 | don't try to insert watchpoint. We don't automatically delete | |
1913 | such watchpoint, though, since failure to parse expression | |
1914 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1915 | if (!target_has_execution) |
2d134ed3 PA |
1916 | { |
1917 | /* Without execution, memory can't change. No use to try and | |
1918 | set watchpoint locations. The watchpoint will be reset when | |
1919 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1920 | if (!can_use_hw_watchpoints) |
1921 | { | |
1922 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1923 | b->base.type = bp_watchpoint; | |
1924 | else | |
638aa5a1 AB |
1925 | error (_("Can't set read/access watchpoint when " |
1926 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1927 | } |
2d134ed3 PA |
1928 | } |
1929 | else if (within_current_scope && b->exp) | |
a5606eee | 1930 | { |
0cf6dd15 | 1931 | int pc = 0; |
fa4727a6 | 1932 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1933 | struct program_space *frame_pspace; |
a5606eee | 1934 | |
3a1115a0 | 1935 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1936 | |
a5606eee VP |
1937 | /* Avoid setting b->val if it's already set. The meaning of |
1938 | b->val is 'the last value' user saw, and we should update | |
1939 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1940 | happens, the code that reports it updates b->val directly. |
1941 | We don't keep track of the memory value for masked | |
1942 | watchpoints. */ | |
3a5c3e22 | 1943 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 | 1944 | { |
bb9d5f81 PP |
1945 | if (b->val_bitsize != 0) |
1946 | { | |
1947 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1948 | if (v != NULL) | |
1949 | release_value (v); | |
1950 | } | |
fa4727a6 DJ |
1951 | b->val = v; |
1952 | b->val_valid = 1; | |
1953 | } | |
a5606eee | 1954 | |
2d134ed3 PA |
1955 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1956 | ||
a5606eee | 1957 | /* Look at each value on the value chain. */ |
9fa40276 | 1958 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1959 | { |
1960 | /* If it's a memory location, and GDB actually needed | |
1961 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1962 | must watch it. If the first value returned is |
1963 | still lazy, that means an error occurred reading it; | |
1964 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1965 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1966 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1967 | { |
1968 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1969 | |
a5606eee VP |
1970 | /* We only watch structs and arrays if user asked |
1971 | for it explicitly, never if they just happen to | |
1972 | appear in the middle of some value chain. */ | |
fa4727a6 | 1973 | if (v == result |
a5606eee VP |
1974 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1975 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1976 | { | |
1977 | CORE_ADDR addr; | |
f486487f | 1978 | enum target_hw_bp_type type; |
a5606eee | 1979 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1980 | int bitpos = 0, bitsize = 0; |
1981 | ||
1982 | if (value_bitsize (v) != 0) | |
1983 | { | |
1984 | /* Extract the bit parameters out from the bitfield | |
1985 | sub-expression. */ | |
1986 | bitpos = value_bitpos (v); | |
1987 | bitsize = value_bitsize (v); | |
1988 | } | |
1989 | else if (v == result && b->val_bitsize != 0) | |
1990 | { | |
1991 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1992 | lvalue whose bit parameters are saved in the fields | |
1993 | VAL_BITPOS and VAL_BITSIZE. */ | |
1994 | bitpos = b->val_bitpos; | |
1995 | bitsize = b->val_bitsize; | |
1996 | } | |
a5606eee | 1997 | |
42ae5230 | 1998 | addr = value_address (v); |
bb9d5f81 PP |
1999 | if (bitsize != 0) |
2000 | { | |
2001 | /* Skip the bytes that don't contain the bitfield. */ | |
2002 | addr += bitpos / 8; | |
2003 | } | |
2004 | ||
a5606eee | 2005 | type = hw_write; |
3a5c3e22 | 2006 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 2007 | type = hw_read; |
3a5c3e22 | 2008 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 2009 | type = hw_access; |
3a5c3e22 PA |
2010 | |
2011 | loc = allocate_bp_location (&b->base); | |
2012 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2013 | ; |
2014 | *tmp = loc; | |
a6d9a66e | 2015 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2016 | |
2017 | loc->pspace = frame_pspace; | |
a5606eee | 2018 | loc->address = addr; |
bb9d5f81 PP |
2019 | |
2020 | if (bitsize != 0) | |
2021 | { | |
2022 | /* Just cover the bytes that make up the bitfield. */ | |
2023 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2024 | } | |
2025 | else | |
2026 | loc->length = TYPE_LENGTH (value_type (v)); | |
2027 | ||
a5606eee VP |
2028 | loc->watchpoint_type = type; |
2029 | } | |
2030 | } | |
9fa40276 TJB |
2031 | } |
2032 | ||
2033 | /* Change the type of breakpoint between hardware assisted or | |
2034 | an ordinary watchpoint depending on the hardware support | |
2035 | and free hardware slots. REPARSE is set when the inferior | |
2036 | is started. */ | |
a9634178 | 2037 | if (reparse) |
9fa40276 | 2038 | { |
e09342b5 | 2039 | int reg_cnt; |
9fa40276 TJB |
2040 | enum bp_loc_type loc_type; |
2041 | struct bp_location *bl; | |
a5606eee | 2042 | |
a9634178 | 2043 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2044 | |
2045 | if (reg_cnt) | |
9fa40276 TJB |
2046 | { |
2047 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2048 | enum bptype type; |
9fa40276 | 2049 | |
a9634178 TJB |
2050 | /* Use an exact watchpoint when there's only one memory region to be |
2051 | watched, and only one debug register is needed to watch it. */ | |
2052 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2053 | ||
9fa40276 | 2054 | /* We need to determine how many resources are already |
e09342b5 TJB |
2055 | used for all other hardware watchpoints plus this one |
2056 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2057 | this watchpoint in as well. */ |
2058 | ||
2059 | /* If this is a software watchpoint, we try to turn it | |
2060 | to a hardware one -- count resources as if B was of | |
2061 | hardware watchpoint type. */ | |
2062 | type = b->base.type; | |
2063 | if (type == bp_watchpoint) | |
2064 | type = bp_hardware_watchpoint; | |
2065 | ||
2066 | /* This watchpoint may or may not have been placed on | |
2067 | the list yet at this point (it won't be in the list | |
2068 | if we're trying to create it for the first time, | |
2069 | through watch_command), so always account for it | |
2070 | manually. */ | |
2071 | ||
2072 | /* Count resources used by all watchpoints except B. */ | |
2073 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
2074 | ||
2075 | /* Add in the resources needed for B. */ | |
2076 | i += hw_watchpoint_use_count (&b->base); | |
2077 | ||
2078 | target_resources_ok | |
2079 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2080 | if (target_resources_ok <= 0) |
a9634178 | 2081 | { |
3a5c3e22 | 2082 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
2083 | |
2084 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2085 | error (_("Target does not support this type of " |
2086 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2087 | else if (target_resources_ok < 0 && !sw_mode) |
2088 | error (_("There are not enough available hardware " | |
2089 | "resources for this watchpoint.")); | |
a1398e0c PA |
2090 | |
2091 | /* Downgrade to software watchpoint. */ | |
2092 | b->base.type = bp_watchpoint; | |
2093 | } | |
2094 | else | |
2095 | { | |
2096 | /* If this was a software watchpoint, we've just | |
2097 | found we have enough resources to turn it to a | |
2098 | hardware watchpoint. Otherwise, this is a | |
2099 | nop. */ | |
2100 | b->base.type = type; | |
a9634178 | 2101 | } |
9fa40276 | 2102 | } |
3a5c3e22 | 2103 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2104 | { |
2105 | if (!can_use_hw_watchpoints) | |
2106 | error (_("Can't set read/access watchpoint when " | |
2107 | "hardware watchpoints are disabled.")); | |
2108 | else | |
2109 | error (_("Expression cannot be implemented with " | |
2110 | "read/access watchpoint.")); | |
2111 | } | |
9fa40276 | 2112 | else |
3a5c3e22 | 2113 | b->base.type = bp_watchpoint; |
9fa40276 | 2114 | |
3a5c3e22 | 2115 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2116 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2117 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2118 | bl->loc_type = loc_type; |
2119 | } | |
2120 | ||
2121 | for (v = val_chain; v; v = next) | |
2122 | { | |
a5606eee VP |
2123 | next = value_next (v); |
2124 | if (v != b->val) | |
2125 | value_free (v); | |
2126 | } | |
2127 | ||
c7437ca6 PA |
2128 | /* If a software watchpoint is not watching any memory, then the |
2129 | above left it without any location set up. But, | |
2130 | bpstat_stop_status requires a location to be able to report | |
2131 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2132 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 2133 | { |
3a5c3e22 PA |
2134 | struct breakpoint *base = &b->base; |
2135 | base->loc = allocate_bp_location (base); | |
2136 | base->loc->pspace = frame_pspace; | |
2137 | base->loc->address = -1; | |
2138 | base->loc->length = -1; | |
2139 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 2140 | } |
a5606eee VP |
2141 | } |
2142 | else if (!within_current_scope) | |
7270d8f2 | 2143 | { |
ac74f770 MS |
2144 | printf_filtered (_("\ |
2145 | Watchpoint %d deleted because the program has left the block\n\ | |
2146 | in which its expression is valid.\n"), | |
3a5c3e22 | 2147 | b->base.number); |
d0fb5eae | 2148 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2149 | } |
a5606eee VP |
2150 | |
2151 | /* Restore the selected frame. */ | |
66076460 DJ |
2152 | if (frame_saved) |
2153 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2154 | } |
2155 | ||
a5606eee | 2156 | |
74960c60 | 2157 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2158 | inserted in the inferior. We don't differentiate the type of BL's owner |
2159 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2160 | breakpoint_ops is not defined, because in insert_bp_location, | |
2161 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2162 | static int |
35df4500 | 2163 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2164 | { |
35df4500 | 2165 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2166 | return 0; |
2167 | ||
35df4500 | 2168 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2169 | return 0; |
2170 | ||
35df4500 | 2171 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2172 | return 0; |
2173 | ||
f8eba3c6 TT |
2174 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2175 | return 0; | |
2176 | ||
56710373 PA |
2177 | /* This is set for example, when we're attached to the parent of a |
2178 | vfork, and have detached from the child. The child is running | |
2179 | free, and we expect it to do an exec or exit, at which point the | |
2180 | OS makes the parent schedulable again (and the target reports | |
2181 | that the vfork is done). Until the child is done with the shared | |
2182 | memory region, do not insert breakpoints in the parent, otherwise | |
2183 | the child could still trip on the parent's breakpoints. Since | |
2184 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2185 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2186 | return 0; |
2187 | ||
31e77af2 PA |
2188 | /* Don't insert a breakpoint if we're trying to step past its |
2189 | location. */ | |
2190 | if ((bl->loc_type == bp_loc_software_breakpoint | |
2191 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2192 | && stepping_past_instruction_at (bl->pspace->aspace, | |
2193 | bl->address)) | |
e558d7c1 PA |
2194 | { |
2195 | if (debug_infrun) | |
2196 | { | |
2197 | fprintf_unfiltered (gdb_stdlog, | |
2198 | "infrun: skipping breakpoint: " | |
2199 | "stepping past insn at: %s\n", | |
2200 | paddress (bl->gdbarch, bl->address)); | |
2201 | } | |
2202 | return 0; | |
2203 | } | |
31e77af2 | 2204 | |
963f9c80 PA |
2205 | /* Don't insert watchpoints if we're trying to step past the |
2206 | instruction that triggered one. */ | |
2207 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2208 | && stepping_past_nonsteppable_watchpoint ()) | |
2209 | { | |
2210 | if (debug_infrun) | |
2211 | { | |
2212 | fprintf_unfiltered (gdb_stdlog, | |
2213 | "infrun: stepping past non-steppable watchpoint. " | |
2214 | "skipping watchpoint at %s:%d\n", | |
2215 | paddress (bl->gdbarch, bl->address), | |
2216 | bl->length); | |
2217 | } | |
2218 | return 0; | |
2219 | } | |
2220 | ||
74960c60 VP |
2221 | return 1; |
2222 | } | |
2223 | ||
934709f0 PW |
2224 | /* Same as should_be_inserted but does the check assuming |
2225 | that the location is not duplicated. */ | |
2226 | ||
2227 | static int | |
2228 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2229 | { | |
2230 | int result; | |
2231 | const int save_duplicate = bl->duplicate; | |
2232 | ||
2233 | bl->duplicate = 0; | |
2234 | result = should_be_inserted (bl); | |
2235 | bl->duplicate = save_duplicate; | |
2236 | return result; | |
2237 | } | |
2238 | ||
b775012e LM |
2239 | /* Parses a conditional described by an expression COND into an |
2240 | agent expression bytecode suitable for evaluation | |
2241 | by the bytecode interpreter. Return NULL if there was | |
2242 | any error during parsing. */ | |
2243 | ||
2244 | static struct agent_expr * | |
2245 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2246 | { | |
2247 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2248 | |
2249 | if (!cond) | |
2250 | return NULL; | |
2251 | ||
2252 | /* We don't want to stop processing, so catch any errors | |
2253 | that may show up. */ | |
492d29ea | 2254 | TRY |
b775012e LM |
2255 | { |
2256 | aexpr = gen_eval_for_expr (scope, cond); | |
2257 | } | |
2258 | ||
492d29ea | 2259 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2260 | { |
2261 | /* If we got here, it means the condition could not be parsed to a valid | |
2262 | bytecode expression and thus can't be evaluated on the target's side. | |
2263 | It's no use iterating through the conditions. */ | |
2264 | return NULL; | |
2265 | } | |
492d29ea | 2266 | END_CATCH |
b775012e LM |
2267 | |
2268 | /* We have a valid agent expression. */ | |
2269 | return aexpr; | |
2270 | } | |
2271 | ||
2272 | /* Based on location BL, create a list of breakpoint conditions to be | |
2273 | passed on to the target. If we have duplicated locations with different | |
2274 | conditions, we will add such conditions to the list. The idea is that the | |
2275 | target will evaluate the list of conditions and will only notify GDB when | |
2276 | one of them is true. */ | |
2277 | ||
2278 | static void | |
2279 | build_target_condition_list (struct bp_location *bl) | |
2280 | { | |
2281 | struct bp_location **locp = NULL, **loc2p; | |
2282 | int null_condition_or_parse_error = 0; | |
2283 | int modified = bl->needs_update; | |
2284 | struct bp_location *loc; | |
2285 | ||
8b4f3082 PA |
2286 | /* Release conditions left over from a previous insert. */ |
2287 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2288 | ||
b775012e LM |
2289 | /* This is only meaningful if the target is |
2290 | evaluating conditions and if the user has | |
2291 | opted for condition evaluation on the target's | |
2292 | side. */ | |
2293 | if (gdb_evaluates_breakpoint_condition_p () | |
2294 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2295 | return; | |
2296 | ||
2297 | /* Do a first pass to check for locations with no assigned | |
2298 | conditions or conditions that fail to parse to a valid agent expression | |
2299 | bytecode. If any of these happen, then it's no use to send conditions | |
2300 | to the target since this location will always trigger and generate a | |
2301 | response back to GDB. */ | |
2302 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2303 | { | |
2304 | loc = (*loc2p); | |
2305 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2306 | { | |
2307 | if (modified) | |
2308 | { | |
2309 | struct agent_expr *aexpr; | |
2310 | ||
2311 | /* Re-parse the conditions since something changed. In that | |
2312 | case we already freed the condition bytecodes (see | |
2313 | force_breakpoint_reinsertion). We just | |
2314 | need to parse the condition to bytecodes again. */ | |
2315 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2316 | loc->cond_bytecode = aexpr; | |
2317 | ||
2318 | /* Check if we managed to parse the conditional expression | |
2319 | correctly. If not, we will not send this condition | |
2320 | to the target. */ | |
2321 | if (aexpr) | |
2322 | continue; | |
2323 | } | |
2324 | ||
2325 | /* If we have a NULL bytecode expression, it means something | |
2326 | went wrong or we have a null condition expression. */ | |
2327 | if (!loc->cond_bytecode) | |
2328 | { | |
2329 | null_condition_or_parse_error = 1; | |
2330 | break; | |
2331 | } | |
2332 | } | |
2333 | } | |
2334 | ||
2335 | /* If any of these happened, it means we will have to evaluate the conditions | |
2336 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2337 | for all the other duplicate locations, thus we free all of them here. | |
2338 | ||
2339 | This is so we have a finer control over which locations' conditions are | |
2340 | being evaluated by GDB or the remote stub. */ | |
2341 | if (null_condition_or_parse_error) | |
2342 | { | |
2343 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2344 | { | |
2345 | loc = (*loc2p); | |
2346 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2347 | { | |
2348 | /* Only go as far as the first NULL bytecode is | |
2349 | located. */ | |
2350 | if (!loc->cond_bytecode) | |
2351 | return; | |
2352 | ||
2353 | free_agent_expr (loc->cond_bytecode); | |
2354 | loc->cond_bytecode = NULL; | |
2355 | } | |
2356 | } | |
2357 | } | |
2358 | ||
2359 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2360 | for this location's address. */ | |
2361 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2362 | { | |
2363 | loc = (*loc2p); | |
2364 | if (loc->cond | |
2365 | && is_breakpoint (loc->owner) | |
2366 | && loc->pspace->num == bl->pspace->num | |
2367 | && loc->owner->enable_state == bp_enabled | |
2368 | && loc->enabled) | |
2369 | /* Add the condition to the vector. This will be used later to send the | |
2370 | conditions to the target. */ | |
2371 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2372 | loc->cond_bytecode); | |
2373 | } | |
2374 | ||
2375 | return; | |
2376 | } | |
2377 | ||
d3ce09f5 SS |
2378 | /* Parses a command described by string CMD into an agent expression |
2379 | bytecode suitable for evaluation by the bytecode interpreter. | |
2380 | Return NULL if there was any error during parsing. */ | |
2381 | ||
2382 | static struct agent_expr * | |
2383 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2384 | { | |
2385 | struct cleanup *old_cleanups = 0; | |
2386 | struct expression *expr, **argvec; | |
2387 | struct agent_expr *aexpr = NULL; | |
bbc13ae3 KS |
2388 | const char *cmdrest; |
2389 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2390 | struct format_piece *fpieces; |
2391 | int nargs; | |
2392 | struct gdbarch *gdbarch = get_current_arch (); | |
2393 | ||
2394 | if (!cmd) | |
2395 | return NULL; | |
2396 | ||
2397 | cmdrest = cmd; | |
2398 | ||
2399 | if (*cmdrest == ',') | |
2400 | ++cmdrest; | |
bbc13ae3 | 2401 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2402 | |
2403 | if (*cmdrest++ != '"') | |
2404 | error (_("No format string following the location")); | |
2405 | ||
2406 | format_start = cmdrest; | |
2407 | ||
2408 | fpieces = parse_format_string (&cmdrest); | |
2409 | ||
2410 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2411 | ||
2412 | format_end = cmdrest; | |
2413 | ||
2414 | if (*cmdrest++ != '"') | |
2415 | error (_("Bad format string, non-terminated '\"'.")); | |
2416 | ||
bbc13ae3 | 2417 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2418 | |
2419 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2420 | error (_("Invalid argument syntax")); | |
2421 | ||
2422 | if (*cmdrest == ',') | |
2423 | cmdrest++; | |
bbc13ae3 | 2424 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2425 | |
2426 | /* For each argument, make an expression. */ | |
2427 | ||
2428 | argvec = (struct expression **) alloca (strlen (cmd) | |
2429 | * sizeof (struct expression *)); | |
2430 | ||
2431 | nargs = 0; | |
2432 | while (*cmdrest != '\0') | |
2433 | { | |
bbc13ae3 | 2434 | const char *cmd1; |
d3ce09f5 SS |
2435 | |
2436 | cmd1 = cmdrest; | |
2437 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2438 | argvec[nargs++] = expr; | |
2439 | cmdrest = cmd1; | |
2440 | if (*cmdrest == ',') | |
2441 | ++cmdrest; | |
2442 | } | |
2443 | ||
2444 | /* We don't want to stop processing, so catch any errors | |
2445 | that may show up. */ | |
492d29ea | 2446 | TRY |
d3ce09f5 SS |
2447 | { |
2448 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2449 | format_start, format_end - format_start, | |
2450 | fpieces, nargs, argvec); | |
2451 | } | |
492d29ea | 2452 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2453 | { |
2454 | /* If we got here, it means the command could not be parsed to a valid | |
2455 | bytecode expression and thus can't be evaluated on the target's side. | |
2456 | It's no use iterating through the other commands. */ | |
492d29ea | 2457 | aexpr = NULL; |
d3ce09f5 | 2458 | } |
492d29ea PA |
2459 | END_CATCH |
2460 | ||
2461 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2462 | |
d3ce09f5 SS |
2463 | /* We have a valid agent expression, return it. */ |
2464 | return aexpr; | |
2465 | } | |
2466 | ||
2467 | /* Based on location BL, create a list of breakpoint commands to be | |
2468 | passed on to the target. If we have duplicated locations with | |
2469 | different commands, we will add any such to the list. */ | |
2470 | ||
2471 | static void | |
2472 | build_target_command_list (struct bp_location *bl) | |
2473 | { | |
2474 | struct bp_location **locp = NULL, **loc2p; | |
2475 | int null_command_or_parse_error = 0; | |
2476 | int modified = bl->needs_update; | |
2477 | struct bp_location *loc; | |
2478 | ||
8b4f3082 PA |
2479 | /* Release commands left over from a previous insert. */ |
2480 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2481 | ||
41fac0cf | 2482 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2483 | return; |
2484 | ||
41fac0cf PA |
2485 | /* For now, limit to agent-style dprintf breakpoints. */ |
2486 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2487 | return; |
2488 | ||
41fac0cf PA |
2489 | /* For now, if we have any duplicate location that isn't a dprintf, |
2490 | don't install the target-side commands, as that would make the | |
2491 | breakpoint not be reported to the core, and we'd lose | |
2492 | control. */ | |
2493 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2494 | { | |
2495 | loc = (*loc2p); | |
2496 | if (is_breakpoint (loc->owner) | |
2497 | && loc->pspace->num == bl->pspace->num | |
2498 | && loc->owner->type != bp_dprintf) | |
2499 | return; | |
2500 | } | |
2501 | ||
d3ce09f5 SS |
2502 | /* Do a first pass to check for locations with no assigned |
2503 | conditions or conditions that fail to parse to a valid agent expression | |
2504 | bytecode. If any of these happen, then it's no use to send conditions | |
2505 | to the target since this location will always trigger and generate a | |
2506 | response back to GDB. */ | |
2507 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2508 | { | |
2509 | loc = (*loc2p); | |
2510 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2511 | { | |
2512 | if (modified) | |
2513 | { | |
2514 | struct agent_expr *aexpr; | |
2515 | ||
2516 | /* Re-parse the commands since something changed. In that | |
2517 | case we already freed the command bytecodes (see | |
2518 | force_breakpoint_reinsertion). We just | |
2519 | need to parse the command to bytecodes again. */ | |
2520 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2521 | loc->owner->extra_string); | |
2522 | loc->cmd_bytecode = aexpr; | |
2523 | ||
2524 | if (!aexpr) | |
2525 | continue; | |
2526 | } | |
2527 | ||
2528 | /* If we have a NULL bytecode expression, it means something | |
2529 | went wrong or we have a null command expression. */ | |
2530 | if (!loc->cmd_bytecode) | |
2531 | { | |
2532 | null_command_or_parse_error = 1; | |
2533 | break; | |
2534 | } | |
2535 | } | |
2536 | } | |
2537 | ||
2538 | /* If anything failed, then we're not doing target-side commands, | |
2539 | and so clean up. */ | |
2540 | if (null_command_or_parse_error) | |
2541 | { | |
2542 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2543 | { | |
2544 | loc = (*loc2p); | |
2545 | if (is_breakpoint (loc->owner) | |
2546 | && loc->pspace->num == bl->pspace->num) | |
2547 | { | |
2548 | /* Only go as far as the first NULL bytecode is | |
2549 | located. */ | |
40fb6c5e | 2550 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2551 | return; |
2552 | ||
40fb6c5e HZ |
2553 | free_agent_expr (loc->cmd_bytecode); |
2554 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2555 | } |
2556 | } | |
2557 | } | |
2558 | ||
2559 | /* No NULL commands or failed bytecode generation. Build a command list | |
2560 | for this location's address. */ | |
2561 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2562 | { | |
2563 | loc = (*loc2p); | |
2564 | if (loc->owner->extra_string | |
2565 | && is_breakpoint (loc->owner) | |
2566 | && loc->pspace->num == bl->pspace->num | |
2567 | && loc->owner->enable_state == bp_enabled | |
2568 | && loc->enabled) | |
2569 | /* Add the command to the vector. This will be used later | |
2570 | to send the commands to the target. */ | |
2571 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2572 | loc->cmd_bytecode); | |
2573 | } | |
2574 | ||
2575 | bl->target_info.persist = 0; | |
2576 | /* Maybe flag this location as persistent. */ | |
2577 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2578 | bl->target_info.persist = 1; | |
2579 | } | |
2580 | ||
35df4500 TJB |
2581 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2582 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2583 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2584 | Returns 0 for success, 1 if the bp_location type is not supported or |
2585 | -1 for failure. | |
879bfdc2 | 2586 | |
4a64f543 MS |
2587 | NOTE drow/2003-09-09: This routine could be broken down to an |
2588 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2589 | static int |
35df4500 | 2590 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2591 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2592 | int *disabled_breaks, |
dd61ec5c MW |
2593 | int *hw_breakpoint_error, |
2594 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2595 | { |
0000e5cc PA |
2596 | enum errors bp_err = GDB_NO_ERROR; |
2597 | const char *bp_err_message = NULL; | |
879bfdc2 | 2598 | |
b775012e | 2599 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2600 | return 0; |
2601 | ||
35c63cd8 JB |
2602 | /* Note we don't initialize bl->target_info, as that wipes out |
2603 | the breakpoint location's shadow_contents if the breakpoint | |
2604 | is still inserted at that location. This in turn breaks | |
2605 | target_read_memory which depends on these buffers when | |
2606 | a memory read is requested at the breakpoint location: | |
2607 | Once the target_info has been wiped, we fail to see that | |
2608 | we have a breakpoint inserted at that address and thus | |
2609 | read the breakpoint instead of returning the data saved in | |
2610 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2611 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2612 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2613 | bl->target_info.length = bl->length; |
8181d85f | 2614 | |
b775012e LM |
2615 | /* When working with target-side conditions, we must pass all the conditions |
2616 | for the same breakpoint address down to the target since GDB will not | |
2617 | insert those locations. With a list of breakpoint conditions, the target | |
2618 | can decide when to stop and notify GDB. */ | |
2619 | ||
2620 | if (is_breakpoint (bl->owner)) | |
2621 | { | |
2622 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2623 | build_target_command_list (bl); |
2624 | /* Reset the modification marker. */ | |
b775012e LM |
2625 | bl->needs_update = 0; |
2626 | } | |
2627 | ||
35df4500 TJB |
2628 | if (bl->loc_type == bp_loc_software_breakpoint |
2629 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2630 | { |
35df4500 | 2631 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2632 | { |
2633 | /* If the explicitly specified breakpoint type | |
2634 | is not hardware breakpoint, check the memory map to see | |
2635 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2636 | |
765dc015 VP |
2637 | Two important cases are: |
2638 | - location type is not hardware breakpoint, memory | |
2639 | is readonly. We change the type of the location to | |
2640 | hardware breakpoint. | |
4a64f543 MS |
2641 | - location type is hardware breakpoint, memory is |
2642 | read-write. This means we've previously made the | |
2643 | location hardware one, but then the memory map changed, | |
2644 | so we undo. | |
765dc015 | 2645 | |
4a64f543 MS |
2646 | When breakpoints are removed, remove_breakpoints will use |
2647 | location types we've just set here, the only possible | |
2648 | problem is that memory map has changed during running | |
2649 | program, but it's not going to work anyway with current | |
2650 | gdb. */ | |
765dc015 | 2651 | struct mem_region *mr |
0d5ed153 | 2652 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2653 | |
2654 | if (mr) | |
2655 | { | |
2656 | if (automatic_hardware_breakpoints) | |
2657 | { | |
765dc015 VP |
2658 | enum bp_loc_type new_type; |
2659 | ||
2660 | if (mr->attrib.mode != MEM_RW) | |
2661 | new_type = bp_loc_hardware_breakpoint; | |
2662 | else | |
2663 | new_type = bp_loc_software_breakpoint; | |
2664 | ||
35df4500 | 2665 | if (new_type != bl->loc_type) |
765dc015 VP |
2666 | { |
2667 | static int said = 0; | |
cc59ec59 | 2668 | |
35df4500 | 2669 | bl->loc_type = new_type; |
765dc015 VP |
2670 | if (!said) |
2671 | { | |
3e43a32a MS |
2672 | fprintf_filtered (gdb_stdout, |
2673 | _("Note: automatically using " | |
2674 | "hardware breakpoints for " | |
2675 | "read-only addresses.\n")); | |
765dc015 VP |
2676 | said = 1; |
2677 | } | |
2678 | } | |
2679 | } | |
35df4500 | 2680 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2681 | && mr->attrib.mode != MEM_RW) |
2682 | { | |
2683 | fprintf_unfiltered (tmp_error_stream, | |
2684 | _("Cannot insert breakpoint %d.\n" | |
2685 | "Cannot set software breakpoint " | |
2686 | "at read-only address %s\n"), | |
2687 | bl->owner->number, | |
2688 | paddress (bl->gdbarch, bl->address)); | |
2689 | return 1; | |
2690 | } | |
765dc015 VP |
2691 | } |
2692 | } | |
2693 | ||
879bfdc2 DJ |
2694 | /* First check to see if we have to handle an overlay. */ |
2695 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2696 | || bl->section == NULL |
2697 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2698 | { |
2699 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2700 | TRY |
dd61ec5c | 2701 | { |
0000e5cc PA |
2702 | int val; |
2703 | ||
dd61ec5c | 2704 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2705 | if (val) |
2706 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2707 | } |
492d29ea | 2708 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2709 | { |
0000e5cc PA |
2710 | bp_err = e.error; |
2711 | bp_err_message = e.message; | |
dd61ec5c | 2712 | } |
492d29ea | 2713 | END_CATCH |
879bfdc2 DJ |
2714 | } |
2715 | else | |
2716 | { | |
4a64f543 | 2717 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2718 | Shall we set a breakpoint at the LMA? */ |
2719 | if (!overlay_events_enabled) | |
2720 | { | |
2721 | /* Yes -- overlay event support is not active, | |
2722 | so we must try to set a breakpoint at the LMA. | |
2723 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2724 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2725 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2726 | bl->owner->number); |
879bfdc2 DJ |
2727 | else |
2728 | { | |
35df4500 TJB |
2729 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2730 | bl->section); | |
879bfdc2 | 2731 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2732 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2733 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2734 | |
2735 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2736 | TRY |
0000e5cc PA |
2737 | { |
2738 | int val; | |
2739 | ||
2740 | val = target_insert_breakpoint (bl->gdbarch, | |
2741 | &bl->overlay_target_info); | |
2742 | if (val) | |
2743 | bp_err = GENERIC_ERROR; | |
2744 | } | |
492d29ea | 2745 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2746 | { |
2747 | bp_err = e.error; | |
2748 | bp_err_message = e.message; | |
2749 | } | |
492d29ea | 2750 | END_CATCH |
0000e5cc PA |
2751 | |
2752 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2753 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2754 | "Overlay breakpoint %d " |
2755 | "failed: in ROM?\n", | |
35df4500 | 2756 | bl->owner->number); |
879bfdc2 DJ |
2757 | } |
2758 | } | |
2759 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2760 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2761 | { |
2762 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2763 | TRY |
dd61ec5c | 2764 | { |
0000e5cc PA |
2765 | int val; |
2766 | ||
dd61ec5c | 2767 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2768 | if (val) |
2769 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2770 | } |
492d29ea | 2771 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2772 | { |
0000e5cc PA |
2773 | bp_err = e.error; |
2774 | bp_err_message = e.message; | |
dd61ec5c | 2775 | } |
492d29ea | 2776 | END_CATCH |
879bfdc2 DJ |
2777 | } |
2778 | else | |
2779 | { | |
2780 | /* No. This breakpoint will not be inserted. | |
2781 | No error, but do not mark the bp as 'inserted'. */ | |
2782 | return 0; | |
2783 | } | |
2784 | } | |
2785 | ||
0000e5cc | 2786 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2787 | { |
2788 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2789 | |
2790 | /* In some cases, we might not be able to insert a | |
2791 | breakpoint in a shared library that has already been | |
2792 | removed, but we have not yet processed the shlib unload | |
2793 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2794 | breakpoint insertion themselves can't tell why the |
2795 | breakpoint insertion failed (e.g., the remote target | |
2796 | doesn't define error codes), so we must treat generic | |
2797 | errors as memory errors. */ | |
0000e5cc | 2798 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2799 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2800 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2801 | || shared_objfile_contains_address_p (bl->pspace, |
2802 | bl->address))) | |
879bfdc2 | 2803 | { |
4a64f543 | 2804 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2805 | bl->shlib_disabled = 1; |
8d3788bd | 2806 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2807 | if (!*disabled_breaks) |
2808 | { | |
2809 | fprintf_unfiltered (tmp_error_stream, | |
2810 | "Cannot insert breakpoint %d.\n", | |
2811 | bl->owner->number); | |
2812 | fprintf_unfiltered (tmp_error_stream, | |
2813 | "Temporarily disabling shared " | |
2814 | "library breakpoints:\n"); | |
2815 | } | |
2816 | *disabled_breaks = 1; | |
879bfdc2 | 2817 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2818 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2819 | return 0; |
879bfdc2 DJ |
2820 | } |
2821 | else | |
879bfdc2 | 2822 | { |
35df4500 | 2823 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2824 | { |
0000e5cc PA |
2825 | *hw_breakpoint_error = 1; |
2826 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2827 | fprintf_unfiltered (tmp_error_stream, |
2828 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2829 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2830 | if (bp_err_message != NULL) | |
2831 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2832 | } |
2833 | else | |
2834 | { | |
0000e5cc PA |
2835 | if (bp_err_message == NULL) |
2836 | { | |
2837 | char *message | |
2838 | = memory_error_message (TARGET_XFER_E_IO, | |
2839 | bl->gdbarch, bl->address); | |
2840 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2841 | ||
2842 | fprintf_unfiltered (tmp_error_stream, | |
2843 | "Cannot insert breakpoint %d.\n" | |
2844 | "%s\n", | |
2845 | bl->owner->number, message); | |
2846 | do_cleanups (old_chain); | |
2847 | } | |
2848 | else | |
2849 | { | |
2850 | fprintf_unfiltered (tmp_error_stream, | |
2851 | "Cannot insert breakpoint %d: %s\n", | |
2852 | bl->owner->number, | |
2853 | bp_err_message); | |
2854 | } | |
879bfdc2 | 2855 | } |
0000e5cc | 2856 | return 1; |
879bfdc2 DJ |
2857 | |
2858 | } | |
2859 | } | |
2860 | else | |
35df4500 | 2861 | bl->inserted = 1; |
879bfdc2 | 2862 | |
0000e5cc | 2863 | return 0; |
879bfdc2 DJ |
2864 | } |
2865 | ||
35df4500 | 2866 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2867 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2868 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2869 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2870 | { |
0000e5cc PA |
2871 | int val; |
2872 | ||
77b06cd7 TJB |
2873 | gdb_assert (bl->owner->ops != NULL |
2874 | && bl->owner->ops->insert_location != NULL); | |
2875 | ||
2876 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2877 | |
2878 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2879 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2880 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2881 | { |
2882 | struct bp_location *loc, **loc_temp; | |
2883 | ||
2884 | /* But don't try to insert it, if there's already another | |
2885 | hw_access location that would be considered a duplicate | |
2886 | of this one. */ | |
2887 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2888 | if (loc != bl |
85d721b8 | 2889 | && loc->watchpoint_type == hw_access |
35df4500 | 2890 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2891 | { |
35df4500 TJB |
2892 | bl->duplicate = 1; |
2893 | bl->inserted = 1; | |
2894 | bl->target_info = loc->target_info; | |
2895 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2896 | val = 0; |
2897 | break; | |
2898 | } | |
2899 | ||
2900 | if (val == 1) | |
2901 | { | |
77b06cd7 TJB |
2902 | bl->watchpoint_type = hw_access; |
2903 | val = bl->owner->ops->insert_location (bl); | |
2904 | ||
2905 | if (val) | |
2906 | /* Back to the original value. */ | |
2907 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2908 | } |
2909 | } | |
2910 | ||
35df4500 | 2911 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2912 | } |
2913 | ||
35df4500 | 2914 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2915 | { |
0000e5cc PA |
2916 | int val; |
2917 | ||
77b06cd7 TJB |
2918 | gdb_assert (bl->owner->ops != NULL |
2919 | && bl->owner->ops->insert_location != NULL); | |
2920 | ||
2921 | val = bl->owner->ops->insert_location (bl); | |
2922 | if (val) | |
2923 | { | |
2924 | bl->owner->enable_state = bp_disabled; | |
2925 | ||
2926 | if (val == 1) | |
2927 | warning (_("\ | |
2928 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2929 | of catchpoint."), bl->owner->number); | |
2930 | else | |
2931 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2932 | } | |
2933 | ||
2934 | bl->inserted = (val == 0); | |
1640b821 DJ |
2935 | |
2936 | /* We've already printed an error message if there was a problem | |
2937 | inserting this catchpoint, and we've disabled the catchpoint, | |
2938 | so just return success. */ | |
2939 | return 0; | |
879bfdc2 DJ |
2940 | } |
2941 | ||
2942 | return 0; | |
2943 | } | |
2944 | ||
6c95b8df PA |
2945 | /* This function is called when program space PSPACE is about to be |
2946 | deleted. It takes care of updating breakpoints to not reference | |
2947 | PSPACE anymore. */ | |
2948 | ||
2949 | void | |
2950 | breakpoint_program_space_exit (struct program_space *pspace) | |
2951 | { | |
2952 | struct breakpoint *b, *b_temp; | |
876fa593 | 2953 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2954 | |
2955 | /* Remove any breakpoint that was set through this program space. */ | |
2956 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2957 | { | |
2958 | if (b->pspace == pspace) | |
2959 | delete_breakpoint (b); | |
2960 | } | |
2961 | ||
2962 | /* Breakpoints set through other program spaces could have locations | |
2963 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2964 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2965 | { |
2966 | struct bp_location *tmp; | |
2967 | ||
2968 | if (loc->pspace == pspace) | |
2969 | { | |
2bdf28a0 | 2970 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2971 | if (loc->owner->loc == loc) |
2972 | loc->owner->loc = loc->next; | |
2973 | else | |
2974 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2975 | if (tmp->next == loc) | |
2976 | { | |
2977 | tmp->next = loc->next; | |
2978 | break; | |
2979 | } | |
2980 | } | |
2981 | } | |
2982 | ||
2983 | /* Now update the global location list to permanently delete the | |
2984 | removed locations above. */ | |
44702360 | 2985 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2986 | } |
2987 | ||
74960c60 VP |
2988 | /* Make sure all breakpoints are inserted in inferior. |
2989 | Throws exception on any error. | |
2990 | A breakpoint that is already inserted won't be inserted | |
2991 | again, so calling this function twice is safe. */ | |
2992 | void | |
2993 | insert_breakpoints (void) | |
2994 | { | |
2995 | struct breakpoint *bpt; | |
2996 | ||
2997 | ALL_BREAKPOINTS (bpt) | |
2998 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2999 | { |
3000 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3001 | ||
3002 | update_watchpoint (w, 0 /* don't reparse. */); | |
3003 | } | |
74960c60 | 3004 | |
04086b45 PA |
3005 | /* Updating watchpoints creates new locations, so update the global |
3006 | location list. Explicitly tell ugll to insert locations and | |
3007 | ignore breakpoints_always_inserted_mode. */ | |
3008 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3009 | } |
3010 | ||
20388dd6 YQ |
3011 | /* Invoke CALLBACK for each of bp_location. */ |
3012 | ||
3013 | void | |
3014 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3015 | { | |
3016 | struct bp_location *loc, **loc_tmp; | |
3017 | ||
3018 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3019 | { | |
3020 | callback (loc, NULL); | |
3021 | } | |
3022 | } | |
3023 | ||
b775012e LM |
3024 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3025 | target. It is the case with deleting and disabling of breakpoints when using | |
3026 | always-inserted mode. */ | |
3027 | ||
3028 | static void | |
3029 | update_inserted_breakpoint_locations (void) | |
3030 | { | |
3031 | struct bp_location *bl, **blp_tmp; | |
3032 | int error_flag = 0; | |
3033 | int val = 0; | |
3034 | int disabled_breaks = 0; | |
3035 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3036 | int hw_bp_details_reported = 0; |
b775012e LM |
3037 | |
3038 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
3039 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
3040 | ||
3041 | /* Explicitly mark the warning -- this will only be printed if | |
3042 | there was an error. */ | |
3043 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
3044 | ||
3045 | save_current_space_and_thread (); | |
3046 | ||
3047 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3048 | { | |
3049 | /* We only want to update software breakpoints and hardware | |
3050 | breakpoints. */ | |
3051 | if (!is_breakpoint (bl->owner)) | |
3052 | continue; | |
3053 | ||
3054 | /* We only want to update locations that are already inserted | |
3055 | and need updating. This is to avoid unwanted insertion during | |
3056 | deletion of breakpoints. */ | |
3057 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3058 | continue; | |
3059 | ||
3060 | switch_to_program_space_and_thread (bl->pspace); | |
3061 | ||
3062 | /* For targets that support global breakpoints, there's no need | |
3063 | to select an inferior to insert breakpoint to. In fact, even | |
3064 | if we aren't attached to any process yet, we should still | |
3065 | insert breakpoints. */ | |
f5656ead | 3066 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3067 | && ptid_equal (inferior_ptid, null_ptid)) |
3068 | continue; | |
3069 | ||
3070 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 3071 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3072 | if (val) |
3073 | error_flag = val; | |
3074 | } | |
3075 | ||
3076 | if (error_flag) | |
3077 | { | |
3078 | target_terminal_ours_for_output (); | |
3079 | error_stream (tmp_error_stream); | |
3080 | } | |
3081 | ||
3082 | do_cleanups (cleanups); | |
3083 | } | |
3084 | ||
c30eee59 | 3085 | /* Used when starting or continuing the program. */ |
c906108c | 3086 | |
74960c60 VP |
3087 | static void |
3088 | insert_breakpoint_locations (void) | |
c906108c | 3089 | { |
a5606eee | 3090 | struct breakpoint *bpt; |
35df4500 | 3091 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3092 | int error_flag = 0; |
c906108c | 3093 | int val = 0; |
3fbb6ffa | 3094 | int disabled_breaks = 0; |
81d0cc19 | 3095 | int hw_breakpoint_error = 0; |
dd61ec5c | 3096 | int hw_bp_error_explained_already = 0; |
c906108c | 3097 | |
81d0cc19 | 3098 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 3099 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 3100 | |
81d0cc19 GS |
3101 | /* Explicitly mark the warning -- this will only be printed if |
3102 | there was an error. */ | |
3103 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
3104 | |
3105 | save_current_space_and_thread (); | |
3106 | ||
35df4500 | 3107 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3108 | { |
b775012e | 3109 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3110 | continue; |
3111 | ||
4a64f543 MS |
3112 | /* There is no point inserting thread-specific breakpoints if |
3113 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3114 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
3115 | if (bl->owner->thread != -1 |
3116 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
3117 | continue; |
3118 | ||
35df4500 | 3119 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3120 | |
3121 | /* For targets that support global breakpoints, there's no need | |
3122 | to select an inferior to insert breakpoint to. In fact, even | |
3123 | if we aren't attached to any process yet, we should still | |
3124 | insert breakpoints. */ | |
f5656ead | 3125 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3126 | && ptid_equal (inferior_ptid, null_ptid)) |
3127 | continue; | |
3128 | ||
3fbb6ffa | 3129 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3130 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3131 | if (val) |
eacd795a | 3132 | error_flag = val; |
879bfdc2 | 3133 | } |
c906108c | 3134 | |
4a64f543 MS |
3135 | /* If we failed to insert all locations of a watchpoint, remove |
3136 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3137 | ALL_BREAKPOINTS (bpt) |
3138 | { | |
3139 | int some_failed = 0; | |
3140 | struct bp_location *loc; | |
3141 | ||
3142 | if (!is_hardware_watchpoint (bpt)) | |
3143 | continue; | |
3144 | ||
d6b74ac4 | 3145 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3146 | continue; |
74960c60 VP |
3147 | |
3148 | if (bpt->disposition == disp_del_at_next_stop) | |
3149 | continue; | |
a5606eee VP |
3150 | |
3151 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3152 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3153 | { |
3154 | some_failed = 1; | |
3155 | break; | |
3156 | } | |
3157 | if (some_failed) | |
3158 | { | |
3159 | for (loc = bpt->loc; loc; loc = loc->next) | |
3160 | if (loc->inserted) | |
3161 | remove_breakpoint (loc, mark_uninserted); | |
3162 | ||
3163 | hw_breakpoint_error = 1; | |
3164 | fprintf_unfiltered (tmp_error_stream, | |
3165 | "Could not insert hardware watchpoint %d.\n", | |
3166 | bpt->number); | |
eacd795a | 3167 | error_flag = -1; |
a5606eee VP |
3168 | } |
3169 | } | |
3170 | ||
eacd795a | 3171 | if (error_flag) |
81d0cc19 GS |
3172 | { |
3173 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3174 | message about possibly exhausted resources. */ | |
dd61ec5c | 3175 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3176 | { |
c6510018 MS |
3177 | fprintf_unfiltered (tmp_error_stream, |
3178 | "Could not insert hardware breakpoints:\n\ | |
3179 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3180 | } |
81d0cc19 GS |
3181 | target_terminal_ours_for_output (); |
3182 | error_stream (tmp_error_stream); | |
3183 | } | |
f7545552 TT |
3184 | |
3185 | do_cleanups (cleanups); | |
c906108c SS |
3186 | } |
3187 | ||
c30eee59 TJB |
3188 | /* Used when the program stops. |
3189 | Returns zero if successful, or non-zero if there was a problem | |
3190 | removing a breakpoint location. */ | |
3191 | ||
c906108c | 3192 | int |
fba45db2 | 3193 | remove_breakpoints (void) |
c906108c | 3194 | { |
35df4500 | 3195 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3196 | int val = 0; |
c906108c | 3197 | |
35df4500 | 3198 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3199 | { |
1e4d1764 | 3200 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 3201 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 3202 | } |
3a1bae8e | 3203 | return val; |
c906108c SS |
3204 | } |
3205 | ||
49fa26b0 PA |
3206 | /* When a thread exits, remove breakpoints that are related to |
3207 | that thread. */ | |
3208 | ||
3209 | static void | |
3210 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3211 | { | |
3212 | struct breakpoint *b, *b_tmp; | |
3213 | ||
3214 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3215 | { | |
96181529 | 3216 | if (b->thread == tp->num && user_breakpoint_p (b)) |
49fa26b0 PA |
3217 | { |
3218 | b->disposition = disp_del_at_next_stop; | |
3219 | ||
3220 | printf_filtered (_("\ | |
46ecd527 | 3221 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
49fa26b0 PA |
3222 | b->number, tp->num); |
3223 | ||
3224 | /* Hide it from the user. */ | |
3225 | b->number = 0; | |
3226 | } | |
3227 | } | |
3228 | } | |
3229 | ||
6c95b8df PA |
3230 | /* Remove breakpoints of process PID. */ |
3231 | ||
3232 | int | |
3233 | remove_breakpoints_pid (int pid) | |
3234 | { | |
35df4500 | 3235 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3236 | int val; |
3237 | struct inferior *inf = find_inferior_pid (pid); | |
3238 | ||
35df4500 | 3239 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3240 | { |
35df4500 | 3241 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3242 | continue; |
3243 | ||
fc126975 | 3244 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3245 | { |
35df4500 | 3246 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
3247 | if (val != 0) |
3248 | return val; | |
3249 | } | |
3250 | } | |
3251 | return 0; | |
3252 | } | |
3253 | ||
c906108c | 3254 | int |
fba45db2 | 3255 | reattach_breakpoints (int pid) |
c906108c | 3256 | { |
6c95b8df | 3257 | struct cleanup *old_chain; |
35df4500 | 3258 | struct bp_location *bl, **blp_tmp; |
c906108c | 3259 | int val; |
86b887df | 3260 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3261 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3262 | struct inferior *inf; |
3263 | struct thread_info *tp; | |
3264 | ||
3265 | tp = any_live_thread_of_process (pid); | |
3266 | if (tp == NULL) | |
3267 | return 1; | |
3268 | ||
3269 | inf = find_inferior_pid (pid); | |
3270 | old_chain = save_inferior_ptid (); | |
3271 | ||
3272 | inferior_ptid = tp->ptid; | |
a4954f26 | 3273 | |
86b887df | 3274 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3275 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3276 | |
35df4500 | 3277 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3278 | { |
35df4500 | 3279 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3280 | continue; |
3281 | ||
35df4500 | 3282 | if (bl->inserted) |
c5aa993b | 3283 | { |
35df4500 | 3284 | bl->inserted = 0; |
dd61ec5c | 3285 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3286 | if (val != 0) |
3287 | { | |
ce696e05 | 3288 | do_cleanups (old_chain); |
c5aa993b JM |
3289 | return val; |
3290 | } | |
3291 | } | |
3292 | } | |
ce696e05 | 3293 | do_cleanups (old_chain); |
c906108c SS |
3294 | return 0; |
3295 | } | |
3296 | ||
e58b0e63 PA |
3297 | static int internal_breakpoint_number = -1; |
3298 | ||
84f4c1fe PM |
3299 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3300 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3301 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3302 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3303 | breakpoint_count and that value incremented. Internal breakpoints |
3304 | do not set the internal var bpnum. */ | |
3305 | static void | |
3306 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3307 | { | |
3308 | if (internal) | |
3309 | b->number = internal_breakpoint_number--; | |
3310 | else | |
3311 | { | |
3312 | set_breakpoint_count (breakpoint_count + 1); | |
3313 | b->number = breakpoint_count; | |
3314 | } | |
3315 | } | |
3316 | ||
e62c965a | 3317 | static struct breakpoint * |
a6d9a66e | 3318 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3319 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3320 | const struct breakpoint_ops *ops) |
e62c965a | 3321 | { |
e62c965a PP |
3322 | struct symtab_and_line sal; |
3323 | struct breakpoint *b; | |
3324 | ||
4a64f543 | 3325 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3326 | |
3327 | sal.pc = address; | |
3328 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3329 | sal.pspace = current_program_space; |
e62c965a | 3330 | |
06edf0c0 | 3331 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3332 | b->number = internal_breakpoint_number--; |
3333 | b->disposition = disp_donttouch; | |
3334 | ||
3335 | return b; | |
3336 | } | |
3337 | ||
17450429 PP |
3338 | static const char *const longjmp_names[] = |
3339 | { | |
3340 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3341 | }; | |
3342 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3343 | ||
3344 | /* Per-objfile data private to breakpoint.c. */ | |
3345 | struct breakpoint_objfile_data | |
3346 | { | |
3347 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3348 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3349 | |
3350 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3351 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3352 | |
28106bc2 SDJ |
3353 | /* True if we have looked for longjmp probes. */ |
3354 | int longjmp_searched; | |
3355 | ||
3356 | /* SystemTap probe points for longjmp (if any). */ | |
3357 | VEC (probe_p) *longjmp_probes; | |
3358 | ||
17450429 | 3359 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3360 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3361 | |
3362 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3363 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3364 | |
3365 | /* True if we have looked for exception probes. */ | |
3366 | int exception_searched; | |
3367 | ||
3368 | /* SystemTap probe points for unwinding (if any). */ | |
3369 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3370 | }; |
3371 | ||
3372 | static const struct objfile_data *breakpoint_objfile_key; | |
3373 | ||
3374 | /* Minimal symbol not found sentinel. */ | |
3375 | static struct minimal_symbol msym_not_found; | |
3376 | ||
3377 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3378 | ||
3379 | static int | |
3380 | msym_not_found_p (const struct minimal_symbol *msym) | |
3381 | { | |
3382 | return msym == &msym_not_found; | |
3383 | } | |
3384 | ||
3385 | /* Return per-objfile data needed by breakpoint.c. | |
3386 | Allocate the data if necessary. */ | |
3387 | ||
3388 | static struct breakpoint_objfile_data * | |
3389 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3390 | { | |
3391 | struct breakpoint_objfile_data *bp_objfile_data; | |
3392 | ||
3393 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
3394 | if (bp_objfile_data == NULL) | |
3395 | { | |
3396 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
3397 | sizeof (*bp_objfile_data)); | |
3398 | ||
3399 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3400 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3401 | } | |
3402 | return bp_objfile_data; | |
3403 | } | |
3404 | ||
28106bc2 SDJ |
3405 | static void |
3406 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3407 | { | |
3408 | struct breakpoint_objfile_data *bp_objfile_data = data; | |
3409 | ||
3410 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3411 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3412 | } | |
3413 | ||
e62c965a | 3414 | static void |
af02033e | 3415 | create_overlay_event_breakpoint (void) |
e62c965a | 3416 | { |
69de3c6a | 3417 | struct objfile *objfile; |
af02033e | 3418 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3419 | |
69de3c6a PP |
3420 | ALL_OBJFILES (objfile) |
3421 | { | |
3422 | struct breakpoint *b; | |
17450429 PP |
3423 | struct breakpoint_objfile_data *bp_objfile_data; |
3424 | CORE_ADDR addr; | |
69de3c6a | 3425 | |
17450429 PP |
3426 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3427 | ||
3b7344d5 | 3428 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3429 | continue; |
3430 | ||
3b7344d5 | 3431 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3432 | { |
3b7344d5 | 3433 | struct bound_minimal_symbol m; |
17450429 PP |
3434 | |
3435 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3436 | if (m.minsym == NULL) |
17450429 PP |
3437 | { |
3438 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3439 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3440 | continue; |
3441 | } | |
3442 | bp_objfile_data->overlay_msym = m; | |
3443 | } | |
e62c965a | 3444 | |
77e371c0 | 3445 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3446 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3447 | bp_overlay_event, |
3448 | &internal_breakpoint_ops); | |
69de3c6a | 3449 | b->addr_string = xstrdup (func_name); |
e62c965a | 3450 | |
69de3c6a PP |
3451 | if (overlay_debugging == ovly_auto) |
3452 | { | |
3453 | b->enable_state = bp_enabled; | |
3454 | overlay_events_enabled = 1; | |
3455 | } | |
3456 | else | |
3457 | { | |
3458 | b->enable_state = bp_disabled; | |
3459 | overlay_events_enabled = 0; | |
3460 | } | |
e62c965a | 3461 | } |
44702360 | 3462 | update_global_location_list (UGLL_MAY_INSERT); |
e62c965a PP |
3463 | } |
3464 | ||
0fd8e87f | 3465 | static void |
af02033e | 3466 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3467 | { |
6c95b8df | 3468 | struct program_space *pspace; |
6c95b8df PA |
3469 | struct cleanup *old_chain; |
3470 | ||
3471 | old_chain = save_current_program_space (); | |
0fd8e87f | 3472 | |
6c95b8df | 3473 | ALL_PSPACES (pspace) |
af02033e PP |
3474 | { |
3475 | struct objfile *objfile; | |
3476 | ||
3477 | set_current_program_space (pspace); | |
3478 | ||
3479 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3480 | { |
af02033e PP |
3481 | int i; |
3482 | struct gdbarch *gdbarch; | |
17450429 | 3483 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3484 | |
af02033e | 3485 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3486 | |
17450429 PP |
3487 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3488 | ||
28106bc2 SDJ |
3489 | if (!bp_objfile_data->longjmp_searched) |
3490 | { | |
25f9533e SDJ |
3491 | VEC (probe_p) *ret; |
3492 | ||
3493 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3494 | if (ret != NULL) | |
3495 | { | |
3496 | /* We are only interested in checking one element. */ | |
3497 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3498 | ||
3499 | if (!can_evaluate_probe_arguments (p)) | |
3500 | { | |
3501 | /* We cannot use the probe interface here, because it does | |
3502 | not know how to evaluate arguments. */ | |
3503 | VEC_free (probe_p, ret); | |
3504 | ret = NULL; | |
3505 | } | |
3506 | } | |
3507 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3508 | bp_objfile_data->longjmp_searched = 1; |
3509 | } | |
3510 | ||
3511 | if (bp_objfile_data->longjmp_probes != NULL) | |
3512 | { | |
3513 | int i; | |
3514 | struct probe *probe; | |
3515 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3516 | ||
3517 | for (i = 0; | |
3518 | VEC_iterate (probe_p, | |
3519 | bp_objfile_data->longjmp_probes, | |
3520 | i, probe); | |
3521 | ++i) | |
3522 | { | |
3523 | struct breakpoint *b; | |
3524 | ||
729662a5 TT |
3525 | b = create_internal_breakpoint (gdbarch, |
3526 | get_probe_address (probe, | |
3527 | objfile), | |
28106bc2 SDJ |
3528 | bp_longjmp_master, |
3529 | &internal_breakpoint_ops); | |
3530 | b->addr_string = xstrdup ("-probe-stap libc:longjmp"); | |
3531 | b->enable_state = bp_disabled; | |
3532 | } | |
3533 | ||
3534 | continue; | |
3535 | } | |
3536 | ||
0569175e TSD |
3537 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3538 | continue; | |
3539 | ||
17450429 | 3540 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3541 | { |
3542 | struct breakpoint *b; | |
af02033e | 3543 | const char *func_name; |
17450429 | 3544 | CORE_ADDR addr; |
6c95b8df | 3545 | |
3b7344d5 | 3546 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3547 | continue; |
0fd8e87f | 3548 | |
17450429 | 3549 | func_name = longjmp_names[i]; |
3b7344d5 | 3550 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3551 | { |
3b7344d5 | 3552 | struct bound_minimal_symbol m; |
17450429 PP |
3553 | |
3554 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3555 | if (m.minsym == NULL) |
17450429 PP |
3556 | { |
3557 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3558 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3559 | continue; |
3560 | } | |
3561 | bp_objfile_data->longjmp_msym[i] = m; | |
3562 | } | |
3563 | ||
77e371c0 | 3564 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3565 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3566 | &internal_breakpoint_ops); | |
af02033e PP |
3567 | b->addr_string = xstrdup (func_name); |
3568 | b->enable_state = bp_disabled; | |
3569 | } | |
0fd8e87f | 3570 | } |
af02033e | 3571 | } |
44702360 | 3572 | update_global_location_list (UGLL_MAY_INSERT); |
6c95b8df PA |
3573 | |
3574 | do_cleanups (old_chain); | |
0fd8e87f UW |
3575 | } |
3576 | ||
af02033e | 3577 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3578 | static void |
af02033e | 3579 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3580 | { |
3581 | struct program_space *pspace; | |
aa7d318d | 3582 | struct cleanup *old_chain; |
af02033e | 3583 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3584 | |
3585 | old_chain = save_current_program_space (); | |
3586 | ||
3587 | ALL_PSPACES (pspace) | |
17450429 PP |
3588 | { |
3589 | struct objfile *objfile; | |
3590 | CORE_ADDR addr; | |
3591 | ||
3592 | set_current_program_space (pspace); | |
3593 | ||
aa7d318d TT |
3594 | ALL_OBJFILES (objfile) |
3595 | { | |
3596 | struct breakpoint *b; | |
17450429 | 3597 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 3598 | |
17450429 | 3599 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3600 | |
3b7344d5 | 3601 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3602 | continue; |
3603 | ||
3b7344d5 | 3604 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3605 | { |
3b7344d5 | 3606 | struct bound_minimal_symbol m; |
17450429 PP |
3607 | |
3608 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3609 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3610 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3611 | { |
3612 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3613 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3614 | continue; |
3615 | } | |
3616 | bp_objfile_data->terminate_msym = m; | |
3617 | } | |
aa7d318d | 3618 | |
77e371c0 | 3619 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3620 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3621 | bp_std_terminate_master, |
3622 | &internal_breakpoint_ops); | |
aa7d318d TT |
3623 | b->addr_string = xstrdup (func_name); |
3624 | b->enable_state = bp_disabled; | |
3625 | } | |
17450429 PP |
3626 | } |
3627 | ||
44702360 | 3628 | update_global_location_list (UGLL_MAY_INSERT); |
aa7d318d TT |
3629 | |
3630 | do_cleanups (old_chain); | |
3631 | } | |
3632 | ||
186c406b TT |
3633 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3634 | ||
70221824 | 3635 | static void |
186c406b TT |
3636 | create_exception_master_breakpoint (void) |
3637 | { | |
3638 | struct objfile *objfile; | |
17450429 | 3639 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3640 | |
3641 | ALL_OBJFILES (objfile) | |
3642 | { | |
17450429 PP |
3643 | struct breakpoint *b; |
3644 | struct gdbarch *gdbarch; | |
3645 | struct breakpoint_objfile_data *bp_objfile_data; | |
3646 | CORE_ADDR addr; | |
3647 | ||
3648 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3649 | ||
28106bc2 SDJ |
3650 | /* We prefer the SystemTap probe point if it exists. */ |
3651 | if (!bp_objfile_data->exception_searched) | |
3652 | { | |
25f9533e SDJ |
3653 | VEC (probe_p) *ret; |
3654 | ||
3655 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3656 | ||
3657 | if (ret != NULL) | |
3658 | { | |
3659 | /* We are only interested in checking one element. */ | |
3660 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3661 | ||
3662 | if (!can_evaluate_probe_arguments (p)) | |
3663 | { | |
3664 | /* We cannot use the probe interface here, because it does | |
3665 | not know how to evaluate arguments. */ | |
3666 | VEC_free (probe_p, ret); | |
3667 | ret = NULL; | |
3668 | } | |
3669 | } | |
3670 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3671 | bp_objfile_data->exception_searched = 1; |
3672 | } | |
3673 | ||
3674 | if (bp_objfile_data->exception_probes != NULL) | |
3675 | { | |
3676 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3677 | int i; | |
3678 | struct probe *probe; | |
3679 | ||
3680 | for (i = 0; | |
3681 | VEC_iterate (probe_p, | |
3682 | bp_objfile_data->exception_probes, | |
3683 | i, probe); | |
3684 | ++i) | |
3685 | { | |
3686 | struct breakpoint *b; | |
3687 | ||
729662a5 TT |
3688 | b = create_internal_breakpoint (gdbarch, |
3689 | get_probe_address (probe, | |
3690 | objfile), | |
28106bc2 SDJ |
3691 | bp_exception_master, |
3692 | &internal_breakpoint_ops); | |
3693 | b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); | |
3694 | b->enable_state = bp_disabled; | |
3695 | } | |
3696 | ||
3697 | continue; | |
3698 | } | |
3699 | ||
3700 | /* Otherwise, try the hook function. */ | |
3701 | ||
3b7344d5 | 3702 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3703 | continue; |
3704 | ||
3705 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3706 | |
3b7344d5 | 3707 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3708 | { |
3b7344d5 | 3709 | struct bound_minimal_symbol debug_hook; |
186c406b | 3710 | |
17450429 | 3711 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3712 | if (debug_hook.minsym == NULL) |
17450429 | 3713 | { |
3b7344d5 | 3714 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3715 | continue; |
3716 | } | |
3717 | ||
3718 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3719 | } |
17450429 | 3720 | |
77e371c0 | 3721 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3722 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3723 | ¤t_target); | |
06edf0c0 PA |
3724 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3725 | &internal_breakpoint_ops); | |
17450429 PP |
3726 | b->addr_string = xstrdup (func_name); |
3727 | b->enable_state = bp_disabled; | |
186c406b TT |
3728 | } |
3729 | ||
44702360 | 3730 | update_global_location_list (UGLL_MAY_INSERT); |
186c406b TT |
3731 | } |
3732 | ||
c906108c | 3733 | void |
fba45db2 | 3734 | update_breakpoints_after_exec (void) |
c906108c | 3735 | { |
35df4500 | 3736 | struct breakpoint *b, *b_tmp; |
876fa593 | 3737 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3738 | |
25b22b0a PA |
3739 | /* We're about to delete breakpoints from GDB's lists. If the |
3740 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3741 | writing the breakpoints' "shadow contents" back into memory. The | |
3742 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3743 | do that. Instead, the target is responsible from marking | |
3744 | breakpoints out as soon as it detects an exec. We don't do that | |
3745 | here instead, because there may be other attempts to delete | |
3746 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3747 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3748 | if (bploc->pspace == current_program_space) |
3749 | gdb_assert (!bploc->inserted); | |
c906108c | 3750 | |
35df4500 | 3751 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3752 | { |
6c95b8df PA |
3753 | if (b->pspace != current_program_space) |
3754 | continue; | |
3755 | ||
4a64f543 | 3756 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3757 | if (b->type == bp_shlib_event) |
3758 | { | |
3759 | delete_breakpoint (b); | |
3760 | continue; | |
3761 | } | |
c906108c | 3762 | |
4a64f543 | 3763 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3764 | if (b->type == bp_jit_event) |
3765 | { | |
3766 | delete_breakpoint (b); | |
3767 | continue; | |
3768 | } | |
3769 | ||
1900040c | 3770 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3771 | as must overlay event and longjmp master breakpoints. */ |
3772 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3773 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3774 | || b->type == bp_exception_master) | |
c4093a6a JM |
3775 | { |
3776 | delete_breakpoint (b); | |
3777 | continue; | |
3778 | } | |
3779 | ||
4a64f543 | 3780 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3781 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3782 | { |
3783 | delete_breakpoint (b); | |
3784 | continue; | |
3785 | } | |
3786 | ||
7c16b83e PA |
3787 | /* Just like single-step breakpoints. */ |
3788 | if (b->type == bp_single_step) | |
3789 | { | |
3790 | delete_breakpoint (b); | |
3791 | continue; | |
3792 | } | |
3793 | ||
611c83ae PA |
3794 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3795 | after an exec. */ | |
186c406b | 3796 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3797 | || b->type == bp_longjmp_call_dummy |
186c406b | 3798 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3799 | { |
3800 | delete_breakpoint (b); | |
3801 | continue; | |
3802 | } | |
3803 | ||
ce78b96d JB |
3804 | if (b->type == bp_catchpoint) |
3805 | { | |
3806 | /* For now, none of the bp_catchpoint breakpoints need to | |
3807 | do anything at this point. In the future, if some of | |
3808 | the catchpoints need to something, we will need to add | |
3809 | a new method, and call this method from here. */ | |
3810 | continue; | |
3811 | } | |
3812 | ||
c5aa993b JM |
3813 | /* bp_finish is a special case. The only way we ought to be able |
3814 | to see one of these when an exec() has happened, is if the user | |
3815 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3816 | carries them to the call-site of the current callee, by setting | |
3817 | a temporary bp there and resuming. But in this case, the finish | |
3818 | will carry them entirely through the vfork & exec. | |
3819 | ||
3820 | We don't want to allow a bp_finish to remain inserted now. But | |
3821 | we can't safely delete it, 'cause finish_command has a handle to | |
3822 | the bp on a bpstat, and will later want to delete it. There's a | |
3823 | chance (and I've seen it happen) that if we delete the bp_finish | |
3824 | here, that its storage will get reused by the time finish_command | |
3825 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3826 | We really must allow finish_command to delete a bp_finish. | |
3827 | ||
e5dd4106 | 3828 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3829 | it's safe to delete something others may have handles to?" |
3830 | problem, what we'll do here is just uninsert the bp_finish, and | |
3831 | let finish_command delete it. | |
3832 | ||
3833 | (We know the bp_finish is "doomed" in the sense that it's | |
3834 | momentary, and will be deleted as soon as finish_command sees | |
3835 | the inferior stopped. So it doesn't matter that the bp's | |
3836 | address is probably bogus in the new a.out, unlike e.g., the | |
3837 | solib breakpoints.) */ | |
c5aa993b | 3838 | |
c5aa993b JM |
3839 | if (b->type == bp_finish) |
3840 | { | |
3841 | continue; | |
3842 | } | |
3843 | ||
3844 | /* Without a symbolic address, we have little hope of the | |
3845 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3846 | a.out. */ |
c5aa993b JM |
3847 | if (b->addr_string == NULL) |
3848 | { | |
3849 | delete_breakpoint (b); | |
3850 | continue; | |
3851 | } | |
c5aa993b | 3852 | } |
c906108c SS |
3853 | } |
3854 | ||
3855 | int | |
d80ee84f | 3856 | detach_breakpoints (ptid_t ptid) |
c906108c | 3857 | { |
35df4500 | 3858 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3859 | int val = 0; |
ce696e05 | 3860 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3861 | struct inferior *inf = current_inferior (); |
c5aa993b | 3862 | |
dfd4cc63 | 3863 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3864 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3865 | |
6c95b8df | 3866 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3867 | inferior_ptid = ptid; |
35df4500 | 3868 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3869 | { |
35df4500 | 3870 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3871 | continue; |
3872 | ||
bd9673a4 PW |
3873 | /* This function must physically remove breakpoints locations |
3874 | from the specified ptid, without modifying the breakpoint | |
3875 | package's state. Locations of type bp_loc_other are only | |
3876 | maintained at GDB side. So, there is no need to remove | |
3877 | these bp_loc_other locations. Moreover, removing these | |
3878 | would modify the breakpoint package's state. */ | |
3879 | if (bl->loc_type == bp_loc_other) | |
3880 | continue; | |
3881 | ||
35df4500 TJB |
3882 | if (bl->inserted) |
3883 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3884 | } |
d03285ec | 3885 | |
ce696e05 | 3886 | do_cleanups (old_chain); |
3a1bae8e | 3887 | return val; |
c906108c SS |
3888 | } |
3889 | ||
35df4500 | 3890 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3891 | Note that this is used to detach breakpoints from a child fork. |
3892 | When we get here, the child isn't in the inferior list, and neither | |
3893 | do we have objects to represent its address space --- we should | |
35df4500 | 3894 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3895 | |
c906108c | 3896 | static int |
35df4500 | 3897 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3898 | { |
3899 | int val; | |
c5aa993b | 3900 | |
35df4500 TJB |
3901 | /* BL is never in moribund_locations by our callers. */ |
3902 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3903 | |
74960c60 VP |
3904 | /* The type of none suggests that owner is actually deleted. |
3905 | This should not ever happen. */ | |
35df4500 | 3906 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3907 | |
35df4500 TJB |
3908 | if (bl->loc_type == bp_loc_software_breakpoint |
3909 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3910 | { |
c02f5703 MS |
3911 | /* "Normal" instruction breakpoint: either the standard |
3912 | trap-instruction bp (bp_breakpoint), or a | |
3913 | bp_hardware_breakpoint. */ | |
3914 | ||
3915 | /* First check to see if we have to handle an overlay. */ | |
3916 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3917 | || bl->section == NULL |
3918 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3919 | { |
3920 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3921 | |
3922 | /* If we're trying to uninsert a memory breakpoint that we | |
3923 | know is set in a dynamic object that is marked | |
3924 | shlib_disabled, then either the dynamic object was | |
3925 | removed with "remove-symbol-file" or with | |
3926 | "nosharedlibrary". In the former case, we don't know | |
3927 | whether another dynamic object might have loaded over the | |
3928 | breakpoint's address -- the user might well let us know | |
3929 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3930 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3931 | list of dynamically loaded objects). If we have the |
3932 | breakpoint's shadow memory, that is, this is a software | |
3933 | breakpoint managed by GDB, check whether the breakpoint | |
3934 | is still inserted in memory, to avoid overwriting wrong | |
3935 | code with stale saved shadow contents. Note that HW | |
3936 | breakpoints don't have shadow memory, as they're | |
3937 | implemented using a mechanism that is not dependent on | |
3938 | being able to modify the target's memory, and as such | |
3939 | they should always be removed. */ | |
3940 | if (bl->shlib_disabled | |
3941 | && bl->target_info.shadow_len != 0 | |
3942 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3943 | val = 0; | |
3944 | else | |
3945 | val = bl->owner->ops->remove_location (bl); | |
c02f5703 | 3946 | } |
c906108c SS |
3947 | else |
3948 | { | |
4a64f543 | 3949 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3950 | Did we set a breakpoint at the LMA? */ |
3951 | if (!overlay_events_enabled) | |
3952 | { | |
3953 | /* Yes -- overlay event support is not active, so we | |
3954 | should have set a breakpoint at the LMA. Remove it. | |
3955 | */ | |
c02f5703 MS |
3956 | /* Ignore any failures: if the LMA is in ROM, we will |
3957 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3958 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3959 | target_remove_hw_breakpoint (bl->gdbarch, | |
3960 | &bl->overlay_target_info); | |
c02f5703 | 3961 | else |
35df4500 TJB |
3962 | target_remove_breakpoint (bl->gdbarch, |
3963 | &bl->overlay_target_info); | |
c02f5703 MS |
3964 | } |
3965 | /* Did we set a breakpoint at the VMA? | |
3966 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3967 | if (bl->inserted) |
c906108c | 3968 | { |
c02f5703 MS |
3969 | /* Yes -- remove it. Previously we did not bother to |
3970 | remove the breakpoint if the section had been | |
3971 | unmapped, but let's not rely on that being safe. We | |
3972 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3973 | |
3974 | /* However, we should remove *software* breakpoints only | |
3975 | if the section is still mapped, or else we overwrite | |
3976 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3977 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3978 | || section_is_mapped (bl->section)) | |
3979 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3980 | else |
3981 | val = 0; | |
c906108c | 3982 | } |
c02f5703 MS |
3983 | else |
3984 | { | |
3985 | /* No -- not inserted, so no need to remove. No error. */ | |
3986 | val = 0; | |
3987 | } | |
c906108c | 3988 | } |
879d1e6b | 3989 | |
08351840 PA |
3990 | /* In some cases, we might not be able to remove a breakpoint in |
3991 | a shared library that has already been removed, but we have | |
3992 | not yet processed the shlib unload event. Similarly for an | |
3993 | unloaded add-symbol-file object - the user might not yet have | |
3994 | had the chance to remove-symbol-file it. shlib_disabled will | |
3995 | be set if the library/object has already been removed, but | |
3996 | the breakpoint hasn't been uninserted yet, e.g., after | |
3997 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3998 | always-inserted mode. */ | |
076855f9 | 3999 | if (val |
08351840 PA |
4000 | && (bl->loc_type == bp_loc_software_breakpoint |
4001 | && (bl->shlib_disabled | |
4002 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4003 | || shared_objfile_contains_address_p (bl->pspace, |
4004 | bl->address)))) | |
879d1e6b UW |
4005 | val = 0; |
4006 | ||
c906108c SS |
4007 | if (val) |
4008 | return val; | |
35df4500 | 4009 | bl->inserted = (is == mark_inserted); |
c906108c | 4010 | } |
35df4500 | 4011 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4012 | { |
77b06cd7 TJB |
4013 | gdb_assert (bl->owner->ops != NULL |
4014 | && bl->owner->ops->remove_location != NULL); | |
4015 | ||
35df4500 | 4016 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 4017 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 4018 | |
c906108c | 4019 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 4020 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 4021 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4022 | bl->owner->number); |
c906108c | 4023 | } |
35df4500 TJB |
4024 | else if (bl->owner->type == bp_catchpoint |
4025 | && breakpoint_enabled (bl->owner) | |
4026 | && !bl->duplicate) | |
ce78b96d | 4027 | { |
77b06cd7 TJB |
4028 | gdb_assert (bl->owner->ops != NULL |
4029 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4030 | |
77b06cd7 | 4031 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
4032 | if (val) |
4033 | return val; | |
77b06cd7 | 4034 | |
35df4500 | 4035 | bl->inserted = (is == mark_inserted); |
ce78b96d | 4036 | } |
c906108c SS |
4037 | |
4038 | return 0; | |
4039 | } | |
4040 | ||
6c95b8df | 4041 | static int |
35df4500 | 4042 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
4043 | { |
4044 | int ret; | |
4045 | struct cleanup *old_chain; | |
4046 | ||
35df4500 TJB |
4047 | /* BL is never in moribund_locations by our callers. */ |
4048 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4049 | |
6c95b8df PA |
4050 | /* The type of none suggests that owner is actually deleted. |
4051 | This should not ever happen. */ | |
35df4500 | 4052 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4053 | |
4054 | old_chain = save_current_space_and_thread (); | |
4055 | ||
35df4500 | 4056 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4057 | |
35df4500 | 4058 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
4059 | |
4060 | do_cleanups (old_chain); | |
4061 | return ret; | |
4062 | } | |
4063 | ||
c906108c SS |
4064 | /* Clear the "inserted" flag in all breakpoints. */ |
4065 | ||
25b22b0a | 4066 | void |
fba45db2 | 4067 | mark_breakpoints_out (void) |
c906108c | 4068 | { |
35df4500 | 4069 | struct bp_location *bl, **blp_tmp; |
c906108c | 4070 | |
35df4500 | 4071 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4072 | if (bl->pspace == current_program_space) |
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 | |
f486487f | 4223 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
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 | 4849 | { |
f486487f | 4850 | enum print_stop_action 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: |
0a39bb32 PA |
5764 | if (bs->stop) |
5765 | { | |
5766 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5767 | retval.is_longjmp = bptype != bp_exception; | |
5768 | } | |
5769 | else | |
5770 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5771 | break; |
5772 | case bp_longjmp_resume: | |
186c406b | 5773 | case bp_exception_resume: |
0a39bb32 PA |
5774 | if (bs->stop) |
5775 | { | |
5776 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5777 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5778 | } | |
5779 | else | |
5780 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5781 | break; |
5782 | case bp_step_resume: | |
5783 | if (bs->stop) | |
628fe4e4 JK |
5784 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5785 | else | |
c906108c | 5786 | { |
628fe4e4 JK |
5787 | /* It is for the wrong frame. */ |
5788 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5789 | } |
c906108c | 5790 | break; |
2c03e5be PA |
5791 | case bp_hp_step_resume: |
5792 | if (bs->stop) | |
5793 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5794 | else | |
5795 | { | |
5796 | /* It is for the wrong frame. */ | |
5797 | this_action = BPSTAT_WHAT_SINGLE; | |
5798 | } | |
5799 | break; | |
c906108c | 5800 | case bp_watchpoint_scope: |
c4093a6a | 5801 | case bp_thread_event: |
1900040c | 5802 | case bp_overlay_event: |
0fd8e87f | 5803 | case bp_longjmp_master: |
aa7d318d | 5804 | case bp_std_terminate_master: |
186c406b | 5805 | case bp_exception_master: |
628fe4e4 | 5806 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5807 | break; |
ce78b96d | 5808 | case bp_catchpoint: |
c5aa993b JM |
5809 | if (bs->stop) |
5810 | { | |
5811 | if (bs->print) | |
628fe4e4 | 5812 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5813 | else |
628fe4e4 | 5814 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5815 | } |
5816 | else | |
628fe4e4 JK |
5817 | { |
5818 | /* There was a catchpoint, but we're not stopping. | |
5819 | This requires no further action. */ | |
5820 | } | |
5821 | break; | |
628fe4e4 JK |
5822 | case bp_jit_event: |
5823 | jit_event = 1; | |
5824 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5825 | break; |
c906108c | 5826 | case bp_call_dummy: |
53a5351d JM |
5827 | /* Make sure the action is stop (silent or noisy), |
5828 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5829 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5830 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5831 | break; |
5832 | case bp_std_terminate: | |
5833 | /* Make sure the action is stop (silent or noisy), | |
5834 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5835 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5836 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5837 | break; |
1042e4c0 | 5838 | case bp_tracepoint: |
7a697b8d | 5839 | case bp_fast_tracepoint: |
0fb4aa4b | 5840 | case bp_static_tracepoint: |
1042e4c0 SS |
5841 | /* Tracepoint hits should not be reported back to GDB, and |
5842 | if one got through somehow, it should have been filtered | |
5843 | out already. */ | |
5844 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5845 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5846 | break; |
5847 | case bp_gnu_ifunc_resolver: | |
5848 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5849 | this_action = BPSTAT_WHAT_SINGLE; | |
5850 | break; | |
5851 | case bp_gnu_ifunc_resolver_return: | |
5852 | /* The breakpoint will be removed, execution will restart from the | |
5853 | PC of the former breakpoint. */ | |
5854 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5855 | break; | |
e7e0cddf SS |
5856 | |
5857 | case bp_dprintf: | |
a11cfd87 HZ |
5858 | if (bs->stop) |
5859 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5860 | else | |
5861 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5862 | break; |
5863 | ||
628fe4e4 JK |
5864 | default: |
5865 | internal_error (__FILE__, __LINE__, | |
5866 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5867 | } |
628fe4e4 JK |
5868 | |
5869 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5870 | } |
628fe4e4 | 5871 | |
0e30163f JK |
5872 | /* These operations may affect the bs->breakpoint_at state so they are |
5873 | delayed after MAIN_ACTION is decided above. */ | |
5874 | ||
628fe4e4 JK |
5875 | if (jit_event) |
5876 | { | |
5877 | if (debug_infrun) | |
5878 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5879 | ||
5880 | handle_jit_event (); | |
5881 | } | |
5882 | ||
0e30163f JK |
5883 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5884 | { | |
5885 | struct breakpoint *b = bs->breakpoint_at; | |
5886 | ||
5887 | if (b == NULL) | |
5888 | continue; | |
5889 | switch (b->type) | |
5890 | { | |
5891 | case bp_gnu_ifunc_resolver: | |
5892 | gnu_ifunc_resolver_stop (b); | |
5893 | break; | |
5894 | case bp_gnu_ifunc_resolver_return: | |
5895 | gnu_ifunc_resolver_return_stop (b); | |
5896 | break; | |
5897 | } | |
5898 | } | |
5899 | ||
c906108c SS |
5900 | return retval; |
5901 | } | |
5902 | ||
5903 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5904 | without hardware support). This isn't related to a specific bpstat, | |
5905 | just to things like whether watchpoints are set. */ | |
5906 | ||
c5aa993b | 5907 | int |
fba45db2 | 5908 | bpstat_should_step (void) |
c906108c SS |
5909 | { |
5910 | struct breakpoint *b; | |
cc59ec59 | 5911 | |
c906108c | 5912 | ALL_BREAKPOINTS (b) |
717a8278 | 5913 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5914 | return 1; |
c906108c SS |
5915 | return 0; |
5916 | } | |
5917 | ||
67822962 PA |
5918 | int |
5919 | bpstat_causes_stop (bpstat bs) | |
5920 | { | |
5921 | for (; bs != NULL; bs = bs->next) | |
5922 | if (bs->stop) | |
5923 | return 1; | |
5924 | ||
5925 | return 0; | |
5926 | } | |
5927 | ||
c906108c | 5928 | \f |
c5aa993b | 5929 | |
170b53b2 UW |
5930 | /* Compute a string of spaces suitable to indent the next line |
5931 | so it starts at the position corresponding to the table column | |
5932 | named COL_NAME in the currently active table of UIOUT. */ | |
5933 | ||
5934 | static char * | |
5935 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5936 | { | |
5937 | static char wrap_indent[80]; | |
5938 | int i, total_width, width, align; | |
5939 | char *text; | |
5940 | ||
5941 | total_width = 0; | |
5942 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5943 | { | |
5944 | if (strcmp (text, col_name) == 0) | |
5945 | { | |
5946 | gdb_assert (total_width < sizeof wrap_indent); | |
5947 | memset (wrap_indent, ' ', total_width); | |
5948 | wrap_indent[total_width] = 0; | |
5949 | ||
5950 | return wrap_indent; | |
5951 | } | |
5952 | ||
5953 | total_width += width + 1; | |
5954 | } | |
5955 | ||
5956 | return NULL; | |
5957 | } | |
5958 | ||
b775012e LM |
5959 | /* Determine if the locations of this breakpoint will have their conditions |
5960 | evaluated by the target, host or a mix of both. Returns the following: | |
5961 | ||
5962 | "host": Host evals condition. | |
5963 | "host or target": Host or Target evals condition. | |
5964 | "target": Target evals condition. | |
5965 | */ | |
5966 | ||
5967 | static const char * | |
5968 | bp_condition_evaluator (struct breakpoint *b) | |
5969 | { | |
5970 | struct bp_location *bl; | |
5971 | char host_evals = 0; | |
5972 | char target_evals = 0; | |
5973 | ||
5974 | if (!b) | |
5975 | return NULL; | |
5976 | ||
5977 | if (!is_breakpoint (b)) | |
5978 | return NULL; | |
5979 | ||
5980 | if (gdb_evaluates_breakpoint_condition_p () | |
5981 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5982 | return condition_evaluation_host; | |
5983 | ||
5984 | for (bl = b->loc; bl; bl = bl->next) | |
5985 | { | |
5986 | if (bl->cond_bytecode) | |
5987 | target_evals++; | |
5988 | else | |
5989 | host_evals++; | |
5990 | } | |
5991 | ||
5992 | if (host_evals && target_evals) | |
5993 | return condition_evaluation_both; | |
5994 | else if (target_evals) | |
5995 | return condition_evaluation_target; | |
5996 | else | |
5997 | return condition_evaluation_host; | |
5998 | } | |
5999 | ||
6000 | /* Determine the breakpoint location's condition evaluator. This is | |
6001 | similar to bp_condition_evaluator, but for locations. */ | |
6002 | ||
6003 | static const char * | |
6004 | bp_location_condition_evaluator (struct bp_location *bl) | |
6005 | { | |
6006 | if (bl && !is_breakpoint (bl->owner)) | |
6007 | return NULL; | |
6008 | ||
6009 | if (gdb_evaluates_breakpoint_condition_p () | |
6010 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6011 | return condition_evaluation_host; | |
6012 | ||
6013 | if (bl && bl->cond_bytecode) | |
6014 | return condition_evaluation_target; | |
6015 | else | |
6016 | return condition_evaluation_host; | |
6017 | } | |
6018 | ||
859825b8 JK |
6019 | /* Print the LOC location out of the list of B->LOC locations. */ |
6020 | ||
170b53b2 UW |
6021 | static void |
6022 | print_breakpoint_location (struct breakpoint *b, | |
6023 | struct bp_location *loc) | |
0d381245 | 6024 | { |
79a45e25 | 6025 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
6026 | struct cleanup *old_chain = save_current_program_space (); |
6027 | ||
859825b8 JK |
6028 | if (loc != NULL && loc->shlib_disabled) |
6029 | loc = NULL; | |
6030 | ||
6c95b8df PA |
6031 | if (loc != NULL) |
6032 | set_current_program_space (loc->pspace); | |
6033 | ||
56435ebe TT |
6034 | if (b->display_canonical) |
6035 | ui_out_field_string (uiout, "what", b->addr_string); | |
2f202fde | 6036 | else if (loc && loc->symtab) |
0d381245 VP |
6037 | { |
6038 | struct symbol *sym | |
6039 | = find_pc_sect_function (loc->address, loc->section); | |
6040 | if (sym) | |
6041 | { | |
6042 | ui_out_text (uiout, "in "); | |
6043 | ui_out_field_string (uiout, "func", | |
6044 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
6045 | ui_out_text (uiout, " "); |
6046 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
6047 | ui_out_text (uiout, "at "); | |
0d381245 | 6048 | } |
05cba821 JK |
6049 | ui_out_field_string (uiout, "file", |
6050 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 6051 | ui_out_text (uiout, ":"); |
05cba821 | 6052 | |
0d381245 | 6053 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
6054 | ui_out_field_string (uiout, "fullname", |
6055 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 6056 | |
f8eba3c6 | 6057 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 6058 | } |
859825b8 | 6059 | else if (loc) |
0d381245 | 6060 | { |
f99d8bf4 PA |
6061 | struct ui_file *stb = mem_fileopen (); |
6062 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 6063 | |
f99d8bf4 | 6064 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 6065 | demangle, ""); |
0d381245 | 6066 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
6067 | |
6068 | do_cleanups (stb_chain); | |
0d381245 | 6069 | } |
859825b8 JK |
6070 | else |
6071 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 6072 | |
b775012e LM |
6073 | if (loc && is_breakpoint (b) |
6074 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6075 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6076 | { | |
6077 | ui_out_text (uiout, " ("); | |
6078 | ui_out_field_string (uiout, "evaluated-by", | |
6079 | bp_location_condition_evaluator (loc)); | |
6080 | ui_out_text (uiout, ")"); | |
6081 | } | |
6082 | ||
6c95b8df | 6083 | do_cleanups (old_chain); |
0d381245 VP |
6084 | } |
6085 | ||
269b11a2 PA |
6086 | static const char * |
6087 | bptype_string (enum bptype type) | |
c906108c | 6088 | { |
c4093a6a JM |
6089 | struct ep_type_description |
6090 | { | |
6091 | enum bptype type; | |
6092 | char *description; | |
6093 | }; | |
6094 | static struct ep_type_description bptypes[] = | |
c906108c | 6095 | { |
c5aa993b JM |
6096 | {bp_none, "?deleted?"}, |
6097 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6098 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6099 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6100 | {bp_until, "until"}, |
6101 | {bp_finish, "finish"}, | |
6102 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6103 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6104 | {bp_read_watchpoint, "read watchpoint"}, |
6105 | {bp_access_watchpoint, "acc watchpoint"}, | |
6106 | {bp_longjmp, "longjmp"}, | |
6107 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6108 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6109 | {bp_exception, "exception"}, |
6110 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6111 | {bp_step_resume, "step resume"}, |
2c03e5be | 6112 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6113 | {bp_watchpoint_scope, "watchpoint scope"}, |
6114 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6115 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6116 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6117 | {bp_thread_event, "thread events"}, |
1900040c | 6118 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6119 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6120 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6121 | {bp_exception_master, "exception master"}, |
ce78b96d | 6122 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6123 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6124 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6125 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6126 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6127 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6128 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6129 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6130 | }; |
269b11a2 PA |
6131 | |
6132 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6133 | || ((int) type != bptypes[(int) type].type)) | |
6134 | internal_error (__FILE__, __LINE__, | |
6135 | _("bptypes table does not describe type #%d."), | |
6136 | (int) type); | |
6137 | ||
6138 | return bptypes[(int) type].description; | |
6139 | } | |
6140 | ||
998580f1 MK |
6141 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6142 | For CLI, prefix the list with the string 'inf'. */ | |
6143 | ||
6144 | static void | |
6145 | output_thread_groups (struct ui_out *uiout, | |
6146 | const char *field_name, | |
6147 | VEC(int) *inf_num, | |
6148 | int mi_only) | |
6149 | { | |
752eb8b4 | 6150 | struct cleanup *back_to; |
998580f1 MK |
6151 | int is_mi = ui_out_is_mi_like_p (uiout); |
6152 | int inf; | |
6153 | int i; | |
6154 | ||
6155 | /* For backward compatibility, don't display inferiors in CLI unless | |
6156 | there are several. Always display them for MI. */ | |
6157 | if (!is_mi && mi_only) | |
6158 | return; | |
6159 | ||
752eb8b4 TT |
6160 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6161 | ||
998580f1 MK |
6162 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6163 | { | |
6164 | if (is_mi) | |
6165 | { | |
6166 | char mi_group[10]; | |
6167 | ||
6168 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6169 | ui_out_field_string (uiout, NULL, mi_group); | |
6170 | } | |
6171 | else | |
6172 | { | |
6173 | if (i == 0) | |
6174 | ui_out_text (uiout, " inf "); | |
6175 | else | |
6176 | ui_out_text (uiout, ", "); | |
6177 | ||
6178 | ui_out_text (uiout, plongest (inf)); | |
6179 | } | |
6180 | } | |
6181 | ||
6182 | do_cleanups (back_to); | |
6183 | } | |
6184 | ||
269b11a2 PA |
6185 | /* Print B to gdb_stdout. */ |
6186 | ||
6187 | static void | |
6188 | print_one_breakpoint_location (struct breakpoint *b, | |
6189 | struct bp_location *loc, | |
6190 | int loc_number, | |
6191 | struct bp_location **last_loc, | |
269b11a2 PA |
6192 | int allflag) |
6193 | { | |
6194 | struct command_line *l; | |
c2c6d25f | 6195 | static char bpenables[] = "nynny"; |
c906108c | 6196 | |
79a45e25 | 6197 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6198 | int header_of_multiple = 0; |
6199 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6200 | struct value_print_options opts; |
6201 | ||
6202 | get_user_print_options (&opts); | |
0d381245 VP |
6203 | |
6204 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6205 | /* See comment in print_one_breakpoint concerning treatment of |
6206 | breakpoints with single disabled location. */ | |
0d381245 VP |
6207 | if (loc == NULL |
6208 | && (b->loc != NULL | |
6209 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6210 | header_of_multiple = 1; | |
6211 | if (loc == NULL) | |
6212 | loc = b->loc; | |
6213 | ||
c4093a6a JM |
6214 | annotate_record (); |
6215 | ||
6216 | /* 1 */ | |
6217 | annotate_field (0); | |
0d381245 VP |
6218 | if (part_of_multiple) |
6219 | { | |
6220 | char *formatted; | |
0c6773c1 | 6221 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6222 | ui_out_field_string (uiout, "number", formatted); |
6223 | xfree (formatted); | |
6224 | } | |
6225 | else | |
6226 | { | |
6227 | ui_out_field_int (uiout, "number", b->number); | |
6228 | } | |
c4093a6a JM |
6229 | |
6230 | /* 2 */ | |
6231 | annotate_field (1); | |
0d381245 VP |
6232 | if (part_of_multiple) |
6233 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6234 | else |
6235 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6236 | |
6237 | /* 3 */ | |
6238 | annotate_field (2); | |
0d381245 VP |
6239 | if (part_of_multiple) |
6240 | ui_out_field_skip (uiout, "disp"); | |
6241 | else | |
2cec12e5 | 6242 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6243 | |
c4093a6a JM |
6244 | |
6245 | /* 4 */ | |
6246 | annotate_field (3); | |
0d381245 | 6247 | if (part_of_multiple) |
54e52265 | 6248 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6249 | else |
4a64f543 MS |
6250 | ui_out_field_fmt (uiout, "enabled", "%c", |
6251 | bpenables[(int) b->enable_state]); | |
54e52265 | 6252 | ui_out_spaces (uiout, 2); |
0d381245 | 6253 | |
c4093a6a JM |
6254 | |
6255 | /* 5 and 6 */ | |
3086aeae | 6256 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6257 | { |
4a64f543 MS |
6258 | /* Although the print_one can possibly print all locations, |
6259 | calling it here is not likely to get any nice result. So, | |
6260 | make sure there's just one location. */ | |
0d381245 | 6261 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6262 | b->ops->print_one (b, last_loc); |
0d381245 | 6263 | } |
3086aeae DJ |
6264 | else |
6265 | switch (b->type) | |
6266 | { | |
6267 | case bp_none: | |
6268 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6269 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6270 | break; |
c906108c | 6271 | |
3086aeae DJ |
6272 | case bp_watchpoint: |
6273 | case bp_hardware_watchpoint: | |
6274 | case bp_read_watchpoint: | |
6275 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6276 | { |
6277 | struct watchpoint *w = (struct watchpoint *) b; | |
6278 | ||
6279 | /* Field 4, the address, is omitted (which makes the columns | |
6280 | not line up too nicely with the headers, but the effect | |
6281 | is relatively readable). */ | |
6282 | if (opts.addressprint) | |
6283 | ui_out_field_skip (uiout, "addr"); | |
6284 | annotate_field (5); | |
6285 | ui_out_field_string (uiout, "what", w->exp_string); | |
6286 | } | |
3086aeae DJ |
6287 | break; |
6288 | ||
3086aeae DJ |
6289 | case bp_breakpoint: |
6290 | case bp_hardware_breakpoint: | |
7c16b83e | 6291 | case bp_single_step: |
3086aeae DJ |
6292 | case bp_until: |
6293 | case bp_finish: | |
6294 | case bp_longjmp: | |
6295 | case bp_longjmp_resume: | |
e2e4d78b | 6296 | case bp_longjmp_call_dummy: |
186c406b TT |
6297 | case bp_exception: |
6298 | case bp_exception_resume: | |
3086aeae | 6299 | case bp_step_resume: |
2c03e5be | 6300 | case bp_hp_step_resume: |
3086aeae DJ |
6301 | case bp_watchpoint_scope: |
6302 | case bp_call_dummy: | |
aa7d318d | 6303 | case bp_std_terminate: |
3086aeae DJ |
6304 | case bp_shlib_event: |
6305 | case bp_thread_event: | |
6306 | case bp_overlay_event: | |
0fd8e87f | 6307 | case bp_longjmp_master: |
aa7d318d | 6308 | case bp_std_terminate_master: |
186c406b | 6309 | case bp_exception_master: |
1042e4c0 | 6310 | case bp_tracepoint: |
7a697b8d | 6311 | case bp_fast_tracepoint: |
0fb4aa4b | 6312 | case bp_static_tracepoint: |
e7e0cddf | 6313 | case bp_dprintf: |
4efc6507 | 6314 | case bp_jit_event: |
0e30163f JK |
6315 | case bp_gnu_ifunc_resolver: |
6316 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6317 | if (opts.addressprint) |
3086aeae DJ |
6318 | { |
6319 | annotate_field (4); | |
54e52265 | 6320 | if (header_of_multiple) |
0d381245 | 6321 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6322 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6323 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6324 | else |
5af949e3 UW |
6325 | ui_out_field_core_addr (uiout, "addr", |
6326 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6327 | } |
6328 | annotate_field (5); | |
0d381245 | 6329 | if (!header_of_multiple) |
170b53b2 | 6330 | print_breakpoint_location (b, loc); |
0d381245 | 6331 | if (b->loc) |
a6d9a66e | 6332 | *last_loc = b->loc; |
3086aeae DJ |
6333 | break; |
6334 | } | |
c906108c | 6335 | |
6c95b8df | 6336 | |
998580f1 | 6337 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6338 | { |
6339 | struct inferior *inf; | |
998580f1 MK |
6340 | VEC(int) *inf_num = NULL; |
6341 | int mi_only = 1; | |
6c95b8df | 6342 | |
998580f1 | 6343 | ALL_INFERIORS (inf) |
6c95b8df PA |
6344 | { |
6345 | if (inf->pspace == loc->pspace) | |
998580f1 | 6346 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6347 | } |
998580f1 MK |
6348 | |
6349 | /* For backward compatibility, don't display inferiors in CLI unless | |
6350 | there are several. Always display for MI. */ | |
6351 | if (allflag | |
6352 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6353 | && (number_of_program_spaces () > 1 | |
6354 | || number_of_inferiors () > 1) | |
6355 | /* LOC is for existing B, it cannot be in | |
6356 | moribund_locations and thus having NULL OWNER. */ | |
6357 | && loc->owner->type != bp_catchpoint)) | |
6358 | mi_only = 0; | |
6359 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6360 | VEC_free (int, inf_num); | |
6c95b8df PA |
6361 | } |
6362 | ||
4a306c9a | 6363 | if (!part_of_multiple) |
c4093a6a | 6364 | { |
4a306c9a JB |
6365 | if (b->thread != -1) |
6366 | { | |
6367 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6368 | "stop only in" line a little further down. */ |
4a306c9a JB |
6369 | ui_out_text (uiout, " thread "); |
6370 | ui_out_field_int (uiout, "thread", b->thread); | |
6371 | } | |
6372 | else if (b->task != 0) | |
6373 | { | |
6374 | ui_out_text (uiout, " task "); | |
6375 | ui_out_field_int (uiout, "task", b->task); | |
6376 | } | |
c4093a6a | 6377 | } |
f1310107 | 6378 | |
8b93c638 | 6379 | ui_out_text (uiout, "\n"); |
f1310107 | 6380 | |
348d480f | 6381 | if (!part_of_multiple) |
f1310107 TJB |
6382 | b->ops->print_one_detail (b, uiout); |
6383 | ||
0d381245 | 6384 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6385 | { |
6386 | annotate_field (6); | |
8b93c638 | 6387 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6388 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6389 | the frame ID. */ |
5af949e3 UW |
6390 | ui_out_field_core_addr (uiout, "frame", |
6391 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6392 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6393 | } |
6394 | ||
28010a5d | 6395 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6396 | { |
6397 | annotate_field (7); | |
d77f58be | 6398 | if (is_tracepoint (b)) |
1042e4c0 SS |
6399 | ui_out_text (uiout, "\ttrace only if "); |
6400 | else | |
6401 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6402 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6403 | |
6404 | /* Print whether the target is doing the breakpoint's condition | |
6405 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6406 | if (is_breakpoint (b) | |
6407 | && breakpoint_condition_evaluation_mode () | |
6408 | == condition_evaluation_target) | |
6409 | { | |
6410 | ui_out_text (uiout, " ("); | |
6411 | ui_out_field_string (uiout, "evaluated-by", | |
6412 | bp_condition_evaluator (b)); | |
6413 | ui_out_text (uiout, " evals)"); | |
6414 | } | |
0101ce28 JJ |
6415 | ui_out_text (uiout, "\n"); |
6416 | } | |
6417 | ||
0d381245 | 6418 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6419 | { |
4a64f543 | 6420 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6421 | ui_out_text (uiout, "\tstop only in thread "); |
6422 | ui_out_field_int (uiout, "thread", b->thread); | |
6423 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6424 | } |
6425 | ||
556ec64d YQ |
6426 | if (!part_of_multiple) |
6427 | { | |
6428 | if (b->hit_count) | |
31f56a27 YQ |
6429 | { |
6430 | /* FIXME should make an annotation for this. */ | |
6431 | if (is_catchpoint (b)) | |
6432 | ui_out_text (uiout, "\tcatchpoint"); | |
6433 | else if (is_tracepoint (b)) | |
6434 | ui_out_text (uiout, "\ttracepoint"); | |
6435 | else | |
6436 | ui_out_text (uiout, "\tbreakpoint"); | |
6437 | ui_out_text (uiout, " already hit "); | |
6438 | ui_out_field_int (uiout, "times", b->hit_count); | |
6439 | if (b->hit_count == 1) | |
6440 | ui_out_text (uiout, " time\n"); | |
6441 | else | |
6442 | ui_out_text (uiout, " times\n"); | |
6443 | } | |
556ec64d YQ |
6444 | else |
6445 | { | |
31f56a27 YQ |
6446 | /* Output the count also if it is zero, but only if this is mi. */ |
6447 | if (ui_out_is_mi_like_p (uiout)) | |
6448 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6449 | } |
6450 | } | |
8b93c638 | 6451 | |
0d381245 | 6452 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6453 | { |
6454 | annotate_field (8); | |
8b93c638 JM |
6455 | ui_out_text (uiout, "\tignore next "); |
6456 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6457 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6458 | } |
059fb39f | 6459 | |
816338b5 SS |
6460 | /* Note that an enable count of 1 corresponds to "enable once" |
6461 | behavior, which is reported by the combination of enablement and | |
6462 | disposition, so we don't need to mention it here. */ | |
6463 | if (!part_of_multiple && b->enable_count > 1) | |
6464 | { | |
6465 | annotate_field (8); | |
6466 | ui_out_text (uiout, "\tdisable after "); | |
6467 | /* Tweak the wording to clarify that ignore and enable counts | |
6468 | are distinct, and have additive effect. */ | |
6469 | if (b->ignore_count) | |
6470 | ui_out_text (uiout, "additional "); | |
6471 | else | |
6472 | ui_out_text (uiout, "next "); | |
6473 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6474 | ui_out_text (uiout, " hits\n"); | |
6475 | } | |
6476 | ||
f196051f SS |
6477 | if (!part_of_multiple && is_tracepoint (b)) |
6478 | { | |
6479 | struct tracepoint *tp = (struct tracepoint *) b; | |
6480 | ||
6481 | if (tp->traceframe_usage) | |
6482 | { | |
6483 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6484 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6485 | ui_out_text (uiout, " bytes\n"); | |
6486 | } | |
6487 | } | |
d3ce09f5 | 6488 | |
9add0f1b | 6489 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6490 | if (!part_of_multiple && l) |
c4093a6a | 6491 | { |
3b31d625 EZ |
6492 | struct cleanup *script_chain; |
6493 | ||
c4093a6a | 6494 | annotate_field (9); |
3b31d625 | 6495 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6496 | print_command_lines (uiout, l, 4); |
3b31d625 | 6497 | do_cleanups (script_chain); |
c4093a6a | 6498 | } |
d24317b4 | 6499 | |
d9b3f62e | 6500 | if (is_tracepoint (b)) |
1042e4c0 | 6501 | { |
d9b3f62e PA |
6502 | struct tracepoint *t = (struct tracepoint *) b; |
6503 | ||
6504 | if (!part_of_multiple && t->pass_count) | |
6505 | { | |
6506 | annotate_field (10); | |
6507 | ui_out_text (uiout, "\tpass count "); | |
6508 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6509 | ui_out_text (uiout, " \n"); | |
6510 | } | |
f2a8bc8a YQ |
6511 | |
6512 | /* Don't display it when tracepoint or tracepoint location is | |
6513 | pending. */ | |
6514 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6515 | { | |
6516 | annotate_field (11); | |
6517 | ||
6518 | if (ui_out_is_mi_like_p (uiout)) | |
6519 | ui_out_field_string (uiout, "installed", | |
6520 | loc->inserted ? "y" : "n"); | |
6521 | else | |
6522 | { | |
6523 | if (loc->inserted) | |
6524 | ui_out_text (uiout, "\t"); | |
6525 | else | |
6526 | ui_out_text (uiout, "\tnot "); | |
6527 | ui_out_text (uiout, "installed on target\n"); | |
6528 | } | |
6529 | } | |
1042e4c0 SS |
6530 | } |
6531 | ||
d24317b4 VP |
6532 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6533 | { | |
3a5c3e22 PA |
6534 | if (is_watchpoint (b)) |
6535 | { | |
6536 | struct watchpoint *w = (struct watchpoint *) b; | |
6537 | ||
6538 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6539 | } | |
6540 | else if (b->addr_string) | |
d24317b4 | 6541 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 6542 | } |
c4093a6a | 6543 | } |
c5aa993b | 6544 | |
0d381245 VP |
6545 | static void |
6546 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6547 | struct bp_location **last_loc, |
6c95b8df | 6548 | int allflag) |
0d381245 | 6549 | { |
8d3788bd | 6550 | struct cleanup *bkpt_chain; |
79a45e25 | 6551 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6552 | |
6553 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6554 | ||
12c5a436 | 6555 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6556 | do_cleanups (bkpt_chain); |
0d381245 VP |
6557 | |
6558 | /* If this breakpoint has custom print function, | |
6559 | it's already printed. Otherwise, print individual | |
6560 | locations, if any. */ | |
6561 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6562 | { | |
4a64f543 MS |
6563 | /* If breakpoint has a single location that is disabled, we |
6564 | print it as if it had several locations, since otherwise it's | |
6565 | hard to represent "breakpoint enabled, location disabled" | |
6566 | situation. | |
6567 | ||
6568 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6569 | internally, that's not a property exposed to user. */ |
0d381245 | 6570 | if (b->loc |
a5606eee | 6571 | && !is_hardware_watchpoint (b) |
8d3788bd | 6572 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6573 | { |
6574 | struct bp_location *loc; | |
6575 | int n = 1; | |
8d3788bd | 6576 | |
0d381245 | 6577 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6578 | { |
6579 | struct cleanup *inner2 = | |
6580 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6581 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6582 | do_cleanups (inner2); | |
6583 | } | |
0d381245 VP |
6584 | } |
6585 | } | |
6586 | } | |
6587 | ||
a6d9a66e UW |
6588 | static int |
6589 | breakpoint_address_bits (struct breakpoint *b) | |
6590 | { | |
6591 | int print_address_bits = 0; | |
6592 | struct bp_location *loc; | |
6593 | ||
6594 | for (loc = b->loc; loc; loc = loc->next) | |
6595 | { | |
c7437ca6 PA |
6596 | int addr_bit; |
6597 | ||
6598 | /* Software watchpoints that aren't watching memory don't have | |
6599 | an address to print. */ | |
6600 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
6601 | continue; | |
6602 | ||
6603 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
6604 | if (addr_bit > print_address_bits) |
6605 | print_address_bits = addr_bit; | |
6606 | } | |
6607 | ||
6608 | return print_address_bits; | |
6609 | } | |
0d381245 | 6610 | |
c4093a6a JM |
6611 | struct captured_breakpoint_query_args |
6612 | { | |
6613 | int bnum; | |
6614 | }; | |
c5aa993b | 6615 | |
c4093a6a | 6616 | static int |
2b65245e | 6617 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
6618 | { |
6619 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 6620 | struct breakpoint *b; |
a6d9a66e | 6621 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6622 | |
c4093a6a JM |
6623 | ALL_BREAKPOINTS (b) |
6624 | { | |
6625 | if (args->bnum == b->number) | |
c5aa993b | 6626 | { |
12c5a436 | 6627 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6628 | return GDB_RC_OK; |
c5aa993b | 6629 | } |
c4093a6a JM |
6630 | } |
6631 | return GDB_RC_NONE; | |
6632 | } | |
c5aa993b | 6633 | |
c4093a6a | 6634 | enum gdb_rc |
4a64f543 MS |
6635 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6636 | char **error_message) | |
c4093a6a JM |
6637 | { |
6638 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6639 | |
c4093a6a JM |
6640 | args.bnum = bnum; |
6641 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6642 | an error. */ |
b0b13bb4 DJ |
6643 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6644 | error_message, RETURN_MASK_ALL) < 0) | |
6645 | return GDB_RC_FAIL; | |
6646 | else | |
6647 | return GDB_RC_OK; | |
c4093a6a | 6648 | } |
c5aa993b | 6649 | |
09d682a4 TT |
6650 | /* Return true if this breakpoint was set by the user, false if it is |
6651 | internal or momentary. */ | |
6652 | ||
6653 | int | |
6654 | user_breakpoint_p (struct breakpoint *b) | |
6655 | { | |
46c6471b | 6656 | return b->number > 0; |
09d682a4 TT |
6657 | } |
6658 | ||
7f3b0473 | 6659 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6660 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6661 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6662 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6663 | ones for which it returns non-zero. Return the total number of | |
6664 | breakpoints listed. */ | |
c906108c | 6665 | |
d77f58be | 6666 | static int |
e5a67952 | 6667 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6668 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6669 | { |
52f0bd74 | 6670 | struct breakpoint *b; |
a6d9a66e | 6671 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6672 | int nr_printable_breakpoints; |
3b31d625 | 6673 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6674 | struct value_print_options opts; |
a6d9a66e | 6675 | int print_address_bits = 0; |
269b11a2 | 6676 | int print_type_col_width = 14; |
79a45e25 | 6677 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6678 | |
79a45b7d TT |
6679 | get_user_print_options (&opts); |
6680 | ||
4a64f543 MS |
6681 | /* Compute the number of rows in the table, as well as the size |
6682 | required for address fields. */ | |
7f3b0473 AC |
6683 | nr_printable_breakpoints = 0; |
6684 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6685 | { |
6686 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6687 | if (filter && !filter (b)) | |
6688 | continue; | |
6689 | ||
6690 | /* If we have an "args" string, it is a list of breakpoints to | |
6691 | accept. Skip the others. */ | |
6692 | if (args != NULL && *args != '\0') | |
6693 | { | |
6694 | if (allflag && parse_and_eval_long (args) != b->number) | |
6695 | continue; | |
6696 | if (!allflag && !number_is_in_list (args, b->number)) | |
6697 | continue; | |
6698 | } | |
269b11a2 | 6699 | |
e5a67952 MS |
6700 | if (allflag || user_breakpoint_p (b)) |
6701 | { | |
6702 | int addr_bit, type_len; | |
a6d9a66e | 6703 | |
e5a67952 MS |
6704 | addr_bit = breakpoint_address_bits (b); |
6705 | if (addr_bit > print_address_bits) | |
6706 | print_address_bits = addr_bit; | |
269b11a2 | 6707 | |
e5a67952 MS |
6708 | type_len = strlen (bptype_string (b->type)); |
6709 | if (type_len > print_type_col_width) | |
6710 | print_type_col_width = type_len; | |
6711 | ||
6712 | nr_printable_breakpoints++; | |
6713 | } | |
6714 | } | |
7f3b0473 | 6715 | |
79a45b7d | 6716 | if (opts.addressprint) |
3b31d625 | 6717 | bkpttbl_chain |
3e43a32a MS |
6718 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6719 | nr_printable_breakpoints, | |
3b31d625 | 6720 | "BreakpointTable"); |
8b93c638 | 6721 | else |
3b31d625 | 6722 | bkpttbl_chain |
3e43a32a MS |
6723 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6724 | nr_printable_breakpoints, | |
3b31d625 | 6725 | "BreakpointTable"); |
8b93c638 | 6726 | |
7f3b0473 | 6727 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6728 | annotate_breakpoints_headers (); |
6729 | if (nr_printable_breakpoints > 0) | |
6730 | annotate_field (0); | |
4a64f543 | 6731 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6732 | if (nr_printable_breakpoints > 0) |
6733 | annotate_field (1); | |
269b11a2 | 6734 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6735 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6736 | if (nr_printable_breakpoints > 0) |
6737 | annotate_field (2); | |
4a64f543 | 6738 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6739 | if (nr_printable_breakpoints > 0) |
6740 | annotate_field (3); | |
54e52265 | 6741 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6742 | if (opts.addressprint) |
e5a67952 MS |
6743 | { |
6744 | if (nr_printable_breakpoints > 0) | |
6745 | annotate_field (4); | |
6746 | if (print_address_bits <= 32) | |
6747 | ui_out_table_header (uiout, 10, ui_left, | |
6748 | "addr", "Address"); /* 5 */ | |
6749 | else | |
6750 | ui_out_table_header (uiout, 18, ui_left, | |
6751 | "addr", "Address"); /* 5 */ | |
6752 | } | |
d7faa9e7 AC |
6753 | if (nr_printable_breakpoints > 0) |
6754 | annotate_field (5); | |
6755 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6756 | ui_out_table_body (uiout); | |
6757 | if (nr_printable_breakpoints > 0) | |
6758 | annotate_breakpoints_table (); | |
7f3b0473 | 6759 | |
c4093a6a | 6760 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6761 | { |
6762 | QUIT; | |
6763 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6764 | if (filter && !filter (b)) | |
6765 | continue; | |
6766 | ||
6767 | /* If we have an "args" string, it is a list of breakpoints to | |
6768 | accept. Skip the others. */ | |
6769 | ||
6770 | if (args != NULL && *args != '\0') | |
6771 | { | |
6772 | if (allflag) /* maintenance info breakpoint */ | |
6773 | { | |
6774 | if (parse_and_eval_long (args) != b->number) | |
6775 | continue; | |
6776 | } | |
6777 | else /* all others */ | |
6778 | { | |
6779 | if (!number_is_in_list (args, b->number)) | |
6780 | continue; | |
6781 | } | |
6782 | } | |
6783 | /* We only print out user settable breakpoints unless the | |
6784 | allflag is set. */ | |
6785 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6786 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6787 | } |
6788 | ||
3b31d625 | 6789 | do_cleanups (bkpttbl_chain); |
698384cd | 6790 | |
7f3b0473 | 6791 | if (nr_printable_breakpoints == 0) |
c906108c | 6792 | { |
4a64f543 MS |
6793 | /* If there's a filter, let the caller decide how to report |
6794 | empty list. */ | |
d77f58be SS |
6795 | if (!filter) |
6796 | { | |
e5a67952 | 6797 | if (args == NULL || *args == '\0') |
d77f58be SS |
6798 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6799 | else | |
4a64f543 | 6800 | ui_out_message (uiout, 0, |
e5a67952 MS |
6801 | "No breakpoint or watchpoint matching '%s'.\n", |
6802 | args); | |
d77f58be | 6803 | } |
c906108c SS |
6804 | } |
6805 | else | |
c4093a6a | 6806 | { |
a6d9a66e UW |
6807 | if (last_loc && !server_command) |
6808 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6809 | } |
c906108c | 6810 | |
4a64f543 | 6811 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6812 | there have been breakpoints? */ |
c906108c | 6813 | annotate_breakpoints_table_end (); |
d77f58be SS |
6814 | |
6815 | return nr_printable_breakpoints; | |
c906108c SS |
6816 | } |
6817 | ||
ad443146 SS |
6818 | /* Display the value of default-collect in a way that is generally |
6819 | compatible with the breakpoint list. */ | |
6820 | ||
6821 | static void | |
6822 | default_collect_info (void) | |
6823 | { | |
79a45e25 PA |
6824 | struct ui_out *uiout = current_uiout; |
6825 | ||
ad443146 SS |
6826 | /* If it has no value (which is frequently the case), say nothing; a |
6827 | message like "No default-collect." gets in user's face when it's | |
6828 | not wanted. */ | |
6829 | if (!*default_collect) | |
6830 | return; | |
6831 | ||
6832 | /* The following phrase lines up nicely with per-tracepoint collect | |
6833 | actions. */ | |
6834 | ui_out_text (uiout, "default collect "); | |
6835 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6836 | ui_out_text (uiout, " \n"); | |
6837 | } | |
6838 | ||
c906108c | 6839 | static void |
e5a67952 | 6840 | breakpoints_info (char *args, int from_tty) |
c906108c | 6841 | { |
e5a67952 | 6842 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6843 | |
6844 | default_collect_info (); | |
d77f58be SS |
6845 | } |
6846 | ||
6847 | static void | |
e5a67952 | 6848 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6849 | { |
e5a67952 | 6850 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6851 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6852 | |
6853 | if (num_printed == 0) | |
6854 | { | |
e5a67952 | 6855 | if (args == NULL || *args == '\0') |
d77f58be SS |
6856 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6857 | else | |
e5a67952 | 6858 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6859 | } |
c906108c SS |
6860 | } |
6861 | ||
7a292a7a | 6862 | static void |
e5a67952 | 6863 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6864 | { |
e5a67952 | 6865 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6866 | |
6867 | default_collect_info (); | |
c906108c SS |
6868 | } |
6869 | ||
0d381245 | 6870 | static int |
714835d5 | 6871 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6872 | struct program_space *pspace, |
714835d5 | 6873 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6874 | { |
6875 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6876 | |
0d381245 VP |
6877 | for (; bl; bl = bl->next) |
6878 | { | |
6c95b8df PA |
6879 | if (bl->pspace == pspace |
6880 | && bl->address == pc | |
0d381245 VP |
6881 | && (!overlay_debugging || bl->section == section)) |
6882 | return 1; | |
6883 | } | |
6884 | return 0; | |
6885 | } | |
6886 | ||
672f9b60 | 6887 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6888 | concerns with logical breakpoints, so we match program spaces, not |
6889 | address spaces. */ | |
c906108c SS |
6890 | |
6891 | static void | |
6c95b8df PA |
6892 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6893 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6894 | struct obj_section *section, int thread) |
c906108c | 6895 | { |
52f0bd74 AC |
6896 | int others = 0; |
6897 | struct breakpoint *b; | |
c906108c SS |
6898 | |
6899 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6900 | others += (user_breakpoint_p (b) |
6901 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6902 | if (others > 0) |
6903 | { | |
a3f17187 AC |
6904 | if (others == 1) |
6905 | printf_filtered (_("Note: breakpoint ")); | |
6906 | else /* if (others == ???) */ | |
6907 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6908 | ALL_BREAKPOINTS (b) |
672f9b60 | 6909 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6910 | { |
6911 | others--; | |
6912 | printf_filtered ("%d", b->number); | |
6913 | if (b->thread == -1 && thread != -1) | |
6914 | printf_filtered (" (all threads)"); | |
6915 | else if (b->thread != -1) | |
6916 | printf_filtered (" (thread %d)", b->thread); | |
6917 | printf_filtered ("%s%s ", | |
059fb39f | 6918 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6919 | || b->enable_state == bp_call_disabled) |
0d381245 | 6920 | ? " (disabled)" |
0d381245 VP |
6921 | : ""), |
6922 | (others > 1) ? "," | |
6923 | : ((others == 1) ? " and" : "")); | |
6924 | } | |
a3f17187 | 6925 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6926 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6927 | printf_filtered (".\n"); |
6928 | } | |
6929 | } | |
6930 | \f | |
c906108c | 6931 | |
e4f237da KB |
6932 | /* Return true iff it is meaningful to use the address member of |
6933 | BPT. For some breakpoint types, the address member is irrelevant | |
6934 | and it makes no sense to attempt to compare it to other addresses | |
6935 | (or use it for any other purpose either). | |
6936 | ||
4a64f543 MS |
6937 | More specifically, each of the following breakpoint types will |
6938 | always have a zero valued address and we don't want to mark | |
6939 | breakpoints of any of these types to be a duplicate of an actual | |
6940 | breakpoint at address zero: | |
e4f237da KB |
6941 | |
6942 | bp_watchpoint | |
2d134ed3 PA |
6943 | bp_catchpoint |
6944 | ||
6945 | */ | |
e4f237da KB |
6946 | |
6947 | static int | |
6948 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6949 | { | |
6950 | enum bptype type = bpt->type; | |
6951 | ||
2d134ed3 PA |
6952 | return (type != bp_watchpoint && type != bp_catchpoint); |
6953 | } | |
6954 | ||
6955 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6956 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6957 | ||
6958 | static int | |
4a64f543 MS |
6959 | watchpoint_locations_match (struct bp_location *loc1, |
6960 | struct bp_location *loc2) | |
2d134ed3 | 6961 | { |
3a5c3e22 PA |
6962 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6963 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6964 | ||
6965 | /* Both of them must exist. */ | |
6966 | gdb_assert (w1 != NULL); | |
6967 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6968 | |
4a64f543 MS |
6969 | /* If the target can evaluate the condition expression in hardware, |
6970 | then we we need to insert both watchpoints even if they are at | |
6971 | the same place. Otherwise the watchpoint will only trigger when | |
6972 | the condition of whichever watchpoint was inserted evaluates to | |
6973 | true, not giving a chance for GDB to check the condition of the | |
6974 | other watchpoint. */ | |
3a5c3e22 | 6975 | if ((w1->cond_exp |
4a64f543 MS |
6976 | && target_can_accel_watchpoint_condition (loc1->address, |
6977 | loc1->length, | |
0cf6dd15 | 6978 | loc1->watchpoint_type, |
3a5c3e22 PA |
6979 | w1->cond_exp)) |
6980 | || (w2->cond_exp | |
4a64f543 MS |
6981 | && target_can_accel_watchpoint_condition (loc2->address, |
6982 | loc2->length, | |
0cf6dd15 | 6983 | loc2->watchpoint_type, |
3a5c3e22 | 6984 | w2->cond_exp))) |
0cf6dd15 TJB |
6985 | return 0; |
6986 | ||
85d721b8 PA |
6987 | /* Note that this checks the owner's type, not the location's. In |
6988 | case the target does not support read watchpoints, but does | |
6989 | support access watchpoints, we'll have bp_read_watchpoint | |
6990 | watchpoints with hw_access locations. Those should be considered | |
6991 | duplicates of hw_read locations. The hw_read locations will | |
6992 | become hw_access locations later. */ | |
2d134ed3 PA |
6993 | return (loc1->owner->type == loc2->owner->type |
6994 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6995 | && loc1->address == loc2->address | |
6996 | && loc1->length == loc2->length); | |
e4f237da KB |
6997 | } |
6998 | ||
31e77af2 | 6999 | /* See breakpoint.h. */ |
6c95b8df | 7000 | |
31e77af2 | 7001 | int |
6c95b8df PA |
7002 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7003 | struct address_space *aspace2, CORE_ADDR addr2) | |
7004 | { | |
f5656ead | 7005 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7006 | || aspace1 == aspace2) |
7007 | && addr1 == addr2); | |
7008 | } | |
7009 | ||
f1310107 TJB |
7010 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7011 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7012 | matches ASPACE2. On targets that have global breakpoints, the address | |
7013 | space doesn't really matter. */ | |
7014 | ||
7015 | static int | |
7016 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7017 | int len1, struct address_space *aspace2, | |
7018 | CORE_ADDR addr2) | |
7019 | { | |
f5656ead | 7020 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7021 | || aspace1 == aspace2) |
7022 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7023 | } | |
7024 | ||
7025 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7026 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7027 | matches the breakpoint's address space. On targets that have global | |
7028 | breakpoints, the address space doesn't really matter. */ | |
7029 | ||
7030 | static int | |
7031 | breakpoint_location_address_match (struct bp_location *bl, | |
7032 | struct address_space *aspace, | |
7033 | CORE_ADDR addr) | |
7034 | { | |
7035 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7036 | aspace, addr) | |
7037 | || (bl->length | |
7038 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7039 | bl->address, bl->length, | |
7040 | aspace, addr))); | |
7041 | } | |
7042 | ||
1e4d1764 YQ |
7043 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7044 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7045 | true, otherwise returns false. */ | |
7046 | ||
7047 | static int | |
7048 | tracepoint_locations_match (struct bp_location *loc1, | |
7049 | struct bp_location *loc2) | |
7050 | { | |
7051 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7052 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7053 | locations at the same address of different tracepoints are regarded as | |
7054 | different locations. */ | |
7055 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7056 | else | |
7057 | return 0; | |
7058 | } | |
7059 | ||
2d134ed3 PA |
7060 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7061 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7062 | represent the same location. */ | |
7063 | ||
7064 | static int | |
4a64f543 MS |
7065 | breakpoint_locations_match (struct bp_location *loc1, |
7066 | struct bp_location *loc2) | |
2d134ed3 | 7067 | { |
2bdf28a0 JK |
7068 | int hw_point1, hw_point2; |
7069 | ||
7070 | /* Both of them must not be in moribund_locations. */ | |
7071 | gdb_assert (loc1->owner != NULL); | |
7072 | gdb_assert (loc2->owner != NULL); | |
7073 | ||
7074 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7075 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7076 | |
7077 | if (hw_point1 != hw_point2) | |
7078 | return 0; | |
7079 | else if (hw_point1) | |
7080 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7081 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7082 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7083 | else |
f1310107 TJB |
7084 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7085 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7086 | loc2->pspace->aspace, loc2->address) | |
7087 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7088 | } |
7089 | ||
76897487 KB |
7090 | static void |
7091 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7092 | int bnum, int have_bnum) | |
7093 | { | |
f63fbe86 MS |
7094 | /* The longest string possibly returned by hex_string_custom |
7095 | is 50 chars. These must be at least that big for safety. */ | |
7096 | char astr1[64]; | |
7097 | char astr2[64]; | |
76897487 | 7098 | |
bb599908 PH |
7099 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7100 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7101 | if (have_bnum) |
8a3fe4f8 | 7102 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7103 | bnum, astr1, astr2); |
7104 | else | |
8a3fe4f8 | 7105 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7106 | } |
7107 | ||
4a64f543 MS |
7108 | /* Adjust a breakpoint's address to account for architectural |
7109 | constraints on breakpoint placement. Return the adjusted address. | |
7110 | Note: Very few targets require this kind of adjustment. For most | |
7111 | targets, this function is simply the identity function. */ | |
76897487 KB |
7112 | |
7113 | static CORE_ADDR | |
a6d9a66e UW |
7114 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7115 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7116 | { |
a6d9a66e | 7117 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7118 | { |
7119 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7120 | return bpaddr; | |
7121 | } | |
88f7da05 KB |
7122 | else if (bptype == bp_watchpoint |
7123 | || bptype == bp_hardware_watchpoint | |
7124 | || bptype == bp_read_watchpoint | |
7125 | || bptype == bp_access_watchpoint | |
fe798b75 | 7126 | || bptype == bp_catchpoint) |
88f7da05 KB |
7127 | { |
7128 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7129 | have their addresses modified. */ | |
7130 | return bpaddr; | |
7131 | } | |
7c16b83e PA |
7132 | else if (bptype == bp_single_step) |
7133 | { | |
7134 | /* Single-step breakpoints should not have their addresses | |
7135 | modified. If there's any architectural constrain that | |
7136 | applies to this address, then it should have already been | |
7137 | taken into account when the breakpoint was created in the | |
7138 | first place. If we didn't do this, stepping through e.g., | |
7139 | Thumb-2 IT blocks would break. */ | |
7140 | return bpaddr; | |
7141 | } | |
76897487 KB |
7142 | else |
7143 | { | |
7144 | CORE_ADDR adjusted_bpaddr; | |
7145 | ||
7146 | /* Some targets have architectural constraints on the placement | |
7147 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7148 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7149 | |
7150 | /* An adjusted breakpoint address can significantly alter | |
7151 | a user's expectations. Print a warning if an adjustment | |
7152 | is required. */ | |
7153 | if (adjusted_bpaddr != bpaddr) | |
7154 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7155 | ||
7156 | return adjusted_bpaddr; | |
7157 | } | |
7158 | } | |
7159 | ||
28010a5d PA |
7160 | void |
7161 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7162 | struct breakpoint *owner) | |
7cc221ef | 7163 | { |
7cc221ef DJ |
7164 | memset (loc, 0, sizeof (*loc)); |
7165 | ||
348d480f PA |
7166 | gdb_assert (ops != NULL); |
7167 | ||
28010a5d PA |
7168 | loc->ops = ops; |
7169 | loc->owner = owner; | |
511a6cd4 | 7170 | loc->cond = NULL; |
b775012e | 7171 | loc->cond_bytecode = NULL; |
0d381245 VP |
7172 | loc->shlib_disabled = 0; |
7173 | loc->enabled = 1; | |
e049a4b5 | 7174 | |
28010a5d | 7175 | switch (owner->type) |
e049a4b5 DJ |
7176 | { |
7177 | case bp_breakpoint: | |
7c16b83e | 7178 | case bp_single_step: |
e049a4b5 DJ |
7179 | case bp_until: |
7180 | case bp_finish: | |
7181 | case bp_longjmp: | |
7182 | case bp_longjmp_resume: | |
e2e4d78b | 7183 | case bp_longjmp_call_dummy: |
186c406b TT |
7184 | case bp_exception: |
7185 | case bp_exception_resume: | |
e049a4b5 | 7186 | case bp_step_resume: |
2c03e5be | 7187 | case bp_hp_step_resume: |
e049a4b5 DJ |
7188 | case bp_watchpoint_scope: |
7189 | case bp_call_dummy: | |
aa7d318d | 7190 | case bp_std_terminate: |
e049a4b5 DJ |
7191 | case bp_shlib_event: |
7192 | case bp_thread_event: | |
7193 | case bp_overlay_event: | |
4efc6507 | 7194 | case bp_jit_event: |
0fd8e87f | 7195 | case bp_longjmp_master: |
aa7d318d | 7196 | case bp_std_terminate_master: |
186c406b | 7197 | case bp_exception_master: |
0e30163f JK |
7198 | case bp_gnu_ifunc_resolver: |
7199 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7200 | case bp_dprintf: |
e049a4b5 | 7201 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7202 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7203 | break; |
7204 | case bp_hardware_breakpoint: | |
7205 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7206 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7207 | break; |
7208 | case bp_hardware_watchpoint: | |
7209 | case bp_read_watchpoint: | |
7210 | case bp_access_watchpoint: | |
7211 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7212 | break; | |
7213 | case bp_watchpoint: | |
ce78b96d | 7214 | case bp_catchpoint: |
15c3d785 PA |
7215 | case bp_tracepoint: |
7216 | case bp_fast_tracepoint: | |
0fb4aa4b | 7217 | case bp_static_tracepoint: |
e049a4b5 DJ |
7218 | loc->loc_type = bp_loc_other; |
7219 | break; | |
7220 | default: | |
e2e0b3e5 | 7221 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7222 | } |
7223 | ||
f431efe5 | 7224 | loc->refc = 1; |
28010a5d PA |
7225 | } |
7226 | ||
7227 | /* Allocate a struct bp_location. */ | |
7228 | ||
7229 | static struct bp_location * | |
7230 | allocate_bp_location (struct breakpoint *bpt) | |
7231 | { | |
348d480f PA |
7232 | return bpt->ops->allocate_location (bpt); |
7233 | } | |
7cc221ef | 7234 | |
f431efe5 PA |
7235 | static void |
7236 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7237 | { |
348d480f | 7238 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7239 | xfree (loc); |
7240 | } | |
7241 | ||
f431efe5 PA |
7242 | /* Increment reference count. */ |
7243 | ||
7244 | static void | |
7245 | incref_bp_location (struct bp_location *bl) | |
7246 | { | |
7247 | ++bl->refc; | |
7248 | } | |
7249 | ||
7250 | /* Decrement reference count. If the reference count reaches 0, | |
7251 | destroy the bp_location. Sets *BLP to NULL. */ | |
7252 | ||
7253 | static void | |
7254 | decref_bp_location (struct bp_location **blp) | |
7255 | { | |
0807b50c PA |
7256 | gdb_assert ((*blp)->refc > 0); |
7257 | ||
f431efe5 PA |
7258 | if (--(*blp)->refc == 0) |
7259 | free_bp_location (*blp); | |
7260 | *blp = NULL; | |
7261 | } | |
7262 | ||
346774a9 | 7263 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7264 | |
346774a9 PA |
7265 | static void |
7266 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7267 | { |
346774a9 | 7268 | struct breakpoint *b1; |
c906108c | 7269 | |
346774a9 PA |
7270 | /* Add this breakpoint to the end of the chain so that a list of |
7271 | breakpoints will come out in order of increasing numbers. */ | |
7272 | ||
7273 | b1 = breakpoint_chain; | |
7274 | if (b1 == 0) | |
7275 | breakpoint_chain = b; | |
7276 | else | |
7277 | { | |
7278 | while (b1->next) | |
7279 | b1 = b1->next; | |
7280 | b1->next = b; | |
7281 | } | |
7282 | } | |
7283 | ||
7284 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7285 | ||
7286 | static void | |
7287 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7288 | struct gdbarch *gdbarch, | |
28010a5d | 7289 | enum bptype bptype, |
c0a91b2b | 7290 | const struct breakpoint_ops *ops) |
346774a9 | 7291 | { |
c906108c | 7292 | memset (b, 0, sizeof (*b)); |
2219d63c | 7293 | |
348d480f PA |
7294 | gdb_assert (ops != NULL); |
7295 | ||
28010a5d | 7296 | b->ops = ops; |
4d28f7a8 | 7297 | b->type = bptype; |
a6d9a66e | 7298 | b->gdbarch = gdbarch; |
c906108c SS |
7299 | b->language = current_language->la_language; |
7300 | b->input_radix = input_radix; | |
7301 | b->thread = -1; | |
b5de0fa7 | 7302 | b->enable_state = bp_enabled; |
c906108c SS |
7303 | b->next = 0; |
7304 | b->silent = 0; | |
7305 | b->ignore_count = 0; | |
7306 | b->commands = NULL; | |
818dd999 | 7307 | b->frame_id = null_frame_id; |
0d381245 | 7308 | b->condition_not_parsed = 0; |
84f4c1fe | 7309 | b->py_bp_object = NULL; |
d0fb5eae | 7310 | b->related_breakpoint = b; |
346774a9 PA |
7311 | } |
7312 | ||
7313 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7314 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7315 | |
7316 | static struct breakpoint * | |
7317 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7318 | enum bptype bptype, |
c0a91b2b | 7319 | const struct breakpoint_ops *ops) |
346774a9 PA |
7320 | { |
7321 | struct breakpoint *b = XNEW (struct breakpoint); | |
7322 | ||
348d480f | 7323 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7324 | add_to_breakpoint_chain (b); |
0d381245 VP |
7325 | return b; |
7326 | } | |
7327 | ||
0e30163f JK |
7328 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7329 | resolutions should be made as the user specified the location explicitly | |
7330 | enough. */ | |
7331 | ||
0d381245 | 7332 | static void |
0e30163f | 7333 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7334 | { |
2bdf28a0 JK |
7335 | gdb_assert (loc->owner != NULL); |
7336 | ||
0d381245 | 7337 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7338 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7339 | || is_tracepoint (loc->owner)) |
0d381245 | 7340 | { |
0e30163f | 7341 | int is_gnu_ifunc; |
2c02bd72 | 7342 | const char *function_name; |
6a3a010b | 7343 | CORE_ADDR func_addr; |
0e30163f | 7344 | |
2c02bd72 | 7345 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7346 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7347 | |
7348 | if (is_gnu_ifunc && !explicit_loc) | |
7349 | { | |
7350 | struct breakpoint *b = loc->owner; | |
7351 | ||
7352 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7353 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7354 | &loc->requested_address)) |
7355 | { | |
7356 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7357 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7358 | loc->requested_address, | |
7359 | b->type); | |
7360 | } | |
7361 | else if (b->type == bp_breakpoint && b->loc == loc | |
7362 | && loc->next == NULL && b->related_breakpoint == b) | |
7363 | { | |
7364 | /* Create only the whole new breakpoint of this type but do not | |
7365 | mess more complicated breakpoints with multiple locations. */ | |
7366 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7367 | /* Remember the resolver's address for use by the return |
7368 | breakpoint. */ | |
7369 | loc->related_address = func_addr; | |
0e30163f JK |
7370 | } |
7371 | } | |
7372 | ||
2c02bd72 DE |
7373 | if (function_name) |
7374 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7375 | } |
7376 | } | |
7377 | ||
a6d9a66e | 7378 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7379 | struct gdbarch * |
a6d9a66e UW |
7380 | get_sal_arch (struct symtab_and_line sal) |
7381 | { | |
7382 | if (sal.section) | |
7383 | return get_objfile_arch (sal.section->objfile); | |
7384 | if (sal.symtab) | |
eb822aa6 | 7385 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7386 | |
7387 | return NULL; | |
7388 | } | |
7389 | ||
346774a9 PA |
7390 | /* Low level routine for partially initializing a breakpoint of type |
7391 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7392 | file name, and line number are provided by SAL. |
0d381245 VP |
7393 | |
7394 | It is expected that the caller will complete the initialization of | |
7395 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7396 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7397 | |
346774a9 PA |
7398 | static void |
7399 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7400 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7401 | const struct breakpoint_ops *ops) |
0d381245 | 7402 | { |
28010a5d | 7403 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7404 | |
3742cc8b | 7405 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7406 | |
6c95b8df PA |
7407 | if (bptype != bp_catchpoint) |
7408 | gdb_assert (sal.pspace != NULL); | |
7409 | ||
f8eba3c6 TT |
7410 | /* Store the program space that was used to set the breakpoint, |
7411 | except for ordinary breakpoints, which are independent of the | |
7412 | program space. */ | |
7413 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7414 | b->pspace = sal.pspace; | |
346774a9 | 7415 | } |
c906108c | 7416 | |
346774a9 PA |
7417 | /* set_raw_breakpoint is a low level routine for allocating and |
7418 | partially initializing a breakpoint of type BPTYPE. The newly | |
7419 | created breakpoint's address, section, source file name, and line | |
7420 | number are provided by SAL. The newly created and partially | |
7421 | initialized breakpoint is added to the breakpoint chain and | |
7422 | is also returned as the value of this function. | |
7423 | ||
7424 | It is expected that the caller will complete the initialization of | |
7425 | the newly created breakpoint struct as well as output any status | |
7426 | information regarding the creation of a new breakpoint. In | |
7427 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7428 | number! Care should be taken to not allow an error to occur | |
7429 | prior to completing the initialization of the breakpoint. If this | |
7430 | should happen, a bogus breakpoint will be left on the chain. */ | |
7431 | ||
7432 | struct breakpoint * | |
7433 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7434 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7435 | const struct breakpoint_ops *ops) |
346774a9 PA |
7436 | { |
7437 | struct breakpoint *b = XNEW (struct breakpoint); | |
7438 | ||
348d480f | 7439 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7440 | add_to_breakpoint_chain (b); |
c906108c SS |
7441 | return b; |
7442 | } | |
7443 | ||
53a5351d | 7444 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7445 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7446 | initiated the operation. */ | |
c906108c SS |
7447 | |
7448 | void | |
186c406b | 7449 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7450 | { |
35df4500 | 7451 | struct breakpoint *b, *b_tmp; |
186c406b | 7452 | int thread = tp->num; |
0fd8e87f UW |
7453 | |
7454 | /* To avoid having to rescan all objfile symbols at every step, | |
7455 | we maintain a list of continually-inserted but always disabled | |
7456 | longjmp "master" breakpoints. Here, we simply create momentary | |
7457 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7458 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7459 | if (b->pspace == current_program_space |
186c406b TT |
7460 | && (b->type == bp_longjmp_master |
7461 | || b->type == bp_exception_master)) | |
0fd8e87f | 7462 | { |
06edf0c0 PA |
7463 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7464 | struct breakpoint *clone; | |
cc59ec59 | 7465 | |
e2e4d78b JK |
7466 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7467 | after their removal. */ | |
06edf0c0 | 7468 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7469 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7470 | clone->thread = thread; |
7471 | } | |
186c406b TT |
7472 | |
7473 | tp->initiating_frame = frame; | |
c906108c SS |
7474 | } |
7475 | ||
611c83ae | 7476 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7477 | void |
611c83ae | 7478 | delete_longjmp_breakpoint (int thread) |
c906108c | 7479 | { |
35df4500 | 7480 | struct breakpoint *b, *b_tmp; |
c906108c | 7481 | |
35df4500 | 7482 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7483 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7484 | { |
7485 | if (b->thread == thread) | |
7486 | delete_breakpoint (b); | |
7487 | } | |
c906108c SS |
7488 | } |
7489 | ||
f59f708a PA |
7490 | void |
7491 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7492 | { | |
7493 | struct breakpoint *b, *b_tmp; | |
7494 | ||
7495 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7496 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7497 | { | |
7498 | if (b->thread == thread) | |
7499 | b->disposition = disp_del_at_next_stop; | |
7500 | } | |
7501 | } | |
7502 | ||
e2e4d78b JK |
7503 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7504 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7505 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7506 | breakpoints. */ | |
7507 | ||
7508 | struct breakpoint * | |
7509 | set_longjmp_breakpoint_for_call_dummy (void) | |
7510 | { | |
7511 | struct breakpoint *b, *retval = NULL; | |
7512 | ||
7513 | ALL_BREAKPOINTS (b) | |
7514 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7515 | { | |
7516 | struct breakpoint *new_b; | |
7517 | ||
7518 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7519 | &momentary_breakpoint_ops, |
7520 | 1); | |
e2e4d78b JK |
7521 | new_b->thread = pid_to_thread_id (inferior_ptid); |
7522 | ||
7523 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7524 | ||
7525 | gdb_assert (new_b->related_breakpoint == new_b); | |
7526 | if (retval == NULL) | |
7527 | retval = new_b; | |
7528 | new_b->related_breakpoint = retval; | |
7529 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7530 | retval = retval->related_breakpoint; | |
7531 | retval->related_breakpoint = new_b; | |
7532 | } | |
7533 | ||
7534 | return retval; | |
7535 | } | |
7536 | ||
7537 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7538 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7539 | stack. |
7540 | ||
7541 | You should call this function only at places where it is safe to currently | |
7542 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7543 | frames. */ | |
7544 | ||
7545 | void | |
b67a2c6f | 7546 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7547 | { |
7548 | struct breakpoint *b, *b_tmp; | |
7549 | ||
7550 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
b67a2c6f | 7551 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->num) |
e2e4d78b JK |
7552 | { |
7553 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7554 | ||
7555 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7556 | dummy_b = dummy_b->related_breakpoint; | |
7557 | if (dummy_b->type != bp_call_dummy | |
7558 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7559 | continue; | |
7560 | ||
b67a2c6f | 7561 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7562 | |
7563 | while (b->related_breakpoint != b) | |
7564 | { | |
7565 | if (b_tmp == b->related_breakpoint) | |
7566 | b_tmp = b->related_breakpoint->next; | |
7567 | delete_breakpoint (b->related_breakpoint); | |
7568 | } | |
7569 | delete_breakpoint (b); | |
7570 | } | |
7571 | } | |
7572 | ||
1900040c MS |
7573 | void |
7574 | enable_overlay_breakpoints (void) | |
7575 | { | |
52f0bd74 | 7576 | struct breakpoint *b; |
1900040c MS |
7577 | |
7578 | ALL_BREAKPOINTS (b) | |
7579 | if (b->type == bp_overlay_event) | |
7580 | { | |
7581 | b->enable_state = bp_enabled; | |
44702360 | 7582 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7583 | overlay_events_enabled = 1; |
1900040c MS |
7584 | } |
7585 | } | |
7586 | ||
7587 | void | |
7588 | disable_overlay_breakpoints (void) | |
7589 | { | |
52f0bd74 | 7590 | struct breakpoint *b; |
1900040c MS |
7591 | |
7592 | ALL_BREAKPOINTS (b) | |
7593 | if (b->type == bp_overlay_event) | |
7594 | { | |
7595 | b->enable_state = bp_disabled; | |
44702360 | 7596 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7597 | overlay_events_enabled = 0; |
1900040c MS |
7598 | } |
7599 | } | |
7600 | ||
aa7d318d TT |
7601 | /* Set an active std::terminate breakpoint for each std::terminate |
7602 | master breakpoint. */ | |
7603 | void | |
7604 | set_std_terminate_breakpoint (void) | |
7605 | { | |
35df4500 | 7606 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7607 | |
35df4500 | 7608 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7609 | if (b->pspace == current_program_space |
7610 | && b->type == bp_std_terminate_master) | |
7611 | { | |
06edf0c0 | 7612 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7613 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7614 | } |
7615 | } | |
7616 | ||
7617 | /* Delete all the std::terminate breakpoints. */ | |
7618 | void | |
7619 | delete_std_terminate_breakpoint (void) | |
7620 | { | |
35df4500 | 7621 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7622 | |
35df4500 | 7623 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7624 | if (b->type == bp_std_terminate) |
7625 | delete_breakpoint (b); | |
7626 | } | |
7627 | ||
c4093a6a | 7628 | struct breakpoint * |
a6d9a66e | 7629 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7630 | { |
7631 | struct breakpoint *b; | |
c4093a6a | 7632 | |
06edf0c0 PA |
7633 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7634 | &internal_breakpoint_ops); | |
7635 | ||
b5de0fa7 | 7636 | b->enable_state = bp_enabled; |
c4093a6a | 7637 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
7638 | b->addr_string |
7639 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 7640 | |
44702360 | 7641 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7642 | |
c4093a6a JM |
7643 | return b; |
7644 | } | |
7645 | ||
7646 | void | |
7647 | remove_thread_event_breakpoints (void) | |
7648 | { | |
35df4500 | 7649 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7650 | |
35df4500 | 7651 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7652 | if (b->type == bp_thread_event |
7653 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7654 | delete_breakpoint (b); |
7655 | } | |
7656 | ||
0101ce28 JJ |
7657 | struct lang_and_radix |
7658 | { | |
7659 | enum language lang; | |
7660 | int radix; | |
7661 | }; | |
7662 | ||
4efc6507 DE |
7663 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7664 | ||
7665 | struct breakpoint * | |
7666 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7667 | { | |
7668 | struct breakpoint *b; | |
7669 | ||
06edf0c0 PA |
7670 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7671 | &internal_breakpoint_ops); | |
44702360 | 7672 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
4efc6507 DE |
7673 | return b; |
7674 | } | |
0101ce28 | 7675 | |
03673fc7 PP |
7676 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7677 | ||
7678 | void | |
7679 | remove_jit_event_breakpoints (void) | |
7680 | { | |
7681 | struct breakpoint *b, *b_tmp; | |
7682 | ||
7683 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7684 | if (b->type == bp_jit_event | |
7685 | && b->loc->pspace == current_program_space) | |
7686 | delete_breakpoint (b); | |
7687 | } | |
7688 | ||
cae688ec JJ |
7689 | void |
7690 | remove_solib_event_breakpoints (void) | |
7691 | { | |
35df4500 | 7692 | struct breakpoint *b, *b_tmp; |
cae688ec | 7693 | |
35df4500 | 7694 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7695 | if (b->type == bp_shlib_event |
7696 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7697 | delete_breakpoint (b); |
7698 | } | |
7699 | ||
f37f681c PA |
7700 | /* See breakpoint.h. */ |
7701 | ||
7702 | void | |
7703 | remove_solib_event_breakpoints_at_next_stop (void) | |
7704 | { | |
7705 | struct breakpoint *b, *b_tmp; | |
7706 | ||
7707 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7708 | if (b->type == bp_shlib_event | |
7709 | && b->loc->pspace == current_program_space) | |
7710 | b->disposition = disp_del_at_next_stop; | |
7711 | } | |
7712 | ||
04086b45 PA |
7713 | /* Helper for create_solib_event_breakpoint / |
7714 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7715 | INSERT_MODE to pass through to update_global_location_list. */ | |
7716 | ||
7717 | static struct breakpoint * | |
7718 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7719 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7720 | { |
7721 | struct breakpoint *b; | |
7722 | ||
06edf0c0 PA |
7723 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7724 | &internal_breakpoint_ops); | |
04086b45 | 7725 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7726 | return b; |
7727 | } | |
7728 | ||
04086b45 PA |
7729 | struct breakpoint * |
7730 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7731 | { | |
7732 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7733 | } | |
7734 | ||
f37f681c PA |
7735 | /* See breakpoint.h. */ |
7736 | ||
7737 | struct breakpoint * | |
7738 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7739 | { | |
7740 | struct breakpoint *b; | |
7741 | ||
04086b45 PA |
7742 | /* Explicitly tell update_global_location_list to insert |
7743 | locations. */ | |
7744 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7745 | if (!b->loc->inserted) |
7746 | { | |
7747 | delete_breakpoint (b); | |
7748 | return NULL; | |
7749 | } | |
7750 | return b; | |
7751 | } | |
7752 | ||
cae688ec JJ |
7753 | /* Disable any breakpoints that are on code in shared libraries. Only |
7754 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7755 | ||
7756 | void | |
cb851954 | 7757 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7758 | { |
876fa593 | 7759 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7760 | |
876fa593 | 7761 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7762 | { |
2bdf28a0 | 7763 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7764 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7765 | |
4a64f543 MS |
7766 | /* We apply the check to all breakpoints, including disabled for |
7767 | those with loc->duplicate set. This is so that when breakpoint | |
7768 | becomes enabled, or the duplicate is removed, gdb will try to | |
7769 | insert all breakpoints. If we don't set shlib_disabled here, | |
7770 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7771 | if (((b->type == bp_breakpoint) |
508ccb1f | 7772 | || (b->type == bp_jit_event) |
1042e4c0 | 7773 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7774 | || (is_tracepoint (b))) |
6c95b8df | 7775 | && loc->pspace == current_program_space |
0d381245 | 7776 | && !loc->shlib_disabled |
6c95b8df | 7777 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7778 | ) |
0d381245 VP |
7779 | { |
7780 | loc->shlib_disabled = 1; | |
7781 | } | |
cae688ec JJ |
7782 | } |
7783 | } | |
7784 | ||
63644780 NB |
7785 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7786 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7787 | disabled ones can just stay disabled. */ | |
84acb35a | 7788 | |
75149521 | 7789 | static void |
84acb35a JJ |
7790 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7791 | { | |
876fa593 | 7792 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7793 | int disabled_shlib_breaks = 0; |
7794 | ||
c86cf029 VP |
7795 | /* SunOS a.out shared libraries are always mapped, so do not |
7796 | disable breakpoints; they will only be reported as unloaded | |
7797 | through clear_solib when GDB discards its shared library | |
7798 | list. See clear_solib for more information. */ | |
7799 | if (exec_bfd != NULL | |
7800 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7801 | return; | |
7802 | ||
876fa593 | 7803 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7804 | { |
2bdf28a0 | 7805 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7806 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7807 | |
1e4d1764 | 7808 | if (solib->pspace == loc->pspace |
e2dd7057 | 7809 | && !loc->shlib_disabled |
1e4d1764 YQ |
7810 | && (((b->type == bp_breakpoint |
7811 | || b->type == bp_jit_event | |
7812 | || b->type == bp_hardware_breakpoint) | |
7813 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7814 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7815 | || is_tracepoint (b)) | |
e2dd7057 | 7816 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7817 | { |
e2dd7057 PP |
7818 | loc->shlib_disabled = 1; |
7819 | /* At this point, we cannot rely on remove_breakpoint | |
7820 | succeeding so we must mark the breakpoint as not inserted | |
7821 | to prevent future errors occurring in remove_breakpoints. */ | |
7822 | loc->inserted = 0; | |
8d3788bd VP |
7823 | |
7824 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7825 | observer_notify_breakpoint_modified (b); | |
7826 | ||
e2dd7057 PP |
7827 | if (!disabled_shlib_breaks) |
7828 | { | |
7829 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7830 | warning (_("Temporarily disabling breakpoints " |
7831 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7832 | solib->so_name); |
84acb35a | 7833 | } |
e2dd7057 | 7834 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7835 | } |
7836 | } | |
84acb35a JJ |
7837 | } |
7838 | ||
63644780 NB |
7839 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7840 | notification of free_objfile. Only apply to enabled breakpoints, | |
7841 | disabled ones can just stay disabled. */ | |
7842 | ||
7843 | static void | |
7844 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7845 | { | |
7846 | struct breakpoint *b; | |
7847 | ||
7848 | if (objfile == NULL) | |
7849 | return; | |
7850 | ||
d03de421 PA |
7851 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7852 | managed by the user with add-symbol-file/remove-symbol-file. | |
7853 | Similarly to how breakpoints in shared libraries are handled in | |
7854 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7855 | shlib_disabled so they end up uninserted on the next global |
7856 | location list update. Shared libraries not loaded by the user | |
7857 | aren't handled here -- they're already handled in | |
7858 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7859 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7860 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7861 | main objfile). */ | |
7862 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7863 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7864 | return; |
7865 | ||
7866 | ALL_BREAKPOINTS (b) | |
7867 | { | |
7868 | struct bp_location *loc; | |
7869 | int bp_modified = 0; | |
7870 | ||
7871 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7872 | continue; | |
7873 | ||
7874 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7875 | { | |
7876 | CORE_ADDR loc_addr = loc->address; | |
7877 | ||
7878 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7879 | && loc->loc_type != bp_loc_software_breakpoint) | |
7880 | continue; | |
7881 | ||
7882 | if (loc->shlib_disabled != 0) | |
7883 | continue; | |
7884 | ||
7885 | if (objfile->pspace != loc->pspace) | |
7886 | continue; | |
7887 | ||
7888 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7889 | && loc->loc_type != bp_loc_software_breakpoint) | |
7890 | continue; | |
7891 | ||
7892 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7893 | { | |
7894 | loc->shlib_disabled = 1; | |
08351840 PA |
7895 | /* At this point, we don't know whether the object was |
7896 | unmapped from the inferior or not, so leave the | |
7897 | inserted flag alone. We'll handle failure to | |
7898 | uninsert quietly, in case the object was indeed | |
7899 | unmapped. */ | |
63644780 NB |
7900 | |
7901 | mark_breakpoint_location_modified (loc); | |
7902 | ||
7903 | bp_modified = 1; | |
7904 | } | |
7905 | } | |
7906 | ||
7907 | if (bp_modified) | |
7908 | observer_notify_breakpoint_modified (b); | |
7909 | } | |
7910 | } | |
7911 | ||
ce78b96d JB |
7912 | /* FORK & VFORK catchpoints. */ |
7913 | ||
e29a4733 PA |
7914 | /* An instance of this type is used to represent a fork or vfork |
7915 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
7916 | class; users downcast to "struct breakpoint *" when needed. A | |
7917 | breakpoint is really of this type iff its ops pointer points to | |
7918 | CATCH_FORK_BREAKPOINT_OPS. */ | |
7919 | ||
7920 | struct fork_catchpoint | |
7921 | { | |
7922 | /* The base class. */ | |
7923 | struct breakpoint base; | |
7924 | ||
7925 | /* Process id of a child process whose forking triggered this | |
7926 | catchpoint. This field is only valid immediately after this | |
7927 | catchpoint has triggered. */ | |
7928 | ptid_t forked_inferior_pid; | |
7929 | }; | |
7930 | ||
4a64f543 MS |
7931 | /* Implement the "insert" breakpoint_ops method for fork |
7932 | catchpoints. */ | |
ce78b96d | 7933 | |
77b06cd7 TJB |
7934 | static int |
7935 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7936 | { |
dfd4cc63 | 7937 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7938 | } |
7939 | ||
4a64f543 MS |
7940 | /* Implement the "remove" breakpoint_ops method for fork |
7941 | catchpoints. */ | |
ce78b96d JB |
7942 | |
7943 | static int | |
77b06cd7 | 7944 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 7945 | { |
dfd4cc63 | 7946 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7947 | } |
7948 | ||
7949 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7950 | catchpoints. */ | |
7951 | ||
7952 | static int | |
f1310107 | 7953 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7954 | struct address_space *aspace, CORE_ADDR bp_addr, |
7955 | const struct target_waitstatus *ws) | |
ce78b96d | 7956 | { |
e29a4733 PA |
7957 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7958 | ||
f90263c1 TT |
7959 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7960 | return 0; | |
7961 | ||
7962 | c->forked_inferior_pid = ws->value.related_pid; | |
7963 | return 1; | |
ce78b96d JB |
7964 | } |
7965 | ||
4a64f543 MS |
7966 | /* Implement the "print_it" breakpoint_ops method for fork |
7967 | catchpoints. */ | |
ce78b96d JB |
7968 | |
7969 | static enum print_stop_action | |
348d480f | 7970 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7971 | { |
36dfb11c | 7972 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7973 | struct breakpoint *b = bs->breakpoint_at; |
7974 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7975 | |
ce78b96d | 7976 | annotate_catchpoint (b->number); |
36dfb11c TT |
7977 | if (b->disposition == disp_del) |
7978 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7979 | else | |
7980 | ui_out_text (uiout, "\nCatchpoint "); | |
7981 | if (ui_out_is_mi_like_p (uiout)) | |
7982 | { | |
7983 | ui_out_field_string (uiout, "reason", | |
7984 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
7985 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7986 | } | |
7987 | ui_out_field_int (uiout, "bkptno", b->number); | |
7988 | ui_out_text (uiout, " (forked process "); | |
7989 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7990 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7991 | return PRINT_SRC_AND_LOC; |
7992 | } | |
7993 | ||
4a64f543 MS |
7994 | /* Implement the "print_one" breakpoint_ops method for fork |
7995 | catchpoints. */ | |
ce78b96d JB |
7996 | |
7997 | static void | |
a6d9a66e | 7998 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7999 | { |
e29a4733 | 8000 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8001 | struct value_print_options opts; |
79a45e25 | 8002 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8003 | |
8004 | get_user_print_options (&opts); | |
8005 | ||
4a64f543 MS |
8006 | /* Field 4, the address, is omitted (which makes the columns not |
8007 | line up too nicely with the headers, but the effect is relatively | |
8008 | readable). */ | |
79a45b7d | 8009 | if (opts.addressprint) |
ce78b96d JB |
8010 | ui_out_field_skip (uiout, "addr"); |
8011 | annotate_field (5); | |
8012 | ui_out_text (uiout, "fork"); | |
e29a4733 | 8013 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8014 | { |
8015 | ui_out_text (uiout, ", process "); | |
8016 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8017 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8018 | ui_out_spaces (uiout, 1); |
8019 | } | |
8ac3646f TT |
8020 | |
8021 | if (ui_out_is_mi_like_p (uiout)) | |
8022 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
8023 | } |
8024 | ||
8025 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8026 | catchpoints. */ | |
8027 | ||
8028 | static void | |
8029 | print_mention_catch_fork (struct breakpoint *b) | |
8030 | { | |
8031 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8032 | } | |
8033 | ||
6149aea9 PA |
8034 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8035 | catchpoints. */ | |
8036 | ||
8037 | static void | |
8038 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8039 | { | |
8040 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8041 | print_recreate_thread (b, fp); |
6149aea9 PA |
8042 | } |
8043 | ||
ce78b96d JB |
8044 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8045 | ||
2060206e | 8046 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8047 | |
4a64f543 MS |
8048 | /* Implement the "insert" breakpoint_ops method for vfork |
8049 | catchpoints. */ | |
ce78b96d | 8050 | |
77b06cd7 TJB |
8051 | static int |
8052 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8053 | { |
dfd4cc63 | 8054 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8055 | } |
8056 | ||
4a64f543 MS |
8057 | /* Implement the "remove" breakpoint_ops method for vfork |
8058 | catchpoints. */ | |
ce78b96d JB |
8059 | |
8060 | static int | |
77b06cd7 | 8061 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 8062 | { |
dfd4cc63 | 8063 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8064 | } |
8065 | ||
8066 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8067 | catchpoints. */ | |
8068 | ||
8069 | static int | |
f1310107 | 8070 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8071 | struct address_space *aspace, CORE_ADDR bp_addr, |
8072 | const struct target_waitstatus *ws) | |
ce78b96d | 8073 | { |
e29a4733 PA |
8074 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8075 | ||
f90263c1 TT |
8076 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8077 | return 0; | |
8078 | ||
8079 | c->forked_inferior_pid = ws->value.related_pid; | |
8080 | return 1; | |
ce78b96d JB |
8081 | } |
8082 | ||
4a64f543 MS |
8083 | /* Implement the "print_it" breakpoint_ops method for vfork |
8084 | catchpoints. */ | |
ce78b96d JB |
8085 | |
8086 | static enum print_stop_action | |
348d480f | 8087 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8088 | { |
36dfb11c | 8089 | struct ui_out *uiout = current_uiout; |
348d480f | 8090 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8091 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8092 | ||
ce78b96d | 8093 | annotate_catchpoint (b->number); |
36dfb11c TT |
8094 | if (b->disposition == disp_del) |
8095 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8096 | else | |
8097 | ui_out_text (uiout, "\nCatchpoint "); | |
8098 | if (ui_out_is_mi_like_p (uiout)) | |
8099 | { | |
8100 | ui_out_field_string (uiout, "reason", | |
8101 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8102 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8103 | } | |
8104 | ui_out_field_int (uiout, "bkptno", b->number); | |
8105 | ui_out_text (uiout, " (vforked process "); | |
8106 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8107 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8108 | return PRINT_SRC_AND_LOC; |
8109 | } | |
8110 | ||
4a64f543 MS |
8111 | /* Implement the "print_one" breakpoint_ops method for vfork |
8112 | catchpoints. */ | |
ce78b96d JB |
8113 | |
8114 | static void | |
a6d9a66e | 8115 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8116 | { |
e29a4733 | 8117 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8118 | struct value_print_options opts; |
79a45e25 | 8119 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8120 | |
8121 | get_user_print_options (&opts); | |
4a64f543 MS |
8122 | /* Field 4, the address, is omitted (which makes the columns not |
8123 | line up too nicely with the headers, but the effect is relatively | |
8124 | readable). */ | |
79a45b7d | 8125 | if (opts.addressprint) |
ce78b96d JB |
8126 | ui_out_field_skip (uiout, "addr"); |
8127 | annotate_field (5); | |
8128 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8129 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8130 | { |
8131 | ui_out_text (uiout, ", process "); | |
8132 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8133 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8134 | ui_out_spaces (uiout, 1); |
8135 | } | |
8ac3646f TT |
8136 | |
8137 | if (ui_out_is_mi_like_p (uiout)) | |
8138 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8139 | } |
8140 | ||
8141 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8142 | catchpoints. */ | |
8143 | ||
8144 | static void | |
8145 | print_mention_catch_vfork (struct breakpoint *b) | |
8146 | { | |
8147 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8148 | } | |
8149 | ||
6149aea9 PA |
8150 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8151 | catchpoints. */ | |
8152 | ||
8153 | static void | |
8154 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8155 | { | |
8156 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8157 | print_recreate_thread (b, fp); |
6149aea9 PA |
8158 | } |
8159 | ||
ce78b96d JB |
8160 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8161 | ||
2060206e | 8162 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8163 | |
edcc5120 TT |
8164 | /* An instance of this type is used to represent an solib catchpoint. |
8165 | It includes a "struct breakpoint" as a kind of base class; users | |
8166 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8167 | really of this type iff its ops pointer points to | |
8168 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8169 | ||
8170 | struct solib_catchpoint | |
8171 | { | |
8172 | /* The base class. */ | |
8173 | struct breakpoint base; | |
8174 | ||
8175 | /* True for "catch load", false for "catch unload". */ | |
8176 | unsigned char is_load; | |
8177 | ||
8178 | /* Regular expression to match, if any. COMPILED is only valid when | |
8179 | REGEX is non-NULL. */ | |
8180 | char *regex; | |
8181 | regex_t compiled; | |
8182 | }; | |
8183 | ||
8184 | static void | |
8185 | dtor_catch_solib (struct breakpoint *b) | |
8186 | { | |
8187 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8188 | ||
8189 | if (self->regex) | |
8190 | regfree (&self->compiled); | |
8191 | xfree (self->regex); | |
8192 | ||
8193 | base_breakpoint_ops.dtor (b); | |
8194 | } | |
8195 | ||
8196 | static int | |
8197 | insert_catch_solib (struct bp_location *ignore) | |
8198 | { | |
8199 | return 0; | |
8200 | } | |
8201 | ||
8202 | static int | |
8203 | remove_catch_solib (struct bp_location *ignore) | |
8204 | { | |
8205 | return 0; | |
8206 | } | |
8207 | ||
8208 | static int | |
8209 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8210 | struct address_space *aspace, | |
8211 | CORE_ADDR bp_addr, | |
8212 | const struct target_waitstatus *ws) | |
8213 | { | |
8214 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8215 | struct breakpoint *other; | |
8216 | ||
8217 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8218 | return 1; | |
8219 | ||
8220 | ALL_BREAKPOINTS (other) | |
8221 | { | |
8222 | struct bp_location *other_bl; | |
8223 | ||
8224 | if (other == bl->owner) | |
8225 | continue; | |
8226 | ||
8227 | if (other->type != bp_shlib_event) | |
8228 | continue; | |
8229 | ||
8230 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8231 | continue; | |
8232 | ||
8233 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8234 | { | |
8235 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8236 | return 1; | |
8237 | } | |
8238 | } | |
8239 | ||
8240 | return 0; | |
8241 | } | |
8242 | ||
8243 | static void | |
8244 | check_status_catch_solib (struct bpstats *bs) | |
8245 | { | |
8246 | struct solib_catchpoint *self | |
8247 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8248 | int ix; | |
8249 | ||
8250 | if (self->is_load) | |
8251 | { | |
8252 | struct so_list *iter; | |
8253 | ||
8254 | for (ix = 0; | |
8255 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8256 | ix, iter); | |
8257 | ++ix) | |
8258 | { | |
8259 | if (!self->regex | |
8260 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8261 | return; | |
8262 | } | |
8263 | } | |
8264 | else | |
8265 | { | |
8266 | char *iter; | |
8267 | ||
8268 | for (ix = 0; | |
8269 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8270 | ix, iter); | |
8271 | ++ix) | |
8272 | { | |
8273 | if (!self->regex | |
8274 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8275 | return; | |
8276 | } | |
8277 | } | |
8278 | ||
8279 | bs->stop = 0; | |
8280 | bs->print_it = print_it_noop; | |
8281 | } | |
8282 | ||
8283 | static enum print_stop_action | |
8284 | print_it_catch_solib (bpstat bs) | |
8285 | { | |
8286 | struct breakpoint *b = bs->breakpoint_at; | |
8287 | struct ui_out *uiout = current_uiout; | |
8288 | ||
8289 | annotate_catchpoint (b->number); | |
8290 | if (b->disposition == disp_del) | |
8291 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8292 | else | |
8293 | ui_out_text (uiout, "\nCatchpoint "); | |
8294 | ui_out_field_int (uiout, "bkptno", b->number); | |
8295 | ui_out_text (uiout, "\n"); | |
8296 | if (ui_out_is_mi_like_p (uiout)) | |
8297 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8298 | print_solib_event (1); | |
8299 | return PRINT_SRC_AND_LOC; | |
8300 | } | |
8301 | ||
8302 | static void | |
8303 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8304 | { | |
8305 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8306 | struct value_print_options opts; | |
8307 | struct ui_out *uiout = current_uiout; | |
8308 | char *msg; | |
8309 | ||
8310 | get_user_print_options (&opts); | |
8311 | /* Field 4, the address, is omitted (which makes the columns not | |
8312 | line up too nicely with the headers, but the effect is relatively | |
8313 | readable). */ | |
8314 | if (opts.addressprint) | |
8315 | { | |
8316 | annotate_field (4); | |
8317 | ui_out_field_skip (uiout, "addr"); | |
8318 | } | |
8319 | ||
8320 | annotate_field (5); | |
8321 | if (self->is_load) | |
8322 | { | |
8323 | if (self->regex) | |
8324 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8325 | else | |
8326 | msg = xstrdup (_("load of library")); | |
8327 | } | |
8328 | else | |
8329 | { | |
8330 | if (self->regex) | |
8331 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8332 | else | |
8333 | msg = xstrdup (_("unload of library")); | |
8334 | } | |
8335 | ui_out_field_string (uiout, "what", msg); | |
8336 | xfree (msg); | |
8ac3646f TT |
8337 | |
8338 | if (ui_out_is_mi_like_p (uiout)) | |
8339 | ui_out_field_string (uiout, "catch-type", | |
8340 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8341 | } |
8342 | ||
8343 | static void | |
8344 | print_mention_catch_solib (struct breakpoint *b) | |
8345 | { | |
8346 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8347 | ||
8348 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8349 | self->is_load ? "load" : "unload"); | |
8350 | } | |
8351 | ||
8352 | static void | |
8353 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8354 | { | |
8355 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8356 | ||
8357 | fprintf_unfiltered (fp, "%s %s", | |
8358 | b->disposition == disp_del ? "tcatch" : "catch", | |
8359 | self->is_load ? "load" : "unload"); | |
8360 | if (self->regex) | |
8361 | fprintf_unfiltered (fp, " %s", self->regex); | |
8362 | fprintf_unfiltered (fp, "\n"); | |
8363 | } | |
8364 | ||
8365 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8366 | ||
91985142 MG |
8367 | /* Shared helper function (MI and CLI) for creating and installing |
8368 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8369 | the events to be caught are load events, otherwise they are | |
8370 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8371 | temporary one. If ENABLED is non-zero the catchpoint is | |
8372 | created in an enabled state. */ | |
edcc5120 | 8373 | |
91985142 MG |
8374 | void |
8375 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8376 | { |
8377 | struct solib_catchpoint *c; | |
8378 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8379 | struct cleanup *cleanup; |
8380 | ||
edcc5120 TT |
8381 | if (!arg) |
8382 | arg = ""; | |
8383 | arg = skip_spaces (arg); | |
8384 | ||
8385 | c = XCNEW (struct solib_catchpoint); | |
8386 | cleanup = make_cleanup (xfree, c); | |
8387 | ||
8388 | if (*arg != '\0') | |
8389 | { | |
8390 | int errcode; | |
8391 | ||
8392 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8393 | if (errcode != 0) | |
8394 | { | |
8395 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8396 | ||
8397 | make_cleanup (xfree, err); | |
8398 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8399 | } | |
8400 | c->regex = xstrdup (arg); | |
8401 | } | |
8402 | ||
8403 | c->is_load = is_load; | |
91985142 | 8404 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8405 | &catch_solib_breakpoint_ops); |
8406 | ||
91985142 MG |
8407 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8408 | ||
edcc5120 TT |
8409 | discard_cleanups (cleanup); |
8410 | install_breakpoint (0, &c->base, 1); | |
8411 | } | |
8412 | ||
91985142 MG |
8413 | /* A helper function that does all the work for "catch load" and |
8414 | "catch unload". */ | |
8415 | ||
8416 | static void | |
8417 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8418 | struct cmd_list_element *command) | |
8419 | { | |
8420 | int tempflag; | |
8421 | const int enabled = 1; | |
8422 | ||
8423 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8424 | ||
8425 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8426 | } | |
8427 | ||
edcc5120 TT |
8428 | static void |
8429 | catch_load_command_1 (char *arg, int from_tty, | |
8430 | struct cmd_list_element *command) | |
8431 | { | |
8432 | catch_load_or_unload (arg, from_tty, 1, command); | |
8433 | } | |
8434 | ||
8435 | static void | |
8436 | catch_unload_command_1 (char *arg, int from_tty, | |
8437 | struct cmd_list_element *command) | |
8438 | { | |
8439 | catch_load_or_unload (arg, from_tty, 0, command); | |
8440 | } | |
8441 | ||
346774a9 PA |
8442 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8443 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8444 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8445 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8446 | |
ab04a2af | 8447 | void |
346774a9 PA |
8448 | init_catchpoint (struct breakpoint *b, |
8449 | struct gdbarch *gdbarch, int tempflag, | |
8450 | char *cond_string, | |
c0a91b2b | 8451 | const struct breakpoint_ops *ops) |
c906108c | 8452 | { |
c5aa993b | 8453 | struct symtab_and_line sal; |
346774a9 | 8454 | |
fe39c653 | 8455 | init_sal (&sal); |
6c95b8df | 8456 | sal.pspace = current_program_space; |
c5aa993b | 8457 | |
28010a5d | 8458 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8459 | |
1b36a34b | 8460 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8461 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8462 | } |
8463 | ||
28010a5d | 8464 | void |
3ea46bff | 8465 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8466 | { |
8467 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8468 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8469 | if (is_tracepoint (b)) |
8470 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8471 | if (!internal) |
8472 | mention (b); | |
c56053d2 | 8473 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8474 | |
8475 | if (update_gll) | |
44702360 | 8476 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8477 | } |
8478 | ||
9b70b993 | 8479 | static void |
a6d9a66e UW |
8480 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8481 | int tempflag, char *cond_string, | |
c0a91b2b | 8482 | const struct breakpoint_ops *ops) |
c906108c | 8483 | { |
e29a4733 | 8484 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8485 | |
e29a4733 PA |
8486 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8487 | ||
8488 | c->forked_inferior_pid = null_ptid; | |
8489 | ||
3ea46bff | 8490 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8491 | } |
8492 | ||
fe798b75 JB |
8493 | /* Exec catchpoints. */ |
8494 | ||
b4d90040 PA |
8495 | /* An instance of this type is used to represent an exec catchpoint. |
8496 | It includes a "struct breakpoint" as a kind of base class; users | |
8497 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8498 | really of this type iff its ops pointer points to | |
8499 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8500 | ||
8501 | struct exec_catchpoint | |
8502 | { | |
8503 | /* The base class. */ | |
8504 | struct breakpoint base; | |
8505 | ||
8506 | /* Filename of a program whose exec triggered this catchpoint. | |
8507 | This field is only valid immediately after this catchpoint has | |
8508 | triggered. */ | |
8509 | char *exec_pathname; | |
8510 | }; | |
8511 | ||
8512 | /* Implement the "dtor" breakpoint_ops method for exec | |
8513 | catchpoints. */ | |
8514 | ||
8515 | static void | |
8516 | dtor_catch_exec (struct breakpoint *b) | |
8517 | { | |
8518 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8519 | ||
8520 | xfree (c->exec_pathname); | |
348d480f | 8521 | |
2060206e | 8522 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8523 | } |
8524 | ||
77b06cd7 TJB |
8525 | static int |
8526 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8527 | { |
dfd4cc63 | 8528 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8529 | } |
c906108c | 8530 | |
fe798b75 | 8531 | static int |
77b06cd7 | 8532 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8533 | { |
dfd4cc63 | 8534 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8535 | } |
c906108c | 8536 | |
fe798b75 | 8537 | static int |
f1310107 | 8538 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8539 | struct address_space *aspace, CORE_ADDR bp_addr, |
8540 | const struct target_waitstatus *ws) | |
fe798b75 | 8541 | { |
b4d90040 PA |
8542 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8543 | ||
f90263c1 TT |
8544 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8545 | return 0; | |
8546 | ||
8547 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8548 | return 1; | |
fe798b75 | 8549 | } |
c906108c | 8550 | |
fe798b75 | 8551 | static enum print_stop_action |
348d480f | 8552 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8553 | { |
36dfb11c | 8554 | struct ui_out *uiout = current_uiout; |
348d480f | 8555 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8556 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8557 | ||
fe798b75 | 8558 | annotate_catchpoint (b->number); |
36dfb11c TT |
8559 | if (b->disposition == disp_del) |
8560 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8561 | else | |
8562 | ui_out_text (uiout, "\nCatchpoint "); | |
8563 | if (ui_out_is_mi_like_p (uiout)) | |
8564 | { | |
8565 | ui_out_field_string (uiout, "reason", | |
8566 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8567 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8568 | } | |
8569 | ui_out_field_int (uiout, "bkptno", b->number); | |
8570 | ui_out_text (uiout, " (exec'd "); | |
8571 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8572 | ui_out_text (uiout, "), "); | |
8573 | ||
fe798b75 | 8574 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8575 | } |
8576 | ||
fe798b75 | 8577 | static void |
a6d9a66e | 8578 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8579 | { |
b4d90040 | 8580 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8581 | struct value_print_options opts; |
79a45e25 | 8582 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8583 | |
8584 | get_user_print_options (&opts); | |
8585 | ||
8586 | /* Field 4, the address, is omitted (which makes the columns | |
8587 | not line up too nicely with the headers, but the effect | |
8588 | is relatively readable). */ | |
8589 | if (opts.addressprint) | |
8590 | ui_out_field_skip (uiout, "addr"); | |
8591 | annotate_field (5); | |
8592 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8593 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8594 | { |
8595 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8596 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8597 | ui_out_text (uiout, "\" "); |
8598 | } | |
8ac3646f TT |
8599 | |
8600 | if (ui_out_is_mi_like_p (uiout)) | |
8601 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8602 | } |
8603 | ||
8604 | static void | |
8605 | print_mention_catch_exec (struct breakpoint *b) | |
8606 | { | |
8607 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8608 | } | |
8609 | ||
6149aea9 PA |
8610 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8611 | catchpoints. */ | |
8612 | ||
8613 | static void | |
8614 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8615 | { | |
8616 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8617 | print_recreate_thread (b, fp); |
6149aea9 PA |
8618 | } |
8619 | ||
2060206e | 8620 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8621 | |
c906108c | 8622 | static int |
fba45db2 | 8623 | hw_breakpoint_used_count (void) |
c906108c | 8624 | { |
c906108c | 8625 | int i = 0; |
f1310107 TJB |
8626 | struct breakpoint *b; |
8627 | struct bp_location *bl; | |
c906108c SS |
8628 | |
8629 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8630 | { |
d6b74ac4 | 8631 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8632 | for (bl = b->loc; bl; bl = bl->next) |
8633 | { | |
8634 | /* Special types of hardware breakpoints may use more than | |
8635 | one register. */ | |
348d480f | 8636 | i += b->ops->resources_needed (bl); |
f1310107 | 8637 | } |
c5aa993b | 8638 | } |
c906108c SS |
8639 | |
8640 | return i; | |
8641 | } | |
8642 | ||
a1398e0c PA |
8643 | /* Returns the resources B would use if it were a hardware |
8644 | watchpoint. */ | |
8645 | ||
c906108c | 8646 | static int |
a1398e0c | 8647 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8648 | { |
c906108c | 8649 | int i = 0; |
e09342b5 | 8650 | struct bp_location *bl; |
c906108c | 8651 | |
a1398e0c PA |
8652 | if (!breakpoint_enabled (b)) |
8653 | return 0; | |
8654 | ||
8655 | for (bl = b->loc; bl; bl = bl->next) | |
8656 | { | |
8657 | /* Special types of hardware watchpoints may use more than | |
8658 | one register. */ | |
8659 | i += b->ops->resources_needed (bl); | |
8660 | } | |
8661 | ||
8662 | return i; | |
8663 | } | |
8664 | ||
8665 | /* Returns the sum the used resources of all hardware watchpoints of | |
8666 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8667 | the sum of the used resources of all hardware watchpoints of other | |
8668 | types _not_ TYPE. */ | |
8669 | ||
8670 | static int | |
8671 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8672 | enum bptype type, int *other_type_used) | |
8673 | { | |
8674 | int i = 0; | |
8675 | struct breakpoint *b; | |
8676 | ||
c906108c SS |
8677 | *other_type_used = 0; |
8678 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8679 | { |
a1398e0c PA |
8680 | if (b == except) |
8681 | continue; | |
e09342b5 TJB |
8682 | if (!breakpoint_enabled (b)) |
8683 | continue; | |
8684 | ||
a1398e0c PA |
8685 | if (b->type == type) |
8686 | i += hw_watchpoint_use_count (b); | |
8687 | else if (is_hardware_watchpoint (b)) | |
8688 | *other_type_used = 1; | |
e09342b5 TJB |
8689 | } |
8690 | ||
c906108c SS |
8691 | return i; |
8692 | } | |
8693 | ||
c906108c | 8694 | void |
fba45db2 | 8695 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8696 | { |
c5aa993b | 8697 | struct breakpoint *b; |
c906108c SS |
8698 | |
8699 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8700 | { |
cc60f2e3 | 8701 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8702 | { |
b5de0fa7 | 8703 | b->enable_state = bp_call_disabled; |
44702360 | 8704 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8705 | } |
8706 | } | |
c906108c SS |
8707 | } |
8708 | ||
8709 | void | |
fba45db2 | 8710 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8711 | { |
c5aa993b | 8712 | struct breakpoint *b; |
c906108c SS |
8713 | |
8714 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8715 | { |
cc60f2e3 | 8716 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8717 | { |
b5de0fa7 | 8718 | b->enable_state = bp_enabled; |
44702360 | 8719 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8720 | } |
8721 | } | |
c906108c SS |
8722 | } |
8723 | ||
8bea4e01 UW |
8724 | void |
8725 | disable_breakpoints_before_startup (void) | |
8726 | { | |
6c95b8df | 8727 | current_program_space->executing_startup = 1; |
44702360 | 8728 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8729 | } |
8730 | ||
8731 | void | |
8732 | enable_breakpoints_after_startup (void) | |
8733 | { | |
6c95b8df | 8734 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8735 | breakpoint_re_set (); |
8bea4e01 UW |
8736 | } |
8737 | ||
7c16b83e PA |
8738 | /* Create a new single-step breakpoint for thread THREAD, with no |
8739 | locations. */ | |
c906108c | 8740 | |
7c16b83e PA |
8741 | static struct breakpoint * |
8742 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8743 | { | |
8744 | struct breakpoint *b = XNEW (struct breakpoint); | |
8745 | ||
8746 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
8747 | &momentary_breakpoint_ops); | |
8748 | ||
8749 | b->disposition = disp_donttouch; | |
8750 | b->frame_id = null_frame_id; | |
8751 | ||
8752 | b->thread = thread; | |
8753 | gdb_assert (b->thread != 0); | |
8754 | ||
8755 | add_to_breakpoint_chain (b); | |
8756 | ||
8757 | return b; | |
8758 | } | |
8759 | ||
8760 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8761 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8762 | frame. */ | |
c906108c SS |
8763 | |
8764 | struct breakpoint * | |
a6d9a66e UW |
8765 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8766 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8767 | { |
52f0bd74 | 8768 | struct breakpoint *b; |
edb3359d | 8769 | |
193facb3 JK |
8770 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8771 | tail-called one. */ | |
8772 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8773 | |
06edf0c0 | 8774 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8775 | b->enable_state = bp_enabled; |
8776 | b->disposition = disp_donttouch; | |
818dd999 | 8777 | b->frame_id = frame_id; |
c906108c | 8778 | |
4a64f543 MS |
8779 | /* If we're debugging a multi-threaded program, then we want |
8780 | momentary breakpoints to be active in only a single thread of | |
8781 | control. */ | |
39f77062 KB |
8782 | if (in_thread_list (inferior_ptid)) |
8783 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 8784 | |
44702360 | 8785 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8786 | |
c906108c SS |
8787 | return b; |
8788 | } | |
611c83ae | 8789 | |
06edf0c0 | 8790 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8791 | The new breakpoint will have type TYPE, use OPS as its |
8792 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8793 | |
06edf0c0 PA |
8794 | static struct breakpoint * |
8795 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8796 | enum bptype type, | |
a1aa2221 LM |
8797 | const struct breakpoint_ops *ops, |
8798 | int loc_enabled) | |
e58b0e63 PA |
8799 | { |
8800 | struct breakpoint *copy; | |
8801 | ||
06edf0c0 | 8802 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8803 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8804 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8805 | |
a6d9a66e | 8806 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8807 | copy->loc->requested_address = orig->loc->requested_address; |
8808 | copy->loc->address = orig->loc->address; | |
8809 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8810 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8811 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8812 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8813 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8814 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8815 | copy->frame_id = orig->frame_id; |
8816 | copy->thread = orig->thread; | |
6c95b8df | 8817 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8818 | |
8819 | copy->enable_state = bp_enabled; | |
8820 | copy->disposition = disp_donttouch; | |
8821 | copy->number = internal_breakpoint_number--; | |
8822 | ||
44702360 | 8823 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8824 | return copy; |
8825 | } | |
8826 | ||
06edf0c0 PA |
8827 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8828 | ORIG is NULL. */ | |
8829 | ||
8830 | struct breakpoint * | |
8831 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8832 | { | |
8833 | /* If there's nothing to clone, then return nothing. */ | |
8834 | if (orig == NULL) | |
8835 | return NULL; | |
8836 | ||
a1aa2221 | 8837 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8838 | } |
8839 | ||
611c83ae | 8840 | struct breakpoint * |
a6d9a66e UW |
8841 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8842 | enum bptype type) | |
611c83ae PA |
8843 | { |
8844 | struct symtab_and_line sal; | |
8845 | ||
8846 | sal = find_pc_line (pc, 0); | |
8847 | sal.pc = pc; | |
8848 | sal.section = find_pc_overlay (pc); | |
8849 | sal.explicit_pc = 1; | |
8850 | ||
a6d9a66e | 8851 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8852 | } |
c906108c | 8853 | \f |
c5aa993b | 8854 | |
c906108c SS |
8855 | /* Tell the user we have just set a breakpoint B. */ |
8856 | ||
8857 | static void | |
fba45db2 | 8858 | mention (struct breakpoint *b) |
c906108c | 8859 | { |
348d480f | 8860 | b->ops->print_mention (b); |
79a45e25 | 8861 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 8862 | return; |
c906108c SS |
8863 | printf_filtered ("\n"); |
8864 | } | |
c906108c | 8865 | \f |
c5aa993b | 8866 | |
1a853c52 PA |
8867 | static int bp_loc_is_permanent (struct bp_location *loc); |
8868 | ||
0d381245 | 8869 | static struct bp_location * |
39d61571 | 8870 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8871 | const struct symtab_and_line *sal) |
8872 | { | |
8873 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8874 | CORE_ADDR adjusted_address; |
8875 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8876 | ||
8877 | if (loc_gdbarch == NULL) | |
8878 | loc_gdbarch = b->gdbarch; | |
8879 | ||
8880 | /* Adjust the breakpoint's address prior to allocating a location. | |
8881 | Once we call allocate_bp_location(), that mostly uninitialized | |
8882 | location will be placed on the location chain. Adjustment of the | |
8883 | breakpoint may cause target_read_memory() to be called and we do | |
8884 | not want its scan of the location chain to find a breakpoint and | |
8885 | location that's only been partially initialized. */ | |
8886 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8887 | sal->pc, b->type); | |
0d381245 | 8888 | |
d30113d4 | 8889 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8890 | loc = allocate_bp_location (b); |
d30113d4 JK |
8891 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8892 | tmp = &((*tmp)->next)) | |
0d381245 | 8893 | ; |
d30113d4 | 8894 | loc->next = *tmp; |
0d381245 | 8895 | *tmp = loc; |
3742cc8b | 8896 | |
0d381245 | 8897 | loc->requested_address = sal->pc; |
3742cc8b | 8898 | loc->address = adjusted_address; |
6c95b8df | 8899 | loc->pspace = sal->pspace; |
729662a5 TT |
8900 | loc->probe.probe = sal->probe; |
8901 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 8902 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8903 | loc->section = sal->section; |
3742cc8b | 8904 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8905 | loc->line_number = sal->line; |
2f202fde | 8906 | loc->symtab = sal->symtab; |
f8eba3c6 | 8907 | |
0e30163f JK |
8908 | set_breakpoint_location_function (loc, |
8909 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 8910 | |
6ae88661 LM |
8911 | /* While by definition, permanent breakpoints are already present in the |
8912 | code, we don't mark the location as inserted. Normally one would expect | |
8913 | that GDB could rely on that breakpoint instruction to stop the program, | |
8914 | thus removing the need to insert its own breakpoint, except that executing | |
8915 | the breakpoint instruction can kill the target instead of reporting a | |
8916 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8917 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8918 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8919 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8920 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8921 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8922 | it manually increments the PC, thus avoiding executing the breakpoint | |
8923 | instruction.) */ | |
1a853c52 | 8924 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8925 | loc->permanent = 1; |
1a853c52 | 8926 | |
0d381245 VP |
8927 | return loc; |
8928 | } | |
514f746b AR |
8929 | \f |
8930 | ||
1cf4d951 | 8931 | /* See breakpoint.h. */ |
514f746b | 8932 | |
1cf4d951 PA |
8933 | int |
8934 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
8935 | { |
8936 | int len; | |
8937 | CORE_ADDR addr; | |
1afeeb75 | 8938 | const gdb_byte *bpoint; |
514f746b | 8939 | gdb_byte *target_mem; |
939c61fa JK |
8940 | struct cleanup *cleanup; |
8941 | int retval = 0; | |
514f746b | 8942 | |
1cf4d951 PA |
8943 | addr = address; |
8944 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
8945 | ||
8946 | /* Software breakpoints unsupported? */ | |
8947 | if (bpoint == NULL) | |
8948 | return 0; | |
8949 | ||
8950 | target_mem = alloca (len); | |
8951 | ||
8952 | /* Enable the automatic memory restoration from breakpoints while | |
8953 | we read the memory. Otherwise we could say about our temporary | |
8954 | breakpoints they are permanent. */ | |
8955 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
8956 | ||
8957 | if (target_read_memory (address, target_mem, len) == 0 | |
8958 | && memcmp (target_mem, bpoint, len) == 0) | |
8959 | retval = 1; | |
8960 | ||
8961 | do_cleanups (cleanup); | |
8962 | ||
8963 | return retval; | |
8964 | } | |
8965 | ||
8966 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8967 | return 0 otherwise. */ | |
8968 | ||
8969 | static int | |
8970 | bp_loc_is_permanent (struct bp_location *loc) | |
8971 | { | |
8972 | struct cleanup *cleanup; | |
8973 | int retval; | |
8974 | ||
514f746b AR |
8975 | gdb_assert (loc != NULL); |
8976 | ||
6c95b8df | 8977 | cleanup = save_current_space_and_thread (); |
6c95b8df | 8978 | switch_to_program_space_and_thread (loc->pspace); |
939c61fa | 8979 | |
1cf4d951 | 8980 | retval = program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b | 8981 | |
939c61fa JK |
8982 | do_cleanups (cleanup); |
8983 | ||
8984 | return retval; | |
514f746b AR |
8985 | } |
8986 | ||
e7e0cddf SS |
8987 | /* Build a command list for the dprintf corresponding to the current |
8988 | settings of the dprintf style options. */ | |
8989 | ||
8990 | static void | |
8991 | update_dprintf_command_list (struct breakpoint *b) | |
8992 | { | |
8993 | char *dprintf_args = b->extra_string; | |
8994 | char *printf_line = NULL; | |
8995 | ||
8996 | if (!dprintf_args) | |
8997 | return; | |
8998 | ||
8999 | dprintf_args = skip_spaces (dprintf_args); | |
9000 | ||
9001 | /* Allow a comma, as it may have terminated a location, but don't | |
9002 | insist on it. */ | |
9003 | if (*dprintf_args == ',') | |
9004 | ++dprintf_args; | |
9005 | dprintf_args = skip_spaces (dprintf_args); | |
9006 | ||
9007 | if (*dprintf_args != '"') | |
9008 | error (_("Bad format string, missing '\"'.")); | |
9009 | ||
d3ce09f5 | 9010 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9011 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9012 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9013 | { |
9014 | if (!dprintf_function) | |
9015 | error (_("No function supplied for dprintf call")); | |
9016 | ||
9017 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9018 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9019 | dprintf_function, | |
9020 | dprintf_channel, | |
9021 | dprintf_args); | |
9022 | else | |
9023 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9024 | dprintf_function, | |
9025 | dprintf_args); | |
9026 | } | |
d3ce09f5 SS |
9027 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9028 | { | |
9029 | if (target_can_run_breakpoint_commands ()) | |
9030 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9031 | else | |
9032 | { | |
9033 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9034 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9035 | } | |
9036 | } | |
e7e0cddf SS |
9037 | else |
9038 | internal_error (__FILE__, __LINE__, | |
9039 | _("Invalid dprintf style.")); | |
9040 | ||
f28045c2 | 9041 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9042 | /* Manufacture a printf sequence. */ |
f28045c2 | 9043 | { |
9d6e6e84 HZ |
9044 | struct command_line *printf_cmd_line |
9045 | = xmalloc (sizeof (struct command_line)); | |
e7e0cddf | 9046 | |
f28045c2 YQ |
9047 | printf_cmd_line->control_type = simple_control; |
9048 | printf_cmd_line->body_count = 0; | |
9049 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9050 | printf_cmd_line->next = NULL; |
f28045c2 | 9051 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9052 | |
f28045c2 YQ |
9053 | breakpoint_set_commands (b, printf_cmd_line); |
9054 | } | |
e7e0cddf SS |
9055 | } |
9056 | ||
9057 | /* Update all dprintf commands, making their command lists reflect | |
9058 | current style settings. */ | |
9059 | ||
9060 | static void | |
9061 | update_dprintf_commands (char *args, int from_tty, | |
9062 | struct cmd_list_element *c) | |
9063 | { | |
9064 | struct breakpoint *b; | |
9065 | ||
9066 | ALL_BREAKPOINTS (b) | |
9067 | { | |
9068 | if (b->type == bp_dprintf) | |
9069 | update_dprintf_command_list (b); | |
9070 | } | |
9071 | } | |
c3f6f71d | 9072 | |
018d34a4 VP |
9073 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
9074 | as textual description of the location, and COND_STRING | |
db107f19 | 9075 | as condition expression. */ |
018d34a4 VP |
9076 | |
9077 | static void | |
d9b3f62e PA |
9078 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
9079 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9080 | char *filter, char *cond_string, |
e7e0cddf | 9081 | char *extra_string, |
d9b3f62e PA |
9082 | enum bptype type, enum bpdisp disposition, |
9083 | int thread, int task, int ignore_count, | |
c0a91b2b | 9084 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9085 | int enabled, int internal, unsigned flags, |
9086 | int display_canonical) | |
018d34a4 | 9087 | { |
0d381245 | 9088 | int i; |
018d34a4 VP |
9089 | |
9090 | if (type == bp_hardware_breakpoint) | |
9091 | { | |
fbbd034e AS |
9092 | int target_resources_ok; |
9093 | ||
9094 | i = hw_breakpoint_used_count (); | |
9095 | target_resources_ok = | |
9096 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9097 | i + 1, 0); |
9098 | if (target_resources_ok == 0) | |
9099 | error (_("No hardware breakpoint support in the target.")); | |
9100 | else if (target_resources_ok < 0) | |
9101 | error (_("Hardware breakpoints used exceeds limit.")); | |
9102 | } | |
9103 | ||
6c95b8df PA |
9104 | gdb_assert (sals.nelts > 0); |
9105 | ||
0d381245 VP |
9106 | for (i = 0; i < sals.nelts; ++i) |
9107 | { | |
9108 | struct symtab_and_line sal = sals.sals[i]; | |
9109 | struct bp_location *loc; | |
9110 | ||
9111 | if (from_tty) | |
5af949e3 UW |
9112 | { |
9113 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9114 | if (!loc_gdbarch) | |
9115 | loc_gdbarch = gdbarch; | |
9116 | ||
9117 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9118 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9119 | } |
0d381245 VP |
9120 | |
9121 | if (i == 0) | |
9122 | { | |
d9b3f62e | 9123 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9124 | b->thread = thread; |
4a306c9a | 9125 | b->task = task; |
855a6e68 | 9126 | |
0d381245 | 9127 | b->cond_string = cond_string; |
e7e0cddf | 9128 | b->extra_string = extra_string; |
0d381245 | 9129 | b->ignore_count = ignore_count; |
41447f92 | 9130 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9131 | b->disposition = disposition; |
6c95b8df | 9132 | |
44f238bb PA |
9133 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9134 | b->loc->inserted = 1; | |
9135 | ||
0fb4aa4b PA |
9136 | if (type == bp_static_tracepoint) |
9137 | { | |
d9b3f62e | 9138 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9139 | struct static_tracepoint_marker marker; |
9140 | ||
983af33b | 9141 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9142 | { |
9143 | /* We already know the marker exists, otherwise, we | |
9144 | wouldn't see a sal for it. */ | |
9145 | char *p = &addr_string[3]; | |
9146 | char *endp; | |
9147 | char *marker_str; | |
0fb4aa4b | 9148 | |
e9cafbcc | 9149 | p = skip_spaces (p); |
0fb4aa4b | 9150 | |
e9cafbcc | 9151 | endp = skip_to_space (p); |
0fb4aa4b PA |
9152 | |
9153 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9154 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9155 | |
3e43a32a MS |
9156 | printf_filtered (_("Probed static tracepoint " |
9157 | "marker \"%s\"\n"), | |
d9b3f62e | 9158 | t->static_trace_marker_id); |
0fb4aa4b PA |
9159 | } |
9160 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9161 | { | |
d9b3f62e | 9162 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9163 | release_static_tracepoint_marker (&marker); |
9164 | ||
3e43a32a MS |
9165 | printf_filtered (_("Probed static tracepoint " |
9166 | "marker \"%s\"\n"), | |
d9b3f62e | 9167 | t->static_trace_marker_id); |
0fb4aa4b PA |
9168 | } |
9169 | else | |
3e43a32a MS |
9170 | warning (_("Couldn't determine the static " |
9171 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9172 | } |
9173 | ||
0d381245 VP |
9174 | loc = b->loc; |
9175 | } | |
9176 | else | |
018d34a4 | 9177 | { |
39d61571 | 9178 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9179 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9180 | loc->inserted = 1; | |
0d381245 VP |
9181 | } |
9182 | ||
9183 | if (b->cond_string) | |
9184 | { | |
bbc13ae3 KS |
9185 | const char *arg = b->cond_string; |
9186 | ||
1bb9788d TT |
9187 | loc->cond = parse_exp_1 (&arg, loc->address, |
9188 | block_for_pc (loc->address), 0); | |
0d381245 | 9189 | if (*arg) |
588ae58c | 9190 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9191 | } |
e7e0cddf SS |
9192 | |
9193 | /* Dynamic printf requires and uses additional arguments on the | |
9194 | command line, otherwise it's an error. */ | |
9195 | if (type == bp_dprintf) | |
9196 | { | |
9197 | if (b->extra_string) | |
9198 | update_dprintf_command_list (b); | |
9199 | else | |
9200 | error (_("Format string required")); | |
9201 | } | |
9202 | else if (b->extra_string) | |
588ae58c | 9203 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9204 | } |
018d34a4 | 9205 | |
56435ebe | 9206 | b->display_canonical = display_canonical; |
018d34a4 VP |
9207 | if (addr_string) |
9208 | b->addr_string = addr_string; | |
9209 | else | |
9210 | /* addr_string has to be used or breakpoint_re_set will delete | |
9211 | me. */ | |
5af949e3 UW |
9212 | b->addr_string |
9213 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 9214 | b->filter = filter; |
d9b3f62e | 9215 | } |
018d34a4 | 9216 | |
d9b3f62e PA |
9217 | static void |
9218 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
9219 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9220 | char *filter, char *cond_string, |
e7e0cddf | 9221 | char *extra_string, |
d9b3f62e PA |
9222 | enum bptype type, enum bpdisp disposition, |
9223 | int thread, int task, int ignore_count, | |
c0a91b2b | 9224 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9225 | int enabled, int internal, unsigned flags, |
9226 | int display_canonical) | |
d9b3f62e PA |
9227 | { |
9228 | struct breakpoint *b; | |
9229 | struct cleanup *old_chain; | |
9230 | ||
9231 | if (is_tracepoint_type (type)) | |
9232 | { | |
9233 | struct tracepoint *t; | |
9234 | ||
9235 | t = XCNEW (struct tracepoint); | |
9236 | b = &t->base; | |
9237 | } | |
9238 | else | |
9239 | b = XNEW (struct breakpoint); | |
9240 | ||
9241 | old_chain = make_cleanup (xfree, b); | |
9242 | ||
9243 | init_breakpoint_sal (b, gdbarch, | |
9244 | sals, addr_string, | |
e7e0cddf | 9245 | filter, cond_string, extra_string, |
d9b3f62e PA |
9246 | type, disposition, |
9247 | thread, task, ignore_count, | |
9248 | ops, from_tty, | |
44f238bb PA |
9249 | enabled, internal, flags, |
9250 | display_canonical); | |
d9b3f62e PA |
9251 | discard_cleanups (old_chain); |
9252 | ||
3ea46bff | 9253 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9254 | } |
9255 | ||
9256 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9257 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9258 | value. COND_STRING, if not NULL, specified the condition to be | |
9259 | used for all breakpoints. Essentially the only case where | |
9260 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9261 | function. In that case, it's still not possible to specify | |
9262 | separate conditions for different overloaded functions, so | |
9263 | we take just a single condition string. | |
9264 | ||
c3f6f71d | 9265 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9266 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9267 | array contents). If the function fails (error() is called), the |
9268 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9269 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9270 | |
9271 | static void | |
8cdf0e15 | 9272 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9273 | struct linespec_result *canonical, |
e7e0cddf | 9274 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9275 | enum bptype type, enum bpdisp disposition, |
9276 | int thread, int task, int ignore_count, | |
c0a91b2b | 9277 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9278 | int enabled, int internal, unsigned flags) |
c906108c | 9279 | { |
018d34a4 | 9280 | int i; |
f8eba3c6 | 9281 | struct linespec_sals *lsal; |
cc59ec59 | 9282 | |
f8eba3c6 TT |
9283 | if (canonical->pre_expanded) |
9284 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9285 | ||
9286 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9287 | { |
f8eba3c6 TT |
9288 | /* Note that 'addr_string' can be NULL in the case of a plain |
9289 | 'break', without arguments. */ | |
9290 | char *addr_string = (canonical->addr_string | |
9291 | ? xstrdup (canonical->addr_string) | |
9292 | : NULL); | |
9293 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
9294 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 9295 | |
f8eba3c6 TT |
9296 | make_cleanup (xfree, filter_string); |
9297 | create_breakpoint_sal (gdbarch, lsal->sals, | |
9298 | addr_string, | |
9299 | filter_string, | |
e7e0cddf SS |
9300 | cond_string, extra_string, |
9301 | type, disposition, | |
84f4c1fe | 9302 | thread, task, ignore_count, ops, |
44f238bb | 9303 | from_tty, enabled, internal, flags, |
56435ebe | 9304 | canonical->special_display); |
f8eba3c6 | 9305 | discard_cleanups (inner); |
c3f6f71d | 9306 | } |
c3f6f71d | 9307 | } |
c906108c | 9308 | |
9998af43 | 9309 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 9310 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 9311 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
9312 | address strings. ADDRESS points to the end of the SAL. |
9313 | ||
9314 | The array and the line spec strings are allocated on the heap, it is | |
9315 | the caller's responsibility to free them. */ | |
c906108c | 9316 | |
b9362cc7 | 9317 | static void |
c3f6f71d | 9318 | parse_breakpoint_sals (char **address, |
58438ac1 | 9319 | struct linespec_result *canonical) |
c3f6f71d | 9320 | { |
c3f6f71d | 9321 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 9322 | breakpoint. */ |
0578b14e | 9323 | if ((*address) == NULL || linespec_lexer_lex_keyword (*address)) |
c906108c | 9324 | { |
1bfeeb0f JL |
9325 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
9326 | address. */ | |
9327 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9328 | { |
f8eba3c6 | 9329 | struct linespec_sals lsal; |
c3f6f71d | 9330 | struct symtab_and_line sal; |
1c8cdcb1 | 9331 | CORE_ADDR pc; |
cc59ec59 | 9332 | |
4a64f543 | 9333 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 9334 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 9335 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
9336 | |
9337 | /* Set sal's pspace, pc, symtab, and line to the values | |
1c8cdcb1 JK |
9338 | corresponding to the last call to print_frame_info. |
9339 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9340 | as the breakpoint line number is inappropriate otherwise. | |
9341 | find_pc_line would adjust PC, re-set it back. */ | |
1bfeeb0f | 9342 | get_last_displayed_sal (&sal); |
1c8cdcb1 JK |
9343 | pc = sal.pc; |
9344 | sal = find_pc_line (pc, 0); | |
00903456 | 9345 | |
4a64f543 | 9346 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
9347 | where PC is the last displayed codepoint's address. So |
9348 | make sure to set sal.explicit_pc to prevent GDB from | |
9349 | trying to expand the list of sals to include all other | |
9350 | instances with the same symtab and line. */ | |
1c8cdcb1 | 9351 | sal.pc = pc; |
00903456 JK |
9352 | sal.explicit_pc = 1; |
9353 | ||
f8eba3c6 TT |
9354 | lsal.sals.sals[0] = sal; |
9355 | lsal.sals.nelts = 1; | |
9356 | lsal.canonical = NULL; | |
9357 | ||
9358 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
9359 | } |
9360 | else | |
8a3fe4f8 | 9361 | error (_("No default breakpoint address now.")); |
c906108c SS |
9362 | } |
9363 | else | |
9364 | { | |
cc80f267 JK |
9365 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
9366 | ||
c906108c | 9367 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
9368 | current_source_symtab (which is decode_line_1's default). |
9369 | This should produce the results we want almost all of the | |
cc80f267 JK |
9370 | time while leaving default_breakpoint_* alone. |
9371 | ||
9372 | ObjC: However, don't match an Objective-C method name which | |
9373 | may have a '+' or '-' succeeded by a '['. */ | |
9374 | if (last_displayed_sal_is_valid () | |
9375 | && (!cursal.symtab | |
9376 | || ((strchr ("+-", (*address)[0]) != NULL) | |
9377 | && ((*address)[1] != '[')))) | |
f8eba3c6 TT |
9378 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
9379 | get_last_displayed_symtab (), | |
9380 | get_last_displayed_line (), | |
9381 | canonical, NULL, NULL); | |
c906108c | 9382 | else |
f8eba3c6 | 9383 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
cc80f267 | 9384 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c906108c | 9385 | } |
c3f6f71d | 9386 | } |
c906108c | 9387 | |
c906108c | 9388 | |
c3f6f71d | 9389 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9390 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9391 | |
b9362cc7 | 9392 | static void |
23e7acfb | 9393 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9394 | { |
9395 | int i; | |
cc59ec59 | 9396 | |
c3f6f71d | 9397 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9398 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9399 | } |
9400 | ||
7a697b8d SS |
9401 | /* Fast tracepoints may have restrictions on valid locations. For |
9402 | instance, a fast tracepoint using a jump instead of a trap will | |
9403 | likely have to overwrite more bytes than a trap would, and so can | |
9404 | only be placed where the instruction is longer than the jump, or a | |
9405 | multi-instruction sequence does not have a jump into the middle of | |
9406 | it, etc. */ | |
9407 | ||
9408 | static void | |
9409 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9410 | struct symtabs_and_lines *sals) | |
9411 | { | |
9412 | int i, rslt; | |
9413 | struct symtab_and_line *sal; | |
9414 | char *msg; | |
9415 | struct cleanup *old_chain; | |
9416 | ||
9417 | for (i = 0; i < sals->nelts; i++) | |
9418 | { | |
f8eba3c6 TT |
9419 | struct gdbarch *sarch; |
9420 | ||
7a697b8d SS |
9421 | sal = &sals->sals[i]; |
9422 | ||
f8eba3c6 TT |
9423 | sarch = get_sal_arch (*sal); |
9424 | /* We fall back to GDBARCH if there is no architecture | |
9425 | associated with SAL. */ | |
9426 | if (sarch == NULL) | |
9427 | sarch = gdbarch; | |
6b940e6a | 9428 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg); |
7a697b8d SS |
9429 | old_chain = make_cleanup (xfree, msg); |
9430 | ||
9431 | if (!rslt) | |
9432 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9433 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9434 | |
9435 | do_cleanups (old_chain); | |
9436 | } | |
9437 | } | |
9438 | ||
af4908ba KS |
9439 | /* Issue an invalid thread ID error. */ |
9440 | ||
9441 | static void ATTRIBUTE_NORETURN | |
9442 | invalid_thread_id_error (int id) | |
9443 | { | |
9444 | error (_("Unknown thread %d."), id); | |
9445 | } | |
9446 | ||
018d34a4 VP |
9447 | /* Given TOK, a string specification of condition and thread, as |
9448 | accepted by the 'break' command, extract the condition | |
9449 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9450 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9451 | If no condition is found, *COND_STRING is set to NULL. |
9452 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9453 | |
9454 | static void | |
bbc13ae3 | 9455 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9456 | char **cond_string, int *thread, int *task, |
9457 | char **rest) | |
018d34a4 VP |
9458 | { |
9459 | *cond_string = NULL; | |
9460 | *thread = -1; | |
ed1d1739 KS |
9461 | *task = 0; |
9462 | *rest = NULL; | |
9463 | ||
018d34a4 VP |
9464 | while (tok && *tok) |
9465 | { | |
bbc13ae3 | 9466 | const char *end_tok; |
018d34a4 | 9467 | int toklen; |
bbc13ae3 KS |
9468 | const char *cond_start = NULL; |
9469 | const char *cond_end = NULL; | |
cc59ec59 | 9470 | |
bbc13ae3 | 9471 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9472 | |
9473 | if ((*tok == '"' || *tok == ',') && rest) | |
9474 | { | |
9475 | *rest = savestring (tok, strlen (tok)); | |
9476 | return; | |
9477 | } | |
9478 | ||
bbc13ae3 | 9479 | end_tok = skip_to_space_const (tok); |
d634f2de | 9480 | |
018d34a4 | 9481 | toklen = end_tok - tok; |
d634f2de | 9482 | |
018d34a4 VP |
9483 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9484 | { | |
f7545552 TT |
9485 | struct expression *expr; |
9486 | ||
018d34a4 | 9487 | tok = cond_start = end_tok + 1; |
1bb9788d | 9488 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9489 | xfree (expr); |
018d34a4 | 9490 | cond_end = tok; |
d634f2de | 9491 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9492 | } |
9493 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9494 | { | |
9495 | char *tmptok; | |
d634f2de | 9496 | |
018d34a4 | 9497 | tok = end_tok + 1; |
bbc13ae3 | 9498 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9499 | if (tok == tmptok) |
9500 | error (_("Junk after thread keyword.")); | |
9501 | if (!valid_thread_id (*thread)) | |
af4908ba | 9502 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9503 | tok = tmptok; |
018d34a4 | 9504 | } |
4a306c9a JB |
9505 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9506 | { | |
9507 | char *tmptok; | |
9508 | ||
9509 | tok = end_tok + 1; | |
bbc13ae3 | 9510 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9511 | if (tok == tmptok) |
9512 | error (_("Junk after task keyword.")); | |
9513 | if (!valid_task_id (*task)) | |
b6199126 | 9514 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9515 | tok = tmptok; |
4a306c9a | 9516 | } |
e7e0cddf SS |
9517 | else if (rest) |
9518 | { | |
9519 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9520 | return; |
e7e0cddf | 9521 | } |
018d34a4 VP |
9522 | else |
9523 | error (_("Junk at end of arguments.")); | |
9524 | } | |
9525 | } | |
9526 | ||
0fb4aa4b PA |
9527 | /* Decode a static tracepoint marker spec. */ |
9528 | ||
9529 | static struct symtabs_and_lines | |
9530 | decode_static_tracepoint_spec (char **arg_p) | |
9531 | { | |
9532 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9533 | struct symtabs_and_lines sals; | |
0fb4aa4b PA |
9534 | struct cleanup *old_chain; |
9535 | char *p = &(*arg_p)[3]; | |
9536 | char *endp; | |
9537 | char *marker_str; | |
9538 | int i; | |
9539 | ||
e9cafbcc | 9540 | p = skip_spaces (p); |
0fb4aa4b | 9541 | |
e9cafbcc | 9542 | endp = skip_to_space (p); |
0fb4aa4b PA |
9543 | |
9544 | marker_str = savestring (p, endp - p); | |
9545 | old_chain = make_cleanup (xfree, marker_str); | |
9546 | ||
9547 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9548 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9549 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9550 | ||
9551 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
9552 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
9553 | ||
9554 | for (i = 0; i < sals.nelts; i++) | |
9555 | { | |
9556 | struct static_tracepoint_marker *marker; | |
9557 | ||
9558 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9559 | ||
9560 | init_sal (&sals.sals[i]); | |
9561 | ||
9562 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9563 | sals.sals[i].pc = marker->address; | |
9564 | ||
9565 | release_static_tracepoint_marker (marker); | |
9566 | } | |
9567 | ||
9568 | do_cleanups (old_chain); | |
9569 | ||
9570 | *arg_p = endp; | |
9571 | return sals; | |
9572 | } | |
9573 | ||
fd9b8c24 PA |
9574 | /* Set a breakpoint. This function is shared between CLI and MI |
9575 | functions for setting a breakpoint. This function has two major | |
f6de8ec2 PA |
9576 | modes of operations, selected by the PARSE_ARG parameter. If |
9577 | non-zero, the function will parse ARG, extracting location, | |
9578 | condition, thread and extra string. Otherwise, ARG is just the | |
9579 | breakpoint's location, with condition, thread, and extra string | |
9580 | specified by the COND_STRING, THREAD and EXTRA_STRING parameters. | |
9581 | If INTERNAL is non-zero, the breakpoint number will be allocated | |
9582 | from the internal breakpoint count. Returns true if any breakpoint | |
9583 | was created; false otherwise. */ | |
0101ce28 | 9584 | |
8cdf0e15 VP |
9585 | int |
9586 | create_breakpoint (struct gdbarch *gdbarch, | |
e7e0cddf SS |
9587 | char *arg, char *cond_string, |
9588 | int thread, char *extra_string, | |
f6de8ec2 | 9589 | int parse_arg, |
0fb4aa4b | 9590 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9591 | int ignore_count, |
9592 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9593 | const struct breakpoint_ops *ops, |
44f238bb PA |
9594 | int from_tty, int enabled, int internal, |
9595 | unsigned flags) | |
c3f6f71d | 9596 | { |
f8eba3c6 | 9597 | char *copy_arg = NULL; |
c3f6f71d | 9598 | char *addr_start = arg; |
7efd8fc2 | 9599 | struct linespec_result canonical; |
c3f6f71d | 9600 | struct cleanup *old_chain; |
80c99de1 | 9601 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9602 | int pending = 0; |
4a306c9a | 9603 | int task = 0; |
86b17b60 | 9604 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9605 | |
348d480f PA |
9606 | gdb_assert (ops != NULL); |
9607 | ||
7efd8fc2 | 9608 | init_linespec_result (&canonical); |
c3f6f71d | 9609 | |
492d29ea | 9610 | TRY |
b78a6381 | 9611 | { |
5f700d83 KS |
9612 | ops->create_sals_from_location (&arg, &canonical, type_wanted, |
9613 | addr_start, ©_arg); | |
b78a6381 | 9614 | } |
492d29ea | 9615 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9616 | { |
492d29ea PA |
9617 | /* If caller is interested in rc value from parse, set |
9618 | value. */ | |
9619 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9620 | { |
05ff989b AC |
9621 | /* If pending breakpoint support is turned off, throw |
9622 | error. */ | |
fa8d40ab JJ |
9623 | |
9624 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9625 | throw_exception (e); |
9626 | ||
9627 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9628 | |
05ff989b AC |
9629 | /* If pending breakpoint support is auto query and the user |
9630 | selects no, then simply return the error code. */ | |
059fb39f | 9631 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9632 | && !nquery (_("Make %s pending on future shared library load? "), |
9633 | bptype_string (type_wanted))) | |
fd9b8c24 | 9634 | return 0; |
fa8d40ab | 9635 | |
05ff989b AC |
9636 | /* At this point, either the user was queried about setting |
9637 | a pending breakpoint and selected yes, or pending | |
9638 | breakpoint behavior is on and thus a pending breakpoint | |
9639 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
9640 | { |
9641 | struct linespec_sals lsal; | |
9642 | ||
9643 | copy_arg = xstrdup (addr_start); | |
9644 | lsal.canonical = xstrdup (copy_arg); | |
9645 | lsal.sals.nelts = 1; | |
9646 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
9647 | init_sal (&lsal.sals.sals[0]); | |
9648 | pending = 1; | |
9649 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
9650 | } | |
0101ce28 | 9651 | } |
492d29ea PA |
9652 | else |
9653 | throw_exception (e); | |
0101ce28 | 9654 | } |
492d29ea PA |
9655 | END_CATCH |
9656 | ||
9657 | if (VEC_empty (linespec_sals, canonical.sals)) | |
9658 | return 0; | |
c3f6f71d | 9659 | |
4a64f543 | 9660 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9661 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9662 | |
c3f6f71d JM |
9663 | /* ----------------------------- SNIP ----------------------------- |
9664 | Anything added to the cleanup chain beyond this point is assumed | |
9665 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9666 | then the memory is not reclaimed. */ |
9667 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9668 | |
c3f6f71d JM |
9669 | /* Resolve all line numbers to PC's and verify that the addresses |
9670 | are ok for the target. */ | |
0101ce28 | 9671 | if (!pending) |
f8eba3c6 TT |
9672 | { |
9673 | int ix; | |
9674 | struct linespec_sals *iter; | |
9675 | ||
9676 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9677 | breakpoint_sals_to_pc (&iter->sals); | |
9678 | } | |
c3f6f71d | 9679 | |
7a697b8d | 9680 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9681 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9682 | { |
9683 | int ix; | |
9684 | struct linespec_sals *iter; | |
9685 | ||
9686 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9687 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9688 | } | |
7a697b8d | 9689 | |
c3f6f71d JM |
9690 | /* Verify that condition can be parsed, before setting any |
9691 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9692 | breakpoint. */ |
0101ce28 | 9693 | if (!pending) |
c3f6f71d | 9694 | { |
f6de8ec2 | 9695 | if (parse_arg) |
72b2ff0e | 9696 | { |
0878d0fa | 9697 | char *rest; |
52d361e1 YQ |
9698 | struct linespec_sals *lsal; |
9699 | ||
9700 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9701 | ||
0878d0fa YQ |
9702 | /* Here we only parse 'arg' to separate condition |
9703 | from thread number, so parsing in context of first | |
9704 | sal is OK. When setting the breakpoint we'll | |
9705 | re-parse it in context of each sal. */ | |
9706 | ||
9707 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, | |
9708 | &thread, &task, &rest); | |
9709 | if (cond_string) | |
9710 | make_cleanup (xfree, cond_string); | |
9711 | if (rest) | |
9712 | make_cleanup (xfree, rest); | |
9713 | if (rest) | |
9714 | extra_string = rest; | |
72b2ff0e | 9715 | } |
2f069f6f | 9716 | else |
72b2ff0e | 9717 | { |
0878d0fa YQ |
9718 | if (*arg != '\0') |
9719 | error (_("Garbage '%s' at end of location"), arg); | |
9720 | ||
9721 | /* Create a private copy of condition string. */ | |
9722 | if (cond_string) | |
9723 | { | |
9724 | cond_string = xstrdup (cond_string); | |
9725 | make_cleanup (xfree, cond_string); | |
9726 | } | |
9727 | /* Create a private copy of any extra string. */ | |
9728 | if (extra_string) | |
9729 | { | |
9730 | extra_string = xstrdup (extra_string); | |
9731 | make_cleanup (xfree, extra_string); | |
9732 | } | |
72b2ff0e | 9733 | } |
0fb4aa4b | 9734 | |
52d361e1 | 9735 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9736 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9737 | tempflag ? disp_del : disp_donttouch, |
9738 | thread, task, ignore_count, ops, | |
44f238bb | 9739 | from_tty, enabled, internal, flags); |
c906108c | 9740 | } |
0101ce28 JJ |
9741 | else |
9742 | { | |
0101ce28 JJ |
9743 | struct breakpoint *b; |
9744 | ||
0101ce28 JJ |
9745 | make_cleanup (xfree, copy_arg); |
9746 | ||
bfccc43c YQ |
9747 | if (is_tracepoint_type (type_wanted)) |
9748 | { | |
9749 | struct tracepoint *t; | |
9750 | ||
9751 | t = XCNEW (struct tracepoint); | |
9752 | b = &t->base; | |
9753 | } | |
9754 | else | |
9755 | b = XNEW (struct breakpoint); | |
9756 | ||
9757 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
9758 | ||
f8eba3c6 | 9759 | b->addr_string = copy_arg; |
f6de8ec2 | 9760 | if (parse_arg) |
98aa42ee AT |
9761 | { |
9762 | b->cond_string = NULL; | |
9763 | b->extra_string = NULL; | |
9764 | } | |
e12c7713 MK |
9765 | else |
9766 | { | |
9767 | /* Create a private copy of condition string. */ | |
9768 | if (cond_string) | |
9769 | { | |
9770 | cond_string = xstrdup (cond_string); | |
9771 | make_cleanup (xfree, cond_string); | |
9772 | } | |
98aa42ee AT |
9773 | /* Create a private copy of any extra string. */ |
9774 | if (extra_string != NULL) | |
9775 | { | |
9776 | extra_string = xstrdup (extra_string); | |
9777 | make_cleanup (xfree, extra_string); | |
9778 | } | |
e12c7713 | 9779 | b->cond_string = cond_string; |
98aa42ee | 9780 | b->extra_string = extra_string; |
15630549 | 9781 | b->thread = thread; |
e12c7713 | 9782 | } |
0101ce28 | 9783 | b->ignore_count = ignore_count; |
0101ce28 | 9784 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9785 | b->condition_not_parsed = 1; |
41447f92 | 9786 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9787 | if ((type_wanted != bp_breakpoint |
9788 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9789 | b->pspace = current_program_space; |
8bea4e01 | 9790 | |
bfccc43c | 9791 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9792 | } |
9793 | ||
f8eba3c6 | 9794 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9795 | { |
3e43a32a MS |
9796 | warning (_("Multiple breakpoints were set.\nUse the " |
9797 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9798 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9799 | } |
9800 | ||
80c99de1 PA |
9801 | /* That's it. Discard the cleanups for data inserted into the |
9802 | breakpoint. */ | |
9803 | discard_cleanups (bkpt_chain); | |
9804 | /* But cleanup everything else. */ | |
c3f6f71d | 9805 | do_cleanups (old_chain); |
217dc9e2 | 9806 | |
80c99de1 | 9807 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9808 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9809 | |
9810 | return 1; | |
c3f6f71d | 9811 | } |
c906108c | 9812 | |
348d480f | 9813 | /* Set a breakpoint. |
72b2ff0e VP |
9814 | ARG is a string describing breakpoint address, |
9815 | condition, and thread. | |
9816 | FLAG specifies if a breakpoint is hardware on, | |
9817 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9818 | and BP_TEMPFLAG. */ | |
348d480f | 9819 | |
98deb0da | 9820 | static void |
72b2ff0e | 9821 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9822 | { |
72b2ff0e | 9823 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9824 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9825 | ? bp_hardware_breakpoint | |
9826 | : bp_breakpoint); | |
55aa24fb SDJ |
9827 | struct breakpoint_ops *ops; |
9828 | const char *arg_cp = arg; | |
9829 | ||
9830 | /* Matching breakpoints on probes. */ | |
9831 | if (arg && probe_linespec_to_ops (&arg_cp) != NULL) | |
9832 | ops = &bkpt_probe_breakpoint_ops; | |
9833 | else | |
9834 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9835 | |
8cdf0e15 VP |
9836 | create_breakpoint (get_current_arch (), |
9837 | arg, | |
e7e0cddf | 9838 | NULL, 0, NULL, 1 /* parse arg */, |
0fb4aa4b | 9839 | tempflag, type_wanted, |
8cdf0e15 VP |
9840 | 0 /* Ignore count */, |
9841 | pending_break_support, | |
55aa24fb | 9842 | ops, |
8cdf0e15 | 9843 | from_tty, |
84f4c1fe | 9844 | 1 /* enabled */, |
44f238bb PA |
9845 | 0 /* internal */, |
9846 | 0); | |
c906108c SS |
9847 | } |
9848 | ||
c906108c SS |
9849 | /* Helper function for break_command_1 and disassemble_command. */ |
9850 | ||
9851 | void | |
fba45db2 | 9852 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9853 | { |
9854 | CORE_ADDR pc; | |
9855 | ||
9856 | if (sal->pc == 0 && sal->symtab != NULL) | |
9857 | { | |
9858 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9859 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9860 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9861 | sal->pc = pc; |
6a048695 | 9862 | |
4a64f543 MS |
9863 | /* If this SAL corresponds to a breakpoint inserted using a line |
9864 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9865 | if (sal->explicit_line) |
059acae7 | 9866 | skip_prologue_sal (sal); |
c906108c SS |
9867 | } |
9868 | ||
9869 | if (sal->section == 0 && sal->symtab != NULL) | |
9870 | { | |
346d1dfe | 9871 | const struct blockvector *bv; |
3977b71f | 9872 | const struct block *b; |
c5aa993b | 9873 | struct symbol *sym; |
c906108c | 9874 | |
43f3e411 DE |
9875 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9876 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9877 | if (bv != NULL) |
9878 | { | |
7f0df278 | 9879 | sym = block_linkage_function (b); |
c906108c SS |
9880 | if (sym != NULL) |
9881 | { | |
eb822aa6 DE |
9882 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9883 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9884 | sym); | |
c906108c SS |
9885 | } |
9886 | else | |
9887 | { | |
4a64f543 MS |
9888 | /* It really is worthwhile to have the section, so we'll |
9889 | just have to look harder. This case can be executed | |
9890 | if we have line numbers but no functions (as can | |
9891 | happen in assembly source). */ | |
c906108c | 9892 | |
7cbd4a93 | 9893 | struct bound_minimal_symbol msym; |
6c95b8df PA |
9894 | struct cleanup *old_chain = save_current_space_and_thread (); |
9895 | ||
9896 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
9897 | |
9898 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 9899 | if (msym.minsym) |
efd66ac6 | 9900 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
9901 | |
9902 | do_cleanups (old_chain); | |
c906108c SS |
9903 | } |
9904 | } | |
9905 | } | |
9906 | } | |
9907 | ||
9908 | void | |
fba45db2 | 9909 | break_command (char *arg, int from_tty) |
c906108c | 9910 | { |
db107f19 | 9911 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9912 | } |
9913 | ||
c906108c | 9914 | void |
fba45db2 | 9915 | tbreak_command (char *arg, int from_tty) |
c906108c | 9916 | { |
db107f19 | 9917 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9918 | } |
9919 | ||
c906108c | 9920 | static void |
fba45db2 | 9921 | hbreak_command (char *arg, int from_tty) |
c906108c | 9922 | { |
db107f19 | 9923 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9924 | } |
9925 | ||
9926 | static void | |
fba45db2 | 9927 | thbreak_command (char *arg, int from_tty) |
c906108c | 9928 | { |
db107f19 | 9929 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9930 | } |
9931 | ||
9932 | static void | |
fba45db2 | 9933 | stop_command (char *arg, int from_tty) |
c906108c | 9934 | { |
a3f17187 | 9935 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9936 | Usage: stop in <function | address>\n\ |
a3f17187 | 9937 | stop at <line>\n")); |
c906108c SS |
9938 | } |
9939 | ||
9940 | static void | |
fba45db2 | 9941 | stopin_command (char *arg, int from_tty) |
c906108c SS |
9942 | { |
9943 | int badInput = 0; | |
9944 | ||
c5aa993b | 9945 | if (arg == (char *) NULL) |
c906108c SS |
9946 | badInput = 1; |
9947 | else if (*arg != '*') | |
9948 | { | |
9949 | char *argptr = arg; | |
9950 | int hasColon = 0; | |
9951 | ||
4a64f543 | 9952 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9953 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9954 | function/method name. */ |
c906108c | 9955 | while (*argptr && !hasColon) |
c5aa993b JM |
9956 | { |
9957 | hasColon = (*argptr == ':'); | |
9958 | argptr++; | |
9959 | } | |
c906108c SS |
9960 | |
9961 | if (hasColon) | |
c5aa993b | 9962 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9963 | else |
c5aa993b | 9964 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9965 | } |
9966 | ||
9967 | if (badInput) | |
a3f17187 | 9968 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9969 | else |
db107f19 | 9970 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9971 | } |
9972 | ||
9973 | static void | |
fba45db2 | 9974 | stopat_command (char *arg, int from_tty) |
c906108c SS |
9975 | { |
9976 | int badInput = 0; | |
9977 | ||
c5aa993b | 9978 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
9979 | badInput = 1; |
9980 | else | |
9981 | { | |
9982 | char *argptr = arg; | |
9983 | int hasColon = 0; | |
9984 | ||
4a64f543 MS |
9985 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9986 | it is probably a line number. */ | |
c906108c | 9987 | while (*argptr && !hasColon) |
c5aa993b JM |
9988 | { |
9989 | hasColon = (*argptr == ':'); | |
9990 | argptr++; | |
9991 | } | |
c906108c SS |
9992 | |
9993 | if (hasColon) | |
c5aa993b | 9994 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9995 | else |
c5aa993b | 9996 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9997 | } |
9998 | ||
9999 | if (badInput) | |
a3f17187 | 10000 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10001 | else |
db107f19 | 10002 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10003 | } |
10004 | ||
e7e0cddf SS |
10005 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10006 | with a prewired command list consisting of a single output command, | |
10007 | built from extra arguments supplied on the dprintf command | |
10008 | line. */ | |
10009 | ||
da821c7b | 10010 | static void |
e7e0cddf SS |
10011 | dprintf_command (char *arg, int from_tty) |
10012 | { | |
10013 | create_breakpoint (get_current_arch (), | |
10014 | arg, | |
10015 | NULL, 0, NULL, 1 /* parse arg */, | |
10016 | 0, bp_dprintf, | |
10017 | 0 /* Ignore count */, | |
10018 | pending_break_support, | |
10019 | &dprintf_breakpoint_ops, | |
10020 | from_tty, | |
10021 | 1 /* enabled */, | |
10022 | 0 /* internal */, | |
10023 | 0); | |
10024 | } | |
10025 | ||
d3ce09f5 SS |
10026 | static void |
10027 | agent_printf_command (char *arg, int from_tty) | |
10028 | { | |
10029 | error (_("May only run agent-printf on the target")); | |
10030 | } | |
10031 | ||
f1310107 TJB |
10032 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10033 | ranged breakpoints. */ | |
10034 | ||
10035 | static int | |
10036 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10037 | struct address_space *aspace, | |
09ac7c10 TT |
10038 | CORE_ADDR bp_addr, |
10039 | const struct target_waitstatus *ws) | |
f1310107 | 10040 | { |
09ac7c10 | 10041 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10042 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10043 | return 0; |
10044 | ||
f1310107 TJB |
10045 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10046 | bl->length, aspace, bp_addr); | |
10047 | } | |
10048 | ||
10049 | /* Implement the "resources_needed" breakpoint_ops method for | |
10050 | ranged breakpoints. */ | |
10051 | ||
10052 | static int | |
10053 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10054 | { | |
10055 | return target_ranged_break_num_registers (); | |
10056 | } | |
10057 | ||
10058 | /* Implement the "print_it" breakpoint_ops method for | |
10059 | ranged breakpoints. */ | |
10060 | ||
10061 | static enum print_stop_action | |
348d480f | 10062 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10063 | { |
348d480f | 10064 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10065 | struct bp_location *bl = b->loc; |
79a45e25 | 10066 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10067 | |
10068 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10069 | ||
10070 | /* Ranged breakpoints have only one location. */ | |
10071 | gdb_assert (bl && bl->next == NULL); | |
10072 | ||
10073 | annotate_breakpoint (b->number); | |
10074 | if (b->disposition == disp_del) | |
10075 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10076 | else | |
10077 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10078 | if (ui_out_is_mi_like_p (uiout)) | |
10079 | { | |
10080 | ui_out_field_string (uiout, "reason", | |
10081 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10082 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10083 | } | |
10084 | ui_out_field_int (uiout, "bkptno", b->number); | |
10085 | ui_out_text (uiout, ", "); | |
10086 | ||
10087 | return PRINT_SRC_AND_LOC; | |
10088 | } | |
10089 | ||
10090 | /* Implement the "print_one" breakpoint_ops method for | |
10091 | ranged breakpoints. */ | |
10092 | ||
10093 | static void | |
10094 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10095 | struct bp_location **last_loc) | |
10096 | { | |
10097 | struct bp_location *bl = b->loc; | |
10098 | struct value_print_options opts; | |
79a45e25 | 10099 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10100 | |
10101 | /* Ranged breakpoints have only one location. */ | |
10102 | gdb_assert (bl && bl->next == NULL); | |
10103 | ||
10104 | get_user_print_options (&opts); | |
10105 | ||
10106 | if (opts.addressprint) | |
10107 | /* We don't print the address range here, it will be printed later | |
10108 | by print_one_detail_ranged_breakpoint. */ | |
10109 | ui_out_field_skip (uiout, "addr"); | |
10110 | annotate_field (5); | |
10111 | print_breakpoint_location (b, bl); | |
10112 | *last_loc = bl; | |
10113 | } | |
10114 | ||
10115 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10116 | ranged breakpoints. */ | |
10117 | ||
10118 | static void | |
10119 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10120 | struct ui_out *uiout) | |
10121 | { | |
10122 | CORE_ADDR address_start, address_end; | |
10123 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10124 | struct ui_file *stb = mem_fileopen (); |
10125 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10126 | |
10127 | gdb_assert (bl); | |
10128 | ||
10129 | address_start = bl->address; | |
10130 | address_end = address_start + bl->length - 1; | |
10131 | ||
10132 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10133 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10134 | print_core_address (bl->gdbarch, address_start), |
10135 | print_core_address (bl->gdbarch, address_end)); | |
10136 | ui_out_field_stream (uiout, "addr", stb); | |
10137 | ui_out_text (uiout, "\n"); | |
10138 | ||
10139 | do_cleanups (cleanup); | |
10140 | } | |
10141 | ||
10142 | /* Implement the "print_mention" breakpoint_ops method for | |
10143 | ranged breakpoints. */ | |
10144 | ||
10145 | static void | |
10146 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10147 | { | |
10148 | struct bp_location *bl = b->loc; | |
79a45e25 | 10149 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10150 | |
10151 | gdb_assert (bl); | |
10152 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10153 | ||
10154 | if (ui_out_is_mi_like_p (uiout)) | |
10155 | return; | |
10156 | ||
10157 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10158 | b->number, paddress (bl->gdbarch, bl->address), | |
10159 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10160 | } | |
10161 | ||
10162 | /* Implement the "print_recreate" breakpoint_ops method for | |
10163 | ranged breakpoints. */ | |
10164 | ||
10165 | static void | |
10166 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10167 | { | |
10168 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
10169 | b->addr_string_range_end); | |
d9b3f62e | 10170 | print_recreate_thread (b, fp); |
f1310107 TJB |
10171 | } |
10172 | ||
10173 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10174 | ||
2060206e | 10175 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10176 | |
10177 | /* Find the address where the end of the breakpoint range should be | |
10178 | placed, given the SAL of the end of the range. This is so that if | |
10179 | the user provides a line number, the end of the range is set to the | |
10180 | last instruction of the given line. */ | |
10181 | ||
10182 | static CORE_ADDR | |
10183 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10184 | { | |
10185 | CORE_ADDR end; | |
10186 | ||
10187 | /* If the user provided a PC value, use it. Otherwise, | |
10188 | find the address of the end of the given location. */ | |
10189 | if (sal.explicit_pc) | |
10190 | end = sal.pc; | |
10191 | else | |
10192 | { | |
10193 | int ret; | |
10194 | CORE_ADDR start; | |
10195 | ||
10196 | ret = find_line_pc_range (sal, &start, &end); | |
10197 | if (!ret) | |
10198 | error (_("Could not find location of the end of the range.")); | |
10199 | ||
10200 | /* find_line_pc_range returns the start of the next line. */ | |
10201 | end--; | |
10202 | } | |
10203 | ||
10204 | return end; | |
10205 | } | |
10206 | ||
10207 | /* Implement the "break-range" CLI command. */ | |
10208 | ||
10209 | static void | |
10210 | break_range_command (char *arg, int from_tty) | |
10211 | { | |
10212 | char *arg_start, *addr_string_start, *addr_string_end; | |
10213 | struct linespec_result canonical_start, canonical_end; | |
10214 | int bp_count, can_use_bp, length; | |
10215 | CORE_ADDR end; | |
10216 | struct breakpoint *b; | |
10217 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10218 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10219 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10220 | |
10221 | /* We don't support software ranged breakpoints. */ | |
10222 | if (target_ranged_break_num_registers () < 0) | |
10223 | error (_("This target does not support hardware ranged breakpoints.")); | |
10224 | ||
10225 | bp_count = hw_breakpoint_used_count (); | |
10226 | bp_count += target_ranged_break_num_registers (); | |
10227 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10228 | bp_count, 0); | |
10229 | if (can_use_bp < 0) | |
10230 | error (_("Hardware breakpoints used exceeds limit.")); | |
10231 | ||
f8eba3c6 | 10232 | arg = skip_spaces (arg); |
f1310107 TJB |
10233 | if (arg == NULL || arg[0] == '\0') |
10234 | error(_("No address range specified.")); | |
10235 | ||
f1310107 TJB |
10236 | init_linespec_result (&canonical_start); |
10237 | ||
f8eba3c6 TT |
10238 | arg_start = arg; |
10239 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 10240 | |
f8eba3c6 | 10241 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
10242 | |
10243 | if (arg[0] != ',') | |
10244 | error (_("Too few arguments.")); | |
f8eba3c6 | 10245 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10246 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10247 | |
10248 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10249 | ||
10250 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10251 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10252 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10253 | ||
f8eba3c6 TT |
10254 | sal_start = lsal_start->sals.sals[0]; |
10255 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10256 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10257 | |
10258 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10259 | arg = skip_spaces (arg); |
f1310107 TJB |
10260 | |
10261 | /* Parse the end location. */ | |
10262 | ||
f1310107 TJB |
10263 | init_linespec_result (&canonical_end); |
10264 | arg_start = arg; | |
10265 | ||
f8eba3c6 | 10266 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10267 | parse_breakpoint_sals because we need to specify the start location's |
10268 | symtab and line as the default symtab and line for the end of the | |
10269 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10270 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
10271 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
10272 | sal_start.symtab, sal_start.line, | |
10273 | &canonical_end, NULL, NULL); | |
10274 | ||
10275 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10276 | |
f8eba3c6 | 10277 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10278 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10279 | |
10280 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10281 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10282 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10283 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10284 | ||
f8eba3c6 TT |
10285 | sal_end = lsal_end->sals.sals[0]; |
10286 | addr_string_end = savestring (arg_start, arg - arg_start); | |
10287 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
10288 | |
10289 | end = find_breakpoint_range_end (sal_end); | |
10290 | if (sal_start.pc > end) | |
177b42fe | 10291 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10292 | |
10293 | length = end - sal_start.pc + 1; | |
10294 | if (length < 0) | |
10295 | /* Length overflowed. */ | |
10296 | error (_("Address range too large.")); | |
10297 | else if (length == 1) | |
10298 | { | |
10299 | /* This range is simple enough to be handled by | |
10300 | the `hbreak' command. */ | |
10301 | hbreak_command (addr_string_start, 1); | |
10302 | ||
10303 | do_cleanups (cleanup_bkpt); | |
10304 | ||
10305 | return; | |
10306 | } | |
10307 | ||
10308 | /* Now set up the breakpoint. */ | |
10309 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10310 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10311 | set_breakpoint_count (breakpoint_count + 1); |
10312 | b->number = breakpoint_count; | |
10313 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
10314 | b->addr_string = xstrdup (addr_string_start); |
10315 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
10316 | b->loc->length = length; |
10317 | ||
f8eba3c6 | 10318 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10319 | |
10320 | mention (b); | |
8d3788bd | 10321 | observer_notify_breakpoint_created (b); |
44702360 | 10322 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10323 | } |
10324 | ||
4a64f543 MS |
10325 | /* Return non-zero if EXP is verified as constant. Returned zero |
10326 | means EXP is variable. Also the constant detection may fail for | |
10327 | some constant expressions and in such case still falsely return | |
10328 | zero. */ | |
2e6e3d9c | 10329 | |
65d79d4b SDJ |
10330 | static int |
10331 | watchpoint_exp_is_const (const struct expression *exp) | |
10332 | { | |
10333 | int i = exp->nelts; | |
10334 | ||
10335 | while (i > 0) | |
10336 | { | |
10337 | int oplenp, argsp; | |
10338 | ||
10339 | /* We are only interested in the descriptor of each element. */ | |
10340 | operator_length (exp, i, &oplenp, &argsp); | |
10341 | i -= oplenp; | |
10342 | ||
10343 | switch (exp->elts[i].opcode) | |
10344 | { | |
10345 | case BINOP_ADD: | |
10346 | case BINOP_SUB: | |
10347 | case BINOP_MUL: | |
10348 | case BINOP_DIV: | |
10349 | case BINOP_REM: | |
10350 | case BINOP_MOD: | |
10351 | case BINOP_LSH: | |
10352 | case BINOP_RSH: | |
10353 | case BINOP_LOGICAL_AND: | |
10354 | case BINOP_LOGICAL_OR: | |
10355 | case BINOP_BITWISE_AND: | |
10356 | case BINOP_BITWISE_IOR: | |
10357 | case BINOP_BITWISE_XOR: | |
10358 | case BINOP_EQUAL: | |
10359 | case BINOP_NOTEQUAL: | |
10360 | case BINOP_LESS: | |
10361 | case BINOP_GTR: | |
10362 | case BINOP_LEQ: | |
10363 | case BINOP_GEQ: | |
10364 | case BINOP_REPEAT: | |
10365 | case BINOP_COMMA: | |
10366 | case BINOP_EXP: | |
10367 | case BINOP_MIN: | |
10368 | case BINOP_MAX: | |
10369 | case BINOP_INTDIV: | |
10370 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10371 | case TERNOP_COND: |
10372 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10373 | |
10374 | case OP_LONG: | |
10375 | case OP_DOUBLE: | |
10376 | case OP_DECFLOAT: | |
10377 | case OP_LAST: | |
10378 | case OP_COMPLEX: | |
10379 | case OP_STRING: | |
65d79d4b SDJ |
10380 | case OP_ARRAY: |
10381 | case OP_TYPE: | |
608b4967 TT |
10382 | case OP_TYPEOF: |
10383 | case OP_DECLTYPE: | |
6e72ca20 | 10384 | case OP_TYPEID: |
65d79d4b SDJ |
10385 | case OP_NAME: |
10386 | case OP_OBJC_NSSTRING: | |
10387 | ||
10388 | case UNOP_NEG: | |
10389 | case UNOP_LOGICAL_NOT: | |
10390 | case UNOP_COMPLEMENT: | |
10391 | case UNOP_ADDR: | |
10392 | case UNOP_HIGH: | |
aeaa2474 | 10393 | case UNOP_CAST: |
9eaf6705 TT |
10394 | |
10395 | case UNOP_CAST_TYPE: | |
10396 | case UNOP_REINTERPRET_CAST: | |
10397 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10398 | /* Unary, binary and ternary operators: We have to check |
10399 | their operands. If they are constant, then so is the | |
10400 | result of that operation. For instance, if A and B are | |
10401 | determined to be constants, then so is "A + B". | |
10402 | ||
10403 | UNOP_IND is one exception to the rule above, because the | |
10404 | value of *ADDR is not necessarily a constant, even when | |
10405 | ADDR is. */ | |
65d79d4b SDJ |
10406 | break; |
10407 | ||
10408 | case OP_VAR_VALUE: | |
10409 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10410 | |
65d79d4b | 10411 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10412 | possible that a buggy compiler could mark a variable as |
10413 | constant even when it is not, and TYPE_CONST would return | |
10414 | true in this case, while SYMBOL_CLASS wouldn't. | |
10415 | ||
10416 | We also have to check for function symbols because they | |
10417 | are always constant. */ | |
65d79d4b SDJ |
10418 | { |
10419 | struct symbol *s = exp->elts[i + 2].symbol; | |
10420 | ||
10421 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10422 | && SYMBOL_CLASS (s) != LOC_CONST | |
10423 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10424 | return 0; | |
10425 | break; | |
10426 | } | |
10427 | ||
10428 | /* The default action is to return 0 because we are using | |
10429 | the optimistic approach here: If we don't know something, | |
10430 | then it is not a constant. */ | |
10431 | default: | |
10432 | return 0; | |
10433 | } | |
10434 | } | |
10435 | ||
10436 | return 1; | |
10437 | } | |
10438 | ||
3a5c3e22 PA |
10439 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10440 | ||
10441 | static void | |
10442 | dtor_watchpoint (struct breakpoint *self) | |
10443 | { | |
10444 | struct watchpoint *w = (struct watchpoint *) self; | |
10445 | ||
10446 | xfree (w->cond_exp); | |
10447 | xfree (w->exp); | |
10448 | xfree (w->exp_string); | |
10449 | xfree (w->exp_string_reparse); | |
10450 | value_free (w->val); | |
10451 | ||
10452 | base_breakpoint_ops.dtor (self); | |
10453 | } | |
10454 | ||
348d480f PA |
10455 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10456 | ||
10457 | static void | |
10458 | re_set_watchpoint (struct breakpoint *b) | |
10459 | { | |
3a5c3e22 PA |
10460 | struct watchpoint *w = (struct watchpoint *) b; |
10461 | ||
348d480f PA |
10462 | /* Watchpoint can be either on expression using entirely global |
10463 | variables, or it can be on local variables. | |
10464 | ||
10465 | Watchpoints of the first kind are never auto-deleted, and even | |
10466 | persist across program restarts. Since they can use variables | |
10467 | from shared libraries, we need to reparse expression as libraries | |
10468 | are loaded and unloaded. | |
10469 | ||
10470 | Watchpoints on local variables can also change meaning as result | |
10471 | of solib event. For example, if a watchpoint uses both a local | |
10472 | and a global variables in expression, it's a local watchpoint, | |
10473 | but unloading of a shared library will make the expression | |
10474 | invalid. This is not a very common use case, but we still | |
10475 | re-evaluate expression, to avoid surprises to the user. | |
10476 | ||
10477 | Note that for local watchpoints, we re-evaluate it only if | |
10478 | watchpoints frame id is still valid. If it's not, it means the | |
10479 | watchpoint is out of scope and will be deleted soon. In fact, | |
10480 | I'm not sure we'll ever be called in this case. | |
10481 | ||
10482 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10483 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10484 | |
3a5c3e22 PA |
10485 | Don't do anything about disabled watchpoints, since they will be |
10486 | reevaluated again when enabled. */ | |
10487 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10488 | } |
10489 | ||
77b06cd7 TJB |
10490 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10491 | ||
10492 | static int | |
10493 | insert_watchpoint (struct bp_location *bl) | |
10494 | { | |
3a5c3e22 PA |
10495 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10496 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10497 | |
10498 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10499 | w->cond_exp); |
77b06cd7 TJB |
10500 | } |
10501 | ||
10502 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10503 | ||
10504 | static int | |
10505 | remove_watchpoint (struct bp_location *bl) | |
10506 | { | |
3a5c3e22 PA |
10507 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10508 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10509 | |
10510 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10511 | w->cond_exp); |
e09342b5 TJB |
10512 | } |
10513 | ||
e09342b5 | 10514 | static int |
348d480f | 10515 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10516 | struct address_space *aspace, CORE_ADDR bp_addr, |
10517 | const struct target_waitstatus *ws) | |
e09342b5 | 10518 | { |
348d480f | 10519 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10520 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10521 | |
348d480f PA |
10522 | /* Continuable hardware watchpoints are treated as non-existent if the |
10523 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10524 | some data address). Otherwise gdb won't stop on a break instruction | |
10525 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10526 | been defined. Also skip watchpoints which we know did not trigger | |
10527 | (did not match the data address). */ | |
10528 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10529 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10530 | return 0; |
9c06b0b4 | 10531 | |
348d480f | 10532 | return 1; |
9c06b0b4 TJB |
10533 | } |
10534 | ||
348d480f PA |
10535 | static void |
10536 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10537 | { |
348d480f | 10538 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10539 | |
348d480f | 10540 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10541 | } |
10542 | ||
10543 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10544 | hardware watchpoints. */ |
9c06b0b4 TJB |
10545 | |
10546 | static int | |
348d480f | 10547 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10548 | { |
3a5c3e22 PA |
10549 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10550 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10551 | |
10552 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10553 | } |
10554 | ||
10555 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10556 | hardware watchpoints. */ |
9c06b0b4 TJB |
10557 | |
10558 | static int | |
348d480f | 10559 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10560 | { |
efa80663 PA |
10561 | /* Read and access watchpoints only work with hardware support. */ |
10562 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10563 | } |
10564 | ||
9c06b0b4 | 10565 | static enum print_stop_action |
348d480f | 10566 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10567 | { |
348d480f PA |
10568 | struct cleanup *old_chain; |
10569 | struct breakpoint *b; | |
f99d8bf4 | 10570 | struct ui_file *stb; |
348d480f | 10571 | enum print_stop_action result; |
3a5c3e22 | 10572 | struct watchpoint *w; |
79a45e25 | 10573 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10574 | |
10575 | gdb_assert (bs->bp_location_at != NULL); | |
10576 | ||
348d480f | 10577 | b = bs->breakpoint_at; |
3a5c3e22 | 10578 | w = (struct watchpoint *) b; |
348d480f | 10579 | |
f99d8bf4 PA |
10580 | stb = mem_fileopen (); |
10581 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10582 | |
10583 | switch (b->type) | |
10584 | { | |
348d480f | 10585 | case bp_watchpoint: |
9c06b0b4 TJB |
10586 | case bp_hardware_watchpoint: |
10587 | annotate_watchpoint (b->number); | |
10588 | if (ui_out_is_mi_like_p (uiout)) | |
10589 | ui_out_field_string | |
10590 | (uiout, "reason", | |
10591 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10592 | mention (b); |
10593 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10594 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10595 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10596 | ui_out_field_stream (uiout, "old", stb); |
10597 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10598 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10599 | ui_out_field_stream (uiout, "new", stb); |
10600 | ui_out_text (uiout, "\n"); | |
10601 | /* More than one watchpoint may have been triggered. */ | |
10602 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10603 | break; |
10604 | ||
10605 | case bp_read_watchpoint: | |
10606 | if (ui_out_is_mi_like_p (uiout)) | |
10607 | ui_out_field_string | |
10608 | (uiout, "reason", | |
10609 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10610 | mention (b); |
10611 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10612 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10613 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10614 | ui_out_field_stream (uiout, "value", stb); |
10615 | ui_out_text (uiout, "\n"); | |
10616 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10617 | break; |
10618 | ||
10619 | case bp_access_watchpoint: | |
348d480f PA |
10620 | if (bs->old_val != NULL) |
10621 | { | |
10622 | annotate_watchpoint (b->number); | |
10623 | if (ui_out_is_mi_like_p (uiout)) | |
10624 | ui_out_field_string | |
10625 | (uiout, "reason", | |
10626 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10627 | mention (b); | |
10628 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10629 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10630 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10631 | ui_out_field_stream (uiout, "old", stb); |
10632 | ui_out_text (uiout, "\nNew value = "); | |
10633 | } | |
10634 | else | |
10635 | { | |
10636 | mention (b); | |
10637 | if (ui_out_is_mi_like_p (uiout)) | |
10638 | ui_out_field_string | |
10639 | (uiout, "reason", | |
10640 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10641 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10642 | ui_out_text (uiout, "\nValue = "); | |
10643 | } | |
f99d8bf4 | 10644 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10645 | ui_out_field_stream (uiout, "new", stb); |
10646 | ui_out_text (uiout, "\n"); | |
10647 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10648 | break; |
10649 | default: | |
348d480f | 10650 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10651 | } |
10652 | ||
348d480f PA |
10653 | do_cleanups (old_chain); |
10654 | return result; | |
10655 | } | |
10656 | ||
10657 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10658 | watchpoints. */ | |
10659 | ||
10660 | static void | |
10661 | print_mention_watchpoint (struct breakpoint *b) | |
10662 | { | |
10663 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10664 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10665 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10666 | |
10667 | switch (b->type) | |
10668 | { | |
10669 | case bp_watchpoint: | |
10670 | ui_out_text (uiout, "Watchpoint "); | |
10671 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10672 | break; | |
10673 | case bp_hardware_watchpoint: | |
10674 | ui_out_text (uiout, "Hardware watchpoint "); | |
10675 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10676 | break; | |
10677 | case bp_read_watchpoint: | |
10678 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10679 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10680 | break; | |
10681 | case bp_access_watchpoint: | |
10682 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10683 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10684 | break; | |
10685 | default: | |
10686 | internal_error (__FILE__, __LINE__, | |
10687 | _("Invalid hardware watchpoint type.")); | |
10688 | } | |
10689 | ||
10690 | ui_out_field_int (uiout, "number", b->number); | |
10691 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10692 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10693 | do_cleanups (ui_out_chain); |
10694 | } | |
10695 | ||
10696 | /* Implement the "print_recreate" breakpoint_ops method for | |
10697 | watchpoints. */ | |
10698 | ||
10699 | static void | |
10700 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10701 | { | |
3a5c3e22 PA |
10702 | struct watchpoint *w = (struct watchpoint *) b; |
10703 | ||
348d480f PA |
10704 | switch (b->type) |
10705 | { | |
10706 | case bp_watchpoint: | |
10707 | case bp_hardware_watchpoint: | |
10708 | fprintf_unfiltered (fp, "watch"); | |
10709 | break; | |
10710 | case bp_read_watchpoint: | |
10711 | fprintf_unfiltered (fp, "rwatch"); | |
10712 | break; | |
10713 | case bp_access_watchpoint: | |
10714 | fprintf_unfiltered (fp, "awatch"); | |
10715 | break; | |
10716 | default: | |
10717 | internal_error (__FILE__, __LINE__, | |
10718 | _("Invalid watchpoint type.")); | |
10719 | } | |
10720 | ||
3a5c3e22 | 10721 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10722 | print_recreate_thread (b, fp); |
348d480f PA |
10723 | } |
10724 | ||
427cd150 TT |
10725 | /* Implement the "explains_signal" breakpoint_ops method for |
10726 | watchpoints. */ | |
10727 | ||
47591c29 | 10728 | static int |
427cd150 TT |
10729 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10730 | { | |
10731 | /* A software watchpoint cannot cause a signal other than | |
10732 | GDB_SIGNAL_TRAP. */ | |
10733 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10734 | return 0; |
427cd150 | 10735 | |
47591c29 | 10736 | return 1; |
427cd150 TT |
10737 | } |
10738 | ||
348d480f PA |
10739 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10740 | ||
2060206e | 10741 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10742 | |
10743 | /* Implement the "insert" breakpoint_ops method for | |
10744 | masked hardware watchpoints. */ | |
10745 | ||
10746 | static int | |
10747 | insert_masked_watchpoint (struct bp_location *bl) | |
10748 | { | |
3a5c3e22 PA |
10749 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10750 | ||
10751 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10752 | bl->watchpoint_type); |
10753 | } | |
10754 | ||
10755 | /* Implement the "remove" breakpoint_ops method for | |
10756 | masked hardware watchpoints. */ | |
10757 | ||
10758 | static int | |
10759 | remove_masked_watchpoint (struct bp_location *bl) | |
10760 | { | |
3a5c3e22 PA |
10761 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10762 | ||
10763 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10764 | bl->watchpoint_type); |
10765 | } | |
10766 | ||
10767 | /* Implement the "resources_needed" breakpoint_ops method for | |
10768 | masked hardware watchpoints. */ | |
10769 | ||
10770 | static int | |
10771 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10772 | { | |
3a5c3e22 PA |
10773 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10774 | ||
10775 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10776 | } |
10777 | ||
10778 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10779 | masked hardware watchpoints. */ | |
10780 | ||
10781 | static int | |
10782 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10783 | { | |
10784 | return 0; | |
10785 | } | |
10786 | ||
10787 | /* Implement the "print_it" breakpoint_ops method for | |
10788 | masked hardware watchpoints. */ | |
10789 | ||
10790 | static enum print_stop_action | |
10791 | print_it_masked_watchpoint (bpstat bs) | |
10792 | { | |
10793 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10794 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10795 | |
10796 | /* Masked watchpoints have only one location. */ | |
10797 | gdb_assert (b->loc && b->loc->next == NULL); | |
10798 | ||
10799 | switch (b->type) | |
10800 | { | |
10801 | case bp_hardware_watchpoint: | |
10802 | annotate_watchpoint (b->number); | |
10803 | if (ui_out_is_mi_like_p (uiout)) | |
10804 | ui_out_field_string | |
10805 | (uiout, "reason", | |
10806 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
10807 | break; | |
10808 | ||
10809 | case bp_read_watchpoint: | |
10810 | if (ui_out_is_mi_like_p (uiout)) | |
10811 | ui_out_field_string | |
10812 | (uiout, "reason", | |
10813 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
10814 | break; | |
10815 | ||
10816 | case bp_access_watchpoint: | |
10817 | if (ui_out_is_mi_like_p (uiout)) | |
10818 | ui_out_field_string | |
10819 | (uiout, "reason", | |
10820 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10821 | break; | |
10822 | default: | |
10823 | internal_error (__FILE__, __LINE__, | |
10824 | _("Invalid hardware watchpoint type.")); | |
10825 | } | |
10826 | ||
10827 | mention (b); | |
9c06b0b4 TJB |
10828 | ui_out_text (uiout, _("\n\ |
10829 | Check the underlying instruction at PC for the memory\n\ | |
10830 | address and value which triggered this watchpoint.\n")); | |
10831 | ui_out_text (uiout, "\n"); | |
10832 | ||
10833 | /* More than one watchpoint may have been triggered. */ | |
10834 | return PRINT_UNKNOWN; | |
10835 | } | |
10836 | ||
10837 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10838 | masked hardware watchpoints. */ | |
10839 | ||
10840 | static void | |
10841 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10842 | struct ui_out *uiout) | |
10843 | { | |
3a5c3e22 PA |
10844 | struct watchpoint *w = (struct watchpoint *) b; |
10845 | ||
9c06b0b4 TJB |
10846 | /* Masked watchpoints have only one location. */ |
10847 | gdb_assert (b->loc && b->loc->next == NULL); | |
10848 | ||
10849 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 10850 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
10851 | ui_out_text (uiout, "\n"); |
10852 | } | |
10853 | ||
10854 | /* Implement the "print_mention" breakpoint_ops method for | |
10855 | masked hardware watchpoints. */ | |
10856 | ||
10857 | static void | |
10858 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10859 | { | |
3a5c3e22 | 10860 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10861 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
10862 | struct cleanup *ui_out_chain; |
10863 | ||
10864 | switch (b->type) | |
10865 | { | |
10866 | case bp_hardware_watchpoint: | |
10867 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
10868 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10869 | break; | |
10870 | case bp_read_watchpoint: | |
10871 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
10872 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10873 | break; | |
10874 | case bp_access_watchpoint: | |
10875 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
10876 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10877 | break; | |
10878 | default: | |
10879 | internal_error (__FILE__, __LINE__, | |
10880 | _("Invalid hardware watchpoint type.")); | |
10881 | } | |
10882 | ||
10883 | ui_out_field_int (uiout, "number", b->number); | |
10884 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10885 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
10886 | do_cleanups (ui_out_chain); |
10887 | } | |
10888 | ||
10889 | /* Implement the "print_recreate" breakpoint_ops method for | |
10890 | masked hardware watchpoints. */ | |
10891 | ||
10892 | static void | |
10893 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10894 | { | |
3a5c3e22 | 10895 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10896 | char tmp[40]; |
10897 | ||
10898 | switch (b->type) | |
10899 | { | |
10900 | case bp_hardware_watchpoint: | |
10901 | fprintf_unfiltered (fp, "watch"); | |
10902 | break; | |
10903 | case bp_read_watchpoint: | |
10904 | fprintf_unfiltered (fp, "rwatch"); | |
10905 | break; | |
10906 | case bp_access_watchpoint: | |
10907 | fprintf_unfiltered (fp, "awatch"); | |
10908 | break; | |
10909 | default: | |
10910 | internal_error (__FILE__, __LINE__, | |
10911 | _("Invalid hardware watchpoint type.")); | |
10912 | } | |
10913 | ||
3a5c3e22 PA |
10914 | sprintf_vma (tmp, w->hw_wp_mask); |
10915 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10916 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10917 | } |
10918 | ||
10919 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10920 | ||
2060206e | 10921 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10922 | |
10923 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10924 | ||
10925 | static int | |
10926 | is_masked_watchpoint (const struct breakpoint *b) | |
10927 | { | |
10928 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10929 | } | |
10930 | ||
53a5351d JM |
10931 | /* accessflag: hw_write: watch write, |
10932 | hw_read: watch read, | |
10933 | hw_access: watch access (read or write) */ | |
c906108c | 10934 | static void |
bbc13ae3 | 10935 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10936 | int just_location, int internal) |
c906108c | 10937 | { |
d983da9c | 10938 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 10939 | struct expression *exp; |
270140bd | 10940 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 10941 | struct value *val, *mark, *result; |
bb9d5f81 | 10942 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 10943 | struct frame_info *frame; |
bbc13ae3 KS |
10944 | const char *exp_start = NULL; |
10945 | const char *exp_end = NULL; | |
10946 | const char *tok, *end_tok; | |
9c06b0b4 | 10947 | int toklen = -1; |
bbc13ae3 KS |
10948 | const char *cond_start = NULL; |
10949 | const char *cond_end = NULL; | |
c906108c | 10950 | enum bptype bp_type; |
37e4754d | 10951 | int thread = -1; |
0cf6dd15 | 10952 | int pc = 0; |
9c06b0b4 TJB |
10953 | /* Flag to indicate whether we are going to use masks for |
10954 | the hardware watchpoint. */ | |
10955 | int use_mask = 0; | |
10956 | CORE_ADDR mask = 0; | |
3a5c3e22 | 10957 | struct watchpoint *w; |
bbc13ae3 KS |
10958 | char *expression; |
10959 | struct cleanup *back_to; | |
c906108c | 10960 | |
37e4754d LM |
10961 | /* Make sure that we actually have parameters to parse. */ |
10962 | if (arg != NULL && arg[0] != '\0') | |
10963 | { | |
bbc13ae3 KS |
10964 | const char *value_start; |
10965 | ||
10966 | exp_end = arg + strlen (arg); | |
37e4754d | 10967 | |
9c06b0b4 TJB |
10968 | /* Look for "parameter value" pairs at the end |
10969 | of the arguments string. */ | |
bbc13ae3 | 10970 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10971 | { |
10972 | /* Skip whitespace at the end of the argument list. */ | |
10973 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10974 | tok--; | |
10975 | ||
10976 | /* Find the beginning of the last token. | |
10977 | This is the value of the parameter. */ | |
10978 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10979 | tok--; | |
10980 | value_start = tok + 1; | |
10981 | ||
10982 | /* Skip whitespace. */ | |
10983 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10984 | tok--; | |
10985 | ||
10986 | end_tok = tok; | |
10987 | ||
10988 | /* Find the beginning of the second to last token. | |
10989 | This is the parameter itself. */ | |
10990 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10991 | tok--; | |
10992 | tok++; | |
10993 | toklen = end_tok - tok + 1; | |
10994 | ||
61012eef | 10995 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 TJB |
10996 | { |
10997 | /* At this point we've found a "thread" token, which means | |
10998 | the user is trying to set a watchpoint that triggers | |
10999 | only in a specific thread. */ | |
11000 | char *endp; | |
37e4754d | 11001 | |
9c06b0b4 TJB |
11002 | if (thread != -1) |
11003 | error(_("You can specify only one thread.")); | |
37e4754d | 11004 | |
9c06b0b4 TJB |
11005 | /* Extract the thread ID from the next token. */ |
11006 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 11007 | |
9c06b0b4 TJB |
11008 | /* Check if the user provided a valid numeric value for the |
11009 | thread ID. */ | |
11010 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
11011 | error (_("Invalid thread ID specification %s."), value_start); | |
11012 | ||
11013 | /* Check if the thread actually exists. */ | |
11014 | if (!valid_thread_id (thread)) | |
af4908ba | 11015 | invalid_thread_id_error (thread); |
9c06b0b4 | 11016 | } |
61012eef | 11017 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
11018 | { |
11019 | /* We've found a "mask" token, which means the user wants to | |
11020 | create a hardware watchpoint that is going to have the mask | |
11021 | facility. */ | |
11022 | struct value *mask_value, *mark; | |
37e4754d | 11023 | |
9c06b0b4 TJB |
11024 | if (use_mask) |
11025 | error(_("You can specify only one mask.")); | |
37e4754d | 11026 | |
9c06b0b4 | 11027 | use_mask = just_location = 1; |
37e4754d | 11028 | |
9c06b0b4 TJB |
11029 | mark = value_mark (); |
11030 | mask_value = parse_to_comma_and_eval (&value_start); | |
11031 | mask = value_as_address (mask_value); | |
11032 | value_free_to_mark (mark); | |
11033 | } | |
11034 | else | |
11035 | /* We didn't recognize what we found. We should stop here. */ | |
11036 | break; | |
37e4754d | 11037 | |
9c06b0b4 TJB |
11038 | /* Truncate the string and get rid of the "parameter value" pair before |
11039 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11040 | exp_end = tok; |
9c06b0b4 | 11041 | } |
37e4754d | 11042 | } |
bbc13ae3 KS |
11043 | else |
11044 | exp_end = arg; | |
37e4754d | 11045 | |
bbc13ae3 KS |
11046 | /* Parse the rest of the arguments. From here on out, everything |
11047 | is in terms of a newly allocated string instead of the original | |
11048 | ARG. */ | |
c906108c | 11049 | innermost_block = NULL; |
bbc13ae3 KS |
11050 | expression = savestring (arg, exp_end - arg); |
11051 | back_to = make_cleanup (xfree, expression); | |
11052 | exp_start = arg = expression; | |
1bb9788d | 11053 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11054 | exp_end = arg; |
fa8a61dc TT |
11055 | /* Remove trailing whitespace from the expression before saving it. |
11056 | This makes the eventual display of the expression string a bit | |
11057 | prettier. */ | |
11058 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11059 | --exp_end; | |
11060 | ||
65d79d4b SDJ |
11061 | /* Checking if the expression is not constant. */ |
11062 | if (watchpoint_exp_is_const (exp)) | |
11063 | { | |
11064 | int len; | |
11065 | ||
11066 | len = exp_end - exp_start; | |
11067 | while (len > 0 && isspace (exp_start[len - 1])) | |
11068 | len--; | |
11069 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11070 | } | |
11071 | ||
c906108c SS |
11072 | exp_valid_block = innermost_block; |
11073 | mark = value_mark (); | |
3a1115a0 | 11074 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b | 11075 | |
bb9d5f81 PP |
11076 | if (val != NULL && just_location) |
11077 | { | |
11078 | saved_bitpos = value_bitpos (val); | |
11079 | saved_bitsize = value_bitsize (val); | |
11080 | } | |
11081 | ||
06a64a0b TT |
11082 | if (just_location) |
11083 | { | |
9c06b0b4 TJB |
11084 | int ret; |
11085 | ||
06a64a0b | 11086 | exp_valid_block = NULL; |
a1442452 | 11087 | val = value_addr (result); |
06a64a0b TT |
11088 | release_value (val); |
11089 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11090 | |
11091 | if (use_mask) | |
11092 | { | |
11093 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11094 | mask); | |
11095 | if (ret == -1) | |
11096 | error (_("This target does not support masked watchpoints.")); | |
11097 | else if (ret == -2) | |
11098 | error (_("Invalid mask or memory region.")); | |
11099 | } | |
06a64a0b TT |
11100 | } |
11101 | else if (val != NULL) | |
fa4727a6 | 11102 | release_value (val); |
c906108c | 11103 | |
bbc13ae3 KS |
11104 | tok = skip_spaces_const (arg); |
11105 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11106 | |
11107 | toklen = end_tok - tok; | |
11108 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11109 | { | |
2d134ed3 PA |
11110 | struct expression *cond; |
11111 | ||
60e1c644 | 11112 | innermost_block = NULL; |
c906108c | 11113 | tok = cond_start = end_tok + 1; |
1bb9788d | 11114 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11115 | |
11116 | /* The watchpoint expression may not be local, but the condition | |
11117 | may still be. E.g.: `watch global if local > 0'. */ | |
11118 | cond_exp_valid_block = innermost_block; | |
11119 | ||
2d134ed3 | 11120 | xfree (cond); |
c906108c SS |
11121 | cond_end = tok; |
11122 | } | |
11123 | if (*tok) | |
8a3fe4f8 | 11124 | error (_("Junk at end of command.")); |
c906108c | 11125 | |
d983da9c | 11126 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11127 | |
11128 | /* If the expression is "local", then set up a "watchpoint scope" | |
11129 | breakpoint at the point where we've left the scope of the watchpoint | |
11130 | expression. Create the scope breakpoint before the watchpoint, so | |
11131 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11132 | if (exp_valid_block && frame) |
d983da9c | 11133 | { |
edb3359d DJ |
11134 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11135 | { | |
11136 | scope_breakpoint | |
a6d9a66e UW |
11137 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11138 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11139 | bp_watchpoint_scope, |
11140 | &momentary_breakpoint_ops); | |
d983da9c | 11141 | |
edb3359d | 11142 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11143 | |
edb3359d DJ |
11144 | /* Automatically delete the breakpoint when it hits. */ |
11145 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11146 | |
edb3359d DJ |
11147 | /* Only break in the proper frame (help with recursion). */ |
11148 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11149 | |
edb3359d | 11150 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11151 | scope_breakpoint->loc->gdbarch |
11152 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11153 | scope_breakpoint->loc->requested_address |
11154 | = frame_unwind_caller_pc (frame); | |
11155 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11156 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11157 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11158 | scope_breakpoint->type); |
11159 | } | |
d983da9c DJ |
11160 | } |
11161 | ||
e8369a73 AB |
11162 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11163 | watchpoints here even if hardware watchpoints are turned off, a call | |
11164 | to update_watchpoint later in this function will cause the type to | |
11165 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11166 | ||
11167 | if (accessflag == hw_read) | |
11168 | bp_type = bp_read_watchpoint; | |
11169 | else if (accessflag == hw_access) | |
11170 | bp_type = bp_access_watchpoint; | |
11171 | else | |
11172 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11173 | |
11174 | w = XCNEW (struct watchpoint); | |
11175 | b = &w->base; | |
348d480f | 11176 | if (use_mask) |
3a5c3e22 PA |
11177 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11178 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11179 | else |
3a5c3e22 PA |
11180 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11181 | &watchpoint_breakpoint_ops); | |
37e4754d | 11182 | b->thread = thread; |
b5de0fa7 | 11183 | b->disposition = disp_donttouch; |
348d480f | 11184 | b->pspace = current_program_space; |
3a5c3e22 PA |
11185 | w->exp = exp; |
11186 | w->exp_valid_block = exp_valid_block; | |
11187 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11188 | if (just_location) |
11189 | { | |
11190 | struct type *t = value_type (val); | |
11191 | CORE_ADDR addr = value_as_address (val); | |
11192 | char *name; | |
11193 | ||
11194 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11195 | name = type_to_string (t); | |
11196 | ||
3a5c3e22 | 11197 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11198 | core_addr_to_string (addr)); |
06a64a0b TT |
11199 | xfree (name); |
11200 | ||
3a5c3e22 | 11201 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11202 | (int) (exp_end - exp_start), exp_start); |
11203 | ||
06a64a0b TT |
11204 | /* The above expression is in C. */ |
11205 | b->language = language_c; | |
11206 | } | |
11207 | else | |
3a5c3e22 | 11208 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11209 | |
11210 | if (use_mask) | |
11211 | { | |
3a5c3e22 | 11212 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11213 | } |
11214 | else | |
11215 | { | |
3a5c3e22 | 11216 | w->val = val; |
bb9d5f81 PP |
11217 | w->val_bitpos = saved_bitpos; |
11218 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11219 | w->val_valid = 1; |
9c06b0b4 | 11220 | } |
77b06cd7 | 11221 | |
c906108c SS |
11222 | if (cond_start) |
11223 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11224 | else | |
11225 | b->cond_string = 0; | |
c5aa993b | 11226 | |
c906108c | 11227 | if (frame) |
f6bc2008 | 11228 | { |
3a5c3e22 PA |
11229 | w->watchpoint_frame = get_frame_id (frame); |
11230 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11231 | } |
c906108c | 11232 | else |
f6bc2008 | 11233 | { |
3a5c3e22 PA |
11234 | w->watchpoint_frame = null_frame_id; |
11235 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11236 | } |
c906108c | 11237 | |
d983da9c | 11238 | if (scope_breakpoint != NULL) |
c906108c | 11239 | { |
d983da9c DJ |
11240 | /* The scope breakpoint is related to the watchpoint. We will |
11241 | need to act on them together. */ | |
11242 | b->related_breakpoint = scope_breakpoint; | |
11243 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11244 | } |
d983da9c | 11245 | |
06a64a0b TT |
11246 | if (!just_location) |
11247 | value_free_to_mark (mark); | |
2d134ed3 | 11248 | |
492d29ea | 11249 | TRY |
a9634178 TJB |
11250 | { |
11251 | /* Finally update the new watchpoint. This creates the locations | |
11252 | that should be inserted. */ | |
3a5c3e22 | 11253 | update_watchpoint (w, 1); |
a9634178 | 11254 | } |
492d29ea | 11255 | CATCH (e, RETURN_MASK_ALL) |
a9634178 TJB |
11256 | { |
11257 | delete_breakpoint (b); | |
11258 | throw_exception (e); | |
11259 | } | |
492d29ea | 11260 | END_CATCH |
a9634178 | 11261 | |
3ea46bff | 11262 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11263 | do_cleanups (back_to); |
c906108c SS |
11264 | } |
11265 | ||
e09342b5 | 11266 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11267 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11268 | |
c906108c | 11269 | static int |
a9634178 | 11270 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11271 | { |
11272 | int found_memory_cnt = 0; | |
2e70b7b9 | 11273 | struct value *head = v; |
c906108c SS |
11274 | |
11275 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11276 | if (!can_use_hw_watchpoints) |
c906108c | 11277 | return 0; |
c5aa993b | 11278 | |
5c44784c JM |
11279 | /* Make sure that the value of the expression depends only upon |
11280 | memory contents, and values computed from them within GDB. If we | |
11281 | find any register references or function calls, we can't use a | |
11282 | hardware watchpoint. | |
11283 | ||
11284 | The idea here is that evaluating an expression generates a series | |
11285 | of values, one holding the value of every subexpression. (The | |
11286 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11287 | a*b+c.) GDB's values hold almost enough information to establish | |
11288 | the criteria given above --- they identify memory lvalues, | |
11289 | register lvalues, computed values, etcetera. So we can evaluate | |
11290 | the expression, and then scan the chain of values that leaves | |
11291 | behind to decide whether we can detect any possible change to the | |
11292 | expression's final value using only hardware watchpoints. | |
11293 | ||
11294 | However, I don't think that the values returned by inferior | |
11295 | function calls are special in any way. So this function may not | |
11296 | notice that an expression involving an inferior function call | |
11297 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11298 | for (; v; v = value_next (v)) |
c906108c | 11299 | { |
5c44784c | 11300 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11301 | { |
8464be76 DJ |
11302 | if (v != head && value_lazy (v)) |
11303 | /* A lazy memory lvalue in the chain is one that GDB never | |
11304 | needed to fetch; we either just used its address (e.g., | |
11305 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11306 | in `a,b'). This doesn't apply to HEAD; if that is | |
11307 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11308 | ; |
53a5351d | 11309 | else |
5c44784c JM |
11310 | { |
11311 | /* Ahh, memory we actually used! Check if we can cover | |
11312 | it with hardware watchpoints. */ | |
df407dfe | 11313 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11314 | |
11315 | /* We only watch structs and arrays if user asked for it | |
11316 | explicitly, never if they just happen to appear in a | |
11317 | middle of some value chain. */ | |
11318 | if (v == head | |
11319 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11320 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11321 | { | |
42ae5230 | 11322 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11323 | int len; |
11324 | int num_regs; | |
11325 | ||
a9634178 | 11326 | len = (target_exact_watchpoints |
e09342b5 TJB |
11327 | && is_scalar_type_recursive (vtype))? |
11328 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11329 | |
e09342b5 TJB |
11330 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11331 | if (!num_regs) | |
2e70b7b9 MS |
11332 | return 0; |
11333 | else | |
e09342b5 | 11334 | found_memory_cnt += num_regs; |
2e70b7b9 | 11335 | } |
5c44784c | 11336 | } |
c5aa993b | 11337 | } |
5086187c AC |
11338 | else if (VALUE_LVAL (v) != not_lval |
11339 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11340 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11341 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11342 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11343 | } |
11344 | ||
11345 | /* The expression itself looks suitable for using a hardware | |
11346 | watchpoint, but give the target machine a chance to reject it. */ | |
11347 | return found_memory_cnt; | |
11348 | } | |
11349 | ||
8b93c638 | 11350 | void |
84f4c1fe | 11351 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11352 | { |
84f4c1fe | 11353 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11354 | } |
11355 | ||
06a64a0b TT |
11356 | /* A helper function that looks for the "-location" argument and then |
11357 | calls watch_command_1. */ | |
11358 | ||
11359 | static void | |
11360 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11361 | { | |
11362 | int just_location = 0; | |
11363 | ||
11364 | if (arg | |
11365 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11366 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11367 | { | |
e9cafbcc | 11368 | arg = skip_spaces (arg); |
06a64a0b TT |
11369 | just_location = 1; |
11370 | } | |
11371 | ||
84f4c1fe | 11372 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11373 | } |
8926118c | 11374 | |
c5aa993b | 11375 | static void |
fba45db2 | 11376 | watch_command (char *arg, int from_tty) |
c906108c | 11377 | { |
06a64a0b | 11378 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11379 | } |
11380 | ||
8b93c638 | 11381 | void |
84f4c1fe | 11382 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11383 | { |
84f4c1fe | 11384 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11385 | } |
8926118c | 11386 | |
c5aa993b | 11387 | static void |
fba45db2 | 11388 | rwatch_command (char *arg, int from_tty) |
c906108c | 11389 | { |
06a64a0b | 11390 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11391 | } |
11392 | ||
8b93c638 | 11393 | void |
84f4c1fe | 11394 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11395 | { |
84f4c1fe | 11396 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11397 | } |
8926118c | 11398 | |
c5aa993b | 11399 | static void |
fba45db2 | 11400 | awatch_command (char *arg, int from_tty) |
c906108c | 11401 | { |
06a64a0b | 11402 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11403 | } |
c906108c | 11404 | \f |
c5aa993b | 11405 | |
43ff13b4 | 11406 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
11407 | because it uses the mechanisms of breakpoints. */ |
11408 | ||
bfec99b2 PA |
11409 | struct until_break_command_continuation_args |
11410 | { | |
11411 | struct breakpoint *breakpoint; | |
11412 | struct breakpoint *breakpoint2; | |
186c406b | 11413 | int thread_num; |
bfec99b2 PA |
11414 | }; |
11415 | ||
43ff13b4 | 11416 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 11417 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 11418 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 11419 | command. */ |
c2c6d25f | 11420 | static void |
fa4cd53f | 11421 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 11422 | { |
bfec99b2 PA |
11423 | struct until_break_command_continuation_args *a = arg; |
11424 | ||
11425 | delete_breakpoint (a->breakpoint); | |
11426 | if (a->breakpoint2) | |
11427 | delete_breakpoint (a->breakpoint2); | |
186c406b | 11428 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
11429 | } |
11430 | ||
c906108c | 11431 | void |
ae66c1fc | 11432 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11433 | { |
11434 | struct symtabs_and_lines sals; | |
11435 | struct symtab_and_line sal; | |
8556afb4 PA |
11436 | struct frame_info *frame; |
11437 | struct gdbarch *frame_gdbarch; | |
11438 | struct frame_id stack_frame_id; | |
11439 | struct frame_id caller_frame_id; | |
c906108c | 11440 | struct breakpoint *breakpoint; |
f107f563 | 11441 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 11442 | struct cleanup *old_chain; |
186c406b TT |
11443 | int thread; |
11444 | struct thread_info *tp; | |
c906108c | 11445 | |
70509625 | 11446 | clear_proceed_status (0); |
c906108c SS |
11447 | |
11448 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11449 | this function. */ |
c5aa993b | 11450 | |
1bfeeb0f | 11451 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 11452 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11453 | get_last_displayed_symtab (), |
f8eba3c6 | 11454 | get_last_displayed_line ()); |
c906108c | 11455 | else |
f8eba3c6 TT |
11456 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
11457 | (struct symtab *) NULL, 0); | |
c5aa993b | 11458 | |
c906108c | 11459 | if (sals.nelts != 1) |
8a3fe4f8 | 11460 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11461 | |
c906108c | 11462 | sal = sals.sals[0]; |
4a64f543 | 11463 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11464 | |
c906108c | 11465 | if (*arg) |
8a3fe4f8 | 11466 | error (_("Junk at end of arguments.")); |
c5aa993b | 11467 | |
c906108c | 11468 | resolve_sal_pc (&sal); |
c5aa993b | 11469 | |
186c406b TT |
11470 | tp = inferior_thread (); |
11471 | thread = tp->num; | |
11472 | ||
883bc8d1 PA |
11473 | old_chain = make_cleanup (null_cleanup, NULL); |
11474 | ||
8556afb4 PA |
11475 | /* Note linespec handling above invalidates the frame chain. |
11476 | Installing a breakpoint also invalidates the frame chain (as it | |
11477 | may need to switch threads), so do any frame handling before | |
11478 | that. */ | |
11479 | ||
11480 | frame = get_selected_frame (NULL); | |
11481 | frame_gdbarch = get_frame_arch (frame); | |
11482 | stack_frame_id = get_stack_frame_id (frame); | |
11483 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11484 | |
ae66c1fc EZ |
11485 | /* Keep within the current frame, or in frames called by the current |
11486 | one. */ | |
edb3359d | 11487 | |
883bc8d1 | 11488 | if (frame_id_p (caller_frame_id)) |
c906108c | 11489 | { |
883bc8d1 PA |
11490 | struct symtab_and_line sal2; |
11491 | ||
11492 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11493 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 11494 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
11495 | sal2, |
11496 | caller_frame_id, | |
f107f563 VP |
11497 | bp_until); |
11498 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 11499 | |
883bc8d1 | 11500 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11501 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11502 | } |
c5aa993b | 11503 | |
c70a6932 JK |
11504 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11505 | frame = NULL; | |
11506 | ||
883bc8d1 PA |
11507 | if (anywhere) |
11508 | /* If the user told us to continue until a specified location, | |
11509 | we don't specify a frame at which we need to stop. */ | |
11510 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11511 | null_frame_id, bp_until); | |
11512 | else | |
11513 | /* Otherwise, specify the selected frame, because we want to stop | |
11514 | only at the very same frame. */ | |
11515 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11516 | stack_frame_id, bp_until); | |
11517 | make_cleanup_delete_breakpoint (breakpoint); | |
11518 | ||
64ce06e4 | 11519 | proceed (-1, GDB_SIGNAL_DEFAULT); |
f107f563 | 11520 | |
4a64f543 MS |
11521 | /* If we are running asynchronously, and proceed call above has |
11522 | actually managed to start the target, arrange for breakpoints to | |
11523 | be deleted when the target stops. Otherwise, we're already | |
11524 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 11525 | |
8ea051c5 | 11526 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 11527 | { |
bfec99b2 PA |
11528 | struct until_break_command_continuation_args *args; |
11529 | args = xmalloc (sizeof (*args)); | |
f107f563 | 11530 | |
bfec99b2 PA |
11531 | args->breakpoint = breakpoint; |
11532 | args->breakpoint2 = breakpoint2; | |
186c406b | 11533 | args->thread_num = thread; |
f107f563 VP |
11534 | |
11535 | discard_cleanups (old_chain); | |
95e54da7 PA |
11536 | add_continuation (inferior_thread (), |
11537 | until_break_command_continuation, args, | |
604ead4a | 11538 | xfree); |
f107f563 VP |
11539 | } |
11540 | else | |
c5aa993b | 11541 | do_cleanups (old_chain); |
c906108c | 11542 | } |
ae66c1fc | 11543 | |
c906108c SS |
11544 | /* This function attempts to parse an optional "if <cond>" clause |
11545 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11546 | |
c906108c SS |
11547 | Else, it returns a pointer to the condition string. (It does not |
11548 | attempt to evaluate the string against a particular block.) And, | |
11549 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11550 | if clause in the arg string. */ |
53a5351d | 11551 | |
916703c0 | 11552 | char * |
fba45db2 | 11553 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11554 | { |
c5aa993b JM |
11555 | char *cond_string; |
11556 | ||
11557 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11558 | return NULL; |
c5aa993b | 11559 | |
4a64f543 | 11560 | /* Skip the "if" keyword. */ |
c906108c | 11561 | (*arg) += 2; |
c5aa993b | 11562 | |
c906108c | 11563 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11564 | condition string. */ |
e9cafbcc | 11565 | *arg = skip_spaces (*arg); |
c906108c | 11566 | cond_string = *arg; |
c5aa993b | 11567 | |
4a64f543 MS |
11568 | /* Assume that the condition occupies the remainder of the arg |
11569 | string. */ | |
c906108c | 11570 | (*arg) += strlen (cond_string); |
c5aa993b | 11571 | |
c906108c SS |
11572 | return cond_string; |
11573 | } | |
c5aa993b | 11574 | |
c906108c SS |
11575 | /* Commands to deal with catching events, such as signals, exceptions, |
11576 | process start/exit, etc. */ | |
c5aa993b JM |
11577 | |
11578 | typedef enum | |
11579 | { | |
44feb3ce TT |
11580 | catch_fork_temporary, catch_vfork_temporary, |
11581 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11582 | } |
11583 | catch_fork_kind; | |
11584 | ||
c906108c | 11585 | static void |
cc59ec59 MS |
11586 | catch_fork_command_1 (char *arg, int from_tty, |
11587 | struct cmd_list_element *command) | |
c906108c | 11588 | { |
a6d9a66e | 11589 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11590 | char *cond_string = NULL; |
44feb3ce TT |
11591 | catch_fork_kind fork_kind; |
11592 | int tempflag; | |
11593 | ||
11594 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11595 | tempflag = (fork_kind == catch_fork_temporary | |
11596 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11597 | |
44feb3ce TT |
11598 | if (!arg) |
11599 | arg = ""; | |
e9cafbcc | 11600 | arg = skip_spaces (arg); |
c5aa993b | 11601 | |
c906108c | 11602 | /* The allowed syntax is: |
c5aa993b JM |
11603 | catch [v]fork |
11604 | catch [v]fork if <cond> | |
11605 | ||
4a64f543 | 11606 | First, check if there's an if clause. */ |
c906108c | 11607 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11608 | |
c906108c | 11609 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11610 | error (_("Junk at end of arguments.")); |
c5aa993b | 11611 | |
c906108c | 11612 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11613 | and enable reporting of such events. */ |
c5aa993b JM |
11614 | switch (fork_kind) |
11615 | { | |
44feb3ce TT |
11616 | case catch_fork_temporary: |
11617 | case catch_fork_permanent: | |
a6d9a66e | 11618 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11619 | &catch_fork_breakpoint_ops); |
c906108c | 11620 | break; |
44feb3ce TT |
11621 | case catch_vfork_temporary: |
11622 | case catch_vfork_permanent: | |
a6d9a66e | 11623 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11624 | &catch_vfork_breakpoint_ops); |
c906108c | 11625 | break; |
c5aa993b | 11626 | default: |
8a3fe4f8 | 11627 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11628 | break; |
c5aa993b | 11629 | } |
c906108c SS |
11630 | } |
11631 | ||
11632 | static void | |
cc59ec59 MS |
11633 | catch_exec_command_1 (char *arg, int from_tty, |
11634 | struct cmd_list_element *command) | |
c906108c | 11635 | { |
b4d90040 | 11636 | struct exec_catchpoint *c; |
a6d9a66e | 11637 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11638 | int tempflag; |
c5aa993b | 11639 | char *cond_string = NULL; |
c906108c | 11640 | |
44feb3ce TT |
11641 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11642 | ||
11643 | if (!arg) | |
11644 | arg = ""; | |
e9cafbcc | 11645 | arg = skip_spaces (arg); |
c906108c SS |
11646 | |
11647 | /* The allowed syntax is: | |
c5aa993b JM |
11648 | catch exec |
11649 | catch exec if <cond> | |
c906108c | 11650 | |
4a64f543 | 11651 | First, check if there's an if clause. */ |
c906108c SS |
11652 | cond_string = ep_parse_optional_if_clause (&arg); |
11653 | ||
11654 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11655 | error (_("Junk at end of arguments.")); |
c906108c | 11656 | |
b4d90040 PA |
11657 | c = XNEW (struct exec_catchpoint); |
11658 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11659 | &catch_exec_breakpoint_ops); | |
11660 | c->exec_pathname = NULL; | |
11661 | ||
3ea46bff | 11662 | install_breakpoint (0, &c->base, 1); |
c906108c | 11663 | } |
c5aa993b | 11664 | |
9ac4176b | 11665 | void |
28010a5d PA |
11666 | init_ada_exception_breakpoint (struct breakpoint *b, |
11667 | struct gdbarch *gdbarch, | |
11668 | struct symtab_and_line sal, | |
11669 | char *addr_string, | |
c0a91b2b | 11670 | const struct breakpoint_ops *ops, |
28010a5d | 11671 | int tempflag, |
349774ef | 11672 | int enabled, |
28010a5d | 11673 | int from_tty) |
f7f9143b | 11674 | { |
f7f9143b JB |
11675 | if (from_tty) |
11676 | { | |
5af949e3 UW |
11677 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11678 | if (!loc_gdbarch) | |
11679 | loc_gdbarch = gdbarch; | |
11680 | ||
6c95b8df PA |
11681 | describe_other_breakpoints (loc_gdbarch, |
11682 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11683 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11684 | version for exception catchpoints, because two catchpoints | |
11685 | used for different exception names will use the same address. | |
11686 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11687 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11688 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11689 | the user what type of catchpoint it is. The above is good |
11690 | enough for now, though. */ | |
11691 | } | |
11692 | ||
28010a5d | 11693 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11694 | |
349774ef | 11695 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11696 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f7f9143b JB |
11697 | b->addr_string = addr_string; |
11698 | b->language = language_ada; | |
f7f9143b JB |
11699 | } |
11700 | ||
c906108c | 11701 | static void |
fba45db2 | 11702 | catch_command (char *arg, int from_tty) |
c906108c | 11703 | { |
44feb3ce | 11704 | error (_("Catch requires an event name.")); |
c906108c SS |
11705 | } |
11706 | \f | |
11707 | ||
11708 | static void | |
fba45db2 | 11709 | tcatch_command (char *arg, int from_tty) |
c906108c | 11710 | { |
44feb3ce | 11711 | error (_("Catch requires an event name.")); |
c906108c SS |
11712 | } |
11713 | ||
8a2c437b TT |
11714 | /* A qsort comparison function that sorts breakpoints in order. */ |
11715 | ||
11716 | static int | |
11717 | compare_breakpoints (const void *a, const void *b) | |
11718 | { | |
11719 | const breakpoint_p *ba = a; | |
11720 | uintptr_t ua = (uintptr_t) *ba; | |
11721 | const breakpoint_p *bb = b; | |
11722 | uintptr_t ub = (uintptr_t) *bb; | |
11723 | ||
11724 | if ((*ba)->number < (*bb)->number) | |
11725 | return -1; | |
11726 | else if ((*ba)->number > (*bb)->number) | |
11727 | return 1; | |
11728 | ||
11729 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11730 | the number 0. */ | |
11731 | if (ua < ub) | |
11732 | return -1; | |
94b0e70d | 11733 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11734 | } |
11735 | ||
80f8a6eb | 11736 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11737 | |
11738 | static void | |
fba45db2 | 11739 | clear_command (char *arg, int from_tty) |
c906108c | 11740 | { |
8a2c437b | 11741 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11742 | VEC(breakpoint_p) *found = 0; |
11743 | int ix; | |
c906108c SS |
11744 | int default_match; |
11745 | struct symtabs_and_lines sals; | |
11746 | struct symtab_and_line sal; | |
c906108c | 11747 | int i; |
8a2c437b | 11748 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11749 | |
11750 | if (arg) | |
11751 | { | |
39cf75f7 DE |
11752 | sals = decode_line_with_current_source (arg, |
11753 | (DECODE_LINE_FUNFIRSTLINE | |
11754 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 11755 | make_cleanup (xfree, sals.sals); |
c906108c SS |
11756 | default_match = 0; |
11757 | } | |
11758 | else | |
11759 | { | |
c5aa993b | 11760 | sals.sals = (struct symtab_and_line *) |
c906108c | 11761 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 11762 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11763 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11764 | |
11765 | /* Set sal's line, symtab, pc, and pspace to the values | |
11766 | corresponding to the last call to print_frame_info. If the | |
11767 | codepoint is not valid, this will set all the fields to 0. */ | |
11768 | get_last_displayed_sal (&sal); | |
c906108c | 11769 | if (sal.symtab == 0) |
8a3fe4f8 | 11770 | error (_("No source file specified.")); |
c906108c SS |
11771 | |
11772 | sals.sals[0] = sal; | |
11773 | sals.nelts = 1; | |
11774 | ||
11775 | default_match = 1; | |
11776 | } | |
11777 | ||
4a64f543 MS |
11778 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11779 | seems, because all existing breakpoints typically have both | |
11780 | file/line and pc set. So, if clear is given file/line, we can | |
11781 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11782 | |
11783 | We only support clearing given the address explicitly | |
11784 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11785 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11786 | due to optimization, all in one block. |
4a64f543 MS |
11787 | |
11788 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11789 | PC corresponding to the same file:line, the breakpoint won't |
11790 | be cleared. We probably can still clear the breakpoint, but | |
11791 | since the other PC value is never presented to user, user | |
11792 | can only find it by guessing, and it does not seem important | |
11793 | to support that. */ | |
11794 | ||
4a64f543 MS |
11795 | /* For each line spec given, delete bps which correspond to it. Do |
11796 | it in two passes, solely to preserve the current behavior that | |
11797 | from_tty is forced true if we delete more than one | |
11798 | breakpoint. */ | |
c906108c | 11799 | |
80f8a6eb | 11800 | found = NULL; |
8a2c437b | 11801 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
11802 | for (i = 0; i < sals.nelts; i++) |
11803 | { | |
05cba821 JK |
11804 | const char *sal_fullname; |
11805 | ||
c906108c | 11806 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11807 | If line given (pc == 0), clear all bpts on specified line. |
11808 | If defaulting, clear all bpts on default line | |
c906108c | 11809 | or at default pc. |
c5aa993b JM |
11810 | |
11811 | defaulting sal.pc != 0 tests to do | |
11812 | ||
11813 | 0 1 pc | |
11814 | 1 1 pc _and_ line | |
11815 | 0 0 line | |
11816 | 1 0 <can't happen> */ | |
c906108c SS |
11817 | |
11818 | sal = sals.sals[i]; | |
05cba821 JK |
11819 | sal_fullname = (sal.symtab == NULL |
11820 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11821 | |
4a64f543 | 11822 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11823 | ALL_BREAKPOINTS (b) |
c5aa993b | 11824 | { |
0d381245 | 11825 | int match = 0; |
4a64f543 | 11826 | /* Are we going to delete b? */ |
cc60f2e3 | 11827 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11828 | { |
11829 | struct bp_location *loc = b->loc; | |
11830 | for (; loc; loc = loc->next) | |
11831 | { | |
f8eba3c6 TT |
11832 | /* If the user specified file:line, don't allow a PC |
11833 | match. This matches historical gdb behavior. */ | |
11834 | int pc_match = (!sal.explicit_line | |
11835 | && sal.pc | |
11836 | && (loc->pspace == sal.pspace) | |
11837 | && (loc->address == sal.pc) | |
11838 | && (!section_is_overlay (loc->section) | |
11839 | || loc->section == sal.section)); | |
4aac40c8 TT |
11840 | int line_match = 0; |
11841 | ||
11842 | if ((default_match || sal.explicit_line) | |
2f202fde | 11843 | && loc->symtab != NULL |
05cba821 | 11844 | && sal_fullname != NULL |
4aac40c8 | 11845 | && sal.pspace == loc->pspace |
05cba821 JK |
11846 | && loc->line_number == sal.line |
11847 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11848 | sal_fullname) == 0) | |
11849 | line_match = 1; | |
4aac40c8 | 11850 | |
0d381245 VP |
11851 | if (pc_match || line_match) |
11852 | { | |
11853 | match = 1; | |
11854 | break; | |
11855 | } | |
11856 | } | |
11857 | } | |
11858 | ||
11859 | if (match) | |
d6e956e5 | 11860 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 11861 | } |
80f8a6eb | 11862 | } |
8a2c437b | 11863 | |
80f8a6eb | 11864 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 11865 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
11866 | { |
11867 | if (arg) | |
8a3fe4f8 | 11868 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11869 | else |
8a3fe4f8 | 11870 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11871 | } |
c906108c | 11872 | |
8a2c437b TT |
11873 | /* Remove duplicates from the vec. */ |
11874 | qsort (VEC_address (breakpoint_p, found), | |
11875 | VEC_length (breakpoint_p, found), | |
11876 | sizeof (breakpoint_p), | |
11877 | compare_breakpoints); | |
11878 | prev = VEC_index (breakpoint_p, found, 0); | |
11879 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
11880 | { | |
11881 | if (b == prev) | |
11882 | { | |
11883 | VEC_ordered_remove (breakpoint_p, found, ix); | |
11884 | --ix; | |
11885 | } | |
11886 | } | |
11887 | ||
d6e956e5 | 11888 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 11889 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11890 | if (from_tty) |
a3f17187 | 11891 | { |
d6e956e5 | 11892 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
11893 | printf_unfiltered (_("Deleted breakpoint ")); |
11894 | else | |
11895 | printf_unfiltered (_("Deleted breakpoints ")); | |
11896 | } | |
d6e956e5 VP |
11897 | |
11898 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 11899 | { |
c5aa993b | 11900 | if (from_tty) |
d6e956e5 VP |
11901 | printf_unfiltered ("%d ", b->number); |
11902 | delete_breakpoint (b); | |
c906108c | 11903 | } |
80f8a6eb MS |
11904 | if (from_tty) |
11905 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
11906 | |
11907 | do_cleanups (cleanups); | |
c906108c SS |
11908 | } |
11909 | \f | |
11910 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11911 | all breakpoints that are marked for deletion, whether hit or not. | |
11912 | This is called after any breakpoint is hit, or after errors. */ | |
11913 | ||
11914 | void | |
fba45db2 | 11915 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11916 | { |
35df4500 | 11917 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11918 | |
11919 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11920 | if (bs->breakpoint_at |
11921 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11922 | && bs->stop) |
f431efe5 | 11923 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11924 | |
35df4500 | 11925 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11926 | { |
b5de0fa7 | 11927 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11928 | delete_breakpoint (b); |
11929 | } | |
c906108c SS |
11930 | } |
11931 | ||
4a64f543 MS |
11932 | /* A comparison function for bp_location AP and BP being interfaced to |
11933 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
11934 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 11935 | secondarily by ordering first permanent elements and |
4a64f543 | 11936 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 11937 | qsort being an unstable algorithm. */ |
876fa593 JK |
11938 | |
11939 | static int | |
494cfb0f | 11940 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 11941 | { |
494cfb0f JK |
11942 | struct bp_location *a = *(void **) ap; |
11943 | struct bp_location *b = *(void **) bp; | |
876fa593 JK |
11944 | |
11945 | if (a->address != b->address) | |
11946 | return (a->address > b->address) - (a->address < b->address); | |
11947 | ||
dea2aa5f LM |
11948 | /* Sort locations at the same address by their pspace number, keeping |
11949 | locations of the same inferior (in a multi-inferior environment) | |
11950 | grouped. */ | |
11951 | ||
11952 | if (a->pspace->num != b->pspace->num) | |
11953 | return ((a->pspace->num > b->pspace->num) | |
11954 | - (a->pspace->num < b->pspace->num)); | |
11955 | ||
876fa593 | 11956 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
11957 | if (a->permanent != b->permanent) |
11958 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 11959 | |
c56a97f9 JK |
11960 | /* Make the internal GDB representation stable across GDB runs |
11961 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11962 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11963 | |
11964 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
11965 | return ((a->owner->number > b->owner->number) |
11966 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
11967 | |
11968 | return (a > b) - (a < b); | |
11969 | } | |
11970 | ||
876fa593 | 11971 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
11972 | bp_location_shadow_len_after_address_max according to the current |
11973 | content of the bp_location array. */ | |
f7545552 TT |
11974 | |
11975 | static void | |
876fa593 | 11976 | bp_location_target_extensions_update (void) |
f7545552 | 11977 | { |
876fa593 JK |
11978 | struct bp_location *bl, **blp_tmp; |
11979 | ||
11980 | bp_location_placed_address_before_address_max = 0; | |
11981 | bp_location_shadow_len_after_address_max = 0; | |
11982 | ||
11983 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11984 | { | |
11985 | CORE_ADDR start, end, addr; | |
11986 | ||
11987 | if (!bp_location_has_shadow (bl)) | |
11988 | continue; | |
11989 | ||
11990 | start = bl->target_info.placed_address; | |
11991 | end = start + bl->target_info.shadow_len; | |
11992 | ||
11993 | gdb_assert (bl->address >= start); | |
11994 | addr = bl->address - start; | |
11995 | if (addr > bp_location_placed_address_before_address_max) | |
11996 | bp_location_placed_address_before_address_max = addr; | |
11997 | ||
11998 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11999 | ||
12000 | gdb_assert (bl->address < end); | |
12001 | addr = end - bl->address; | |
12002 | if (addr > bp_location_shadow_len_after_address_max) | |
12003 | bp_location_shadow_len_after_address_max = addr; | |
12004 | } | |
f7545552 TT |
12005 | } |
12006 | ||
1e4d1764 YQ |
12007 | /* Download tracepoint locations if they haven't been. */ |
12008 | ||
12009 | static void | |
12010 | download_tracepoint_locations (void) | |
12011 | { | |
7ed2c994 | 12012 | struct breakpoint *b; |
1e4d1764 YQ |
12013 | struct cleanup *old_chain; |
12014 | ||
12015 | if (!target_can_download_tracepoint ()) | |
12016 | return; | |
12017 | ||
12018 | old_chain = save_current_space_and_thread (); | |
12019 | ||
7ed2c994 | 12020 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12021 | { |
7ed2c994 | 12022 | struct bp_location *bl; |
1e4d1764 | 12023 | struct tracepoint *t; |
f2a8bc8a | 12024 | int bp_location_downloaded = 0; |
1e4d1764 | 12025 | |
7ed2c994 | 12026 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12027 | ? !may_insert_fast_tracepoints |
12028 | : !may_insert_tracepoints)) | |
12029 | continue; | |
12030 | ||
7ed2c994 YQ |
12031 | for (bl = b->loc; bl; bl = bl->next) |
12032 | { | |
12033 | /* In tracepoint, locations are _never_ duplicated, so | |
12034 | should_be_inserted is equivalent to | |
12035 | unduplicated_should_be_inserted. */ | |
12036 | if (!should_be_inserted (bl) || bl->inserted) | |
12037 | continue; | |
1e4d1764 | 12038 | |
7ed2c994 | 12039 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12040 | |
7ed2c994 | 12041 | target_download_tracepoint (bl); |
1e4d1764 | 12042 | |
7ed2c994 | 12043 | bl->inserted = 1; |
f2a8bc8a | 12044 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12045 | } |
12046 | t = (struct tracepoint *) b; | |
12047 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12048 | if (bp_location_downloaded) |
12049 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12050 | } |
12051 | ||
12052 | do_cleanups (old_chain); | |
12053 | } | |
12054 | ||
934709f0 PW |
12055 | /* Swap the insertion/duplication state between two locations. */ |
12056 | ||
12057 | static void | |
12058 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12059 | { | |
12060 | const int left_inserted = left->inserted; | |
12061 | const int left_duplicate = left->duplicate; | |
b775012e | 12062 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12063 | const struct bp_target_info left_target_info = left->target_info; |
12064 | ||
1e4d1764 YQ |
12065 | /* Locations of tracepoints can never be duplicated. */ |
12066 | if (is_tracepoint (left->owner)) | |
12067 | gdb_assert (!left->duplicate); | |
12068 | if (is_tracepoint (right->owner)) | |
12069 | gdb_assert (!right->duplicate); | |
12070 | ||
934709f0 PW |
12071 | left->inserted = right->inserted; |
12072 | left->duplicate = right->duplicate; | |
b775012e | 12073 | left->needs_update = right->needs_update; |
934709f0 PW |
12074 | left->target_info = right->target_info; |
12075 | right->inserted = left_inserted; | |
12076 | right->duplicate = left_duplicate; | |
b775012e | 12077 | right->needs_update = left_needs_update; |
934709f0 PW |
12078 | right->target_info = left_target_info; |
12079 | } | |
12080 | ||
b775012e LM |
12081 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12082 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12083 | conditions on the target's side. Such conditions need to be updated on | |
12084 | the target. */ | |
12085 | ||
12086 | static void | |
12087 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12088 | { | |
12089 | struct bp_location **locp = NULL, **loc2p; | |
12090 | struct bp_location *loc; | |
12091 | CORE_ADDR address = 0; | |
12092 | int pspace_num; | |
12093 | ||
12094 | address = bl->address; | |
12095 | pspace_num = bl->pspace->num; | |
12096 | ||
12097 | /* This is only meaningful if the target is | |
12098 | evaluating conditions and if the user has | |
12099 | opted for condition evaluation on the target's | |
12100 | side. */ | |
12101 | if (gdb_evaluates_breakpoint_condition_p () | |
12102 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12103 | return; | |
12104 | ||
12105 | /* Flag all breakpoint locations with this address and | |
12106 | the same program space as the location | |
12107 | as "its condition has changed". We need to | |
12108 | update the conditions on the target's side. */ | |
12109 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12110 | { | |
12111 | loc = *loc2p; | |
12112 | ||
12113 | if (!is_breakpoint (loc->owner) | |
12114 | || pspace_num != loc->pspace->num) | |
12115 | continue; | |
12116 | ||
12117 | /* Flag the location appropriately. We use a different state to | |
12118 | let everyone know that we already updated the set of locations | |
12119 | with addr bl->address and program space bl->pspace. This is so | |
12120 | we don't have to keep calling these functions just to mark locations | |
12121 | that have already been marked. */ | |
12122 | loc->condition_changed = condition_updated; | |
12123 | ||
12124 | /* Free the agent expression bytecode as well. We will compute | |
12125 | it later on. */ | |
12126 | if (loc->cond_bytecode) | |
12127 | { | |
12128 | free_agent_expr (loc->cond_bytecode); | |
12129 | loc->cond_bytecode = NULL; | |
12130 | } | |
12131 | } | |
12132 | } | |
44702360 PA |
12133 | /* Called whether new breakpoints are created, or existing breakpoints |
12134 | deleted, to update the global location list and recompute which | |
12135 | locations are duplicate of which. | |
b775012e | 12136 | |
04086b45 PA |
12137 | The INSERT_MODE flag determines whether locations may not, may, or |
12138 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12139 | info. */ | |
b60e7edf | 12140 | |
0d381245 | 12141 | static void |
44702360 | 12142 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12143 | { |
74960c60 | 12144 | struct breakpoint *b; |
876fa593 | 12145 | struct bp_location **locp, *loc; |
f7545552 | 12146 | struct cleanup *cleanups; |
b775012e LM |
12147 | /* Last breakpoint location address that was marked for update. */ |
12148 | CORE_ADDR last_addr = 0; | |
12149 | /* Last breakpoint location program space that was marked for update. */ | |
12150 | int last_pspace_num = -1; | |
f7545552 | 12151 | |
2d134ed3 PA |
12152 | /* Used in the duplicates detection below. When iterating over all |
12153 | bp_locations, points to the first bp_location of a given address. | |
12154 | Breakpoints and watchpoints of different types are never | |
12155 | duplicates of each other. Keep one pointer for each type of | |
12156 | breakpoint/watchpoint, so we only need to loop over all locations | |
12157 | once. */ | |
12158 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12159 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12160 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12161 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12162 | |
4a64f543 MS |
12163 | /* Saved former bp_location array which we compare against the newly |
12164 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12165 | struct bp_location **old_location, **old_locp; |
12166 | unsigned old_location_count; | |
12167 | ||
12168 | old_location = bp_location; | |
12169 | old_location_count = bp_location_count; | |
12170 | bp_location = NULL; | |
12171 | bp_location_count = 0; | |
12172 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12173 | |
74960c60 | 12174 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12175 | for (loc = b->loc; loc; loc = loc->next) |
12176 | bp_location_count++; | |
12177 | ||
12178 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
12179 | locp = bp_location; | |
12180 | ALL_BREAKPOINTS (b) | |
12181 | for (loc = b->loc; loc; loc = loc->next) | |
12182 | *locp++ = loc; | |
12183 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12184 | bp_location_compare); |
876fa593 JK |
12185 | |
12186 | bp_location_target_extensions_update (); | |
74960c60 | 12187 | |
4a64f543 MS |
12188 | /* Identify bp_location instances that are no longer present in the |
12189 | new list, and therefore should be freed. Note that it's not | |
12190 | necessary that those locations should be removed from inferior -- | |
12191 | if there's another location at the same address (previously | |
12192 | marked as duplicate), we don't need to remove/insert the | |
12193 | location. | |
876fa593 | 12194 | |
4a64f543 MS |
12195 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12196 | and former bp_location array state respectively. */ | |
876fa593 JK |
12197 | |
12198 | locp = bp_location; | |
12199 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12200 | old_locp++) | |
74960c60 | 12201 | { |
876fa593 | 12202 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12203 | struct bp_location **loc2p; |
876fa593 | 12204 | |
e5dd4106 | 12205 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12206 | not, we have to free it. */ |
c7d46a38 | 12207 | int found_object = 0; |
20874c92 VP |
12208 | /* Tells if the location should remain inserted in the target. */ |
12209 | int keep_in_target = 0; | |
12210 | int removed = 0; | |
876fa593 | 12211 | |
4a64f543 MS |
12212 | /* Skip LOCP entries which will definitely never be needed. |
12213 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12214 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12215 | && (*locp)->address < old_loc->address) |
876fa593 | 12216 | locp++; |
c7d46a38 PA |
12217 | |
12218 | for (loc2p = locp; | |
12219 | (loc2p < bp_location + bp_location_count | |
12220 | && (*loc2p)->address == old_loc->address); | |
12221 | loc2p++) | |
12222 | { | |
b775012e LM |
12223 | /* Check if this is a new/duplicated location or a duplicated |
12224 | location that had its condition modified. If so, we want to send | |
12225 | its condition to the target if evaluation of conditions is taking | |
12226 | place there. */ | |
12227 | if ((*loc2p)->condition_changed == condition_modified | |
12228 | && (last_addr != old_loc->address | |
12229 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12230 | { |
b775012e LM |
12231 | force_breakpoint_reinsertion (*loc2p); |
12232 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12233 | } |
b775012e LM |
12234 | |
12235 | if (*loc2p == old_loc) | |
12236 | found_object = 1; | |
c7d46a38 | 12237 | } |
74960c60 | 12238 | |
b775012e LM |
12239 | /* We have already handled this address, update it so that we don't |
12240 | have to go through updates again. */ | |
12241 | last_addr = old_loc->address; | |
12242 | ||
12243 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12244 | if (!found_object) | |
12245 | force_breakpoint_reinsertion (old_loc); | |
12246 | ||
4a64f543 MS |
12247 | /* If this location is no longer present, and inserted, look if |
12248 | there's maybe a new location at the same address. If so, | |
12249 | mark that one inserted, and don't remove this one. This is | |
12250 | needed so that we don't have a time window where a breakpoint | |
12251 | at certain location is not inserted. */ | |
74960c60 | 12252 | |
876fa593 | 12253 | if (old_loc->inserted) |
0d381245 | 12254 | { |
4a64f543 MS |
12255 | /* If the location is inserted now, we might have to remove |
12256 | it. */ | |
74960c60 | 12257 | |
876fa593 | 12258 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12259 | { |
4a64f543 MS |
12260 | /* The location is still present in the location list, |
12261 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12262 | keep_in_target = 1; |
74960c60 VP |
12263 | } |
12264 | else | |
12265 | { | |
b775012e LM |
12266 | /* This location still exists, but it won't be kept in the |
12267 | target since it may have been disabled. We proceed to | |
12268 | remove its target-side condition. */ | |
12269 | ||
4a64f543 MS |
12270 | /* The location is either no longer present, or got |
12271 | disabled. See if there's another location at the | |
12272 | same address, in which case we don't need to remove | |
12273 | this one from the target. */ | |
876fa593 | 12274 | |
2bdf28a0 | 12275 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12276 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12277 | { | |
876fa593 | 12278 | for (loc2p = locp; |
c7d46a38 PA |
12279 | (loc2p < bp_location + bp_location_count |
12280 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12281 | loc2p++) |
12282 | { | |
12283 | struct bp_location *loc2 = *loc2p; | |
12284 | ||
2d134ed3 | 12285 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12286 | { |
85d721b8 PA |
12287 | /* Read watchpoint locations are switched to |
12288 | access watchpoints, if the former are not | |
12289 | supported, but the latter are. */ | |
12290 | if (is_hardware_watchpoint (old_loc->owner)) | |
12291 | { | |
12292 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12293 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12294 | } | |
12295 | ||
934709f0 PW |
12296 | /* loc2 is a duplicated location. We need to check |
12297 | if it should be inserted in case it will be | |
12298 | unduplicated. */ | |
12299 | if (loc2 != old_loc | |
12300 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12301 | { |
934709f0 | 12302 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12303 | keep_in_target = 1; |
12304 | break; | |
12305 | } | |
876fa593 JK |
12306 | } |
12307 | } | |
12308 | } | |
74960c60 VP |
12309 | } |
12310 | ||
20874c92 VP |
12311 | if (!keep_in_target) |
12312 | { | |
876fa593 | 12313 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12314 | { |
4a64f543 MS |
12315 | /* This is just about all we can do. We could keep |
12316 | this location on the global list, and try to | |
12317 | remove it next time, but there's no particular | |
12318 | reason why we will succeed next time. | |
20874c92 | 12319 | |
4a64f543 MS |
12320 | Note that at this point, old_loc->owner is still |
12321 | valid, as delete_breakpoint frees the breakpoint | |
12322 | only after calling us. */ | |
3e43a32a MS |
12323 | printf_filtered (_("warning: Error removing " |
12324 | "breakpoint %d\n"), | |
876fa593 | 12325 | old_loc->owner->number); |
20874c92 VP |
12326 | } |
12327 | removed = 1; | |
12328 | } | |
0d381245 | 12329 | } |
74960c60 VP |
12330 | |
12331 | if (!found_object) | |
1c5cfe86 | 12332 | { |
fbea99ea | 12333 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12334 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12335 | { |
db82e815 PA |
12336 | /* This location was removed from the target. In |
12337 | non-stop mode, a race condition is possible where | |
12338 | we've removed a breakpoint, but stop events for that | |
12339 | breakpoint are already queued and will arrive later. | |
12340 | We apply an heuristic to be able to distinguish such | |
12341 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12342 | breakpoint location for a bit, and will retire it | |
12343 | after we see some number of events. The theory here | |
12344 | is that reporting of events should, "on the average", | |
12345 | be fair, so after a while we'll see events from all | |
12346 | threads that have anything of interest, and no longer | |
12347 | need to keep this breakpoint location around. We | |
12348 | don't hold locations forever so to reduce chances of | |
12349 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12350 | SIGTRAP. | |
12351 | ||
12352 | The heuristic failing can be disastrous on | |
12353 | decr_pc_after_break targets. | |
12354 | ||
12355 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12356 | if we fail to recognize a late breakpoint SIGTRAP, | |
12357 | because events_till_retirement has reached 0 too | |
12358 | soon, we'll fail to do the PC adjustment, and report | |
12359 | a random SIGTRAP to the user. When the user resumes | |
12360 | the inferior, it will most likely immediately crash | |
2dec564e | 12361 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12362 | corrupted, because of being resumed e.g., in the |
12363 | middle of a multi-byte instruction, or skipped a | |
12364 | one-byte instruction. This was actually seen happen | |
12365 | on native x86-linux, and should be less rare on | |
12366 | targets that do not support new thread events, like | |
12367 | remote, due to the heuristic depending on | |
12368 | thread_count. | |
12369 | ||
12370 | Mistaking a random SIGTRAP for a breakpoint trap | |
12371 | causes similar symptoms (PC adjustment applied when | |
12372 | it shouldn't), but then again, playing with SIGTRAPs | |
12373 | behind the debugger's back is asking for trouble. | |
12374 | ||
12375 | Since hardware watchpoint traps are always | |
12376 | distinguishable from other traps, so we don't need to | |
12377 | apply keep hardware watchpoint moribund locations | |
12378 | around. We simply always ignore hardware watchpoint | |
12379 | traps we can no longer explain. */ | |
12380 | ||
876fa593 JK |
12381 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12382 | old_loc->owner = NULL; | |
20874c92 | 12383 | |
876fa593 | 12384 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12385 | } |
12386 | else | |
f431efe5 PA |
12387 | { |
12388 | old_loc->owner = NULL; | |
12389 | decref_bp_location (&old_loc); | |
12390 | } | |
20874c92 | 12391 | } |
74960c60 | 12392 | } |
1c5cfe86 | 12393 | |
348d480f PA |
12394 | /* Rescan breakpoints at the same address and section, marking the |
12395 | first one as "first" and any others as "duplicates". This is so | |
12396 | that the bpt instruction is only inserted once. If we have a | |
12397 | permanent breakpoint at the same place as BPT, make that one the | |
12398 | official one, and the rest as duplicates. Permanent breakpoints | |
12399 | are sorted first for the same address. | |
12400 | ||
12401 | Do the same for hardware watchpoints, but also considering the | |
12402 | watchpoint's type (regular/access/read) and length. */ | |
12403 | ||
12404 | bp_loc_first = NULL; | |
12405 | wp_loc_first = NULL; | |
12406 | awp_loc_first = NULL; | |
12407 | rwp_loc_first = NULL; | |
12408 | ALL_BP_LOCATIONS (loc, locp) | |
12409 | { | |
12410 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12411 | non-NULL. */ | |
348d480f | 12412 | struct bp_location **loc_first_p; |
d3fbdd86 | 12413 | b = loc->owner; |
348d480f | 12414 | |
6f380991 | 12415 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12416 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12417 | /* Don't detect duplicate for tracepoint locations because they are |
12418 | never duplicated. See the comments in field `duplicate' of | |
12419 | `struct bp_location'. */ | |
348d480f | 12420 | || is_tracepoint (b)) |
b775012e LM |
12421 | { |
12422 | /* Clear the condition modification flag. */ | |
12423 | loc->condition_changed = condition_unchanged; | |
12424 | continue; | |
12425 | } | |
348d480f | 12426 | |
348d480f PA |
12427 | if (b->type == bp_hardware_watchpoint) |
12428 | loc_first_p = &wp_loc_first; | |
12429 | else if (b->type == bp_read_watchpoint) | |
12430 | loc_first_p = &rwp_loc_first; | |
12431 | else if (b->type == bp_access_watchpoint) | |
12432 | loc_first_p = &awp_loc_first; | |
12433 | else | |
12434 | loc_first_p = &bp_loc_first; | |
12435 | ||
12436 | if (*loc_first_p == NULL | |
12437 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12438 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12439 | { | |
12440 | *loc_first_p = loc; | |
12441 | loc->duplicate = 0; | |
b775012e LM |
12442 | |
12443 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12444 | { | |
12445 | loc->needs_update = 1; | |
12446 | /* Clear the condition modification flag. */ | |
12447 | loc->condition_changed = condition_unchanged; | |
12448 | } | |
348d480f PA |
12449 | continue; |
12450 | } | |
12451 | ||
934709f0 PW |
12452 | |
12453 | /* This and the above ensure the invariant that the first location | |
12454 | is not duplicated, and is the inserted one. | |
12455 | All following are marked as duplicated, and are not inserted. */ | |
12456 | if (loc->inserted) | |
12457 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12458 | loc->duplicate = 1; |
12459 | ||
b775012e LM |
12460 | /* Clear the condition modification flag. */ |
12461 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12462 | } |
12463 | ||
a25a5a45 | 12464 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12465 | { |
04086b45 | 12466 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12467 | insert_breakpoint_locations (); |
12468 | else | |
12469 | { | |
44702360 PA |
12470 | /* Even though the caller told us to not insert new |
12471 | locations, we may still need to update conditions on the | |
12472 | target's side of breakpoints that were already inserted | |
12473 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12474 | only update conditions for locations that are marked |
12475 | "needs_update". */ | |
12476 | update_inserted_breakpoint_locations (); | |
12477 | } | |
12478 | } | |
348d480f | 12479 | |
04086b45 | 12480 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12481 | download_tracepoint_locations (); |
12482 | ||
348d480f PA |
12483 | do_cleanups (cleanups); |
12484 | } | |
12485 | ||
12486 | void | |
12487 | breakpoint_retire_moribund (void) | |
12488 | { | |
12489 | struct bp_location *loc; | |
12490 | int ix; | |
12491 | ||
12492 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12493 | if (--(loc->events_till_retirement) == 0) | |
12494 | { | |
12495 | decref_bp_location (&loc); | |
12496 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12497 | --ix; | |
12498 | } | |
12499 | } | |
12500 | ||
12501 | static void | |
44702360 | 12502 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12503 | { |
348d480f | 12504 | |
492d29ea PA |
12505 | TRY |
12506 | { | |
12507 | update_global_location_list (insert_mode); | |
12508 | } | |
12509 | CATCH (e, RETURN_MASK_ERROR) | |
12510 | { | |
12511 | } | |
12512 | END_CATCH | |
348d480f PA |
12513 | } |
12514 | ||
12515 | /* Clear BKP from a BPS. */ | |
12516 | ||
12517 | static void | |
12518 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12519 | { | |
12520 | bpstat bs; | |
12521 | ||
12522 | for (bs = bps; bs; bs = bs->next) | |
12523 | if (bs->breakpoint_at == bpt) | |
12524 | { | |
12525 | bs->breakpoint_at = NULL; | |
12526 | bs->old_val = NULL; | |
12527 | /* bs->commands will be freed later. */ | |
12528 | } | |
12529 | } | |
12530 | ||
12531 | /* Callback for iterate_over_threads. */ | |
12532 | static int | |
12533 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12534 | { | |
12535 | struct breakpoint *bpt = data; | |
12536 | ||
12537 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12538 | return 0; | |
12539 | } | |
12540 | ||
12541 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12542 | callbacks. */ | |
12543 | ||
12544 | static void | |
12545 | say_where (struct breakpoint *b) | |
12546 | { | |
12547 | struct value_print_options opts; | |
12548 | ||
12549 | get_user_print_options (&opts); | |
12550 | ||
12551 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12552 | single string. */ | |
12553 | if (b->loc == NULL) | |
12554 | { | |
12555 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
12556 | } | |
12557 | else | |
12558 | { | |
2f202fde | 12559 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12560 | { |
12561 | printf_filtered (" at "); | |
12562 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12563 | gdb_stdout); | |
12564 | } | |
2f202fde | 12565 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12566 | { |
12567 | /* If there is a single location, we can print the location | |
12568 | more nicely. */ | |
12569 | if (b->loc->next == NULL) | |
12570 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12571 | symtab_to_filename_for_display (b->loc->symtab), |
12572 | b->loc->line_number); | |
f8eba3c6 TT |
12573 | else |
12574 | /* This is not ideal, but each location may have a | |
12575 | different file name, and this at least reflects the | |
12576 | real situation somewhat. */ | |
12577 | printf_filtered (": %s.", b->addr_string); | |
12578 | } | |
348d480f PA |
12579 | |
12580 | if (b->loc->next) | |
12581 | { | |
12582 | struct bp_location *loc = b->loc; | |
12583 | int n = 0; | |
12584 | for (; loc; loc = loc->next) | |
12585 | ++n; | |
12586 | printf_filtered (" (%d locations)", n); | |
12587 | } | |
12588 | } | |
12589 | } | |
12590 | ||
348d480f PA |
12591 | /* Default bp_location_ops methods. */ |
12592 | ||
12593 | static void | |
12594 | bp_location_dtor (struct bp_location *self) | |
12595 | { | |
12596 | xfree (self->cond); | |
b775012e LM |
12597 | if (self->cond_bytecode) |
12598 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12599 | xfree (self->function_name); |
8b4f3082 PA |
12600 | |
12601 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12602 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12603 | } |
12604 | ||
12605 | static const struct bp_location_ops bp_location_ops = | |
12606 | { | |
12607 | bp_location_dtor | |
12608 | }; | |
12609 | ||
2060206e PA |
12610 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12611 | inherit from. */ | |
348d480f | 12612 | |
2060206e PA |
12613 | static void |
12614 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12615 | { |
12616 | decref_counted_command_line (&self->commands); | |
12617 | xfree (self->cond_string); | |
fb81d016 | 12618 | xfree (self->extra_string); |
348d480f | 12619 | xfree (self->addr_string); |
f8eba3c6 | 12620 | xfree (self->filter); |
348d480f | 12621 | xfree (self->addr_string_range_end); |
348d480f PA |
12622 | } |
12623 | ||
2060206e PA |
12624 | static struct bp_location * |
12625 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12626 | { |
12627 | struct bp_location *loc; | |
12628 | ||
12629 | loc = XNEW (struct bp_location); | |
12630 | init_bp_location (loc, &bp_location_ops, self); | |
12631 | return loc; | |
12632 | } | |
12633 | ||
2060206e PA |
12634 | static void |
12635 | base_breakpoint_re_set (struct breakpoint *b) | |
12636 | { | |
12637 | /* Nothing to re-set. */ | |
12638 | } | |
12639 | ||
12640 | #define internal_error_pure_virtual_called() \ | |
12641 | gdb_assert_not_reached ("pure virtual function called") | |
12642 | ||
12643 | static int | |
12644 | base_breakpoint_insert_location (struct bp_location *bl) | |
12645 | { | |
12646 | internal_error_pure_virtual_called (); | |
12647 | } | |
12648 | ||
12649 | static int | |
12650 | base_breakpoint_remove_location (struct bp_location *bl) | |
12651 | { | |
12652 | internal_error_pure_virtual_called (); | |
12653 | } | |
12654 | ||
12655 | static int | |
12656 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12657 | struct address_space *aspace, | |
09ac7c10 TT |
12658 | CORE_ADDR bp_addr, |
12659 | const struct target_waitstatus *ws) | |
2060206e PA |
12660 | { |
12661 | internal_error_pure_virtual_called (); | |
12662 | } | |
12663 | ||
12664 | static void | |
12665 | base_breakpoint_check_status (bpstat bs) | |
12666 | { | |
12667 | /* Always stop. */ | |
12668 | } | |
12669 | ||
12670 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12671 | errors. */ | |
12672 | ||
12673 | static int | |
12674 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12675 | { | |
12676 | internal_error_pure_virtual_called (); | |
12677 | } | |
12678 | ||
12679 | /* A "resources_needed" breakpoint_ops method that just internal | |
12680 | errors. */ | |
12681 | ||
12682 | static int | |
12683 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12684 | { | |
12685 | internal_error_pure_virtual_called (); | |
12686 | } | |
12687 | ||
12688 | static enum print_stop_action | |
12689 | base_breakpoint_print_it (bpstat bs) | |
12690 | { | |
12691 | internal_error_pure_virtual_called (); | |
12692 | } | |
12693 | ||
12694 | static void | |
12695 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12696 | struct ui_out *uiout) | |
12697 | { | |
12698 | /* nothing */ | |
12699 | } | |
12700 | ||
12701 | static void | |
12702 | base_breakpoint_print_mention (struct breakpoint *b) | |
12703 | { | |
12704 | internal_error_pure_virtual_called (); | |
12705 | } | |
12706 | ||
12707 | static void | |
12708 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12709 | { | |
12710 | internal_error_pure_virtual_called (); | |
12711 | } | |
12712 | ||
983af33b | 12713 | static void |
5f700d83 KS |
12714 | base_breakpoint_create_sals_from_location (char **arg, |
12715 | struct linespec_result *canonical, | |
12716 | enum bptype type_wanted, | |
12717 | char *addr_start, | |
12718 | char **copy_arg) | |
983af33b SDJ |
12719 | { |
12720 | internal_error_pure_virtual_called (); | |
12721 | } | |
12722 | ||
12723 | static void | |
12724 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12725 | struct linespec_result *c, | |
983af33b | 12726 | char *cond_string, |
e7e0cddf | 12727 | char *extra_string, |
983af33b SDJ |
12728 | enum bptype type_wanted, |
12729 | enum bpdisp disposition, | |
12730 | int thread, | |
12731 | int task, int ignore_count, | |
12732 | const struct breakpoint_ops *o, | |
12733 | int from_tty, int enabled, | |
44f238bb | 12734 | int internal, unsigned flags) |
983af33b SDJ |
12735 | { |
12736 | internal_error_pure_virtual_called (); | |
12737 | } | |
12738 | ||
12739 | static void | |
5f700d83 | 12740 | base_breakpoint_decode_location (struct breakpoint *b, char **s, |
983af33b SDJ |
12741 | struct symtabs_and_lines *sals) |
12742 | { | |
12743 | internal_error_pure_virtual_called (); | |
12744 | } | |
12745 | ||
ab04a2af TT |
12746 | /* The default 'explains_signal' method. */ |
12747 | ||
47591c29 | 12748 | static int |
427cd150 | 12749 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12750 | { |
47591c29 | 12751 | return 1; |
ab04a2af TT |
12752 | } |
12753 | ||
9d6e6e84 HZ |
12754 | /* The default "after_condition_true" method. */ |
12755 | ||
12756 | static void | |
12757 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12758 | { | |
12759 | /* Nothing to do. */ | |
12760 | } | |
12761 | ||
ab04a2af | 12762 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
12763 | { |
12764 | base_breakpoint_dtor, | |
12765 | base_breakpoint_allocate_location, | |
12766 | base_breakpoint_re_set, | |
12767 | base_breakpoint_insert_location, | |
12768 | base_breakpoint_remove_location, | |
12769 | base_breakpoint_breakpoint_hit, | |
12770 | base_breakpoint_check_status, | |
12771 | base_breakpoint_resources_needed, | |
12772 | base_breakpoint_works_in_software_mode, | |
12773 | base_breakpoint_print_it, | |
12774 | NULL, | |
12775 | base_breakpoint_print_one_detail, | |
12776 | base_breakpoint_print_mention, | |
983af33b | 12777 | base_breakpoint_print_recreate, |
5f700d83 | 12778 | base_breakpoint_create_sals_from_location, |
983af33b | 12779 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12780 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12781 | base_breakpoint_explains_signal, |
12782 | base_breakpoint_after_condition_true, | |
2060206e PA |
12783 | }; |
12784 | ||
12785 | /* Default breakpoint_ops methods. */ | |
12786 | ||
12787 | static void | |
348d480f PA |
12788 | bkpt_re_set (struct breakpoint *b) |
12789 | { | |
06edf0c0 PA |
12790 | /* FIXME: is this still reachable? */ |
12791 | if (b->addr_string == NULL) | |
12792 | { | |
12793 | /* Anything without a string can't be re-set. */ | |
348d480f | 12794 | delete_breakpoint (b); |
06edf0c0 | 12795 | return; |
348d480f | 12796 | } |
06edf0c0 PA |
12797 | |
12798 | breakpoint_re_set_default (b); | |
348d480f PA |
12799 | } |
12800 | ||
2060206e | 12801 | static int |
348d480f PA |
12802 | bkpt_insert_location (struct bp_location *bl) |
12803 | { | |
12804 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
7c16b83e | 12805 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12806 | else |
7c16b83e | 12807 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12808 | } |
12809 | ||
2060206e | 12810 | static int |
348d480f PA |
12811 | bkpt_remove_location (struct bp_location *bl) |
12812 | { | |
12813 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12814 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12815 | else | |
7c16b83e | 12816 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12817 | } |
12818 | ||
2060206e | 12819 | static int |
348d480f | 12820 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
12821 | struct address_space *aspace, CORE_ADDR bp_addr, |
12822 | const struct target_waitstatus *ws) | |
348d480f | 12823 | { |
09ac7c10 | 12824 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12825 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12826 | return 0; |
12827 | ||
348d480f PA |
12828 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12829 | aspace, bp_addr)) | |
12830 | return 0; | |
12831 | ||
12832 | if (overlay_debugging /* unmapped overlay section */ | |
12833 | && section_is_overlay (bl->section) | |
12834 | && !section_is_mapped (bl->section)) | |
12835 | return 0; | |
12836 | ||
12837 | return 1; | |
12838 | } | |
12839 | ||
cd1608cc PA |
12840 | static int |
12841 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
12842 | struct address_space *aspace, CORE_ADDR bp_addr, | |
12843 | const struct target_waitstatus *ws) | |
12844 | { | |
12845 | if (dprintf_style == dprintf_style_agent | |
12846 | && target_can_run_breakpoint_commands ()) | |
12847 | { | |
12848 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12849 | for this address it must be for a breakpoint that happens to | |
12850 | be set at the same address. */ | |
12851 | return 0; | |
12852 | } | |
12853 | ||
12854 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12855 | } | |
12856 | ||
2060206e | 12857 | static int |
348d480f PA |
12858 | bkpt_resources_needed (const struct bp_location *bl) |
12859 | { | |
12860 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12861 | ||
12862 | return 1; | |
12863 | } | |
12864 | ||
2060206e | 12865 | static enum print_stop_action |
348d480f PA |
12866 | bkpt_print_it (bpstat bs) |
12867 | { | |
348d480f PA |
12868 | struct breakpoint *b; |
12869 | const struct bp_location *bl; | |
001c8c33 | 12870 | int bp_temp; |
79a45e25 | 12871 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12872 | |
12873 | gdb_assert (bs->bp_location_at != NULL); | |
12874 | ||
12875 | bl = bs->bp_location_at; | |
12876 | b = bs->breakpoint_at; | |
12877 | ||
001c8c33 PA |
12878 | bp_temp = b->disposition == disp_del; |
12879 | if (bl->address != bl->requested_address) | |
12880 | breakpoint_adjustment_warning (bl->requested_address, | |
12881 | bl->address, | |
12882 | b->number, 1); | |
12883 | annotate_breakpoint (b->number); | |
12884 | if (bp_temp) | |
12885 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
12886 | else | |
12887 | ui_out_text (uiout, "\nBreakpoint "); | |
12888 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 12889 | { |
001c8c33 PA |
12890 | ui_out_field_string (uiout, "reason", |
12891 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
12892 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 12893 | } |
001c8c33 PA |
12894 | ui_out_field_int (uiout, "bkptno", b->number); |
12895 | ui_out_text (uiout, ", "); | |
06edf0c0 | 12896 | |
001c8c33 | 12897 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12898 | } |
12899 | ||
2060206e | 12900 | static void |
06edf0c0 PA |
12901 | bkpt_print_mention (struct breakpoint *b) |
12902 | { | |
79a45e25 | 12903 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
12904 | return; |
12905 | ||
12906 | switch (b->type) | |
12907 | { | |
12908 | case bp_breakpoint: | |
12909 | case bp_gnu_ifunc_resolver: | |
12910 | if (b->disposition == disp_del) | |
12911 | printf_filtered (_("Temporary breakpoint")); | |
12912 | else | |
12913 | printf_filtered (_("Breakpoint")); | |
12914 | printf_filtered (_(" %d"), b->number); | |
12915 | if (b->type == bp_gnu_ifunc_resolver) | |
12916 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12917 | break; | |
12918 | case bp_hardware_breakpoint: | |
12919 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12920 | break; | |
e7e0cddf SS |
12921 | case bp_dprintf: |
12922 | printf_filtered (_("Dprintf %d"), b->number); | |
12923 | break; | |
06edf0c0 PA |
12924 | } |
12925 | ||
12926 | say_where (b); | |
12927 | } | |
12928 | ||
2060206e | 12929 | static void |
06edf0c0 PA |
12930 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12931 | { | |
12932 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12933 | fprintf_unfiltered (fp, "tbreak"); | |
12934 | else if (tp->type == bp_breakpoint) | |
12935 | fprintf_unfiltered (fp, "break"); | |
12936 | else if (tp->type == bp_hardware_breakpoint | |
12937 | && tp->disposition == disp_del) | |
12938 | fprintf_unfiltered (fp, "thbreak"); | |
12939 | else if (tp->type == bp_hardware_breakpoint) | |
12940 | fprintf_unfiltered (fp, "hbreak"); | |
12941 | else | |
12942 | internal_error (__FILE__, __LINE__, | |
12943 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12944 | ||
2060206e | 12945 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 12946 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12947 | } |
12948 | ||
983af33b | 12949 | static void |
5f700d83 | 12950 | bkpt_create_sals_from_location (char **arg, |
983af33b SDJ |
12951 | struct linespec_result *canonical, |
12952 | enum bptype type_wanted, | |
12953 | char *addr_start, char **copy_arg) | |
12954 | { | |
5f700d83 | 12955 | create_sals_from_location_default (arg, canonical, type_wanted, |
983af33b SDJ |
12956 | addr_start, copy_arg); |
12957 | } | |
12958 | ||
12959 | static void | |
12960 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12961 | struct linespec_result *canonical, | |
983af33b | 12962 | char *cond_string, |
e7e0cddf | 12963 | char *extra_string, |
983af33b SDJ |
12964 | enum bptype type_wanted, |
12965 | enum bpdisp disposition, | |
12966 | int thread, | |
12967 | int task, int ignore_count, | |
12968 | const struct breakpoint_ops *ops, | |
12969 | int from_tty, int enabled, | |
44f238bb | 12970 | int internal, unsigned flags) |
983af33b | 12971 | { |
023fa29b | 12972 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
12973 | cond_string, extra_string, |
12974 | type_wanted, | |
983af33b SDJ |
12975 | disposition, thread, task, |
12976 | ignore_count, ops, from_tty, | |
44f238bb | 12977 | enabled, internal, flags); |
983af33b SDJ |
12978 | } |
12979 | ||
12980 | static void | |
5f700d83 | 12981 | bkpt_decode_location (struct breakpoint *b, char **s, |
983af33b SDJ |
12982 | struct symtabs_and_lines *sals) |
12983 | { | |
5f700d83 | 12984 | decode_location_default (b, s, sals); |
983af33b SDJ |
12985 | } |
12986 | ||
06edf0c0 PA |
12987 | /* Virtual table for internal breakpoints. */ |
12988 | ||
12989 | static void | |
12990 | internal_bkpt_re_set (struct breakpoint *b) | |
12991 | { | |
12992 | switch (b->type) | |
12993 | { | |
12994 | /* Delete overlay event and longjmp master breakpoints; they | |
12995 | will be reset later by breakpoint_re_set. */ | |
12996 | case bp_overlay_event: | |
12997 | case bp_longjmp_master: | |
12998 | case bp_std_terminate_master: | |
12999 | case bp_exception_master: | |
13000 | delete_breakpoint (b); | |
13001 | break; | |
13002 | ||
13003 | /* This breakpoint is special, it's set up when the inferior | |
13004 | starts and we really don't want to touch it. */ | |
13005 | case bp_shlib_event: | |
13006 | ||
13007 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13008 | it is set up, we do not want to touch it. */ | |
13009 | case bp_thread_event: | |
13010 | break; | |
13011 | } | |
13012 | } | |
13013 | ||
13014 | static void | |
13015 | internal_bkpt_check_status (bpstat bs) | |
13016 | { | |
a9b3a50f PA |
13017 | if (bs->breakpoint_at->type == bp_shlib_event) |
13018 | { | |
13019 | /* If requested, stop when the dynamic linker notifies GDB of | |
13020 | events. This allows the user to get control and place | |
13021 | breakpoints in initializer routines for dynamically loaded | |
13022 | objects (among other things). */ | |
13023 | bs->stop = stop_on_solib_events; | |
13024 | bs->print = stop_on_solib_events; | |
13025 | } | |
13026 | else | |
13027 | bs->stop = 0; | |
06edf0c0 PA |
13028 | } |
13029 | ||
13030 | static enum print_stop_action | |
13031 | internal_bkpt_print_it (bpstat bs) | |
13032 | { | |
06edf0c0 | 13033 | struct breakpoint *b; |
06edf0c0 | 13034 | |
06edf0c0 PA |
13035 | b = bs->breakpoint_at; |
13036 | ||
06edf0c0 PA |
13037 | switch (b->type) |
13038 | { | |
348d480f PA |
13039 | case bp_shlib_event: |
13040 | /* Did we stop because the user set the stop_on_solib_events | |
13041 | variable? (If so, we report this as a generic, "Stopped due | |
13042 | to shlib event" message.) */ | |
edcc5120 | 13043 | print_solib_event (0); |
348d480f PA |
13044 | break; |
13045 | ||
13046 | case bp_thread_event: | |
13047 | /* Not sure how we will get here. | |
13048 | GDB should not stop for these breakpoints. */ | |
13049 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13050 | break; |
13051 | ||
13052 | case bp_overlay_event: | |
13053 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13054 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13055 | break; |
13056 | ||
13057 | case bp_longjmp_master: | |
13058 | /* These should never be enabled. */ | |
13059 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13060 | break; |
13061 | ||
13062 | case bp_std_terminate_master: | |
13063 | /* These should never be enabled. */ | |
13064 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13065 | "gdb should not stop!\n")); | |
348d480f PA |
13066 | break; |
13067 | ||
13068 | case bp_exception_master: | |
13069 | /* These should never be enabled. */ | |
13070 | printf_filtered (_("Exception Master Breakpoint: " | |
13071 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13072 | break; |
13073 | } | |
13074 | ||
001c8c33 | 13075 | return PRINT_NOTHING; |
06edf0c0 PA |
13076 | } |
13077 | ||
13078 | static void | |
13079 | internal_bkpt_print_mention (struct breakpoint *b) | |
13080 | { | |
13081 | /* Nothing to mention. These breakpoints are internal. */ | |
13082 | } | |
13083 | ||
06edf0c0 PA |
13084 | /* Virtual table for momentary breakpoints */ |
13085 | ||
13086 | static void | |
13087 | momentary_bkpt_re_set (struct breakpoint *b) | |
13088 | { | |
13089 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13090 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13091 | Otherwise these should have been blown away via the cleanup chain |
13092 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13093 | } | |
13094 | ||
13095 | static void | |
13096 | momentary_bkpt_check_status (bpstat bs) | |
13097 | { | |
13098 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13099 | } | |
13100 | ||
13101 | static enum print_stop_action | |
13102 | momentary_bkpt_print_it (bpstat bs) | |
13103 | { | |
79a45e25 PA |
13104 | struct ui_out *uiout = current_uiout; |
13105 | ||
001c8c33 | 13106 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 13107 | { |
001c8c33 | 13108 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 13109 | |
001c8c33 PA |
13110 | switch (b->type) |
13111 | { | |
13112 | case bp_finish: | |
13113 | ui_out_field_string | |
13114 | (uiout, "reason", | |
13115 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
13116 | break; | |
348d480f | 13117 | |
001c8c33 PA |
13118 | case bp_until: |
13119 | ui_out_field_string | |
13120 | (uiout, "reason", | |
13121 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
13122 | break; | |
13123 | } | |
348d480f PA |
13124 | } |
13125 | ||
001c8c33 | 13126 | return PRINT_UNKNOWN; |
348d480f PA |
13127 | } |
13128 | ||
06edf0c0 PA |
13129 | static void |
13130 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13131 | { |
06edf0c0 | 13132 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13133 | } |
13134 | ||
e2e4d78b JK |
13135 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13136 | ||
13137 | It gets cleared already on the removal of the first one of such placed | |
13138 | breakpoints. This is OK as they get all removed altogether. */ | |
13139 | ||
13140 | static void | |
13141 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13142 | { | |
13143 | struct thread_info *tp = find_thread_id (self->thread); | |
13144 | ||
13145 | if (tp) | |
13146 | tp->initiating_frame = null_frame_id; | |
13147 | ||
13148 | momentary_breakpoint_ops.dtor (self); | |
13149 | } | |
13150 | ||
55aa24fb SDJ |
13151 | /* Specific methods for probe breakpoints. */ |
13152 | ||
13153 | static int | |
13154 | bkpt_probe_insert_location (struct bp_location *bl) | |
13155 | { | |
13156 | int v = bkpt_insert_location (bl); | |
13157 | ||
13158 | if (v == 0) | |
13159 | { | |
13160 | /* The insertion was successful, now let's set the probe's semaphore | |
13161 | if needed. */ | |
0ea5cda8 SDJ |
13162 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13163 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13164 | bl->probe.objfile, | |
13165 | bl->gdbarch); | |
55aa24fb SDJ |
13166 | } |
13167 | ||
13168 | return v; | |
13169 | } | |
13170 | ||
13171 | static int | |
13172 | bkpt_probe_remove_location (struct bp_location *bl) | |
13173 | { | |
13174 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13175 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13176 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13177 | bl->probe.objfile, | |
13178 | bl->gdbarch); | |
55aa24fb SDJ |
13179 | |
13180 | return bkpt_remove_location (bl); | |
13181 | } | |
13182 | ||
13183 | static void | |
5f700d83 KS |
13184 | bkpt_probe_create_sals_from_location (char **arg, |
13185 | struct linespec_result *canonical, | |
13186 | enum bptype type_wanted, | |
13187 | char *addr_start, char **copy_arg) | |
55aa24fb SDJ |
13188 | { |
13189 | struct linespec_sals lsal; | |
13190 | ||
13191 | lsal.sals = parse_probes (arg, canonical); | |
13192 | ||
13193 | *copy_arg = xstrdup (canonical->addr_string); | |
13194 | lsal.canonical = xstrdup (*copy_arg); | |
13195 | ||
13196 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13197 | } | |
13198 | ||
13199 | static void | |
5f700d83 | 13200 | bkpt_probe_decode_location (struct breakpoint *b, char **s, |
55aa24fb SDJ |
13201 | struct symtabs_and_lines *sals) |
13202 | { | |
13203 | *sals = parse_probes (s, NULL); | |
13204 | if (!sals->sals) | |
13205 | error (_("probe not found")); | |
13206 | } | |
13207 | ||
348d480f | 13208 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13209 | |
348d480f PA |
13210 | static void |
13211 | tracepoint_re_set (struct breakpoint *b) | |
13212 | { | |
13213 | breakpoint_re_set_default (b); | |
13214 | } | |
876fa593 | 13215 | |
348d480f PA |
13216 | static int |
13217 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13218 | struct address_space *aspace, CORE_ADDR bp_addr, |
13219 | const struct target_waitstatus *ws) | |
348d480f PA |
13220 | { |
13221 | /* By definition, the inferior does not report stops at | |
13222 | tracepoints. */ | |
13223 | return 0; | |
74960c60 VP |
13224 | } |
13225 | ||
13226 | static void | |
348d480f PA |
13227 | tracepoint_print_one_detail (const struct breakpoint *self, |
13228 | struct ui_out *uiout) | |
74960c60 | 13229 | { |
d9b3f62e PA |
13230 | struct tracepoint *tp = (struct tracepoint *) self; |
13231 | if (tp->static_trace_marker_id) | |
348d480f PA |
13232 | { |
13233 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13234 | |
348d480f PA |
13235 | ui_out_text (uiout, "\tmarker id is "); |
13236 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13237 | tp->static_trace_marker_id); |
348d480f PA |
13238 | ui_out_text (uiout, "\n"); |
13239 | } | |
0d381245 VP |
13240 | } |
13241 | ||
a474d7c2 | 13242 | static void |
348d480f | 13243 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13244 | { |
79a45e25 | 13245 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13246 | return; |
cc59ec59 | 13247 | |
348d480f PA |
13248 | switch (b->type) |
13249 | { | |
13250 | case bp_tracepoint: | |
13251 | printf_filtered (_("Tracepoint")); | |
13252 | printf_filtered (_(" %d"), b->number); | |
13253 | break; | |
13254 | case bp_fast_tracepoint: | |
13255 | printf_filtered (_("Fast tracepoint")); | |
13256 | printf_filtered (_(" %d"), b->number); | |
13257 | break; | |
13258 | case bp_static_tracepoint: | |
13259 | printf_filtered (_("Static tracepoint")); | |
13260 | printf_filtered (_(" %d"), b->number); | |
13261 | break; | |
13262 | default: | |
13263 | internal_error (__FILE__, __LINE__, | |
13264 | _("unhandled tracepoint type %d"), (int) b->type); | |
13265 | } | |
13266 | ||
13267 | say_where (b); | |
a474d7c2 PA |
13268 | } |
13269 | ||
348d480f | 13270 | static void |
d9b3f62e | 13271 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13272 | { |
d9b3f62e PA |
13273 | struct tracepoint *tp = (struct tracepoint *) self; |
13274 | ||
13275 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13276 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13277 | if (self->type == bp_static_tracepoint) |
348d480f | 13278 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13279 | else if (self->type == bp_tracepoint) |
348d480f PA |
13280 | fprintf_unfiltered (fp, "trace"); |
13281 | else | |
13282 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13283 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13284 | |
d9b3f62e PA |
13285 | fprintf_unfiltered (fp, " %s", self->addr_string); |
13286 | print_recreate_thread (self, fp); | |
13287 | ||
13288 | if (tp->pass_count) | |
13289 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13290 | } |
13291 | ||
983af33b | 13292 | static void |
5f700d83 | 13293 | tracepoint_create_sals_from_location (char **arg, |
983af33b SDJ |
13294 | struct linespec_result *canonical, |
13295 | enum bptype type_wanted, | |
13296 | char *addr_start, char **copy_arg) | |
13297 | { | |
5f700d83 | 13298 | create_sals_from_location_default (arg, canonical, type_wanted, |
983af33b SDJ |
13299 | addr_start, copy_arg); |
13300 | } | |
13301 | ||
13302 | static void | |
13303 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13304 | struct linespec_result *canonical, | |
983af33b | 13305 | char *cond_string, |
e7e0cddf | 13306 | char *extra_string, |
983af33b SDJ |
13307 | enum bptype type_wanted, |
13308 | enum bpdisp disposition, | |
13309 | int thread, | |
13310 | int task, int ignore_count, | |
13311 | const struct breakpoint_ops *ops, | |
13312 | int from_tty, int enabled, | |
44f238bb | 13313 | int internal, unsigned flags) |
983af33b | 13314 | { |
023fa29b | 13315 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13316 | cond_string, extra_string, |
13317 | type_wanted, | |
983af33b SDJ |
13318 | disposition, thread, task, |
13319 | ignore_count, ops, from_tty, | |
44f238bb | 13320 | enabled, internal, flags); |
983af33b SDJ |
13321 | } |
13322 | ||
13323 | static void | |
5f700d83 | 13324 | tracepoint_decode_location (struct breakpoint *b, char **s, |
983af33b SDJ |
13325 | struct symtabs_and_lines *sals) |
13326 | { | |
5f700d83 | 13327 | decode_location_default (b, s, sals); |
983af33b SDJ |
13328 | } |
13329 | ||
2060206e | 13330 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13331 | |
55aa24fb SDJ |
13332 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13333 | static probe. */ | |
13334 | ||
13335 | static void | |
5f700d83 KS |
13336 | tracepoint_probe_create_sals_from_location (char **arg, |
13337 | struct linespec_result *canonical, | |
13338 | enum bptype type_wanted, | |
13339 | char *addr_start, char **copy_arg) | |
55aa24fb SDJ |
13340 | { |
13341 | /* We use the same method for breakpoint on probes. */ | |
5f700d83 KS |
13342 | bkpt_probe_create_sals_from_location (arg, canonical, type_wanted, |
13343 | addr_start, copy_arg); | |
55aa24fb SDJ |
13344 | } |
13345 | ||
13346 | static void | |
5f700d83 | 13347 | tracepoint_probe_decode_location (struct breakpoint *b, char **s, |
55aa24fb SDJ |
13348 | struct symtabs_and_lines *sals) |
13349 | { | |
13350 | /* We use the same method for breakpoint on probes. */ | |
5f700d83 | 13351 | bkpt_probe_decode_location (b, s, sals); |
55aa24fb SDJ |
13352 | } |
13353 | ||
13354 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13355 | ||
5c2b4418 HZ |
13356 | /* Dprintf breakpoint_ops methods. */ |
13357 | ||
13358 | static void | |
13359 | dprintf_re_set (struct breakpoint *b) | |
13360 | { | |
13361 | breakpoint_re_set_default (b); | |
13362 | ||
13363 | /* This breakpoint could have been pending, and be resolved now, and | |
13364 | if so, we should now have the extra string. If we don't, the | |
13365 | dprintf was malformed when created, but we couldn't tell because | |
13366 | we can't extract the extra string until the location is | |
13367 | resolved. */ | |
13368 | if (b->loc != NULL && b->extra_string == NULL) | |
13369 | error (_("Format string required")); | |
13370 | ||
13371 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13372 | 2 - create a dprintf, which resolves fine. | |
13373 | 3 - disconnect from target 1 | |
13374 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13375 | ||
13376 | After steps #3/#4, you'll want the dprintf command list to | |
13377 | be updated, because target 1 and 2 may well return different | |
13378 | answers for target_can_run_breakpoint_commands(). | |
13379 | Given absence of finer grained resetting, we get to do | |
13380 | it all the time. */ | |
13381 | if (b->extra_string != NULL) | |
13382 | update_dprintf_command_list (b); | |
13383 | } | |
13384 | ||
2d9442cc HZ |
13385 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13386 | ||
13387 | static void | |
13388 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13389 | { | |
13390 | fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string, | |
13391 | tp->extra_string); | |
13392 | print_recreate_thread (tp, fp); | |
13393 | } | |
13394 | ||
9d6e6e84 HZ |
13395 | /* Implement the "after_condition_true" breakpoint_ops method for |
13396 | dprintf. | |
13397 | ||
13398 | dprintf's are implemented with regular commands in their command | |
13399 | list, but we run the commands here instead of before presenting the | |
13400 | stop to the user, as dprintf's don't actually cause a stop. This | |
13401 | also makes it so that the commands of multiple dprintfs at the same | |
13402 | address are all handled. */ | |
13403 | ||
13404 | static void | |
13405 | dprintf_after_condition_true (struct bpstats *bs) | |
13406 | { | |
13407 | struct cleanup *old_chain; | |
13408 | struct bpstats tmp_bs = { NULL }; | |
13409 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13410 | ||
13411 | /* dprintf's never cause a stop. This wasn't set in the | |
13412 | check_status hook instead because that would make the dprintf's | |
13413 | condition not be evaluated. */ | |
13414 | bs->stop = 0; | |
13415 | ||
13416 | /* Run the command list here. Take ownership of it instead of | |
13417 | copying. We never want these commands to run later in | |
13418 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13419 | be set at same address as this dprintf, or even if running the | |
13420 | commands here throws. */ | |
13421 | tmp_bs.commands = bs->commands; | |
13422 | bs->commands = NULL; | |
13423 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13424 | ||
13425 | bpstat_do_actions_1 (&tmp_bs_p); | |
13426 | ||
13427 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13428 | bpstat_do_actions_1 may return early without processing the whole | |
13429 | list. */ | |
13430 | do_cleanups (old_chain); | |
13431 | } | |
13432 | ||
983af33b SDJ |
13433 | /* The breakpoint_ops structure to be used on static tracepoints with |
13434 | markers (`-m'). */ | |
13435 | ||
13436 | static void | |
5f700d83 KS |
13437 | strace_marker_create_sals_from_location (char **arg, |
13438 | struct linespec_result *canonical, | |
13439 | enum bptype type_wanted, | |
13440 | char *addr_start, char **copy_arg) | |
983af33b SDJ |
13441 | { |
13442 | struct linespec_sals lsal; | |
13443 | ||
13444 | lsal.sals = decode_static_tracepoint_spec (arg); | |
13445 | ||
13446 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
13447 | ||
13448 | canonical->addr_string = xstrdup (*copy_arg); | |
13449 | lsal.canonical = xstrdup (*copy_arg); | |
13450 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13451 | } | |
13452 | ||
13453 | static void | |
13454 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13455 | struct linespec_result *canonical, | |
983af33b | 13456 | char *cond_string, |
e7e0cddf | 13457 | char *extra_string, |
983af33b SDJ |
13458 | enum bptype type_wanted, |
13459 | enum bpdisp disposition, | |
13460 | int thread, | |
13461 | int task, int ignore_count, | |
13462 | const struct breakpoint_ops *ops, | |
13463 | int from_tty, int enabled, | |
44f238bb | 13464 | int internal, unsigned flags) |
983af33b SDJ |
13465 | { |
13466 | int i; | |
52d361e1 YQ |
13467 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13468 | canonical->sals, 0); | |
983af33b SDJ |
13469 | |
13470 | /* If the user is creating a static tracepoint by marker id | |
13471 | (strace -m MARKER_ID), then store the sals index, so that | |
13472 | breakpoint_re_set can try to match up which of the newly | |
13473 | found markers corresponds to this one, and, don't try to | |
13474 | expand multiple locations for each sal, given than SALS | |
13475 | already should contain all sals for MARKER_ID. */ | |
13476 | ||
13477 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13478 | { | |
13479 | struct symtabs_and_lines expanded; | |
13480 | struct tracepoint *tp; | |
13481 | struct cleanup *old_chain; | |
13482 | char *addr_string; | |
13483 | ||
13484 | expanded.nelts = 1; | |
13485 | expanded.sals = &lsal->sals.sals[i]; | |
13486 | ||
13487 | addr_string = xstrdup (canonical->addr_string); | |
13488 | old_chain = make_cleanup (xfree, addr_string); | |
13489 | ||
13490 | tp = XCNEW (struct tracepoint); | |
13491 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
13492 | addr_string, NULL, | |
e7e0cddf SS |
13493 | cond_string, extra_string, |
13494 | type_wanted, disposition, | |
983af33b | 13495 | thread, task, ignore_count, ops, |
44f238bb | 13496 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13497 | canonical->special_display); |
13498 | /* Given that its possible to have multiple markers with | |
13499 | the same string id, if the user is creating a static | |
13500 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13501 | store the sals index, so that breakpoint_re_set can | |
13502 | try to match up which of the newly found markers | |
13503 | corresponds to this one */ | |
13504 | tp->static_trace_marker_id_idx = i; | |
13505 | ||
13506 | install_breakpoint (internal, &tp->base, 0); | |
13507 | ||
13508 | discard_cleanups (old_chain); | |
13509 | } | |
13510 | } | |
13511 | ||
13512 | static void | |
5f700d83 | 13513 | strace_marker_decode_location (struct breakpoint *b, char **s, |
983af33b SDJ |
13514 | struct symtabs_and_lines *sals) |
13515 | { | |
13516 | struct tracepoint *tp = (struct tracepoint *) b; | |
13517 | ||
13518 | *sals = decode_static_tracepoint_spec (s); | |
13519 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
13520 | { | |
13521 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13522 | sals->nelts = 1; | |
13523 | } | |
13524 | else | |
13525 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13526 | } | |
13527 | ||
13528 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13529 | ||
13530 | static int | |
13531 | strace_marker_p (struct breakpoint *b) | |
13532 | { | |
13533 | return b->ops == &strace_marker_breakpoint_ops; | |
13534 | } | |
13535 | ||
53a5351d | 13536 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13537 | structures. */ |
c906108c SS |
13538 | |
13539 | void | |
fba45db2 | 13540 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13541 | { |
52f0bd74 | 13542 | struct breakpoint *b; |
c906108c | 13543 | |
8a3fe4f8 | 13544 | gdb_assert (bpt != NULL); |
c906108c | 13545 | |
4a64f543 MS |
13546 | /* Has this bp already been deleted? This can happen because |
13547 | multiple lists can hold pointers to bp's. bpstat lists are | |
13548 | especial culprits. | |
13549 | ||
13550 | One example of this happening is a watchpoint's scope bp. When | |
13551 | the scope bp triggers, we notice that the watchpoint is out of | |
13552 | scope, and delete it. We also delete its scope bp. But the | |
13553 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13554 | That bpstat is then checked for auto-deleting bp's, which are | |
13555 | deleted. | |
13556 | ||
13557 | A real solution to this problem might involve reference counts in | |
13558 | bp's, and/or giving them pointers back to their referencing | |
13559 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13560 | storage when no more references were extent. A cheaper bandaid | |
13561 | was chosen. */ | |
c906108c SS |
13562 | if (bpt->type == bp_none) |
13563 | return; | |
13564 | ||
4a64f543 MS |
13565 | /* At least avoid this stale reference until the reference counting |
13566 | of breakpoints gets resolved. */ | |
d0fb5eae | 13567 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13568 | { |
d0fb5eae | 13569 | struct breakpoint *related; |
3a5c3e22 | 13570 | struct watchpoint *w; |
d0fb5eae JK |
13571 | |
13572 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13573 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13574 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13575 | w = (struct watchpoint *) bpt; |
13576 | else | |
13577 | w = NULL; | |
13578 | if (w != NULL) | |
13579 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13580 | |
13581 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13582 | for (related = bpt; related->related_breakpoint != bpt; | |
13583 | related = related->related_breakpoint); | |
13584 | related->related_breakpoint = bpt->related_breakpoint; | |
13585 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13586 | } |
13587 | ||
a9634178 TJB |
13588 | /* watch_command_1 creates a watchpoint but only sets its number if |
13589 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13590 | a problem in that process, we'll be asked to delete the half-created | |
13591 | watchpoint. In that case, don't announce the deletion. */ | |
13592 | if (bpt->number) | |
13593 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13594 | |
c906108c SS |
13595 | if (breakpoint_chain == bpt) |
13596 | breakpoint_chain = bpt->next; | |
13597 | ||
c906108c SS |
13598 | ALL_BREAKPOINTS (b) |
13599 | if (b->next == bpt) | |
c5aa993b JM |
13600 | { |
13601 | b->next = bpt->next; | |
13602 | break; | |
13603 | } | |
c906108c | 13604 | |
f431efe5 PA |
13605 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13606 | been freed. */ | |
13607 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13608 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13609 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13610 | commands are associated with the bpstat; if we remove it here, | |
13611 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13612 | event-top.c won't do anything, and temporary breakpoints with | |
13613 | commands won't work. */ | |
13614 | ||
13615 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13616 | ||
4a64f543 MS |
13617 | /* Now that breakpoint is removed from breakpoint list, update the |
13618 | global location list. This will remove locations that used to | |
13619 | belong to this breakpoint. Do this before freeing the breakpoint | |
13620 | itself, since remove_breakpoint looks at location's owner. It | |
13621 | might be better design to have location completely | |
13622 | self-contained, but it's not the case now. */ | |
44702360 | 13623 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13624 | |
348d480f | 13625 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13626 | /* On the chance that someone will soon try again to delete this |
13627 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13628 | bpt->type = bp_none; |
b8c9b27d | 13629 | xfree (bpt); |
c906108c SS |
13630 | } |
13631 | ||
4d6140d9 AC |
13632 | static void |
13633 | do_delete_breakpoint_cleanup (void *b) | |
13634 | { | |
13635 | delete_breakpoint (b); | |
13636 | } | |
13637 | ||
13638 | struct cleanup * | |
13639 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13640 | { | |
13641 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13642 | } | |
13643 | ||
51be5b68 PA |
13644 | /* Iterator function to call a user-provided callback function once |
13645 | for each of B and its related breakpoints. */ | |
13646 | ||
13647 | static void | |
13648 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13649 | void (*function) (struct breakpoint *, | |
13650 | void *), | |
13651 | void *data) | |
13652 | { | |
13653 | struct breakpoint *related; | |
13654 | ||
13655 | related = b; | |
13656 | do | |
13657 | { | |
13658 | struct breakpoint *next; | |
13659 | ||
13660 | /* FUNCTION may delete RELATED. */ | |
13661 | next = related->related_breakpoint; | |
13662 | ||
13663 | if (next == related) | |
13664 | { | |
13665 | /* RELATED is the last ring entry. */ | |
13666 | function (related, data); | |
13667 | ||
13668 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13669 | B. There's nothing left to do anyway, so just break | |
13670 | out. */ | |
13671 | break; | |
13672 | } | |
13673 | else | |
13674 | function (related, data); | |
13675 | ||
13676 | related = next; | |
13677 | } | |
13678 | while (related != b); | |
13679 | } | |
95a42b64 TT |
13680 | |
13681 | static void | |
13682 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13683 | { | |
13684 | delete_breakpoint (b); | |
13685 | } | |
13686 | ||
51be5b68 PA |
13687 | /* A callback for map_breakpoint_numbers that calls |
13688 | delete_breakpoint. */ | |
13689 | ||
13690 | static void | |
13691 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13692 | { | |
13693 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13694 | } | |
13695 | ||
c906108c | 13696 | void |
fba45db2 | 13697 | delete_command (char *arg, int from_tty) |
c906108c | 13698 | { |
35df4500 | 13699 | struct breakpoint *b, *b_tmp; |
c906108c | 13700 | |
ea9365bb TT |
13701 | dont_repeat (); |
13702 | ||
c906108c SS |
13703 | if (arg == 0) |
13704 | { | |
13705 | int breaks_to_delete = 0; | |
13706 | ||
46c6471b PA |
13707 | /* Delete all breakpoints if no argument. Do not delete |
13708 | internal breakpoints, these have to be deleted with an | |
13709 | explicit breakpoint number argument. */ | |
c5aa993b | 13710 | ALL_BREAKPOINTS (b) |
46c6471b | 13711 | if (user_breakpoint_p (b)) |
973d738b DJ |
13712 | { |
13713 | breaks_to_delete = 1; | |
13714 | break; | |
13715 | } | |
c906108c SS |
13716 | |
13717 | /* Ask user only if there are some breakpoints to delete. */ | |
13718 | if (!from_tty | |
e2e0b3e5 | 13719 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13720 | { |
35df4500 | 13721 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13722 | if (user_breakpoint_p (b)) |
c5aa993b | 13723 | delete_breakpoint (b); |
c906108c SS |
13724 | } |
13725 | } | |
13726 | else | |
51be5b68 | 13727 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13728 | } |
13729 | ||
0d381245 VP |
13730 | static int |
13731 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 13732 | { |
0d381245 | 13733 | for (; loc; loc = loc->next) |
8645ff69 UW |
13734 | if (!loc->shlib_disabled |
13735 | && !loc->pspace->executing_startup) | |
0d381245 VP |
13736 | return 0; |
13737 | return 1; | |
fe3f5fa8 VP |
13738 | } |
13739 | ||
776592bf DE |
13740 | /* Subroutine of update_breakpoint_locations to simplify it. |
13741 | Return non-zero if multiple fns in list LOC have the same name. | |
13742 | Null names are ignored. */ | |
13743 | ||
13744 | static int | |
13745 | ambiguous_names_p (struct bp_location *loc) | |
13746 | { | |
13747 | struct bp_location *l; | |
13748 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13749 | (int (*) (const void *, |
13750 | const void *)) streq, | |
776592bf DE |
13751 | NULL, xcalloc, xfree); |
13752 | ||
13753 | for (l = loc; l != NULL; l = l->next) | |
13754 | { | |
13755 | const char **slot; | |
13756 | const char *name = l->function_name; | |
13757 | ||
13758 | /* Allow for some names to be NULL, ignore them. */ | |
13759 | if (name == NULL) | |
13760 | continue; | |
13761 | ||
13762 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13763 | INSERT); | |
4a64f543 MS |
13764 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13765 | returns NULL. */ | |
776592bf DE |
13766 | if (*slot != NULL) |
13767 | { | |
13768 | htab_delete (htab); | |
13769 | return 1; | |
13770 | } | |
13771 | *slot = name; | |
13772 | } | |
13773 | ||
13774 | htab_delete (htab); | |
13775 | return 0; | |
13776 | } | |
13777 | ||
0fb4aa4b PA |
13778 | /* When symbols change, it probably means the sources changed as well, |
13779 | and it might mean the static tracepoint markers are no longer at | |
13780 | the same address or line numbers they used to be at last we | |
13781 | checked. Losing your static tracepoints whenever you rebuild is | |
13782 | undesirable. This function tries to resync/rematch gdb static | |
13783 | tracepoints with the markers on the target, for static tracepoints | |
13784 | that have not been set by marker id. Static tracepoint that have | |
13785 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13786 | The heuristic is: | |
13787 | ||
13788 | 1) For a tracepoint set at a specific address, look for a marker at | |
13789 | the old PC. If one is found there, assume to be the same marker. | |
13790 | If the name / string id of the marker found is different from the | |
13791 | previous known name, assume that means the user renamed the marker | |
13792 | in the sources, and output a warning. | |
13793 | ||
13794 | 2) For a tracepoint set at a given line number, look for a marker | |
13795 | at the new address of the old line number. If one is found there, | |
13796 | assume to be the same marker. If the name / string id of the | |
13797 | marker found is different from the previous known name, assume that | |
13798 | means the user renamed the marker in the sources, and output a | |
13799 | warning. | |
13800 | ||
13801 | 3) If a marker is no longer found at the same address or line, it | |
13802 | may mean the marker no longer exists. But it may also just mean | |
13803 | the code changed a bit. Maybe the user added a few lines of code | |
13804 | that made the marker move up or down (in line number terms). Ask | |
13805 | the target for info about the marker with the string id as we knew | |
13806 | it. If found, update line number and address in the matching | |
13807 | static tracepoint. This will get confused if there's more than one | |
13808 | marker with the same ID (possible in UST, although unadvised | |
13809 | precisely because it confuses tools). */ | |
13810 | ||
13811 | static struct symtab_and_line | |
13812 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13813 | { | |
d9b3f62e | 13814 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13815 | struct static_tracepoint_marker marker; |
13816 | CORE_ADDR pc; | |
0fb4aa4b PA |
13817 | |
13818 | pc = sal.pc; | |
13819 | if (sal.line) | |
13820 | find_line_pc (sal.symtab, sal.line, &pc); | |
13821 | ||
13822 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13823 | { | |
d9b3f62e | 13824 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
13825 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
13826 | b->number, | |
d9b3f62e | 13827 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 13828 | |
d9b3f62e PA |
13829 | xfree (tp->static_trace_marker_id); |
13830 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
13831 | release_static_tracepoint_marker (&marker); |
13832 | ||
13833 | return sal; | |
13834 | } | |
13835 | ||
13836 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13837 | by string ID. */ | |
13838 | if (!sal.explicit_pc | |
13839 | && sal.line != 0 | |
13840 | && sal.symtab != NULL | |
d9b3f62e | 13841 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
13842 | { |
13843 | VEC(static_tracepoint_marker_p) *markers; | |
13844 | ||
13845 | markers | |
d9b3f62e | 13846 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
13847 | |
13848 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
13849 | { | |
80e1d417 | 13850 | struct symtab_and_line sal2; |
0fb4aa4b | 13851 | struct symbol *sym; |
80e1d417 | 13852 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13853 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 13854 | |
80e1d417 | 13855 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 13856 | |
d9b3f62e | 13857 | xfree (tp->static_trace_marker_id); |
80e1d417 | 13858 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
13859 | |
13860 | warning (_("marker for static tracepoint %d (%s) not " | |
13861 | "found at previous line number"), | |
d9b3f62e | 13862 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 13863 | |
80e1d417 | 13864 | init_sal (&sal2); |
0fb4aa4b | 13865 | |
80e1d417 | 13866 | sal2.pc = tpmarker->address; |
0fb4aa4b | 13867 | |
80e1d417 AS |
13868 | sal2 = find_pc_line (tpmarker->address, 0); |
13869 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
13870 | ui_out_text (uiout, "Now in "); |
13871 | if (sym) | |
13872 | { | |
13873 | ui_out_field_string (uiout, "func", | |
13874 | SYMBOL_PRINT_NAME (sym)); | |
13875 | ui_out_text (uiout, " at "); | |
13876 | } | |
05cba821 JK |
13877 | ui_out_field_string (uiout, "file", |
13878 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
13879 | ui_out_text (uiout, ":"); |
13880 | ||
13881 | if (ui_out_is_mi_like_p (uiout)) | |
13882 | { | |
0b0865da | 13883 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13884 | |
f35a17b5 | 13885 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
13886 | } |
13887 | ||
80e1d417 | 13888 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
13889 | ui_out_text (uiout, "\n"); |
13890 | ||
80e1d417 | 13891 | b->loc->line_number = sal2.line; |
2f202fde | 13892 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b PA |
13893 | |
13894 | xfree (b->addr_string); | |
13895 | b->addr_string = xstrprintf ("%s:%d", | |
05cba821 | 13896 | symtab_to_filename_for_display (sal2.symtab), |
f8eba3c6 | 13897 | b->loc->line_number); |
0fb4aa4b PA |
13898 | |
13899 | /* Might be nice to check if function changed, and warn if | |
13900 | so. */ | |
13901 | ||
80e1d417 | 13902 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
13903 | } |
13904 | } | |
13905 | return sal; | |
13906 | } | |
13907 | ||
8d3788bd VP |
13908 | /* Returns 1 iff locations A and B are sufficiently same that |
13909 | we don't need to report breakpoint as changed. */ | |
13910 | ||
13911 | static int | |
13912 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13913 | { | |
13914 | while (a && b) | |
13915 | { | |
13916 | if (a->address != b->address) | |
13917 | return 0; | |
13918 | ||
13919 | if (a->shlib_disabled != b->shlib_disabled) | |
13920 | return 0; | |
13921 | ||
13922 | if (a->enabled != b->enabled) | |
13923 | return 0; | |
13924 | ||
13925 | a = a->next; | |
13926 | b = b->next; | |
13927 | } | |
13928 | ||
13929 | if ((a == NULL) != (b == NULL)) | |
13930 | return 0; | |
13931 | ||
13932 | return 1; | |
13933 | } | |
13934 | ||
f1310107 TJB |
13935 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
13936 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
13937 | a ranged breakpoint. */ | |
13938 | ||
0e30163f | 13939 | void |
0d381245 | 13940 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
13941 | struct symtabs_and_lines sals, |
13942 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
13943 | { |
13944 | int i; | |
0d381245 VP |
13945 | struct bp_location *existing_locations = b->loc; |
13946 | ||
f8eba3c6 TT |
13947 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
13948 | { | |
13949 | /* Ranged breakpoints have only one start location and one end | |
13950 | location. */ | |
13951 | b->enable_state = bp_disabled; | |
44702360 | 13952 | update_global_location_list (UGLL_MAY_INSERT); |
f8eba3c6 TT |
13953 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
13954 | "multiple locations found\n"), | |
13955 | b->number); | |
13956 | return; | |
13957 | } | |
f1310107 | 13958 | |
4a64f543 MS |
13959 | /* If there's no new locations, and all existing locations are |
13960 | pending, don't do anything. This optimizes the common case where | |
13961 | all locations are in the same shared library, that was unloaded. | |
13962 | We'd like to retain the location, so that when the library is | |
13963 | loaded again, we don't loose the enabled/disabled status of the | |
13964 | individual locations. */ | |
0d381245 | 13965 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
13966 | return; |
13967 | ||
fe3f5fa8 VP |
13968 | b->loc = NULL; |
13969 | ||
0d381245 | 13970 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 13971 | { |
f8eba3c6 TT |
13972 | struct bp_location *new_loc; |
13973 | ||
13974 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
13975 | ||
13976 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 13977 | |
0d381245 VP |
13978 | /* Reparse conditions, they might contain references to the |
13979 | old symtab. */ | |
13980 | if (b->cond_string != NULL) | |
13981 | { | |
bbc13ae3 | 13982 | const char *s; |
fe3f5fa8 | 13983 | |
0d381245 | 13984 | s = b->cond_string; |
492d29ea | 13985 | TRY |
0d381245 | 13986 | { |
1bb9788d TT |
13987 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
13988 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
13989 | 0); |
13990 | } | |
492d29ea | 13991 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 13992 | { |
3e43a32a MS |
13993 | warning (_("failed to reevaluate condition " |
13994 | "for breakpoint %d: %s"), | |
0d381245 VP |
13995 | b->number, e.message); |
13996 | new_loc->enabled = 0; | |
13997 | } | |
492d29ea | 13998 | END_CATCH |
0d381245 | 13999 | } |
fe3f5fa8 | 14000 | |
f1310107 TJB |
14001 | if (sals_end.nelts) |
14002 | { | |
14003 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14004 | ||
14005 | new_loc->length = end - sals.sals[0].pc + 1; | |
14006 | } | |
0d381245 | 14007 | } |
fe3f5fa8 | 14008 | |
4a64f543 MS |
14009 | /* If possible, carry over 'disable' status from existing |
14010 | breakpoints. */ | |
0d381245 VP |
14011 | { |
14012 | struct bp_location *e = existing_locations; | |
776592bf DE |
14013 | /* If there are multiple breakpoints with the same function name, |
14014 | e.g. for inline functions, comparing function names won't work. | |
14015 | Instead compare pc addresses; this is just a heuristic as things | |
14016 | may have moved, but in practice it gives the correct answer | |
14017 | often enough until a better solution is found. */ | |
14018 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14019 | ||
0d381245 VP |
14020 | for (; e; e = e->next) |
14021 | { | |
14022 | if (!e->enabled && e->function_name) | |
14023 | { | |
14024 | struct bp_location *l = b->loc; | |
776592bf DE |
14025 | if (have_ambiguous_names) |
14026 | { | |
14027 | for (; l; l = l->next) | |
f1310107 | 14028 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14029 | { |
14030 | l->enabled = 0; | |
14031 | break; | |
14032 | } | |
14033 | } | |
14034 | else | |
14035 | { | |
14036 | for (; l; l = l->next) | |
14037 | if (l->function_name | |
14038 | && strcmp (e->function_name, l->function_name) == 0) | |
14039 | { | |
14040 | l->enabled = 0; | |
14041 | break; | |
14042 | } | |
14043 | } | |
0d381245 VP |
14044 | } |
14045 | } | |
14046 | } | |
fe3f5fa8 | 14047 | |
8d3788bd VP |
14048 | if (!locations_are_equal (existing_locations, b->loc)) |
14049 | observer_notify_breakpoint_modified (b); | |
14050 | ||
44702360 | 14051 | update_global_location_list (UGLL_MAY_INSERT); |
fe3f5fa8 VP |
14052 | } |
14053 | ||
ef23e705 TJB |
14054 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
14055 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
14056 | ||
14057 | static struct symtabs_and_lines | |
5f700d83 | 14058 | location_to_sals (struct breakpoint *b, char *addr_string, int *found) |
ef23e705 TJB |
14059 | { |
14060 | char *s; | |
02d20e4a | 14061 | struct symtabs_and_lines sals = {0}; |
492d29ea | 14062 | struct gdb_exception exception = exception_none; |
ef23e705 | 14063 | |
983af33b | 14064 | gdb_assert (b->ops != NULL); |
ef23e705 | 14065 | s = addr_string; |
ef23e705 | 14066 | |
492d29ea | 14067 | TRY |
ef23e705 | 14068 | { |
5f700d83 | 14069 | b->ops->decode_location (b, &s, &sals); |
ef23e705 | 14070 | } |
492d29ea | 14071 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14072 | { |
14073 | int not_found_and_ok = 0; | |
492d29ea PA |
14074 | |
14075 | exception = e; | |
14076 | ||
ef23e705 TJB |
14077 | /* For pending breakpoints, it's expected that parsing will |
14078 | fail until the right shared library is loaded. User has | |
14079 | already told to create pending breakpoints and don't need | |
14080 | extra messages. If breakpoint is in bp_shlib_disabled | |
14081 | state, then user already saw the message about that | |
14082 | breakpoint being disabled, and don't want to see more | |
14083 | errors. */ | |
58438ac1 | 14084 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14085 | && (b->condition_not_parsed |
14086 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14087 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14088 | || b->enable_state == bp_disabled)) |
14089 | not_found_and_ok = 1; | |
14090 | ||
14091 | if (!not_found_and_ok) | |
14092 | { | |
14093 | /* We surely don't want to warn about the same breakpoint | |
14094 | 10 times. One solution, implemented here, is disable | |
14095 | the breakpoint on error. Another solution would be to | |
14096 | have separate 'warning emitted' flag. Since this | |
14097 | happens only when a binary has changed, I don't know | |
14098 | which approach is better. */ | |
14099 | b->enable_state = bp_disabled; | |
14100 | throw_exception (e); | |
14101 | } | |
14102 | } | |
492d29ea | 14103 | END_CATCH |
ef23e705 | 14104 | |
492d29ea | 14105 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14106 | { |
f8eba3c6 | 14107 | int i; |
ef23e705 | 14108 | |
f8eba3c6 TT |
14109 | for (i = 0; i < sals.nelts; ++i) |
14110 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
14111 | if (b->condition_not_parsed && s && s[0]) |
14112 | { | |
ed1d1739 KS |
14113 | char *cond_string, *extra_string; |
14114 | int thread, task; | |
ef23e705 TJB |
14115 | |
14116 | find_condition_and_thread (s, sals.sals[0].pc, | |
e7e0cddf SS |
14117 | &cond_string, &thread, &task, |
14118 | &extra_string); | |
ef23e705 TJB |
14119 | if (cond_string) |
14120 | b->cond_string = cond_string; | |
14121 | b->thread = thread; | |
14122 | b->task = task; | |
e7e0cddf SS |
14123 | if (extra_string) |
14124 | b->extra_string = extra_string; | |
ef23e705 TJB |
14125 | b->condition_not_parsed = 0; |
14126 | } | |
14127 | ||
983af33b | 14128 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14129 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14130 | |
58438ac1 TT |
14131 | *found = 1; |
14132 | } | |
14133 | else | |
14134 | *found = 0; | |
ef23e705 TJB |
14135 | |
14136 | return sals; | |
14137 | } | |
14138 | ||
348d480f PA |
14139 | /* The default re_set method, for typical hardware or software |
14140 | breakpoints. Reevaluate the breakpoint and recreate its | |
14141 | locations. */ | |
14142 | ||
14143 | static void | |
28010a5d | 14144 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14145 | { |
14146 | int found; | |
f1310107 | 14147 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14148 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14149 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 | 14150 | |
5f700d83 | 14151 | sals = location_to_sals (b, b->addr_string, &found); |
ef23e705 TJB |
14152 | if (found) |
14153 | { | |
14154 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14155 | expanded = sals; |
ef23e705 TJB |
14156 | } |
14157 | ||
f1310107 TJB |
14158 | if (b->addr_string_range_end) |
14159 | { | |
5f700d83 | 14160 | sals_end = location_to_sals (b, b->addr_string_range_end, &found); |
f1310107 TJB |
14161 | if (found) |
14162 | { | |
14163 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14164 | expanded_end = sals_end; |
f1310107 TJB |
14165 | } |
14166 | } | |
14167 | ||
14168 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14169 | } |
14170 | ||
983af33b SDJ |
14171 | /* Default method for creating SALs from an address string. It basically |
14172 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14173 | ||
14174 | static void | |
5f700d83 | 14175 | create_sals_from_location_default (char **arg, |
983af33b SDJ |
14176 | struct linespec_result *canonical, |
14177 | enum bptype type_wanted, | |
14178 | char *addr_start, char **copy_arg) | |
14179 | { | |
14180 | parse_breakpoint_sals (arg, canonical); | |
14181 | } | |
14182 | ||
14183 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14184 | function for the `create_breakpoints_sal' method of | |
14185 | breakpoint_ops. */ | |
14186 | ||
14187 | static void | |
14188 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14189 | struct linespec_result *canonical, | |
983af33b | 14190 | char *cond_string, |
e7e0cddf | 14191 | char *extra_string, |
983af33b SDJ |
14192 | enum bptype type_wanted, |
14193 | enum bpdisp disposition, | |
14194 | int thread, | |
14195 | int task, int ignore_count, | |
14196 | const struct breakpoint_ops *ops, | |
14197 | int from_tty, int enabled, | |
44f238bb | 14198 | int internal, unsigned flags) |
983af33b SDJ |
14199 | { |
14200 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14201 | extra_string, |
983af33b SDJ |
14202 | type_wanted, disposition, |
14203 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14204 | enabled, internal, flags); |
983af33b SDJ |
14205 | } |
14206 | ||
14207 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14208 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b SDJ |
14209 | |
14210 | static void | |
5f700d83 | 14211 | decode_location_default (struct breakpoint *b, char **s, |
983af33b SDJ |
14212 | struct symtabs_and_lines *sals) |
14213 | { | |
14214 | struct linespec_result canonical; | |
14215 | ||
14216 | init_linespec_result (&canonical); | |
14217 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
14218 | (struct symtab *) NULL, 0, | |
14219 | &canonical, multiple_symbols_all, | |
14220 | b->filter); | |
14221 | ||
14222 | /* We should get 0 or 1 resulting SALs. */ | |
14223 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14224 | ||
14225 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14226 | { | |
14227 | struct linespec_sals *lsal; | |
14228 | ||
14229 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14230 | *sals = lsal->sals; | |
14231 | /* Arrange it so the destructor does not free the | |
14232 | contents. */ | |
14233 | lsal->sals.sals = NULL; | |
14234 | } | |
14235 | ||
14236 | destroy_linespec_result (&canonical); | |
14237 | } | |
14238 | ||
28010a5d PA |
14239 | /* Prepare the global context for a re-set of breakpoint B. */ |
14240 | ||
14241 | static struct cleanup * | |
14242 | prepare_re_set_context (struct breakpoint *b) | |
14243 | { | |
14244 | struct cleanup *cleanups; | |
14245 | ||
14246 | input_radix = b->input_radix; | |
14247 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14248 | if (b->pspace != NULL) |
14249 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14250 | set_language (b->language); |
14251 | ||
14252 | return cleanups; | |
ef23e705 TJB |
14253 | } |
14254 | ||
c906108c SS |
14255 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14256 | The value we return ends up being the return value from catch_errors. | |
14257 | Unused in this case. */ | |
14258 | ||
14259 | static int | |
4efb68b1 | 14260 | breakpoint_re_set_one (void *bint) |
c906108c | 14261 | { |
4a64f543 | 14262 | /* Get past catch_errs. */ |
53a5351d | 14263 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14264 | struct cleanup *cleanups; |
c906108c | 14265 | |
348d480f PA |
14266 | cleanups = prepare_re_set_context (b); |
14267 | b->ops->re_set (b); | |
14268 | do_cleanups (cleanups); | |
c906108c SS |
14269 | return 0; |
14270 | } | |
14271 | ||
69de3c6a | 14272 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14273 | void |
69de3c6a | 14274 | breakpoint_re_set (void) |
c906108c | 14275 | { |
35df4500 | 14276 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14277 | enum language save_language; |
14278 | int save_input_radix; | |
6c95b8df | 14279 | struct cleanup *old_chain; |
c5aa993b | 14280 | |
c906108c SS |
14281 | save_language = current_language->la_language; |
14282 | save_input_radix = input_radix; | |
6c95b8df PA |
14283 | old_chain = save_current_program_space (); |
14284 | ||
35df4500 | 14285 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14286 | { |
4a64f543 | 14287 | /* Format possible error msg. */ |
fe3f5fa8 | 14288 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14289 | b->number); |
14290 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14291 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14292 | do_cleanups (cleanups); |
c5aa993b | 14293 | } |
c906108c SS |
14294 | set_language (save_language); |
14295 | input_radix = save_input_radix; | |
e62c965a | 14296 | |
0756c555 | 14297 | jit_breakpoint_re_set (); |
4efc6507 | 14298 | |
6c95b8df PA |
14299 | do_cleanups (old_chain); |
14300 | ||
af02033e PP |
14301 | create_overlay_event_breakpoint (); |
14302 | create_longjmp_master_breakpoint (); | |
14303 | create_std_terminate_master_breakpoint (); | |
186c406b | 14304 | create_exception_master_breakpoint (); |
c906108c SS |
14305 | } |
14306 | \f | |
c906108c SS |
14307 | /* Reset the thread number of this breakpoint: |
14308 | ||
14309 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14310 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14311 | void |
fba45db2 | 14312 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14313 | { |
14314 | if (b->thread != -1) | |
14315 | { | |
39f77062 KB |
14316 | if (in_thread_list (inferior_ptid)) |
14317 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14318 | |
14319 | /* We're being called after following a fork. The new fork is | |
14320 | selected as current, and unless this was a vfork will have a | |
14321 | different program space from the original thread. Reset that | |
14322 | as well. */ | |
14323 | b->loc->pspace = current_program_space; | |
c906108c SS |
14324 | } |
14325 | } | |
14326 | ||
03ac34d5 MS |
14327 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14328 | If from_tty is nonzero, it prints a message to that effect, | |
14329 | which ends with a period (no newline). */ | |
14330 | ||
c906108c | 14331 | void |
fba45db2 | 14332 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14333 | { |
52f0bd74 | 14334 | struct breakpoint *b; |
c906108c SS |
14335 | |
14336 | if (count < 0) | |
14337 | count = 0; | |
14338 | ||
14339 | ALL_BREAKPOINTS (b) | |
14340 | if (b->number == bptnum) | |
c5aa993b | 14341 | { |
d77f58be SS |
14342 | if (is_tracepoint (b)) |
14343 | { | |
14344 | if (from_tty && count != 0) | |
14345 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14346 | bptnum); | |
14347 | return; | |
14348 | } | |
14349 | ||
c5aa993b | 14350 | b->ignore_count = count; |
221ea385 KS |
14351 | if (from_tty) |
14352 | { | |
14353 | if (count == 0) | |
3e43a32a MS |
14354 | printf_filtered (_("Will stop next time " |
14355 | "breakpoint %d is reached."), | |
221ea385 KS |
14356 | bptnum); |
14357 | else if (count == 1) | |
a3f17187 | 14358 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14359 | bptnum); |
14360 | else | |
3e43a32a MS |
14361 | printf_filtered (_("Will ignore next %d " |
14362 | "crossings of breakpoint %d."), | |
221ea385 KS |
14363 | count, bptnum); |
14364 | } | |
8d3788bd | 14365 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14366 | return; |
14367 | } | |
c906108c | 14368 | |
8a3fe4f8 | 14369 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14370 | } |
14371 | ||
c906108c SS |
14372 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14373 | ||
14374 | static void | |
fba45db2 | 14375 | ignore_command (char *args, int from_tty) |
c906108c SS |
14376 | { |
14377 | char *p = args; | |
52f0bd74 | 14378 | int num; |
c906108c SS |
14379 | |
14380 | if (p == 0) | |
e2e0b3e5 | 14381 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14382 | |
c906108c | 14383 | num = get_number (&p); |
5c44784c | 14384 | if (num == 0) |
8a3fe4f8 | 14385 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14386 | if (*p == 0) |
8a3fe4f8 | 14387 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14388 | |
14389 | set_ignore_count (num, | |
14390 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14391 | from_tty); | |
221ea385 KS |
14392 | if (from_tty) |
14393 | printf_filtered ("\n"); | |
c906108c SS |
14394 | } |
14395 | \f | |
14396 | /* Call FUNCTION on each of the breakpoints | |
14397 | whose numbers are given in ARGS. */ | |
14398 | ||
14399 | static void | |
95a42b64 TT |
14400 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14401 | void *), | |
14402 | void *data) | |
c906108c | 14403 | { |
52f0bd74 AC |
14404 | int num; |
14405 | struct breakpoint *b, *tmp; | |
11cf8741 | 14406 | int match; |
197f0a60 | 14407 | struct get_number_or_range_state state; |
c906108c | 14408 | |
b9d61307 | 14409 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14410 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14411 | |
197f0a60 TT |
14412 | init_number_or_range (&state, args); |
14413 | ||
14414 | while (!state.finished) | |
c906108c | 14415 | { |
e799154c | 14416 | const char *p = state.string; |
197f0a60 | 14417 | |
11cf8741 | 14418 | match = 0; |
c5aa993b | 14419 | |
197f0a60 | 14420 | num = get_number_or_range (&state); |
5c44784c | 14421 | if (num == 0) |
c5aa993b | 14422 | { |
8a3fe4f8 | 14423 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14424 | } |
14425 | else | |
14426 | { | |
14427 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14428 | if (b->number == num) | |
14429 | { | |
11cf8741 | 14430 | match = 1; |
cdac0397 | 14431 | function (b, data); |
11cf8741 | 14432 | break; |
5c44784c | 14433 | } |
11cf8741 | 14434 | if (match == 0) |
a3f17187 | 14435 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14436 | } |
c906108c SS |
14437 | } |
14438 | } | |
14439 | ||
0d381245 VP |
14440 | static struct bp_location * |
14441 | find_location_by_number (char *number) | |
14442 | { | |
14443 | char *dot = strchr (number, '.'); | |
14444 | char *p1; | |
14445 | int bp_num; | |
14446 | int loc_num; | |
14447 | struct breakpoint *b; | |
14448 | struct bp_location *loc; | |
14449 | ||
14450 | *dot = '\0'; | |
14451 | ||
14452 | p1 = number; | |
197f0a60 | 14453 | bp_num = get_number (&p1); |
0d381245 VP |
14454 | if (bp_num == 0) |
14455 | error (_("Bad breakpoint number '%s'"), number); | |
14456 | ||
14457 | ALL_BREAKPOINTS (b) | |
14458 | if (b->number == bp_num) | |
14459 | { | |
14460 | break; | |
14461 | } | |
14462 | ||
14463 | if (!b || b->number != bp_num) | |
14464 | error (_("Bad breakpoint number '%s'"), number); | |
14465 | ||
14466 | p1 = dot+1; | |
197f0a60 | 14467 | loc_num = get_number (&p1); |
0d381245 VP |
14468 | if (loc_num == 0) |
14469 | error (_("Bad breakpoint location number '%s'"), number); | |
14470 | ||
14471 | --loc_num; | |
14472 | loc = b->loc; | |
14473 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14474 | ; | |
14475 | if (!loc) | |
14476 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14477 | ||
14478 | return loc; | |
14479 | } | |
14480 | ||
14481 | ||
1900040c MS |
14482 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14483 | If from_tty is nonzero, it prints a message to that effect, | |
14484 | which ends with a period (no newline). */ | |
14485 | ||
c906108c | 14486 | void |
fba45db2 | 14487 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14488 | { |
14489 | /* Never disable a watchpoint scope breakpoint; we want to | |
14490 | hit them when we leave scope so we can delete both the | |
14491 | watchpoint and its scope breakpoint at that time. */ | |
14492 | if (bpt->type == bp_watchpoint_scope) | |
14493 | return; | |
14494 | ||
b5de0fa7 | 14495 | bpt->enable_state = bp_disabled; |
c906108c | 14496 | |
b775012e LM |
14497 | /* Mark breakpoint locations modified. */ |
14498 | mark_breakpoint_modified (bpt); | |
14499 | ||
d248b706 KY |
14500 | if (target_supports_enable_disable_tracepoint () |
14501 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14502 | { | |
14503 | struct bp_location *location; | |
14504 | ||
14505 | for (location = bpt->loc; location; location = location->next) | |
14506 | target_disable_tracepoint (location); | |
14507 | } | |
14508 | ||
44702360 | 14509 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14510 | |
8d3788bd | 14511 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14512 | } |
14513 | ||
51be5b68 PA |
14514 | /* A callback for iterate_over_related_breakpoints. */ |
14515 | ||
14516 | static void | |
14517 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14518 | { | |
14519 | disable_breakpoint (b); | |
14520 | } | |
14521 | ||
95a42b64 TT |
14522 | /* A callback for map_breakpoint_numbers that calls |
14523 | disable_breakpoint. */ | |
14524 | ||
14525 | static void | |
14526 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14527 | { | |
51be5b68 | 14528 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14529 | } |
14530 | ||
c906108c | 14531 | static void |
fba45db2 | 14532 | disable_command (char *args, int from_tty) |
c906108c | 14533 | { |
c906108c | 14534 | if (args == 0) |
46c6471b PA |
14535 | { |
14536 | struct breakpoint *bpt; | |
14537 | ||
14538 | ALL_BREAKPOINTS (bpt) | |
14539 | if (user_breakpoint_p (bpt)) | |
14540 | disable_breakpoint (bpt); | |
14541 | } | |
9eaabc75 | 14542 | else |
0d381245 | 14543 | { |
9eaabc75 MW |
14544 | char *num = extract_arg (&args); |
14545 | ||
14546 | while (num) | |
d248b706 | 14547 | { |
9eaabc75 | 14548 | if (strchr (num, '.')) |
b775012e | 14549 | { |
9eaabc75 MW |
14550 | struct bp_location *loc = find_location_by_number (num); |
14551 | ||
14552 | if (loc) | |
14553 | { | |
14554 | if (loc->enabled) | |
14555 | { | |
14556 | loc->enabled = 0; | |
14557 | mark_breakpoint_location_modified (loc); | |
14558 | } | |
14559 | if (target_supports_enable_disable_tracepoint () | |
14560 | && current_trace_status ()->running && loc->owner | |
14561 | && is_tracepoint (loc->owner)) | |
14562 | target_disable_tracepoint (loc); | |
14563 | } | |
44702360 | 14564 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14565 | } |
9eaabc75 MW |
14566 | else |
14567 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14568 | num = extract_arg (&args); | |
d248b706 | 14569 | } |
0d381245 | 14570 | } |
c906108c SS |
14571 | } |
14572 | ||
14573 | static void | |
816338b5 SS |
14574 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14575 | int count) | |
c906108c | 14576 | { |
afe38095 | 14577 | int target_resources_ok; |
c906108c SS |
14578 | |
14579 | if (bpt->type == bp_hardware_breakpoint) | |
14580 | { | |
14581 | int i; | |
c5aa993b | 14582 | i = hw_breakpoint_used_count (); |
53a5351d | 14583 | target_resources_ok = |
d92524f1 | 14584 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14585 | i + 1, 0); |
c906108c | 14586 | if (target_resources_ok == 0) |
8a3fe4f8 | 14587 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14588 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14589 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14590 | } |
14591 | ||
cc60f2e3 | 14592 | if (is_watchpoint (bpt)) |
c906108c | 14593 | { |
d07205c2 | 14594 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14595 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14596 | |
492d29ea | 14597 | TRY |
c906108c | 14598 | { |
3a5c3e22 PA |
14599 | struct watchpoint *w = (struct watchpoint *) bpt; |
14600 | ||
1e718ff1 TJB |
14601 | orig_enable_state = bpt->enable_state; |
14602 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14603 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14604 | } |
492d29ea | 14605 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14606 | { |
1e718ff1 | 14607 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14608 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14609 | bpt->number); | |
14610 | return; | |
c5aa993b | 14611 | } |
492d29ea | 14612 | END_CATCH |
c906108c | 14613 | } |
0101ce28 | 14614 | |
b775012e LM |
14615 | bpt->enable_state = bp_enabled; |
14616 | ||
14617 | /* Mark breakpoint locations modified. */ | |
14618 | mark_breakpoint_modified (bpt); | |
14619 | ||
d248b706 KY |
14620 | if (target_supports_enable_disable_tracepoint () |
14621 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14622 | { | |
14623 | struct bp_location *location; | |
14624 | ||
14625 | for (location = bpt->loc; location; location = location->next) | |
14626 | target_enable_tracepoint (location); | |
14627 | } | |
14628 | ||
b4c291bb | 14629 | bpt->disposition = disposition; |
816338b5 | 14630 | bpt->enable_count = count; |
44702360 | 14631 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14632 | |
8d3788bd | 14633 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14634 | } |
14635 | ||
fe3f5fa8 | 14636 | |
c906108c | 14637 | void |
fba45db2 | 14638 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14639 | { |
816338b5 | 14640 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14641 | } |
14642 | ||
14643 | static void | |
14644 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14645 | { | |
14646 | enable_breakpoint (bpt); | |
c906108c SS |
14647 | } |
14648 | ||
95a42b64 TT |
14649 | /* A callback for map_breakpoint_numbers that calls |
14650 | enable_breakpoint. */ | |
14651 | ||
14652 | static void | |
14653 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14654 | { | |
51be5b68 | 14655 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14656 | } |
14657 | ||
c906108c SS |
14658 | /* The enable command enables the specified breakpoints (or all defined |
14659 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14660 | in stopping the inferior. */ |
c906108c | 14661 | |
c906108c | 14662 | static void |
fba45db2 | 14663 | enable_command (char *args, int from_tty) |
c906108c | 14664 | { |
c906108c | 14665 | if (args == 0) |
46c6471b PA |
14666 | { |
14667 | struct breakpoint *bpt; | |
14668 | ||
14669 | ALL_BREAKPOINTS (bpt) | |
14670 | if (user_breakpoint_p (bpt)) | |
14671 | enable_breakpoint (bpt); | |
14672 | } | |
9eaabc75 | 14673 | else |
0d381245 | 14674 | { |
9eaabc75 MW |
14675 | char *num = extract_arg (&args); |
14676 | ||
14677 | while (num) | |
d248b706 | 14678 | { |
9eaabc75 | 14679 | if (strchr (num, '.')) |
b775012e | 14680 | { |
9eaabc75 MW |
14681 | struct bp_location *loc = find_location_by_number (num); |
14682 | ||
14683 | if (loc) | |
14684 | { | |
14685 | if (!loc->enabled) | |
14686 | { | |
14687 | loc->enabled = 1; | |
14688 | mark_breakpoint_location_modified (loc); | |
14689 | } | |
14690 | if (target_supports_enable_disable_tracepoint () | |
14691 | && current_trace_status ()->running && loc->owner | |
14692 | && is_tracepoint (loc->owner)) | |
14693 | target_enable_tracepoint (loc); | |
14694 | } | |
44702360 | 14695 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 14696 | } |
9eaabc75 MW |
14697 | else |
14698 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
14699 | num = extract_arg (&args); | |
d248b706 | 14700 | } |
0d381245 | 14701 | } |
c906108c SS |
14702 | } |
14703 | ||
816338b5 SS |
14704 | /* This struct packages up disposition data for application to multiple |
14705 | breakpoints. */ | |
14706 | ||
14707 | struct disp_data | |
14708 | { | |
14709 | enum bpdisp disp; | |
14710 | int count; | |
14711 | }; | |
14712 | ||
c906108c | 14713 | static void |
51be5b68 PA |
14714 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14715 | { | |
816338b5 | 14716 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14717 | |
816338b5 | 14718 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
14719 | } |
14720 | ||
14721 | static void | |
14722 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 14723 | { |
816338b5 | 14724 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
14725 | |
14726 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14727 | } |
14728 | ||
c906108c | 14729 | static void |
fba45db2 | 14730 | enable_once_command (char *args, int from_tty) |
c906108c | 14731 | { |
51be5b68 | 14732 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
14733 | } |
14734 | ||
816338b5 SS |
14735 | static void |
14736 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
14737 | { | |
14738 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
14739 | ||
14740 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
14741 | } | |
14742 | ||
14743 | static void | |
14744 | enable_count_command (char *args, int from_tty) | |
14745 | { | |
b9d61307 SM |
14746 | int count; |
14747 | ||
14748 | if (args == NULL) | |
14749 | error_no_arg (_("hit count")); | |
14750 | ||
14751 | count = get_number (&args); | |
816338b5 SS |
14752 | |
14753 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
14754 | } | |
14755 | ||
c906108c | 14756 | static void |
51be5b68 | 14757 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 14758 | { |
816338b5 | 14759 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
14760 | |
14761 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14762 | } |
14763 | ||
c906108c | 14764 | static void |
fba45db2 | 14765 | enable_delete_command (char *args, int from_tty) |
c906108c | 14766 | { |
51be5b68 | 14767 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
14768 | } |
14769 | \f | |
fa8d40ab JJ |
14770 | static void |
14771 | set_breakpoint_cmd (char *args, int from_tty) | |
14772 | { | |
14773 | } | |
14774 | ||
14775 | static void | |
14776 | show_breakpoint_cmd (char *args, int from_tty) | |
14777 | { | |
14778 | } | |
14779 | ||
1f3b5d1b PP |
14780 | /* Invalidate last known value of any hardware watchpoint if |
14781 | the memory which that value represents has been written to by | |
14782 | GDB itself. */ | |
14783 | ||
14784 | static void | |
8de0566d YQ |
14785 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14786 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14787 | const bfd_byte *data) |
14788 | { | |
14789 | struct breakpoint *bp; | |
14790 | ||
14791 | ALL_BREAKPOINTS (bp) | |
14792 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14793 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14794 | { |
3a5c3e22 | 14795 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14796 | |
3a5c3e22 PA |
14797 | if (wp->val_valid && wp->val) |
14798 | { | |
14799 | struct bp_location *loc; | |
14800 | ||
14801 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14802 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14803 | && loc->address + loc->length > addr | |
14804 | && addr + len > loc->address) | |
14805 | { | |
14806 | value_free (wp->val); | |
14807 | wp->val = NULL; | |
14808 | wp->val_valid = 0; | |
14809 | } | |
14810 | } | |
1f3b5d1b PP |
14811 | } |
14812 | } | |
14813 | ||
8181d85f DJ |
14814 | /* Create and insert a breakpoint for software single step. */ |
14815 | ||
14816 | void | |
6c95b8df | 14817 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
14818 | struct address_space *aspace, |
14819 | CORE_ADDR next_pc) | |
8181d85f | 14820 | { |
7c16b83e PA |
14821 | struct thread_info *tp = inferior_thread (); |
14822 | struct symtab_and_line sal; | |
14823 | CORE_ADDR pc = next_pc; | |
8181d85f | 14824 | |
34b7e8a6 PA |
14825 | if (tp->control.single_step_breakpoints == NULL) |
14826 | { | |
14827 | tp->control.single_step_breakpoints | |
14828 | = new_single_step_breakpoint (tp->num, gdbarch); | |
14829 | } | |
8181d85f | 14830 | |
7c16b83e PA |
14831 | sal = find_pc_line (pc, 0); |
14832 | sal.pc = pc; | |
14833 | sal.section = find_pc_overlay (pc); | |
14834 | sal.explicit_pc = 1; | |
34b7e8a6 | 14835 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14836 | |
7c16b83e | 14837 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14838 | } |
14839 | ||
34b7e8a6 | 14840 | /* See breakpoint.h. */ |
f02253f1 HZ |
14841 | |
14842 | int | |
7c16b83e PA |
14843 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
14844 | struct address_space *aspace, | |
14845 | CORE_ADDR pc) | |
1aafd4da | 14846 | { |
7c16b83e | 14847 | struct bp_location *loc; |
1aafd4da | 14848 | |
7c16b83e PA |
14849 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14850 | if (loc->inserted | |
14851 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14852 | return 1; | |
1aafd4da | 14853 | |
7c16b83e | 14854 | return 0; |
ef370185 JB |
14855 | } |
14856 | ||
14857 | /* Check whether a software single-step breakpoint is inserted at | |
14858 | PC. */ | |
14859 | ||
14860 | int | |
14861 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
14862 | CORE_ADDR pc) | |
14863 | { | |
34b7e8a6 PA |
14864 | struct breakpoint *bpt; |
14865 | ||
14866 | ALL_BREAKPOINTS (bpt) | |
14867 | { | |
14868 | if (bpt->type == bp_single_step | |
14869 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14870 | return 1; | |
14871 | } | |
14872 | return 0; | |
1aafd4da UW |
14873 | } |
14874 | ||
1042e4c0 SS |
14875 | /* Tracepoint-specific operations. */ |
14876 | ||
14877 | /* Set tracepoint count to NUM. */ | |
14878 | static void | |
14879 | set_tracepoint_count (int num) | |
14880 | { | |
14881 | tracepoint_count = num; | |
4fa62494 | 14882 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14883 | } |
14884 | ||
70221824 | 14885 | static void |
1042e4c0 SS |
14886 | trace_command (char *arg, int from_tty) |
14887 | { | |
55aa24fb SDJ |
14888 | struct breakpoint_ops *ops; |
14889 | const char *arg_cp = arg; | |
14890 | ||
14891 | if (arg && probe_linespec_to_ops (&arg_cp)) | |
14892 | ops = &tracepoint_probe_breakpoint_ops; | |
14893 | else | |
14894 | ops = &tracepoint_breakpoint_ops; | |
14895 | ||
558a9d82 YQ |
14896 | create_breakpoint (get_current_arch (), |
14897 | arg, | |
14898 | NULL, 0, NULL, 1 /* parse arg */, | |
14899 | 0 /* tempflag */, | |
14900 | bp_tracepoint /* type_wanted */, | |
14901 | 0 /* Ignore count */, | |
14902 | pending_break_support, | |
14903 | ops, | |
14904 | from_tty, | |
14905 | 1 /* enabled */, | |
14906 | 0 /* internal */, 0); | |
1042e4c0 SS |
14907 | } |
14908 | ||
70221824 | 14909 | static void |
7a697b8d SS |
14910 | ftrace_command (char *arg, int from_tty) |
14911 | { | |
558a9d82 YQ |
14912 | create_breakpoint (get_current_arch (), |
14913 | arg, | |
14914 | NULL, 0, NULL, 1 /* parse arg */, | |
14915 | 0 /* tempflag */, | |
14916 | bp_fast_tracepoint /* type_wanted */, | |
14917 | 0 /* Ignore count */, | |
14918 | pending_break_support, | |
14919 | &tracepoint_breakpoint_ops, | |
14920 | from_tty, | |
14921 | 1 /* enabled */, | |
14922 | 0 /* internal */, 0); | |
0fb4aa4b PA |
14923 | } |
14924 | ||
14925 | /* strace command implementation. Creates a static tracepoint. */ | |
14926 | ||
70221824 | 14927 | static void |
0fb4aa4b PA |
14928 | strace_command (char *arg, int from_tty) |
14929 | { | |
983af33b SDJ |
14930 | struct breakpoint_ops *ops; |
14931 | ||
14932 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14933 | or with a normal static tracepoint. */ | |
61012eef | 14934 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
983af33b SDJ |
14935 | ops = &strace_marker_breakpoint_ops; |
14936 | else | |
14937 | ops = &tracepoint_breakpoint_ops; | |
14938 | ||
558a9d82 YQ |
14939 | create_breakpoint (get_current_arch (), |
14940 | arg, | |
14941 | NULL, 0, NULL, 1 /* parse arg */, | |
14942 | 0 /* tempflag */, | |
14943 | bp_static_tracepoint /* type_wanted */, | |
14944 | 0 /* Ignore count */, | |
14945 | pending_break_support, | |
14946 | ops, | |
14947 | from_tty, | |
14948 | 1 /* enabled */, | |
14949 | 0 /* internal */, 0); | |
7a697b8d SS |
14950 | } |
14951 | ||
409873ef SS |
14952 | /* Set up a fake reader function that gets command lines from a linked |
14953 | list that was acquired during tracepoint uploading. */ | |
14954 | ||
14955 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14956 | static int next_cmd; |
409873ef SS |
14957 | |
14958 | static char * | |
14959 | read_uploaded_action (void) | |
14960 | { | |
14961 | char *rslt; | |
14962 | ||
3149d8c1 | 14963 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 14964 | |
3149d8c1 | 14965 | next_cmd++; |
409873ef SS |
14966 | |
14967 | return rslt; | |
14968 | } | |
14969 | ||
00bf0b85 SS |
14970 | /* Given information about a tracepoint as recorded on a target (which |
14971 | can be either a live system or a trace file), attempt to create an | |
14972 | equivalent GDB tracepoint. This is not a reliable process, since | |
14973 | the target does not necessarily have all the information used when | |
14974 | the tracepoint was originally defined. */ | |
14975 | ||
d9b3f62e | 14976 | struct tracepoint * |
00bf0b85 | 14977 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14978 | { |
409873ef | 14979 | char *addr_str, small_buf[100]; |
d9b3f62e | 14980 | struct tracepoint *tp; |
fd9b8c24 | 14981 | |
409873ef SS |
14982 | if (utp->at_string) |
14983 | addr_str = utp->at_string; | |
14984 | else | |
14985 | { | |
14986 | /* In the absence of a source location, fall back to raw | |
14987 | address. Since there is no way to confirm that the address | |
14988 | means the same thing as when the trace was started, warn the | |
14989 | user. */ | |
3e43a32a MS |
14990 | warning (_("Uploaded tracepoint %d has no " |
14991 | "source location, using raw address"), | |
409873ef | 14992 | utp->number); |
8c042590 | 14993 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
14994 | addr_str = small_buf; |
14995 | } | |
14996 | ||
14997 | /* There's not much we can do with a sequence of bytecodes. */ | |
14998 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14999 | warning (_("Uploaded tracepoint %d condition " |
15000 | "has no source form, ignoring it"), | |
409873ef | 15001 | utp->number); |
d5551862 | 15002 | |
8cdf0e15 | 15003 | if (!create_breakpoint (get_current_arch (), |
409873ef | 15004 | addr_str, |
e7e0cddf SS |
15005 | utp->cond_string, -1, NULL, |
15006 | 0 /* parse cond/thread */, | |
8cdf0e15 | 15007 | 0 /* tempflag */, |
0fb4aa4b | 15008 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15009 | 0 /* Ignore count */, |
15010 | pending_break_support, | |
348d480f | 15011 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15012 | 0 /* from_tty */, |
84f4c1fe | 15013 | utp->enabled /* enabled */, |
44f238bb PA |
15014 | 0 /* internal */, |
15015 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
15016 | return NULL; |
15017 | ||
409873ef | 15018 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15019 | tp = get_tracepoint (tracepoint_count); |
15020 | gdb_assert (tp != NULL); | |
d5551862 | 15021 | |
00bf0b85 SS |
15022 | if (utp->pass > 0) |
15023 | { | |
8c042590 PM |
15024 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15025 | tp->base.number); | |
00bf0b85 | 15026 | |
409873ef | 15027 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15028 | } |
15029 | ||
409873ef SS |
15030 | /* If we have uploaded versions of the original commands, set up a |
15031 | special-purpose "reader" function and call the usual command line | |
15032 | reader, then pass the result to the breakpoint command-setting | |
15033 | function. */ | |
3149d8c1 | 15034 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15035 | { |
409873ef | 15036 | struct command_line *cmd_list; |
00bf0b85 | 15037 | |
409873ef | 15038 | this_utp = utp; |
3149d8c1 | 15039 | next_cmd = 0; |
d5551862 | 15040 | |
409873ef SS |
15041 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15042 | ||
d9b3f62e | 15043 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15044 | } |
3149d8c1 SS |
15045 | else if (!VEC_empty (char_ptr, utp->actions) |
15046 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15047 | warning (_("Uploaded tracepoint %d actions " |
15048 | "have no source form, ignoring them"), | |
409873ef | 15049 | utp->number); |
00bf0b85 | 15050 | |
f196051f SS |
15051 | /* Copy any status information that might be available. */ |
15052 | tp->base.hit_count = utp->hit_count; | |
15053 | tp->traceframe_usage = utp->traceframe_usage; | |
15054 | ||
00bf0b85 | 15055 | return tp; |
d9b3f62e | 15056 | } |
00bf0b85 | 15057 | |
1042e4c0 SS |
15058 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15059 | omitted. */ | |
15060 | ||
15061 | static void | |
e5a67952 | 15062 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15063 | { |
79a45e25 | 15064 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15065 | int num_printed; |
1042e4c0 | 15066 | |
e5a67952 | 15067 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15068 | |
15069 | if (num_printed == 0) | |
1042e4c0 | 15070 | { |
e5a67952 | 15071 | if (args == NULL || *args == '\0') |
d77f58be SS |
15072 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15073 | else | |
e5a67952 | 15074 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15075 | } |
ad443146 SS |
15076 | |
15077 | default_collect_info (); | |
1042e4c0 SS |
15078 | } |
15079 | ||
4a64f543 | 15080 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15081 | Not supported by all targets. */ |
15082 | static void | |
15083 | enable_trace_command (char *args, int from_tty) | |
15084 | { | |
15085 | enable_command (args, from_tty); | |
15086 | } | |
15087 | ||
4a64f543 | 15088 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15089 | Not supported by all targets. */ |
15090 | static void | |
15091 | disable_trace_command (char *args, int from_tty) | |
15092 | { | |
15093 | disable_command (args, from_tty); | |
15094 | } | |
15095 | ||
4a64f543 | 15096 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15097 | static void |
15098 | delete_trace_command (char *arg, int from_tty) | |
15099 | { | |
35df4500 | 15100 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15101 | |
15102 | dont_repeat (); | |
15103 | ||
15104 | if (arg == 0) | |
15105 | { | |
15106 | int breaks_to_delete = 0; | |
15107 | ||
15108 | /* Delete all breakpoints if no argument. | |
15109 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15110 | have to be deleted with an explicit breakpoint number |
15111 | argument. */ | |
1042e4c0 | 15112 | ALL_TRACEPOINTS (b) |
46c6471b | 15113 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15114 | { |
15115 | breaks_to_delete = 1; | |
15116 | break; | |
15117 | } | |
1042e4c0 SS |
15118 | |
15119 | /* Ask user only if there are some breakpoints to delete. */ | |
15120 | if (!from_tty | |
15121 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15122 | { | |
35df4500 | 15123 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15124 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15125 | delete_breakpoint (b); |
1042e4c0 SS |
15126 | } |
15127 | } | |
15128 | else | |
51be5b68 | 15129 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15130 | } |
15131 | ||
197f0a60 TT |
15132 | /* Helper function for trace_pass_command. */ |
15133 | ||
15134 | static void | |
d9b3f62e | 15135 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15136 | { |
d9b3f62e | 15137 | tp->pass_count = count; |
6f6484cd | 15138 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15139 | if (from_tty) |
15140 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15141 | tp->base.number, count); |
197f0a60 TT |
15142 | } |
15143 | ||
1042e4c0 SS |
15144 | /* Set passcount for tracepoint. |
15145 | ||
15146 | First command argument is passcount, second is tracepoint number. | |
15147 | If tracepoint number omitted, apply to most recently defined. | |
15148 | Also accepts special argument "all". */ | |
15149 | ||
15150 | static void | |
15151 | trace_pass_command (char *args, int from_tty) | |
15152 | { | |
d9b3f62e | 15153 | struct tracepoint *t1; |
1042e4c0 | 15154 | unsigned int count; |
1042e4c0 SS |
15155 | |
15156 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15157 | error (_("passcount command requires an " |
15158 | "argument (count + optional TP num)")); | |
1042e4c0 | 15159 | |
4a64f543 | 15160 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15161 | |
529480d0 | 15162 | args = skip_spaces (args); |
1042e4c0 SS |
15163 | if (*args && strncasecmp (args, "all", 3) == 0) |
15164 | { | |
d9b3f62e PA |
15165 | struct breakpoint *b; |
15166 | ||
1042e4c0 | 15167 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15168 | if (*args) |
15169 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15170 | |
d9b3f62e | 15171 | ALL_TRACEPOINTS (b) |
197f0a60 | 15172 | { |
d9b3f62e | 15173 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15174 | trace_pass_set_count (t1, count, from_tty); |
15175 | } | |
15176 | } | |
15177 | else if (*args == '\0') | |
1042e4c0 | 15178 | { |
5fa1d40e | 15179 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15180 | if (t1) |
197f0a60 TT |
15181 | trace_pass_set_count (t1, count, from_tty); |
15182 | } | |
15183 | else | |
15184 | { | |
15185 | struct get_number_or_range_state state; | |
15186 | ||
15187 | init_number_or_range (&state, args); | |
15188 | while (!state.finished) | |
1042e4c0 | 15189 | { |
5fa1d40e | 15190 | t1 = get_tracepoint_by_number (&args, &state); |
197f0a60 TT |
15191 | if (t1) |
15192 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15193 | } |
15194 | } | |
1042e4c0 SS |
15195 | } |
15196 | ||
d9b3f62e | 15197 | struct tracepoint * |
1042e4c0 SS |
15198 | get_tracepoint (int num) |
15199 | { | |
15200 | struct breakpoint *t; | |
15201 | ||
15202 | ALL_TRACEPOINTS (t) | |
15203 | if (t->number == num) | |
d9b3f62e | 15204 | return (struct tracepoint *) t; |
1042e4c0 SS |
15205 | |
15206 | return NULL; | |
15207 | } | |
15208 | ||
d5551862 SS |
15209 | /* Find the tracepoint with the given target-side number (which may be |
15210 | different from the tracepoint number after disconnecting and | |
15211 | reconnecting). */ | |
15212 | ||
d9b3f62e | 15213 | struct tracepoint * |
d5551862 SS |
15214 | get_tracepoint_by_number_on_target (int num) |
15215 | { | |
d9b3f62e | 15216 | struct breakpoint *b; |
d5551862 | 15217 | |
d9b3f62e PA |
15218 | ALL_TRACEPOINTS (b) |
15219 | { | |
15220 | struct tracepoint *t = (struct tracepoint *) b; | |
15221 | ||
15222 | if (t->number_on_target == num) | |
15223 | return t; | |
15224 | } | |
d5551862 SS |
15225 | |
15226 | return NULL; | |
15227 | } | |
15228 | ||
1042e4c0 | 15229 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15230 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15231 | If the argument is missing, the most recent tracepoint |
15232 | (tracepoint_count) is returned. */ | |
15233 | ||
d9b3f62e | 15234 | struct tracepoint * |
197f0a60 | 15235 | get_tracepoint_by_number (char **arg, |
5fa1d40e | 15236 | struct get_number_or_range_state *state) |
1042e4c0 | 15237 | { |
1042e4c0 SS |
15238 | struct breakpoint *t; |
15239 | int tpnum; | |
15240 | char *instring = arg == NULL ? NULL : *arg; | |
15241 | ||
197f0a60 TT |
15242 | if (state) |
15243 | { | |
15244 | gdb_assert (!state->finished); | |
15245 | tpnum = get_number_or_range (state); | |
15246 | } | |
15247 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15248 | tpnum = tracepoint_count; |
1042e4c0 | 15249 | else |
197f0a60 | 15250 | tpnum = get_number (arg); |
1042e4c0 SS |
15251 | |
15252 | if (tpnum <= 0) | |
15253 | { | |
15254 | if (instring && *instring) | |
15255 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15256 | instring); | |
15257 | else | |
5fa1d40e | 15258 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15259 | return NULL; |
15260 | } | |
15261 | ||
15262 | ALL_TRACEPOINTS (t) | |
15263 | if (t->number == tpnum) | |
15264 | { | |
d9b3f62e | 15265 | return (struct tracepoint *) t; |
1042e4c0 SS |
15266 | } |
15267 | ||
1042e4c0 SS |
15268 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15269 | return NULL; | |
15270 | } | |
15271 | ||
d9b3f62e PA |
15272 | void |
15273 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15274 | { | |
15275 | if (b->thread != -1) | |
15276 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15277 | ||
15278 | if (b->task != 0) | |
15279 | fprintf_unfiltered (fp, " task %d", b->task); | |
15280 | ||
15281 | fprintf_unfiltered (fp, "\n"); | |
15282 | } | |
15283 | ||
6149aea9 PA |
15284 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15285 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15286 | on each breakpoint and only include the ones for which it returns | |
15287 | non-zero. */ | |
15288 | ||
1042e4c0 | 15289 | static void |
6149aea9 PA |
15290 | save_breakpoints (char *filename, int from_tty, |
15291 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15292 | { |
15293 | struct breakpoint *tp; | |
6149aea9 | 15294 | int any = 0; |
1042e4c0 | 15295 | struct cleanup *cleanup; |
a7bdde9e | 15296 | struct ui_file *fp; |
6149aea9 | 15297 | int extra_trace_bits = 0; |
1042e4c0 | 15298 | |
6149aea9 PA |
15299 | if (filename == 0 || *filename == 0) |
15300 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15301 | |
15302 | /* See if we have anything to save. */ | |
6149aea9 | 15303 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15304 | { |
6149aea9 | 15305 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15306 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15307 | continue; |
15308 | ||
15309 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15310 | if (filter && !filter (tp)) | |
15311 | continue; | |
15312 | ||
15313 | any = 1; | |
15314 | ||
15315 | if (is_tracepoint (tp)) | |
15316 | { | |
15317 | extra_trace_bits = 1; | |
15318 | ||
15319 | /* We can stop searching. */ | |
15320 | break; | |
15321 | } | |
1042e4c0 | 15322 | } |
6149aea9 PA |
15323 | |
15324 | if (!any) | |
1042e4c0 | 15325 | { |
6149aea9 | 15326 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15327 | return; |
15328 | } | |
15329 | ||
c718be47 PA |
15330 | filename = tilde_expand (filename); |
15331 | cleanup = make_cleanup (xfree, filename); | |
15332 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15333 | if (!fp) |
6149aea9 PA |
15334 | error (_("Unable to open file '%s' for saving (%s)"), |
15335 | filename, safe_strerror (errno)); | |
a7bdde9e | 15336 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15337 | |
6149aea9 PA |
15338 | if (extra_trace_bits) |
15339 | save_trace_state_variables (fp); | |
8bf6485c | 15340 | |
6149aea9 | 15341 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15342 | { |
6149aea9 | 15343 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15344 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15345 | continue; |
8bf6485c | 15346 | |
6149aea9 PA |
15347 | /* If we have a filter, only save the breakpoints it accepts. */ |
15348 | if (filter && !filter (tp)) | |
15349 | continue; | |
15350 | ||
348d480f | 15351 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15352 | |
6149aea9 PA |
15353 | /* Note, we can't rely on tp->number for anything, as we can't |
15354 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15355 | instead. */ | |
15356 | ||
15357 | if (tp->cond_string) | |
15358 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15359 | ||
15360 | if (tp->ignore_count) | |
15361 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15362 | ||
2d9442cc | 15363 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15364 | { |
6c63c96a | 15365 | struct gdb_exception exception; |
a7bdde9e | 15366 | |
6149aea9 | 15367 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15368 | |
79a45e25 | 15369 | ui_out_redirect (current_uiout, fp); |
492d29ea | 15370 | TRY |
1042e4c0 | 15371 | { |
79a45e25 | 15372 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15373 | } |
492d29ea PA |
15374 | CATCH (ex, RETURN_MASK_ALL) |
15375 | { | |
6c63c96a | 15376 | ui_out_redirect (current_uiout, NULL); |
492d29ea PA |
15377 | throw_exception (ex); |
15378 | } | |
15379 | END_CATCH | |
1042e4c0 | 15380 | |
6c63c96a | 15381 | ui_out_redirect (current_uiout, NULL); |
a7bdde9e | 15382 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15383 | } |
6149aea9 PA |
15384 | |
15385 | if (tp->enable_state == bp_disabled) | |
99894e11 | 15386 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
6149aea9 PA |
15387 | |
15388 | /* If this is a multi-location breakpoint, check if the locations | |
15389 | should be individually disabled. Watchpoint locations are | |
15390 | special, and not user visible. */ | |
15391 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15392 | { | |
15393 | struct bp_location *loc; | |
15394 | int n = 1; | |
15395 | ||
15396 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15397 | if (!loc->enabled) | |
15398 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15399 | } | |
1042e4c0 | 15400 | } |
8bf6485c | 15401 | |
6149aea9 | 15402 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15403 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15404 | ||
1042e4c0 | 15405 | if (from_tty) |
6149aea9 | 15406 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15407 | do_cleanups (cleanup); |
6149aea9 PA |
15408 | } |
15409 | ||
15410 | /* The `save breakpoints' command. */ | |
15411 | ||
15412 | static void | |
15413 | save_breakpoints_command (char *args, int from_tty) | |
15414 | { | |
15415 | save_breakpoints (args, from_tty, NULL); | |
15416 | } | |
15417 | ||
15418 | /* The `save tracepoints' command. */ | |
15419 | ||
15420 | static void | |
15421 | save_tracepoints_command (char *args, int from_tty) | |
15422 | { | |
15423 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15424 | } |
15425 | ||
15426 | /* Create a vector of all tracepoints. */ | |
15427 | ||
15428 | VEC(breakpoint_p) * | |
eeae04df | 15429 | all_tracepoints (void) |
1042e4c0 SS |
15430 | { |
15431 | VEC(breakpoint_p) *tp_vec = 0; | |
15432 | struct breakpoint *tp; | |
15433 | ||
15434 | ALL_TRACEPOINTS (tp) | |
15435 | { | |
15436 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15437 | } | |
15438 | ||
15439 | return tp_vec; | |
15440 | } | |
15441 | ||
c906108c | 15442 | \f |
4a64f543 MS |
15443 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15444 | commands. It is defined as a macro to prevent duplication. | |
15445 | COMMAND should be a string constant containing the name of the | |
15446 | command. */ | |
31e2b00f | 15447 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15448 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15449 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15450 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15451 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15452 | `-probe-dtrace' (for a DTrace probe).\n\ | |
31e2b00f AS |
15453 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
15454 | If a line number is specified, break at start of code for that line.\n\ | |
15455 | If a function is specified, break at start of code for that function.\n\ | |
15456 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
15457 | With no LOCATION, uses current execution address of the selected\n\ |
15458 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15459 | \n\ |
15460 | THREADNUM is the number from \"info threads\".\n\ | |
15461 | CONDITION is a boolean expression.\n\ | |
15462 | \n\ | |
d41c0fc8 PA |
15463 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15464 | conditions are different.\n\ | |
31e2b00f AS |
15465 | \n\ |
15466 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15467 | ||
44feb3ce TT |
15468 | /* List of subcommands for "catch". */ |
15469 | static struct cmd_list_element *catch_cmdlist; | |
15470 | ||
15471 | /* List of subcommands for "tcatch". */ | |
15472 | static struct cmd_list_element *tcatch_cmdlist; | |
15473 | ||
9ac4176b | 15474 | void |
44feb3ce | 15475 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 15476 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15477 | completer_ftype *completer, |
44feb3ce TT |
15478 | void *user_data_catch, |
15479 | void *user_data_tcatch) | |
15480 | { | |
15481 | struct cmd_list_element *command; | |
15482 | ||
15483 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15484 | &catch_cmdlist); | |
15485 | set_cmd_sfunc (command, sfunc); | |
15486 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15487 | set_cmd_completer (command, completer); |
44feb3ce TT |
15488 | |
15489 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15490 | &tcatch_cmdlist); | |
15491 | set_cmd_sfunc (command, sfunc); | |
15492 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15493 | set_cmd_completer (command, completer); |
44feb3ce TT |
15494 | } |
15495 | ||
6149aea9 PA |
15496 | static void |
15497 | save_command (char *arg, int from_tty) | |
15498 | { | |
3e43a32a MS |
15499 | printf_unfiltered (_("\"save\" must be followed by " |
15500 | "the name of a save subcommand.\n")); | |
635c7e8a | 15501 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15502 | } |
15503 | ||
84f4c1fe PM |
15504 | struct breakpoint * |
15505 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15506 | void *data) | |
15507 | { | |
35df4500 | 15508 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15509 | |
35df4500 | 15510 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15511 | { |
15512 | if ((*callback) (b, data)) | |
15513 | return b; | |
15514 | } | |
15515 | ||
15516 | return NULL; | |
15517 | } | |
15518 | ||
0574c78f GB |
15519 | /* Zero if any of the breakpoint's locations could be a location where |
15520 | functions have been inlined, nonzero otherwise. */ | |
15521 | ||
15522 | static int | |
15523 | is_non_inline_function (struct breakpoint *b) | |
15524 | { | |
15525 | /* The shared library event breakpoint is set on the address of a | |
15526 | non-inline function. */ | |
15527 | if (b->type == bp_shlib_event) | |
15528 | return 1; | |
15529 | ||
15530 | return 0; | |
15531 | } | |
15532 | ||
15533 | /* Nonzero if the specified PC cannot be a location where functions | |
15534 | have been inlined. */ | |
15535 | ||
15536 | int | |
09ac7c10 TT |
15537 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15538 | const struct target_waitstatus *ws) | |
0574c78f GB |
15539 | { |
15540 | struct breakpoint *b; | |
15541 | struct bp_location *bl; | |
15542 | ||
15543 | ALL_BREAKPOINTS (b) | |
15544 | { | |
15545 | if (!is_non_inline_function (b)) | |
15546 | continue; | |
15547 | ||
15548 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15549 | { | |
15550 | if (!bl->shlib_disabled | |
09ac7c10 | 15551 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15552 | return 1; |
15553 | } | |
15554 | } | |
15555 | ||
15556 | return 0; | |
15557 | } | |
15558 | ||
2f202fde JK |
15559 | /* Remove any references to OBJFILE which is going to be freed. */ |
15560 | ||
15561 | void | |
15562 | breakpoint_free_objfile (struct objfile *objfile) | |
15563 | { | |
15564 | struct bp_location **locp, *loc; | |
15565 | ||
15566 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15567 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15568 | loc->symtab = NULL; |
15569 | } | |
15570 | ||
2060206e PA |
15571 | void |
15572 | initialize_breakpoint_ops (void) | |
15573 | { | |
15574 | static int initialized = 0; | |
15575 | ||
15576 | struct breakpoint_ops *ops; | |
15577 | ||
15578 | if (initialized) | |
15579 | return; | |
15580 | initialized = 1; | |
15581 | ||
15582 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15583 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15584 | internal and momentary breakpoints, etc.). */ | |
15585 | ops = &bkpt_base_breakpoint_ops; | |
15586 | *ops = base_breakpoint_ops; | |
15587 | ops->re_set = bkpt_re_set; | |
15588 | ops->insert_location = bkpt_insert_location; | |
15589 | ops->remove_location = bkpt_remove_location; | |
15590 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15591 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15592 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15593 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15594 | |
15595 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15596 | ops = &bkpt_breakpoint_ops; | |
15597 | *ops = bkpt_base_breakpoint_ops; | |
15598 | ops->re_set = bkpt_re_set; | |
15599 | ops->resources_needed = bkpt_resources_needed; | |
15600 | ops->print_it = bkpt_print_it; | |
15601 | ops->print_mention = bkpt_print_mention; | |
15602 | ops->print_recreate = bkpt_print_recreate; | |
15603 | ||
15604 | /* Ranged breakpoints. */ | |
15605 | ops = &ranged_breakpoint_ops; | |
15606 | *ops = bkpt_breakpoint_ops; | |
15607 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15608 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15609 | ops->print_it = print_it_ranged_breakpoint; | |
15610 | ops->print_one = print_one_ranged_breakpoint; | |
15611 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15612 | ops->print_mention = print_mention_ranged_breakpoint; | |
15613 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15614 | ||
15615 | /* Internal breakpoints. */ | |
15616 | ops = &internal_breakpoint_ops; | |
15617 | *ops = bkpt_base_breakpoint_ops; | |
15618 | ops->re_set = internal_bkpt_re_set; | |
15619 | ops->check_status = internal_bkpt_check_status; | |
15620 | ops->print_it = internal_bkpt_print_it; | |
15621 | ops->print_mention = internal_bkpt_print_mention; | |
15622 | ||
15623 | /* Momentary breakpoints. */ | |
15624 | ops = &momentary_breakpoint_ops; | |
15625 | *ops = bkpt_base_breakpoint_ops; | |
15626 | ops->re_set = momentary_bkpt_re_set; | |
15627 | ops->check_status = momentary_bkpt_check_status; | |
15628 | ops->print_it = momentary_bkpt_print_it; | |
15629 | ops->print_mention = momentary_bkpt_print_mention; | |
15630 | ||
e2e4d78b JK |
15631 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
15632 | ops = &longjmp_breakpoint_ops; | |
15633 | *ops = momentary_breakpoint_ops; | |
15634 | ops->dtor = longjmp_bkpt_dtor; | |
15635 | ||
55aa24fb SDJ |
15636 | /* Probe breakpoints. */ |
15637 | ops = &bkpt_probe_breakpoint_ops; | |
15638 | *ops = bkpt_breakpoint_ops; | |
15639 | ops->insert_location = bkpt_probe_insert_location; | |
15640 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15641 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15642 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15643 | |
2060206e PA |
15644 | /* Watchpoints. */ |
15645 | ops = &watchpoint_breakpoint_ops; | |
15646 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 15647 | ops->dtor = dtor_watchpoint; |
2060206e PA |
15648 | ops->re_set = re_set_watchpoint; |
15649 | ops->insert_location = insert_watchpoint; | |
15650 | ops->remove_location = remove_watchpoint; | |
15651 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15652 | ops->check_status = check_status_watchpoint; | |
15653 | ops->resources_needed = resources_needed_watchpoint; | |
15654 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15655 | ops->print_it = print_it_watchpoint; | |
15656 | ops->print_mention = print_mention_watchpoint; | |
15657 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15658 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15659 | |
15660 | /* Masked watchpoints. */ | |
15661 | ops = &masked_watchpoint_breakpoint_ops; | |
15662 | *ops = watchpoint_breakpoint_ops; | |
15663 | ops->insert_location = insert_masked_watchpoint; | |
15664 | ops->remove_location = remove_masked_watchpoint; | |
15665 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15666 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15667 | ops->print_it = print_it_masked_watchpoint; | |
15668 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15669 | ops->print_mention = print_mention_masked_watchpoint; | |
15670 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15671 | ||
15672 | /* Tracepoints. */ | |
15673 | ops = &tracepoint_breakpoint_ops; | |
15674 | *ops = base_breakpoint_ops; | |
15675 | ops->re_set = tracepoint_re_set; | |
15676 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15677 | ops->print_one_detail = tracepoint_print_one_detail; | |
15678 | ops->print_mention = tracepoint_print_mention; | |
15679 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15680 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15681 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15682 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15683 | |
55aa24fb SDJ |
15684 | /* Probe tracepoints. */ |
15685 | ops = &tracepoint_probe_breakpoint_ops; | |
15686 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15687 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15688 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15689 | |
983af33b SDJ |
15690 | /* Static tracepoints with marker (`-m'). */ |
15691 | ops = &strace_marker_breakpoint_ops; | |
15692 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15693 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15694 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15695 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15696 | |
15697 | /* Fork catchpoints. */ | |
15698 | ops = &catch_fork_breakpoint_ops; | |
15699 | *ops = base_breakpoint_ops; | |
15700 | ops->insert_location = insert_catch_fork; | |
15701 | ops->remove_location = remove_catch_fork; | |
15702 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15703 | ops->print_it = print_it_catch_fork; | |
15704 | ops->print_one = print_one_catch_fork; | |
15705 | ops->print_mention = print_mention_catch_fork; | |
15706 | ops->print_recreate = print_recreate_catch_fork; | |
15707 | ||
15708 | /* Vfork catchpoints. */ | |
15709 | ops = &catch_vfork_breakpoint_ops; | |
15710 | *ops = base_breakpoint_ops; | |
15711 | ops->insert_location = insert_catch_vfork; | |
15712 | ops->remove_location = remove_catch_vfork; | |
15713 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15714 | ops->print_it = print_it_catch_vfork; | |
15715 | ops->print_one = print_one_catch_vfork; | |
15716 | ops->print_mention = print_mention_catch_vfork; | |
15717 | ops->print_recreate = print_recreate_catch_vfork; | |
15718 | ||
15719 | /* Exec catchpoints. */ | |
15720 | ops = &catch_exec_breakpoint_ops; | |
15721 | *ops = base_breakpoint_ops; | |
15722 | ops->dtor = dtor_catch_exec; | |
15723 | ops->insert_location = insert_catch_exec; | |
15724 | ops->remove_location = remove_catch_exec; | |
15725 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15726 | ops->print_it = print_it_catch_exec; | |
15727 | ops->print_one = print_one_catch_exec; | |
15728 | ops->print_mention = print_mention_catch_exec; | |
15729 | ops->print_recreate = print_recreate_catch_exec; | |
15730 | ||
edcc5120 TT |
15731 | /* Solib-related catchpoints. */ |
15732 | ops = &catch_solib_breakpoint_ops; | |
15733 | *ops = base_breakpoint_ops; | |
15734 | ops->dtor = dtor_catch_solib; | |
15735 | ops->insert_location = insert_catch_solib; | |
15736 | ops->remove_location = remove_catch_solib; | |
15737 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15738 | ops->check_status = check_status_catch_solib; | |
15739 | ops->print_it = print_it_catch_solib; | |
15740 | ops->print_one = print_one_catch_solib; | |
15741 | ops->print_mention = print_mention_catch_solib; | |
15742 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15743 | |
15744 | ops = &dprintf_breakpoint_ops; | |
15745 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15746 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15747 | ops->resources_needed = bkpt_resources_needed; |
15748 | ops->print_it = bkpt_print_it; | |
15749 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15750 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15751 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15752 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15753 | } |
15754 | ||
8bfd80db YQ |
15755 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15756 | ||
15757 | static struct cmd_list_element *enablebreaklist = NULL; | |
15758 | ||
c906108c | 15759 | void |
fba45db2 | 15760 | _initialize_breakpoint (void) |
c906108c SS |
15761 | { |
15762 | struct cmd_list_element *c; | |
15763 | ||
2060206e PA |
15764 | initialize_breakpoint_ops (); |
15765 | ||
84acb35a | 15766 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 15767 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 15768 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 15769 | |
55aa24fb SDJ |
15770 | breakpoint_objfile_key |
15771 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 15772 | |
c906108c SS |
15773 | breakpoint_chain = 0; |
15774 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15775 | before a breakpoint is set. */ | |
15776 | breakpoint_count = 0; | |
15777 | ||
1042e4c0 SS |
15778 | tracepoint_count = 0; |
15779 | ||
1bedd215 AC |
15780 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15781 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15782 | Usage is `ignore N COUNT'.")); | |
c906108c | 15783 | |
1bedd215 AC |
15784 | add_com ("commands", class_breakpoint, commands_command, _("\ |
15785 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
15786 | Give breakpoint number as argument after \"commands\".\n\ |
15787 | With no argument, the targeted breakpoint is the last one set.\n\ | |
15788 | The commands themselves follow starting on the next line.\n\ | |
15789 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15790 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15791 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15792 | |
d55637df | 15793 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 15794 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 15795 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15796 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 15797 | set_cmd_completer (c, condition_completer); |
c906108c | 15798 | |
1bedd215 | 15799 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15800 | Set a temporary breakpoint.\n\ |
c906108c SS |
15801 | Like \"break\" except the breakpoint is only temporary,\n\ |
15802 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15803 | by using \"enable delete\" on the breakpoint number.\n\ |
15804 | \n" | |
15805 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15806 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15807 | |
1bedd215 | 15808 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15809 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15810 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15811 | some target hardware may not have this support.\n\ |
15812 | \n" | |
15813 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15814 | set_cmd_completer (c, location_completer); |
c906108c | 15815 | |
1bedd215 | 15816 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15817 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15818 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15819 | so it will be deleted when hit.\n\ |
15820 | \n" | |
15821 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15822 | set_cmd_completer (c, location_completer); |
c906108c | 15823 | |
1bedd215 AC |
15824 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
15825 | Enable some breakpoints.\n\ | |
c906108c SS |
15826 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15827 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15828 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15829 | With a subcommand you can enable temporarily."), |
c906108c | 15830 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15831 | |
15832 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15833 | ||
84951ab5 | 15834 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 15835 | Enable some breakpoints.\n\ |
c906108c SS |
15836 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15837 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15838 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 15839 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15840 | |
1a966eab AC |
15841 | add_cmd ("once", no_class, enable_once_command, _("\ |
15842 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15843 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
15844 | &enablebreaklist); |
15845 | ||
1a966eab AC |
15846 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15847 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15848 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15849 | &enablebreaklist); |
15850 | ||
816338b5 SS |
15851 | add_cmd ("count", no_class, enable_count_command, _("\ |
15852 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15853 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15854 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15855 | &enablebreaklist); | |
15856 | ||
1a966eab AC |
15857 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15858 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15859 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15860 | &enablelist); |
15861 | ||
1a966eab AC |
15862 | add_cmd ("once", no_class, enable_once_command, _("\ |
15863 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15864 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
15865 | &enablelist); |
15866 | ||
15867 | add_cmd ("count", no_class, enable_count_command, _("\ | |
15868 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15869 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15870 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15871 | &enablelist); |
15872 | ||
1bedd215 AC |
15873 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
15874 | Disable some breakpoints.\n\ | |
c906108c SS |
15875 | Arguments are breakpoint numbers with spaces in between.\n\ |
15876 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15877 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15878 | &disablelist, "disable ", 1, &cmdlist); |
15879 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15880 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 15881 | |
1a966eab AC |
15882 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
15883 | Disable some breakpoints.\n\ | |
c906108c SS |
15884 | Arguments are breakpoint numbers with spaces in between.\n\ |
15885 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15886 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15887 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15888 | &disablelist); |
15889 | ||
1bedd215 AC |
15890 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
15891 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15892 | Arguments are breakpoint numbers with spaces in between.\n\ |
15893 | To delete all breakpoints, give no argument.\n\ | |
15894 | \n\ | |
15895 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 15896 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
15897 | &deletelist, "delete ", 1, &cmdlist); |
15898 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15899 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15900 | |
1a966eab AC |
15901 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
15902 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15903 | Arguments are breakpoint numbers with spaces in between.\n\ |
15904 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15905 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15906 | &deletelist); |
15907 | ||
1bedd215 AC |
15908 | add_com ("clear", class_breakpoint, clear_command, _("\ |
15909 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
15910 | Argument may be line number, function name, or \"*\" and an address.\n\ |
15911 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
15912 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
15913 | If an address is specified, breakpoints at that address are cleared.\n\ |
15914 | \n\ | |
15915 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
15916 | is executing in.\n\ |
15917 | \n\ | |
1bedd215 | 15918 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15919 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15920 | |
1bedd215 | 15921 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
15922 | Set breakpoint at specified line or function.\n" |
15923 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 15924 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15925 | |
c906108c SS |
15926 | add_com_alias ("b", "break", class_run, 1); |
15927 | add_com_alias ("br", "break", class_run, 1); | |
15928 | add_com_alias ("bre", "break", class_run, 1); | |
15929 | add_com_alias ("brea", "break", class_run, 1); | |
15930 | ||
c906108c SS |
15931 | if (dbx_commands) |
15932 | { | |
1bedd215 AC |
15933 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15934 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15935 | &stoplist, "stop ", 1, &cmdlist); |
15936 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15937 | _("Break in function or address."), &stoplist); |
c5aa993b | 15938 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15939 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
15940 | add_com ("status", class_info, breakpoints_info, _("\ |
15941 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15942 | The \"Type\" column indicates one of:\n\ |
15943 | \tbreakpoint - normal breakpoint\n\ | |
15944 | \twatchpoint - watchpoint\n\ | |
15945 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15946 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15947 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15948 | address and file/line number respectively.\n\ |
15949 | \n\ | |
15950 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15951 | are set to the address of the last breakpoint listed unless the command\n\ |
15952 | is prefixed with \"server \".\n\n\ | |
c906108c | 15953 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15954 | breakpoint set.")); |
c906108c SS |
15955 | } |
15956 | ||
1bedd215 | 15957 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 15958 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15959 | The \"Type\" column indicates one of:\n\ |
15960 | \tbreakpoint - normal breakpoint\n\ | |
15961 | \twatchpoint - watchpoint\n\ | |
15962 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15963 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15964 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15965 | address and file/line number respectively.\n\ |
15966 | \n\ | |
15967 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15968 | are set to the address of the last breakpoint listed unless the command\n\ |
15969 | is prefixed with \"server \".\n\n\ | |
c906108c | 15970 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15971 | breakpoint set.")); |
c906108c | 15972 | |
6b04bdb7 MS |
15973 | add_info_alias ("b", "breakpoints", 1); |
15974 | ||
1a966eab AC |
15975 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15976 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15977 | The \"Type\" column indicates one of:\n\ |
15978 | \tbreakpoint - normal breakpoint\n\ | |
15979 | \twatchpoint - watchpoint\n\ | |
15980 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15981 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15982 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15983 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15984 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15985 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15986 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15987 | address and file/line number respectively.\n\ |
15988 | \n\ | |
15989 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15990 | are set to the address of the last breakpoint listed unless the command\n\ |
15991 | is prefixed with \"server \".\n\n\ | |
c906108c | 15992 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15993 | breakpoint set."), |
c906108c SS |
15994 | &maintenanceinfolist); |
15995 | ||
44feb3ce TT |
15996 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
15997 | Set catchpoints to catch events."), | |
15998 | &catch_cmdlist, "catch ", | |
15999 | 0/*allow-unknown*/, &cmdlist); | |
16000 | ||
16001 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16002 | Set temporary catchpoints to catch events."), | |
16003 | &tcatch_cmdlist, "tcatch ", | |
16004 | 0/*allow-unknown*/, &cmdlist); | |
16005 | ||
44feb3ce TT |
16006 | add_catch_command ("fork", _("Catch calls to fork."), |
16007 | catch_fork_command_1, | |
a96d9b2e | 16008 | NULL, |
44feb3ce TT |
16009 | (void *) (uintptr_t) catch_fork_permanent, |
16010 | (void *) (uintptr_t) catch_fork_temporary); | |
16011 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16012 | catch_fork_command_1, | |
a96d9b2e | 16013 | NULL, |
44feb3ce TT |
16014 | (void *) (uintptr_t) catch_vfork_permanent, |
16015 | (void *) (uintptr_t) catch_vfork_temporary); | |
16016 | add_catch_command ("exec", _("Catch calls to exec."), | |
16017 | catch_exec_command_1, | |
a96d9b2e SDJ |
16018 | NULL, |
16019 | CATCH_PERMANENT, | |
16020 | CATCH_TEMPORARY); | |
edcc5120 TT |
16021 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16022 | Usage: catch load [REGEX]\n\ | |
16023 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16024 | catch_load_command_1, | |
16025 | NULL, | |
16026 | CATCH_PERMANENT, | |
16027 | CATCH_TEMPORARY); | |
16028 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16029 | Usage: catch unload [REGEX]\n\ | |
16030 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16031 | catch_unload_command_1, | |
16032 | NULL, | |
16033 | CATCH_PERMANENT, | |
16034 | CATCH_TEMPORARY); | |
c5aa993b | 16035 | |
1bedd215 AC |
16036 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16037 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16038 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16039 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16040 | an expression changes.\n\ |
16041 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16042 | the memory to which it refers.")); | |
65d12d83 | 16043 | set_cmd_completer (c, expression_completer); |
c906108c | 16044 | |
1bedd215 AC |
16045 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16046 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16047 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16048 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16049 | an expression is read.\n\ |
16050 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16051 | the memory to which it refers.")); | |
65d12d83 | 16052 | set_cmd_completer (c, expression_completer); |
c906108c | 16053 | |
1bedd215 AC |
16054 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16055 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16056 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16057 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16058 | an expression is either read or written.\n\ |
16059 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16060 | the memory to which it refers.")); | |
65d12d83 | 16061 | set_cmd_completer (c, expression_completer); |
c906108c | 16062 | |
d77f58be | 16063 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16064 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16065 | |
920d2a44 AC |
16066 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16067 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16068 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16069 | &can_use_hw_watchpoints, _("\ | |
16070 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16071 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16072 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16073 | such is available. (However, any hardware watchpoints that were\n\ | |
16074 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16075 | hardware.)"), |
16076 | NULL, | |
920d2a44 | 16077 | show_can_use_hw_watchpoints, |
85c07804 | 16078 | &setlist, &showlist); |
c906108c SS |
16079 | |
16080 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16081 | |
1042e4c0 SS |
16082 | /* Tracepoint manipulation commands. */ |
16083 | ||
16084 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
16085 | Set a tracepoint at specified line or function.\n\ | |
16086 | \n" | |
16087 | BREAK_ARGS_HELP ("trace") "\n\ | |
16088 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16089 | set_cmd_completer (c, location_completer); | |
16090 | ||
16091 | add_com_alias ("tp", "trace", class_alias, 0); | |
16092 | add_com_alias ("tr", "trace", class_alias, 1); | |
16093 | add_com_alias ("tra", "trace", class_alias, 1); | |
16094 | add_com_alias ("trac", "trace", class_alias, 1); | |
16095 | ||
7a697b8d SS |
16096 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
16097 | Set a fast tracepoint at specified line or function.\n\ | |
16098 | \n" | |
16099 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16100 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16101 | set_cmd_completer (c, location_completer); | |
16102 | ||
0fb4aa4b PA |
16103 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
16104 | Set a static tracepoint at specified line, function or marker.\n\ | |
16105 | \n\ | |
16106 | strace [LOCATION] [if CONDITION]\n\ | |
16107 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
16108 | or -m MARKER_ID.\n\ | |
16109 | If a line number is specified, probe the marker at start of code\n\ | |
16110 | for that line. If a function is specified, probe the marker at start\n\ | |
16111 | of code for that function. If an address is specified, probe the marker\n\ | |
16112 | at that exact address. If a marker id is specified, probe the marker\n\ | |
16113 | with that name. With no LOCATION, uses current execution address of\n\ | |
16114 | the selected stack frame.\n\ | |
16115 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
16116 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16117 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16118 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16119 | \n\ | |
16120 | CONDITION is a boolean expression.\n\ | |
16121 | \n\ | |
d41c0fc8 PA |
16122 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16123 | conditions are different.\n\ | |
0fb4aa4b PA |
16124 | \n\ |
16125 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16126 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16127 | set_cmd_completer (c, location_completer); | |
16128 | ||
1042e4c0 | 16129 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16130 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16131 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16132 | last tracepoint set.")); | |
16133 | ||
16134 | add_info_alias ("tp", "tracepoints", 1); | |
16135 | ||
16136 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16137 | Delete specified tracepoints.\n\ | |
16138 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16139 | No argument means delete all tracepoints."), | |
16140 | &deletelist); | |
7e20dfcd | 16141 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16142 | |
16143 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16144 | Disable specified tracepoints.\n\ | |
16145 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16146 | No argument means disable all tracepoints."), | |
16147 | &disablelist); | |
16148 | deprecate_cmd (c, "disable"); | |
16149 | ||
16150 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16151 | Enable specified tracepoints.\n\ | |
16152 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16153 | No argument means enable all tracepoints."), | |
16154 | &enablelist); | |
16155 | deprecate_cmd (c, "enable"); | |
16156 | ||
16157 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16158 | Set the passcount for a tracepoint.\n\ | |
16159 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16160 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16161 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16162 | ||
6149aea9 PA |
16163 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16164 | _("Save breakpoint definitions as a script."), | |
16165 | &save_cmdlist, "save ", | |
16166 | 0/*allow-unknown*/, &cmdlist); | |
16167 | ||
16168 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16169 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16170 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16171 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16172 | session to restore them."), | |
16173 | &save_cmdlist); | |
16174 | set_cmd_completer (c, filename_completer); | |
16175 | ||
16176 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16177 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16178 | Use the 'source' command in another debug session to restore them."), |
16179 | &save_cmdlist); | |
1042e4c0 SS |
16180 | set_cmd_completer (c, filename_completer); |
16181 | ||
6149aea9 PA |
16182 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16183 | deprecate_cmd (c, "save tracepoints"); | |
16184 | ||
1bedd215 | 16185 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16186 | Breakpoint specific settings\n\ |
16187 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16188 | pending breakpoint behavior"), |
fa8d40ab JJ |
16189 | &breakpoint_set_cmdlist, "set breakpoint ", |
16190 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16191 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16192 | Breakpoint specific settings\n\ |
16193 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16194 | pending breakpoint behavior"), |
fa8d40ab JJ |
16195 | &breakpoint_show_cmdlist, "show breakpoint ", |
16196 | 0/*allow-unknown*/, &showlist); | |
16197 | ||
7915a72c AC |
16198 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16199 | &pending_break_support, _("\ | |
16200 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16201 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16202 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16203 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16204 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16205 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16206 | NULL, |
920d2a44 | 16207 | show_pending_break_support, |
6e1d7d6c AC |
16208 | &breakpoint_set_cmdlist, |
16209 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16210 | |
16211 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16212 | |
16213 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16214 | &automatic_hardware_breakpoints, _("\ | |
16215 | Set automatic usage of hardware breakpoints."), _("\ | |
16216 | Show automatic usage of hardware breakpoints."), _("\ | |
16217 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16218 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16219 | a warning will be emitted for such breakpoints."), | |
16220 | NULL, | |
16221 | show_automatic_hardware_breakpoints, | |
16222 | &breakpoint_set_cmdlist, | |
16223 | &breakpoint_show_cmdlist); | |
74960c60 | 16224 | |
a25a5a45 PA |
16225 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16226 | &always_inserted_mode, _("\ | |
74960c60 VP |
16227 | Set mode for inserting breakpoints."), _("\ |
16228 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16229 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16230 | they're created, kept inserted even when execution stops, and removed\n\ | |
16231 | only when the user deletes them. When this mode is off (the default),\n\ | |
16232 | breakpoints are inserted only when execution continues, and removed\n\ | |
16233 | when execution stops."), | |
72d0e2c5 YQ |
16234 | NULL, |
16235 | &show_always_inserted_mode, | |
16236 | &breakpoint_set_cmdlist, | |
16237 | &breakpoint_show_cmdlist); | |
f1310107 | 16238 | |
b775012e LM |
16239 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16240 | condition_evaluation_enums, | |
16241 | &condition_evaluation_mode_1, _("\ | |
16242 | Set mode of breakpoint condition evaluation."), _("\ | |
16243 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16244 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16245 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16246 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16247 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16248 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16249 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16250 | be set to \"gdb\""), | |
16251 | &set_condition_evaluation_mode, | |
16252 | &show_condition_evaluation_mode, | |
16253 | &breakpoint_set_cmdlist, | |
16254 | &breakpoint_show_cmdlist); | |
16255 | ||
f1310107 TJB |
16256 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16257 | Set a breakpoint for an address range.\n\ | |
16258 | break-range START-LOCATION, END-LOCATION\n\ | |
16259 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16260 | LINENUM, for that line in the current file,\n\ | |
16261 | FILE:LINENUM, for that line in that file,\n\ | |
16262 | +OFFSET, for that number of lines after the current line\n\ | |
16263 | or the start of the range\n\ | |
16264 | FUNCTION, for the first line in that function,\n\ | |
16265 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16266 | *ADDRESS, for the instruction at that address.\n\ | |
16267 | \n\ | |
16268 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16269 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16270 | range (including START-LOCATION and END-LOCATION).")); | |
16271 | ||
e7e0cddf SS |
16272 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
16273 | Set a dynamic printf at specified line or function.\n\ | |
16274 | dprintf location,format string,arg1,arg2,...\n\ | |
16275 | location may be a line number, function name, or \"*\" and an address.\n\ | |
16276 | If a line number is specified, break at start of code for that line.\n\ | |
0e4777df | 16277 | If a function is specified, break at start of code for that function.")); |
e7e0cddf SS |
16278 | set_cmd_completer (c, location_completer); |
16279 | ||
16280 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16281 | dprintf_style_enums, &dprintf_style, _("\ | |
16282 | Set the style of usage for dynamic printf."), _("\ | |
16283 | Show the style of usage for dynamic printf."), _("\ | |
16284 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16285 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16286 | console, as with the \"printf\" command.\n\ | |
16287 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16288 | program; by default printf(), but you can choose a different function or\n\ | |
16289 | output stream by setting dprintf-function and dprintf-channel."), | |
16290 | update_dprintf_commands, NULL, | |
16291 | &setlist, &showlist); | |
16292 | ||
16293 | dprintf_function = xstrdup ("printf"); | |
16294 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16295 | &dprintf_function, _("\ | |
16296 | Set the function to use for dynamic printf"), _("\ | |
16297 | Show the function to use for dynamic printf"), NULL, | |
16298 | update_dprintf_commands, NULL, | |
16299 | &setlist, &showlist); | |
16300 | ||
16301 | dprintf_channel = xstrdup (""); | |
16302 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16303 | &dprintf_channel, _("\ | |
16304 | Set the channel to use for dynamic printf"), _("\ | |
16305 | Show the channel to use for dynamic printf"), NULL, | |
16306 | update_dprintf_commands, NULL, | |
16307 | &setlist, &showlist); | |
16308 | ||
d3ce09f5 SS |
16309 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16310 | &disconnected_dprintf, _("\ | |
16311 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16312 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16313 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16314 | even if GDB disconnects or detaches from the target."), | |
16315 | NULL, | |
16316 | NULL, | |
16317 | &setlist, &showlist); | |
16318 | ||
16319 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16320 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16321 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16322 | ||
765dc015 | 16323 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16324 | |
16325 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16326 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16327 | } |