Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
32d0add0 | 3 | Copyright (C) 1986-2015 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
45741a9c | 35 | #include "infrun.h" |
c906108c SS |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
38 | #include "language.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
fe898f56 | 50 | #include "block.h" |
a77053c2 | 51 | #include "solib.h" |
84acb35a JJ |
52 | #include "solist.h" |
53 | #include "observer.h" | |
765dc015 | 54 | #include "memattr.h" |
f7f9143b | 55 | #include "ada-lang.h" |
d1aa2f50 | 56 | #include "top.h" |
79a45b7d | 57 | #include "valprint.h" |
4efc6507 | 58 | #include "jit.h" |
65d79d4b | 59 | #include "parser-defs.h" |
55aa24fb SDJ |
60 | #include "gdb_regex.h" |
61 | #include "probe.h" | |
e9cafbcc | 62 | #include "cli/cli-utils.h" |
be34f849 | 63 | #include "continuations.h" |
1bfeeb0f JL |
64 | #include "stack.h" |
65 | #include "skip.h" | |
b775012e | 66 | #include "ax-gdb.h" |
e2e4d78b | 67 | #include "dummy-frame.h" |
5589af0e | 68 | #include "interps.h" |
d3ce09f5 | 69 | #include "format.h" |
f00aae0f | 70 | #include "location.h" |
d3ce09f5 | 71 | |
1042e4c0 SS |
72 | /* readline include files */ |
73 | #include "readline/readline.h" | |
74 | #include "readline/history.h" | |
75 | ||
76 | /* readline defines this. */ | |
77 | #undef savestring | |
78 | ||
034dad6f | 79 | #include "mi/mi-common.h" |
6dddc817 | 80 | #include "extension.h" |
104c1213 | 81 | |
e7e8980f YQ |
82 | /* Enums for exception-handling support. */ |
83 | enum exception_event_kind | |
84 | { | |
85 | EX_EVENT_THROW, | |
591f19e8 | 86 | EX_EVENT_RETHROW, |
e7e8980f YQ |
87 | EX_EVENT_CATCH |
88 | }; | |
89 | ||
4a64f543 | 90 | /* Prototypes for local functions. */ |
c906108c | 91 | |
a14ed312 | 92 | static void enable_delete_command (char *, int); |
c906108c | 93 | |
a14ed312 | 94 | static void enable_once_command (char *, int); |
c906108c | 95 | |
816338b5 SS |
96 | static void enable_count_command (char *, int); |
97 | ||
a14ed312 | 98 | static void disable_command (char *, int); |
c906108c | 99 | |
a14ed312 | 100 | static void enable_command (char *, int); |
c906108c | 101 | |
95a42b64 TT |
102 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
103 | void *), | |
104 | void *); | |
c906108c | 105 | |
a14ed312 | 106 | static void ignore_command (char *, int); |
c906108c | 107 | |
4efb68b1 | 108 | static int breakpoint_re_set_one (void *); |
c906108c | 109 | |
348d480f PA |
110 | static void breakpoint_re_set_default (struct breakpoint *); |
111 | ||
f00aae0f KS |
112 | static void |
113 | create_sals_from_location_default (const struct event_location *location, | |
114 | struct linespec_result *canonical, | |
115 | enum bptype type_wanted); | |
983af33b SDJ |
116 | |
117 | static void create_breakpoints_sal_default (struct gdbarch *, | |
118 | struct linespec_result *, | |
e7e0cddf | 119 | char *, char *, enum bptype, |
983af33b SDJ |
120 | enum bpdisp, int, int, |
121 | int, | |
122 | const struct breakpoint_ops *, | |
44f238bb | 123 | int, int, int, unsigned); |
983af33b | 124 | |
f00aae0f KS |
125 | static void decode_location_default (struct breakpoint *b, |
126 | const struct event_location *location, | |
127 | struct symtabs_and_lines *sals); | |
983af33b | 128 | |
a14ed312 | 129 | static void clear_command (char *, int); |
c906108c | 130 | |
a14ed312 | 131 | static void catch_command (char *, int); |
c906108c | 132 | |
a9634178 | 133 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 134 | |
98deb0da | 135 | static void break_command_1 (char *, int, int); |
c906108c | 136 | |
a14ed312 | 137 | static void mention (struct breakpoint *); |
c906108c | 138 | |
348d480f PA |
139 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
140 | enum bptype, | |
c0a91b2b | 141 | const struct breakpoint_ops *); |
3742cc8b YQ |
142 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
143 | const struct symtab_and_line *); | |
144 | ||
4a64f543 MS |
145 | /* This function is used in gdbtk sources and thus can not be made |
146 | static. */ | |
63c252f8 | 147 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 148 | struct symtab_and_line, |
c0a91b2b TT |
149 | enum bptype, |
150 | const struct breakpoint_ops *); | |
c906108c | 151 | |
06edf0c0 PA |
152 | static struct breakpoint * |
153 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
154 | enum bptype type, | |
a1aa2221 LM |
155 | const struct breakpoint_ops *ops, |
156 | int loc_enabled); | |
06edf0c0 | 157 | |
76897487 KB |
158 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
159 | ||
a6d9a66e UW |
160 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
161 | CORE_ADDR bpaddr, | |
88f7da05 | 162 | enum bptype bptype); |
76897487 | 163 | |
6c95b8df PA |
164 | static void describe_other_breakpoints (struct gdbarch *, |
165 | struct program_space *, CORE_ADDR, | |
5af949e3 | 166 | struct obj_section *, int); |
c906108c | 167 | |
85d721b8 PA |
168 | static int watchpoint_locations_match (struct bp_location *loc1, |
169 | struct bp_location *loc2); | |
170 | ||
f1310107 TJB |
171 | static int breakpoint_location_address_match (struct bp_location *bl, |
172 | struct address_space *aspace, | |
173 | CORE_ADDR addr); | |
174 | ||
a14ed312 | 175 | static void breakpoints_info (char *, int); |
c906108c | 176 | |
d77f58be SS |
177 | static void watchpoints_info (char *, int); |
178 | ||
e5a67952 MS |
179 | static int breakpoint_1 (char *, int, |
180 | int (*) (const struct breakpoint *)); | |
c906108c | 181 | |
4efb68b1 | 182 | static int breakpoint_cond_eval (void *); |
c906108c | 183 | |
4efb68b1 | 184 | static void cleanup_executing_breakpoints (void *); |
c906108c | 185 | |
a14ed312 | 186 | static void commands_command (char *, int); |
c906108c | 187 | |
a14ed312 | 188 | static void condition_command (char *, int); |
c906108c | 189 | |
c5aa993b JM |
190 | typedef enum |
191 | { | |
192 | mark_inserted, | |
193 | mark_uninserted | |
194 | } | |
195 | insertion_state_t; | |
c906108c | 196 | |
0bde7532 | 197 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 198 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 199 | |
e514a9d6 | 200 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 201 | |
4efb68b1 | 202 | static int watchpoint_check (void *); |
c906108c | 203 | |
a14ed312 | 204 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 205 | |
a14ed312 | 206 | static int hw_breakpoint_used_count (void); |
c906108c | 207 | |
a1398e0c PA |
208 | static int hw_watchpoint_use_count (struct breakpoint *); |
209 | ||
210 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
211 | enum bptype type, | |
212 | int *other_type_used); | |
c906108c | 213 | |
a14ed312 | 214 | static void hbreak_command (char *, int); |
c906108c | 215 | |
a14ed312 | 216 | static void thbreak_command (char *, int); |
c906108c | 217 | |
816338b5 SS |
218 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
219 | int count); | |
c906108c | 220 | |
a14ed312 | 221 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 222 | |
a14ed312 | 223 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 224 | |
a14ed312 | 225 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 226 | |
a14ed312 | 227 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 228 | |
fe3f5fa8 | 229 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
230 | static void incref_bp_location (struct bp_location *loc); |
231 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 232 | |
39d61571 | 233 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 234 | |
44702360 PA |
235 | /* update_global_location_list's modes of operation wrt to whether to |
236 | insert locations now. */ | |
237 | enum ugll_insert_mode | |
238 | { | |
239 | /* Don't insert any breakpoint locations into the inferior, only | |
240 | remove already-inserted locations that no longer should be | |
241 | inserted. Functions that delete a breakpoint or breakpoints | |
242 | should specify this mode, so that deleting a breakpoint doesn't | |
243 | have the side effect of inserting the locations of other | |
244 | breakpoints that are marked not-inserted, but should_be_inserted | |
245 | returns true on them. | |
246 | ||
247 | This behavior is useful is situations close to tear-down -- e.g., | |
248 | after an exec, while the target still has execution, but | |
249 | breakpoint shadows of the previous executable image should *NOT* | |
250 | be restored to the new image; or before detaching, where the | |
251 | target still has execution and wants to delete breakpoints from | |
252 | GDB's lists, and all breakpoints had already been removed from | |
253 | the inferior. */ | |
254 | UGLL_DONT_INSERT, | |
255 | ||
a25a5a45 PA |
256 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
257 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
258 | UGLL_MAY_INSERT, |
259 | ||
a25a5a45 PA |
260 | /* Insert locations now, irrespective of |
261 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
262 | stopped right now, and the user did "continue". We need to | |
263 | insert breakpoints _before_ resuming the target, but | |
264 | UGLL_MAY_INSERT wouldn't insert them, because | |
265 | breakpoints_should_be_inserted_now returns false at that point, | |
266 | as no thread is running yet. */ | |
04086b45 | 267 | UGLL_INSERT |
44702360 PA |
268 | }; |
269 | ||
270 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 271 | |
44702360 | 272 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 273 | |
d77f58be | 274 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
275 | |
276 | static void insert_breakpoint_locations (void); | |
a5606eee | 277 | |
1042e4c0 SS |
278 | static void tracepoints_info (char *, int); |
279 | ||
280 | static void delete_trace_command (char *, int); | |
281 | ||
282 | static void enable_trace_command (char *, int); | |
283 | ||
284 | static void disable_trace_command (char *, int); | |
285 | ||
286 | static void trace_pass_command (char *, int); | |
287 | ||
558a9d82 YQ |
288 | static void set_tracepoint_count (int num); |
289 | ||
9c06b0b4 TJB |
290 | static int is_masked_watchpoint (const struct breakpoint *b); |
291 | ||
b775012e LM |
292 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
293 | ||
983af33b SDJ |
294 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
295 | otherwise. */ | |
296 | ||
297 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 298 | |
2060206e PA |
299 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
300 | that are implemented on top of software or hardware breakpoints | |
301 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
302 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
303 | ||
304 | /* Internal breakpoints class type. */ | |
06edf0c0 | 305 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
306 | |
307 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
308 | static struct breakpoint_ops momentary_breakpoint_ops; |
309 | ||
e2e4d78b JK |
310 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
311 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
312 | ||
2060206e PA |
313 | /* The breakpoint_ops structure to be used in regular user created |
314 | breakpoints. */ | |
315 | struct breakpoint_ops bkpt_breakpoint_ops; | |
316 | ||
55aa24fb SDJ |
317 | /* Breakpoints set on probes. */ |
318 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
319 | ||
e7e0cddf | 320 | /* Dynamic printf class type. */ |
c5867ab6 | 321 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 322 | |
d3ce09f5 SS |
323 | /* The style in which to perform a dynamic printf. This is a user |
324 | option because different output options have different tradeoffs; | |
325 | if GDB does the printing, there is better error handling if there | |
326 | is a problem with any of the arguments, but using an inferior | |
327 | function lets you have special-purpose printers and sending of | |
328 | output to the same place as compiled-in print functions. */ | |
329 | ||
330 | static const char dprintf_style_gdb[] = "gdb"; | |
331 | static const char dprintf_style_call[] = "call"; | |
332 | static const char dprintf_style_agent[] = "agent"; | |
333 | static const char *const dprintf_style_enums[] = { | |
334 | dprintf_style_gdb, | |
335 | dprintf_style_call, | |
336 | dprintf_style_agent, | |
337 | NULL | |
338 | }; | |
339 | static const char *dprintf_style = dprintf_style_gdb; | |
340 | ||
341 | /* The function to use for dynamic printf if the preferred style is to | |
342 | call into the inferior. The value is simply a string that is | |
343 | copied into the command, so it can be anything that GDB can | |
344 | evaluate to a callable address, not necessarily a function name. */ | |
345 | ||
346 | static char *dprintf_function = ""; | |
347 | ||
348 | /* The channel to use for dynamic printf if the preferred style is to | |
349 | call into the inferior; if a nonempty string, it will be passed to | |
350 | the call as the first argument, with the format string as the | |
351 | second. As with the dprintf function, this can be anything that | |
352 | GDB knows how to evaluate, so in addition to common choices like | |
353 | "stderr", this could be an app-specific expression like | |
354 | "mystreams[curlogger]". */ | |
355 | ||
356 | static char *dprintf_channel = ""; | |
357 | ||
358 | /* True if dprintf commands should continue to operate even if GDB | |
359 | has disconnected. */ | |
360 | static int disconnected_dprintf = 1; | |
361 | ||
5cea2a26 PA |
362 | /* A reference-counted struct command_line. This lets multiple |
363 | breakpoints share a single command list. */ | |
364 | struct counted_command_line | |
365 | { | |
366 | /* The reference count. */ | |
367 | int refc; | |
368 | ||
369 | /* The command list. */ | |
370 | struct command_line *commands; | |
371 | }; | |
372 | ||
373 | struct command_line * | |
374 | breakpoint_commands (struct breakpoint *b) | |
375 | { | |
376 | return b->commands ? b->commands->commands : NULL; | |
377 | } | |
3daf8fe5 | 378 | |
f3b1572e PA |
379 | /* Flag indicating that a command has proceeded the inferior past the |
380 | current breakpoint. */ | |
381 | ||
382 | static int breakpoint_proceeded; | |
383 | ||
956a9fb9 | 384 | const char * |
2cec12e5 AR |
385 | bpdisp_text (enum bpdisp disp) |
386 | { | |
4a64f543 MS |
387 | /* NOTE: the following values are a part of MI protocol and |
388 | represent values of 'disp' field returned when inferior stops at | |
389 | a breakpoint. */ | |
bc043ef3 | 390 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 391 | |
2cec12e5 AR |
392 | return bpdisps[(int) disp]; |
393 | } | |
c906108c | 394 | |
4a64f543 | 395 | /* Prototypes for exported functions. */ |
c906108c | 396 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 397 | if such is available. */ |
c906108c SS |
398 | static int can_use_hw_watchpoints; |
399 | ||
920d2a44 AC |
400 | static void |
401 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
402 | struct cmd_list_element *c, | |
403 | const char *value) | |
404 | { | |
3e43a32a MS |
405 | fprintf_filtered (file, |
406 | _("Debugger's willingness to use " | |
407 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
408 | value); |
409 | } | |
410 | ||
fa8d40ab JJ |
411 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
412 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 413 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
414 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
415 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
416 | static void |
417 | show_pending_break_support (struct ui_file *file, int from_tty, | |
418 | struct cmd_list_element *c, | |
419 | const char *value) | |
420 | { | |
3e43a32a MS |
421 | fprintf_filtered (file, |
422 | _("Debugger's behavior regarding " | |
423 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
424 | value); |
425 | } | |
fa8d40ab | 426 | |
765dc015 | 427 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 428 | set with "break" but falling in read-only memory. |
765dc015 VP |
429 | If 0, gdb will warn about such breakpoints, but won't automatically |
430 | use hardware breakpoints. */ | |
431 | static int automatic_hardware_breakpoints; | |
432 | static void | |
433 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
434 | struct cmd_list_element *c, | |
435 | const char *value) | |
436 | { | |
3e43a32a MS |
437 | fprintf_filtered (file, |
438 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
439 | value); |
440 | } | |
441 | ||
a25a5a45 PA |
442 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
443 | stopped, and immediately inserts any new breakpoints as soon as | |
444 | they're created. If off (default), GDB keeps breakpoints off of | |
445 | the target as long as possible. That is, it delays inserting | |
446 | breakpoints until the next resume, and removes them again when the | |
447 | target fully stops. This is a bit safer in case GDB crashes while | |
448 | processing user input. */ | |
449 | static int always_inserted_mode = 0; | |
72d0e2c5 | 450 | |
33e5cbd6 | 451 | static void |
74960c60 | 452 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 453 | struct cmd_list_element *c, const char *value) |
74960c60 | 454 | { |
a25a5a45 PA |
455 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
456 | value); | |
74960c60 VP |
457 | } |
458 | ||
b57bacec PA |
459 | /* See breakpoint.h. */ |
460 | ||
33e5cbd6 | 461 | int |
a25a5a45 | 462 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 463 | { |
a25a5a45 PA |
464 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
465 | { | |
466 | /* If breakpoints are global, they should be inserted even if no | |
467 | thread under gdb's control is running, or even if there are | |
468 | no threads under GDB's control yet. */ | |
469 | return 1; | |
470 | } | |
471 | else if (target_has_execution) | |
472 | { | |
372316f1 PA |
473 | struct thread_info *tp; |
474 | ||
a25a5a45 PA |
475 | if (always_inserted_mode) |
476 | { | |
477 | /* The user wants breakpoints inserted even if all threads | |
478 | are stopped. */ | |
479 | return 1; | |
480 | } | |
481 | ||
b57bacec PA |
482 | if (threads_are_executing ()) |
483 | return 1; | |
372316f1 PA |
484 | |
485 | /* Don't remove breakpoints yet if, even though all threads are | |
486 | stopped, we still have events to process. */ | |
487 | ALL_NON_EXITED_THREADS (tp) | |
488 | if (tp->resumed | |
489 | && tp->suspend.waitstatus_pending_p) | |
490 | return 1; | |
a25a5a45 PA |
491 | } |
492 | return 0; | |
33e5cbd6 | 493 | } |
765dc015 | 494 | |
b775012e LM |
495 | static const char condition_evaluation_both[] = "host or target"; |
496 | ||
497 | /* Modes for breakpoint condition evaluation. */ | |
498 | static const char condition_evaluation_auto[] = "auto"; | |
499 | static const char condition_evaluation_host[] = "host"; | |
500 | static const char condition_evaluation_target[] = "target"; | |
501 | static const char *const condition_evaluation_enums[] = { | |
502 | condition_evaluation_auto, | |
503 | condition_evaluation_host, | |
504 | condition_evaluation_target, | |
505 | NULL | |
506 | }; | |
507 | ||
508 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
509 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
510 | ||
511 | /* Global that we use to display information to the user (gets its value from | |
512 | condition_evaluation_mode_1. */ | |
513 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
514 | ||
515 | /* Translate a condition evaluation mode MODE into either "host" | |
516 | or "target". This is used mostly to translate from "auto" to the | |
517 | real setting that is being used. It returns the translated | |
518 | evaluation mode. */ | |
519 | ||
520 | static const char * | |
521 | translate_condition_evaluation_mode (const char *mode) | |
522 | { | |
523 | if (mode == condition_evaluation_auto) | |
524 | { | |
525 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
526 | return condition_evaluation_target; | |
527 | else | |
528 | return condition_evaluation_host; | |
529 | } | |
530 | else | |
531 | return mode; | |
532 | } | |
533 | ||
534 | /* Discovers what condition_evaluation_auto translates to. */ | |
535 | ||
536 | static const char * | |
537 | breakpoint_condition_evaluation_mode (void) | |
538 | { | |
539 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
540 | } | |
541 | ||
542 | /* Return true if GDB should evaluate breakpoint conditions or false | |
543 | otherwise. */ | |
544 | ||
545 | static int | |
546 | gdb_evaluates_breakpoint_condition_p (void) | |
547 | { | |
548 | const char *mode = breakpoint_condition_evaluation_mode (); | |
549 | ||
550 | return (mode == condition_evaluation_host); | |
551 | } | |
552 | ||
a14ed312 | 553 | void _initialize_breakpoint (void); |
c906108c | 554 | |
c906108c SS |
555 | /* Are we executing breakpoint commands? */ |
556 | static int executing_breakpoint_commands; | |
557 | ||
c02f5703 MS |
558 | /* Are overlay event breakpoints enabled? */ |
559 | static int overlay_events_enabled; | |
560 | ||
e09342b5 TJB |
561 | /* See description in breakpoint.h. */ |
562 | int target_exact_watchpoints = 0; | |
563 | ||
c906108c | 564 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 565 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 566 | current breakpoint. */ |
c906108c | 567 | |
5c44784c | 568 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 569 | |
5c44784c JM |
570 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
571 | for (B = breakpoint_chain; \ | |
572 | B ? (TMP=B->next, 1): 0; \ | |
573 | B = TMP) | |
c906108c | 574 | |
4a64f543 MS |
575 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
576 | not provided so update_global_location_list must not be called | |
577 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 578 | |
876fa593 JK |
579 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
580 | for (BP_TMP = bp_location; \ | |
581 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
582 | BP_TMP++) | |
7cc221ef | 583 | |
b775012e LM |
584 | /* Iterates through locations with address ADDRESS for the currently selected |
585 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
586 | to where the loop should start from. | |
587 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
588 | appropriate location to start with. */ | |
589 | ||
590 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
591 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
592 | BP_LOCP_TMP = BP_LOCP_START; \ | |
593 | BP_LOCP_START \ | |
594 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
595 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
596 | BP_LOCP_TMP++) | |
597 | ||
1042e4c0 SS |
598 | /* Iterator for tracepoints only. */ |
599 | ||
600 | #define ALL_TRACEPOINTS(B) \ | |
601 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 602 | if (is_tracepoint (B)) |
1042e4c0 | 603 | |
7cc221ef | 604 | /* Chains of all breakpoints defined. */ |
c906108c SS |
605 | |
606 | struct breakpoint *breakpoint_chain; | |
607 | ||
876fa593 JK |
608 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
609 | ||
610 | static struct bp_location **bp_location; | |
611 | ||
612 | /* Number of elements of BP_LOCATION. */ | |
613 | ||
614 | static unsigned bp_location_count; | |
615 | ||
4a64f543 MS |
616 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
617 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
618 | result from bp_location_has_shadow. You can use it for roughly | |
619 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
620 | an address you need to read. */ | |
876fa593 JK |
621 | |
622 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
623 | ||
4a64f543 MS |
624 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
625 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
626 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
627 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
628 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
629 | |
630 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 631 | |
4a64f543 MS |
632 | /* The locations that no longer correspond to any breakpoint, unlinked |
633 | from bp_location array, but for which a hit may still be reported | |
634 | by a target. */ | |
20874c92 VP |
635 | VEC(bp_location_p) *moribund_locations = NULL; |
636 | ||
c906108c SS |
637 | /* Number of last breakpoint made. */ |
638 | ||
95a42b64 TT |
639 | static int breakpoint_count; |
640 | ||
86b17b60 PA |
641 | /* The value of `breakpoint_count' before the last command that |
642 | created breakpoints. If the last (break-like) command created more | |
643 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
644 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
645 | static int prev_breakpoint_count; | |
c906108c | 646 | |
1042e4c0 SS |
647 | /* Number of last tracepoint made. */ |
648 | ||
95a42b64 | 649 | static int tracepoint_count; |
1042e4c0 | 650 | |
6149aea9 PA |
651 | static struct cmd_list_element *breakpoint_set_cmdlist; |
652 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 653 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 654 | |
badd37ce SDJ |
655 | /* See declaration at breakpoint.h. */ |
656 | ||
657 | struct breakpoint * | |
658 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
659 | void *user_data) | |
660 | { | |
661 | struct breakpoint *b = NULL; | |
662 | ||
663 | ALL_BREAKPOINTS (b) | |
664 | { | |
665 | if (func (b, user_data) != 0) | |
666 | break; | |
667 | } | |
668 | ||
669 | return b; | |
670 | } | |
671 | ||
468d015d JJ |
672 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
673 | static int | |
674 | breakpoint_enabled (struct breakpoint *b) | |
675 | { | |
0d381245 | 676 | return (b->enable_state == bp_enabled); |
468d015d JJ |
677 | } |
678 | ||
c906108c SS |
679 | /* Set breakpoint count to NUM. */ |
680 | ||
95a42b64 | 681 | static void |
fba45db2 | 682 | set_breakpoint_count (int num) |
c906108c | 683 | { |
86b17b60 | 684 | prev_breakpoint_count = breakpoint_count; |
c906108c | 685 | breakpoint_count = num; |
4fa62494 | 686 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
687 | } |
688 | ||
86b17b60 PA |
689 | /* Used by `start_rbreak_breakpoints' below, to record the current |
690 | breakpoint count before "rbreak" creates any breakpoint. */ | |
691 | static int rbreak_start_breakpoint_count; | |
692 | ||
95a42b64 TT |
693 | /* Called at the start an "rbreak" command to record the first |
694 | breakpoint made. */ | |
86b17b60 | 695 | |
95a42b64 TT |
696 | void |
697 | start_rbreak_breakpoints (void) | |
698 | { | |
86b17b60 | 699 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
700 | } |
701 | ||
702 | /* Called at the end of an "rbreak" command to record the last | |
703 | breakpoint made. */ | |
86b17b60 | 704 | |
95a42b64 TT |
705 | void |
706 | end_rbreak_breakpoints (void) | |
707 | { | |
86b17b60 | 708 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
709 | } |
710 | ||
4a64f543 | 711 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
712 | |
713 | void | |
fba45db2 | 714 | clear_breakpoint_hit_counts (void) |
c906108c SS |
715 | { |
716 | struct breakpoint *b; | |
717 | ||
718 | ALL_BREAKPOINTS (b) | |
719 | b->hit_count = 0; | |
720 | } | |
721 | ||
9add0f1b TT |
722 | /* Allocate a new counted_command_line with reference count of 1. |
723 | The new structure owns COMMANDS. */ | |
724 | ||
725 | static struct counted_command_line * | |
726 | alloc_counted_command_line (struct command_line *commands) | |
727 | { | |
728 | struct counted_command_line *result | |
729 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 730 | |
9add0f1b TT |
731 | result->refc = 1; |
732 | result->commands = commands; | |
733 | return result; | |
734 | } | |
735 | ||
736 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
737 | ||
738 | static void | |
739 | incref_counted_command_line (struct counted_command_line *cmd) | |
740 | { | |
741 | if (cmd) | |
742 | ++cmd->refc; | |
743 | } | |
744 | ||
745 | /* Decrement reference count. If the reference count reaches 0, | |
746 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
747 | nothing if *CMDP is NULL. */ | |
748 | ||
749 | static void | |
750 | decref_counted_command_line (struct counted_command_line **cmdp) | |
751 | { | |
752 | if (*cmdp) | |
753 | { | |
754 | if (--(*cmdp)->refc == 0) | |
755 | { | |
756 | free_command_lines (&(*cmdp)->commands); | |
757 | xfree (*cmdp); | |
758 | } | |
759 | *cmdp = NULL; | |
760 | } | |
761 | } | |
762 | ||
763 | /* A cleanup function that calls decref_counted_command_line. */ | |
764 | ||
765 | static void | |
766 | do_cleanup_counted_command_line (void *arg) | |
767 | { | |
768 | decref_counted_command_line (arg); | |
769 | } | |
770 | ||
771 | /* Create a cleanup that calls decref_counted_command_line on the | |
772 | argument. */ | |
773 | ||
774 | static struct cleanup * | |
775 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
776 | { | |
777 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
778 | } | |
779 | ||
c906108c | 780 | \f |
48cb2d85 VP |
781 | /* Return the breakpoint with the specified number, or NULL |
782 | if the number does not refer to an existing breakpoint. */ | |
783 | ||
784 | struct breakpoint * | |
785 | get_breakpoint (int num) | |
786 | { | |
787 | struct breakpoint *b; | |
788 | ||
789 | ALL_BREAKPOINTS (b) | |
790 | if (b->number == num) | |
791 | return b; | |
792 | ||
793 | return NULL; | |
794 | } | |
5c44784c | 795 | |
c906108c | 796 | \f |
adc36818 | 797 | |
b775012e LM |
798 | /* Mark locations as "conditions have changed" in case the target supports |
799 | evaluating conditions on its side. */ | |
800 | ||
801 | static void | |
802 | mark_breakpoint_modified (struct breakpoint *b) | |
803 | { | |
804 | struct bp_location *loc; | |
805 | ||
806 | /* This is only meaningful if the target is | |
807 | evaluating conditions and if the user has | |
808 | opted for condition evaluation on the target's | |
809 | side. */ | |
810 | if (gdb_evaluates_breakpoint_condition_p () | |
811 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
812 | return; | |
813 | ||
814 | if (!is_breakpoint (b)) | |
815 | return; | |
816 | ||
817 | for (loc = b->loc; loc; loc = loc->next) | |
818 | loc->condition_changed = condition_modified; | |
819 | } | |
820 | ||
821 | /* Mark location as "conditions have changed" in case the target supports | |
822 | evaluating conditions on its side. */ | |
823 | ||
824 | static void | |
825 | mark_breakpoint_location_modified (struct bp_location *loc) | |
826 | { | |
827 | /* This is only meaningful if the target is | |
828 | evaluating conditions and if the user has | |
829 | opted for condition evaluation on the target's | |
830 | side. */ | |
831 | if (gdb_evaluates_breakpoint_condition_p () | |
832 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
833 | ||
834 | return; | |
835 | ||
836 | if (!is_breakpoint (loc->owner)) | |
837 | return; | |
838 | ||
839 | loc->condition_changed = condition_modified; | |
840 | } | |
841 | ||
842 | /* Sets the condition-evaluation mode using the static global | |
843 | condition_evaluation_mode. */ | |
844 | ||
845 | static void | |
846 | set_condition_evaluation_mode (char *args, int from_tty, | |
847 | struct cmd_list_element *c) | |
848 | { | |
b775012e LM |
849 | const char *old_mode, *new_mode; |
850 | ||
851 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
852 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
853 | { | |
854 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
855 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
856 | "Using host evaluation mode instead.")); | |
857 | return; | |
858 | } | |
859 | ||
860 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
861 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
862 | ||
abf1152a JK |
863 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
864 | settings was "auto". */ | |
865 | condition_evaluation_mode = condition_evaluation_mode_1; | |
866 | ||
b775012e LM |
867 | /* Only update the mode if the user picked a different one. */ |
868 | if (new_mode != old_mode) | |
869 | { | |
870 | struct bp_location *loc, **loc_tmp; | |
871 | /* If the user switched to a different evaluation mode, we | |
872 | need to synch the changes with the target as follows: | |
873 | ||
874 | "host" -> "target": Send all (valid) conditions to the target. | |
875 | "target" -> "host": Remove all the conditions from the target. | |
876 | */ | |
877 | ||
b775012e LM |
878 | if (new_mode == condition_evaluation_target) |
879 | { | |
880 | /* Mark everything modified and synch conditions with the | |
881 | target. */ | |
882 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
883 | mark_breakpoint_location_modified (loc); | |
884 | } | |
885 | else | |
886 | { | |
887 | /* Manually mark non-duplicate locations to synch conditions | |
888 | with the target. We do this to remove all the conditions the | |
889 | target knows about. */ | |
890 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
891 | if (is_breakpoint (loc->owner) && loc->inserted) | |
892 | loc->needs_update = 1; | |
893 | } | |
894 | ||
895 | /* Do the update. */ | |
44702360 | 896 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
897 | } |
898 | ||
899 | return; | |
900 | } | |
901 | ||
902 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
903 | what "auto" is translating to. */ | |
904 | ||
905 | static void | |
906 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
907 | struct cmd_list_element *c, const char *value) | |
908 | { | |
909 | if (condition_evaluation_mode == condition_evaluation_auto) | |
910 | fprintf_filtered (file, | |
911 | _("Breakpoint condition evaluation " | |
912 | "mode is %s (currently %s).\n"), | |
913 | value, | |
914 | breakpoint_condition_evaluation_mode ()); | |
915 | else | |
916 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
917 | value); | |
918 | } | |
919 | ||
920 | /* A comparison function for bp_location AP and BP that is used by | |
921 | bsearch. This comparison function only cares about addresses, unlike | |
922 | the more general bp_location_compare function. */ | |
923 | ||
924 | static int | |
925 | bp_location_compare_addrs (const void *ap, const void *bp) | |
926 | { | |
927 | struct bp_location *a = *(void **) ap; | |
928 | struct bp_location *b = *(void **) bp; | |
929 | ||
930 | if (a->address == b->address) | |
931 | return 0; | |
932 | else | |
933 | return ((a->address > b->address) - (a->address < b->address)); | |
934 | } | |
935 | ||
936 | /* Helper function to skip all bp_locations with addresses | |
937 | less than ADDRESS. It returns the first bp_location that | |
938 | is greater than or equal to ADDRESS. If none is found, just | |
939 | return NULL. */ | |
940 | ||
941 | static struct bp_location ** | |
942 | get_first_locp_gte_addr (CORE_ADDR address) | |
943 | { | |
944 | struct bp_location dummy_loc; | |
945 | struct bp_location *dummy_locp = &dummy_loc; | |
946 | struct bp_location **locp_found = NULL; | |
947 | ||
948 | /* Initialize the dummy location's address field. */ | |
949 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
950 | dummy_loc.address = address; | |
951 | ||
952 | /* Find a close match to the first location at ADDRESS. */ | |
953 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, | |
954 | sizeof (struct bp_location **), | |
955 | bp_location_compare_addrs); | |
956 | ||
957 | /* Nothing was found, nothing left to do. */ | |
958 | if (locp_found == NULL) | |
959 | return NULL; | |
960 | ||
961 | /* We may have found a location that is at ADDRESS but is not the first in the | |
962 | location's list. Go backwards (if possible) and locate the first one. */ | |
963 | while ((locp_found - 1) >= bp_location | |
964 | && (*(locp_found - 1))->address == address) | |
965 | locp_found--; | |
966 | ||
967 | return locp_found; | |
968 | } | |
969 | ||
adc36818 | 970 | void |
7a26bd4d | 971 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
972 | int from_tty) |
973 | { | |
3a5c3e22 PA |
974 | xfree (b->cond_string); |
975 | b->cond_string = NULL; | |
adc36818 | 976 | |
3a5c3e22 | 977 | if (is_watchpoint (b)) |
adc36818 | 978 | { |
3a5c3e22 PA |
979 | struct watchpoint *w = (struct watchpoint *) b; |
980 | ||
981 | xfree (w->cond_exp); | |
982 | w->cond_exp = NULL; | |
983 | } | |
984 | else | |
985 | { | |
986 | struct bp_location *loc; | |
987 | ||
988 | for (loc = b->loc; loc; loc = loc->next) | |
989 | { | |
990 | xfree (loc->cond); | |
991 | loc->cond = NULL; | |
b775012e LM |
992 | |
993 | /* No need to free the condition agent expression | |
994 | bytecode (if we have one). We will handle this | |
995 | when we go through update_global_location_list. */ | |
3a5c3e22 | 996 | } |
adc36818 | 997 | } |
adc36818 PM |
998 | |
999 | if (*exp == 0) | |
1000 | { | |
1001 | if (from_tty) | |
1002 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
1003 | } | |
1004 | else | |
1005 | { | |
bbc13ae3 | 1006 | const char *arg = exp; |
cc59ec59 | 1007 | |
adc36818 PM |
1008 | /* I don't know if it matters whether this is the string the user |
1009 | typed in or the decompiled expression. */ | |
1010 | b->cond_string = xstrdup (arg); | |
1011 | b->condition_not_parsed = 0; | |
1012 | ||
1013 | if (is_watchpoint (b)) | |
1014 | { | |
3a5c3e22 PA |
1015 | struct watchpoint *w = (struct watchpoint *) b; |
1016 | ||
adc36818 PM |
1017 | innermost_block = NULL; |
1018 | arg = exp; | |
1bb9788d | 1019 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1020 | if (*arg) |
1021 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1022 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1023 | } |
1024 | else | |
1025 | { | |
3a5c3e22 PA |
1026 | struct bp_location *loc; |
1027 | ||
adc36818 PM |
1028 | for (loc = b->loc; loc; loc = loc->next) |
1029 | { | |
1030 | arg = exp; | |
1031 | loc->cond = | |
1bb9788d TT |
1032 | parse_exp_1 (&arg, loc->address, |
1033 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1034 | if (*arg) |
1035 | error (_("Junk at end of expression")); | |
1036 | } | |
1037 | } | |
1038 | } | |
b775012e LM |
1039 | mark_breakpoint_modified (b); |
1040 | ||
8d3788bd | 1041 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1042 | } |
1043 | ||
d55637df TT |
1044 | /* Completion for the "condition" command. */ |
1045 | ||
1046 | static VEC (char_ptr) * | |
6f937416 PA |
1047 | condition_completer (struct cmd_list_element *cmd, |
1048 | const char *text, const char *word) | |
d55637df | 1049 | { |
6f937416 | 1050 | const char *space; |
d55637df | 1051 | |
6f937416 PA |
1052 | text = skip_spaces_const (text); |
1053 | space = skip_to_space_const (text); | |
d55637df TT |
1054 | if (*space == '\0') |
1055 | { | |
1056 | int len; | |
1057 | struct breakpoint *b; | |
1058 | VEC (char_ptr) *result = NULL; | |
1059 | ||
1060 | if (text[0] == '$') | |
1061 | { | |
1062 | /* We don't support completion of history indices. */ | |
1063 | if (isdigit (text[1])) | |
1064 | return NULL; | |
1065 | return complete_internalvar (&text[1]); | |
1066 | } | |
1067 | ||
1068 | /* We're completing the breakpoint number. */ | |
1069 | len = strlen (text); | |
1070 | ||
1071 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1072 | { |
1073 | char number[50]; | |
1074 | ||
1075 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1076 | ||
1077 | if (strncmp (number, text, len) == 0) | |
1078 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1079 | } | |
d55637df TT |
1080 | |
1081 | return result; | |
1082 | } | |
1083 | ||
1084 | /* We're completing the expression part. */ | |
6f937416 | 1085 | text = skip_spaces_const (space); |
d55637df TT |
1086 | return expression_completer (cmd, text, word); |
1087 | } | |
1088 | ||
c906108c SS |
1089 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1090 | ||
1091 | static void | |
fba45db2 | 1092 | condition_command (char *arg, int from_tty) |
c906108c | 1093 | { |
52f0bd74 | 1094 | struct breakpoint *b; |
c906108c | 1095 | char *p; |
52f0bd74 | 1096 | int bnum; |
c906108c SS |
1097 | |
1098 | if (arg == 0) | |
e2e0b3e5 | 1099 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1100 | |
1101 | p = arg; | |
1102 | bnum = get_number (&p); | |
5c44784c | 1103 | if (bnum == 0) |
8a3fe4f8 | 1104 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1105 | |
1106 | ALL_BREAKPOINTS (b) | |
1107 | if (b->number == bnum) | |
2f069f6f | 1108 | { |
6dddc817 DE |
1109 | /* Check if this breakpoint has a "stop" method implemented in an |
1110 | extension language. This method and conditions entered into GDB | |
1111 | from the CLI are mutually exclusive. */ | |
1112 | const struct extension_language_defn *extlang | |
1113 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1114 | ||
1115 | if (extlang != NULL) | |
1116 | { | |
1117 | error (_("Only one stop condition allowed. There is currently" | |
1118 | " a %s stop condition defined for this breakpoint."), | |
1119 | ext_lang_capitalized_name (extlang)); | |
1120 | } | |
2566ad2d | 1121 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1122 | |
1123 | if (is_breakpoint (b)) | |
44702360 | 1124 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1125 | |
2f069f6f JB |
1126 | return; |
1127 | } | |
c906108c | 1128 | |
8a3fe4f8 | 1129 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1130 | } |
1131 | ||
a7bdde9e VP |
1132 | /* Check that COMMAND do not contain commands that are suitable |
1133 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1134 | Throw if any such commands is found. */ |
1135 | ||
a7bdde9e VP |
1136 | static void |
1137 | check_no_tracepoint_commands (struct command_line *commands) | |
1138 | { | |
1139 | struct command_line *c; | |
cc59ec59 | 1140 | |
a7bdde9e VP |
1141 | for (c = commands; c; c = c->next) |
1142 | { | |
1143 | int i; | |
1144 | ||
1145 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1146 | error (_("The 'while-stepping' command can " |
1147 | "only be used for tracepoints")); | |
a7bdde9e VP |
1148 | |
1149 | for (i = 0; i < c->body_count; ++i) | |
1150 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1151 | ||
1152 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1153 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1154 | command directly. */ |
1155 | if (strstr (c->line, "collect ") == c->line) | |
1156 | error (_("The 'collect' command can only be used for tracepoints")); | |
1157 | ||
51661e93 VP |
1158 | if (strstr (c->line, "teval ") == c->line) |
1159 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1160 | } |
1161 | } | |
1162 | ||
d77f58be SS |
1163 | /* Encapsulate tests for different types of tracepoints. */ |
1164 | ||
d9b3f62e PA |
1165 | static int |
1166 | is_tracepoint_type (enum bptype type) | |
1167 | { | |
1168 | return (type == bp_tracepoint | |
1169 | || type == bp_fast_tracepoint | |
1170 | || type == bp_static_tracepoint); | |
1171 | } | |
1172 | ||
a7bdde9e | 1173 | int |
d77f58be | 1174 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1175 | { |
d9b3f62e | 1176 | return is_tracepoint_type (b->type); |
a7bdde9e | 1177 | } |
d9b3f62e | 1178 | |
e5dd4106 | 1179 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1180 | breakpoint. This function will throw an exception if a problem is |
1181 | found. */ | |
48cb2d85 | 1182 | |
95a42b64 TT |
1183 | static void |
1184 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1185 | struct command_line *commands) | |
48cb2d85 | 1186 | { |
d77f58be | 1187 | if (is_tracepoint (b)) |
a7bdde9e | 1188 | { |
c9a6ce02 | 1189 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1190 | struct command_line *c; |
1191 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1192 | |
1193 | /* Reset the while-stepping step count. The previous commands | |
1194 | might have included a while-stepping action, while the new | |
1195 | ones might not. */ | |
1196 | t->step_count = 0; | |
1197 | ||
1198 | /* We need to verify that each top-level element of commands is | |
1199 | valid for tracepoints, that there's at most one | |
1200 | while-stepping element, and that the while-stepping's body | |
1201 | has valid tracing commands excluding nested while-stepping. | |
1202 | We also need to validate the tracepoint action line in the | |
1203 | context of the tracepoint --- validate_actionline actually | |
1204 | has side effects, like setting the tracepoint's | |
1205 | while-stepping STEP_COUNT, in addition to checking if the | |
1206 | collect/teval actions parse and make sense in the | |
1207 | tracepoint's context. */ | |
a7bdde9e VP |
1208 | for (c = commands; c; c = c->next) |
1209 | { | |
a7bdde9e VP |
1210 | if (c->control_type == while_stepping_control) |
1211 | { | |
1212 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1213 | error (_("The 'while-stepping' command " |
1214 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1215 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1216 | error (_("The 'while-stepping' command " |
1217 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1218 | |
1219 | if (while_stepping) | |
3e43a32a MS |
1220 | error (_("The 'while-stepping' command " |
1221 | "can be used only once")); | |
a7bdde9e VP |
1222 | else |
1223 | while_stepping = c; | |
1224 | } | |
c9a6ce02 PA |
1225 | |
1226 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1227 | } |
1228 | if (while_stepping) | |
1229 | { | |
1230 | struct command_line *c2; | |
1231 | ||
1232 | gdb_assert (while_stepping->body_count == 1); | |
1233 | c2 = while_stepping->body_list[0]; | |
1234 | for (; c2; c2 = c2->next) | |
1235 | { | |
a7bdde9e VP |
1236 | if (c2->control_type == while_stepping_control) |
1237 | error (_("The 'while-stepping' command cannot be nested")); | |
1238 | } | |
1239 | } | |
1240 | } | |
1241 | else | |
1242 | { | |
1243 | check_no_tracepoint_commands (commands); | |
1244 | } | |
95a42b64 TT |
1245 | } |
1246 | ||
0fb4aa4b PA |
1247 | /* Return a vector of all the static tracepoints set at ADDR. The |
1248 | caller is responsible for releasing the vector. */ | |
1249 | ||
1250 | VEC(breakpoint_p) * | |
1251 | static_tracepoints_here (CORE_ADDR addr) | |
1252 | { | |
1253 | struct breakpoint *b; | |
1254 | VEC(breakpoint_p) *found = 0; | |
1255 | struct bp_location *loc; | |
1256 | ||
1257 | ALL_BREAKPOINTS (b) | |
1258 | if (b->type == bp_static_tracepoint) | |
1259 | { | |
1260 | for (loc = b->loc; loc; loc = loc->next) | |
1261 | if (loc->address == addr) | |
1262 | VEC_safe_push(breakpoint_p, found, b); | |
1263 | } | |
1264 | ||
1265 | return found; | |
1266 | } | |
1267 | ||
95a42b64 | 1268 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1269 | validate that only allowed commands are included. */ |
95a42b64 TT |
1270 | |
1271 | void | |
4a64f543 MS |
1272 | breakpoint_set_commands (struct breakpoint *b, |
1273 | struct command_line *commands) | |
95a42b64 TT |
1274 | { |
1275 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1276 | |
9add0f1b TT |
1277 | decref_counted_command_line (&b->commands); |
1278 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1279 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1280 | } |
1281 | ||
45a43567 TT |
1282 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1283 | is not the same as the "silent" that may appear in the breakpoint's | |
1284 | commands. */ | |
1285 | ||
1286 | void | |
1287 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1288 | { | |
1289 | int old_silent = b->silent; | |
1290 | ||
1291 | b->silent = silent; | |
1292 | if (old_silent != silent) | |
8d3788bd | 1293 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1294 | } |
1295 | ||
1296 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1297 | breakpoint work for any thread. */ | |
1298 | ||
1299 | void | |
1300 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1301 | { | |
1302 | int old_thread = b->thread; | |
1303 | ||
1304 | b->thread = thread; | |
1305 | if (old_thread != thread) | |
8d3788bd | 1306 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1307 | } |
1308 | ||
1309 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1310 | breakpoint work for any task. */ | |
1311 | ||
1312 | void | |
1313 | breakpoint_set_task (struct breakpoint *b, int task) | |
1314 | { | |
1315 | int old_task = b->task; | |
1316 | ||
1317 | b->task = task; | |
1318 | if (old_task != task) | |
8d3788bd | 1319 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1320 | } |
1321 | ||
95a42b64 TT |
1322 | void |
1323 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1324 | { |
1325 | struct breakpoint *b = closure; | |
cc59ec59 | 1326 | |
6f937416 | 1327 | validate_actionline (line, b); |
a7bdde9e VP |
1328 | } |
1329 | ||
95a42b64 TT |
1330 | /* A structure used to pass information through |
1331 | map_breakpoint_numbers. */ | |
1332 | ||
1333 | struct commands_info | |
1334 | { | |
1335 | /* True if the command was typed at a tty. */ | |
1336 | int from_tty; | |
86b17b60 PA |
1337 | |
1338 | /* The breakpoint range spec. */ | |
1339 | char *arg; | |
1340 | ||
95a42b64 TT |
1341 | /* Non-NULL if the body of the commands are being read from this |
1342 | already-parsed command. */ | |
1343 | struct command_line *control; | |
86b17b60 | 1344 | |
95a42b64 TT |
1345 | /* The command lines read from the user, or NULL if they have not |
1346 | yet been read. */ | |
1347 | struct counted_command_line *cmd; | |
1348 | }; | |
1349 | ||
1350 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1351 | commands_command. */ | |
1352 | ||
c906108c | 1353 | static void |
95a42b64 | 1354 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1355 | { |
95a42b64 | 1356 | struct commands_info *info = data; |
c906108c | 1357 | |
95a42b64 TT |
1358 | if (info->cmd == NULL) |
1359 | { | |
1360 | struct command_line *l; | |
5c44784c | 1361 | |
95a42b64 TT |
1362 | if (info->control != NULL) |
1363 | l = copy_command_lines (info->control->body_list[0]); | |
1364 | else | |
86b17b60 PA |
1365 | { |
1366 | struct cleanup *old_chain; | |
1367 | char *str; | |
c5aa993b | 1368 | |
3e43a32a MS |
1369 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1370 | "%s, one per line."), | |
86b17b60 PA |
1371 | info->arg); |
1372 | ||
1373 | old_chain = make_cleanup (xfree, str); | |
1374 | ||
1375 | l = read_command_lines (str, | |
1376 | info->from_tty, 1, | |
d77f58be | 1377 | (is_tracepoint (b) |
86b17b60 PA |
1378 | ? check_tracepoint_command : 0), |
1379 | b); | |
1380 | ||
1381 | do_cleanups (old_chain); | |
1382 | } | |
a7bdde9e | 1383 | |
95a42b64 TT |
1384 | info->cmd = alloc_counted_command_line (l); |
1385 | } | |
1386 | ||
1387 | /* If a breakpoint was on the list more than once, we don't need to | |
1388 | do anything. */ | |
1389 | if (b->commands != info->cmd) | |
1390 | { | |
1391 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1392 | incref_counted_command_line (info->cmd); | |
1393 | decref_counted_command_line (&b->commands); | |
1394 | b->commands = info->cmd; | |
8d3788bd | 1395 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1396 | } |
95a42b64 TT |
1397 | } |
1398 | ||
1399 | static void | |
4a64f543 MS |
1400 | commands_command_1 (char *arg, int from_tty, |
1401 | struct command_line *control) | |
95a42b64 TT |
1402 | { |
1403 | struct cleanup *cleanups; | |
1404 | struct commands_info info; | |
1405 | ||
1406 | info.from_tty = from_tty; | |
1407 | info.control = control; | |
1408 | info.cmd = NULL; | |
1409 | /* If we read command lines from the user, then `info' will hold an | |
1410 | extra reference to the commands that we must clean up. */ | |
1411 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1412 | ||
1413 | if (arg == NULL || !*arg) | |
1414 | { | |
86b17b60 | 1415 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1416 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1417 | breakpoint_count); | |
95a42b64 TT |
1418 | else if (breakpoint_count > 0) |
1419 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1420 | else |
1421 | { | |
1422 | /* So that we don't try to free the incoming non-NULL | |
1423 | argument in the cleanup below. Mapping breakpoint | |
1424 | numbers will fail in this case. */ | |
1425 | arg = NULL; | |
1426 | } | |
95a42b64 | 1427 | } |
9766ced4 SS |
1428 | else |
1429 | /* The command loop has some static state, so we need to preserve | |
1430 | our argument. */ | |
1431 | arg = xstrdup (arg); | |
86b17b60 PA |
1432 | |
1433 | if (arg != NULL) | |
1434 | make_cleanup (xfree, arg); | |
1435 | ||
1436 | info.arg = arg; | |
95a42b64 TT |
1437 | |
1438 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1439 | ||
1440 | if (info.cmd == NULL) | |
1441 | error (_("No breakpoints specified.")); | |
1442 | ||
1443 | do_cleanups (cleanups); | |
1444 | } | |
1445 | ||
1446 | static void | |
1447 | commands_command (char *arg, int from_tty) | |
1448 | { | |
1449 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1450 | } |
40c03ae8 EZ |
1451 | |
1452 | /* Like commands_command, but instead of reading the commands from | |
1453 | input stream, takes them from an already parsed command structure. | |
1454 | ||
1455 | This is used by cli-script.c to DTRT with breakpoint commands | |
1456 | that are part of if and while bodies. */ | |
1457 | enum command_control_type | |
1458 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1459 | { | |
95a42b64 TT |
1460 | commands_command_1 (arg, 0, cmd); |
1461 | return simple_control; | |
40c03ae8 | 1462 | } |
876fa593 JK |
1463 | |
1464 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1465 | ||
1466 | static int | |
1467 | bp_location_has_shadow (struct bp_location *bl) | |
1468 | { | |
1469 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1470 | return 0; | |
1471 | if (!bl->inserted) | |
1472 | return 0; | |
1473 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1474 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1475 | return 0; |
1476 | return 1; | |
1477 | } | |
1478 | ||
9d497a19 PA |
1479 | /* Update BUF, which is LEN bytes read from the target address |
1480 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1481 | contents. | |
1482 | ||
1483 | If READBUF is not NULL, this buffer must not overlap with the of | |
1484 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1485 | failed assertion internal error will be raised. */ | |
1486 | ||
1487 | static void | |
1488 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1489 | const gdb_byte *writebuf_org, | |
1490 | ULONGEST memaddr, LONGEST len, | |
1491 | struct bp_target_info *target_info, | |
1492 | struct gdbarch *gdbarch) | |
1493 | { | |
1494 | /* Now do full processing of the found relevant range of elements. */ | |
1495 | CORE_ADDR bp_addr = 0; | |
1496 | int bp_size = 0; | |
1497 | int bptoffset = 0; | |
1498 | ||
1499 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1500 | current_program_space->aspace, 0)) | |
1501 | { | |
1502 | /* The breakpoint is inserted in a different address space. */ | |
1503 | return; | |
1504 | } | |
1505 | ||
1506 | /* Addresses and length of the part of the breakpoint that | |
1507 | we need to copy. */ | |
1508 | bp_addr = target_info->placed_address; | |
1509 | bp_size = target_info->shadow_len; | |
1510 | ||
1511 | if (bp_addr + bp_size <= memaddr) | |
1512 | { | |
1513 | /* The breakpoint is entirely before the chunk of memory we are | |
1514 | reading. */ | |
1515 | return; | |
1516 | } | |
1517 | ||
1518 | if (bp_addr >= memaddr + len) | |
1519 | { | |
1520 | /* The breakpoint is entirely after the chunk of memory we are | |
1521 | reading. */ | |
1522 | return; | |
1523 | } | |
1524 | ||
1525 | /* Offset within shadow_contents. */ | |
1526 | if (bp_addr < memaddr) | |
1527 | { | |
1528 | /* Only copy the second part of the breakpoint. */ | |
1529 | bp_size -= memaddr - bp_addr; | |
1530 | bptoffset = memaddr - bp_addr; | |
1531 | bp_addr = memaddr; | |
1532 | } | |
1533 | ||
1534 | if (bp_addr + bp_size > memaddr + len) | |
1535 | { | |
1536 | /* Only copy the first part of the breakpoint. */ | |
1537 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1538 | } | |
1539 | ||
1540 | if (readbuf != NULL) | |
1541 | { | |
1542 | /* Verify that the readbuf buffer does not overlap with the | |
1543 | shadow_contents buffer. */ | |
1544 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1545 | || readbuf >= (target_info->shadow_contents | |
1546 | + target_info->shadow_len)); | |
1547 | ||
1548 | /* Update the read buffer with this inserted breakpoint's | |
1549 | shadow. */ | |
1550 | memcpy (readbuf + bp_addr - memaddr, | |
1551 | target_info->shadow_contents + bptoffset, bp_size); | |
1552 | } | |
1553 | else | |
1554 | { | |
1555 | const unsigned char *bp; | |
0d5ed153 MR |
1556 | CORE_ADDR addr = target_info->reqstd_address; |
1557 | int placed_size; | |
9d497a19 PA |
1558 | |
1559 | /* Update the shadow with what we want to write to memory. */ | |
1560 | memcpy (target_info->shadow_contents + bptoffset, | |
1561 | writebuf_org + bp_addr - memaddr, bp_size); | |
1562 | ||
1563 | /* Determine appropriate breakpoint contents and size for this | |
1564 | address. */ | |
0d5ed153 | 1565 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1566 | |
1567 | /* Update the final write buffer with this inserted | |
1568 | breakpoint's INSN. */ | |
1569 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1570 | } | |
1571 | } | |
1572 | ||
8defab1a | 1573 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1574 | by replacing any memory breakpoints with their shadowed contents. |
1575 | ||
35c63cd8 JB |
1576 | If READBUF is not NULL, this buffer must not overlap with any of |
1577 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1578 | a failed assertion internal error will be raised. | |
1579 | ||
876fa593 | 1580 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1581 | bl->address - bp_location_placed_address_before_address_max |
1582 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1583 | The range we were requested to resolve shadows for is: |
1584 | memaddr ... memaddr + len | |
1585 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1586 | memaddr + len <= (bl->address |
1587 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1588 | and: |
35df4500 | 1589 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1590 | |
8defab1a | 1591 | void |
f0ba3972 PA |
1592 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1593 | const gdb_byte *writebuf_org, | |
1594 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1595 | { |
4a64f543 MS |
1596 | /* Left boundary, right boundary and median element of our binary |
1597 | search. */ | |
876fa593 | 1598 | unsigned bc_l, bc_r, bc; |
9d497a19 | 1599 | size_t i; |
876fa593 | 1600 | |
4a64f543 MS |
1601 | /* Find BC_L which is a leftmost element which may affect BUF |
1602 | content. It is safe to report lower value but a failure to | |
1603 | report higher one. */ | |
876fa593 JK |
1604 | |
1605 | bc_l = 0; | |
1606 | bc_r = bp_location_count; | |
1607 | while (bc_l + 1 < bc_r) | |
1608 | { | |
35df4500 | 1609 | struct bp_location *bl; |
876fa593 JK |
1610 | |
1611 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1612 | bl = bp_location[bc]; |
876fa593 | 1613 | |
4a64f543 MS |
1614 | /* Check first BL->ADDRESS will not overflow due to the added |
1615 | constant. Then advance the left boundary only if we are sure | |
1616 | the BC element can in no way affect the BUF content (MEMADDR | |
1617 | to MEMADDR + LEN range). | |
876fa593 | 1618 | |
4a64f543 MS |
1619 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1620 | offset so that we cannot miss a breakpoint with its shadow | |
1621 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1622 | |
35df4500 TJB |
1623 | if ((bl->address + bp_location_shadow_len_after_address_max |
1624 | >= bl->address) | |
1625 | && (bl->address + bp_location_shadow_len_after_address_max | |
1626 | <= memaddr)) | |
876fa593 JK |
1627 | bc_l = bc; |
1628 | else | |
1629 | bc_r = bc; | |
1630 | } | |
1631 | ||
128070bb PA |
1632 | /* Due to the binary search above, we need to make sure we pick the |
1633 | first location that's at BC_L's address. E.g., if there are | |
1634 | multiple locations at the same address, BC_L may end up pointing | |
1635 | at a duplicate location, and miss the "master"/"inserted" | |
1636 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1637 | B: | |
1638 | ||
1639 | L1@A, L2@A, L3@B, ... | |
1640 | ||
1641 | BC_L could end up pointing at location L2, while the "master" | |
1642 | location could be L1. Since the `loc->inserted' flag is only set | |
1643 | on "master" locations, we'd forget to restore the shadow of L1 | |
1644 | and L2. */ | |
1645 | while (bc_l > 0 | |
1646 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1647 | bc_l--; | |
1648 | ||
876fa593 JK |
1649 | /* Now do full processing of the found relevant range of elements. */ |
1650 | ||
1651 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1652 | { |
35df4500 | 1653 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1654 | CORE_ADDR bp_addr = 0; |
1655 | int bp_size = 0; | |
1656 | int bptoffset = 0; | |
1657 | ||
35df4500 TJB |
1658 | /* bp_location array has BL->OWNER always non-NULL. */ |
1659 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1660 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1661 | bl->owner->number); |
ffce0d52 | 1662 | |
e5dd4106 | 1663 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1664 | content. */ |
1665 | ||
35df4500 TJB |
1666 | if (bl->address >= bp_location_placed_address_before_address_max |
1667 | && memaddr + len <= (bl->address | |
1668 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1669 | break; |
1670 | ||
35df4500 | 1671 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1672 | continue; |
6c95b8df | 1673 | |
9d497a19 PA |
1674 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1675 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1676 | } | |
c906108c | 1677 | } |
9d497a19 | 1678 | |
c906108c | 1679 | \f |
c5aa993b | 1680 | |
b775012e LM |
1681 | /* Return true if BPT is either a software breakpoint or a hardware |
1682 | breakpoint. */ | |
1683 | ||
1684 | int | |
1685 | is_breakpoint (const struct breakpoint *bpt) | |
1686 | { | |
1687 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1688 | || bpt->type == bp_hardware_breakpoint |
1689 | || bpt->type == bp_dprintf); | |
b775012e LM |
1690 | } |
1691 | ||
60e1c644 PA |
1692 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1693 | ||
a5606eee | 1694 | static int |
d77f58be | 1695 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1696 | { |
1697 | return (bpt->type == bp_hardware_watchpoint | |
1698 | || bpt->type == bp_read_watchpoint | |
1699 | || bpt->type == bp_access_watchpoint); | |
1700 | } | |
7270d8f2 | 1701 | |
60e1c644 PA |
1702 | /* Return true if BPT is of any watchpoint kind, hardware or |
1703 | software. */ | |
1704 | ||
3a5c3e22 | 1705 | int |
d77f58be | 1706 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1707 | { |
1708 | return (is_hardware_watchpoint (bpt) | |
1709 | || bpt->type == bp_watchpoint); | |
1710 | } | |
1711 | ||
3a5c3e22 PA |
1712 | /* Returns true if the current thread and its running state are safe |
1713 | to evaluate or update watchpoint B. Watchpoints on local | |
1714 | expressions need to be evaluated in the context of the thread that | |
1715 | was current when the watchpoint was created, and, that thread needs | |
1716 | to be stopped to be able to select the correct frame context. | |
1717 | Watchpoints on global expressions can be evaluated on any thread, | |
1718 | and in any state. It is presently left to the target allowing | |
1719 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1720 | |
1721 | static int | |
3a5c3e22 | 1722 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1723 | { |
d0d8b0c6 JK |
1724 | return (b->base.pspace == current_program_space |
1725 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1726 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1727 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1728 | } |
1729 | ||
d0fb5eae JK |
1730 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1731 | associated bp_watchpoint_scope breakpoint. */ | |
1732 | ||
1733 | static void | |
3a5c3e22 | 1734 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1735 | { |
3a5c3e22 | 1736 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1737 | |
1738 | if (b->related_breakpoint != b) | |
1739 | { | |
1740 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1741 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1742 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1743 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1744 | b->related_breakpoint = b; | |
1745 | } | |
1746 | b->disposition = disp_del_at_next_stop; | |
1747 | } | |
1748 | ||
bb9d5f81 PP |
1749 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1750 | watchpoint W. */ | |
1751 | ||
1752 | static struct value * | |
1753 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1754 | { | |
1755 | struct value *bit_val; | |
1756 | ||
1757 | if (val == NULL) | |
1758 | return NULL; | |
1759 | ||
1760 | bit_val = allocate_value (value_type (val)); | |
1761 | ||
1762 | unpack_value_bitfield (bit_val, | |
1763 | w->val_bitpos, | |
1764 | w->val_bitsize, | |
1765 | value_contents_for_printing (val), | |
1766 | value_offset (val), | |
1767 | val); | |
1768 | ||
1769 | return bit_val; | |
1770 | } | |
1771 | ||
567e1b4e JB |
1772 | /* Assuming that B is a watchpoint: |
1773 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1774 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1775 | - Evaluate the condition if there is one, and store the result |
1776 | in b->loc->cond. | |
a5606eee VP |
1777 | - Update the list of values that must be watched in B->loc. |
1778 | ||
4a64f543 MS |
1779 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1780 | nothing. If this is local watchpoint that is out of scope, delete | |
1781 | it. | |
1782 | ||
1783 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1784 | removed + inserted on each stop here. Normal breakpoints must | |
1785 | never be removed because they might be missed by a running thread | |
1786 | when debugging in non-stop mode. On the other hand, hardware | |
1787 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1788 | to each LWP since they are stored in each LWP's hardware debug | |
1789 | registers. Therefore, such LWP must be stopped first in order to | |
1790 | be able to modify its hardware watchpoints. | |
1791 | ||
1792 | Hardware watchpoints must be reset exactly once after being | |
1793 | presented to the user. It cannot be done sooner, because it would | |
1794 | reset the data used to present the watchpoint hit to the user. And | |
1795 | it must not be done later because it could display the same single | |
1796 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1797 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1798 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1799 | not user-visible - its hit is suppressed if the memory content has | |
1800 | not changed. | |
1801 | ||
1802 | The following constraints influence the location where we can reset | |
1803 | hardware watchpoints: | |
1804 | ||
1805 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1806 | called several times when GDB stops. | |
1807 | ||
1808 | [linux] | |
1809 | * Multiple hardware watchpoints can be hit at the same time, | |
1810 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1811 | hit at a time as the reason for stopping, and all the other hits | |
1812 | are presented later, one after the other, each time the user | |
1813 | requests the execution to be resumed. Execution is not resumed | |
1814 | for the threads still having pending hit event stored in | |
1815 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1816 | the inferior on the first stop the thread hit event is kept being | |
1817 | reported from its cached value by linux_nat_stopped_data_address | |
1818 | until the real thread resume happens after the watchpoint gets | |
1819 | presented and thus its LWP_INFO->STATUS gets reset. | |
1820 | ||
1821 | Therefore the hardware watchpoint hit can get safely reset on the | |
1822 | watchpoint removal from inferior. */ | |
a79d3c27 | 1823 | |
b40ce68a | 1824 | static void |
3a5c3e22 | 1825 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1826 | { |
a5606eee | 1827 | int within_current_scope; |
a5606eee | 1828 | struct frame_id saved_frame_id; |
66076460 | 1829 | int frame_saved; |
a5606eee | 1830 | |
f6bc2008 PA |
1831 | /* If this is a local watchpoint, we only want to check if the |
1832 | watchpoint frame is in scope if the current thread is the thread | |
1833 | that was used to create the watchpoint. */ | |
1834 | if (!watchpoint_in_thread_scope (b)) | |
1835 | return; | |
1836 | ||
3a5c3e22 | 1837 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1838 | return; |
1839 | ||
66076460 | 1840 | frame_saved = 0; |
a5606eee VP |
1841 | |
1842 | /* Determine if the watchpoint is within scope. */ | |
1843 | if (b->exp_valid_block == NULL) | |
1844 | within_current_scope = 1; | |
1845 | else | |
1846 | { | |
b5db5dfc UW |
1847 | struct frame_info *fi = get_current_frame (); |
1848 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1849 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1850 | ||
c9cf6e20 MG |
1851 | /* If we're at a point where the stack has been destroyed |
1852 | (e.g. in a function epilogue), unwinding may not work | |
1853 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1854 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1855 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1856 | return; |
66076460 DJ |
1857 | |
1858 | /* Save the current frame's ID so we can restore it after | |
1859 | evaluating the watchpoint expression on its own frame. */ | |
1860 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1861 | took a frame parameter, so that we didn't have to change the | |
1862 | selected frame. */ | |
1863 | frame_saved = 1; | |
1864 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1865 | ||
a5606eee VP |
1866 | fi = frame_find_by_id (b->watchpoint_frame); |
1867 | within_current_scope = (fi != NULL); | |
1868 | if (within_current_scope) | |
1869 | select_frame (fi); | |
1870 | } | |
1871 | ||
b5db5dfc UW |
1872 | /* We don't free locations. They are stored in the bp_location array |
1873 | and update_global_location_list will eventually delete them and | |
1874 | remove breakpoints if needed. */ | |
3a5c3e22 | 1875 | b->base.loc = NULL; |
b5db5dfc | 1876 | |
a5606eee VP |
1877 | if (within_current_scope && reparse) |
1878 | { | |
bbc13ae3 | 1879 | const char *s; |
d63d0675 | 1880 | |
a5606eee VP |
1881 | if (b->exp) |
1882 | { | |
1883 | xfree (b->exp); | |
1884 | b->exp = NULL; | |
1885 | } | |
d63d0675 | 1886 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1887 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1888 | /* If the meaning of expression itself changed, the old value is |
1889 | no longer relevant. We don't want to report a watchpoint hit | |
1890 | to the user when the old value and the new value may actually | |
1891 | be completely different objects. */ | |
1892 | value_free (b->val); | |
fa4727a6 DJ |
1893 | b->val = NULL; |
1894 | b->val_valid = 0; | |
60e1c644 PA |
1895 | |
1896 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1897 | expression is stored in the breakpoint object, not in the | |
1898 | locations (re)created below. */ | |
3a5c3e22 | 1899 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1900 | { |
1901 | if (b->cond_exp != NULL) | |
1902 | { | |
1903 | xfree (b->cond_exp); | |
1904 | b->cond_exp = NULL; | |
1905 | } | |
1906 | ||
3a5c3e22 | 1907 | s = b->base.cond_string; |
1bb9788d | 1908 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1909 | } |
a5606eee | 1910 | } |
a5606eee VP |
1911 | |
1912 | /* If we failed to parse the expression, for example because | |
1913 | it refers to a global variable in a not-yet-loaded shared library, | |
1914 | don't try to insert watchpoint. We don't automatically delete | |
1915 | such watchpoint, though, since failure to parse expression | |
1916 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1917 | if (!target_has_execution) |
2d134ed3 PA |
1918 | { |
1919 | /* Without execution, memory can't change. No use to try and | |
1920 | set watchpoint locations. The watchpoint will be reset when | |
1921 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1922 | if (!can_use_hw_watchpoints) |
1923 | { | |
1924 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1925 | b->base.type = bp_watchpoint; | |
1926 | else | |
638aa5a1 AB |
1927 | error (_("Can't set read/access watchpoint when " |
1928 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1929 | } |
2d134ed3 PA |
1930 | } |
1931 | else if (within_current_scope && b->exp) | |
a5606eee | 1932 | { |
0cf6dd15 | 1933 | int pc = 0; |
fa4727a6 | 1934 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1935 | struct program_space *frame_pspace; |
a5606eee | 1936 | |
3a1115a0 | 1937 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1938 | |
a5606eee VP |
1939 | /* Avoid setting b->val if it's already set. The meaning of |
1940 | b->val is 'the last value' user saw, and we should update | |
1941 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1942 | happens, the code that reports it updates b->val directly. |
1943 | We don't keep track of the memory value for masked | |
1944 | watchpoints. */ | |
3a5c3e22 | 1945 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 | 1946 | { |
bb9d5f81 PP |
1947 | if (b->val_bitsize != 0) |
1948 | { | |
1949 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1950 | if (v != NULL) | |
1951 | release_value (v); | |
1952 | } | |
fa4727a6 DJ |
1953 | b->val = v; |
1954 | b->val_valid = 1; | |
1955 | } | |
a5606eee | 1956 | |
2d134ed3 PA |
1957 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1958 | ||
a5606eee | 1959 | /* Look at each value on the value chain. */ |
9fa40276 | 1960 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1961 | { |
1962 | /* If it's a memory location, and GDB actually needed | |
1963 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1964 | must watch it. If the first value returned is |
1965 | still lazy, that means an error occurred reading it; | |
1966 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1967 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1968 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1969 | { |
1970 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1971 | |
a5606eee VP |
1972 | /* We only watch structs and arrays if user asked |
1973 | for it explicitly, never if they just happen to | |
1974 | appear in the middle of some value chain. */ | |
fa4727a6 | 1975 | if (v == result |
a5606eee VP |
1976 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1977 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1978 | { | |
1979 | CORE_ADDR addr; | |
f486487f | 1980 | enum target_hw_bp_type type; |
a5606eee | 1981 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1982 | int bitpos = 0, bitsize = 0; |
1983 | ||
1984 | if (value_bitsize (v) != 0) | |
1985 | { | |
1986 | /* Extract the bit parameters out from the bitfield | |
1987 | sub-expression. */ | |
1988 | bitpos = value_bitpos (v); | |
1989 | bitsize = value_bitsize (v); | |
1990 | } | |
1991 | else if (v == result && b->val_bitsize != 0) | |
1992 | { | |
1993 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1994 | lvalue whose bit parameters are saved in the fields | |
1995 | VAL_BITPOS and VAL_BITSIZE. */ | |
1996 | bitpos = b->val_bitpos; | |
1997 | bitsize = b->val_bitsize; | |
1998 | } | |
a5606eee | 1999 | |
42ae5230 | 2000 | addr = value_address (v); |
bb9d5f81 PP |
2001 | if (bitsize != 0) |
2002 | { | |
2003 | /* Skip the bytes that don't contain the bitfield. */ | |
2004 | addr += bitpos / 8; | |
2005 | } | |
2006 | ||
a5606eee | 2007 | type = hw_write; |
3a5c3e22 | 2008 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 2009 | type = hw_read; |
3a5c3e22 | 2010 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 2011 | type = hw_access; |
3a5c3e22 PA |
2012 | |
2013 | loc = allocate_bp_location (&b->base); | |
2014 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2015 | ; |
2016 | *tmp = loc; | |
a6d9a66e | 2017 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2018 | |
2019 | loc->pspace = frame_pspace; | |
a5606eee | 2020 | loc->address = addr; |
bb9d5f81 PP |
2021 | |
2022 | if (bitsize != 0) | |
2023 | { | |
2024 | /* Just cover the bytes that make up the bitfield. */ | |
2025 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2026 | } | |
2027 | else | |
2028 | loc->length = TYPE_LENGTH (value_type (v)); | |
2029 | ||
a5606eee VP |
2030 | loc->watchpoint_type = type; |
2031 | } | |
2032 | } | |
9fa40276 TJB |
2033 | } |
2034 | ||
2035 | /* Change the type of breakpoint between hardware assisted or | |
2036 | an ordinary watchpoint depending on the hardware support | |
2037 | and free hardware slots. REPARSE is set when the inferior | |
2038 | is started. */ | |
a9634178 | 2039 | if (reparse) |
9fa40276 | 2040 | { |
e09342b5 | 2041 | int reg_cnt; |
9fa40276 TJB |
2042 | enum bp_loc_type loc_type; |
2043 | struct bp_location *bl; | |
a5606eee | 2044 | |
a9634178 | 2045 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2046 | |
2047 | if (reg_cnt) | |
9fa40276 TJB |
2048 | { |
2049 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2050 | enum bptype type; |
9fa40276 | 2051 | |
a9634178 TJB |
2052 | /* Use an exact watchpoint when there's only one memory region to be |
2053 | watched, and only one debug register is needed to watch it. */ | |
2054 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2055 | ||
9fa40276 | 2056 | /* We need to determine how many resources are already |
e09342b5 TJB |
2057 | used for all other hardware watchpoints plus this one |
2058 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2059 | this watchpoint in as well. */ |
2060 | ||
2061 | /* If this is a software watchpoint, we try to turn it | |
2062 | to a hardware one -- count resources as if B was of | |
2063 | hardware watchpoint type. */ | |
2064 | type = b->base.type; | |
2065 | if (type == bp_watchpoint) | |
2066 | type = bp_hardware_watchpoint; | |
2067 | ||
2068 | /* This watchpoint may or may not have been placed on | |
2069 | the list yet at this point (it won't be in the list | |
2070 | if we're trying to create it for the first time, | |
2071 | through watch_command), so always account for it | |
2072 | manually. */ | |
2073 | ||
2074 | /* Count resources used by all watchpoints except B. */ | |
2075 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
2076 | ||
2077 | /* Add in the resources needed for B. */ | |
2078 | i += hw_watchpoint_use_count (&b->base); | |
2079 | ||
2080 | target_resources_ok | |
2081 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2082 | if (target_resources_ok <= 0) |
a9634178 | 2083 | { |
3a5c3e22 | 2084 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
2085 | |
2086 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2087 | error (_("Target does not support this type of " |
2088 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2089 | else if (target_resources_ok < 0 && !sw_mode) |
2090 | error (_("There are not enough available hardware " | |
2091 | "resources for this watchpoint.")); | |
a1398e0c PA |
2092 | |
2093 | /* Downgrade to software watchpoint. */ | |
2094 | b->base.type = bp_watchpoint; | |
2095 | } | |
2096 | else | |
2097 | { | |
2098 | /* If this was a software watchpoint, we've just | |
2099 | found we have enough resources to turn it to a | |
2100 | hardware watchpoint. Otherwise, this is a | |
2101 | nop. */ | |
2102 | b->base.type = type; | |
a9634178 | 2103 | } |
9fa40276 | 2104 | } |
3a5c3e22 | 2105 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2106 | { |
2107 | if (!can_use_hw_watchpoints) | |
2108 | error (_("Can't set read/access watchpoint when " | |
2109 | "hardware watchpoints are disabled.")); | |
2110 | else | |
2111 | error (_("Expression cannot be implemented with " | |
2112 | "read/access watchpoint.")); | |
2113 | } | |
9fa40276 | 2114 | else |
3a5c3e22 | 2115 | b->base.type = bp_watchpoint; |
9fa40276 | 2116 | |
3a5c3e22 | 2117 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2118 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2119 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2120 | bl->loc_type = loc_type; |
2121 | } | |
2122 | ||
2123 | for (v = val_chain; v; v = next) | |
2124 | { | |
a5606eee VP |
2125 | next = value_next (v); |
2126 | if (v != b->val) | |
2127 | value_free (v); | |
2128 | } | |
2129 | ||
c7437ca6 PA |
2130 | /* If a software watchpoint is not watching any memory, then the |
2131 | above left it without any location set up. But, | |
2132 | bpstat_stop_status requires a location to be able to report | |
2133 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2134 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 2135 | { |
3a5c3e22 PA |
2136 | struct breakpoint *base = &b->base; |
2137 | base->loc = allocate_bp_location (base); | |
2138 | base->loc->pspace = frame_pspace; | |
2139 | base->loc->address = -1; | |
2140 | base->loc->length = -1; | |
2141 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 2142 | } |
a5606eee VP |
2143 | } |
2144 | else if (!within_current_scope) | |
7270d8f2 | 2145 | { |
ac74f770 MS |
2146 | printf_filtered (_("\ |
2147 | Watchpoint %d deleted because the program has left the block\n\ | |
2148 | in which its expression is valid.\n"), | |
3a5c3e22 | 2149 | b->base.number); |
d0fb5eae | 2150 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2151 | } |
a5606eee VP |
2152 | |
2153 | /* Restore the selected frame. */ | |
66076460 DJ |
2154 | if (frame_saved) |
2155 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2156 | } |
2157 | ||
a5606eee | 2158 | |
74960c60 | 2159 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2160 | inserted in the inferior. We don't differentiate the type of BL's owner |
2161 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2162 | breakpoint_ops is not defined, because in insert_bp_location, | |
2163 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2164 | static int |
35df4500 | 2165 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2166 | { |
35df4500 | 2167 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2168 | return 0; |
2169 | ||
35df4500 | 2170 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2171 | return 0; |
2172 | ||
35df4500 | 2173 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2174 | return 0; |
2175 | ||
f8eba3c6 TT |
2176 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2177 | return 0; | |
2178 | ||
56710373 PA |
2179 | /* This is set for example, when we're attached to the parent of a |
2180 | vfork, and have detached from the child. The child is running | |
2181 | free, and we expect it to do an exec or exit, at which point the | |
2182 | OS makes the parent schedulable again (and the target reports | |
2183 | that the vfork is done). Until the child is done with the shared | |
2184 | memory region, do not insert breakpoints in the parent, otherwise | |
2185 | the child could still trip on the parent's breakpoints. Since | |
2186 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2187 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2188 | return 0; |
2189 | ||
31e77af2 PA |
2190 | /* Don't insert a breakpoint if we're trying to step past its |
2191 | location. */ | |
2192 | if ((bl->loc_type == bp_loc_software_breakpoint | |
2193 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2194 | && stepping_past_instruction_at (bl->pspace->aspace, | |
2195 | bl->address)) | |
e558d7c1 PA |
2196 | { |
2197 | if (debug_infrun) | |
2198 | { | |
2199 | fprintf_unfiltered (gdb_stdlog, | |
2200 | "infrun: skipping breakpoint: " | |
2201 | "stepping past insn at: %s\n", | |
2202 | paddress (bl->gdbarch, bl->address)); | |
2203 | } | |
2204 | return 0; | |
2205 | } | |
31e77af2 | 2206 | |
963f9c80 PA |
2207 | /* Don't insert watchpoints if we're trying to step past the |
2208 | instruction that triggered one. */ | |
2209 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2210 | && stepping_past_nonsteppable_watchpoint ()) | |
2211 | { | |
2212 | if (debug_infrun) | |
2213 | { | |
2214 | fprintf_unfiltered (gdb_stdlog, | |
2215 | "infrun: stepping past non-steppable watchpoint. " | |
2216 | "skipping watchpoint at %s:%d\n", | |
2217 | paddress (bl->gdbarch, bl->address), | |
2218 | bl->length); | |
2219 | } | |
2220 | return 0; | |
2221 | } | |
2222 | ||
74960c60 VP |
2223 | return 1; |
2224 | } | |
2225 | ||
934709f0 PW |
2226 | /* Same as should_be_inserted but does the check assuming |
2227 | that the location is not duplicated. */ | |
2228 | ||
2229 | static int | |
2230 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2231 | { | |
2232 | int result; | |
2233 | const int save_duplicate = bl->duplicate; | |
2234 | ||
2235 | bl->duplicate = 0; | |
2236 | result = should_be_inserted (bl); | |
2237 | bl->duplicate = save_duplicate; | |
2238 | return result; | |
2239 | } | |
2240 | ||
b775012e LM |
2241 | /* Parses a conditional described by an expression COND into an |
2242 | agent expression bytecode suitable for evaluation | |
2243 | by the bytecode interpreter. Return NULL if there was | |
2244 | any error during parsing. */ | |
2245 | ||
2246 | static struct agent_expr * | |
2247 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2248 | { | |
2249 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2250 | |
2251 | if (!cond) | |
2252 | return NULL; | |
2253 | ||
2254 | /* We don't want to stop processing, so catch any errors | |
2255 | that may show up. */ | |
492d29ea | 2256 | TRY |
b775012e LM |
2257 | { |
2258 | aexpr = gen_eval_for_expr (scope, cond); | |
2259 | } | |
2260 | ||
492d29ea | 2261 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2262 | { |
2263 | /* If we got here, it means the condition could not be parsed to a valid | |
2264 | bytecode expression and thus can't be evaluated on the target's side. | |
2265 | It's no use iterating through the conditions. */ | |
2266 | return NULL; | |
2267 | } | |
492d29ea | 2268 | END_CATCH |
b775012e LM |
2269 | |
2270 | /* We have a valid agent expression. */ | |
2271 | return aexpr; | |
2272 | } | |
2273 | ||
2274 | /* Based on location BL, create a list of breakpoint conditions to be | |
2275 | passed on to the target. If we have duplicated locations with different | |
2276 | conditions, we will add such conditions to the list. The idea is that the | |
2277 | target will evaluate the list of conditions and will only notify GDB when | |
2278 | one of them is true. */ | |
2279 | ||
2280 | static void | |
2281 | build_target_condition_list (struct bp_location *bl) | |
2282 | { | |
2283 | struct bp_location **locp = NULL, **loc2p; | |
2284 | int null_condition_or_parse_error = 0; | |
2285 | int modified = bl->needs_update; | |
2286 | struct bp_location *loc; | |
2287 | ||
8b4f3082 PA |
2288 | /* Release conditions left over from a previous insert. */ |
2289 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2290 | ||
b775012e LM |
2291 | /* This is only meaningful if the target is |
2292 | evaluating conditions and if the user has | |
2293 | opted for condition evaluation on the target's | |
2294 | side. */ | |
2295 | if (gdb_evaluates_breakpoint_condition_p () | |
2296 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2297 | return; | |
2298 | ||
2299 | /* Do a first pass to check for locations with no assigned | |
2300 | conditions or conditions that fail to parse to a valid agent expression | |
2301 | bytecode. If any of these happen, then it's no use to send conditions | |
2302 | to the target since this location will always trigger and generate a | |
2303 | response back to GDB. */ | |
2304 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2305 | { | |
2306 | loc = (*loc2p); | |
2307 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2308 | { | |
2309 | if (modified) | |
2310 | { | |
2311 | struct agent_expr *aexpr; | |
2312 | ||
2313 | /* Re-parse the conditions since something changed. In that | |
2314 | case we already freed the condition bytecodes (see | |
2315 | force_breakpoint_reinsertion). We just | |
2316 | need to parse the condition to bytecodes again. */ | |
2317 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2318 | loc->cond_bytecode = aexpr; | |
2319 | ||
2320 | /* Check if we managed to parse the conditional expression | |
2321 | correctly. If not, we will not send this condition | |
2322 | to the target. */ | |
2323 | if (aexpr) | |
2324 | continue; | |
2325 | } | |
2326 | ||
2327 | /* If we have a NULL bytecode expression, it means something | |
2328 | went wrong or we have a null condition expression. */ | |
2329 | if (!loc->cond_bytecode) | |
2330 | { | |
2331 | null_condition_or_parse_error = 1; | |
2332 | break; | |
2333 | } | |
2334 | } | |
2335 | } | |
2336 | ||
2337 | /* If any of these happened, it means we will have to evaluate the conditions | |
2338 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2339 | for all the other duplicate locations, thus we free all of them here. | |
2340 | ||
2341 | This is so we have a finer control over which locations' conditions are | |
2342 | being evaluated by GDB or the remote stub. */ | |
2343 | if (null_condition_or_parse_error) | |
2344 | { | |
2345 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2346 | { | |
2347 | loc = (*loc2p); | |
2348 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2349 | { | |
2350 | /* Only go as far as the first NULL bytecode is | |
2351 | located. */ | |
2352 | if (!loc->cond_bytecode) | |
2353 | return; | |
2354 | ||
2355 | free_agent_expr (loc->cond_bytecode); | |
2356 | loc->cond_bytecode = NULL; | |
2357 | } | |
2358 | } | |
2359 | } | |
2360 | ||
2361 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2362 | for this location's address. */ | |
2363 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2364 | { | |
2365 | loc = (*loc2p); | |
2366 | if (loc->cond | |
2367 | && is_breakpoint (loc->owner) | |
2368 | && loc->pspace->num == bl->pspace->num | |
2369 | && loc->owner->enable_state == bp_enabled | |
2370 | && loc->enabled) | |
2371 | /* Add the condition to the vector. This will be used later to send the | |
2372 | conditions to the target. */ | |
2373 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2374 | loc->cond_bytecode); | |
2375 | } | |
2376 | ||
2377 | return; | |
2378 | } | |
2379 | ||
d3ce09f5 SS |
2380 | /* Parses a command described by string CMD into an agent expression |
2381 | bytecode suitable for evaluation by the bytecode interpreter. | |
2382 | Return NULL if there was any error during parsing. */ | |
2383 | ||
2384 | static struct agent_expr * | |
2385 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2386 | { | |
2387 | struct cleanup *old_cleanups = 0; | |
2388 | struct expression *expr, **argvec; | |
2389 | struct agent_expr *aexpr = NULL; | |
bbc13ae3 KS |
2390 | const char *cmdrest; |
2391 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2392 | struct format_piece *fpieces; |
2393 | int nargs; | |
2394 | struct gdbarch *gdbarch = get_current_arch (); | |
2395 | ||
2396 | if (!cmd) | |
2397 | return NULL; | |
2398 | ||
2399 | cmdrest = cmd; | |
2400 | ||
2401 | if (*cmdrest == ',') | |
2402 | ++cmdrest; | |
bbc13ae3 | 2403 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2404 | |
2405 | if (*cmdrest++ != '"') | |
2406 | error (_("No format string following the location")); | |
2407 | ||
2408 | format_start = cmdrest; | |
2409 | ||
2410 | fpieces = parse_format_string (&cmdrest); | |
2411 | ||
2412 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2413 | ||
2414 | format_end = cmdrest; | |
2415 | ||
2416 | if (*cmdrest++ != '"') | |
2417 | error (_("Bad format string, non-terminated '\"'.")); | |
2418 | ||
bbc13ae3 | 2419 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2420 | |
2421 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2422 | error (_("Invalid argument syntax")); | |
2423 | ||
2424 | if (*cmdrest == ',') | |
2425 | cmdrest++; | |
bbc13ae3 | 2426 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2427 | |
2428 | /* For each argument, make an expression. */ | |
2429 | ||
2430 | argvec = (struct expression **) alloca (strlen (cmd) | |
2431 | * sizeof (struct expression *)); | |
2432 | ||
2433 | nargs = 0; | |
2434 | while (*cmdrest != '\0') | |
2435 | { | |
bbc13ae3 | 2436 | const char *cmd1; |
d3ce09f5 SS |
2437 | |
2438 | cmd1 = cmdrest; | |
2439 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2440 | argvec[nargs++] = expr; | |
2441 | cmdrest = cmd1; | |
2442 | if (*cmdrest == ',') | |
2443 | ++cmdrest; | |
2444 | } | |
2445 | ||
2446 | /* We don't want to stop processing, so catch any errors | |
2447 | that may show up. */ | |
492d29ea | 2448 | TRY |
d3ce09f5 SS |
2449 | { |
2450 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2451 | format_start, format_end - format_start, | |
2452 | fpieces, nargs, argvec); | |
2453 | } | |
492d29ea | 2454 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2455 | { |
2456 | /* If we got here, it means the command could not be parsed to a valid | |
2457 | bytecode expression and thus can't be evaluated on the target's side. | |
2458 | It's no use iterating through the other commands. */ | |
492d29ea | 2459 | aexpr = NULL; |
d3ce09f5 | 2460 | } |
492d29ea PA |
2461 | END_CATCH |
2462 | ||
2463 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2464 | |
d3ce09f5 SS |
2465 | /* We have a valid agent expression, return it. */ |
2466 | return aexpr; | |
2467 | } | |
2468 | ||
2469 | /* Based on location BL, create a list of breakpoint commands to be | |
2470 | passed on to the target. If we have duplicated locations with | |
2471 | different commands, we will add any such to the list. */ | |
2472 | ||
2473 | static void | |
2474 | build_target_command_list (struct bp_location *bl) | |
2475 | { | |
2476 | struct bp_location **locp = NULL, **loc2p; | |
2477 | int null_command_or_parse_error = 0; | |
2478 | int modified = bl->needs_update; | |
2479 | struct bp_location *loc; | |
2480 | ||
8b4f3082 PA |
2481 | /* Release commands left over from a previous insert. */ |
2482 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2483 | ||
41fac0cf | 2484 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2485 | return; |
2486 | ||
41fac0cf PA |
2487 | /* For now, limit to agent-style dprintf breakpoints. */ |
2488 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2489 | return; |
2490 | ||
41fac0cf PA |
2491 | /* For now, if we have any duplicate location that isn't a dprintf, |
2492 | don't install the target-side commands, as that would make the | |
2493 | breakpoint not be reported to the core, and we'd lose | |
2494 | control. */ | |
2495 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2496 | { | |
2497 | loc = (*loc2p); | |
2498 | if (is_breakpoint (loc->owner) | |
2499 | && loc->pspace->num == bl->pspace->num | |
2500 | && loc->owner->type != bp_dprintf) | |
2501 | return; | |
2502 | } | |
2503 | ||
d3ce09f5 SS |
2504 | /* Do a first pass to check for locations with no assigned |
2505 | conditions or conditions that fail to parse to a valid agent expression | |
2506 | bytecode. If any of these happen, then it's no use to send conditions | |
2507 | to the target since this location will always trigger and generate a | |
2508 | response back to GDB. */ | |
2509 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2510 | { | |
2511 | loc = (*loc2p); | |
2512 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2513 | { | |
2514 | if (modified) | |
2515 | { | |
2516 | struct agent_expr *aexpr; | |
2517 | ||
2518 | /* Re-parse the commands since something changed. In that | |
2519 | case we already freed the command bytecodes (see | |
2520 | force_breakpoint_reinsertion). We just | |
2521 | need to parse the command to bytecodes again. */ | |
2522 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2523 | loc->owner->extra_string); | |
2524 | loc->cmd_bytecode = aexpr; | |
2525 | ||
2526 | if (!aexpr) | |
2527 | continue; | |
2528 | } | |
2529 | ||
2530 | /* If we have a NULL bytecode expression, it means something | |
2531 | went wrong or we have a null command expression. */ | |
2532 | if (!loc->cmd_bytecode) | |
2533 | { | |
2534 | null_command_or_parse_error = 1; | |
2535 | break; | |
2536 | } | |
2537 | } | |
2538 | } | |
2539 | ||
2540 | /* If anything failed, then we're not doing target-side commands, | |
2541 | and so clean up. */ | |
2542 | if (null_command_or_parse_error) | |
2543 | { | |
2544 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2545 | { | |
2546 | loc = (*loc2p); | |
2547 | if (is_breakpoint (loc->owner) | |
2548 | && loc->pspace->num == bl->pspace->num) | |
2549 | { | |
2550 | /* Only go as far as the first NULL bytecode is | |
2551 | located. */ | |
40fb6c5e | 2552 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2553 | return; |
2554 | ||
40fb6c5e HZ |
2555 | free_agent_expr (loc->cmd_bytecode); |
2556 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2557 | } |
2558 | } | |
2559 | } | |
2560 | ||
2561 | /* No NULL commands or failed bytecode generation. Build a command list | |
2562 | for this location's address. */ | |
2563 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2564 | { | |
2565 | loc = (*loc2p); | |
2566 | if (loc->owner->extra_string | |
2567 | && is_breakpoint (loc->owner) | |
2568 | && loc->pspace->num == bl->pspace->num | |
2569 | && loc->owner->enable_state == bp_enabled | |
2570 | && loc->enabled) | |
2571 | /* Add the command to the vector. This will be used later | |
2572 | to send the commands to the target. */ | |
2573 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2574 | loc->cmd_bytecode); | |
2575 | } | |
2576 | ||
2577 | bl->target_info.persist = 0; | |
2578 | /* Maybe flag this location as persistent. */ | |
2579 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2580 | bl->target_info.persist = 1; | |
2581 | } | |
2582 | ||
35df4500 TJB |
2583 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2584 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2585 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2586 | Returns 0 for success, 1 if the bp_location type is not supported or |
2587 | -1 for failure. | |
879bfdc2 | 2588 | |
4a64f543 MS |
2589 | NOTE drow/2003-09-09: This routine could be broken down to an |
2590 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2591 | static int |
35df4500 | 2592 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2593 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2594 | int *disabled_breaks, |
dd61ec5c MW |
2595 | int *hw_breakpoint_error, |
2596 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2597 | { |
0000e5cc PA |
2598 | enum errors bp_err = GDB_NO_ERROR; |
2599 | const char *bp_err_message = NULL; | |
879bfdc2 | 2600 | |
b775012e | 2601 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2602 | return 0; |
2603 | ||
35c63cd8 JB |
2604 | /* Note we don't initialize bl->target_info, as that wipes out |
2605 | the breakpoint location's shadow_contents if the breakpoint | |
2606 | is still inserted at that location. This in turn breaks | |
2607 | target_read_memory which depends on these buffers when | |
2608 | a memory read is requested at the breakpoint location: | |
2609 | Once the target_info has been wiped, we fail to see that | |
2610 | we have a breakpoint inserted at that address and thus | |
2611 | read the breakpoint instead of returning the data saved in | |
2612 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2613 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2614 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2615 | bl->target_info.length = bl->length; |
8181d85f | 2616 | |
b775012e LM |
2617 | /* When working with target-side conditions, we must pass all the conditions |
2618 | for the same breakpoint address down to the target since GDB will not | |
2619 | insert those locations. With a list of breakpoint conditions, the target | |
2620 | can decide when to stop and notify GDB. */ | |
2621 | ||
2622 | if (is_breakpoint (bl->owner)) | |
2623 | { | |
2624 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2625 | build_target_command_list (bl); |
2626 | /* Reset the modification marker. */ | |
b775012e LM |
2627 | bl->needs_update = 0; |
2628 | } | |
2629 | ||
35df4500 TJB |
2630 | if (bl->loc_type == bp_loc_software_breakpoint |
2631 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2632 | { |
35df4500 | 2633 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2634 | { |
2635 | /* If the explicitly specified breakpoint type | |
2636 | is not hardware breakpoint, check the memory map to see | |
2637 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2638 | |
765dc015 VP |
2639 | Two important cases are: |
2640 | - location type is not hardware breakpoint, memory | |
2641 | is readonly. We change the type of the location to | |
2642 | hardware breakpoint. | |
4a64f543 MS |
2643 | - location type is hardware breakpoint, memory is |
2644 | read-write. This means we've previously made the | |
2645 | location hardware one, but then the memory map changed, | |
2646 | so we undo. | |
765dc015 | 2647 | |
4a64f543 MS |
2648 | When breakpoints are removed, remove_breakpoints will use |
2649 | location types we've just set here, the only possible | |
2650 | problem is that memory map has changed during running | |
2651 | program, but it's not going to work anyway with current | |
2652 | gdb. */ | |
765dc015 | 2653 | struct mem_region *mr |
0d5ed153 | 2654 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2655 | |
2656 | if (mr) | |
2657 | { | |
2658 | if (automatic_hardware_breakpoints) | |
2659 | { | |
765dc015 VP |
2660 | enum bp_loc_type new_type; |
2661 | ||
2662 | if (mr->attrib.mode != MEM_RW) | |
2663 | new_type = bp_loc_hardware_breakpoint; | |
2664 | else | |
2665 | new_type = bp_loc_software_breakpoint; | |
2666 | ||
35df4500 | 2667 | if (new_type != bl->loc_type) |
765dc015 VP |
2668 | { |
2669 | static int said = 0; | |
cc59ec59 | 2670 | |
35df4500 | 2671 | bl->loc_type = new_type; |
765dc015 VP |
2672 | if (!said) |
2673 | { | |
3e43a32a MS |
2674 | fprintf_filtered (gdb_stdout, |
2675 | _("Note: automatically using " | |
2676 | "hardware breakpoints for " | |
2677 | "read-only addresses.\n")); | |
765dc015 VP |
2678 | said = 1; |
2679 | } | |
2680 | } | |
2681 | } | |
35df4500 | 2682 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2683 | && mr->attrib.mode != MEM_RW) |
2684 | { | |
2685 | fprintf_unfiltered (tmp_error_stream, | |
2686 | _("Cannot insert breakpoint %d.\n" | |
2687 | "Cannot set software breakpoint " | |
2688 | "at read-only address %s\n"), | |
2689 | bl->owner->number, | |
2690 | paddress (bl->gdbarch, bl->address)); | |
2691 | return 1; | |
2692 | } | |
765dc015 VP |
2693 | } |
2694 | } | |
2695 | ||
879bfdc2 DJ |
2696 | /* First check to see if we have to handle an overlay. */ |
2697 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2698 | || bl->section == NULL |
2699 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2700 | { |
2701 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2702 | TRY |
dd61ec5c | 2703 | { |
0000e5cc PA |
2704 | int val; |
2705 | ||
dd61ec5c | 2706 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2707 | if (val) |
2708 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2709 | } |
492d29ea | 2710 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2711 | { |
0000e5cc PA |
2712 | bp_err = e.error; |
2713 | bp_err_message = e.message; | |
dd61ec5c | 2714 | } |
492d29ea | 2715 | END_CATCH |
879bfdc2 DJ |
2716 | } |
2717 | else | |
2718 | { | |
4a64f543 | 2719 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2720 | Shall we set a breakpoint at the LMA? */ |
2721 | if (!overlay_events_enabled) | |
2722 | { | |
2723 | /* Yes -- overlay event support is not active, | |
2724 | so we must try to set a breakpoint at the LMA. | |
2725 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2726 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2727 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2728 | bl->owner->number); |
879bfdc2 DJ |
2729 | else |
2730 | { | |
35df4500 TJB |
2731 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2732 | bl->section); | |
879bfdc2 | 2733 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2734 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2735 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2736 | |
2737 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2738 | TRY |
0000e5cc PA |
2739 | { |
2740 | int val; | |
2741 | ||
2742 | val = target_insert_breakpoint (bl->gdbarch, | |
2743 | &bl->overlay_target_info); | |
2744 | if (val) | |
2745 | bp_err = GENERIC_ERROR; | |
2746 | } | |
492d29ea | 2747 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2748 | { |
2749 | bp_err = e.error; | |
2750 | bp_err_message = e.message; | |
2751 | } | |
492d29ea | 2752 | END_CATCH |
0000e5cc PA |
2753 | |
2754 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2755 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2756 | "Overlay breakpoint %d " |
2757 | "failed: in ROM?\n", | |
35df4500 | 2758 | bl->owner->number); |
879bfdc2 DJ |
2759 | } |
2760 | } | |
2761 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2762 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2763 | { |
2764 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2765 | TRY |
dd61ec5c | 2766 | { |
0000e5cc PA |
2767 | int val; |
2768 | ||
dd61ec5c | 2769 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2770 | if (val) |
2771 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2772 | } |
492d29ea | 2773 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2774 | { |
0000e5cc PA |
2775 | bp_err = e.error; |
2776 | bp_err_message = e.message; | |
dd61ec5c | 2777 | } |
492d29ea | 2778 | END_CATCH |
879bfdc2 DJ |
2779 | } |
2780 | else | |
2781 | { | |
2782 | /* No. This breakpoint will not be inserted. | |
2783 | No error, but do not mark the bp as 'inserted'. */ | |
2784 | return 0; | |
2785 | } | |
2786 | } | |
2787 | ||
0000e5cc | 2788 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2789 | { |
2790 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2791 | |
2792 | /* In some cases, we might not be able to insert a | |
2793 | breakpoint in a shared library that has already been | |
2794 | removed, but we have not yet processed the shlib unload | |
2795 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2796 | breakpoint insertion themselves can't tell why the |
2797 | breakpoint insertion failed (e.g., the remote target | |
2798 | doesn't define error codes), so we must treat generic | |
2799 | errors as memory errors. */ | |
0000e5cc | 2800 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2801 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2802 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2803 | || shared_objfile_contains_address_p (bl->pspace, |
2804 | bl->address))) | |
879bfdc2 | 2805 | { |
4a64f543 | 2806 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2807 | bl->shlib_disabled = 1; |
8d3788bd | 2808 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2809 | if (!*disabled_breaks) |
2810 | { | |
2811 | fprintf_unfiltered (tmp_error_stream, | |
2812 | "Cannot insert breakpoint %d.\n", | |
2813 | bl->owner->number); | |
2814 | fprintf_unfiltered (tmp_error_stream, | |
2815 | "Temporarily disabling shared " | |
2816 | "library breakpoints:\n"); | |
2817 | } | |
2818 | *disabled_breaks = 1; | |
879bfdc2 | 2819 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2820 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2821 | return 0; |
879bfdc2 DJ |
2822 | } |
2823 | else | |
879bfdc2 | 2824 | { |
35df4500 | 2825 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2826 | { |
0000e5cc PA |
2827 | *hw_breakpoint_error = 1; |
2828 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2829 | fprintf_unfiltered (tmp_error_stream, |
2830 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2831 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2832 | if (bp_err_message != NULL) | |
2833 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2834 | } |
2835 | else | |
2836 | { | |
0000e5cc PA |
2837 | if (bp_err_message == NULL) |
2838 | { | |
2839 | char *message | |
2840 | = memory_error_message (TARGET_XFER_E_IO, | |
2841 | bl->gdbarch, bl->address); | |
2842 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2843 | ||
2844 | fprintf_unfiltered (tmp_error_stream, | |
2845 | "Cannot insert breakpoint %d.\n" | |
2846 | "%s\n", | |
2847 | bl->owner->number, message); | |
2848 | do_cleanups (old_chain); | |
2849 | } | |
2850 | else | |
2851 | { | |
2852 | fprintf_unfiltered (tmp_error_stream, | |
2853 | "Cannot insert breakpoint %d: %s\n", | |
2854 | bl->owner->number, | |
2855 | bp_err_message); | |
2856 | } | |
879bfdc2 | 2857 | } |
0000e5cc | 2858 | return 1; |
879bfdc2 DJ |
2859 | |
2860 | } | |
2861 | } | |
2862 | else | |
35df4500 | 2863 | bl->inserted = 1; |
879bfdc2 | 2864 | |
0000e5cc | 2865 | return 0; |
879bfdc2 DJ |
2866 | } |
2867 | ||
35df4500 | 2868 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2869 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2870 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2871 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2872 | { |
0000e5cc PA |
2873 | int val; |
2874 | ||
77b06cd7 TJB |
2875 | gdb_assert (bl->owner->ops != NULL |
2876 | && bl->owner->ops->insert_location != NULL); | |
2877 | ||
2878 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2879 | |
2880 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2881 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2882 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2883 | { |
2884 | struct bp_location *loc, **loc_temp; | |
2885 | ||
2886 | /* But don't try to insert it, if there's already another | |
2887 | hw_access location that would be considered a duplicate | |
2888 | of this one. */ | |
2889 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2890 | if (loc != bl |
85d721b8 | 2891 | && loc->watchpoint_type == hw_access |
35df4500 | 2892 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2893 | { |
35df4500 TJB |
2894 | bl->duplicate = 1; |
2895 | bl->inserted = 1; | |
2896 | bl->target_info = loc->target_info; | |
2897 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2898 | val = 0; |
2899 | break; | |
2900 | } | |
2901 | ||
2902 | if (val == 1) | |
2903 | { | |
77b06cd7 TJB |
2904 | bl->watchpoint_type = hw_access; |
2905 | val = bl->owner->ops->insert_location (bl); | |
2906 | ||
2907 | if (val) | |
2908 | /* Back to the original value. */ | |
2909 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2910 | } |
2911 | } | |
2912 | ||
35df4500 | 2913 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2914 | } |
2915 | ||
35df4500 | 2916 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2917 | { |
0000e5cc PA |
2918 | int val; |
2919 | ||
77b06cd7 TJB |
2920 | gdb_assert (bl->owner->ops != NULL |
2921 | && bl->owner->ops->insert_location != NULL); | |
2922 | ||
2923 | val = bl->owner->ops->insert_location (bl); | |
2924 | if (val) | |
2925 | { | |
2926 | bl->owner->enable_state = bp_disabled; | |
2927 | ||
2928 | if (val == 1) | |
2929 | warning (_("\ | |
2930 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2931 | of catchpoint."), bl->owner->number); | |
2932 | else | |
2933 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2934 | } | |
2935 | ||
2936 | bl->inserted = (val == 0); | |
1640b821 DJ |
2937 | |
2938 | /* We've already printed an error message if there was a problem | |
2939 | inserting this catchpoint, and we've disabled the catchpoint, | |
2940 | so just return success. */ | |
2941 | return 0; | |
879bfdc2 DJ |
2942 | } |
2943 | ||
2944 | return 0; | |
2945 | } | |
2946 | ||
6c95b8df PA |
2947 | /* This function is called when program space PSPACE is about to be |
2948 | deleted. It takes care of updating breakpoints to not reference | |
2949 | PSPACE anymore. */ | |
2950 | ||
2951 | void | |
2952 | breakpoint_program_space_exit (struct program_space *pspace) | |
2953 | { | |
2954 | struct breakpoint *b, *b_temp; | |
876fa593 | 2955 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2956 | |
2957 | /* Remove any breakpoint that was set through this program space. */ | |
2958 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2959 | { | |
2960 | if (b->pspace == pspace) | |
2961 | delete_breakpoint (b); | |
2962 | } | |
2963 | ||
2964 | /* Breakpoints set through other program spaces could have locations | |
2965 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2966 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2967 | { |
2968 | struct bp_location *tmp; | |
2969 | ||
2970 | if (loc->pspace == pspace) | |
2971 | { | |
2bdf28a0 | 2972 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2973 | if (loc->owner->loc == loc) |
2974 | loc->owner->loc = loc->next; | |
2975 | else | |
2976 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2977 | if (tmp->next == loc) | |
2978 | { | |
2979 | tmp->next = loc->next; | |
2980 | break; | |
2981 | } | |
2982 | } | |
2983 | } | |
2984 | ||
2985 | /* Now update the global location list to permanently delete the | |
2986 | removed locations above. */ | |
44702360 | 2987 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2988 | } |
2989 | ||
74960c60 VP |
2990 | /* Make sure all breakpoints are inserted in inferior. |
2991 | Throws exception on any error. | |
2992 | A breakpoint that is already inserted won't be inserted | |
2993 | again, so calling this function twice is safe. */ | |
2994 | void | |
2995 | insert_breakpoints (void) | |
2996 | { | |
2997 | struct breakpoint *bpt; | |
2998 | ||
2999 | ALL_BREAKPOINTS (bpt) | |
3000 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
3001 | { |
3002 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3003 | ||
3004 | update_watchpoint (w, 0 /* don't reparse. */); | |
3005 | } | |
74960c60 | 3006 | |
04086b45 PA |
3007 | /* Updating watchpoints creates new locations, so update the global |
3008 | location list. Explicitly tell ugll to insert locations and | |
3009 | ignore breakpoints_always_inserted_mode. */ | |
3010 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3011 | } |
3012 | ||
20388dd6 YQ |
3013 | /* Invoke CALLBACK for each of bp_location. */ |
3014 | ||
3015 | void | |
3016 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3017 | { | |
3018 | struct bp_location *loc, **loc_tmp; | |
3019 | ||
3020 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3021 | { | |
3022 | callback (loc, NULL); | |
3023 | } | |
3024 | } | |
3025 | ||
b775012e LM |
3026 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3027 | target. It is the case with deleting and disabling of breakpoints when using | |
3028 | always-inserted mode. */ | |
3029 | ||
3030 | static void | |
3031 | update_inserted_breakpoint_locations (void) | |
3032 | { | |
3033 | struct bp_location *bl, **blp_tmp; | |
3034 | int error_flag = 0; | |
3035 | int val = 0; | |
3036 | int disabled_breaks = 0; | |
3037 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3038 | int hw_bp_details_reported = 0; |
b775012e LM |
3039 | |
3040 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
3041 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
3042 | ||
3043 | /* Explicitly mark the warning -- this will only be printed if | |
3044 | there was an error. */ | |
3045 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
3046 | ||
3047 | save_current_space_and_thread (); | |
3048 | ||
3049 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3050 | { | |
3051 | /* We only want to update software breakpoints and hardware | |
3052 | breakpoints. */ | |
3053 | if (!is_breakpoint (bl->owner)) | |
3054 | continue; | |
3055 | ||
3056 | /* We only want to update locations that are already inserted | |
3057 | and need updating. This is to avoid unwanted insertion during | |
3058 | deletion of breakpoints. */ | |
3059 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3060 | continue; | |
3061 | ||
3062 | switch_to_program_space_and_thread (bl->pspace); | |
3063 | ||
3064 | /* For targets that support global breakpoints, there's no need | |
3065 | to select an inferior to insert breakpoint to. In fact, even | |
3066 | if we aren't attached to any process yet, we should still | |
3067 | insert breakpoints. */ | |
f5656ead | 3068 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3069 | && ptid_equal (inferior_ptid, null_ptid)) |
3070 | continue; | |
3071 | ||
3072 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 3073 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3074 | if (val) |
3075 | error_flag = val; | |
3076 | } | |
3077 | ||
3078 | if (error_flag) | |
3079 | { | |
3080 | target_terminal_ours_for_output (); | |
3081 | error_stream (tmp_error_stream); | |
3082 | } | |
3083 | ||
3084 | do_cleanups (cleanups); | |
3085 | } | |
3086 | ||
c30eee59 | 3087 | /* Used when starting or continuing the program. */ |
c906108c | 3088 | |
74960c60 VP |
3089 | static void |
3090 | insert_breakpoint_locations (void) | |
c906108c | 3091 | { |
a5606eee | 3092 | struct breakpoint *bpt; |
35df4500 | 3093 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3094 | int error_flag = 0; |
c906108c | 3095 | int val = 0; |
3fbb6ffa | 3096 | int disabled_breaks = 0; |
81d0cc19 | 3097 | int hw_breakpoint_error = 0; |
dd61ec5c | 3098 | int hw_bp_error_explained_already = 0; |
c906108c | 3099 | |
81d0cc19 | 3100 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 3101 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 3102 | |
81d0cc19 GS |
3103 | /* Explicitly mark the warning -- this will only be printed if |
3104 | there was an error. */ | |
3105 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
3106 | |
3107 | save_current_space_and_thread (); | |
3108 | ||
35df4500 | 3109 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3110 | { |
b775012e | 3111 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3112 | continue; |
3113 | ||
4a64f543 MS |
3114 | /* There is no point inserting thread-specific breakpoints if |
3115 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3116 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
3117 | if (bl->owner->thread != -1 |
3118 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
3119 | continue; |
3120 | ||
35df4500 | 3121 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3122 | |
3123 | /* For targets that support global breakpoints, there's no need | |
3124 | to select an inferior to insert breakpoint to. In fact, even | |
3125 | if we aren't attached to any process yet, we should still | |
3126 | insert breakpoints. */ | |
f5656ead | 3127 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3128 | && ptid_equal (inferior_ptid, null_ptid)) |
3129 | continue; | |
3130 | ||
3fbb6ffa | 3131 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3132 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3133 | if (val) |
eacd795a | 3134 | error_flag = val; |
879bfdc2 | 3135 | } |
c906108c | 3136 | |
4a64f543 MS |
3137 | /* If we failed to insert all locations of a watchpoint, remove |
3138 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3139 | ALL_BREAKPOINTS (bpt) |
3140 | { | |
3141 | int some_failed = 0; | |
3142 | struct bp_location *loc; | |
3143 | ||
3144 | if (!is_hardware_watchpoint (bpt)) | |
3145 | continue; | |
3146 | ||
d6b74ac4 | 3147 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3148 | continue; |
74960c60 VP |
3149 | |
3150 | if (bpt->disposition == disp_del_at_next_stop) | |
3151 | continue; | |
a5606eee VP |
3152 | |
3153 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3154 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3155 | { |
3156 | some_failed = 1; | |
3157 | break; | |
3158 | } | |
3159 | if (some_failed) | |
3160 | { | |
3161 | for (loc = bpt->loc; loc; loc = loc->next) | |
3162 | if (loc->inserted) | |
3163 | remove_breakpoint (loc, mark_uninserted); | |
3164 | ||
3165 | hw_breakpoint_error = 1; | |
3166 | fprintf_unfiltered (tmp_error_stream, | |
3167 | "Could not insert hardware watchpoint %d.\n", | |
3168 | bpt->number); | |
eacd795a | 3169 | error_flag = -1; |
a5606eee VP |
3170 | } |
3171 | } | |
3172 | ||
eacd795a | 3173 | if (error_flag) |
81d0cc19 GS |
3174 | { |
3175 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3176 | message about possibly exhausted resources. */ | |
dd61ec5c | 3177 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3178 | { |
c6510018 MS |
3179 | fprintf_unfiltered (tmp_error_stream, |
3180 | "Could not insert hardware breakpoints:\n\ | |
3181 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3182 | } |
81d0cc19 GS |
3183 | target_terminal_ours_for_output (); |
3184 | error_stream (tmp_error_stream); | |
3185 | } | |
f7545552 TT |
3186 | |
3187 | do_cleanups (cleanups); | |
c906108c SS |
3188 | } |
3189 | ||
c30eee59 TJB |
3190 | /* Used when the program stops. |
3191 | Returns zero if successful, or non-zero if there was a problem | |
3192 | removing a breakpoint location. */ | |
3193 | ||
c906108c | 3194 | int |
fba45db2 | 3195 | remove_breakpoints (void) |
c906108c | 3196 | { |
35df4500 | 3197 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3198 | int val = 0; |
c906108c | 3199 | |
35df4500 | 3200 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3201 | { |
1e4d1764 | 3202 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 3203 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 3204 | } |
3a1bae8e | 3205 | return val; |
c906108c SS |
3206 | } |
3207 | ||
49fa26b0 PA |
3208 | /* When a thread exits, remove breakpoints that are related to |
3209 | that thread. */ | |
3210 | ||
3211 | static void | |
3212 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3213 | { | |
3214 | struct breakpoint *b, *b_tmp; | |
3215 | ||
3216 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3217 | { | |
96181529 | 3218 | if (b->thread == tp->num && user_breakpoint_p (b)) |
49fa26b0 PA |
3219 | { |
3220 | b->disposition = disp_del_at_next_stop; | |
3221 | ||
3222 | printf_filtered (_("\ | |
46ecd527 | 3223 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
49fa26b0 PA |
3224 | b->number, tp->num); |
3225 | ||
3226 | /* Hide it from the user. */ | |
3227 | b->number = 0; | |
3228 | } | |
3229 | } | |
3230 | } | |
3231 | ||
6c95b8df PA |
3232 | /* Remove breakpoints of process PID. */ |
3233 | ||
3234 | int | |
3235 | remove_breakpoints_pid (int pid) | |
3236 | { | |
35df4500 | 3237 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3238 | int val; |
3239 | struct inferior *inf = find_inferior_pid (pid); | |
3240 | ||
35df4500 | 3241 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3242 | { |
35df4500 | 3243 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3244 | continue; |
3245 | ||
fc126975 | 3246 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3247 | { |
35df4500 | 3248 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
3249 | if (val != 0) |
3250 | return val; | |
3251 | } | |
3252 | } | |
3253 | return 0; | |
3254 | } | |
3255 | ||
c906108c | 3256 | int |
fba45db2 | 3257 | reattach_breakpoints (int pid) |
c906108c | 3258 | { |
6c95b8df | 3259 | struct cleanup *old_chain; |
35df4500 | 3260 | struct bp_location *bl, **blp_tmp; |
c906108c | 3261 | int val; |
86b887df | 3262 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3263 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3264 | struct inferior *inf; |
3265 | struct thread_info *tp; | |
3266 | ||
3267 | tp = any_live_thread_of_process (pid); | |
3268 | if (tp == NULL) | |
3269 | return 1; | |
3270 | ||
3271 | inf = find_inferior_pid (pid); | |
3272 | old_chain = save_inferior_ptid (); | |
3273 | ||
3274 | inferior_ptid = tp->ptid; | |
a4954f26 | 3275 | |
86b887df | 3276 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3277 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3278 | |
35df4500 | 3279 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3280 | { |
35df4500 | 3281 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3282 | continue; |
3283 | ||
35df4500 | 3284 | if (bl->inserted) |
c5aa993b | 3285 | { |
35df4500 | 3286 | bl->inserted = 0; |
dd61ec5c | 3287 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3288 | if (val != 0) |
3289 | { | |
ce696e05 | 3290 | do_cleanups (old_chain); |
c5aa993b JM |
3291 | return val; |
3292 | } | |
3293 | } | |
3294 | } | |
ce696e05 | 3295 | do_cleanups (old_chain); |
c906108c SS |
3296 | return 0; |
3297 | } | |
3298 | ||
e58b0e63 PA |
3299 | static int internal_breakpoint_number = -1; |
3300 | ||
84f4c1fe PM |
3301 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3302 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3303 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3304 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3305 | breakpoint_count and that value incremented. Internal breakpoints |
3306 | do not set the internal var bpnum. */ | |
3307 | static void | |
3308 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3309 | { | |
3310 | if (internal) | |
3311 | b->number = internal_breakpoint_number--; | |
3312 | else | |
3313 | { | |
3314 | set_breakpoint_count (breakpoint_count + 1); | |
3315 | b->number = breakpoint_count; | |
3316 | } | |
3317 | } | |
3318 | ||
e62c965a | 3319 | static struct breakpoint * |
a6d9a66e | 3320 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3321 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3322 | const struct breakpoint_ops *ops) |
e62c965a | 3323 | { |
e62c965a PP |
3324 | struct symtab_and_line sal; |
3325 | struct breakpoint *b; | |
3326 | ||
4a64f543 | 3327 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3328 | |
3329 | sal.pc = address; | |
3330 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3331 | sal.pspace = current_program_space; |
e62c965a | 3332 | |
06edf0c0 | 3333 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3334 | b->number = internal_breakpoint_number--; |
3335 | b->disposition = disp_donttouch; | |
3336 | ||
3337 | return b; | |
3338 | } | |
3339 | ||
17450429 PP |
3340 | static const char *const longjmp_names[] = |
3341 | { | |
3342 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3343 | }; | |
3344 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3345 | ||
3346 | /* Per-objfile data private to breakpoint.c. */ | |
3347 | struct breakpoint_objfile_data | |
3348 | { | |
3349 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3350 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3351 | |
3352 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3353 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3354 | |
28106bc2 SDJ |
3355 | /* True if we have looked for longjmp probes. */ |
3356 | int longjmp_searched; | |
3357 | ||
3358 | /* SystemTap probe points for longjmp (if any). */ | |
3359 | VEC (probe_p) *longjmp_probes; | |
3360 | ||
17450429 | 3361 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3362 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3363 | |
3364 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3365 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3366 | |
3367 | /* True if we have looked for exception probes. */ | |
3368 | int exception_searched; | |
3369 | ||
3370 | /* SystemTap probe points for unwinding (if any). */ | |
3371 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3372 | }; |
3373 | ||
3374 | static const struct objfile_data *breakpoint_objfile_key; | |
3375 | ||
3376 | /* Minimal symbol not found sentinel. */ | |
3377 | static struct minimal_symbol msym_not_found; | |
3378 | ||
3379 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3380 | ||
3381 | static int | |
3382 | msym_not_found_p (const struct minimal_symbol *msym) | |
3383 | { | |
3384 | return msym == &msym_not_found; | |
3385 | } | |
3386 | ||
3387 | /* Return per-objfile data needed by breakpoint.c. | |
3388 | Allocate the data if necessary. */ | |
3389 | ||
3390 | static struct breakpoint_objfile_data * | |
3391 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3392 | { | |
3393 | struct breakpoint_objfile_data *bp_objfile_data; | |
3394 | ||
3395 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
3396 | if (bp_objfile_data == NULL) | |
3397 | { | |
3398 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
3399 | sizeof (*bp_objfile_data)); | |
3400 | ||
3401 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3402 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3403 | } | |
3404 | return bp_objfile_data; | |
3405 | } | |
3406 | ||
28106bc2 SDJ |
3407 | static void |
3408 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3409 | { | |
3410 | struct breakpoint_objfile_data *bp_objfile_data = data; | |
3411 | ||
3412 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3413 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3414 | } | |
3415 | ||
e62c965a | 3416 | static void |
af02033e | 3417 | create_overlay_event_breakpoint (void) |
e62c965a | 3418 | { |
69de3c6a | 3419 | struct objfile *objfile; |
af02033e | 3420 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3421 | |
69de3c6a PP |
3422 | ALL_OBJFILES (objfile) |
3423 | { | |
3424 | struct breakpoint *b; | |
17450429 PP |
3425 | struct breakpoint_objfile_data *bp_objfile_data; |
3426 | CORE_ADDR addr; | |
f00aae0f | 3427 | char *p; |
69de3c6a | 3428 | |
17450429 PP |
3429 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3430 | ||
3b7344d5 | 3431 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3432 | continue; |
3433 | ||
3b7344d5 | 3434 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3435 | { |
3b7344d5 | 3436 | struct bound_minimal_symbol m; |
17450429 PP |
3437 | |
3438 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3439 | if (m.minsym == NULL) |
17450429 PP |
3440 | { |
3441 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3442 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3443 | continue; |
3444 | } | |
3445 | bp_objfile_data->overlay_msym = m; | |
3446 | } | |
e62c965a | 3447 | |
77e371c0 | 3448 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3449 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3450 | bp_overlay_event, |
3451 | &internal_breakpoint_ops); | |
f00aae0f KS |
3452 | p = ASTRDUP (func_name); |
3453 | b->location = new_linespec_location (&p); | |
e62c965a | 3454 | |
69de3c6a PP |
3455 | if (overlay_debugging == ovly_auto) |
3456 | { | |
3457 | b->enable_state = bp_enabled; | |
3458 | overlay_events_enabled = 1; | |
3459 | } | |
3460 | else | |
3461 | { | |
3462 | b->enable_state = bp_disabled; | |
3463 | overlay_events_enabled = 0; | |
3464 | } | |
e62c965a | 3465 | } |
44702360 | 3466 | update_global_location_list (UGLL_MAY_INSERT); |
e62c965a PP |
3467 | } |
3468 | ||
0fd8e87f | 3469 | static void |
af02033e | 3470 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3471 | { |
6c95b8df | 3472 | struct program_space *pspace; |
6c95b8df PA |
3473 | struct cleanup *old_chain; |
3474 | ||
3475 | old_chain = save_current_program_space (); | |
0fd8e87f | 3476 | |
6c95b8df | 3477 | ALL_PSPACES (pspace) |
af02033e PP |
3478 | { |
3479 | struct objfile *objfile; | |
3480 | ||
3481 | set_current_program_space (pspace); | |
3482 | ||
3483 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3484 | { |
af02033e PP |
3485 | int i; |
3486 | struct gdbarch *gdbarch; | |
17450429 | 3487 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3488 | |
af02033e | 3489 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3490 | |
17450429 PP |
3491 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3492 | ||
28106bc2 SDJ |
3493 | if (!bp_objfile_data->longjmp_searched) |
3494 | { | |
25f9533e SDJ |
3495 | VEC (probe_p) *ret; |
3496 | ||
3497 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3498 | if (ret != NULL) | |
3499 | { | |
3500 | /* We are only interested in checking one element. */ | |
3501 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3502 | ||
3503 | if (!can_evaluate_probe_arguments (p)) | |
3504 | { | |
3505 | /* We cannot use the probe interface here, because it does | |
3506 | not know how to evaluate arguments. */ | |
3507 | VEC_free (probe_p, ret); | |
3508 | ret = NULL; | |
3509 | } | |
3510 | } | |
3511 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3512 | bp_objfile_data->longjmp_searched = 1; |
3513 | } | |
3514 | ||
3515 | if (bp_objfile_data->longjmp_probes != NULL) | |
3516 | { | |
3517 | int i; | |
3518 | struct probe *probe; | |
3519 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
f00aae0f | 3520 | char *p; |
28106bc2 SDJ |
3521 | |
3522 | for (i = 0; | |
3523 | VEC_iterate (probe_p, | |
3524 | bp_objfile_data->longjmp_probes, | |
3525 | i, probe); | |
3526 | ++i) | |
3527 | { | |
3528 | struct breakpoint *b; | |
3529 | ||
729662a5 TT |
3530 | b = create_internal_breakpoint (gdbarch, |
3531 | get_probe_address (probe, | |
3532 | objfile), | |
28106bc2 SDJ |
3533 | bp_longjmp_master, |
3534 | &internal_breakpoint_ops); | |
f00aae0f KS |
3535 | p = ASTRDUP ("-probe-stap libc:longjmp"); |
3536 | b->location = new_linespec_location (&p); | |
28106bc2 SDJ |
3537 | b->enable_state = bp_disabled; |
3538 | } | |
3539 | ||
3540 | continue; | |
3541 | } | |
3542 | ||
0569175e TSD |
3543 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3544 | continue; | |
3545 | ||
17450429 | 3546 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3547 | { |
3548 | struct breakpoint *b; | |
af02033e | 3549 | const char *func_name; |
17450429 | 3550 | CORE_ADDR addr; |
f00aae0f | 3551 | char *p; |
6c95b8df | 3552 | |
3b7344d5 | 3553 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3554 | continue; |
0fd8e87f | 3555 | |
17450429 | 3556 | func_name = longjmp_names[i]; |
3b7344d5 | 3557 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3558 | { |
3b7344d5 | 3559 | struct bound_minimal_symbol m; |
17450429 PP |
3560 | |
3561 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3562 | if (m.minsym == NULL) |
17450429 PP |
3563 | { |
3564 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3565 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3566 | continue; |
3567 | } | |
3568 | bp_objfile_data->longjmp_msym[i] = m; | |
3569 | } | |
3570 | ||
77e371c0 | 3571 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3572 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3573 | &internal_breakpoint_ops); | |
f00aae0f KS |
3574 | p = ASTRDUP (func_name); |
3575 | b->location = new_linespec_location (&p); | |
af02033e PP |
3576 | b->enable_state = bp_disabled; |
3577 | } | |
0fd8e87f | 3578 | } |
af02033e | 3579 | } |
44702360 | 3580 | update_global_location_list (UGLL_MAY_INSERT); |
6c95b8df PA |
3581 | |
3582 | do_cleanups (old_chain); | |
0fd8e87f UW |
3583 | } |
3584 | ||
af02033e | 3585 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3586 | static void |
af02033e | 3587 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3588 | { |
3589 | struct program_space *pspace; | |
aa7d318d | 3590 | struct cleanup *old_chain; |
af02033e | 3591 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3592 | |
3593 | old_chain = save_current_program_space (); | |
3594 | ||
3595 | ALL_PSPACES (pspace) | |
17450429 PP |
3596 | { |
3597 | struct objfile *objfile; | |
3598 | CORE_ADDR addr; | |
3599 | ||
3600 | set_current_program_space (pspace); | |
3601 | ||
aa7d318d TT |
3602 | ALL_OBJFILES (objfile) |
3603 | { | |
3604 | struct breakpoint *b; | |
17450429 | 3605 | struct breakpoint_objfile_data *bp_objfile_data; |
f00aae0f | 3606 | char *p; |
aa7d318d | 3607 | |
17450429 | 3608 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3609 | |
3b7344d5 | 3610 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3611 | continue; |
3612 | ||
3b7344d5 | 3613 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3614 | { |
3b7344d5 | 3615 | struct bound_minimal_symbol m; |
17450429 PP |
3616 | |
3617 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3618 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3619 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3620 | { |
3621 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3622 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3623 | continue; |
3624 | } | |
3625 | bp_objfile_data->terminate_msym = m; | |
3626 | } | |
aa7d318d | 3627 | |
77e371c0 | 3628 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3629 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3630 | bp_std_terminate_master, |
3631 | &internal_breakpoint_ops); | |
f00aae0f KS |
3632 | p = ASTRDUP (func_name); |
3633 | b->location = new_linespec_location (&p); | |
aa7d318d TT |
3634 | b->enable_state = bp_disabled; |
3635 | } | |
17450429 PP |
3636 | } |
3637 | ||
44702360 | 3638 | update_global_location_list (UGLL_MAY_INSERT); |
aa7d318d TT |
3639 | |
3640 | do_cleanups (old_chain); | |
3641 | } | |
3642 | ||
186c406b TT |
3643 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3644 | ||
70221824 | 3645 | static void |
186c406b TT |
3646 | create_exception_master_breakpoint (void) |
3647 | { | |
3648 | struct objfile *objfile; | |
17450429 | 3649 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3650 | |
3651 | ALL_OBJFILES (objfile) | |
3652 | { | |
17450429 PP |
3653 | struct breakpoint *b; |
3654 | struct gdbarch *gdbarch; | |
3655 | struct breakpoint_objfile_data *bp_objfile_data; | |
3656 | CORE_ADDR addr; | |
f00aae0f | 3657 | char *p; |
17450429 PP |
3658 | |
3659 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3660 | ||
28106bc2 SDJ |
3661 | /* We prefer the SystemTap probe point if it exists. */ |
3662 | if (!bp_objfile_data->exception_searched) | |
3663 | { | |
25f9533e SDJ |
3664 | VEC (probe_p) *ret; |
3665 | ||
3666 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3667 | ||
3668 | if (ret != NULL) | |
3669 | { | |
3670 | /* We are only interested in checking one element. */ | |
3671 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3672 | ||
3673 | if (!can_evaluate_probe_arguments (p)) | |
3674 | { | |
3675 | /* We cannot use the probe interface here, because it does | |
3676 | not know how to evaluate arguments. */ | |
3677 | VEC_free (probe_p, ret); | |
3678 | ret = NULL; | |
3679 | } | |
3680 | } | |
3681 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3682 | bp_objfile_data->exception_searched = 1; |
3683 | } | |
3684 | ||
3685 | if (bp_objfile_data->exception_probes != NULL) | |
3686 | { | |
3687 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3688 | int i; | |
3689 | struct probe *probe; | |
3690 | ||
3691 | for (i = 0; | |
3692 | VEC_iterate (probe_p, | |
3693 | bp_objfile_data->exception_probes, | |
3694 | i, probe); | |
3695 | ++i) | |
3696 | { | |
3697 | struct breakpoint *b; | |
f00aae0f | 3698 | char *p; |
28106bc2 | 3699 | |
729662a5 TT |
3700 | b = create_internal_breakpoint (gdbarch, |
3701 | get_probe_address (probe, | |
3702 | objfile), | |
28106bc2 SDJ |
3703 | bp_exception_master, |
3704 | &internal_breakpoint_ops); | |
f00aae0f KS |
3705 | p = ASTRDUP ("-probe-stap libgcc:unwind"); |
3706 | b->location = new_linespec_location (&p); | |
28106bc2 SDJ |
3707 | b->enable_state = bp_disabled; |
3708 | } | |
3709 | ||
3710 | continue; | |
3711 | } | |
3712 | ||
3713 | /* Otherwise, try the hook function. */ | |
3714 | ||
3b7344d5 | 3715 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3716 | continue; |
3717 | ||
3718 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3719 | |
3b7344d5 | 3720 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3721 | { |
3b7344d5 | 3722 | struct bound_minimal_symbol debug_hook; |
186c406b | 3723 | |
17450429 | 3724 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3725 | if (debug_hook.minsym == NULL) |
17450429 | 3726 | { |
3b7344d5 | 3727 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3728 | continue; |
3729 | } | |
3730 | ||
3731 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3732 | } |
17450429 | 3733 | |
77e371c0 | 3734 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3735 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3736 | ¤t_target); | |
06edf0c0 PA |
3737 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3738 | &internal_breakpoint_ops); | |
f00aae0f KS |
3739 | p = ASTRDUP (func_name); |
3740 | b->location = new_linespec_location (&p); | |
17450429 | 3741 | b->enable_state = bp_disabled; |
186c406b TT |
3742 | } |
3743 | ||
44702360 | 3744 | update_global_location_list (UGLL_MAY_INSERT); |
186c406b TT |
3745 | } |
3746 | ||
c906108c | 3747 | void |
fba45db2 | 3748 | update_breakpoints_after_exec (void) |
c906108c | 3749 | { |
35df4500 | 3750 | struct breakpoint *b, *b_tmp; |
876fa593 | 3751 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3752 | |
25b22b0a PA |
3753 | /* We're about to delete breakpoints from GDB's lists. If the |
3754 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3755 | writing the breakpoints' "shadow contents" back into memory. The | |
3756 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3757 | do that. Instead, the target is responsible from marking | |
3758 | breakpoints out as soon as it detects an exec. We don't do that | |
3759 | here instead, because there may be other attempts to delete | |
3760 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3761 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3762 | if (bploc->pspace == current_program_space) |
3763 | gdb_assert (!bploc->inserted); | |
c906108c | 3764 | |
35df4500 | 3765 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3766 | { |
6c95b8df PA |
3767 | if (b->pspace != current_program_space) |
3768 | continue; | |
3769 | ||
4a64f543 | 3770 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3771 | if (b->type == bp_shlib_event) |
3772 | { | |
3773 | delete_breakpoint (b); | |
3774 | continue; | |
3775 | } | |
c906108c | 3776 | |
4a64f543 | 3777 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3778 | if (b->type == bp_jit_event) |
3779 | { | |
3780 | delete_breakpoint (b); | |
3781 | continue; | |
3782 | } | |
3783 | ||
1900040c | 3784 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3785 | as must overlay event and longjmp master breakpoints. */ |
3786 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3787 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3788 | || b->type == bp_exception_master) | |
c4093a6a JM |
3789 | { |
3790 | delete_breakpoint (b); | |
3791 | continue; | |
3792 | } | |
3793 | ||
4a64f543 | 3794 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3795 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3796 | { |
3797 | delete_breakpoint (b); | |
3798 | continue; | |
3799 | } | |
3800 | ||
7c16b83e PA |
3801 | /* Just like single-step breakpoints. */ |
3802 | if (b->type == bp_single_step) | |
3803 | { | |
3804 | delete_breakpoint (b); | |
3805 | continue; | |
3806 | } | |
3807 | ||
611c83ae PA |
3808 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3809 | after an exec. */ | |
186c406b | 3810 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3811 | || b->type == bp_longjmp_call_dummy |
186c406b | 3812 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3813 | { |
3814 | delete_breakpoint (b); | |
3815 | continue; | |
3816 | } | |
3817 | ||
ce78b96d JB |
3818 | if (b->type == bp_catchpoint) |
3819 | { | |
3820 | /* For now, none of the bp_catchpoint breakpoints need to | |
3821 | do anything at this point. In the future, if some of | |
3822 | the catchpoints need to something, we will need to add | |
3823 | a new method, and call this method from here. */ | |
3824 | continue; | |
3825 | } | |
3826 | ||
c5aa993b JM |
3827 | /* bp_finish is a special case. The only way we ought to be able |
3828 | to see one of these when an exec() has happened, is if the user | |
3829 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3830 | carries them to the call-site of the current callee, by setting | |
3831 | a temporary bp there and resuming. But in this case, the finish | |
3832 | will carry them entirely through the vfork & exec. | |
3833 | ||
3834 | We don't want to allow a bp_finish to remain inserted now. But | |
3835 | we can't safely delete it, 'cause finish_command has a handle to | |
3836 | the bp on a bpstat, and will later want to delete it. There's a | |
3837 | chance (and I've seen it happen) that if we delete the bp_finish | |
3838 | here, that its storage will get reused by the time finish_command | |
3839 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3840 | We really must allow finish_command to delete a bp_finish. | |
3841 | ||
e5dd4106 | 3842 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3843 | it's safe to delete something others may have handles to?" |
3844 | problem, what we'll do here is just uninsert the bp_finish, and | |
3845 | let finish_command delete it. | |
3846 | ||
3847 | (We know the bp_finish is "doomed" in the sense that it's | |
3848 | momentary, and will be deleted as soon as finish_command sees | |
3849 | the inferior stopped. So it doesn't matter that the bp's | |
3850 | address is probably bogus in the new a.out, unlike e.g., the | |
3851 | solib breakpoints.) */ | |
c5aa993b | 3852 | |
c5aa993b JM |
3853 | if (b->type == bp_finish) |
3854 | { | |
3855 | continue; | |
3856 | } | |
3857 | ||
3858 | /* Without a symbolic address, we have little hope of the | |
3859 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3860 | a.out. */ |
f00aae0f | 3861 | if (event_location_empty_p (b->location)) |
c5aa993b JM |
3862 | { |
3863 | delete_breakpoint (b); | |
3864 | continue; | |
3865 | } | |
c5aa993b | 3866 | } |
c906108c SS |
3867 | } |
3868 | ||
3869 | int | |
d80ee84f | 3870 | detach_breakpoints (ptid_t ptid) |
c906108c | 3871 | { |
35df4500 | 3872 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3873 | int val = 0; |
ce696e05 | 3874 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3875 | struct inferior *inf = current_inferior (); |
c5aa993b | 3876 | |
dfd4cc63 | 3877 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3878 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3879 | |
6c95b8df | 3880 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3881 | inferior_ptid = ptid; |
35df4500 | 3882 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3883 | { |
35df4500 | 3884 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3885 | continue; |
3886 | ||
bd9673a4 PW |
3887 | /* This function must physically remove breakpoints locations |
3888 | from the specified ptid, without modifying the breakpoint | |
3889 | package's state. Locations of type bp_loc_other are only | |
3890 | maintained at GDB side. So, there is no need to remove | |
3891 | these bp_loc_other locations. Moreover, removing these | |
3892 | would modify the breakpoint package's state. */ | |
3893 | if (bl->loc_type == bp_loc_other) | |
3894 | continue; | |
3895 | ||
35df4500 TJB |
3896 | if (bl->inserted) |
3897 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3898 | } |
d03285ec | 3899 | |
ce696e05 | 3900 | do_cleanups (old_chain); |
3a1bae8e | 3901 | return val; |
c906108c SS |
3902 | } |
3903 | ||
35df4500 | 3904 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3905 | Note that this is used to detach breakpoints from a child fork. |
3906 | When we get here, the child isn't in the inferior list, and neither | |
3907 | do we have objects to represent its address space --- we should | |
35df4500 | 3908 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3909 | |
c906108c | 3910 | static int |
35df4500 | 3911 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3912 | { |
3913 | int val; | |
c5aa993b | 3914 | |
35df4500 TJB |
3915 | /* BL is never in moribund_locations by our callers. */ |
3916 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3917 | |
74960c60 VP |
3918 | /* The type of none suggests that owner is actually deleted. |
3919 | This should not ever happen. */ | |
35df4500 | 3920 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3921 | |
35df4500 TJB |
3922 | if (bl->loc_type == bp_loc_software_breakpoint |
3923 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3924 | { |
c02f5703 MS |
3925 | /* "Normal" instruction breakpoint: either the standard |
3926 | trap-instruction bp (bp_breakpoint), or a | |
3927 | bp_hardware_breakpoint. */ | |
3928 | ||
3929 | /* First check to see if we have to handle an overlay. */ | |
3930 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3931 | || bl->section == NULL |
3932 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3933 | { |
3934 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3935 | |
3936 | /* If we're trying to uninsert a memory breakpoint that we | |
3937 | know is set in a dynamic object that is marked | |
3938 | shlib_disabled, then either the dynamic object was | |
3939 | removed with "remove-symbol-file" or with | |
3940 | "nosharedlibrary". In the former case, we don't know | |
3941 | whether another dynamic object might have loaded over the | |
3942 | breakpoint's address -- the user might well let us know | |
3943 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3944 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3945 | list of dynamically loaded objects). If we have the |
3946 | breakpoint's shadow memory, that is, this is a software | |
3947 | breakpoint managed by GDB, check whether the breakpoint | |
3948 | is still inserted in memory, to avoid overwriting wrong | |
3949 | code with stale saved shadow contents. Note that HW | |
3950 | breakpoints don't have shadow memory, as they're | |
3951 | implemented using a mechanism that is not dependent on | |
3952 | being able to modify the target's memory, and as such | |
3953 | they should always be removed. */ | |
3954 | if (bl->shlib_disabled | |
3955 | && bl->target_info.shadow_len != 0 | |
3956 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3957 | val = 0; | |
3958 | else | |
3959 | val = bl->owner->ops->remove_location (bl); | |
c02f5703 | 3960 | } |
c906108c SS |
3961 | else |
3962 | { | |
4a64f543 | 3963 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3964 | Did we set a breakpoint at the LMA? */ |
3965 | if (!overlay_events_enabled) | |
3966 | { | |
3967 | /* Yes -- overlay event support is not active, so we | |
3968 | should have set a breakpoint at the LMA. Remove it. | |
3969 | */ | |
c02f5703 MS |
3970 | /* Ignore any failures: if the LMA is in ROM, we will |
3971 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3972 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3973 | target_remove_hw_breakpoint (bl->gdbarch, | |
3974 | &bl->overlay_target_info); | |
c02f5703 | 3975 | else |
35df4500 TJB |
3976 | target_remove_breakpoint (bl->gdbarch, |
3977 | &bl->overlay_target_info); | |
c02f5703 MS |
3978 | } |
3979 | /* Did we set a breakpoint at the VMA? | |
3980 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3981 | if (bl->inserted) |
c906108c | 3982 | { |
c02f5703 MS |
3983 | /* Yes -- remove it. Previously we did not bother to |
3984 | remove the breakpoint if the section had been | |
3985 | unmapped, but let's not rely on that being safe. We | |
3986 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3987 | |
3988 | /* However, we should remove *software* breakpoints only | |
3989 | if the section is still mapped, or else we overwrite | |
3990 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3991 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3992 | || section_is_mapped (bl->section)) | |
3993 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3994 | else |
3995 | val = 0; | |
c906108c | 3996 | } |
c02f5703 MS |
3997 | else |
3998 | { | |
3999 | /* No -- not inserted, so no need to remove. No error. */ | |
4000 | val = 0; | |
4001 | } | |
c906108c | 4002 | } |
879d1e6b | 4003 | |
08351840 PA |
4004 | /* In some cases, we might not be able to remove a breakpoint in |
4005 | a shared library that has already been removed, but we have | |
4006 | not yet processed the shlib unload event. Similarly for an | |
4007 | unloaded add-symbol-file object - the user might not yet have | |
4008 | had the chance to remove-symbol-file it. shlib_disabled will | |
4009 | be set if the library/object has already been removed, but | |
4010 | the breakpoint hasn't been uninserted yet, e.g., after | |
4011 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
4012 | always-inserted mode. */ | |
076855f9 | 4013 | if (val |
08351840 PA |
4014 | && (bl->loc_type == bp_loc_software_breakpoint |
4015 | && (bl->shlib_disabled | |
4016 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4017 | || shared_objfile_contains_address_p (bl->pspace, |
4018 | bl->address)))) | |
879d1e6b UW |
4019 | val = 0; |
4020 | ||
c906108c SS |
4021 | if (val) |
4022 | return val; | |
35df4500 | 4023 | bl->inserted = (is == mark_inserted); |
c906108c | 4024 | } |
35df4500 | 4025 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4026 | { |
77b06cd7 TJB |
4027 | gdb_assert (bl->owner->ops != NULL |
4028 | && bl->owner->ops->remove_location != NULL); | |
4029 | ||
35df4500 | 4030 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 4031 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 4032 | |
c906108c | 4033 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 4034 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 4035 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4036 | bl->owner->number); |
c906108c | 4037 | } |
35df4500 TJB |
4038 | else if (bl->owner->type == bp_catchpoint |
4039 | && breakpoint_enabled (bl->owner) | |
4040 | && !bl->duplicate) | |
ce78b96d | 4041 | { |
77b06cd7 TJB |
4042 | gdb_assert (bl->owner->ops != NULL |
4043 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4044 | |
77b06cd7 | 4045 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
4046 | if (val) |
4047 | return val; | |
77b06cd7 | 4048 | |
35df4500 | 4049 | bl->inserted = (is == mark_inserted); |
ce78b96d | 4050 | } |
c906108c SS |
4051 | |
4052 | return 0; | |
4053 | } | |
4054 | ||
6c95b8df | 4055 | static int |
35df4500 | 4056 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
4057 | { |
4058 | int ret; | |
4059 | struct cleanup *old_chain; | |
4060 | ||
35df4500 TJB |
4061 | /* BL is never in moribund_locations by our callers. */ |
4062 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4063 | |
6c95b8df PA |
4064 | /* The type of none suggests that owner is actually deleted. |
4065 | This should not ever happen. */ | |
35df4500 | 4066 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4067 | |
4068 | old_chain = save_current_space_and_thread (); | |
4069 | ||
35df4500 | 4070 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4071 | |
35df4500 | 4072 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
4073 | |
4074 | do_cleanups (old_chain); | |
4075 | return ret; | |
4076 | } | |
4077 | ||
c906108c SS |
4078 | /* Clear the "inserted" flag in all breakpoints. */ |
4079 | ||
25b22b0a | 4080 | void |
fba45db2 | 4081 | mark_breakpoints_out (void) |
c906108c | 4082 | { |
35df4500 | 4083 | struct bp_location *bl, **blp_tmp; |
c906108c | 4084 | |
35df4500 | 4085 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4086 | if (bl->pspace == current_program_space) |
35df4500 | 4087 | bl->inserted = 0; |
c906108c SS |
4088 | } |
4089 | ||
53a5351d JM |
4090 | /* Clear the "inserted" flag in all breakpoints and delete any |
4091 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4092 | |
4093 | Plus other such housekeeping that has to be done for breakpoints | |
4094 | between runs. | |
4095 | ||
53a5351d JM |
4096 | Note: this function gets called at the end of a run (by |
4097 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4098 | init_wait_for_inferior). */ |
c906108c SS |
4099 | |
4100 | ||
4101 | ||
4102 | void | |
fba45db2 | 4103 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4104 | { |
35df4500 TJB |
4105 | struct breakpoint *b, *b_tmp; |
4106 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 4107 | int ix; |
6c95b8df | 4108 | struct program_space *pspace = current_program_space; |
c906108c | 4109 | |
50c71eaf PA |
4110 | /* If breakpoint locations are shared across processes, then there's |
4111 | nothing to do. */ | |
f5656ead | 4112 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4113 | return; |
4114 | ||
1a853c52 | 4115 | mark_breakpoints_out (); |
075f6582 | 4116 | |
35df4500 | 4117 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4118 | { |
6c95b8df PA |
4119 | if (b->loc && b->loc->pspace != pspace) |
4120 | continue; | |
4121 | ||
c5aa993b JM |
4122 | switch (b->type) |
4123 | { | |
4124 | case bp_call_dummy: | |
e2e4d78b | 4125 | case bp_longjmp_call_dummy: |
c906108c | 4126 | |
c5aa993b | 4127 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4128 | cause problems when the inferior is rerun, so we better get |
4129 | rid of it. */ | |
4130 | ||
4131 | case bp_watchpoint_scope: | |
4132 | ||
4133 | /* Also get rid of scope breakpoints. */ | |
4134 | ||
4135 | case bp_shlib_event: | |
4136 | ||
4137 | /* Also remove solib event breakpoints. Their addresses may | |
4138 | have changed since the last time we ran the program. | |
4139 | Actually we may now be debugging against different target; | |
4140 | and so the solib backend that installed this breakpoint may | |
4141 | not be used in by the target. E.g., | |
4142 | ||
4143 | (gdb) file prog-linux | |
4144 | (gdb) run # native linux target | |
4145 | ... | |
4146 | (gdb) kill | |
4147 | (gdb) file prog-win.exe | |
4148 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4149 | */ | |
c906108c | 4150 | |
f59f708a PA |
4151 | case bp_step_resume: |
4152 | ||
4153 | /* Also remove step-resume breakpoints. */ | |
4154 | ||
7c16b83e PA |
4155 | case bp_single_step: |
4156 | ||
4157 | /* Also remove single-step breakpoints. */ | |
4158 | ||
c5aa993b JM |
4159 | delete_breakpoint (b); |
4160 | break; | |
c906108c | 4161 | |
c5aa993b JM |
4162 | case bp_watchpoint: |
4163 | case bp_hardware_watchpoint: | |
4164 | case bp_read_watchpoint: | |
4165 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4166 | { |
4167 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4168 | |
3a5c3e22 PA |
4169 | /* Likewise for watchpoints on local expressions. */ |
4170 | if (w->exp_valid_block != NULL) | |
4171 | delete_breakpoint (b); | |
4172 | else if (context == inf_starting) | |
4173 | { | |
4174 | /* Reset val field to force reread of starting value in | |
4175 | insert_breakpoints. */ | |
4176 | if (w->val) | |
4177 | value_free (w->val); | |
4178 | w->val = NULL; | |
4179 | w->val_valid = 0; | |
c860120c | 4180 | } |
3a5c3e22 | 4181 | } |
c5aa993b JM |
4182 | break; |
4183 | default: | |
c5aa993b JM |
4184 | break; |
4185 | } | |
4186 | } | |
1c5cfe86 PA |
4187 | |
4188 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4189 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4190 | decref_bp_location (&bl); | |
1c5cfe86 | 4191 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4192 | } |
4193 | ||
6c95b8df PA |
4194 | /* These functions concern about actual breakpoints inserted in the |
4195 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4196 | we need to hop over the bkpt --- so we check for address space | |
4197 | match, not program space. */ | |
4198 | ||
c2c6d25f JM |
4199 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4200 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4201 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4202 | permanent breakpoint. | |
4203 | - When continuing from a location with an ordinary breakpoint, we | |
4204 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4205 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4206 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4207 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4208 | |
c2c6d25f | 4209 | enum breakpoint_here |
6c95b8df | 4210 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4211 | { |
35df4500 | 4212 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4213 | int any_breakpoint_here = 0; |
c906108c | 4214 | |
35df4500 | 4215 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4216 | { |
35df4500 TJB |
4217 | if (bl->loc_type != bp_loc_software_breakpoint |
4218 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4219 | continue; |
4220 | ||
f1310107 | 4221 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4222 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4223 | || bl->permanent) |
f1310107 | 4224 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4225 | { |
4226 | if (overlay_debugging | |
35df4500 TJB |
4227 | && section_is_overlay (bl->section) |
4228 | && !section_is_mapped (bl->section)) | |
075f6582 | 4229 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4230 | else if (bl->permanent) |
075f6582 DJ |
4231 | return permanent_breakpoint_here; |
4232 | else | |
4233 | any_breakpoint_here = 1; | |
4234 | } | |
4235 | } | |
c906108c | 4236 | |
f486487f | 4237 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4238 | } |
4239 | ||
1c5cfe86 PA |
4240 | /* Return true if there's a moribund breakpoint at PC. */ |
4241 | ||
4242 | int | |
6c95b8df | 4243 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4244 | { |
4245 | struct bp_location *loc; | |
4246 | int ix; | |
4247 | ||
4248 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4249 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4250 | return 1; |
4251 | ||
4252 | return 0; | |
4253 | } | |
c2c6d25f | 4254 | |
f7ce857f PA |
4255 | /* Returns non-zero iff BL is inserted at PC, in address space |
4256 | ASPACE. */ | |
4257 | ||
4258 | static int | |
4259 | bp_location_inserted_here_p (struct bp_location *bl, | |
4260 | struct address_space *aspace, CORE_ADDR pc) | |
4261 | { | |
4262 | if (bl->inserted | |
4263 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4264 | aspace, pc)) | |
4265 | { | |
4266 | if (overlay_debugging | |
4267 | && section_is_overlay (bl->section) | |
4268 | && !section_is_mapped (bl->section)) | |
4269 | return 0; /* unmapped overlay -- can't be a match */ | |
4270 | else | |
4271 | return 1; | |
4272 | } | |
4273 | return 0; | |
4274 | } | |
4275 | ||
a1fd2fa5 | 4276 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4277 | |
4278 | int | |
a1fd2fa5 | 4279 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4280 | { |
f7ce857f PA |
4281 | struct bp_location **blp, **blp_tmp = NULL; |
4282 | struct bp_location *bl; | |
c906108c | 4283 | |
f7ce857f | 4284 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4285 | { |
f7ce857f PA |
4286 | struct bp_location *bl = *blp; |
4287 | ||
35df4500 TJB |
4288 | if (bl->loc_type != bp_loc_software_breakpoint |
4289 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4290 | continue; |
4291 | ||
f7ce857f PA |
4292 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4293 | return 1; | |
c5aa993b | 4294 | } |
c36b740a VP |
4295 | return 0; |
4296 | } | |
4297 | ||
a1fd2fa5 PA |
4298 | /* This function returns non-zero iff there is a software breakpoint |
4299 | inserted at PC. */ | |
c36b740a VP |
4300 | |
4301 | int | |
a1fd2fa5 PA |
4302 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4303 | CORE_ADDR pc) | |
4fa8626c | 4304 | { |
f7ce857f PA |
4305 | struct bp_location **blp, **blp_tmp = NULL; |
4306 | struct bp_location *bl; | |
4fa8626c | 4307 | |
f7ce857f | 4308 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4309 | { |
f7ce857f PA |
4310 | struct bp_location *bl = *blp; |
4311 | ||
35df4500 | 4312 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4313 | continue; |
4314 | ||
f7ce857f PA |
4315 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4316 | return 1; | |
4fa8626c DJ |
4317 | } |
4318 | ||
4319 | return 0; | |
9c02b525 PA |
4320 | } |
4321 | ||
4322 | /* See breakpoint.h. */ | |
4323 | ||
4324 | int | |
4325 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4326 | CORE_ADDR pc) | |
4327 | { | |
4328 | struct bp_location **blp, **blp_tmp = NULL; | |
4329 | struct bp_location *bl; | |
4330 | ||
4331 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4332 | { | |
4333 | struct bp_location *bl = *blp; | |
4334 | ||
4335 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4336 | continue; | |
4337 | ||
4338 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4339 | return 1; | |
4340 | } | |
4341 | ||
4342 | return 0; | |
4fa8626c DJ |
4343 | } |
4344 | ||
9093389c PA |
4345 | int |
4346 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4347 | CORE_ADDR addr, ULONGEST len) | |
4348 | { | |
4349 | struct breakpoint *bpt; | |
4350 | ||
4351 | ALL_BREAKPOINTS (bpt) | |
4352 | { | |
4353 | struct bp_location *loc; | |
4354 | ||
4355 | if (bpt->type != bp_hardware_watchpoint | |
4356 | && bpt->type != bp_access_watchpoint) | |
4357 | continue; | |
4358 | ||
4359 | if (!breakpoint_enabled (bpt)) | |
4360 | continue; | |
4361 | ||
4362 | for (loc = bpt->loc; loc; loc = loc->next) | |
4363 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4364 | { | |
4365 | CORE_ADDR l, h; | |
4366 | ||
4367 | /* Check for intersection. */ | |
4368 | l = max (loc->address, addr); | |
4369 | h = min (loc->address + loc->length, addr + len); | |
4370 | if (l < h) | |
4371 | return 1; | |
4372 | } | |
4373 | } | |
4374 | return 0; | |
4375 | } | |
c906108c | 4376 | \f |
c5aa993b | 4377 | |
c906108c SS |
4378 | /* bpstat stuff. External routines' interfaces are documented |
4379 | in breakpoint.h. */ | |
4380 | ||
4381 | int | |
c326b90e | 4382 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4383 | { |
533be4dd | 4384 | return (ep->type == bp_catchpoint); |
c906108c SS |
4385 | } |
4386 | ||
f431efe5 PA |
4387 | /* Frees any storage that is part of a bpstat. Does not walk the |
4388 | 'next' chain. */ | |
4389 | ||
4390 | static void | |
198757a8 VP |
4391 | bpstat_free (bpstat bs) |
4392 | { | |
4393 | if (bs->old_val != NULL) | |
4394 | value_free (bs->old_val); | |
9add0f1b | 4395 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4396 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4397 | xfree (bs); |
4398 | } | |
4399 | ||
c906108c SS |
4400 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4401 | Also free any storage that is part of a bpstat. */ | |
4402 | ||
4403 | void | |
fba45db2 | 4404 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4405 | { |
4406 | bpstat p; | |
4407 | bpstat q; | |
4408 | ||
4409 | if (bsp == 0) | |
4410 | return; | |
4411 | p = *bsp; | |
4412 | while (p != NULL) | |
4413 | { | |
4414 | q = p->next; | |
198757a8 | 4415 | bpstat_free (p); |
c906108c SS |
4416 | p = q; |
4417 | } | |
4418 | *bsp = NULL; | |
4419 | } | |
4420 | ||
4421 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4422 | is part of the bpstat is copied as well. */ | |
4423 | ||
4424 | bpstat | |
fba45db2 | 4425 | bpstat_copy (bpstat bs) |
c906108c SS |
4426 | { |
4427 | bpstat p = NULL; | |
4428 | bpstat tmp; | |
4429 | bpstat retval = NULL; | |
4430 | ||
4431 | if (bs == NULL) | |
4432 | return bs; | |
4433 | ||
4434 | for (; bs != NULL; bs = bs->next) | |
4435 | { | |
4436 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4437 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4438 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4439 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4440 | if (bs->old_val != NULL) |
3c3185ac JK |
4441 | { |
4442 | tmp->old_val = value_copy (bs->old_val); | |
4443 | release_value (tmp->old_val); | |
4444 | } | |
31cc81e9 | 4445 | |
c906108c SS |
4446 | if (p == NULL) |
4447 | /* This is the first thing in the chain. */ | |
4448 | retval = tmp; | |
4449 | else | |
4450 | p->next = tmp; | |
4451 | p = tmp; | |
4452 | } | |
4453 | p->next = NULL; | |
4454 | return retval; | |
4455 | } | |
4456 | ||
4a64f543 | 4457 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4458 | |
4459 | bpstat | |
fba45db2 | 4460 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4461 | { |
c5aa993b JM |
4462 | if (bsp == NULL) |
4463 | return NULL; | |
c906108c | 4464 | |
c5aa993b JM |
4465 | for (; bsp != NULL; bsp = bsp->next) |
4466 | { | |
f431efe5 | 4467 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4468 | return bsp; |
4469 | } | |
c906108c SS |
4470 | return NULL; |
4471 | } | |
4472 | ||
ab04a2af TT |
4473 | /* See breakpoint.h. */ |
4474 | ||
47591c29 | 4475 | int |
427cd150 | 4476 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4477 | { |
ab04a2af TT |
4478 | for (; bsp != NULL; bsp = bsp->next) |
4479 | { | |
427cd150 TT |
4480 | if (bsp->breakpoint_at == NULL) |
4481 | { | |
4482 | /* A moribund location can never explain a signal other than | |
4483 | GDB_SIGNAL_TRAP. */ | |
4484 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4485 | return 1; |
427cd150 TT |
4486 | } |
4487 | else | |
47591c29 PA |
4488 | { |
4489 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4490 | sig)) | |
4491 | return 1; | |
4492 | } | |
ab04a2af TT |
4493 | } |
4494 | ||
47591c29 | 4495 | return 0; |
ab04a2af TT |
4496 | } |
4497 | ||
4a64f543 MS |
4498 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4499 | stopped at. *BSP upon return is a bpstat which points to the | |
4500 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4501 | good for anything but further calls to bpstat_num). | |
4502 | ||
8671a17b PA |
4503 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4504 | Return -1 if stopped at a breakpoint that has been deleted since | |
4505 | we set it. | |
4506 | Return 1 otherwise. */ | |
c906108c SS |
4507 | |
4508 | int | |
8671a17b | 4509 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4510 | { |
4511 | struct breakpoint *b; | |
4512 | ||
4513 | if ((*bsp) == NULL) | |
4514 | return 0; /* No more breakpoint values */ | |
8671a17b | 4515 | |
4a64f543 MS |
4516 | /* We assume we'll never have several bpstats that correspond to a |
4517 | single breakpoint -- otherwise, this function might return the | |
4518 | same number more than once and this will look ugly. */ | |
f431efe5 | 4519 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4520 | *bsp = (*bsp)->next; |
4521 | if (b == NULL) | |
4522 | return -1; /* breakpoint that's been deleted since */ | |
4523 | ||
4524 | *num = b->number; /* We have its number */ | |
4525 | return 1; | |
c906108c SS |
4526 | } |
4527 | ||
e93ca019 | 4528 | /* See breakpoint.h. */ |
c906108c SS |
4529 | |
4530 | void | |
e93ca019 | 4531 | bpstat_clear_actions (void) |
c906108c | 4532 | { |
e93ca019 JK |
4533 | struct thread_info *tp; |
4534 | bpstat bs; | |
4535 | ||
4536 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4537 | return; | |
4538 | ||
4539 | tp = find_thread_ptid (inferior_ptid); | |
4540 | if (tp == NULL) | |
4541 | return; | |
4542 | ||
4543 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4544 | { |
9add0f1b | 4545 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4546 | |
c906108c SS |
4547 | if (bs->old_val != NULL) |
4548 | { | |
4549 | value_free (bs->old_val); | |
4550 | bs->old_val = NULL; | |
4551 | } | |
4552 | } | |
4553 | } | |
4554 | ||
f3b1572e PA |
4555 | /* Called when a command is about to proceed the inferior. */ |
4556 | ||
4557 | static void | |
4558 | breakpoint_about_to_proceed (void) | |
4559 | { | |
4560 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4561 | { | |
4562 | struct thread_info *tp = inferior_thread (); | |
4563 | ||
4564 | /* Allow inferior function calls in breakpoint commands to not | |
4565 | interrupt the command list. When the call finishes | |
4566 | successfully, the inferior will be standing at the same | |
4567 | breakpoint as if nothing happened. */ | |
16c381f0 | 4568 | if (tp->control.in_infcall) |
f3b1572e PA |
4569 | return; |
4570 | } | |
4571 | ||
4572 | breakpoint_proceeded = 1; | |
4573 | } | |
4574 | ||
4a64f543 MS |
4575 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4576 | command. */ | |
c906108c | 4577 | static void |
4efb68b1 | 4578 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4579 | { |
4580 | executing_breakpoint_commands = 0; | |
4581 | } | |
4582 | ||
abf85f46 JK |
4583 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4584 | or its equivalent. */ | |
4585 | ||
4586 | static int | |
4587 | command_line_is_silent (struct command_line *cmd) | |
4588 | { | |
4f45d445 | 4589 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4590 | } |
4591 | ||
4a64f543 MS |
4592 | /* Execute all the commands associated with all the breakpoints at |
4593 | this location. Any of these commands could cause the process to | |
4594 | proceed beyond this point, etc. We look out for such changes by | |
4595 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4596 | |
347bddb7 PA |
4597 | Returns true if a breakpoint command resumed the inferior. In that |
4598 | case, it is the caller's responsibility to recall it again with the | |
4599 | bpstat of the current thread. */ | |
4600 | ||
4601 | static int | |
4602 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4603 | { |
4604 | bpstat bs; | |
4605 | struct cleanup *old_chain; | |
347bddb7 | 4606 | int again = 0; |
c906108c SS |
4607 | |
4608 | /* Avoid endless recursion if a `source' command is contained | |
4609 | in bs->commands. */ | |
4610 | if (executing_breakpoint_commands) | |
347bddb7 | 4611 | return 0; |
c906108c SS |
4612 | |
4613 | executing_breakpoint_commands = 1; | |
4614 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4615 | ||
cf6c5ffb TT |
4616 | prevent_dont_repeat (); |
4617 | ||
4a64f543 | 4618 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4619 | bs = *bsp; |
4620 | ||
4621 | breakpoint_proceeded = 0; | |
4622 | for (; bs != NULL; bs = bs->next) | |
4623 | { | |
9add0f1b | 4624 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4625 | struct command_line *cmd; |
4626 | struct cleanup *this_cmd_tree_chain; | |
4627 | ||
4628 | /* Take ownership of the BSP's command tree, if it has one. | |
4629 | ||
4630 | The command tree could legitimately contain commands like | |
4631 | 'step' and 'next', which call clear_proceed_status, which | |
4632 | frees stop_bpstat's command tree. To make sure this doesn't | |
4633 | free the tree we're executing out from under us, we need to | |
4634 | take ownership of the tree ourselves. Since a given bpstat's | |
4635 | commands are only executed once, we don't need to copy it; we | |
4636 | can clear the pointer in the bpstat, and make sure we free | |
4637 | the tree when we're done. */ | |
9add0f1b TT |
4638 | ccmd = bs->commands; |
4639 | bs->commands = NULL; | |
abf85f46 JK |
4640 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4641 | cmd = ccmd ? ccmd->commands : NULL; | |
4642 | if (command_line_is_silent (cmd)) | |
4643 | { | |
4644 | /* The action has been already done by bpstat_stop_status. */ | |
4645 | cmd = cmd->next; | |
4646 | } | |
6c50ab1c | 4647 | |
c906108c SS |
4648 | while (cmd != NULL) |
4649 | { | |
4650 | execute_control_command (cmd); | |
4651 | ||
4652 | if (breakpoint_proceeded) | |
4653 | break; | |
4654 | else | |
4655 | cmd = cmd->next; | |
4656 | } | |
6c50ab1c JB |
4657 | |
4658 | /* We can free this command tree now. */ | |
4659 | do_cleanups (this_cmd_tree_chain); | |
4660 | ||
c906108c | 4661 | if (breakpoint_proceeded) |
32c1e744 | 4662 | { |
5589af0e | 4663 | if (interpreter_async && target_can_async_p ()) |
347bddb7 PA |
4664 | /* If we are in async mode, then the target might be still |
4665 | running, not stopped at any breakpoint, so nothing for | |
4666 | us to do here -- just return to the event loop. */ | |
4667 | ; | |
32c1e744 VP |
4668 | else |
4669 | /* In sync mode, when execute_control_command returns | |
4670 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4671 | Breakpoint commands for that stop were not run, since |
4672 | execute_command does not run breakpoint commands -- | |
4673 | only command_line_handler does, but that one is not | |
4674 | involved in execution of breakpoint commands. So, we | |
4675 | can now execute breakpoint commands. It should be | |
4676 | noted that making execute_command do bpstat actions is | |
4677 | not an option -- in this case we'll have recursive | |
4678 | invocation of bpstat for each breakpoint with a | |
4679 | command, and can easily blow up GDB stack. Instead, we | |
4680 | return true, which will trigger the caller to recall us | |
4681 | with the new stop_bpstat. */ | |
4682 | again = 1; | |
4683 | break; | |
32c1e744 | 4684 | } |
c906108c | 4685 | } |
c2b8ed2c | 4686 | do_cleanups (old_chain); |
347bddb7 PA |
4687 | return again; |
4688 | } | |
4689 | ||
4690 | void | |
4691 | bpstat_do_actions (void) | |
4692 | { | |
353d1d73 JK |
4693 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4694 | ||
347bddb7 PA |
4695 | /* Do any commands attached to breakpoint we are stopped at. */ |
4696 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4697 | && target_has_execution | |
4698 | && !is_exited (inferior_ptid) | |
4699 | && !is_executing (inferior_ptid)) | |
4700 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4701 | and only return when it is stopped at the next breakpoint, we | |
4702 | keep doing breakpoint actions until it returns false to | |
4703 | indicate the inferior was not resumed. */ | |
16c381f0 | 4704 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4705 | break; |
353d1d73 JK |
4706 | |
4707 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4708 | } |
4709 | ||
fa4727a6 DJ |
4710 | /* Print out the (old or new) value associated with a watchpoint. */ |
4711 | ||
4712 | static void | |
4713 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4714 | { | |
4715 | if (val == NULL) | |
4716 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4717 | else | |
79a45b7d TT |
4718 | { |
4719 | struct value_print_options opts; | |
4720 | get_user_print_options (&opts); | |
4721 | value_print (val, stream, &opts); | |
4722 | } | |
fa4727a6 DJ |
4723 | } |
4724 | ||
e514a9d6 | 4725 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4726 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4727 | 'print_it' in the bpstat structure. Under some circumstances we |
4728 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4729 | normal_stop(). */ |
e514a9d6 JM |
4730 | |
4731 | static enum print_stop_action | |
4732 | print_bp_stop_message (bpstat bs) | |
4733 | { | |
4734 | switch (bs->print_it) | |
4735 | { | |
4736 | case print_it_noop: | |
4a64f543 | 4737 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4738 | return PRINT_UNKNOWN; |
4739 | break; | |
4740 | ||
4741 | case print_it_done: | |
4742 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4743 | relevant messages. */ |
e514a9d6 JM |
4744 | return PRINT_SRC_AND_LOC; |
4745 | break; | |
4746 | ||
4747 | case print_it_normal: | |
4f8d1dc6 | 4748 | { |
f431efe5 PA |
4749 | struct breakpoint *b = bs->breakpoint_at; |
4750 | ||
1a6a67de TJB |
4751 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4752 | which has since been deleted. */ | |
4753 | if (b == NULL) | |
4754 | return PRINT_UNKNOWN; | |
4755 | ||
348d480f PA |
4756 | /* Normal case. Call the breakpoint's print_it method. */ |
4757 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4758 | } |
348d480f | 4759 | break; |
3086aeae | 4760 | |
e514a9d6 | 4761 | default: |
8e65ff28 | 4762 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4763 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4764 | break; |
c906108c | 4765 | } |
c906108c SS |
4766 | } |
4767 | ||
edcc5120 TT |
4768 | /* A helper function that prints a shared library stopped event. */ |
4769 | ||
4770 | static void | |
4771 | print_solib_event (int is_catchpoint) | |
4772 | { | |
4773 | int any_deleted | |
4774 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4775 | int any_added | |
4776 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4777 | ||
4778 | if (!is_catchpoint) | |
4779 | { | |
4780 | if (any_added || any_deleted) | |
4781 | ui_out_text (current_uiout, | |
4782 | _("Stopped due to shared library event:\n")); | |
4783 | else | |
4784 | ui_out_text (current_uiout, | |
4785 | _("Stopped due to shared library event (no " | |
4786 | "libraries added or removed)\n")); | |
4787 | } | |
4788 | ||
4789 | if (ui_out_is_mi_like_p (current_uiout)) | |
4790 | ui_out_field_string (current_uiout, "reason", | |
4791 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4792 | ||
4793 | if (any_deleted) | |
4794 | { | |
4795 | struct cleanup *cleanup; | |
4796 | char *name; | |
4797 | int ix; | |
4798 | ||
4799 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4800 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4801 | "removed"); | |
4802 | for (ix = 0; | |
4803 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4804 | ix, name); | |
4805 | ++ix) | |
4806 | { | |
4807 | if (ix > 0) | |
4808 | ui_out_text (current_uiout, " "); | |
4809 | ui_out_field_string (current_uiout, "library", name); | |
4810 | ui_out_text (current_uiout, "\n"); | |
4811 | } | |
4812 | ||
4813 | do_cleanups (cleanup); | |
4814 | } | |
4815 | ||
4816 | if (any_added) | |
4817 | { | |
4818 | struct so_list *iter; | |
4819 | int ix; | |
4820 | struct cleanup *cleanup; | |
4821 | ||
4822 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4823 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4824 | "added"); | |
4825 | for (ix = 0; | |
4826 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4827 | ix, iter); | |
4828 | ++ix) | |
4829 | { | |
4830 | if (ix > 0) | |
4831 | ui_out_text (current_uiout, " "); | |
4832 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4833 | ui_out_text (current_uiout, "\n"); | |
4834 | } | |
4835 | ||
4836 | do_cleanups (cleanup); | |
4837 | } | |
4838 | } | |
4839 | ||
e514a9d6 JM |
4840 | /* Print a message indicating what happened. This is called from |
4841 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4842 | list - a list of the eventpoints that caused this stop. KIND is |
4843 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4844 | routine calls the generic print routine for printing a message |
4845 | about reasons for stopping. This will print (for example) the | |
4846 | "Breakpoint n," part of the output. The return value of this | |
4847 | routine is one of: | |
c906108c | 4848 | |
4a64f543 | 4849 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4850 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4851 | code to print the location. An example is |
c5aa993b JM |
4852 | "Breakpoint 1, " which should be followed by |
4853 | the location. | |
917317f4 | 4854 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4855 | to also print the location part of the message. |
4856 | An example is the catch/throw messages, which | |
4a64f543 | 4857 | don't require a location appended to the end. |
917317f4 | 4858 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4859 | further info to be printed. */ |
c906108c | 4860 | |
917317f4 | 4861 | enum print_stop_action |
36dfb11c | 4862 | bpstat_print (bpstat bs, int kind) |
c906108c | 4863 | { |
f486487f | 4864 | enum print_stop_action val; |
c5aa993b | 4865 | |
c906108c | 4866 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4867 | (Currently all watchpoints go on the bpstat whether hit or not. |
4868 | That probably could (should) be changed, provided care is taken | |
c906108c | 4869 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4870 | for (; bs; bs = bs->next) |
4871 | { | |
4872 | val = print_bp_stop_message (bs); | |
4873 | if (val == PRINT_SRC_ONLY | |
4874 | || val == PRINT_SRC_AND_LOC | |
4875 | || val == PRINT_NOTHING) | |
4876 | return val; | |
4877 | } | |
c906108c | 4878 | |
36dfb11c TT |
4879 | /* If we had hit a shared library event breakpoint, |
4880 | print_bp_stop_message would print out this message. If we hit an | |
4881 | OS-level shared library event, do the same thing. */ | |
4882 | if (kind == TARGET_WAITKIND_LOADED) | |
4883 | { | |
edcc5120 | 4884 | print_solib_event (0); |
36dfb11c TT |
4885 | return PRINT_NOTHING; |
4886 | } | |
4887 | ||
e514a9d6 | 4888 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4889 | with and nothing was printed. */ |
917317f4 | 4890 | return PRINT_UNKNOWN; |
c906108c SS |
4891 | } |
4892 | ||
c42bd95a DE |
4893 | /* Evaluate the expression EXP and return 1 if value is zero. |
4894 | This returns the inverse of the condition because it is called | |
4895 | from catch_errors which returns 0 if an exception happened, and if an | |
4896 | exception happens we want execution to stop. | |
4a64f543 | 4897 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4898 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4899 | |
4900 | static int | |
4efb68b1 | 4901 | breakpoint_cond_eval (void *exp) |
c906108c | 4902 | { |
278cd55f | 4903 | struct value *mark = value_mark (); |
c5aa993b | 4904 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4905 | |
c906108c SS |
4906 | value_free_to_mark (mark); |
4907 | return i; | |
4908 | } | |
4909 | ||
5760d0ab | 4910 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4911 | |
4912 | static bpstat | |
5760d0ab | 4913 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4914 | { |
4915 | bpstat bs; | |
4916 | ||
4917 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4918 | bs->next = NULL; |
4919 | **bs_link_pointer = bs; | |
4920 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4921 | bs->breakpoint_at = bl->owner; |
4922 | bs->bp_location_at = bl; | |
4923 | incref_bp_location (bl); | |
c906108c SS |
4924 | /* If the condition is false, etc., don't do the commands. */ |
4925 | bs->commands = NULL; | |
4926 | bs->old_val = NULL; | |
4927 | bs->print_it = print_it_normal; | |
4928 | return bs; | |
4929 | } | |
4930 | \f | |
d983da9c DJ |
4931 | /* The target has stopped with waitstatus WS. Check if any hardware |
4932 | watchpoints have triggered, according to the target. */ | |
4933 | ||
4934 | int | |
4935 | watchpoints_triggered (struct target_waitstatus *ws) | |
4936 | { | |
d92524f1 | 4937 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4938 | CORE_ADDR addr; |
4939 | struct breakpoint *b; | |
4940 | ||
4941 | if (!stopped_by_watchpoint) | |
4942 | { | |
4943 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4944 | as not triggered. */ | |
4945 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4946 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4947 | { |
4948 | struct watchpoint *w = (struct watchpoint *) b; | |
4949 | ||
4950 | w->watchpoint_triggered = watch_triggered_no; | |
4951 | } | |
d983da9c DJ |
4952 | |
4953 | return 0; | |
4954 | } | |
4955 | ||
4956 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4957 | { | |
4958 | /* We were stopped by a watchpoint, but we don't know where. | |
4959 | Mark all watchpoints as unknown. */ | |
4960 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4961 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4962 | { |
4963 | struct watchpoint *w = (struct watchpoint *) b; | |
4964 | ||
4965 | w->watchpoint_triggered = watch_triggered_unknown; | |
4966 | } | |
d983da9c | 4967 | |
3c4797ba | 4968 | return 1; |
d983da9c DJ |
4969 | } |
4970 | ||
4971 | /* The target could report the data address. Mark watchpoints | |
4972 | affected by this data address as triggered, and all others as not | |
4973 | triggered. */ | |
4974 | ||
4975 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4976 | if (is_hardware_watchpoint (b)) |
d983da9c | 4977 | { |
3a5c3e22 | 4978 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4979 | struct bp_location *loc; |
d983da9c | 4980 | |
3a5c3e22 | 4981 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4982 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4983 | { |
3a5c3e22 | 4984 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4985 | { |
3a5c3e22 PA |
4986 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4987 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4988 | |
4989 | if (newaddr == start) | |
4990 | { | |
3a5c3e22 | 4991 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4992 | break; |
4993 | } | |
4994 | } | |
4995 | /* Exact match not required. Within range is sufficient. */ | |
4996 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4997 | addr, loc->address, | |
4998 | loc->length)) | |
4999 | { | |
3a5c3e22 | 5000 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5001 | break; |
5002 | } | |
5003 | } | |
d983da9c DJ |
5004 | } |
5005 | ||
5006 | return 1; | |
5007 | } | |
5008 | ||
c906108c SS |
5009 | /* Possible return values for watchpoint_check (this can't be an enum |
5010 | because of check_errors). */ | |
5011 | /* The watchpoint has been deleted. */ | |
5012 | #define WP_DELETED 1 | |
5013 | /* The value has changed. */ | |
5014 | #define WP_VALUE_CHANGED 2 | |
5015 | /* The value has not changed. */ | |
5016 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5017 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5018 | #define WP_IGNORE 4 | |
c906108c SS |
5019 | |
5020 | #define BP_TEMPFLAG 1 | |
5021 | #define BP_HARDWAREFLAG 2 | |
5022 | ||
4a64f543 MS |
5023 | /* Evaluate watchpoint condition expression and check if its value |
5024 | changed. | |
553e4c11 JB |
5025 | |
5026 | P should be a pointer to struct bpstat, but is defined as a void * | |
5027 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5028 | |
5029 | static int | |
4efb68b1 | 5030 | watchpoint_check (void *p) |
c906108c SS |
5031 | { |
5032 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5033 | struct watchpoint *b; |
c906108c SS |
5034 | struct frame_info *fr; |
5035 | int within_current_scope; | |
5036 | ||
f431efe5 | 5037 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5038 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5039 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5040 | |
f6bc2008 PA |
5041 | /* If this is a local watchpoint, we only want to check if the |
5042 | watchpoint frame is in scope if the current thread is the thread | |
5043 | that was used to create the watchpoint. */ | |
5044 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5045 | return WP_IGNORE; |
f6bc2008 | 5046 | |
c906108c SS |
5047 | if (b->exp_valid_block == NULL) |
5048 | within_current_scope = 1; | |
5049 | else | |
5050 | { | |
edb3359d DJ |
5051 | struct frame_info *frame = get_current_frame (); |
5052 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5053 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5054 | ||
c9cf6e20 | 5055 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5056 | still in the function but the stack frame has already been |
5057 | invalidated. Since we can't rely on the values of local | |
5058 | variables after the stack has been destroyed, we are treating | |
5059 | the watchpoint in that state as `not changed' without further | |
5060 | checking. Don't mark watchpoints as changed if the current | |
5061 | frame is in an epilogue - even if they are in some other | |
5062 | frame, our view of the stack is likely to be wrong and | |
5063 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5064 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5065 | return WP_IGNORE; |
a0f49112 | 5066 | |
101dcfbe | 5067 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5068 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5069 | |
5070 | /* If we've gotten confused in the unwinder, we might have | |
5071 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5072 | if (within_current_scope) |
5073 | { | |
5074 | struct symbol *function; | |
5075 | ||
5076 | function = get_frame_function (fr); | |
5077 | if (function == NULL | |
5078 | || !contained_in (b->exp_valid_block, | |
5079 | SYMBOL_BLOCK_VALUE (function))) | |
5080 | within_current_scope = 0; | |
5081 | } | |
69fbadd5 | 5082 | |
edb3359d | 5083 | if (within_current_scope) |
c906108c SS |
5084 | /* If we end up stopping, the current frame will get selected |
5085 | in normal_stop. So this call to select_frame won't affect | |
5086 | the user. */ | |
0f7d239c | 5087 | select_frame (fr); |
c906108c | 5088 | } |
c5aa993b | 5089 | |
c906108c SS |
5090 | if (within_current_scope) |
5091 | { | |
4a64f543 MS |
5092 | /* We use value_{,free_to_}mark because it could be a *long* |
5093 | time before we return to the command level and call | |
5094 | free_all_values. We can't call free_all_values because we | |
5095 | might be in the middle of evaluating a function call. */ | |
c906108c | 5096 | |
0cf6dd15 | 5097 | int pc = 0; |
9c06b0b4 | 5098 | struct value *mark; |
fa4727a6 DJ |
5099 | struct value *new_val; |
5100 | ||
3a5c3e22 | 5101 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5102 | /* Since we don't know the exact trigger address (from |
5103 | stopped_data_address), just tell the user we've triggered | |
5104 | a mask watchpoint. */ | |
5105 | return WP_VALUE_CHANGED; | |
5106 | ||
5107 | mark = value_mark (); | |
3a1115a0 | 5108 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5109 | |
bb9d5f81 PP |
5110 | if (b->val_bitsize != 0) |
5111 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5112 | ||
4a64f543 MS |
5113 | /* We use value_equal_contents instead of value_equal because |
5114 | the latter coerces an array to a pointer, thus comparing just | |
5115 | the address of the array instead of its contents. This is | |
5116 | not what we want. */ | |
fa4727a6 | 5117 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5118 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5119 | { |
fa4727a6 DJ |
5120 | if (new_val != NULL) |
5121 | { | |
5122 | release_value (new_val); | |
5123 | value_free_to_mark (mark); | |
5124 | } | |
c906108c SS |
5125 | bs->old_val = b->val; |
5126 | b->val = new_val; | |
fa4727a6 | 5127 | b->val_valid = 1; |
c906108c SS |
5128 | return WP_VALUE_CHANGED; |
5129 | } | |
5130 | else | |
5131 | { | |
60e1c644 | 5132 | /* Nothing changed. */ |
c906108c | 5133 | value_free_to_mark (mark); |
c906108c SS |
5134 | return WP_VALUE_NOT_CHANGED; |
5135 | } | |
5136 | } | |
5137 | else | |
5138 | { | |
79a45e25 PA |
5139 | struct ui_out *uiout = current_uiout; |
5140 | ||
c906108c | 5141 | /* This seems like the only logical thing to do because |
c5aa993b JM |
5142 | if we temporarily ignored the watchpoint, then when |
5143 | we reenter the block in which it is valid it contains | |
5144 | garbage (in the case of a function, it may have two | |
5145 | garbage values, one before and one after the prologue). | |
5146 | So we can't even detect the first assignment to it and | |
5147 | watch after that (since the garbage may or may not equal | |
5148 | the first value assigned). */ | |
348d480f PA |
5149 | /* We print all the stop information in |
5150 | breakpoint_ops->print_it, but in this case, by the time we | |
5151 | call breakpoint_ops->print_it this bp will be deleted | |
5152 | already. So we have no choice but print the information | |
5153 | here. */ | |
9dc5e2a9 | 5154 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
5155 | ui_out_field_string |
5156 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 5157 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 5158 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
5159 | ui_out_text (uiout, |
5160 | " deleted because the program has left the block in\n\ | |
8b93c638 | 5161 | which its expression is valid.\n"); |
4ce44c66 | 5162 | |
cdac0397 | 5163 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5164 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5165 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5166 | |
5167 | return WP_DELETED; | |
5168 | } | |
5169 | } | |
5170 | ||
18a18393 | 5171 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5172 | breakpoint location BL. This function does not check if we should |
5173 | stop, only if BL explains the stop. */ | |
5174 | ||
18a18393 | 5175 | static int |
6c95b8df | 5176 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5177 | struct address_space *aspace, CORE_ADDR bp_addr, |
5178 | const struct target_waitstatus *ws) | |
18a18393 VP |
5179 | { |
5180 | struct breakpoint *b = bl->owner; | |
5181 | ||
348d480f | 5182 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5183 | gdb_assert (b != NULL); |
5184 | ||
09ac7c10 | 5185 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5186 | } |
5187 | ||
3a5c3e22 PA |
5188 | /* Determine if the watched values have actually changed, and we |
5189 | should stop. If not, set BS->stop to 0. */ | |
5190 | ||
18a18393 VP |
5191 | static void |
5192 | bpstat_check_watchpoint (bpstat bs) | |
5193 | { | |
2bdf28a0 | 5194 | const struct bp_location *bl; |
3a5c3e22 | 5195 | struct watchpoint *b; |
2bdf28a0 JK |
5196 | |
5197 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5198 | bl = bs->bp_location_at; |
2bdf28a0 | 5199 | gdb_assert (bl != NULL); |
3a5c3e22 | 5200 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5201 | gdb_assert (b != NULL); |
18a18393 | 5202 | |
18a18393 | 5203 | { |
18a18393 VP |
5204 | int must_check_value = 0; |
5205 | ||
3a5c3e22 | 5206 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5207 | /* For a software watchpoint, we must always check the |
5208 | watched value. */ | |
5209 | must_check_value = 1; | |
5210 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5211 | /* We have a hardware watchpoint (read, write, or access) | |
5212 | and the target earlier reported an address watched by | |
5213 | this watchpoint. */ | |
5214 | must_check_value = 1; | |
5215 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5216 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5217 | /* We were stopped by a hardware watchpoint, but the target could |
5218 | not report the data address. We must check the watchpoint's | |
5219 | value. Access and read watchpoints are out of luck; without | |
5220 | a data address, we can't figure it out. */ | |
5221 | must_check_value = 1; | |
3a5c3e22 | 5222 | |
18a18393 VP |
5223 | if (must_check_value) |
5224 | { | |
3e43a32a MS |
5225 | char *message |
5226 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5227 | b->base.number); |
18a18393 VP |
5228 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5229 | int e = catch_errors (watchpoint_check, bs, message, | |
5230 | RETURN_MASK_ALL); | |
5231 | do_cleanups (cleanups); | |
5232 | switch (e) | |
5233 | { | |
5234 | case WP_DELETED: | |
5235 | /* We've already printed what needs to be printed. */ | |
5236 | bs->print_it = print_it_done; | |
5237 | /* Stop. */ | |
5238 | break; | |
60e1c644 PA |
5239 | case WP_IGNORE: |
5240 | bs->print_it = print_it_noop; | |
5241 | bs->stop = 0; | |
5242 | break; | |
18a18393 | 5243 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5244 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5245 | { |
85d721b8 PA |
5246 | /* There are two cases to consider here: |
5247 | ||
4a64f543 | 5248 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5249 | In that case, trust the target, and always report |
5250 | the watchpoint hit to the user. Even though | |
5251 | reads don't cause value changes, the value may | |
5252 | have changed since the last time it was read, and | |
5253 | since we're not trapping writes, we will not see | |
5254 | those, and as such we should ignore our notion of | |
5255 | old value. | |
5256 | ||
4a64f543 | 5257 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5258 | reads and writes. There are two ways this may |
5259 | happen: | |
5260 | ||
4a64f543 | 5261 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5262 | reads only, but can break on accesses (reads or |
5263 | writes), such as e.g., x86. We detect this case | |
5264 | at the time we try to insert read watchpoints. | |
5265 | ||
4a64f543 | 5266 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5267 | watchpoints, but, the user set an access or write |
5268 | watchpoint watching the same memory as this read | |
5269 | watchpoint. | |
5270 | ||
5271 | If we're watching memory writes as well as reads, | |
5272 | ignore watchpoint hits when we find that the | |
5273 | value hasn't changed, as reads don't cause | |
5274 | changes. This still gives false positives when | |
5275 | the program writes the same value to memory as | |
5276 | what there was already in memory (we will confuse | |
5277 | it for a read), but it's much better than | |
5278 | nothing. */ | |
5279 | ||
5280 | int other_write_watchpoint = 0; | |
5281 | ||
5282 | if (bl->watchpoint_type == hw_read) | |
5283 | { | |
5284 | struct breakpoint *other_b; | |
5285 | ||
5286 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5287 | if (other_b->type == bp_hardware_watchpoint |
5288 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5289 | { |
3a5c3e22 PA |
5290 | struct watchpoint *other_w = |
5291 | (struct watchpoint *) other_b; | |
5292 | ||
5293 | if (other_w->watchpoint_triggered | |
5294 | == watch_triggered_yes) | |
5295 | { | |
5296 | other_write_watchpoint = 1; | |
5297 | break; | |
5298 | } | |
85d721b8 PA |
5299 | } |
5300 | } | |
5301 | ||
5302 | if (other_write_watchpoint | |
5303 | || bl->watchpoint_type == hw_access) | |
5304 | { | |
5305 | /* We're watching the same memory for writes, | |
5306 | and the value changed since the last time we | |
5307 | updated it, so this trap must be for a write. | |
5308 | Ignore it. */ | |
5309 | bs->print_it = print_it_noop; | |
5310 | bs->stop = 0; | |
5311 | } | |
18a18393 VP |
5312 | } |
5313 | break; | |
5314 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5315 | if (b->base.type == bp_hardware_watchpoint |
5316 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5317 | { |
5318 | /* Don't stop: write watchpoints shouldn't fire if | |
5319 | the value hasn't changed. */ | |
5320 | bs->print_it = print_it_noop; | |
5321 | bs->stop = 0; | |
5322 | } | |
5323 | /* Stop. */ | |
5324 | break; | |
5325 | default: | |
5326 | /* Can't happen. */ | |
5327 | case 0: | |
5328 | /* Error from catch_errors. */ | |
3a5c3e22 | 5329 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5330 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5331 | /* We've already printed what needs to be printed. */ |
5332 | bs->print_it = print_it_done; | |
5333 | break; | |
5334 | } | |
5335 | } | |
5336 | else /* must_check_value == 0 */ | |
5337 | { | |
5338 | /* This is a case where some watchpoint(s) triggered, but | |
5339 | not at the address of this watchpoint, or else no | |
5340 | watchpoint triggered after all. So don't print | |
5341 | anything for this watchpoint. */ | |
5342 | bs->print_it = print_it_noop; | |
5343 | bs->stop = 0; | |
5344 | } | |
5345 | } | |
5346 | } | |
5347 | ||
7d4df6a4 DE |
5348 | /* For breakpoints that are currently marked as telling gdb to stop, |
5349 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5350 | of breakpoint referred to by BS. If we should not stop for this |
5351 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5352 | |
18a18393 VP |
5353 | static void |
5354 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5355 | { | |
2bdf28a0 JK |
5356 | const struct bp_location *bl; |
5357 | struct breakpoint *b; | |
7d4df6a4 DE |
5358 | int value_is_zero = 0; |
5359 | struct expression *cond; | |
5360 | ||
5361 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5362 | |
5363 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5364 | bl = bs->bp_location_at; |
2bdf28a0 | 5365 | gdb_assert (bl != NULL); |
f431efe5 | 5366 | b = bs->breakpoint_at; |
2bdf28a0 | 5367 | gdb_assert (b != NULL); |
18a18393 | 5368 | |
b775012e LM |
5369 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5370 | need to do so again since GDB does not know if we stopped due to a | |
5371 | breakpoint or a single step breakpoint. */ | |
5372 | ||
18a18393 | 5373 | if (frame_id_p (b->frame_id) |
edb3359d | 5374 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5375 | { |
7d4df6a4 DE |
5376 | bs->stop = 0; |
5377 | return; | |
5378 | } | |
60e1c644 | 5379 | |
12ab52e9 PA |
5380 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5381 | evaluating the condition if this isn't the specified | |
5382 | thread/task. */ | |
5383 | if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid)) | |
5384 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) | |
5385 | ||
6c1b0f7b DE |
5386 | { |
5387 | bs->stop = 0; | |
5388 | return; | |
5389 | } | |
5390 | ||
6dddc817 DE |
5391 | /* Evaluate extension language breakpoints that have a "stop" method |
5392 | implemented. */ | |
5393 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5394 | |
7d4df6a4 DE |
5395 | if (is_watchpoint (b)) |
5396 | { | |
5397 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5398 | |
7d4df6a4 DE |
5399 | cond = w->cond_exp; |
5400 | } | |
5401 | else | |
5402 | cond = bl->cond; | |
60e1c644 | 5403 | |
7d4df6a4 DE |
5404 | if (cond && b->disposition != disp_del_at_next_stop) |
5405 | { | |
5406 | int within_current_scope = 1; | |
5407 | struct watchpoint * w; | |
60e1c644 | 5408 | |
7d4df6a4 DE |
5409 | /* We use value_mark and value_free_to_mark because it could |
5410 | be a long time before we return to the command level and | |
5411 | call free_all_values. We can't call free_all_values | |
5412 | because we might be in the middle of evaluating a | |
5413 | function call. */ | |
5414 | struct value *mark = value_mark (); | |
5415 | ||
5416 | if (is_watchpoint (b)) | |
5417 | w = (struct watchpoint *) b; | |
5418 | else | |
5419 | w = NULL; | |
5420 | ||
5421 | /* Need to select the frame, with all that implies so that | |
5422 | the conditions will have the right context. Because we | |
5423 | use the frame, we will not see an inlined function's | |
5424 | variables when we arrive at a breakpoint at the start | |
5425 | of the inlined function; the current frame will be the | |
5426 | call site. */ | |
5427 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5428 | select_frame (get_current_frame ()); | |
5429 | else | |
18a18393 | 5430 | { |
7d4df6a4 DE |
5431 | struct frame_info *frame; |
5432 | ||
5433 | /* For local watchpoint expressions, which particular | |
5434 | instance of a local is being watched matters, so we | |
5435 | keep track of the frame to evaluate the expression | |
5436 | in. To evaluate the condition however, it doesn't | |
5437 | really matter which instantiation of the function | |
5438 | where the condition makes sense triggers the | |
5439 | watchpoint. This allows an expression like "watch | |
5440 | global if q > 10" set in `func', catch writes to | |
5441 | global on all threads that call `func', or catch | |
5442 | writes on all recursive calls of `func' by a single | |
5443 | thread. We simply always evaluate the condition in | |
5444 | the innermost frame that's executing where it makes | |
5445 | sense to evaluate the condition. It seems | |
5446 | intuitive. */ | |
5447 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5448 | if (frame != NULL) | |
5449 | select_frame (frame); | |
5450 | else | |
5451 | within_current_scope = 0; | |
18a18393 | 5452 | } |
7d4df6a4 DE |
5453 | if (within_current_scope) |
5454 | value_is_zero | |
5455 | = catch_errors (breakpoint_cond_eval, cond, | |
5456 | "Error in testing breakpoint condition:\n", | |
5457 | RETURN_MASK_ALL); | |
5458 | else | |
18a18393 | 5459 | { |
7d4df6a4 DE |
5460 | warning (_("Watchpoint condition cannot be tested " |
5461 | "in the current scope")); | |
5462 | /* If we failed to set the right context for this | |
5463 | watchpoint, unconditionally report it. */ | |
5464 | value_is_zero = 0; | |
18a18393 | 5465 | } |
7d4df6a4 DE |
5466 | /* FIXME-someday, should give breakpoint #. */ |
5467 | value_free_to_mark (mark); | |
18a18393 | 5468 | } |
7d4df6a4 DE |
5469 | |
5470 | if (cond && value_is_zero) | |
5471 | { | |
5472 | bs->stop = 0; | |
5473 | } | |
7d4df6a4 DE |
5474 | else if (b->ignore_count > 0) |
5475 | { | |
5476 | b->ignore_count--; | |
5477 | bs->stop = 0; | |
5478 | /* Increase the hit count even though we don't stop. */ | |
5479 | ++(b->hit_count); | |
5480 | observer_notify_breakpoint_modified (b); | |
5481 | } | |
18a18393 VP |
5482 | } |
5483 | ||
1cf4d951 PA |
5484 | /* Returns true if we need to track moribund locations of LOC's type |
5485 | on the current target. */ | |
5486 | ||
5487 | static int | |
5488 | need_moribund_for_location_type (struct bp_location *loc) | |
5489 | { | |
5490 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5491 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5492 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5493 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5494 | } | |
5495 | ||
18a18393 | 5496 | |
9709f61c | 5497 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5498 | BP_ADDR in thread PTID. |
c906108c | 5499 | |
d983da9c | 5500 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5501 | don't understand this stop. Result is a chain of bpstat's such |
5502 | that: | |
c906108c | 5503 | |
c5aa993b | 5504 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5505 | |
c5aa993b | 5506 | if we understand why we stopped, the result is not null. |
c906108c | 5507 | |
c5aa993b JM |
5508 | Each element of the chain refers to a particular breakpoint or |
5509 | watchpoint at which we have stopped. (We may have stopped for | |
5510 | several reasons concurrently.) | |
c906108c | 5511 | |
c5aa993b JM |
5512 | Each element of the chain has valid next, breakpoint_at, |
5513 | commands, FIXME??? fields. */ | |
c906108c SS |
5514 | |
5515 | bpstat | |
6c95b8df | 5516 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5517 | CORE_ADDR bp_addr, ptid_t ptid, |
5518 | const struct target_waitstatus *ws) | |
c906108c | 5519 | { |
0d381245 | 5520 | struct breakpoint *b = NULL; |
afe38095 | 5521 | struct bp_location *bl; |
20874c92 | 5522 | struct bp_location *loc; |
5760d0ab JK |
5523 | /* First item of allocated bpstat's. */ |
5524 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5525 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5526 | bpstat bs; |
20874c92 | 5527 | int ix; |
429374b8 | 5528 | int need_remove_insert; |
f431efe5 | 5529 | int removed_any; |
c906108c | 5530 | |
f431efe5 PA |
5531 | /* First, build the bpstat chain with locations that explain a |
5532 | target stop, while being careful to not set the target running, | |
5533 | as that may invalidate locations (in particular watchpoint | |
5534 | locations are recreated). Resuming will happen here with | |
5535 | breakpoint conditions or watchpoint expressions that include | |
5536 | inferior function calls. */ | |
c5aa993b | 5537 | |
429374b8 JK |
5538 | ALL_BREAKPOINTS (b) |
5539 | { | |
1a853c52 | 5540 | if (!breakpoint_enabled (b)) |
429374b8 | 5541 | continue; |
a5606eee | 5542 | |
429374b8 JK |
5543 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5544 | { | |
4a64f543 MS |
5545 | /* For hardware watchpoints, we look only at the first |
5546 | location. The watchpoint_check function will work on the | |
5547 | entire expression, not the individual locations. For | |
5548 | read watchpoints, the watchpoints_triggered function has | |
5549 | checked all locations already. */ | |
429374b8 JK |
5550 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5551 | break; | |
18a18393 | 5552 | |
f6592439 | 5553 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5554 | continue; |
c5aa993b | 5555 | |
09ac7c10 | 5556 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5557 | continue; |
c5aa993b | 5558 | |
4a64f543 MS |
5559 | /* Come here if it's a watchpoint, or if the break address |
5560 | matches. */ | |
c5aa993b | 5561 | |
4a64f543 MS |
5562 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5563 | explain stop. */ | |
c5aa993b | 5564 | |
f431efe5 PA |
5565 | /* Assume we stop. Should we find a watchpoint that is not |
5566 | actually triggered, or if the condition of the breakpoint | |
5567 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5568 | bs->stop = 1; |
5569 | bs->print = 1; | |
d983da9c | 5570 | |
f431efe5 PA |
5571 | /* If this is a scope breakpoint, mark the associated |
5572 | watchpoint as triggered so that we will handle the | |
5573 | out-of-scope event. We'll get to the watchpoint next | |
5574 | iteration. */ | |
d0fb5eae | 5575 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5576 | { |
5577 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5578 | ||
5579 | w->watchpoint_triggered = watch_triggered_yes; | |
5580 | } | |
f431efe5 PA |
5581 | } |
5582 | } | |
5583 | ||
7c16b83e | 5584 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5585 | if (!target_supports_stopped_by_sw_breakpoint () |
5586 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5587 | { |
1cf4d951 | 5588 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5589 | { |
1cf4d951 PA |
5590 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5591 | && need_moribund_for_location_type (loc)) | |
5592 | { | |
5593 | bs = bpstat_alloc (loc, &bs_link); | |
5594 | /* For hits of moribund locations, we should just proceed. */ | |
5595 | bs->stop = 0; | |
5596 | bs->print = 0; | |
5597 | bs->print_it = print_it_noop; | |
5598 | } | |
f431efe5 PA |
5599 | } |
5600 | } | |
5601 | ||
edcc5120 TT |
5602 | /* A bit of special processing for shlib breakpoints. We need to |
5603 | process solib loading here, so that the lists of loaded and | |
5604 | unloaded libraries are correct before we handle "catch load" and | |
5605 | "catch unload". */ | |
5606 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5607 | { | |
5d268276 | 5608 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5609 | { |
5610 | handle_solib_event (); | |
5611 | break; | |
5612 | } | |
5613 | } | |
5614 | ||
f431efe5 PA |
5615 | /* Now go through the locations that caused the target to stop, and |
5616 | check whether we're interested in reporting this stop to higher | |
5617 | layers, or whether we should resume the target transparently. */ | |
5618 | ||
5619 | removed_any = 0; | |
5620 | ||
5760d0ab | 5621 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5622 | { |
5623 | if (!bs->stop) | |
5624 | continue; | |
5625 | ||
f431efe5 | 5626 | b = bs->breakpoint_at; |
348d480f PA |
5627 | b->ops->check_status (bs); |
5628 | if (bs->stop) | |
28010a5d | 5629 | { |
348d480f | 5630 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5631 | |
429374b8 JK |
5632 | if (bs->stop) |
5633 | { | |
5634 | ++(b->hit_count); | |
8d3788bd | 5635 | observer_notify_breakpoint_modified (b); |
c906108c | 5636 | |
4a64f543 | 5637 | /* We will stop here. */ |
429374b8 JK |
5638 | if (b->disposition == disp_disable) |
5639 | { | |
816338b5 | 5640 | --(b->enable_count); |
1a853c52 | 5641 | if (b->enable_count <= 0) |
429374b8 | 5642 | b->enable_state = bp_disabled; |
f431efe5 | 5643 | removed_any = 1; |
429374b8 JK |
5644 | } |
5645 | if (b->silent) | |
5646 | bs->print = 0; | |
5647 | bs->commands = b->commands; | |
9add0f1b | 5648 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5649 | if (command_line_is_silent (bs->commands |
5650 | ? bs->commands->commands : NULL)) | |
5651 | bs->print = 0; | |
9d6e6e84 HZ |
5652 | |
5653 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5654 | } |
5655 | ||
348d480f | 5656 | } |
a9b3a50f PA |
5657 | |
5658 | /* Print nothing for this entry if we don't stop or don't | |
5659 | print. */ | |
5660 | if (!bs->stop || !bs->print) | |
5661 | bs->print_it = print_it_noop; | |
429374b8 | 5662 | } |
876fa593 | 5663 | |
d983da9c DJ |
5664 | /* If we aren't stopping, the value of some hardware watchpoint may |
5665 | not have changed, but the intermediate memory locations we are | |
5666 | watching may have. Don't bother if we're stopping; this will get | |
5667 | done later. */ | |
d832cb68 | 5668 | need_remove_insert = 0; |
5760d0ab JK |
5669 | if (! bpstat_causes_stop (bs_head)) |
5670 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5671 | if (!bs->stop |
f431efe5 PA |
5672 | && bs->breakpoint_at |
5673 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5674 | { |
3a5c3e22 PA |
5675 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5676 | ||
5677 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5678 | need_remove_insert = 1; |
d983da9c DJ |
5679 | } |
5680 | ||
d832cb68 | 5681 | if (need_remove_insert) |
44702360 | 5682 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5683 | else if (removed_any) |
44702360 | 5684 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5685 | |
5760d0ab | 5686 | return bs_head; |
c906108c | 5687 | } |
628fe4e4 JK |
5688 | |
5689 | static void | |
5690 | handle_jit_event (void) | |
5691 | { | |
5692 | struct frame_info *frame; | |
5693 | struct gdbarch *gdbarch; | |
5694 | ||
5695 | /* Switch terminal for any messages produced by | |
5696 | breakpoint_re_set. */ | |
5697 | target_terminal_ours_for_output (); | |
5698 | ||
5699 | frame = get_current_frame (); | |
5700 | gdbarch = get_frame_arch (frame); | |
5701 | ||
5702 | jit_event_handler (gdbarch); | |
5703 | ||
5704 | target_terminal_inferior (); | |
5705 | } | |
5706 | ||
5707 | /* Prepare WHAT final decision for infrun. */ | |
5708 | ||
5709 | /* Decide what infrun needs to do with this bpstat. */ | |
5710 | ||
c906108c | 5711 | struct bpstat_what |
0e30163f | 5712 | bpstat_what (bpstat bs_head) |
c906108c | 5713 | { |
c906108c | 5714 | struct bpstat_what retval; |
628fe4e4 | 5715 | int jit_event = 0; |
0e30163f | 5716 | bpstat bs; |
c906108c | 5717 | |
628fe4e4 | 5718 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5719 | retval.call_dummy = STOP_NONE; |
186c406b | 5720 | retval.is_longjmp = 0; |
628fe4e4 | 5721 | |
0e30163f | 5722 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5723 | { |
628fe4e4 JK |
5724 | /* Extract this BS's action. After processing each BS, we check |
5725 | if its action overrides all we've seem so far. */ | |
5726 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5727 | enum bptype bptype; | |
5728 | ||
c906108c | 5729 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5730 | { |
5731 | /* I suspect this can happen if it was a momentary | |
5732 | breakpoint which has since been deleted. */ | |
5733 | bptype = bp_none; | |
5734 | } | |
20874c92 | 5735 | else |
f431efe5 | 5736 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5737 | |
5738 | switch (bptype) | |
c906108c SS |
5739 | { |
5740 | case bp_none: | |
628fe4e4 | 5741 | break; |
c906108c SS |
5742 | case bp_breakpoint: |
5743 | case bp_hardware_breakpoint: | |
7c16b83e | 5744 | case bp_single_step: |
c906108c SS |
5745 | case bp_until: |
5746 | case bp_finish: | |
a9b3a50f | 5747 | case bp_shlib_event: |
c906108c SS |
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 | 5756 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5757 | break; |
5758 | case bp_watchpoint: | |
5759 | case bp_hardware_watchpoint: | |
5760 | case bp_read_watchpoint: | |
5761 | case bp_access_watchpoint: | |
5762 | if (bs->stop) | |
5763 | { | |
5764 | if (bs->print) | |
628fe4e4 | 5765 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5766 | else |
628fe4e4 | 5767 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5768 | } |
5769 | else | |
628fe4e4 JK |
5770 | { |
5771 | /* There was a watchpoint, but we're not stopping. | |
5772 | This requires no further action. */ | |
5773 | } | |
c906108c SS |
5774 | break; |
5775 | case bp_longjmp: | |
e2e4d78b | 5776 | case bp_longjmp_call_dummy: |
186c406b | 5777 | case bp_exception: |
0a39bb32 PA |
5778 | if (bs->stop) |
5779 | { | |
5780 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5781 | retval.is_longjmp = bptype != bp_exception; | |
5782 | } | |
5783 | else | |
5784 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5785 | break; |
5786 | case bp_longjmp_resume: | |
186c406b | 5787 | case bp_exception_resume: |
0a39bb32 PA |
5788 | if (bs->stop) |
5789 | { | |
5790 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5791 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5792 | } | |
5793 | else | |
5794 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5795 | break; |
5796 | case bp_step_resume: | |
5797 | if (bs->stop) | |
628fe4e4 JK |
5798 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5799 | else | |
c906108c | 5800 | { |
628fe4e4 JK |
5801 | /* It is for the wrong frame. */ |
5802 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5803 | } |
c906108c | 5804 | break; |
2c03e5be PA |
5805 | case bp_hp_step_resume: |
5806 | if (bs->stop) | |
5807 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5808 | else | |
5809 | { | |
5810 | /* It is for the wrong frame. */ | |
5811 | this_action = BPSTAT_WHAT_SINGLE; | |
5812 | } | |
5813 | break; | |
c906108c | 5814 | case bp_watchpoint_scope: |
c4093a6a | 5815 | case bp_thread_event: |
1900040c | 5816 | case bp_overlay_event: |
0fd8e87f | 5817 | case bp_longjmp_master: |
aa7d318d | 5818 | case bp_std_terminate_master: |
186c406b | 5819 | case bp_exception_master: |
628fe4e4 | 5820 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5821 | break; |
ce78b96d | 5822 | case bp_catchpoint: |
c5aa993b JM |
5823 | if (bs->stop) |
5824 | { | |
5825 | if (bs->print) | |
628fe4e4 | 5826 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5827 | else |
628fe4e4 | 5828 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5829 | } |
5830 | else | |
628fe4e4 JK |
5831 | { |
5832 | /* There was a catchpoint, but we're not stopping. | |
5833 | This requires no further action. */ | |
5834 | } | |
5835 | break; | |
628fe4e4 JK |
5836 | case bp_jit_event: |
5837 | jit_event = 1; | |
5838 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5839 | break; |
c906108c | 5840 | case bp_call_dummy: |
53a5351d JM |
5841 | /* Make sure the action is stop (silent or noisy), |
5842 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5843 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5844 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5845 | break; |
5846 | case bp_std_terminate: | |
5847 | /* Make sure the action is stop (silent or noisy), | |
5848 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5849 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5850 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5851 | break; |
1042e4c0 | 5852 | case bp_tracepoint: |
7a697b8d | 5853 | case bp_fast_tracepoint: |
0fb4aa4b | 5854 | case bp_static_tracepoint: |
1042e4c0 SS |
5855 | /* Tracepoint hits should not be reported back to GDB, and |
5856 | if one got through somehow, it should have been filtered | |
5857 | out already. */ | |
5858 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5859 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5860 | break; |
5861 | case bp_gnu_ifunc_resolver: | |
5862 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5863 | this_action = BPSTAT_WHAT_SINGLE; | |
5864 | break; | |
5865 | case bp_gnu_ifunc_resolver_return: | |
5866 | /* The breakpoint will be removed, execution will restart from the | |
5867 | PC of the former breakpoint. */ | |
5868 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5869 | break; | |
e7e0cddf SS |
5870 | |
5871 | case bp_dprintf: | |
a11cfd87 HZ |
5872 | if (bs->stop) |
5873 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5874 | else | |
5875 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5876 | break; |
5877 | ||
628fe4e4 JK |
5878 | default: |
5879 | internal_error (__FILE__, __LINE__, | |
5880 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5881 | } |
628fe4e4 JK |
5882 | |
5883 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5884 | } |
628fe4e4 | 5885 | |
0e30163f JK |
5886 | /* These operations may affect the bs->breakpoint_at state so they are |
5887 | delayed after MAIN_ACTION is decided above. */ | |
5888 | ||
628fe4e4 JK |
5889 | if (jit_event) |
5890 | { | |
5891 | if (debug_infrun) | |
5892 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5893 | ||
5894 | handle_jit_event (); | |
5895 | } | |
5896 | ||
0e30163f JK |
5897 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5898 | { | |
5899 | struct breakpoint *b = bs->breakpoint_at; | |
5900 | ||
5901 | if (b == NULL) | |
5902 | continue; | |
5903 | switch (b->type) | |
5904 | { | |
5905 | case bp_gnu_ifunc_resolver: | |
5906 | gnu_ifunc_resolver_stop (b); | |
5907 | break; | |
5908 | case bp_gnu_ifunc_resolver_return: | |
5909 | gnu_ifunc_resolver_return_stop (b); | |
5910 | break; | |
5911 | } | |
5912 | } | |
5913 | ||
c906108c SS |
5914 | return retval; |
5915 | } | |
5916 | ||
5917 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5918 | without hardware support). This isn't related to a specific bpstat, | |
5919 | just to things like whether watchpoints are set. */ | |
5920 | ||
c5aa993b | 5921 | int |
fba45db2 | 5922 | bpstat_should_step (void) |
c906108c SS |
5923 | { |
5924 | struct breakpoint *b; | |
cc59ec59 | 5925 | |
c906108c | 5926 | ALL_BREAKPOINTS (b) |
717a8278 | 5927 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5928 | return 1; |
c906108c SS |
5929 | return 0; |
5930 | } | |
5931 | ||
67822962 PA |
5932 | int |
5933 | bpstat_causes_stop (bpstat bs) | |
5934 | { | |
5935 | for (; bs != NULL; bs = bs->next) | |
5936 | if (bs->stop) | |
5937 | return 1; | |
5938 | ||
5939 | return 0; | |
5940 | } | |
5941 | ||
c906108c | 5942 | \f |
c5aa993b | 5943 | |
170b53b2 UW |
5944 | /* Compute a string of spaces suitable to indent the next line |
5945 | so it starts at the position corresponding to the table column | |
5946 | named COL_NAME in the currently active table of UIOUT. */ | |
5947 | ||
5948 | static char * | |
5949 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5950 | { | |
5951 | static char wrap_indent[80]; | |
5952 | int i, total_width, width, align; | |
5953 | char *text; | |
5954 | ||
5955 | total_width = 0; | |
5956 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5957 | { | |
5958 | if (strcmp (text, col_name) == 0) | |
5959 | { | |
5960 | gdb_assert (total_width < sizeof wrap_indent); | |
5961 | memset (wrap_indent, ' ', total_width); | |
5962 | wrap_indent[total_width] = 0; | |
5963 | ||
5964 | return wrap_indent; | |
5965 | } | |
5966 | ||
5967 | total_width += width + 1; | |
5968 | } | |
5969 | ||
5970 | return NULL; | |
5971 | } | |
5972 | ||
b775012e LM |
5973 | /* Determine if the locations of this breakpoint will have their conditions |
5974 | evaluated by the target, host or a mix of both. Returns the following: | |
5975 | ||
5976 | "host": Host evals condition. | |
5977 | "host or target": Host or Target evals condition. | |
5978 | "target": Target evals condition. | |
5979 | */ | |
5980 | ||
5981 | static const char * | |
5982 | bp_condition_evaluator (struct breakpoint *b) | |
5983 | { | |
5984 | struct bp_location *bl; | |
5985 | char host_evals = 0; | |
5986 | char target_evals = 0; | |
5987 | ||
5988 | if (!b) | |
5989 | return NULL; | |
5990 | ||
5991 | if (!is_breakpoint (b)) | |
5992 | return NULL; | |
5993 | ||
5994 | if (gdb_evaluates_breakpoint_condition_p () | |
5995 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5996 | return condition_evaluation_host; | |
5997 | ||
5998 | for (bl = b->loc; bl; bl = bl->next) | |
5999 | { | |
6000 | if (bl->cond_bytecode) | |
6001 | target_evals++; | |
6002 | else | |
6003 | host_evals++; | |
6004 | } | |
6005 | ||
6006 | if (host_evals && target_evals) | |
6007 | return condition_evaluation_both; | |
6008 | else if (target_evals) | |
6009 | return condition_evaluation_target; | |
6010 | else | |
6011 | return condition_evaluation_host; | |
6012 | } | |
6013 | ||
6014 | /* Determine the breakpoint location's condition evaluator. This is | |
6015 | similar to bp_condition_evaluator, but for locations. */ | |
6016 | ||
6017 | static const char * | |
6018 | bp_location_condition_evaluator (struct bp_location *bl) | |
6019 | { | |
6020 | if (bl && !is_breakpoint (bl->owner)) | |
6021 | return NULL; | |
6022 | ||
6023 | if (gdb_evaluates_breakpoint_condition_p () | |
6024 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6025 | return condition_evaluation_host; | |
6026 | ||
6027 | if (bl && bl->cond_bytecode) | |
6028 | return condition_evaluation_target; | |
6029 | else | |
6030 | return condition_evaluation_host; | |
6031 | } | |
6032 | ||
859825b8 JK |
6033 | /* Print the LOC location out of the list of B->LOC locations. */ |
6034 | ||
170b53b2 UW |
6035 | static void |
6036 | print_breakpoint_location (struct breakpoint *b, | |
6037 | struct bp_location *loc) | |
0d381245 | 6038 | { |
79a45e25 | 6039 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
6040 | struct cleanup *old_chain = save_current_program_space (); |
6041 | ||
859825b8 JK |
6042 | if (loc != NULL && loc->shlib_disabled) |
6043 | loc = NULL; | |
6044 | ||
6c95b8df PA |
6045 | if (loc != NULL) |
6046 | set_current_program_space (loc->pspace); | |
6047 | ||
56435ebe | 6048 | if (b->display_canonical) |
f00aae0f KS |
6049 | ui_out_field_string (uiout, "what", |
6050 | event_location_to_string (b->location)); | |
2f202fde | 6051 | else if (loc && loc->symtab) |
0d381245 VP |
6052 | { |
6053 | struct symbol *sym | |
6054 | = find_pc_sect_function (loc->address, loc->section); | |
6055 | if (sym) | |
6056 | { | |
6057 | ui_out_text (uiout, "in "); | |
6058 | ui_out_field_string (uiout, "func", | |
6059 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
6060 | ui_out_text (uiout, " "); |
6061 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
6062 | ui_out_text (uiout, "at "); | |
0d381245 | 6063 | } |
05cba821 JK |
6064 | ui_out_field_string (uiout, "file", |
6065 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 6066 | ui_out_text (uiout, ":"); |
05cba821 | 6067 | |
0d381245 | 6068 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
6069 | ui_out_field_string (uiout, "fullname", |
6070 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 6071 | |
f8eba3c6 | 6072 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 6073 | } |
859825b8 | 6074 | else if (loc) |
0d381245 | 6075 | { |
f99d8bf4 PA |
6076 | struct ui_file *stb = mem_fileopen (); |
6077 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 6078 | |
f99d8bf4 | 6079 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 6080 | demangle, ""); |
0d381245 | 6081 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
6082 | |
6083 | do_cleanups (stb_chain); | |
0d381245 | 6084 | } |
859825b8 | 6085 | else |
f00aae0f KS |
6086 | { |
6087 | ui_out_field_string (uiout, "pending", | |
6088 | event_location_to_string (b->location)); | |
6089 | /* If extra_string is available, it could be holding a condition | |
6090 | or dprintf arguments. In either case, make sure it is printed, | |
6091 | too, but only for non-MI streams. */ | |
6092 | if (!ui_out_is_mi_like_p (uiout) && b->extra_string != NULL) | |
6093 | { | |
6094 | if (b->type == bp_dprintf) | |
6095 | ui_out_text (uiout, ","); | |
6096 | else | |
6097 | ui_out_text (uiout, " "); | |
6098 | ui_out_text (uiout, b->extra_string); | |
6099 | } | |
6100 | } | |
6c95b8df | 6101 | |
b775012e LM |
6102 | if (loc && is_breakpoint (b) |
6103 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6104 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6105 | { | |
6106 | ui_out_text (uiout, " ("); | |
6107 | ui_out_field_string (uiout, "evaluated-by", | |
6108 | bp_location_condition_evaluator (loc)); | |
6109 | ui_out_text (uiout, ")"); | |
6110 | } | |
6111 | ||
6c95b8df | 6112 | do_cleanups (old_chain); |
0d381245 VP |
6113 | } |
6114 | ||
269b11a2 PA |
6115 | static const char * |
6116 | bptype_string (enum bptype type) | |
c906108c | 6117 | { |
c4093a6a JM |
6118 | struct ep_type_description |
6119 | { | |
6120 | enum bptype type; | |
6121 | char *description; | |
6122 | }; | |
6123 | static struct ep_type_description bptypes[] = | |
c906108c | 6124 | { |
c5aa993b JM |
6125 | {bp_none, "?deleted?"}, |
6126 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6127 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6128 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6129 | {bp_until, "until"}, |
6130 | {bp_finish, "finish"}, | |
6131 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6132 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6133 | {bp_read_watchpoint, "read watchpoint"}, |
6134 | {bp_access_watchpoint, "acc watchpoint"}, | |
6135 | {bp_longjmp, "longjmp"}, | |
6136 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6137 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6138 | {bp_exception, "exception"}, |
6139 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6140 | {bp_step_resume, "step resume"}, |
2c03e5be | 6141 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6142 | {bp_watchpoint_scope, "watchpoint scope"}, |
6143 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6144 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6145 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6146 | {bp_thread_event, "thread events"}, |
1900040c | 6147 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6148 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6149 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6150 | {bp_exception_master, "exception master"}, |
ce78b96d | 6151 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6152 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6153 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6154 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6155 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6156 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6157 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6158 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6159 | }; |
269b11a2 PA |
6160 | |
6161 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6162 | || ((int) type != bptypes[(int) type].type)) | |
6163 | internal_error (__FILE__, __LINE__, | |
6164 | _("bptypes table does not describe type #%d."), | |
6165 | (int) type); | |
6166 | ||
6167 | return bptypes[(int) type].description; | |
6168 | } | |
6169 | ||
998580f1 MK |
6170 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6171 | For CLI, prefix the list with the string 'inf'. */ | |
6172 | ||
6173 | static void | |
6174 | output_thread_groups (struct ui_out *uiout, | |
6175 | const char *field_name, | |
6176 | VEC(int) *inf_num, | |
6177 | int mi_only) | |
6178 | { | |
752eb8b4 | 6179 | struct cleanup *back_to; |
998580f1 MK |
6180 | int is_mi = ui_out_is_mi_like_p (uiout); |
6181 | int inf; | |
6182 | int i; | |
6183 | ||
6184 | /* For backward compatibility, don't display inferiors in CLI unless | |
6185 | there are several. Always display them for MI. */ | |
6186 | if (!is_mi && mi_only) | |
6187 | return; | |
6188 | ||
752eb8b4 TT |
6189 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6190 | ||
998580f1 MK |
6191 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6192 | { | |
6193 | if (is_mi) | |
6194 | { | |
6195 | char mi_group[10]; | |
6196 | ||
6197 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6198 | ui_out_field_string (uiout, NULL, mi_group); | |
6199 | } | |
6200 | else | |
6201 | { | |
6202 | if (i == 0) | |
6203 | ui_out_text (uiout, " inf "); | |
6204 | else | |
6205 | ui_out_text (uiout, ", "); | |
6206 | ||
6207 | ui_out_text (uiout, plongest (inf)); | |
6208 | } | |
6209 | } | |
6210 | ||
6211 | do_cleanups (back_to); | |
6212 | } | |
6213 | ||
269b11a2 PA |
6214 | /* Print B to gdb_stdout. */ |
6215 | ||
6216 | static void | |
6217 | print_one_breakpoint_location (struct breakpoint *b, | |
6218 | struct bp_location *loc, | |
6219 | int loc_number, | |
6220 | struct bp_location **last_loc, | |
269b11a2 PA |
6221 | int allflag) |
6222 | { | |
6223 | struct command_line *l; | |
c2c6d25f | 6224 | static char bpenables[] = "nynny"; |
c906108c | 6225 | |
79a45e25 | 6226 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6227 | int header_of_multiple = 0; |
6228 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6229 | struct value_print_options opts; |
6230 | ||
6231 | get_user_print_options (&opts); | |
0d381245 VP |
6232 | |
6233 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6234 | /* See comment in print_one_breakpoint concerning treatment of |
6235 | breakpoints with single disabled location. */ | |
0d381245 VP |
6236 | if (loc == NULL |
6237 | && (b->loc != NULL | |
6238 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6239 | header_of_multiple = 1; | |
6240 | if (loc == NULL) | |
6241 | loc = b->loc; | |
6242 | ||
c4093a6a JM |
6243 | annotate_record (); |
6244 | ||
6245 | /* 1 */ | |
6246 | annotate_field (0); | |
0d381245 VP |
6247 | if (part_of_multiple) |
6248 | { | |
6249 | char *formatted; | |
0c6773c1 | 6250 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6251 | ui_out_field_string (uiout, "number", formatted); |
6252 | xfree (formatted); | |
6253 | } | |
6254 | else | |
6255 | { | |
6256 | ui_out_field_int (uiout, "number", b->number); | |
6257 | } | |
c4093a6a JM |
6258 | |
6259 | /* 2 */ | |
6260 | annotate_field (1); | |
0d381245 VP |
6261 | if (part_of_multiple) |
6262 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6263 | else |
6264 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6265 | |
6266 | /* 3 */ | |
6267 | annotate_field (2); | |
0d381245 VP |
6268 | if (part_of_multiple) |
6269 | ui_out_field_skip (uiout, "disp"); | |
6270 | else | |
2cec12e5 | 6271 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6272 | |
c4093a6a JM |
6273 | |
6274 | /* 4 */ | |
6275 | annotate_field (3); | |
0d381245 | 6276 | if (part_of_multiple) |
54e52265 | 6277 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6278 | else |
4a64f543 MS |
6279 | ui_out_field_fmt (uiout, "enabled", "%c", |
6280 | bpenables[(int) b->enable_state]); | |
54e52265 | 6281 | ui_out_spaces (uiout, 2); |
0d381245 | 6282 | |
c4093a6a JM |
6283 | |
6284 | /* 5 and 6 */ | |
3086aeae | 6285 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6286 | { |
4a64f543 MS |
6287 | /* Although the print_one can possibly print all locations, |
6288 | calling it here is not likely to get any nice result. So, | |
6289 | make sure there's just one location. */ | |
0d381245 | 6290 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6291 | b->ops->print_one (b, last_loc); |
0d381245 | 6292 | } |
3086aeae DJ |
6293 | else |
6294 | switch (b->type) | |
6295 | { | |
6296 | case bp_none: | |
6297 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6298 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6299 | break; |
c906108c | 6300 | |
3086aeae DJ |
6301 | case bp_watchpoint: |
6302 | case bp_hardware_watchpoint: | |
6303 | case bp_read_watchpoint: | |
6304 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6305 | { |
6306 | struct watchpoint *w = (struct watchpoint *) b; | |
6307 | ||
6308 | /* Field 4, the address, is omitted (which makes the columns | |
6309 | not line up too nicely with the headers, but the effect | |
6310 | is relatively readable). */ | |
6311 | if (opts.addressprint) | |
6312 | ui_out_field_skip (uiout, "addr"); | |
6313 | annotate_field (5); | |
6314 | ui_out_field_string (uiout, "what", w->exp_string); | |
6315 | } | |
3086aeae DJ |
6316 | break; |
6317 | ||
3086aeae DJ |
6318 | case bp_breakpoint: |
6319 | case bp_hardware_breakpoint: | |
7c16b83e | 6320 | case bp_single_step: |
3086aeae DJ |
6321 | case bp_until: |
6322 | case bp_finish: | |
6323 | case bp_longjmp: | |
6324 | case bp_longjmp_resume: | |
e2e4d78b | 6325 | case bp_longjmp_call_dummy: |
186c406b TT |
6326 | case bp_exception: |
6327 | case bp_exception_resume: | |
3086aeae | 6328 | case bp_step_resume: |
2c03e5be | 6329 | case bp_hp_step_resume: |
3086aeae DJ |
6330 | case bp_watchpoint_scope: |
6331 | case bp_call_dummy: | |
aa7d318d | 6332 | case bp_std_terminate: |
3086aeae DJ |
6333 | case bp_shlib_event: |
6334 | case bp_thread_event: | |
6335 | case bp_overlay_event: | |
0fd8e87f | 6336 | case bp_longjmp_master: |
aa7d318d | 6337 | case bp_std_terminate_master: |
186c406b | 6338 | case bp_exception_master: |
1042e4c0 | 6339 | case bp_tracepoint: |
7a697b8d | 6340 | case bp_fast_tracepoint: |
0fb4aa4b | 6341 | case bp_static_tracepoint: |
e7e0cddf | 6342 | case bp_dprintf: |
4efc6507 | 6343 | case bp_jit_event: |
0e30163f JK |
6344 | case bp_gnu_ifunc_resolver: |
6345 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6346 | if (opts.addressprint) |
3086aeae DJ |
6347 | { |
6348 | annotate_field (4); | |
54e52265 | 6349 | if (header_of_multiple) |
0d381245 | 6350 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6351 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6352 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6353 | else |
5af949e3 UW |
6354 | ui_out_field_core_addr (uiout, "addr", |
6355 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6356 | } |
6357 | annotate_field (5); | |
0d381245 | 6358 | if (!header_of_multiple) |
170b53b2 | 6359 | print_breakpoint_location (b, loc); |
0d381245 | 6360 | if (b->loc) |
a6d9a66e | 6361 | *last_loc = b->loc; |
3086aeae DJ |
6362 | break; |
6363 | } | |
c906108c | 6364 | |
6c95b8df | 6365 | |
998580f1 | 6366 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6367 | { |
6368 | struct inferior *inf; | |
998580f1 MK |
6369 | VEC(int) *inf_num = NULL; |
6370 | int mi_only = 1; | |
6c95b8df | 6371 | |
998580f1 | 6372 | ALL_INFERIORS (inf) |
6c95b8df PA |
6373 | { |
6374 | if (inf->pspace == loc->pspace) | |
998580f1 | 6375 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6376 | } |
998580f1 MK |
6377 | |
6378 | /* For backward compatibility, don't display inferiors in CLI unless | |
6379 | there are several. Always display for MI. */ | |
6380 | if (allflag | |
6381 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6382 | && (number_of_program_spaces () > 1 | |
6383 | || number_of_inferiors () > 1) | |
6384 | /* LOC is for existing B, it cannot be in | |
6385 | moribund_locations and thus having NULL OWNER. */ | |
6386 | && loc->owner->type != bp_catchpoint)) | |
6387 | mi_only = 0; | |
6388 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6389 | VEC_free (int, inf_num); | |
6c95b8df PA |
6390 | } |
6391 | ||
4a306c9a | 6392 | if (!part_of_multiple) |
c4093a6a | 6393 | { |
4a306c9a JB |
6394 | if (b->thread != -1) |
6395 | { | |
6396 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6397 | "stop only in" line a little further down. */ |
4a306c9a JB |
6398 | ui_out_text (uiout, " thread "); |
6399 | ui_out_field_int (uiout, "thread", b->thread); | |
6400 | } | |
6401 | else if (b->task != 0) | |
6402 | { | |
6403 | ui_out_text (uiout, " task "); | |
6404 | ui_out_field_int (uiout, "task", b->task); | |
6405 | } | |
c4093a6a | 6406 | } |
f1310107 | 6407 | |
8b93c638 | 6408 | ui_out_text (uiout, "\n"); |
f1310107 | 6409 | |
348d480f | 6410 | if (!part_of_multiple) |
f1310107 TJB |
6411 | b->ops->print_one_detail (b, uiout); |
6412 | ||
0d381245 | 6413 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6414 | { |
6415 | annotate_field (6); | |
8b93c638 | 6416 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6417 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6418 | the frame ID. */ |
5af949e3 UW |
6419 | ui_out_field_core_addr (uiout, "frame", |
6420 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6421 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6422 | } |
6423 | ||
28010a5d | 6424 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6425 | { |
6426 | annotate_field (7); | |
d77f58be | 6427 | if (is_tracepoint (b)) |
1042e4c0 SS |
6428 | ui_out_text (uiout, "\ttrace only if "); |
6429 | else | |
6430 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6431 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6432 | |
6433 | /* Print whether the target is doing the breakpoint's condition | |
6434 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6435 | if (is_breakpoint (b) | |
6436 | && breakpoint_condition_evaluation_mode () | |
6437 | == condition_evaluation_target) | |
6438 | { | |
6439 | ui_out_text (uiout, " ("); | |
6440 | ui_out_field_string (uiout, "evaluated-by", | |
6441 | bp_condition_evaluator (b)); | |
6442 | ui_out_text (uiout, " evals)"); | |
6443 | } | |
0101ce28 JJ |
6444 | ui_out_text (uiout, "\n"); |
6445 | } | |
6446 | ||
0d381245 | 6447 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6448 | { |
4a64f543 | 6449 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6450 | ui_out_text (uiout, "\tstop only in thread "); |
6451 | ui_out_field_int (uiout, "thread", b->thread); | |
6452 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6453 | } |
6454 | ||
556ec64d YQ |
6455 | if (!part_of_multiple) |
6456 | { | |
6457 | if (b->hit_count) | |
31f56a27 YQ |
6458 | { |
6459 | /* FIXME should make an annotation for this. */ | |
6460 | if (is_catchpoint (b)) | |
6461 | ui_out_text (uiout, "\tcatchpoint"); | |
6462 | else if (is_tracepoint (b)) | |
6463 | ui_out_text (uiout, "\ttracepoint"); | |
6464 | else | |
6465 | ui_out_text (uiout, "\tbreakpoint"); | |
6466 | ui_out_text (uiout, " already hit "); | |
6467 | ui_out_field_int (uiout, "times", b->hit_count); | |
6468 | if (b->hit_count == 1) | |
6469 | ui_out_text (uiout, " time\n"); | |
6470 | else | |
6471 | ui_out_text (uiout, " times\n"); | |
6472 | } | |
556ec64d YQ |
6473 | else |
6474 | { | |
31f56a27 YQ |
6475 | /* Output the count also if it is zero, but only if this is mi. */ |
6476 | if (ui_out_is_mi_like_p (uiout)) | |
6477 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6478 | } |
6479 | } | |
8b93c638 | 6480 | |
0d381245 | 6481 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6482 | { |
6483 | annotate_field (8); | |
8b93c638 JM |
6484 | ui_out_text (uiout, "\tignore next "); |
6485 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6486 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6487 | } |
059fb39f | 6488 | |
816338b5 SS |
6489 | /* Note that an enable count of 1 corresponds to "enable once" |
6490 | behavior, which is reported by the combination of enablement and | |
6491 | disposition, so we don't need to mention it here. */ | |
6492 | if (!part_of_multiple && b->enable_count > 1) | |
6493 | { | |
6494 | annotate_field (8); | |
6495 | ui_out_text (uiout, "\tdisable after "); | |
6496 | /* Tweak the wording to clarify that ignore and enable counts | |
6497 | are distinct, and have additive effect. */ | |
6498 | if (b->ignore_count) | |
6499 | ui_out_text (uiout, "additional "); | |
6500 | else | |
6501 | ui_out_text (uiout, "next "); | |
6502 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6503 | ui_out_text (uiout, " hits\n"); | |
6504 | } | |
6505 | ||
f196051f SS |
6506 | if (!part_of_multiple && is_tracepoint (b)) |
6507 | { | |
6508 | struct tracepoint *tp = (struct tracepoint *) b; | |
6509 | ||
6510 | if (tp->traceframe_usage) | |
6511 | { | |
6512 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6513 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6514 | ui_out_text (uiout, " bytes\n"); | |
6515 | } | |
6516 | } | |
d3ce09f5 | 6517 | |
9add0f1b | 6518 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6519 | if (!part_of_multiple && l) |
c4093a6a | 6520 | { |
3b31d625 EZ |
6521 | struct cleanup *script_chain; |
6522 | ||
c4093a6a | 6523 | annotate_field (9); |
3b31d625 | 6524 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6525 | print_command_lines (uiout, l, 4); |
3b31d625 | 6526 | do_cleanups (script_chain); |
c4093a6a | 6527 | } |
d24317b4 | 6528 | |
d9b3f62e | 6529 | if (is_tracepoint (b)) |
1042e4c0 | 6530 | { |
d9b3f62e PA |
6531 | struct tracepoint *t = (struct tracepoint *) b; |
6532 | ||
6533 | if (!part_of_multiple && t->pass_count) | |
6534 | { | |
6535 | annotate_field (10); | |
6536 | ui_out_text (uiout, "\tpass count "); | |
6537 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6538 | ui_out_text (uiout, " \n"); | |
6539 | } | |
f2a8bc8a YQ |
6540 | |
6541 | /* Don't display it when tracepoint or tracepoint location is | |
6542 | pending. */ | |
6543 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6544 | { | |
6545 | annotate_field (11); | |
6546 | ||
6547 | if (ui_out_is_mi_like_p (uiout)) | |
6548 | ui_out_field_string (uiout, "installed", | |
6549 | loc->inserted ? "y" : "n"); | |
6550 | else | |
6551 | { | |
6552 | if (loc->inserted) | |
6553 | ui_out_text (uiout, "\t"); | |
6554 | else | |
6555 | ui_out_text (uiout, "\tnot "); | |
6556 | ui_out_text (uiout, "installed on target\n"); | |
6557 | } | |
6558 | } | |
1042e4c0 SS |
6559 | } |
6560 | ||
d24317b4 VP |
6561 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6562 | { | |
3a5c3e22 PA |
6563 | if (is_watchpoint (b)) |
6564 | { | |
6565 | struct watchpoint *w = (struct watchpoint *) b; | |
6566 | ||
6567 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6568 | } | |
f00aae0f KS |
6569 | else if (b->location != NULL |
6570 | && event_location_to_string (b->location) != NULL) | |
6571 | ui_out_field_string (uiout, "original-location", | |
6572 | event_location_to_string (b->location)); | |
d24317b4 | 6573 | } |
c4093a6a | 6574 | } |
c5aa993b | 6575 | |
0d381245 VP |
6576 | static void |
6577 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6578 | struct bp_location **last_loc, |
6c95b8df | 6579 | int allflag) |
0d381245 | 6580 | { |
8d3788bd | 6581 | struct cleanup *bkpt_chain; |
79a45e25 | 6582 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6583 | |
6584 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6585 | ||
12c5a436 | 6586 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6587 | do_cleanups (bkpt_chain); |
0d381245 VP |
6588 | |
6589 | /* If this breakpoint has custom print function, | |
6590 | it's already printed. Otherwise, print individual | |
6591 | locations, if any. */ | |
6592 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6593 | { | |
4a64f543 MS |
6594 | /* If breakpoint has a single location that is disabled, we |
6595 | print it as if it had several locations, since otherwise it's | |
6596 | hard to represent "breakpoint enabled, location disabled" | |
6597 | situation. | |
6598 | ||
6599 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6600 | internally, that's not a property exposed to user. */ |
0d381245 | 6601 | if (b->loc |
a5606eee | 6602 | && !is_hardware_watchpoint (b) |
8d3788bd | 6603 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6604 | { |
6605 | struct bp_location *loc; | |
6606 | int n = 1; | |
8d3788bd | 6607 | |
0d381245 | 6608 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6609 | { |
6610 | struct cleanup *inner2 = | |
6611 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6612 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6613 | do_cleanups (inner2); | |
6614 | } | |
0d381245 VP |
6615 | } |
6616 | } | |
6617 | } | |
6618 | ||
a6d9a66e UW |
6619 | static int |
6620 | breakpoint_address_bits (struct breakpoint *b) | |
6621 | { | |
6622 | int print_address_bits = 0; | |
6623 | struct bp_location *loc; | |
6624 | ||
6625 | for (loc = b->loc; loc; loc = loc->next) | |
6626 | { | |
c7437ca6 PA |
6627 | int addr_bit; |
6628 | ||
6629 | /* Software watchpoints that aren't watching memory don't have | |
6630 | an address to print. */ | |
6631 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
6632 | continue; | |
6633 | ||
6634 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
6635 | if (addr_bit > print_address_bits) |
6636 | print_address_bits = addr_bit; | |
6637 | } | |
6638 | ||
6639 | return print_address_bits; | |
6640 | } | |
0d381245 | 6641 | |
c4093a6a JM |
6642 | struct captured_breakpoint_query_args |
6643 | { | |
6644 | int bnum; | |
6645 | }; | |
c5aa993b | 6646 | |
c4093a6a | 6647 | static int |
2b65245e | 6648 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
6649 | { |
6650 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 6651 | struct breakpoint *b; |
a6d9a66e | 6652 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6653 | |
c4093a6a JM |
6654 | ALL_BREAKPOINTS (b) |
6655 | { | |
6656 | if (args->bnum == b->number) | |
c5aa993b | 6657 | { |
12c5a436 | 6658 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6659 | return GDB_RC_OK; |
c5aa993b | 6660 | } |
c4093a6a JM |
6661 | } |
6662 | return GDB_RC_NONE; | |
6663 | } | |
c5aa993b | 6664 | |
c4093a6a | 6665 | enum gdb_rc |
4a64f543 MS |
6666 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6667 | char **error_message) | |
c4093a6a JM |
6668 | { |
6669 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6670 | |
c4093a6a JM |
6671 | args.bnum = bnum; |
6672 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6673 | an error. */ |
b0b13bb4 DJ |
6674 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6675 | error_message, RETURN_MASK_ALL) < 0) | |
6676 | return GDB_RC_FAIL; | |
6677 | else | |
6678 | return GDB_RC_OK; | |
c4093a6a | 6679 | } |
c5aa993b | 6680 | |
09d682a4 TT |
6681 | /* Return true if this breakpoint was set by the user, false if it is |
6682 | internal or momentary. */ | |
6683 | ||
6684 | int | |
6685 | user_breakpoint_p (struct breakpoint *b) | |
6686 | { | |
46c6471b | 6687 | return b->number > 0; |
09d682a4 TT |
6688 | } |
6689 | ||
7f3b0473 | 6690 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6691 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6692 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6693 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6694 | ones for which it returns non-zero. Return the total number of | |
6695 | breakpoints listed. */ | |
c906108c | 6696 | |
d77f58be | 6697 | static int |
e5a67952 | 6698 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6699 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6700 | { |
52f0bd74 | 6701 | struct breakpoint *b; |
a6d9a66e | 6702 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6703 | int nr_printable_breakpoints; |
3b31d625 | 6704 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6705 | struct value_print_options opts; |
a6d9a66e | 6706 | int print_address_bits = 0; |
269b11a2 | 6707 | int print_type_col_width = 14; |
79a45e25 | 6708 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6709 | |
79a45b7d TT |
6710 | get_user_print_options (&opts); |
6711 | ||
4a64f543 MS |
6712 | /* Compute the number of rows in the table, as well as the size |
6713 | required for address fields. */ | |
7f3b0473 AC |
6714 | nr_printable_breakpoints = 0; |
6715 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6716 | { |
6717 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6718 | if (filter && !filter (b)) | |
6719 | continue; | |
6720 | ||
6721 | /* If we have an "args" string, it is a list of breakpoints to | |
6722 | accept. Skip the others. */ | |
6723 | if (args != NULL && *args != '\0') | |
6724 | { | |
6725 | if (allflag && parse_and_eval_long (args) != b->number) | |
6726 | continue; | |
6727 | if (!allflag && !number_is_in_list (args, b->number)) | |
6728 | continue; | |
6729 | } | |
269b11a2 | 6730 | |
e5a67952 MS |
6731 | if (allflag || user_breakpoint_p (b)) |
6732 | { | |
6733 | int addr_bit, type_len; | |
a6d9a66e | 6734 | |
e5a67952 MS |
6735 | addr_bit = breakpoint_address_bits (b); |
6736 | if (addr_bit > print_address_bits) | |
6737 | print_address_bits = addr_bit; | |
269b11a2 | 6738 | |
e5a67952 MS |
6739 | type_len = strlen (bptype_string (b->type)); |
6740 | if (type_len > print_type_col_width) | |
6741 | print_type_col_width = type_len; | |
6742 | ||
6743 | nr_printable_breakpoints++; | |
6744 | } | |
6745 | } | |
7f3b0473 | 6746 | |
79a45b7d | 6747 | if (opts.addressprint) |
3b31d625 | 6748 | bkpttbl_chain |
3e43a32a MS |
6749 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6750 | nr_printable_breakpoints, | |
3b31d625 | 6751 | "BreakpointTable"); |
8b93c638 | 6752 | else |
3b31d625 | 6753 | bkpttbl_chain |
3e43a32a MS |
6754 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6755 | nr_printable_breakpoints, | |
3b31d625 | 6756 | "BreakpointTable"); |
8b93c638 | 6757 | |
7f3b0473 | 6758 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6759 | annotate_breakpoints_headers (); |
6760 | if (nr_printable_breakpoints > 0) | |
6761 | annotate_field (0); | |
4a64f543 | 6762 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6763 | if (nr_printable_breakpoints > 0) |
6764 | annotate_field (1); | |
269b11a2 | 6765 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6766 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6767 | if (nr_printable_breakpoints > 0) |
6768 | annotate_field (2); | |
4a64f543 | 6769 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6770 | if (nr_printable_breakpoints > 0) |
6771 | annotate_field (3); | |
54e52265 | 6772 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6773 | if (opts.addressprint) |
e5a67952 MS |
6774 | { |
6775 | if (nr_printable_breakpoints > 0) | |
6776 | annotate_field (4); | |
6777 | if (print_address_bits <= 32) | |
6778 | ui_out_table_header (uiout, 10, ui_left, | |
6779 | "addr", "Address"); /* 5 */ | |
6780 | else | |
6781 | ui_out_table_header (uiout, 18, ui_left, | |
6782 | "addr", "Address"); /* 5 */ | |
6783 | } | |
d7faa9e7 AC |
6784 | if (nr_printable_breakpoints > 0) |
6785 | annotate_field (5); | |
6786 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6787 | ui_out_table_body (uiout); | |
6788 | if (nr_printable_breakpoints > 0) | |
6789 | annotate_breakpoints_table (); | |
7f3b0473 | 6790 | |
c4093a6a | 6791 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6792 | { |
6793 | QUIT; | |
6794 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6795 | if (filter && !filter (b)) | |
6796 | continue; | |
6797 | ||
6798 | /* If we have an "args" string, it is a list of breakpoints to | |
6799 | accept. Skip the others. */ | |
6800 | ||
6801 | if (args != NULL && *args != '\0') | |
6802 | { | |
6803 | if (allflag) /* maintenance info breakpoint */ | |
6804 | { | |
6805 | if (parse_and_eval_long (args) != b->number) | |
6806 | continue; | |
6807 | } | |
6808 | else /* all others */ | |
6809 | { | |
6810 | if (!number_is_in_list (args, b->number)) | |
6811 | continue; | |
6812 | } | |
6813 | } | |
6814 | /* We only print out user settable breakpoints unless the | |
6815 | allflag is set. */ | |
6816 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6817 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6818 | } |
6819 | ||
3b31d625 | 6820 | do_cleanups (bkpttbl_chain); |
698384cd | 6821 | |
7f3b0473 | 6822 | if (nr_printable_breakpoints == 0) |
c906108c | 6823 | { |
4a64f543 MS |
6824 | /* If there's a filter, let the caller decide how to report |
6825 | empty list. */ | |
d77f58be SS |
6826 | if (!filter) |
6827 | { | |
e5a67952 | 6828 | if (args == NULL || *args == '\0') |
d77f58be SS |
6829 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6830 | else | |
4a64f543 | 6831 | ui_out_message (uiout, 0, |
e5a67952 MS |
6832 | "No breakpoint or watchpoint matching '%s'.\n", |
6833 | args); | |
d77f58be | 6834 | } |
c906108c SS |
6835 | } |
6836 | else | |
c4093a6a | 6837 | { |
a6d9a66e UW |
6838 | if (last_loc && !server_command) |
6839 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6840 | } |
c906108c | 6841 | |
4a64f543 | 6842 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6843 | there have been breakpoints? */ |
c906108c | 6844 | annotate_breakpoints_table_end (); |
d77f58be SS |
6845 | |
6846 | return nr_printable_breakpoints; | |
c906108c SS |
6847 | } |
6848 | ||
ad443146 SS |
6849 | /* Display the value of default-collect in a way that is generally |
6850 | compatible with the breakpoint list. */ | |
6851 | ||
6852 | static void | |
6853 | default_collect_info (void) | |
6854 | { | |
79a45e25 PA |
6855 | struct ui_out *uiout = current_uiout; |
6856 | ||
ad443146 SS |
6857 | /* If it has no value (which is frequently the case), say nothing; a |
6858 | message like "No default-collect." gets in user's face when it's | |
6859 | not wanted. */ | |
6860 | if (!*default_collect) | |
6861 | return; | |
6862 | ||
6863 | /* The following phrase lines up nicely with per-tracepoint collect | |
6864 | actions. */ | |
6865 | ui_out_text (uiout, "default collect "); | |
6866 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6867 | ui_out_text (uiout, " \n"); | |
6868 | } | |
6869 | ||
c906108c | 6870 | static void |
e5a67952 | 6871 | breakpoints_info (char *args, int from_tty) |
c906108c | 6872 | { |
e5a67952 | 6873 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6874 | |
6875 | default_collect_info (); | |
d77f58be SS |
6876 | } |
6877 | ||
6878 | static void | |
e5a67952 | 6879 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6880 | { |
e5a67952 | 6881 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6882 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6883 | |
6884 | if (num_printed == 0) | |
6885 | { | |
e5a67952 | 6886 | if (args == NULL || *args == '\0') |
d77f58be SS |
6887 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6888 | else | |
e5a67952 | 6889 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6890 | } |
c906108c SS |
6891 | } |
6892 | ||
7a292a7a | 6893 | static void |
e5a67952 | 6894 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6895 | { |
e5a67952 | 6896 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6897 | |
6898 | default_collect_info (); | |
c906108c SS |
6899 | } |
6900 | ||
0d381245 | 6901 | static int |
714835d5 | 6902 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6903 | struct program_space *pspace, |
714835d5 | 6904 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6905 | { |
6906 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6907 | |
0d381245 VP |
6908 | for (; bl; bl = bl->next) |
6909 | { | |
6c95b8df PA |
6910 | if (bl->pspace == pspace |
6911 | && bl->address == pc | |
0d381245 VP |
6912 | && (!overlay_debugging || bl->section == section)) |
6913 | return 1; | |
6914 | } | |
6915 | return 0; | |
6916 | } | |
6917 | ||
672f9b60 | 6918 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6919 | concerns with logical breakpoints, so we match program spaces, not |
6920 | address spaces. */ | |
c906108c SS |
6921 | |
6922 | static void | |
6c95b8df PA |
6923 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6924 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6925 | struct obj_section *section, int thread) |
c906108c | 6926 | { |
52f0bd74 AC |
6927 | int others = 0; |
6928 | struct breakpoint *b; | |
c906108c SS |
6929 | |
6930 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6931 | others += (user_breakpoint_p (b) |
6932 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6933 | if (others > 0) |
6934 | { | |
a3f17187 AC |
6935 | if (others == 1) |
6936 | printf_filtered (_("Note: breakpoint ")); | |
6937 | else /* if (others == ???) */ | |
6938 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6939 | ALL_BREAKPOINTS (b) |
672f9b60 | 6940 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6941 | { |
6942 | others--; | |
6943 | printf_filtered ("%d", b->number); | |
6944 | if (b->thread == -1 && thread != -1) | |
6945 | printf_filtered (" (all threads)"); | |
6946 | else if (b->thread != -1) | |
6947 | printf_filtered (" (thread %d)", b->thread); | |
6948 | printf_filtered ("%s%s ", | |
059fb39f | 6949 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6950 | || b->enable_state == bp_call_disabled) |
0d381245 | 6951 | ? " (disabled)" |
0d381245 VP |
6952 | : ""), |
6953 | (others > 1) ? "," | |
6954 | : ((others == 1) ? " and" : "")); | |
6955 | } | |
a3f17187 | 6956 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6957 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6958 | printf_filtered (".\n"); |
6959 | } | |
6960 | } | |
6961 | \f | |
c906108c | 6962 | |
e4f237da KB |
6963 | /* Return true iff it is meaningful to use the address member of |
6964 | BPT. For some breakpoint types, the address member is irrelevant | |
6965 | and it makes no sense to attempt to compare it to other addresses | |
6966 | (or use it for any other purpose either). | |
6967 | ||
4a64f543 MS |
6968 | More specifically, each of the following breakpoint types will |
6969 | always have a zero valued address and we don't want to mark | |
6970 | breakpoints of any of these types to be a duplicate of an actual | |
6971 | breakpoint at address zero: | |
e4f237da KB |
6972 | |
6973 | bp_watchpoint | |
2d134ed3 PA |
6974 | bp_catchpoint |
6975 | ||
6976 | */ | |
e4f237da KB |
6977 | |
6978 | static int | |
6979 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6980 | { | |
6981 | enum bptype type = bpt->type; | |
6982 | ||
2d134ed3 PA |
6983 | return (type != bp_watchpoint && type != bp_catchpoint); |
6984 | } | |
6985 | ||
6986 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6987 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6988 | ||
6989 | static int | |
4a64f543 MS |
6990 | watchpoint_locations_match (struct bp_location *loc1, |
6991 | struct bp_location *loc2) | |
2d134ed3 | 6992 | { |
3a5c3e22 PA |
6993 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6994 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6995 | ||
6996 | /* Both of them must exist. */ | |
6997 | gdb_assert (w1 != NULL); | |
6998 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6999 | |
4a64f543 MS |
7000 | /* If the target can evaluate the condition expression in hardware, |
7001 | then we we need to insert both watchpoints even if they are at | |
7002 | the same place. Otherwise the watchpoint will only trigger when | |
7003 | the condition of whichever watchpoint was inserted evaluates to | |
7004 | true, not giving a chance for GDB to check the condition of the | |
7005 | other watchpoint. */ | |
3a5c3e22 | 7006 | if ((w1->cond_exp |
4a64f543 MS |
7007 | && target_can_accel_watchpoint_condition (loc1->address, |
7008 | loc1->length, | |
0cf6dd15 | 7009 | loc1->watchpoint_type, |
3a5c3e22 PA |
7010 | w1->cond_exp)) |
7011 | || (w2->cond_exp | |
4a64f543 MS |
7012 | && target_can_accel_watchpoint_condition (loc2->address, |
7013 | loc2->length, | |
0cf6dd15 | 7014 | loc2->watchpoint_type, |
3a5c3e22 | 7015 | w2->cond_exp))) |
0cf6dd15 TJB |
7016 | return 0; |
7017 | ||
85d721b8 PA |
7018 | /* Note that this checks the owner's type, not the location's. In |
7019 | case the target does not support read watchpoints, but does | |
7020 | support access watchpoints, we'll have bp_read_watchpoint | |
7021 | watchpoints with hw_access locations. Those should be considered | |
7022 | duplicates of hw_read locations. The hw_read locations will | |
7023 | become hw_access locations later. */ | |
2d134ed3 PA |
7024 | return (loc1->owner->type == loc2->owner->type |
7025 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7026 | && loc1->address == loc2->address | |
7027 | && loc1->length == loc2->length); | |
e4f237da KB |
7028 | } |
7029 | ||
31e77af2 | 7030 | /* See breakpoint.h. */ |
6c95b8df | 7031 | |
31e77af2 | 7032 | int |
6c95b8df PA |
7033 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7034 | struct address_space *aspace2, CORE_ADDR addr2) | |
7035 | { | |
f5656ead | 7036 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7037 | || aspace1 == aspace2) |
7038 | && addr1 == addr2); | |
7039 | } | |
7040 | ||
f1310107 TJB |
7041 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7042 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7043 | matches ASPACE2. On targets that have global breakpoints, the address | |
7044 | space doesn't really matter. */ | |
7045 | ||
7046 | static int | |
7047 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7048 | int len1, struct address_space *aspace2, | |
7049 | CORE_ADDR addr2) | |
7050 | { | |
f5656ead | 7051 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7052 | || aspace1 == aspace2) |
7053 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7054 | } | |
7055 | ||
7056 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7057 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7058 | matches the breakpoint's address space. On targets that have global | |
7059 | breakpoints, the address space doesn't really matter. */ | |
7060 | ||
7061 | static int | |
7062 | breakpoint_location_address_match (struct bp_location *bl, | |
7063 | struct address_space *aspace, | |
7064 | CORE_ADDR addr) | |
7065 | { | |
7066 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7067 | aspace, addr) | |
7068 | || (bl->length | |
7069 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7070 | bl->address, bl->length, | |
7071 | aspace, addr))); | |
7072 | } | |
7073 | ||
1e4d1764 YQ |
7074 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7075 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7076 | true, otherwise returns false. */ | |
7077 | ||
7078 | static int | |
7079 | tracepoint_locations_match (struct bp_location *loc1, | |
7080 | struct bp_location *loc2) | |
7081 | { | |
7082 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7083 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7084 | locations at the same address of different tracepoints are regarded as | |
7085 | different locations. */ | |
7086 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7087 | else | |
7088 | return 0; | |
7089 | } | |
7090 | ||
2d134ed3 PA |
7091 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7092 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7093 | represent the same location. */ | |
7094 | ||
7095 | static int | |
4a64f543 MS |
7096 | breakpoint_locations_match (struct bp_location *loc1, |
7097 | struct bp_location *loc2) | |
2d134ed3 | 7098 | { |
2bdf28a0 JK |
7099 | int hw_point1, hw_point2; |
7100 | ||
7101 | /* Both of them must not be in moribund_locations. */ | |
7102 | gdb_assert (loc1->owner != NULL); | |
7103 | gdb_assert (loc2->owner != NULL); | |
7104 | ||
7105 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7106 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7107 | |
7108 | if (hw_point1 != hw_point2) | |
7109 | return 0; | |
7110 | else if (hw_point1) | |
7111 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7112 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7113 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7114 | else |
f1310107 TJB |
7115 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7116 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7117 | loc2->pspace->aspace, loc2->address) | |
7118 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7119 | } |
7120 | ||
76897487 KB |
7121 | static void |
7122 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7123 | int bnum, int have_bnum) | |
7124 | { | |
f63fbe86 MS |
7125 | /* The longest string possibly returned by hex_string_custom |
7126 | is 50 chars. These must be at least that big for safety. */ | |
7127 | char astr1[64]; | |
7128 | char astr2[64]; | |
76897487 | 7129 | |
bb599908 PH |
7130 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7131 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7132 | if (have_bnum) |
8a3fe4f8 | 7133 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7134 | bnum, astr1, astr2); |
7135 | else | |
8a3fe4f8 | 7136 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7137 | } |
7138 | ||
4a64f543 MS |
7139 | /* Adjust a breakpoint's address to account for architectural |
7140 | constraints on breakpoint placement. Return the adjusted address. | |
7141 | Note: Very few targets require this kind of adjustment. For most | |
7142 | targets, this function is simply the identity function. */ | |
76897487 KB |
7143 | |
7144 | static CORE_ADDR | |
a6d9a66e UW |
7145 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7146 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7147 | { |
a6d9a66e | 7148 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7149 | { |
7150 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7151 | return bpaddr; | |
7152 | } | |
88f7da05 KB |
7153 | else if (bptype == bp_watchpoint |
7154 | || bptype == bp_hardware_watchpoint | |
7155 | || bptype == bp_read_watchpoint | |
7156 | || bptype == bp_access_watchpoint | |
fe798b75 | 7157 | || bptype == bp_catchpoint) |
88f7da05 KB |
7158 | { |
7159 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7160 | have their addresses modified. */ | |
7161 | return bpaddr; | |
7162 | } | |
7c16b83e PA |
7163 | else if (bptype == bp_single_step) |
7164 | { | |
7165 | /* Single-step breakpoints should not have their addresses | |
7166 | modified. If there's any architectural constrain that | |
7167 | applies to this address, then it should have already been | |
7168 | taken into account when the breakpoint was created in the | |
7169 | first place. If we didn't do this, stepping through e.g., | |
7170 | Thumb-2 IT blocks would break. */ | |
7171 | return bpaddr; | |
7172 | } | |
76897487 KB |
7173 | else |
7174 | { | |
7175 | CORE_ADDR adjusted_bpaddr; | |
7176 | ||
7177 | /* Some targets have architectural constraints on the placement | |
7178 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7179 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7180 | |
7181 | /* An adjusted breakpoint address can significantly alter | |
7182 | a user's expectations. Print a warning if an adjustment | |
7183 | is required. */ | |
7184 | if (adjusted_bpaddr != bpaddr) | |
7185 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7186 | ||
7187 | return adjusted_bpaddr; | |
7188 | } | |
7189 | } | |
7190 | ||
28010a5d PA |
7191 | void |
7192 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7193 | struct breakpoint *owner) | |
7cc221ef | 7194 | { |
7cc221ef DJ |
7195 | memset (loc, 0, sizeof (*loc)); |
7196 | ||
348d480f PA |
7197 | gdb_assert (ops != NULL); |
7198 | ||
28010a5d PA |
7199 | loc->ops = ops; |
7200 | loc->owner = owner; | |
511a6cd4 | 7201 | loc->cond = NULL; |
b775012e | 7202 | loc->cond_bytecode = NULL; |
0d381245 VP |
7203 | loc->shlib_disabled = 0; |
7204 | loc->enabled = 1; | |
e049a4b5 | 7205 | |
28010a5d | 7206 | switch (owner->type) |
e049a4b5 DJ |
7207 | { |
7208 | case bp_breakpoint: | |
7c16b83e | 7209 | case bp_single_step: |
e049a4b5 DJ |
7210 | case bp_until: |
7211 | case bp_finish: | |
7212 | case bp_longjmp: | |
7213 | case bp_longjmp_resume: | |
e2e4d78b | 7214 | case bp_longjmp_call_dummy: |
186c406b TT |
7215 | case bp_exception: |
7216 | case bp_exception_resume: | |
e049a4b5 | 7217 | case bp_step_resume: |
2c03e5be | 7218 | case bp_hp_step_resume: |
e049a4b5 DJ |
7219 | case bp_watchpoint_scope: |
7220 | case bp_call_dummy: | |
aa7d318d | 7221 | case bp_std_terminate: |
e049a4b5 DJ |
7222 | case bp_shlib_event: |
7223 | case bp_thread_event: | |
7224 | case bp_overlay_event: | |
4efc6507 | 7225 | case bp_jit_event: |
0fd8e87f | 7226 | case bp_longjmp_master: |
aa7d318d | 7227 | case bp_std_terminate_master: |
186c406b | 7228 | case bp_exception_master: |
0e30163f JK |
7229 | case bp_gnu_ifunc_resolver: |
7230 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7231 | case bp_dprintf: |
e049a4b5 | 7232 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7233 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7234 | break; |
7235 | case bp_hardware_breakpoint: | |
7236 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7237 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7238 | break; |
7239 | case bp_hardware_watchpoint: | |
7240 | case bp_read_watchpoint: | |
7241 | case bp_access_watchpoint: | |
7242 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7243 | break; | |
7244 | case bp_watchpoint: | |
ce78b96d | 7245 | case bp_catchpoint: |
15c3d785 PA |
7246 | case bp_tracepoint: |
7247 | case bp_fast_tracepoint: | |
0fb4aa4b | 7248 | case bp_static_tracepoint: |
e049a4b5 DJ |
7249 | loc->loc_type = bp_loc_other; |
7250 | break; | |
7251 | default: | |
e2e0b3e5 | 7252 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7253 | } |
7254 | ||
f431efe5 | 7255 | loc->refc = 1; |
28010a5d PA |
7256 | } |
7257 | ||
7258 | /* Allocate a struct bp_location. */ | |
7259 | ||
7260 | static struct bp_location * | |
7261 | allocate_bp_location (struct breakpoint *bpt) | |
7262 | { | |
348d480f PA |
7263 | return bpt->ops->allocate_location (bpt); |
7264 | } | |
7cc221ef | 7265 | |
f431efe5 PA |
7266 | static void |
7267 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7268 | { |
348d480f | 7269 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7270 | xfree (loc); |
7271 | } | |
7272 | ||
f431efe5 PA |
7273 | /* Increment reference count. */ |
7274 | ||
7275 | static void | |
7276 | incref_bp_location (struct bp_location *bl) | |
7277 | { | |
7278 | ++bl->refc; | |
7279 | } | |
7280 | ||
7281 | /* Decrement reference count. If the reference count reaches 0, | |
7282 | destroy the bp_location. Sets *BLP to NULL. */ | |
7283 | ||
7284 | static void | |
7285 | decref_bp_location (struct bp_location **blp) | |
7286 | { | |
0807b50c PA |
7287 | gdb_assert ((*blp)->refc > 0); |
7288 | ||
f431efe5 PA |
7289 | if (--(*blp)->refc == 0) |
7290 | free_bp_location (*blp); | |
7291 | *blp = NULL; | |
7292 | } | |
7293 | ||
346774a9 | 7294 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7295 | |
346774a9 PA |
7296 | static void |
7297 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7298 | { |
346774a9 | 7299 | struct breakpoint *b1; |
c906108c | 7300 | |
346774a9 PA |
7301 | /* Add this breakpoint to the end of the chain so that a list of |
7302 | breakpoints will come out in order of increasing numbers. */ | |
7303 | ||
7304 | b1 = breakpoint_chain; | |
7305 | if (b1 == 0) | |
7306 | breakpoint_chain = b; | |
7307 | else | |
7308 | { | |
7309 | while (b1->next) | |
7310 | b1 = b1->next; | |
7311 | b1->next = b; | |
7312 | } | |
7313 | } | |
7314 | ||
7315 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7316 | ||
7317 | static void | |
7318 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7319 | struct gdbarch *gdbarch, | |
28010a5d | 7320 | enum bptype bptype, |
c0a91b2b | 7321 | const struct breakpoint_ops *ops) |
346774a9 | 7322 | { |
c906108c | 7323 | memset (b, 0, sizeof (*b)); |
2219d63c | 7324 | |
348d480f PA |
7325 | gdb_assert (ops != NULL); |
7326 | ||
28010a5d | 7327 | b->ops = ops; |
4d28f7a8 | 7328 | b->type = bptype; |
a6d9a66e | 7329 | b->gdbarch = gdbarch; |
c906108c SS |
7330 | b->language = current_language->la_language; |
7331 | b->input_radix = input_radix; | |
7332 | b->thread = -1; | |
b5de0fa7 | 7333 | b->enable_state = bp_enabled; |
c906108c SS |
7334 | b->next = 0; |
7335 | b->silent = 0; | |
7336 | b->ignore_count = 0; | |
7337 | b->commands = NULL; | |
818dd999 | 7338 | b->frame_id = null_frame_id; |
0d381245 | 7339 | b->condition_not_parsed = 0; |
84f4c1fe | 7340 | b->py_bp_object = NULL; |
d0fb5eae | 7341 | b->related_breakpoint = b; |
f00aae0f | 7342 | b->location = NULL; |
346774a9 PA |
7343 | } |
7344 | ||
7345 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7346 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7347 | |
7348 | static struct breakpoint * | |
7349 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7350 | enum bptype bptype, |
c0a91b2b | 7351 | const struct breakpoint_ops *ops) |
346774a9 PA |
7352 | { |
7353 | struct breakpoint *b = XNEW (struct breakpoint); | |
7354 | ||
348d480f | 7355 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7356 | add_to_breakpoint_chain (b); |
0d381245 VP |
7357 | return b; |
7358 | } | |
7359 | ||
0e30163f JK |
7360 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7361 | resolutions should be made as the user specified the location explicitly | |
7362 | enough. */ | |
7363 | ||
0d381245 | 7364 | static void |
0e30163f | 7365 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7366 | { |
2bdf28a0 JK |
7367 | gdb_assert (loc->owner != NULL); |
7368 | ||
0d381245 | 7369 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7370 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7371 | || is_tracepoint (loc->owner)) |
0d381245 | 7372 | { |
0e30163f | 7373 | int is_gnu_ifunc; |
2c02bd72 | 7374 | const char *function_name; |
6a3a010b | 7375 | CORE_ADDR func_addr; |
0e30163f | 7376 | |
2c02bd72 | 7377 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7378 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7379 | |
7380 | if (is_gnu_ifunc && !explicit_loc) | |
7381 | { | |
7382 | struct breakpoint *b = loc->owner; | |
7383 | ||
7384 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7385 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7386 | &loc->requested_address)) |
7387 | { | |
7388 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7389 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7390 | loc->requested_address, | |
7391 | b->type); | |
7392 | } | |
7393 | else if (b->type == bp_breakpoint && b->loc == loc | |
7394 | && loc->next == NULL && b->related_breakpoint == b) | |
7395 | { | |
7396 | /* Create only the whole new breakpoint of this type but do not | |
7397 | mess more complicated breakpoints with multiple locations. */ | |
7398 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7399 | /* Remember the resolver's address for use by the return |
7400 | breakpoint. */ | |
7401 | loc->related_address = func_addr; | |
0e30163f JK |
7402 | } |
7403 | } | |
7404 | ||
2c02bd72 DE |
7405 | if (function_name) |
7406 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7407 | } |
7408 | } | |
7409 | ||
a6d9a66e | 7410 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7411 | struct gdbarch * |
a6d9a66e UW |
7412 | get_sal_arch (struct symtab_and_line sal) |
7413 | { | |
7414 | if (sal.section) | |
7415 | return get_objfile_arch (sal.section->objfile); | |
7416 | if (sal.symtab) | |
eb822aa6 | 7417 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7418 | |
7419 | return NULL; | |
7420 | } | |
7421 | ||
346774a9 PA |
7422 | /* Low level routine for partially initializing a breakpoint of type |
7423 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7424 | file name, and line number are provided by SAL. |
0d381245 VP |
7425 | |
7426 | It is expected that the caller will complete the initialization of | |
7427 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7428 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7429 | |
346774a9 PA |
7430 | static void |
7431 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7432 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7433 | const struct breakpoint_ops *ops) |
0d381245 | 7434 | { |
28010a5d | 7435 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7436 | |
3742cc8b | 7437 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7438 | |
6c95b8df PA |
7439 | if (bptype != bp_catchpoint) |
7440 | gdb_assert (sal.pspace != NULL); | |
7441 | ||
f8eba3c6 TT |
7442 | /* Store the program space that was used to set the breakpoint, |
7443 | except for ordinary breakpoints, which are independent of the | |
7444 | program space. */ | |
7445 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7446 | b->pspace = sal.pspace; | |
346774a9 | 7447 | } |
c906108c | 7448 | |
346774a9 PA |
7449 | /* set_raw_breakpoint is a low level routine for allocating and |
7450 | partially initializing a breakpoint of type BPTYPE. The newly | |
7451 | created breakpoint's address, section, source file name, and line | |
7452 | number are provided by SAL. The newly created and partially | |
7453 | initialized breakpoint is added to the breakpoint chain and | |
7454 | is also returned as the value of this function. | |
7455 | ||
7456 | It is expected that the caller will complete the initialization of | |
7457 | the newly created breakpoint struct as well as output any status | |
7458 | information regarding the creation of a new breakpoint. In | |
7459 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7460 | number! Care should be taken to not allow an error to occur | |
7461 | prior to completing the initialization of the breakpoint. If this | |
7462 | should happen, a bogus breakpoint will be left on the chain. */ | |
7463 | ||
7464 | struct breakpoint * | |
7465 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7466 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7467 | const struct breakpoint_ops *ops) |
346774a9 PA |
7468 | { |
7469 | struct breakpoint *b = XNEW (struct breakpoint); | |
7470 | ||
348d480f | 7471 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7472 | add_to_breakpoint_chain (b); |
c906108c SS |
7473 | return b; |
7474 | } | |
7475 | ||
53a5351d | 7476 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7477 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7478 | initiated the operation. */ | |
c906108c SS |
7479 | |
7480 | void | |
186c406b | 7481 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7482 | { |
35df4500 | 7483 | struct breakpoint *b, *b_tmp; |
186c406b | 7484 | int thread = tp->num; |
0fd8e87f UW |
7485 | |
7486 | /* To avoid having to rescan all objfile symbols at every step, | |
7487 | we maintain a list of continually-inserted but always disabled | |
7488 | longjmp "master" breakpoints. Here, we simply create momentary | |
7489 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7490 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7491 | if (b->pspace == current_program_space |
186c406b TT |
7492 | && (b->type == bp_longjmp_master |
7493 | || b->type == bp_exception_master)) | |
0fd8e87f | 7494 | { |
06edf0c0 PA |
7495 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7496 | struct breakpoint *clone; | |
cc59ec59 | 7497 | |
e2e4d78b JK |
7498 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7499 | after their removal. */ | |
06edf0c0 | 7500 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7501 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7502 | clone->thread = thread; |
7503 | } | |
186c406b TT |
7504 | |
7505 | tp->initiating_frame = frame; | |
c906108c SS |
7506 | } |
7507 | ||
611c83ae | 7508 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7509 | void |
611c83ae | 7510 | delete_longjmp_breakpoint (int thread) |
c906108c | 7511 | { |
35df4500 | 7512 | struct breakpoint *b, *b_tmp; |
c906108c | 7513 | |
35df4500 | 7514 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7515 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7516 | { |
7517 | if (b->thread == thread) | |
7518 | delete_breakpoint (b); | |
7519 | } | |
c906108c SS |
7520 | } |
7521 | ||
f59f708a PA |
7522 | void |
7523 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7524 | { | |
7525 | struct breakpoint *b, *b_tmp; | |
7526 | ||
7527 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7528 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7529 | { | |
7530 | if (b->thread == thread) | |
7531 | b->disposition = disp_del_at_next_stop; | |
7532 | } | |
7533 | } | |
7534 | ||
e2e4d78b JK |
7535 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7536 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7537 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7538 | breakpoints. */ | |
7539 | ||
7540 | struct breakpoint * | |
7541 | set_longjmp_breakpoint_for_call_dummy (void) | |
7542 | { | |
7543 | struct breakpoint *b, *retval = NULL; | |
7544 | ||
7545 | ALL_BREAKPOINTS (b) | |
7546 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7547 | { | |
7548 | struct breakpoint *new_b; | |
7549 | ||
7550 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7551 | &momentary_breakpoint_ops, |
7552 | 1); | |
e2e4d78b JK |
7553 | new_b->thread = pid_to_thread_id (inferior_ptid); |
7554 | ||
7555 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7556 | ||
7557 | gdb_assert (new_b->related_breakpoint == new_b); | |
7558 | if (retval == NULL) | |
7559 | retval = new_b; | |
7560 | new_b->related_breakpoint = retval; | |
7561 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7562 | retval = retval->related_breakpoint; | |
7563 | retval->related_breakpoint = new_b; | |
7564 | } | |
7565 | ||
7566 | return retval; | |
7567 | } | |
7568 | ||
7569 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7570 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7571 | stack. |
7572 | ||
7573 | You should call this function only at places where it is safe to currently | |
7574 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7575 | frames. */ | |
7576 | ||
7577 | void | |
b67a2c6f | 7578 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7579 | { |
7580 | struct breakpoint *b, *b_tmp; | |
7581 | ||
7582 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
b67a2c6f | 7583 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->num) |
e2e4d78b JK |
7584 | { |
7585 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7586 | ||
7587 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7588 | dummy_b = dummy_b->related_breakpoint; | |
7589 | if (dummy_b->type != bp_call_dummy | |
7590 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7591 | continue; | |
7592 | ||
b67a2c6f | 7593 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7594 | |
7595 | while (b->related_breakpoint != b) | |
7596 | { | |
7597 | if (b_tmp == b->related_breakpoint) | |
7598 | b_tmp = b->related_breakpoint->next; | |
7599 | delete_breakpoint (b->related_breakpoint); | |
7600 | } | |
7601 | delete_breakpoint (b); | |
7602 | } | |
7603 | } | |
7604 | ||
1900040c MS |
7605 | void |
7606 | enable_overlay_breakpoints (void) | |
7607 | { | |
52f0bd74 | 7608 | struct breakpoint *b; |
1900040c MS |
7609 | |
7610 | ALL_BREAKPOINTS (b) | |
7611 | if (b->type == bp_overlay_event) | |
7612 | { | |
7613 | b->enable_state = bp_enabled; | |
44702360 | 7614 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7615 | overlay_events_enabled = 1; |
1900040c MS |
7616 | } |
7617 | } | |
7618 | ||
7619 | void | |
7620 | disable_overlay_breakpoints (void) | |
7621 | { | |
52f0bd74 | 7622 | struct breakpoint *b; |
1900040c MS |
7623 | |
7624 | ALL_BREAKPOINTS (b) | |
7625 | if (b->type == bp_overlay_event) | |
7626 | { | |
7627 | b->enable_state = bp_disabled; | |
44702360 | 7628 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7629 | overlay_events_enabled = 0; |
1900040c MS |
7630 | } |
7631 | } | |
7632 | ||
aa7d318d TT |
7633 | /* Set an active std::terminate breakpoint for each std::terminate |
7634 | master breakpoint. */ | |
7635 | void | |
7636 | set_std_terminate_breakpoint (void) | |
7637 | { | |
35df4500 | 7638 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7639 | |
35df4500 | 7640 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7641 | if (b->pspace == current_program_space |
7642 | && b->type == bp_std_terminate_master) | |
7643 | { | |
06edf0c0 | 7644 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7645 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7646 | } |
7647 | } | |
7648 | ||
7649 | /* Delete all the std::terminate breakpoints. */ | |
7650 | void | |
7651 | delete_std_terminate_breakpoint (void) | |
7652 | { | |
35df4500 | 7653 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7654 | |
35df4500 | 7655 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7656 | if (b->type == bp_std_terminate) |
7657 | delete_breakpoint (b); | |
7658 | } | |
7659 | ||
c4093a6a | 7660 | struct breakpoint * |
a6d9a66e | 7661 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a | 7662 | { |
f00aae0f | 7663 | char *tmp; |
c4093a6a | 7664 | struct breakpoint *b; |
f00aae0f | 7665 | struct cleanup *cleanup; |
c4093a6a | 7666 | |
06edf0c0 PA |
7667 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7668 | &internal_breakpoint_ops); | |
7669 | ||
b5de0fa7 | 7670 | b->enable_state = bp_enabled; |
f00aae0f KS |
7671 | /* location has to be used or breakpoint_re_set will delete me. */ |
7672 | tmp = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
7673 | cleanup = make_cleanup (xfree, tmp); | |
7674 | b->location = new_linespec_location (&tmp); | |
7675 | do_cleanups (cleanup); | |
c4093a6a | 7676 | |
44702360 | 7677 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7678 | |
c4093a6a JM |
7679 | return b; |
7680 | } | |
7681 | ||
7682 | void | |
7683 | remove_thread_event_breakpoints (void) | |
7684 | { | |
35df4500 | 7685 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7686 | |
35df4500 | 7687 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7688 | if (b->type == bp_thread_event |
7689 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7690 | delete_breakpoint (b); |
7691 | } | |
7692 | ||
0101ce28 JJ |
7693 | struct lang_and_radix |
7694 | { | |
7695 | enum language lang; | |
7696 | int radix; | |
7697 | }; | |
7698 | ||
4efc6507 DE |
7699 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7700 | ||
7701 | struct breakpoint * | |
7702 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7703 | { | |
7704 | struct breakpoint *b; | |
7705 | ||
06edf0c0 PA |
7706 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7707 | &internal_breakpoint_ops); | |
44702360 | 7708 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
4efc6507 DE |
7709 | return b; |
7710 | } | |
0101ce28 | 7711 | |
03673fc7 PP |
7712 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7713 | ||
7714 | void | |
7715 | remove_jit_event_breakpoints (void) | |
7716 | { | |
7717 | struct breakpoint *b, *b_tmp; | |
7718 | ||
7719 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7720 | if (b->type == bp_jit_event | |
7721 | && b->loc->pspace == current_program_space) | |
7722 | delete_breakpoint (b); | |
7723 | } | |
7724 | ||
cae688ec JJ |
7725 | void |
7726 | remove_solib_event_breakpoints (void) | |
7727 | { | |
35df4500 | 7728 | struct breakpoint *b, *b_tmp; |
cae688ec | 7729 | |
35df4500 | 7730 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7731 | if (b->type == bp_shlib_event |
7732 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7733 | delete_breakpoint (b); |
7734 | } | |
7735 | ||
f37f681c PA |
7736 | /* See breakpoint.h. */ |
7737 | ||
7738 | void | |
7739 | remove_solib_event_breakpoints_at_next_stop (void) | |
7740 | { | |
7741 | struct breakpoint *b, *b_tmp; | |
7742 | ||
7743 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7744 | if (b->type == bp_shlib_event | |
7745 | && b->loc->pspace == current_program_space) | |
7746 | b->disposition = disp_del_at_next_stop; | |
7747 | } | |
7748 | ||
04086b45 PA |
7749 | /* Helper for create_solib_event_breakpoint / |
7750 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7751 | INSERT_MODE to pass through to update_global_location_list. */ | |
7752 | ||
7753 | static struct breakpoint * | |
7754 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7755 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7756 | { |
7757 | struct breakpoint *b; | |
7758 | ||
06edf0c0 PA |
7759 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7760 | &internal_breakpoint_ops); | |
04086b45 | 7761 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7762 | return b; |
7763 | } | |
7764 | ||
04086b45 PA |
7765 | struct breakpoint * |
7766 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7767 | { | |
7768 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7769 | } | |
7770 | ||
f37f681c PA |
7771 | /* See breakpoint.h. */ |
7772 | ||
7773 | struct breakpoint * | |
7774 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7775 | { | |
7776 | struct breakpoint *b; | |
7777 | ||
04086b45 PA |
7778 | /* Explicitly tell update_global_location_list to insert |
7779 | locations. */ | |
7780 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7781 | if (!b->loc->inserted) |
7782 | { | |
7783 | delete_breakpoint (b); | |
7784 | return NULL; | |
7785 | } | |
7786 | return b; | |
7787 | } | |
7788 | ||
cae688ec JJ |
7789 | /* Disable any breakpoints that are on code in shared libraries. Only |
7790 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7791 | ||
7792 | void | |
cb851954 | 7793 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7794 | { |
876fa593 | 7795 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7796 | |
876fa593 | 7797 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7798 | { |
2bdf28a0 | 7799 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7800 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7801 | |
4a64f543 MS |
7802 | /* We apply the check to all breakpoints, including disabled for |
7803 | those with loc->duplicate set. This is so that when breakpoint | |
7804 | becomes enabled, or the duplicate is removed, gdb will try to | |
7805 | insert all breakpoints. If we don't set shlib_disabled here, | |
7806 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7807 | if (((b->type == bp_breakpoint) |
508ccb1f | 7808 | || (b->type == bp_jit_event) |
1042e4c0 | 7809 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7810 | || (is_tracepoint (b))) |
6c95b8df | 7811 | && loc->pspace == current_program_space |
0d381245 | 7812 | && !loc->shlib_disabled |
6c95b8df | 7813 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7814 | ) |
0d381245 VP |
7815 | { |
7816 | loc->shlib_disabled = 1; | |
7817 | } | |
cae688ec JJ |
7818 | } |
7819 | } | |
7820 | ||
63644780 NB |
7821 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7822 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7823 | disabled ones can just stay disabled. */ | |
84acb35a | 7824 | |
75149521 | 7825 | static void |
84acb35a JJ |
7826 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7827 | { | |
876fa593 | 7828 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7829 | int disabled_shlib_breaks = 0; |
7830 | ||
c86cf029 VP |
7831 | /* SunOS a.out shared libraries are always mapped, so do not |
7832 | disable breakpoints; they will only be reported as unloaded | |
7833 | through clear_solib when GDB discards its shared library | |
7834 | list. See clear_solib for more information. */ | |
7835 | if (exec_bfd != NULL | |
7836 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7837 | return; | |
7838 | ||
876fa593 | 7839 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7840 | { |
2bdf28a0 | 7841 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7842 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7843 | |
1e4d1764 | 7844 | if (solib->pspace == loc->pspace |
e2dd7057 | 7845 | && !loc->shlib_disabled |
1e4d1764 YQ |
7846 | && (((b->type == bp_breakpoint |
7847 | || b->type == bp_jit_event | |
7848 | || b->type == bp_hardware_breakpoint) | |
7849 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7850 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7851 | || is_tracepoint (b)) | |
e2dd7057 | 7852 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7853 | { |
e2dd7057 PP |
7854 | loc->shlib_disabled = 1; |
7855 | /* At this point, we cannot rely on remove_breakpoint | |
7856 | succeeding so we must mark the breakpoint as not inserted | |
7857 | to prevent future errors occurring in remove_breakpoints. */ | |
7858 | loc->inserted = 0; | |
8d3788bd VP |
7859 | |
7860 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7861 | observer_notify_breakpoint_modified (b); | |
7862 | ||
e2dd7057 PP |
7863 | if (!disabled_shlib_breaks) |
7864 | { | |
7865 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7866 | warning (_("Temporarily disabling breakpoints " |
7867 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7868 | solib->so_name); |
84acb35a | 7869 | } |
e2dd7057 | 7870 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7871 | } |
7872 | } | |
84acb35a JJ |
7873 | } |
7874 | ||
63644780 NB |
7875 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7876 | notification of free_objfile. Only apply to enabled breakpoints, | |
7877 | disabled ones can just stay disabled. */ | |
7878 | ||
7879 | static void | |
7880 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7881 | { | |
7882 | struct breakpoint *b; | |
7883 | ||
7884 | if (objfile == NULL) | |
7885 | return; | |
7886 | ||
d03de421 PA |
7887 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7888 | managed by the user with add-symbol-file/remove-symbol-file. | |
7889 | Similarly to how breakpoints in shared libraries are handled in | |
7890 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7891 | shlib_disabled so they end up uninserted on the next global |
7892 | location list update. Shared libraries not loaded by the user | |
7893 | aren't handled here -- they're already handled in | |
7894 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7895 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7896 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7897 | main objfile). */ | |
7898 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7899 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7900 | return; |
7901 | ||
7902 | ALL_BREAKPOINTS (b) | |
7903 | { | |
7904 | struct bp_location *loc; | |
7905 | int bp_modified = 0; | |
7906 | ||
7907 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7908 | continue; | |
7909 | ||
7910 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7911 | { | |
7912 | CORE_ADDR loc_addr = loc->address; | |
7913 | ||
7914 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7915 | && loc->loc_type != bp_loc_software_breakpoint) | |
7916 | continue; | |
7917 | ||
7918 | if (loc->shlib_disabled != 0) | |
7919 | continue; | |
7920 | ||
7921 | if (objfile->pspace != loc->pspace) | |
7922 | continue; | |
7923 | ||
7924 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7925 | && loc->loc_type != bp_loc_software_breakpoint) | |
7926 | continue; | |
7927 | ||
7928 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7929 | { | |
7930 | loc->shlib_disabled = 1; | |
08351840 PA |
7931 | /* At this point, we don't know whether the object was |
7932 | unmapped from the inferior or not, so leave the | |
7933 | inserted flag alone. We'll handle failure to | |
7934 | uninsert quietly, in case the object was indeed | |
7935 | unmapped. */ | |
63644780 NB |
7936 | |
7937 | mark_breakpoint_location_modified (loc); | |
7938 | ||
7939 | bp_modified = 1; | |
7940 | } | |
7941 | } | |
7942 | ||
7943 | if (bp_modified) | |
7944 | observer_notify_breakpoint_modified (b); | |
7945 | } | |
7946 | } | |
7947 | ||
ce78b96d JB |
7948 | /* FORK & VFORK catchpoints. */ |
7949 | ||
e29a4733 PA |
7950 | /* An instance of this type is used to represent a fork or vfork |
7951 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
7952 | class; users downcast to "struct breakpoint *" when needed. A | |
7953 | breakpoint is really of this type iff its ops pointer points to | |
7954 | CATCH_FORK_BREAKPOINT_OPS. */ | |
7955 | ||
7956 | struct fork_catchpoint | |
7957 | { | |
7958 | /* The base class. */ | |
7959 | struct breakpoint base; | |
7960 | ||
7961 | /* Process id of a child process whose forking triggered this | |
7962 | catchpoint. This field is only valid immediately after this | |
7963 | catchpoint has triggered. */ | |
7964 | ptid_t forked_inferior_pid; | |
7965 | }; | |
7966 | ||
4a64f543 MS |
7967 | /* Implement the "insert" breakpoint_ops method for fork |
7968 | catchpoints. */ | |
ce78b96d | 7969 | |
77b06cd7 TJB |
7970 | static int |
7971 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7972 | { |
dfd4cc63 | 7973 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7974 | } |
7975 | ||
4a64f543 MS |
7976 | /* Implement the "remove" breakpoint_ops method for fork |
7977 | catchpoints. */ | |
ce78b96d JB |
7978 | |
7979 | static int | |
77b06cd7 | 7980 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 7981 | { |
dfd4cc63 | 7982 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7983 | } |
7984 | ||
7985 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7986 | catchpoints. */ | |
7987 | ||
7988 | static int | |
f1310107 | 7989 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7990 | struct address_space *aspace, CORE_ADDR bp_addr, |
7991 | const struct target_waitstatus *ws) | |
ce78b96d | 7992 | { |
e29a4733 PA |
7993 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7994 | ||
f90263c1 TT |
7995 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7996 | return 0; | |
7997 | ||
7998 | c->forked_inferior_pid = ws->value.related_pid; | |
7999 | return 1; | |
ce78b96d JB |
8000 | } |
8001 | ||
4a64f543 MS |
8002 | /* Implement the "print_it" breakpoint_ops method for fork |
8003 | catchpoints. */ | |
ce78b96d JB |
8004 | |
8005 | static enum print_stop_action | |
348d480f | 8006 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8007 | { |
36dfb11c | 8008 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8009 | struct breakpoint *b = bs->breakpoint_at; |
8010 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8011 | |
ce78b96d | 8012 | annotate_catchpoint (b->number); |
36dfb11c TT |
8013 | if (b->disposition == disp_del) |
8014 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8015 | else | |
8016 | ui_out_text (uiout, "\nCatchpoint "); | |
8017 | if (ui_out_is_mi_like_p (uiout)) | |
8018 | { | |
8019 | ui_out_field_string (uiout, "reason", | |
8020 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
8021 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8022 | } | |
8023 | ui_out_field_int (uiout, "bkptno", b->number); | |
8024 | ui_out_text (uiout, " (forked process "); | |
8025 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8026 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8027 | return PRINT_SRC_AND_LOC; |
8028 | } | |
8029 | ||
4a64f543 MS |
8030 | /* Implement the "print_one" breakpoint_ops method for fork |
8031 | catchpoints. */ | |
ce78b96d JB |
8032 | |
8033 | static void | |
a6d9a66e | 8034 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8035 | { |
e29a4733 | 8036 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8037 | struct value_print_options opts; |
79a45e25 | 8038 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8039 | |
8040 | get_user_print_options (&opts); | |
8041 | ||
4a64f543 MS |
8042 | /* Field 4, the address, is omitted (which makes the columns not |
8043 | line up too nicely with the headers, but the effect is relatively | |
8044 | readable). */ | |
79a45b7d | 8045 | if (opts.addressprint) |
ce78b96d JB |
8046 | ui_out_field_skip (uiout, "addr"); |
8047 | annotate_field (5); | |
8048 | ui_out_text (uiout, "fork"); | |
e29a4733 | 8049 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8050 | { |
8051 | ui_out_text (uiout, ", process "); | |
8052 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8053 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8054 | ui_out_spaces (uiout, 1); |
8055 | } | |
8ac3646f TT |
8056 | |
8057 | if (ui_out_is_mi_like_p (uiout)) | |
8058 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
8059 | } |
8060 | ||
8061 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8062 | catchpoints. */ | |
8063 | ||
8064 | static void | |
8065 | print_mention_catch_fork (struct breakpoint *b) | |
8066 | { | |
8067 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8068 | } | |
8069 | ||
6149aea9 PA |
8070 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8071 | catchpoints. */ | |
8072 | ||
8073 | static void | |
8074 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8075 | { | |
8076 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8077 | print_recreate_thread (b, fp); |
6149aea9 PA |
8078 | } |
8079 | ||
ce78b96d JB |
8080 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8081 | ||
2060206e | 8082 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8083 | |
4a64f543 MS |
8084 | /* Implement the "insert" breakpoint_ops method for vfork |
8085 | catchpoints. */ | |
ce78b96d | 8086 | |
77b06cd7 TJB |
8087 | static int |
8088 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8089 | { |
dfd4cc63 | 8090 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8091 | } |
8092 | ||
4a64f543 MS |
8093 | /* Implement the "remove" breakpoint_ops method for vfork |
8094 | catchpoints. */ | |
ce78b96d JB |
8095 | |
8096 | static int | |
77b06cd7 | 8097 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 8098 | { |
dfd4cc63 | 8099 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8100 | } |
8101 | ||
8102 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8103 | catchpoints. */ | |
8104 | ||
8105 | static int | |
f1310107 | 8106 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8107 | struct address_space *aspace, CORE_ADDR bp_addr, |
8108 | const struct target_waitstatus *ws) | |
ce78b96d | 8109 | { |
e29a4733 PA |
8110 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8111 | ||
f90263c1 TT |
8112 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8113 | return 0; | |
8114 | ||
8115 | c->forked_inferior_pid = ws->value.related_pid; | |
8116 | return 1; | |
ce78b96d JB |
8117 | } |
8118 | ||
4a64f543 MS |
8119 | /* Implement the "print_it" breakpoint_ops method for vfork |
8120 | catchpoints. */ | |
ce78b96d JB |
8121 | |
8122 | static enum print_stop_action | |
348d480f | 8123 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8124 | { |
36dfb11c | 8125 | struct ui_out *uiout = current_uiout; |
348d480f | 8126 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8127 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8128 | ||
ce78b96d | 8129 | annotate_catchpoint (b->number); |
36dfb11c TT |
8130 | if (b->disposition == disp_del) |
8131 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8132 | else | |
8133 | ui_out_text (uiout, "\nCatchpoint "); | |
8134 | if (ui_out_is_mi_like_p (uiout)) | |
8135 | { | |
8136 | ui_out_field_string (uiout, "reason", | |
8137 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8138 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8139 | } | |
8140 | ui_out_field_int (uiout, "bkptno", b->number); | |
8141 | ui_out_text (uiout, " (vforked process "); | |
8142 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8143 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8144 | return PRINT_SRC_AND_LOC; |
8145 | } | |
8146 | ||
4a64f543 MS |
8147 | /* Implement the "print_one" breakpoint_ops method for vfork |
8148 | catchpoints. */ | |
ce78b96d JB |
8149 | |
8150 | static void | |
a6d9a66e | 8151 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8152 | { |
e29a4733 | 8153 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8154 | struct value_print_options opts; |
79a45e25 | 8155 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8156 | |
8157 | get_user_print_options (&opts); | |
4a64f543 MS |
8158 | /* Field 4, the address, is omitted (which makes the columns not |
8159 | line up too nicely with the headers, but the effect is relatively | |
8160 | readable). */ | |
79a45b7d | 8161 | if (opts.addressprint) |
ce78b96d JB |
8162 | ui_out_field_skip (uiout, "addr"); |
8163 | annotate_field (5); | |
8164 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8165 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8166 | { |
8167 | ui_out_text (uiout, ", process "); | |
8168 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8169 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8170 | ui_out_spaces (uiout, 1); |
8171 | } | |
8ac3646f TT |
8172 | |
8173 | if (ui_out_is_mi_like_p (uiout)) | |
8174 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8175 | } |
8176 | ||
8177 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8178 | catchpoints. */ | |
8179 | ||
8180 | static void | |
8181 | print_mention_catch_vfork (struct breakpoint *b) | |
8182 | { | |
8183 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8184 | } | |
8185 | ||
6149aea9 PA |
8186 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8187 | catchpoints. */ | |
8188 | ||
8189 | static void | |
8190 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8191 | { | |
8192 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8193 | print_recreate_thread (b, fp); |
6149aea9 PA |
8194 | } |
8195 | ||
ce78b96d JB |
8196 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8197 | ||
2060206e | 8198 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8199 | |
edcc5120 TT |
8200 | /* An instance of this type is used to represent an solib catchpoint. |
8201 | It includes a "struct breakpoint" as a kind of base class; users | |
8202 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8203 | really of this type iff its ops pointer points to | |
8204 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8205 | ||
8206 | struct solib_catchpoint | |
8207 | { | |
8208 | /* The base class. */ | |
8209 | struct breakpoint base; | |
8210 | ||
8211 | /* True for "catch load", false for "catch unload". */ | |
8212 | unsigned char is_load; | |
8213 | ||
8214 | /* Regular expression to match, if any. COMPILED is only valid when | |
8215 | REGEX is non-NULL. */ | |
8216 | char *regex; | |
8217 | regex_t compiled; | |
8218 | }; | |
8219 | ||
8220 | static void | |
8221 | dtor_catch_solib (struct breakpoint *b) | |
8222 | { | |
8223 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8224 | ||
8225 | if (self->regex) | |
8226 | regfree (&self->compiled); | |
8227 | xfree (self->regex); | |
8228 | ||
8229 | base_breakpoint_ops.dtor (b); | |
8230 | } | |
8231 | ||
8232 | static int | |
8233 | insert_catch_solib (struct bp_location *ignore) | |
8234 | { | |
8235 | return 0; | |
8236 | } | |
8237 | ||
8238 | static int | |
8239 | remove_catch_solib (struct bp_location *ignore) | |
8240 | { | |
8241 | return 0; | |
8242 | } | |
8243 | ||
8244 | static int | |
8245 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8246 | struct address_space *aspace, | |
8247 | CORE_ADDR bp_addr, | |
8248 | const struct target_waitstatus *ws) | |
8249 | { | |
8250 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8251 | struct breakpoint *other; | |
8252 | ||
8253 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8254 | return 1; | |
8255 | ||
8256 | ALL_BREAKPOINTS (other) | |
8257 | { | |
8258 | struct bp_location *other_bl; | |
8259 | ||
8260 | if (other == bl->owner) | |
8261 | continue; | |
8262 | ||
8263 | if (other->type != bp_shlib_event) | |
8264 | continue; | |
8265 | ||
8266 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8267 | continue; | |
8268 | ||
8269 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8270 | { | |
8271 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8272 | return 1; | |
8273 | } | |
8274 | } | |
8275 | ||
8276 | return 0; | |
8277 | } | |
8278 | ||
8279 | static void | |
8280 | check_status_catch_solib (struct bpstats *bs) | |
8281 | { | |
8282 | struct solib_catchpoint *self | |
8283 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8284 | int ix; | |
8285 | ||
8286 | if (self->is_load) | |
8287 | { | |
8288 | struct so_list *iter; | |
8289 | ||
8290 | for (ix = 0; | |
8291 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8292 | ix, iter); | |
8293 | ++ix) | |
8294 | { | |
8295 | if (!self->regex | |
8296 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8297 | return; | |
8298 | } | |
8299 | } | |
8300 | else | |
8301 | { | |
8302 | char *iter; | |
8303 | ||
8304 | for (ix = 0; | |
8305 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8306 | ix, iter); | |
8307 | ++ix) | |
8308 | { | |
8309 | if (!self->regex | |
8310 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8311 | return; | |
8312 | } | |
8313 | } | |
8314 | ||
8315 | bs->stop = 0; | |
8316 | bs->print_it = print_it_noop; | |
8317 | } | |
8318 | ||
8319 | static enum print_stop_action | |
8320 | print_it_catch_solib (bpstat bs) | |
8321 | { | |
8322 | struct breakpoint *b = bs->breakpoint_at; | |
8323 | struct ui_out *uiout = current_uiout; | |
8324 | ||
8325 | annotate_catchpoint (b->number); | |
8326 | if (b->disposition == disp_del) | |
8327 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8328 | else | |
8329 | ui_out_text (uiout, "\nCatchpoint "); | |
8330 | ui_out_field_int (uiout, "bkptno", b->number); | |
8331 | ui_out_text (uiout, "\n"); | |
8332 | if (ui_out_is_mi_like_p (uiout)) | |
8333 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8334 | print_solib_event (1); | |
8335 | return PRINT_SRC_AND_LOC; | |
8336 | } | |
8337 | ||
8338 | static void | |
8339 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8340 | { | |
8341 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8342 | struct value_print_options opts; | |
8343 | struct ui_out *uiout = current_uiout; | |
8344 | char *msg; | |
8345 | ||
8346 | get_user_print_options (&opts); | |
8347 | /* Field 4, the address, is omitted (which makes the columns not | |
8348 | line up too nicely with the headers, but the effect is relatively | |
8349 | readable). */ | |
8350 | if (opts.addressprint) | |
8351 | { | |
8352 | annotate_field (4); | |
8353 | ui_out_field_skip (uiout, "addr"); | |
8354 | } | |
8355 | ||
8356 | annotate_field (5); | |
8357 | if (self->is_load) | |
8358 | { | |
8359 | if (self->regex) | |
8360 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8361 | else | |
8362 | msg = xstrdup (_("load of library")); | |
8363 | } | |
8364 | else | |
8365 | { | |
8366 | if (self->regex) | |
8367 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8368 | else | |
8369 | msg = xstrdup (_("unload of library")); | |
8370 | } | |
8371 | ui_out_field_string (uiout, "what", msg); | |
8372 | xfree (msg); | |
8ac3646f TT |
8373 | |
8374 | if (ui_out_is_mi_like_p (uiout)) | |
8375 | ui_out_field_string (uiout, "catch-type", | |
8376 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8377 | } |
8378 | ||
8379 | static void | |
8380 | print_mention_catch_solib (struct breakpoint *b) | |
8381 | { | |
8382 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8383 | ||
8384 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8385 | self->is_load ? "load" : "unload"); | |
8386 | } | |
8387 | ||
8388 | static void | |
8389 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8390 | { | |
8391 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8392 | ||
8393 | fprintf_unfiltered (fp, "%s %s", | |
8394 | b->disposition == disp_del ? "tcatch" : "catch", | |
8395 | self->is_load ? "load" : "unload"); | |
8396 | if (self->regex) | |
8397 | fprintf_unfiltered (fp, " %s", self->regex); | |
8398 | fprintf_unfiltered (fp, "\n"); | |
8399 | } | |
8400 | ||
8401 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8402 | ||
91985142 MG |
8403 | /* Shared helper function (MI and CLI) for creating and installing |
8404 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8405 | the events to be caught are load events, otherwise they are | |
8406 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8407 | temporary one. If ENABLED is non-zero the catchpoint is | |
8408 | created in an enabled state. */ | |
edcc5120 | 8409 | |
91985142 MG |
8410 | void |
8411 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8412 | { |
8413 | struct solib_catchpoint *c; | |
8414 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8415 | struct cleanup *cleanup; |
8416 | ||
edcc5120 TT |
8417 | if (!arg) |
8418 | arg = ""; | |
8419 | arg = skip_spaces (arg); | |
8420 | ||
8421 | c = XCNEW (struct solib_catchpoint); | |
8422 | cleanup = make_cleanup (xfree, c); | |
8423 | ||
8424 | if (*arg != '\0') | |
8425 | { | |
8426 | int errcode; | |
8427 | ||
8428 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8429 | if (errcode != 0) | |
8430 | { | |
8431 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8432 | ||
8433 | make_cleanup (xfree, err); | |
8434 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8435 | } | |
8436 | c->regex = xstrdup (arg); | |
8437 | } | |
8438 | ||
8439 | c->is_load = is_load; | |
91985142 | 8440 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8441 | &catch_solib_breakpoint_ops); |
8442 | ||
91985142 MG |
8443 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8444 | ||
edcc5120 TT |
8445 | discard_cleanups (cleanup); |
8446 | install_breakpoint (0, &c->base, 1); | |
8447 | } | |
8448 | ||
91985142 MG |
8449 | /* A helper function that does all the work for "catch load" and |
8450 | "catch unload". */ | |
8451 | ||
8452 | static void | |
8453 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8454 | struct cmd_list_element *command) | |
8455 | { | |
8456 | int tempflag; | |
8457 | const int enabled = 1; | |
8458 | ||
8459 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8460 | ||
8461 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8462 | } | |
8463 | ||
edcc5120 TT |
8464 | static void |
8465 | catch_load_command_1 (char *arg, int from_tty, | |
8466 | struct cmd_list_element *command) | |
8467 | { | |
8468 | catch_load_or_unload (arg, from_tty, 1, command); | |
8469 | } | |
8470 | ||
8471 | static void | |
8472 | catch_unload_command_1 (char *arg, int from_tty, | |
8473 | struct cmd_list_element *command) | |
8474 | { | |
8475 | catch_load_or_unload (arg, from_tty, 0, command); | |
8476 | } | |
8477 | ||
346774a9 PA |
8478 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8479 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8480 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8481 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8482 | |
ab04a2af | 8483 | void |
346774a9 PA |
8484 | init_catchpoint (struct breakpoint *b, |
8485 | struct gdbarch *gdbarch, int tempflag, | |
8486 | char *cond_string, | |
c0a91b2b | 8487 | const struct breakpoint_ops *ops) |
c906108c | 8488 | { |
c5aa993b | 8489 | struct symtab_and_line sal; |
346774a9 | 8490 | |
fe39c653 | 8491 | init_sal (&sal); |
6c95b8df | 8492 | sal.pspace = current_program_space; |
c5aa993b | 8493 | |
28010a5d | 8494 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8495 | |
1b36a34b | 8496 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8497 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8498 | } |
8499 | ||
28010a5d | 8500 | void |
3ea46bff | 8501 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8502 | { |
8503 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8504 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8505 | if (is_tracepoint (b)) |
8506 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8507 | if (!internal) |
8508 | mention (b); | |
c56053d2 | 8509 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8510 | |
8511 | if (update_gll) | |
44702360 | 8512 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8513 | } |
8514 | ||
9b70b993 | 8515 | static void |
a6d9a66e UW |
8516 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8517 | int tempflag, char *cond_string, | |
c0a91b2b | 8518 | const struct breakpoint_ops *ops) |
c906108c | 8519 | { |
e29a4733 | 8520 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8521 | |
e29a4733 PA |
8522 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8523 | ||
8524 | c->forked_inferior_pid = null_ptid; | |
8525 | ||
3ea46bff | 8526 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8527 | } |
8528 | ||
fe798b75 JB |
8529 | /* Exec catchpoints. */ |
8530 | ||
b4d90040 PA |
8531 | /* An instance of this type is used to represent an exec catchpoint. |
8532 | It includes a "struct breakpoint" as a kind of base class; users | |
8533 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8534 | really of this type iff its ops pointer points to | |
8535 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8536 | ||
8537 | struct exec_catchpoint | |
8538 | { | |
8539 | /* The base class. */ | |
8540 | struct breakpoint base; | |
8541 | ||
8542 | /* Filename of a program whose exec triggered this catchpoint. | |
8543 | This field is only valid immediately after this catchpoint has | |
8544 | triggered. */ | |
8545 | char *exec_pathname; | |
8546 | }; | |
8547 | ||
8548 | /* Implement the "dtor" breakpoint_ops method for exec | |
8549 | catchpoints. */ | |
8550 | ||
8551 | static void | |
8552 | dtor_catch_exec (struct breakpoint *b) | |
8553 | { | |
8554 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8555 | ||
8556 | xfree (c->exec_pathname); | |
348d480f | 8557 | |
2060206e | 8558 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8559 | } |
8560 | ||
77b06cd7 TJB |
8561 | static int |
8562 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8563 | { |
dfd4cc63 | 8564 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8565 | } |
c906108c | 8566 | |
fe798b75 | 8567 | static int |
77b06cd7 | 8568 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8569 | { |
dfd4cc63 | 8570 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8571 | } |
c906108c | 8572 | |
fe798b75 | 8573 | static int |
f1310107 | 8574 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8575 | struct address_space *aspace, CORE_ADDR bp_addr, |
8576 | const struct target_waitstatus *ws) | |
fe798b75 | 8577 | { |
b4d90040 PA |
8578 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8579 | ||
f90263c1 TT |
8580 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8581 | return 0; | |
8582 | ||
8583 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8584 | return 1; | |
fe798b75 | 8585 | } |
c906108c | 8586 | |
fe798b75 | 8587 | static enum print_stop_action |
348d480f | 8588 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8589 | { |
36dfb11c | 8590 | struct ui_out *uiout = current_uiout; |
348d480f | 8591 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8592 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8593 | ||
fe798b75 | 8594 | annotate_catchpoint (b->number); |
36dfb11c TT |
8595 | if (b->disposition == disp_del) |
8596 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8597 | else | |
8598 | ui_out_text (uiout, "\nCatchpoint "); | |
8599 | if (ui_out_is_mi_like_p (uiout)) | |
8600 | { | |
8601 | ui_out_field_string (uiout, "reason", | |
8602 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8603 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8604 | } | |
8605 | ui_out_field_int (uiout, "bkptno", b->number); | |
8606 | ui_out_text (uiout, " (exec'd "); | |
8607 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8608 | ui_out_text (uiout, "), "); | |
8609 | ||
fe798b75 | 8610 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8611 | } |
8612 | ||
fe798b75 | 8613 | static void |
a6d9a66e | 8614 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8615 | { |
b4d90040 | 8616 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8617 | struct value_print_options opts; |
79a45e25 | 8618 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8619 | |
8620 | get_user_print_options (&opts); | |
8621 | ||
8622 | /* Field 4, the address, is omitted (which makes the columns | |
8623 | not line up too nicely with the headers, but the effect | |
8624 | is relatively readable). */ | |
8625 | if (opts.addressprint) | |
8626 | ui_out_field_skip (uiout, "addr"); | |
8627 | annotate_field (5); | |
8628 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8629 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8630 | { |
8631 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8632 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8633 | ui_out_text (uiout, "\" "); |
8634 | } | |
8ac3646f TT |
8635 | |
8636 | if (ui_out_is_mi_like_p (uiout)) | |
8637 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8638 | } |
8639 | ||
8640 | static void | |
8641 | print_mention_catch_exec (struct breakpoint *b) | |
8642 | { | |
8643 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8644 | } | |
8645 | ||
6149aea9 PA |
8646 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8647 | catchpoints. */ | |
8648 | ||
8649 | static void | |
8650 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8651 | { | |
8652 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8653 | print_recreate_thread (b, fp); |
6149aea9 PA |
8654 | } |
8655 | ||
2060206e | 8656 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8657 | |
c906108c | 8658 | static int |
fba45db2 | 8659 | hw_breakpoint_used_count (void) |
c906108c | 8660 | { |
c906108c | 8661 | int i = 0; |
f1310107 TJB |
8662 | struct breakpoint *b; |
8663 | struct bp_location *bl; | |
c906108c SS |
8664 | |
8665 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8666 | { |
d6b74ac4 | 8667 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8668 | for (bl = b->loc; bl; bl = bl->next) |
8669 | { | |
8670 | /* Special types of hardware breakpoints may use more than | |
8671 | one register. */ | |
348d480f | 8672 | i += b->ops->resources_needed (bl); |
f1310107 | 8673 | } |
c5aa993b | 8674 | } |
c906108c SS |
8675 | |
8676 | return i; | |
8677 | } | |
8678 | ||
a1398e0c PA |
8679 | /* Returns the resources B would use if it were a hardware |
8680 | watchpoint. */ | |
8681 | ||
c906108c | 8682 | static int |
a1398e0c | 8683 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8684 | { |
c906108c | 8685 | int i = 0; |
e09342b5 | 8686 | struct bp_location *bl; |
c906108c | 8687 | |
a1398e0c PA |
8688 | if (!breakpoint_enabled (b)) |
8689 | return 0; | |
8690 | ||
8691 | for (bl = b->loc; bl; bl = bl->next) | |
8692 | { | |
8693 | /* Special types of hardware watchpoints may use more than | |
8694 | one register. */ | |
8695 | i += b->ops->resources_needed (bl); | |
8696 | } | |
8697 | ||
8698 | return i; | |
8699 | } | |
8700 | ||
8701 | /* Returns the sum the used resources of all hardware watchpoints of | |
8702 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8703 | the sum of the used resources of all hardware watchpoints of other | |
8704 | types _not_ TYPE. */ | |
8705 | ||
8706 | static int | |
8707 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8708 | enum bptype type, int *other_type_used) | |
8709 | { | |
8710 | int i = 0; | |
8711 | struct breakpoint *b; | |
8712 | ||
c906108c SS |
8713 | *other_type_used = 0; |
8714 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8715 | { |
a1398e0c PA |
8716 | if (b == except) |
8717 | continue; | |
e09342b5 TJB |
8718 | if (!breakpoint_enabled (b)) |
8719 | continue; | |
8720 | ||
a1398e0c PA |
8721 | if (b->type == type) |
8722 | i += hw_watchpoint_use_count (b); | |
8723 | else if (is_hardware_watchpoint (b)) | |
8724 | *other_type_used = 1; | |
e09342b5 TJB |
8725 | } |
8726 | ||
c906108c SS |
8727 | return i; |
8728 | } | |
8729 | ||
c906108c | 8730 | void |
fba45db2 | 8731 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8732 | { |
c5aa993b | 8733 | struct breakpoint *b; |
c906108c SS |
8734 | |
8735 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8736 | { |
cc60f2e3 | 8737 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8738 | { |
b5de0fa7 | 8739 | b->enable_state = bp_call_disabled; |
44702360 | 8740 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8741 | } |
8742 | } | |
c906108c SS |
8743 | } |
8744 | ||
8745 | void | |
fba45db2 | 8746 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8747 | { |
c5aa993b | 8748 | struct breakpoint *b; |
c906108c SS |
8749 | |
8750 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8751 | { |
cc60f2e3 | 8752 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8753 | { |
b5de0fa7 | 8754 | b->enable_state = bp_enabled; |
44702360 | 8755 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8756 | } |
8757 | } | |
c906108c SS |
8758 | } |
8759 | ||
8bea4e01 UW |
8760 | void |
8761 | disable_breakpoints_before_startup (void) | |
8762 | { | |
6c95b8df | 8763 | current_program_space->executing_startup = 1; |
44702360 | 8764 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8765 | } |
8766 | ||
8767 | void | |
8768 | enable_breakpoints_after_startup (void) | |
8769 | { | |
6c95b8df | 8770 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8771 | breakpoint_re_set (); |
8bea4e01 UW |
8772 | } |
8773 | ||
7c16b83e PA |
8774 | /* Create a new single-step breakpoint for thread THREAD, with no |
8775 | locations. */ | |
c906108c | 8776 | |
7c16b83e PA |
8777 | static struct breakpoint * |
8778 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8779 | { | |
8780 | struct breakpoint *b = XNEW (struct breakpoint); | |
8781 | ||
8782 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
8783 | &momentary_breakpoint_ops); | |
8784 | ||
8785 | b->disposition = disp_donttouch; | |
8786 | b->frame_id = null_frame_id; | |
8787 | ||
8788 | b->thread = thread; | |
8789 | gdb_assert (b->thread != 0); | |
8790 | ||
8791 | add_to_breakpoint_chain (b); | |
8792 | ||
8793 | return b; | |
8794 | } | |
8795 | ||
8796 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8797 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8798 | frame. */ | |
c906108c SS |
8799 | |
8800 | struct breakpoint * | |
a6d9a66e UW |
8801 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8802 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8803 | { |
52f0bd74 | 8804 | struct breakpoint *b; |
edb3359d | 8805 | |
193facb3 JK |
8806 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8807 | tail-called one. */ | |
8808 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8809 | |
06edf0c0 | 8810 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8811 | b->enable_state = bp_enabled; |
8812 | b->disposition = disp_donttouch; | |
818dd999 | 8813 | b->frame_id = frame_id; |
c906108c | 8814 | |
4a64f543 MS |
8815 | /* If we're debugging a multi-threaded program, then we want |
8816 | momentary breakpoints to be active in only a single thread of | |
8817 | control. */ | |
39f77062 KB |
8818 | if (in_thread_list (inferior_ptid)) |
8819 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 8820 | |
44702360 | 8821 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8822 | |
c906108c SS |
8823 | return b; |
8824 | } | |
611c83ae | 8825 | |
06edf0c0 | 8826 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8827 | The new breakpoint will have type TYPE, use OPS as its |
8828 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8829 | |
06edf0c0 PA |
8830 | static struct breakpoint * |
8831 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8832 | enum bptype type, | |
a1aa2221 LM |
8833 | const struct breakpoint_ops *ops, |
8834 | int loc_enabled) | |
e58b0e63 PA |
8835 | { |
8836 | struct breakpoint *copy; | |
8837 | ||
06edf0c0 | 8838 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8839 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8840 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8841 | |
a6d9a66e | 8842 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8843 | copy->loc->requested_address = orig->loc->requested_address; |
8844 | copy->loc->address = orig->loc->address; | |
8845 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8846 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8847 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8848 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8849 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8850 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8851 | copy->frame_id = orig->frame_id; |
8852 | copy->thread = orig->thread; | |
6c95b8df | 8853 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8854 | |
8855 | copy->enable_state = bp_enabled; | |
8856 | copy->disposition = disp_donttouch; | |
8857 | copy->number = internal_breakpoint_number--; | |
8858 | ||
44702360 | 8859 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8860 | return copy; |
8861 | } | |
8862 | ||
06edf0c0 PA |
8863 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8864 | ORIG is NULL. */ | |
8865 | ||
8866 | struct breakpoint * | |
8867 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8868 | { | |
8869 | /* If there's nothing to clone, then return nothing. */ | |
8870 | if (orig == NULL) | |
8871 | return NULL; | |
8872 | ||
a1aa2221 | 8873 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8874 | } |
8875 | ||
611c83ae | 8876 | struct breakpoint * |
a6d9a66e UW |
8877 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8878 | enum bptype type) | |
611c83ae PA |
8879 | { |
8880 | struct symtab_and_line sal; | |
8881 | ||
8882 | sal = find_pc_line (pc, 0); | |
8883 | sal.pc = pc; | |
8884 | sal.section = find_pc_overlay (pc); | |
8885 | sal.explicit_pc = 1; | |
8886 | ||
a6d9a66e | 8887 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8888 | } |
c906108c | 8889 | \f |
c5aa993b | 8890 | |
c906108c SS |
8891 | /* Tell the user we have just set a breakpoint B. */ |
8892 | ||
8893 | static void | |
fba45db2 | 8894 | mention (struct breakpoint *b) |
c906108c | 8895 | { |
348d480f | 8896 | b->ops->print_mention (b); |
79a45e25 | 8897 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 8898 | return; |
c906108c SS |
8899 | printf_filtered ("\n"); |
8900 | } | |
c906108c | 8901 | \f |
c5aa993b | 8902 | |
1a853c52 PA |
8903 | static int bp_loc_is_permanent (struct bp_location *loc); |
8904 | ||
0d381245 | 8905 | static struct bp_location * |
39d61571 | 8906 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8907 | const struct symtab_and_line *sal) |
8908 | { | |
8909 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8910 | CORE_ADDR adjusted_address; |
8911 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8912 | ||
8913 | if (loc_gdbarch == NULL) | |
8914 | loc_gdbarch = b->gdbarch; | |
8915 | ||
8916 | /* Adjust the breakpoint's address prior to allocating a location. | |
8917 | Once we call allocate_bp_location(), that mostly uninitialized | |
8918 | location will be placed on the location chain. Adjustment of the | |
8919 | breakpoint may cause target_read_memory() to be called and we do | |
8920 | not want its scan of the location chain to find a breakpoint and | |
8921 | location that's only been partially initialized. */ | |
8922 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8923 | sal->pc, b->type); | |
0d381245 | 8924 | |
d30113d4 | 8925 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8926 | loc = allocate_bp_location (b); |
d30113d4 JK |
8927 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8928 | tmp = &((*tmp)->next)) | |
0d381245 | 8929 | ; |
d30113d4 | 8930 | loc->next = *tmp; |
0d381245 | 8931 | *tmp = loc; |
3742cc8b | 8932 | |
0d381245 | 8933 | loc->requested_address = sal->pc; |
3742cc8b | 8934 | loc->address = adjusted_address; |
6c95b8df | 8935 | loc->pspace = sal->pspace; |
729662a5 TT |
8936 | loc->probe.probe = sal->probe; |
8937 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 8938 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8939 | loc->section = sal->section; |
3742cc8b | 8940 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8941 | loc->line_number = sal->line; |
2f202fde | 8942 | loc->symtab = sal->symtab; |
f8eba3c6 | 8943 | |
0e30163f JK |
8944 | set_breakpoint_location_function (loc, |
8945 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 8946 | |
6ae88661 LM |
8947 | /* While by definition, permanent breakpoints are already present in the |
8948 | code, we don't mark the location as inserted. Normally one would expect | |
8949 | that GDB could rely on that breakpoint instruction to stop the program, | |
8950 | thus removing the need to insert its own breakpoint, except that executing | |
8951 | the breakpoint instruction can kill the target instead of reporting a | |
8952 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8953 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8954 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8955 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8956 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8957 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8958 | it manually increments the PC, thus avoiding executing the breakpoint | |
8959 | instruction.) */ | |
1a853c52 | 8960 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8961 | loc->permanent = 1; |
1a853c52 | 8962 | |
0d381245 VP |
8963 | return loc; |
8964 | } | |
514f746b AR |
8965 | \f |
8966 | ||
1cf4d951 | 8967 | /* See breakpoint.h. */ |
514f746b | 8968 | |
1cf4d951 PA |
8969 | int |
8970 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
8971 | { |
8972 | int len; | |
8973 | CORE_ADDR addr; | |
1afeeb75 | 8974 | const gdb_byte *bpoint; |
514f746b | 8975 | gdb_byte *target_mem; |
939c61fa JK |
8976 | struct cleanup *cleanup; |
8977 | int retval = 0; | |
514f746b | 8978 | |
1cf4d951 PA |
8979 | addr = address; |
8980 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
8981 | ||
8982 | /* Software breakpoints unsupported? */ | |
8983 | if (bpoint == NULL) | |
8984 | return 0; | |
8985 | ||
8986 | target_mem = alloca (len); | |
8987 | ||
8988 | /* Enable the automatic memory restoration from breakpoints while | |
8989 | we read the memory. Otherwise we could say about our temporary | |
8990 | breakpoints they are permanent. */ | |
8991 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
8992 | ||
8993 | if (target_read_memory (address, target_mem, len) == 0 | |
8994 | && memcmp (target_mem, bpoint, len) == 0) | |
8995 | retval = 1; | |
8996 | ||
8997 | do_cleanups (cleanup); | |
8998 | ||
8999 | return retval; | |
9000 | } | |
9001 | ||
9002 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9003 | return 0 otherwise. */ | |
9004 | ||
9005 | static int | |
9006 | bp_loc_is_permanent (struct bp_location *loc) | |
9007 | { | |
9008 | struct cleanup *cleanup; | |
9009 | int retval; | |
9010 | ||
514f746b AR |
9011 | gdb_assert (loc != NULL); |
9012 | ||
6c95b8df | 9013 | cleanup = save_current_space_and_thread (); |
6c95b8df | 9014 | switch_to_program_space_and_thread (loc->pspace); |
939c61fa | 9015 | |
1cf4d951 | 9016 | retval = program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b | 9017 | |
939c61fa JK |
9018 | do_cleanups (cleanup); |
9019 | ||
9020 | return retval; | |
514f746b AR |
9021 | } |
9022 | ||
e7e0cddf SS |
9023 | /* Build a command list for the dprintf corresponding to the current |
9024 | settings of the dprintf style options. */ | |
9025 | ||
9026 | static void | |
9027 | update_dprintf_command_list (struct breakpoint *b) | |
9028 | { | |
9029 | char *dprintf_args = b->extra_string; | |
9030 | char *printf_line = NULL; | |
9031 | ||
9032 | if (!dprintf_args) | |
9033 | return; | |
9034 | ||
9035 | dprintf_args = skip_spaces (dprintf_args); | |
9036 | ||
9037 | /* Allow a comma, as it may have terminated a location, but don't | |
9038 | insist on it. */ | |
9039 | if (*dprintf_args == ',') | |
9040 | ++dprintf_args; | |
9041 | dprintf_args = skip_spaces (dprintf_args); | |
9042 | ||
9043 | if (*dprintf_args != '"') | |
9044 | error (_("Bad format string, missing '\"'.")); | |
9045 | ||
d3ce09f5 | 9046 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9047 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9048 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9049 | { |
9050 | if (!dprintf_function) | |
9051 | error (_("No function supplied for dprintf call")); | |
9052 | ||
9053 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9054 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9055 | dprintf_function, | |
9056 | dprintf_channel, | |
9057 | dprintf_args); | |
9058 | else | |
9059 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9060 | dprintf_function, | |
9061 | dprintf_args); | |
9062 | } | |
d3ce09f5 SS |
9063 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9064 | { | |
9065 | if (target_can_run_breakpoint_commands ()) | |
9066 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9067 | else | |
9068 | { | |
9069 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9070 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9071 | } | |
9072 | } | |
e7e0cddf SS |
9073 | else |
9074 | internal_error (__FILE__, __LINE__, | |
9075 | _("Invalid dprintf style.")); | |
9076 | ||
f28045c2 | 9077 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9078 | /* Manufacture a printf sequence. */ |
f28045c2 | 9079 | { |
9d6e6e84 HZ |
9080 | struct command_line *printf_cmd_line |
9081 | = xmalloc (sizeof (struct command_line)); | |
e7e0cddf | 9082 | |
f28045c2 YQ |
9083 | printf_cmd_line->control_type = simple_control; |
9084 | printf_cmd_line->body_count = 0; | |
9085 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9086 | printf_cmd_line->next = NULL; |
f28045c2 | 9087 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9088 | |
f28045c2 YQ |
9089 | breakpoint_set_commands (b, printf_cmd_line); |
9090 | } | |
e7e0cddf SS |
9091 | } |
9092 | ||
9093 | /* Update all dprintf commands, making their command lists reflect | |
9094 | current style settings. */ | |
9095 | ||
9096 | static void | |
9097 | update_dprintf_commands (char *args, int from_tty, | |
9098 | struct cmd_list_element *c) | |
9099 | { | |
9100 | struct breakpoint *b; | |
9101 | ||
9102 | ALL_BREAKPOINTS (b) | |
9103 | { | |
9104 | if (b->type == bp_dprintf) | |
9105 | update_dprintf_command_list (b); | |
9106 | } | |
9107 | } | |
c3f6f71d | 9108 | |
f00aae0f KS |
9109 | /* Create a breakpoint with SAL as location. Use LOCATION |
9110 | as a description of the location, and COND_STRING | |
db107f19 | 9111 | as condition expression. */ |
018d34a4 VP |
9112 | |
9113 | static void | |
d9b3f62e | 9114 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
f00aae0f KS |
9115 | struct symtabs_and_lines sals, |
9116 | struct event_location *location, | |
f8eba3c6 | 9117 | char *filter, char *cond_string, |
e7e0cddf | 9118 | char *extra_string, |
d9b3f62e PA |
9119 | enum bptype type, enum bpdisp disposition, |
9120 | int thread, int task, int ignore_count, | |
c0a91b2b | 9121 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9122 | int enabled, int internal, unsigned flags, |
9123 | int display_canonical) | |
018d34a4 | 9124 | { |
0d381245 | 9125 | int i; |
018d34a4 VP |
9126 | |
9127 | if (type == bp_hardware_breakpoint) | |
9128 | { | |
fbbd034e AS |
9129 | int target_resources_ok; |
9130 | ||
9131 | i = hw_breakpoint_used_count (); | |
9132 | target_resources_ok = | |
9133 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9134 | i + 1, 0); |
9135 | if (target_resources_ok == 0) | |
9136 | error (_("No hardware breakpoint support in the target.")); | |
9137 | else if (target_resources_ok < 0) | |
9138 | error (_("Hardware breakpoints used exceeds limit.")); | |
9139 | } | |
9140 | ||
6c95b8df PA |
9141 | gdb_assert (sals.nelts > 0); |
9142 | ||
0d381245 VP |
9143 | for (i = 0; i < sals.nelts; ++i) |
9144 | { | |
9145 | struct symtab_and_line sal = sals.sals[i]; | |
9146 | struct bp_location *loc; | |
9147 | ||
9148 | if (from_tty) | |
5af949e3 UW |
9149 | { |
9150 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9151 | if (!loc_gdbarch) | |
9152 | loc_gdbarch = gdbarch; | |
9153 | ||
9154 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9155 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9156 | } |
0d381245 VP |
9157 | |
9158 | if (i == 0) | |
9159 | { | |
d9b3f62e | 9160 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9161 | b->thread = thread; |
4a306c9a | 9162 | b->task = task; |
855a6e68 | 9163 | |
0d381245 | 9164 | b->cond_string = cond_string; |
e7e0cddf | 9165 | b->extra_string = extra_string; |
0d381245 | 9166 | b->ignore_count = ignore_count; |
41447f92 | 9167 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9168 | b->disposition = disposition; |
6c95b8df | 9169 | |
44f238bb PA |
9170 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9171 | b->loc->inserted = 1; | |
9172 | ||
0fb4aa4b PA |
9173 | if (type == bp_static_tracepoint) |
9174 | { | |
d9b3f62e | 9175 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9176 | struct static_tracepoint_marker marker; |
9177 | ||
983af33b | 9178 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9179 | { |
9180 | /* We already know the marker exists, otherwise, we | |
9181 | wouldn't see a sal for it. */ | |
f00aae0f KS |
9182 | const char *p = &event_location_to_string (b->location)[3]; |
9183 | const char *endp; | |
0fb4aa4b | 9184 | char *marker_str; |
0fb4aa4b | 9185 | |
f00aae0f | 9186 | p = skip_spaces_const (p); |
0fb4aa4b | 9187 | |
f00aae0f | 9188 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9189 | |
9190 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9191 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9192 | |
3e43a32a MS |
9193 | printf_filtered (_("Probed static tracepoint " |
9194 | "marker \"%s\"\n"), | |
d9b3f62e | 9195 | t->static_trace_marker_id); |
0fb4aa4b PA |
9196 | } |
9197 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9198 | { | |
d9b3f62e | 9199 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9200 | release_static_tracepoint_marker (&marker); |
9201 | ||
3e43a32a MS |
9202 | printf_filtered (_("Probed static tracepoint " |
9203 | "marker \"%s\"\n"), | |
d9b3f62e | 9204 | t->static_trace_marker_id); |
0fb4aa4b PA |
9205 | } |
9206 | else | |
3e43a32a MS |
9207 | warning (_("Couldn't determine the static " |
9208 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9209 | } |
9210 | ||
0d381245 VP |
9211 | loc = b->loc; |
9212 | } | |
9213 | else | |
018d34a4 | 9214 | { |
39d61571 | 9215 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9216 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9217 | loc->inserted = 1; | |
0d381245 VP |
9218 | } |
9219 | ||
9220 | if (b->cond_string) | |
9221 | { | |
bbc13ae3 KS |
9222 | const char *arg = b->cond_string; |
9223 | ||
1bb9788d TT |
9224 | loc->cond = parse_exp_1 (&arg, loc->address, |
9225 | block_for_pc (loc->address), 0); | |
0d381245 | 9226 | if (*arg) |
588ae58c | 9227 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9228 | } |
e7e0cddf SS |
9229 | |
9230 | /* Dynamic printf requires and uses additional arguments on the | |
9231 | command line, otherwise it's an error. */ | |
9232 | if (type == bp_dprintf) | |
9233 | { | |
9234 | if (b->extra_string) | |
9235 | update_dprintf_command_list (b); | |
9236 | else | |
9237 | error (_("Format string required")); | |
9238 | } | |
9239 | else if (b->extra_string) | |
588ae58c | 9240 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9241 | } |
018d34a4 | 9242 | |
56435ebe | 9243 | b->display_canonical = display_canonical; |
f00aae0f KS |
9244 | if (location != NULL) |
9245 | b->location = location; | |
018d34a4 | 9246 | else |
f00aae0f KS |
9247 | { |
9248 | char *tmp; | |
9249 | struct cleanup *cleanup; | |
9250 | ||
9251 | tmp = xstrprintf ("*%s", | |
9252 | paddress (b->loc->gdbarch, b->loc->address)); | |
9253 | cleanup = make_cleanup (xfree, tmp); | |
9254 | b->location = new_linespec_location (&tmp); | |
9255 | do_cleanups (cleanup); | |
9256 | } | |
f8eba3c6 | 9257 | b->filter = filter; |
d9b3f62e | 9258 | } |
018d34a4 | 9259 | |
d9b3f62e PA |
9260 | static void |
9261 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
f00aae0f KS |
9262 | struct symtabs_and_lines sals, |
9263 | struct event_location *location, | |
f8eba3c6 | 9264 | char *filter, char *cond_string, |
e7e0cddf | 9265 | char *extra_string, |
d9b3f62e PA |
9266 | enum bptype type, enum bpdisp disposition, |
9267 | int thread, int task, int ignore_count, | |
c0a91b2b | 9268 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9269 | int enabled, int internal, unsigned flags, |
9270 | int display_canonical) | |
d9b3f62e PA |
9271 | { |
9272 | struct breakpoint *b; | |
9273 | struct cleanup *old_chain; | |
9274 | ||
9275 | if (is_tracepoint_type (type)) | |
9276 | { | |
9277 | struct tracepoint *t; | |
9278 | ||
9279 | t = XCNEW (struct tracepoint); | |
9280 | b = &t->base; | |
9281 | } | |
9282 | else | |
9283 | b = XNEW (struct breakpoint); | |
9284 | ||
9285 | old_chain = make_cleanup (xfree, b); | |
9286 | ||
9287 | init_breakpoint_sal (b, gdbarch, | |
f00aae0f | 9288 | sals, location, |
e7e0cddf | 9289 | filter, cond_string, extra_string, |
d9b3f62e PA |
9290 | type, disposition, |
9291 | thread, task, ignore_count, | |
9292 | ops, from_tty, | |
44f238bb PA |
9293 | enabled, internal, flags, |
9294 | display_canonical); | |
d9b3f62e PA |
9295 | discard_cleanups (old_chain); |
9296 | ||
3ea46bff | 9297 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9298 | } |
9299 | ||
9300 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9301 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9302 | value. COND_STRING, if not NULL, specified the condition to be | |
9303 | used for all breakpoints. Essentially the only case where | |
9304 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9305 | function. In that case, it's still not possible to specify | |
9306 | separate conditions for different overloaded functions, so | |
9307 | we take just a single condition string. | |
9308 | ||
c3f6f71d | 9309 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9310 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9311 | array contents). If the function fails (error() is called), the |
9312 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9313 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9314 | |
9315 | static void | |
8cdf0e15 | 9316 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9317 | struct linespec_result *canonical, |
e7e0cddf | 9318 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9319 | enum bptype type, enum bpdisp disposition, |
9320 | int thread, int task, int ignore_count, | |
c0a91b2b | 9321 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9322 | int enabled, int internal, unsigned flags) |
c906108c | 9323 | { |
018d34a4 | 9324 | int i; |
f8eba3c6 | 9325 | struct linespec_sals *lsal; |
cc59ec59 | 9326 | |
f8eba3c6 TT |
9327 | if (canonical->pre_expanded) |
9328 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9329 | ||
9330 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9331 | { |
f00aae0f | 9332 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9333 | 'break', without arguments. */ |
f00aae0f KS |
9334 | struct event_location *location |
9335 | = (canonical->location != NULL | |
9336 | ? copy_event_location (canonical->location) : NULL); | |
f8eba3c6 | 9337 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; |
f00aae0f | 9338 | struct cleanup *inner = make_cleanup_delete_event_location (location); |
0d381245 | 9339 | |
f8eba3c6 TT |
9340 | make_cleanup (xfree, filter_string); |
9341 | create_breakpoint_sal (gdbarch, lsal->sals, | |
f00aae0f | 9342 | location, |
f8eba3c6 | 9343 | filter_string, |
e7e0cddf SS |
9344 | cond_string, extra_string, |
9345 | type, disposition, | |
84f4c1fe | 9346 | thread, task, ignore_count, ops, |
44f238bb | 9347 | from_tty, enabled, internal, flags, |
56435ebe | 9348 | canonical->special_display); |
f8eba3c6 | 9349 | discard_cleanups (inner); |
c3f6f71d | 9350 | } |
c3f6f71d | 9351 | } |
c906108c | 9352 | |
f00aae0f | 9353 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9354 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9355 | addresses found. LOCATION points to the end of the SAL (for |
9356 | linespec locations). | |
9998af43 TJB |
9357 | |
9358 | The array and the line spec strings are allocated on the heap, it is | |
9359 | the caller's responsibility to free them. */ | |
c906108c | 9360 | |
b9362cc7 | 9361 | static void |
f00aae0f | 9362 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9363 | struct linespec_result *canonical) |
c3f6f71d | 9364 | { |
f00aae0f KS |
9365 | struct symtab_and_line cursal; |
9366 | ||
9367 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9368 | { | |
9369 | const char *address = get_linespec_location (location); | |
9370 | ||
9371 | if (address == NULL) | |
9372 | { | |
9373 | /* The last displayed codepoint, if it's valid, is our default | |
9374 | breakpoint address. */ | |
9375 | if (last_displayed_sal_is_valid ()) | |
9376 | { | |
9377 | struct linespec_sals lsal; | |
9378 | struct symtab_and_line sal; | |
9379 | CORE_ADDR pc; | |
9380 | ||
9381 | init_sal (&sal); /* Initialize to zeroes. */ | |
9382 | lsal.sals.sals = (struct symtab_and_line *) | |
9383 | xmalloc (sizeof (struct symtab_and_line)); | |
9384 | ||
9385 | /* Set sal's pspace, pc, symtab, and line to the values | |
9386 | corresponding to the last call to print_frame_info. | |
9387 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9388 | as the breakpoint line number is inappropriate otherwise. | |
9389 | find_pc_line would adjust PC, re-set it back. */ | |
9390 | get_last_displayed_sal (&sal); | |
9391 | pc = sal.pc; | |
9392 | sal = find_pc_line (pc, 0); | |
9393 | ||
9394 | /* "break" without arguments is equivalent to "break *PC" | |
9395 | where PC is the last displayed codepoint's address. So | |
9396 | make sure to set sal.explicit_pc to prevent GDB from | |
9397 | trying to expand the list of sals to include all other | |
9398 | instances with the same symtab and line. */ | |
9399 | sal.pc = pc; | |
9400 | sal.explicit_pc = 1; | |
9401 | ||
9402 | lsal.sals.sals[0] = sal; | |
9403 | lsal.sals.nelts = 1; | |
9404 | lsal.canonical = NULL; | |
9405 | ||
9406 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
9407 | return; | |
9408 | } | |
9409 | else | |
9410 | error (_("No default breakpoint address now.")); | |
c906108c | 9411 | } |
c906108c | 9412 | } |
f00aae0f KS |
9413 | |
9414 | /* Force almost all breakpoints to be in terms of the | |
9415 | current_source_symtab (which is decode_line_1's default). | |
9416 | This should produce the results we want almost all of the | |
9417 | time while leaving default_breakpoint_* alone. | |
9418 | ||
9419 | ObjC: However, don't match an Objective-C method name which | |
9420 | may have a '+' or '-' succeeded by a '['. */ | |
9421 | cursal = get_current_source_symtab_and_line (); | |
9422 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9423 | { |
f00aae0f | 9424 | const char *address = NULL; |
cc80f267 | 9425 | |
f00aae0f KS |
9426 | if (event_location_type (location) == LINESPEC_LOCATION) |
9427 | address = get_linespec_location (location); | |
cc80f267 | 9428 | |
f00aae0f KS |
9429 | if (!cursal.symtab |
9430 | || (address != NULL | |
9431 | && strchr ("+-", address[0]) != NULL | |
9432 | && address[1] != '[')) | |
9433 | { | |
9434 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, | |
9435 | get_last_displayed_symtab (), | |
9436 | get_last_displayed_line (), | |
9437 | canonical, NULL, NULL); | |
9438 | return; | |
9439 | } | |
c906108c | 9440 | } |
f00aae0f KS |
9441 | |
9442 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, | |
9443 | cursal.symtab, cursal.line, canonical, NULL, NULL); | |
c3f6f71d | 9444 | } |
c906108c | 9445 | |
c906108c | 9446 | |
c3f6f71d | 9447 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9448 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9449 | |
b9362cc7 | 9450 | static void |
23e7acfb | 9451 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9452 | { |
9453 | int i; | |
cc59ec59 | 9454 | |
c3f6f71d | 9455 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9456 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9457 | } |
9458 | ||
7a697b8d SS |
9459 | /* Fast tracepoints may have restrictions on valid locations. For |
9460 | instance, a fast tracepoint using a jump instead of a trap will | |
9461 | likely have to overwrite more bytes than a trap would, and so can | |
9462 | only be placed where the instruction is longer than the jump, or a | |
9463 | multi-instruction sequence does not have a jump into the middle of | |
9464 | it, etc. */ | |
9465 | ||
9466 | static void | |
9467 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9468 | struct symtabs_and_lines *sals) | |
9469 | { | |
9470 | int i, rslt; | |
9471 | struct symtab_and_line *sal; | |
9472 | char *msg; | |
9473 | struct cleanup *old_chain; | |
9474 | ||
9475 | for (i = 0; i < sals->nelts; i++) | |
9476 | { | |
f8eba3c6 TT |
9477 | struct gdbarch *sarch; |
9478 | ||
7a697b8d SS |
9479 | sal = &sals->sals[i]; |
9480 | ||
f8eba3c6 TT |
9481 | sarch = get_sal_arch (*sal); |
9482 | /* We fall back to GDBARCH if there is no architecture | |
9483 | associated with SAL. */ | |
9484 | if (sarch == NULL) | |
9485 | sarch = gdbarch; | |
6b940e6a | 9486 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg); |
7a697b8d SS |
9487 | old_chain = make_cleanup (xfree, msg); |
9488 | ||
9489 | if (!rslt) | |
9490 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9491 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9492 | |
9493 | do_cleanups (old_chain); | |
9494 | } | |
9495 | } | |
9496 | ||
af4908ba KS |
9497 | /* Issue an invalid thread ID error. */ |
9498 | ||
9499 | static void ATTRIBUTE_NORETURN | |
9500 | invalid_thread_id_error (int id) | |
9501 | { | |
9502 | error (_("Unknown thread %d."), id); | |
9503 | } | |
9504 | ||
018d34a4 VP |
9505 | /* Given TOK, a string specification of condition and thread, as |
9506 | accepted by the 'break' command, extract the condition | |
9507 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9508 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9509 | If no condition is found, *COND_STRING is set to NULL. |
9510 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9511 | |
9512 | static void | |
bbc13ae3 | 9513 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9514 | char **cond_string, int *thread, int *task, |
9515 | char **rest) | |
018d34a4 VP |
9516 | { |
9517 | *cond_string = NULL; | |
9518 | *thread = -1; | |
ed1d1739 KS |
9519 | *task = 0; |
9520 | *rest = NULL; | |
9521 | ||
018d34a4 VP |
9522 | while (tok && *tok) |
9523 | { | |
bbc13ae3 | 9524 | const char *end_tok; |
018d34a4 | 9525 | int toklen; |
bbc13ae3 KS |
9526 | const char *cond_start = NULL; |
9527 | const char *cond_end = NULL; | |
cc59ec59 | 9528 | |
bbc13ae3 | 9529 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9530 | |
9531 | if ((*tok == '"' || *tok == ',') && rest) | |
9532 | { | |
9533 | *rest = savestring (tok, strlen (tok)); | |
9534 | return; | |
9535 | } | |
9536 | ||
bbc13ae3 | 9537 | end_tok = skip_to_space_const (tok); |
d634f2de | 9538 | |
018d34a4 | 9539 | toklen = end_tok - tok; |
d634f2de | 9540 | |
018d34a4 VP |
9541 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9542 | { | |
f7545552 TT |
9543 | struct expression *expr; |
9544 | ||
018d34a4 | 9545 | tok = cond_start = end_tok + 1; |
1bb9788d | 9546 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9547 | xfree (expr); |
018d34a4 | 9548 | cond_end = tok; |
d634f2de | 9549 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9550 | } |
9551 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9552 | { | |
9553 | char *tmptok; | |
d634f2de | 9554 | |
018d34a4 | 9555 | tok = end_tok + 1; |
bbc13ae3 | 9556 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9557 | if (tok == tmptok) |
9558 | error (_("Junk after thread keyword.")); | |
9559 | if (!valid_thread_id (*thread)) | |
af4908ba | 9560 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9561 | tok = tmptok; |
018d34a4 | 9562 | } |
4a306c9a JB |
9563 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9564 | { | |
9565 | char *tmptok; | |
9566 | ||
9567 | tok = end_tok + 1; | |
bbc13ae3 | 9568 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9569 | if (tok == tmptok) |
9570 | error (_("Junk after task keyword.")); | |
9571 | if (!valid_task_id (*task)) | |
b6199126 | 9572 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9573 | tok = tmptok; |
4a306c9a | 9574 | } |
e7e0cddf SS |
9575 | else if (rest) |
9576 | { | |
9577 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9578 | return; |
e7e0cddf | 9579 | } |
018d34a4 VP |
9580 | else |
9581 | error (_("Junk at end of arguments.")); | |
9582 | } | |
9583 | } | |
9584 | ||
0fb4aa4b PA |
9585 | /* Decode a static tracepoint marker spec. */ |
9586 | ||
9587 | static struct symtabs_and_lines | |
f00aae0f | 9588 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9589 | { |
9590 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9591 | struct symtabs_and_lines sals; | |
0fb4aa4b | 9592 | struct cleanup *old_chain; |
f00aae0f KS |
9593 | const char *p = &(*arg_p)[3]; |
9594 | const char *endp; | |
0fb4aa4b PA |
9595 | char *marker_str; |
9596 | int i; | |
9597 | ||
f00aae0f | 9598 | p = skip_spaces_const (p); |
0fb4aa4b | 9599 | |
f00aae0f | 9600 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9601 | |
9602 | marker_str = savestring (p, endp - p); | |
9603 | old_chain = make_cleanup (xfree, marker_str); | |
9604 | ||
9605 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9606 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9607 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9608 | ||
9609 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
9610 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
9611 | ||
9612 | for (i = 0; i < sals.nelts; i++) | |
9613 | { | |
9614 | struct static_tracepoint_marker *marker; | |
9615 | ||
9616 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9617 | ||
9618 | init_sal (&sals.sals[i]); | |
9619 | ||
9620 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9621 | sals.sals[i].pc = marker->address; | |
9622 | ||
9623 | release_static_tracepoint_marker (marker); | |
9624 | } | |
9625 | ||
9626 | do_cleanups (old_chain); | |
9627 | ||
9628 | *arg_p = endp; | |
9629 | return sals; | |
9630 | } | |
9631 | ||
f00aae0f | 9632 | /* See breakpoint.h. */ |
0101ce28 | 9633 | |
8cdf0e15 VP |
9634 | int |
9635 | create_breakpoint (struct gdbarch *gdbarch, | |
f00aae0f | 9636 | const struct event_location *location, char *cond_string, |
e7e0cddf | 9637 | int thread, char *extra_string, |
f00aae0f | 9638 | int parse_extra, |
0fb4aa4b | 9639 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9640 | int ignore_count, |
9641 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9642 | const struct breakpoint_ops *ops, |
44f238bb PA |
9643 | int from_tty, int enabled, int internal, |
9644 | unsigned flags) | |
c3f6f71d | 9645 | { |
7efd8fc2 | 9646 | struct linespec_result canonical; |
c3f6f71d | 9647 | struct cleanup *old_chain; |
80c99de1 | 9648 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9649 | int pending = 0; |
4a306c9a | 9650 | int task = 0; |
86b17b60 | 9651 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9652 | |
348d480f PA |
9653 | gdb_assert (ops != NULL); |
9654 | ||
f00aae0f KS |
9655 | /* If extra_string isn't useful, set it to NULL. */ |
9656 | if (extra_string != NULL && *extra_string == '\0') | |
9657 | extra_string = NULL; | |
9658 | ||
7efd8fc2 | 9659 | init_linespec_result (&canonical); |
c3f6f71d | 9660 | |
492d29ea | 9661 | TRY |
b78a6381 | 9662 | { |
f00aae0f | 9663 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9664 | } |
492d29ea | 9665 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9666 | { |
492d29ea PA |
9667 | /* If caller is interested in rc value from parse, set |
9668 | value. */ | |
9669 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9670 | { |
05ff989b AC |
9671 | /* If pending breakpoint support is turned off, throw |
9672 | error. */ | |
fa8d40ab JJ |
9673 | |
9674 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9675 | throw_exception (e); |
9676 | ||
9677 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9678 | |
05ff989b AC |
9679 | /* If pending breakpoint support is auto query and the user |
9680 | selects no, then simply return the error code. */ | |
059fb39f | 9681 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9682 | && !nquery (_("Make %s pending on future shared library load? "), |
9683 | bptype_string (type_wanted))) | |
fd9b8c24 | 9684 | return 0; |
fa8d40ab | 9685 | |
05ff989b AC |
9686 | /* At this point, either the user was queried about setting |
9687 | a pending breakpoint and selected yes, or pending | |
9688 | breakpoint behavior is on and thus a pending breakpoint | |
9689 | is defaulted on behalf of the user. */ | |
f00aae0f | 9690 | pending = 1; |
0101ce28 | 9691 | } |
492d29ea PA |
9692 | else |
9693 | throw_exception (e); | |
0101ce28 | 9694 | } |
492d29ea PA |
9695 | END_CATCH |
9696 | ||
f00aae0f | 9697 | if (!pending && VEC_empty (linespec_sals, canonical.sals)) |
492d29ea | 9698 | return 0; |
c3f6f71d | 9699 | |
4a64f543 | 9700 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9701 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9702 | |
c3f6f71d JM |
9703 | /* ----------------------------- SNIP ----------------------------- |
9704 | Anything added to the cleanup chain beyond this point is assumed | |
9705 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9706 | then the memory is not reclaimed. */ |
9707 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9708 | |
c3f6f71d JM |
9709 | /* Resolve all line numbers to PC's and verify that the addresses |
9710 | are ok for the target. */ | |
0101ce28 | 9711 | if (!pending) |
f8eba3c6 TT |
9712 | { |
9713 | int ix; | |
9714 | struct linespec_sals *iter; | |
9715 | ||
9716 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9717 | breakpoint_sals_to_pc (&iter->sals); | |
9718 | } | |
c3f6f71d | 9719 | |
7a697b8d | 9720 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9721 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9722 | { |
9723 | int ix; | |
9724 | struct linespec_sals *iter; | |
9725 | ||
9726 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9727 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9728 | } | |
7a697b8d | 9729 | |
c3f6f71d JM |
9730 | /* Verify that condition can be parsed, before setting any |
9731 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9732 | breakpoint. */ |
0101ce28 | 9733 | if (!pending) |
c3f6f71d | 9734 | { |
f00aae0f | 9735 | if (parse_extra) |
72b2ff0e | 9736 | { |
0878d0fa | 9737 | char *rest; |
52d361e1 YQ |
9738 | struct linespec_sals *lsal; |
9739 | ||
9740 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9741 | ||
0878d0fa YQ |
9742 | /* Here we only parse 'arg' to separate condition |
9743 | from thread number, so parsing in context of first | |
9744 | sal is OK. When setting the breakpoint we'll | |
9745 | re-parse it in context of each sal. */ | |
9746 | ||
f00aae0f KS |
9747 | find_condition_and_thread (extra_string, lsal->sals.sals[0].pc, |
9748 | &cond_string, &thread, &task, &rest); | |
0878d0fa YQ |
9749 | if (cond_string) |
9750 | make_cleanup (xfree, cond_string); | |
9751 | if (rest) | |
9752 | make_cleanup (xfree, rest); | |
9753 | if (rest) | |
9754 | extra_string = rest; | |
f00aae0f KS |
9755 | else |
9756 | extra_string = NULL; | |
72b2ff0e | 9757 | } |
2f069f6f | 9758 | else |
72b2ff0e | 9759 | { |
f00aae0f KS |
9760 | if (type_wanted != bp_dprintf |
9761 | && extra_string != NULL && *extra_string != '\0') | |
9762 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9763 | |
9764 | /* Create a private copy of condition string. */ | |
9765 | if (cond_string) | |
9766 | { | |
9767 | cond_string = xstrdup (cond_string); | |
9768 | make_cleanup (xfree, cond_string); | |
9769 | } | |
9770 | /* Create a private copy of any extra string. */ | |
9771 | if (extra_string) | |
9772 | { | |
9773 | extra_string = xstrdup (extra_string); | |
9774 | make_cleanup (xfree, extra_string); | |
9775 | } | |
72b2ff0e | 9776 | } |
0fb4aa4b | 9777 | |
52d361e1 | 9778 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9779 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9780 | tempflag ? disp_del : disp_donttouch, |
9781 | thread, task, ignore_count, ops, | |
44f238bb | 9782 | from_tty, enabled, internal, flags); |
c906108c | 9783 | } |
0101ce28 JJ |
9784 | else |
9785 | { | |
0101ce28 JJ |
9786 | struct breakpoint *b; |
9787 | ||
bfccc43c YQ |
9788 | if (is_tracepoint_type (type_wanted)) |
9789 | { | |
9790 | struct tracepoint *t; | |
9791 | ||
9792 | t = XCNEW (struct tracepoint); | |
9793 | b = &t->base; | |
9794 | } | |
9795 | else | |
9796 | b = XNEW (struct breakpoint); | |
9797 | ||
9798 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
f00aae0f | 9799 | b->location = copy_event_location (location); |
bfccc43c | 9800 | |
f00aae0f KS |
9801 | if (parse_extra) |
9802 | b->cond_string = NULL; | |
e12c7713 MK |
9803 | else |
9804 | { | |
9805 | /* Create a private copy of condition string. */ | |
9806 | if (cond_string) | |
9807 | { | |
9808 | cond_string = xstrdup (cond_string); | |
9809 | make_cleanup (xfree, cond_string); | |
9810 | } | |
9811 | b->cond_string = cond_string; | |
15630549 | 9812 | b->thread = thread; |
e12c7713 | 9813 | } |
f00aae0f KS |
9814 | |
9815 | /* Create a private copy of any extra string. */ | |
9816 | if (extra_string != NULL) | |
9817 | { | |
9818 | extra_string = xstrdup (extra_string); | |
9819 | make_cleanup (xfree, extra_string); | |
9820 | } | |
9821 | b->extra_string = extra_string; | |
0101ce28 | 9822 | b->ignore_count = ignore_count; |
0101ce28 | 9823 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9824 | b->condition_not_parsed = 1; |
41447f92 | 9825 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9826 | if ((type_wanted != bp_breakpoint |
9827 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9828 | b->pspace = current_program_space; |
8bea4e01 | 9829 | |
bfccc43c | 9830 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9831 | } |
9832 | ||
f8eba3c6 | 9833 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9834 | { |
3e43a32a MS |
9835 | warning (_("Multiple breakpoints were set.\nUse the " |
9836 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9837 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9838 | } |
9839 | ||
80c99de1 PA |
9840 | /* That's it. Discard the cleanups for data inserted into the |
9841 | breakpoint. */ | |
9842 | discard_cleanups (bkpt_chain); | |
9843 | /* But cleanup everything else. */ | |
c3f6f71d | 9844 | do_cleanups (old_chain); |
217dc9e2 | 9845 | |
80c99de1 | 9846 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9847 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9848 | |
9849 | return 1; | |
c3f6f71d | 9850 | } |
c906108c | 9851 | |
348d480f | 9852 | /* Set a breakpoint. |
72b2ff0e VP |
9853 | ARG is a string describing breakpoint address, |
9854 | condition, and thread. | |
9855 | FLAG specifies if a breakpoint is hardware on, | |
9856 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9857 | and BP_TEMPFLAG. */ | |
348d480f | 9858 | |
98deb0da | 9859 | static void |
72b2ff0e | 9860 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9861 | { |
72b2ff0e | 9862 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9863 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9864 | ? bp_hardware_breakpoint | |
9865 | : bp_breakpoint); | |
55aa24fb SDJ |
9866 | struct breakpoint_ops *ops; |
9867 | const char *arg_cp = arg; | |
f00aae0f KS |
9868 | struct event_location *location; |
9869 | struct cleanup *cleanup; | |
9870 | ||
9871 | location = string_to_event_location (&arg, current_language); | |
9872 | cleanup = make_cleanup_delete_event_location (location); | |
55aa24fb SDJ |
9873 | |
9874 | /* Matching breakpoints on probes. */ | |
f00aae0f | 9875 | if (arg_cp != NULL && probe_linespec_to_ops (&arg_cp) != NULL) |
55aa24fb SDJ |
9876 | ops = &bkpt_probe_breakpoint_ops; |
9877 | else | |
9878 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9879 | |
8cdf0e15 | 9880 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
9881 | location, |
9882 | NULL, 0, arg, 1 /* parse arg */, | |
0fb4aa4b | 9883 | tempflag, type_wanted, |
8cdf0e15 VP |
9884 | 0 /* Ignore count */, |
9885 | pending_break_support, | |
55aa24fb | 9886 | ops, |
8cdf0e15 | 9887 | from_tty, |
84f4c1fe | 9888 | 1 /* enabled */, |
44f238bb PA |
9889 | 0 /* internal */, |
9890 | 0); | |
f00aae0f | 9891 | do_cleanups (cleanup); |
c906108c SS |
9892 | } |
9893 | ||
c906108c SS |
9894 | /* Helper function for break_command_1 and disassemble_command. */ |
9895 | ||
9896 | void | |
fba45db2 | 9897 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9898 | { |
9899 | CORE_ADDR pc; | |
9900 | ||
9901 | if (sal->pc == 0 && sal->symtab != NULL) | |
9902 | { | |
9903 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9904 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9905 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9906 | sal->pc = pc; |
6a048695 | 9907 | |
4a64f543 MS |
9908 | /* If this SAL corresponds to a breakpoint inserted using a line |
9909 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9910 | if (sal->explicit_line) |
059acae7 | 9911 | skip_prologue_sal (sal); |
c906108c SS |
9912 | } |
9913 | ||
9914 | if (sal->section == 0 && sal->symtab != NULL) | |
9915 | { | |
346d1dfe | 9916 | const struct blockvector *bv; |
3977b71f | 9917 | const struct block *b; |
c5aa993b | 9918 | struct symbol *sym; |
c906108c | 9919 | |
43f3e411 DE |
9920 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9921 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9922 | if (bv != NULL) |
9923 | { | |
7f0df278 | 9924 | sym = block_linkage_function (b); |
c906108c SS |
9925 | if (sym != NULL) |
9926 | { | |
eb822aa6 DE |
9927 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9928 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9929 | sym); | |
c906108c SS |
9930 | } |
9931 | else | |
9932 | { | |
4a64f543 MS |
9933 | /* It really is worthwhile to have the section, so we'll |
9934 | just have to look harder. This case can be executed | |
9935 | if we have line numbers but no functions (as can | |
9936 | happen in assembly source). */ | |
c906108c | 9937 | |
7cbd4a93 | 9938 | struct bound_minimal_symbol msym; |
6c95b8df PA |
9939 | struct cleanup *old_chain = save_current_space_and_thread (); |
9940 | ||
9941 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
9942 | |
9943 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 9944 | if (msym.minsym) |
efd66ac6 | 9945 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
9946 | |
9947 | do_cleanups (old_chain); | |
c906108c SS |
9948 | } |
9949 | } | |
9950 | } | |
9951 | } | |
9952 | ||
9953 | void | |
fba45db2 | 9954 | break_command (char *arg, int from_tty) |
c906108c | 9955 | { |
db107f19 | 9956 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9957 | } |
9958 | ||
c906108c | 9959 | void |
fba45db2 | 9960 | tbreak_command (char *arg, int from_tty) |
c906108c | 9961 | { |
db107f19 | 9962 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9963 | } |
9964 | ||
c906108c | 9965 | static void |
fba45db2 | 9966 | hbreak_command (char *arg, int from_tty) |
c906108c | 9967 | { |
db107f19 | 9968 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9969 | } |
9970 | ||
9971 | static void | |
fba45db2 | 9972 | thbreak_command (char *arg, int from_tty) |
c906108c | 9973 | { |
db107f19 | 9974 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9975 | } |
9976 | ||
9977 | static void | |
fba45db2 | 9978 | stop_command (char *arg, int from_tty) |
c906108c | 9979 | { |
a3f17187 | 9980 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9981 | Usage: stop in <function | address>\n\ |
a3f17187 | 9982 | stop at <line>\n")); |
c906108c SS |
9983 | } |
9984 | ||
9985 | static void | |
fba45db2 | 9986 | stopin_command (char *arg, int from_tty) |
c906108c SS |
9987 | { |
9988 | int badInput = 0; | |
9989 | ||
c5aa993b | 9990 | if (arg == (char *) NULL) |
c906108c SS |
9991 | badInput = 1; |
9992 | else if (*arg != '*') | |
9993 | { | |
9994 | char *argptr = arg; | |
9995 | int hasColon = 0; | |
9996 | ||
4a64f543 | 9997 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9998 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9999 | function/method name. */ |
c906108c | 10000 | while (*argptr && !hasColon) |
c5aa993b JM |
10001 | { |
10002 | hasColon = (*argptr == ':'); | |
10003 | argptr++; | |
10004 | } | |
c906108c SS |
10005 | |
10006 | if (hasColon) | |
c5aa993b | 10007 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10008 | else |
c5aa993b | 10009 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10010 | } |
10011 | ||
10012 | if (badInput) | |
a3f17187 | 10013 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10014 | else |
db107f19 | 10015 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10016 | } |
10017 | ||
10018 | static void | |
fba45db2 | 10019 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10020 | { |
10021 | int badInput = 0; | |
10022 | ||
c5aa993b | 10023 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10024 | badInput = 1; |
10025 | else | |
10026 | { | |
10027 | char *argptr = arg; | |
10028 | int hasColon = 0; | |
10029 | ||
4a64f543 MS |
10030 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10031 | it is probably a line number. */ | |
c906108c | 10032 | while (*argptr && !hasColon) |
c5aa993b JM |
10033 | { |
10034 | hasColon = (*argptr == ':'); | |
10035 | argptr++; | |
10036 | } | |
c906108c SS |
10037 | |
10038 | if (hasColon) | |
c5aa993b | 10039 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10040 | else |
c5aa993b | 10041 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10042 | } |
10043 | ||
10044 | if (badInput) | |
a3f17187 | 10045 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10046 | else |
db107f19 | 10047 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10048 | } |
10049 | ||
e7e0cddf SS |
10050 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10051 | with a prewired command list consisting of a single output command, | |
10052 | built from extra arguments supplied on the dprintf command | |
10053 | line. */ | |
10054 | ||
da821c7b | 10055 | static void |
e7e0cddf SS |
10056 | dprintf_command (char *arg, int from_tty) |
10057 | { | |
f00aae0f KS |
10058 | struct event_location *location; |
10059 | struct cleanup *cleanup; | |
10060 | ||
10061 | location = string_to_event_location (&arg, current_language); | |
10062 | cleanup = make_cleanup_delete_event_location (location); | |
10063 | ||
10064 | /* If non-NULL, ARG should have been advanced past the location; | |
10065 | the next character must be ','. */ | |
10066 | if (arg != NULL) | |
10067 | { | |
10068 | if (arg[0] != ',' || arg[1] == '\0') | |
10069 | error (_("Format string required")); | |
10070 | else | |
10071 | { | |
10072 | /* Skip the comma. */ | |
10073 | ++arg; | |
10074 | } | |
10075 | } | |
10076 | ||
e7e0cddf | 10077 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10078 | location, |
10079 | NULL, 0, arg, 1 /* parse arg */, | |
e7e0cddf SS |
10080 | 0, bp_dprintf, |
10081 | 0 /* Ignore count */, | |
10082 | pending_break_support, | |
10083 | &dprintf_breakpoint_ops, | |
10084 | from_tty, | |
10085 | 1 /* enabled */, | |
10086 | 0 /* internal */, | |
10087 | 0); | |
f00aae0f | 10088 | do_cleanups (cleanup); |
e7e0cddf SS |
10089 | } |
10090 | ||
d3ce09f5 SS |
10091 | static void |
10092 | agent_printf_command (char *arg, int from_tty) | |
10093 | { | |
10094 | error (_("May only run agent-printf on the target")); | |
10095 | } | |
10096 | ||
f1310107 TJB |
10097 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10098 | ranged breakpoints. */ | |
10099 | ||
10100 | static int | |
10101 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10102 | struct address_space *aspace, | |
09ac7c10 TT |
10103 | CORE_ADDR bp_addr, |
10104 | const struct target_waitstatus *ws) | |
f1310107 | 10105 | { |
09ac7c10 | 10106 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10107 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10108 | return 0; |
10109 | ||
f1310107 TJB |
10110 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10111 | bl->length, aspace, bp_addr); | |
10112 | } | |
10113 | ||
10114 | /* Implement the "resources_needed" breakpoint_ops method for | |
10115 | ranged breakpoints. */ | |
10116 | ||
10117 | static int | |
10118 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10119 | { | |
10120 | return target_ranged_break_num_registers (); | |
10121 | } | |
10122 | ||
10123 | /* Implement the "print_it" breakpoint_ops method for | |
10124 | ranged breakpoints. */ | |
10125 | ||
10126 | static enum print_stop_action | |
348d480f | 10127 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10128 | { |
348d480f | 10129 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10130 | struct bp_location *bl = b->loc; |
79a45e25 | 10131 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10132 | |
10133 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10134 | ||
10135 | /* Ranged breakpoints have only one location. */ | |
10136 | gdb_assert (bl && bl->next == NULL); | |
10137 | ||
10138 | annotate_breakpoint (b->number); | |
10139 | if (b->disposition == disp_del) | |
10140 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10141 | else | |
10142 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10143 | if (ui_out_is_mi_like_p (uiout)) | |
10144 | { | |
10145 | ui_out_field_string (uiout, "reason", | |
10146 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10147 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10148 | } | |
10149 | ui_out_field_int (uiout, "bkptno", b->number); | |
10150 | ui_out_text (uiout, ", "); | |
10151 | ||
10152 | return PRINT_SRC_AND_LOC; | |
10153 | } | |
10154 | ||
10155 | /* Implement the "print_one" breakpoint_ops method for | |
10156 | ranged breakpoints. */ | |
10157 | ||
10158 | static void | |
10159 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10160 | struct bp_location **last_loc) | |
10161 | { | |
10162 | struct bp_location *bl = b->loc; | |
10163 | struct value_print_options opts; | |
79a45e25 | 10164 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10165 | |
10166 | /* Ranged breakpoints have only one location. */ | |
10167 | gdb_assert (bl && bl->next == NULL); | |
10168 | ||
10169 | get_user_print_options (&opts); | |
10170 | ||
10171 | if (opts.addressprint) | |
10172 | /* We don't print the address range here, it will be printed later | |
10173 | by print_one_detail_ranged_breakpoint. */ | |
10174 | ui_out_field_skip (uiout, "addr"); | |
10175 | annotate_field (5); | |
10176 | print_breakpoint_location (b, bl); | |
10177 | *last_loc = bl; | |
10178 | } | |
10179 | ||
10180 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10181 | ranged breakpoints. */ | |
10182 | ||
10183 | static void | |
10184 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10185 | struct ui_out *uiout) | |
10186 | { | |
10187 | CORE_ADDR address_start, address_end; | |
10188 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10189 | struct ui_file *stb = mem_fileopen (); |
10190 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10191 | |
10192 | gdb_assert (bl); | |
10193 | ||
10194 | address_start = bl->address; | |
10195 | address_end = address_start + bl->length - 1; | |
10196 | ||
10197 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10198 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10199 | print_core_address (bl->gdbarch, address_start), |
10200 | print_core_address (bl->gdbarch, address_end)); | |
10201 | ui_out_field_stream (uiout, "addr", stb); | |
10202 | ui_out_text (uiout, "\n"); | |
10203 | ||
10204 | do_cleanups (cleanup); | |
10205 | } | |
10206 | ||
10207 | /* Implement the "print_mention" breakpoint_ops method for | |
10208 | ranged breakpoints. */ | |
10209 | ||
10210 | static void | |
10211 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10212 | { | |
10213 | struct bp_location *bl = b->loc; | |
79a45e25 | 10214 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10215 | |
10216 | gdb_assert (bl); | |
10217 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10218 | ||
10219 | if (ui_out_is_mi_like_p (uiout)) | |
10220 | return; | |
10221 | ||
10222 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10223 | b->number, paddress (bl->gdbarch, bl->address), | |
10224 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10225 | } | |
10226 | ||
10227 | /* Implement the "print_recreate" breakpoint_ops method for | |
10228 | ranged breakpoints. */ | |
10229 | ||
10230 | static void | |
10231 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10232 | { | |
f00aae0f KS |
10233 | fprintf_unfiltered (fp, "break-range %s, %s", |
10234 | event_location_to_string (b->location), | |
10235 | event_location_to_string (b->location_range_end)); | |
d9b3f62e | 10236 | print_recreate_thread (b, fp); |
f1310107 TJB |
10237 | } |
10238 | ||
10239 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10240 | ||
2060206e | 10241 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10242 | |
10243 | /* Find the address where the end of the breakpoint range should be | |
10244 | placed, given the SAL of the end of the range. This is so that if | |
10245 | the user provides a line number, the end of the range is set to the | |
10246 | last instruction of the given line. */ | |
10247 | ||
10248 | static CORE_ADDR | |
10249 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10250 | { | |
10251 | CORE_ADDR end; | |
10252 | ||
10253 | /* If the user provided a PC value, use it. Otherwise, | |
10254 | find the address of the end of the given location. */ | |
10255 | if (sal.explicit_pc) | |
10256 | end = sal.pc; | |
10257 | else | |
10258 | { | |
10259 | int ret; | |
10260 | CORE_ADDR start; | |
10261 | ||
10262 | ret = find_line_pc_range (sal, &start, &end); | |
10263 | if (!ret) | |
10264 | error (_("Could not find location of the end of the range.")); | |
10265 | ||
10266 | /* find_line_pc_range returns the start of the next line. */ | |
10267 | end--; | |
10268 | } | |
10269 | ||
10270 | return end; | |
10271 | } | |
10272 | ||
10273 | /* Implement the "break-range" CLI command. */ | |
10274 | ||
10275 | static void | |
10276 | break_range_command (char *arg, int from_tty) | |
10277 | { | |
10278 | char *arg_start, *addr_string_start, *addr_string_end; | |
10279 | struct linespec_result canonical_start, canonical_end; | |
10280 | int bp_count, can_use_bp, length; | |
10281 | CORE_ADDR end; | |
10282 | struct breakpoint *b; | |
10283 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10284 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10285 | struct linespec_sals *lsal_start, *lsal_end; |
f00aae0f | 10286 | struct event_location *start_location, *end_location; |
f1310107 TJB |
10287 | |
10288 | /* We don't support software ranged breakpoints. */ | |
10289 | if (target_ranged_break_num_registers () < 0) | |
10290 | error (_("This target does not support hardware ranged breakpoints.")); | |
10291 | ||
10292 | bp_count = hw_breakpoint_used_count (); | |
10293 | bp_count += target_ranged_break_num_registers (); | |
10294 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10295 | bp_count, 0); | |
10296 | if (can_use_bp < 0) | |
10297 | error (_("Hardware breakpoints used exceeds limit.")); | |
10298 | ||
f8eba3c6 | 10299 | arg = skip_spaces (arg); |
f1310107 TJB |
10300 | if (arg == NULL || arg[0] == '\0') |
10301 | error(_("No address range specified.")); | |
10302 | ||
f1310107 TJB |
10303 | init_linespec_result (&canonical_start); |
10304 | ||
f8eba3c6 | 10305 | arg_start = arg; |
f00aae0f KS |
10306 | start_location = string_to_event_location (&arg, current_language); |
10307 | cleanup_bkpt = make_cleanup_delete_event_location (start_location); | |
10308 | parse_breakpoint_sals (start_location, &canonical_start); | |
10309 | make_cleanup_destroy_linespec_result (&canonical_start); | |
f1310107 TJB |
10310 | |
10311 | if (arg[0] != ',') | |
10312 | error (_("Too few arguments.")); | |
f8eba3c6 | 10313 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10314 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10315 | |
10316 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10317 | ||
10318 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10319 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10320 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10321 | ||
f8eba3c6 TT |
10322 | sal_start = lsal_start->sals.sals[0]; |
10323 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10324 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10325 | |
10326 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10327 | arg = skip_spaces (arg); |
f1310107 TJB |
10328 | |
10329 | /* Parse the end location. */ | |
10330 | ||
f1310107 TJB |
10331 | init_linespec_result (&canonical_end); |
10332 | arg_start = arg; | |
10333 | ||
f8eba3c6 | 10334 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10335 | parse_breakpoint_sals because we need to specify the start location's |
10336 | symtab and line as the default symtab and line for the end of the | |
10337 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10338 | where +14 means 14 lines from the start location. */ | |
f00aae0f KS |
10339 | end_location = string_to_event_location (&arg, current_language); |
10340 | make_cleanup_delete_event_location (end_location); | |
10341 | decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, | |
f8eba3c6 TT |
10342 | sal_start.symtab, sal_start.line, |
10343 | &canonical_end, NULL, NULL); | |
10344 | ||
10345 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10346 | |
f8eba3c6 | 10347 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10348 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10349 | |
10350 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10351 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10352 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10353 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10354 | ||
f8eba3c6 | 10355 | sal_end = lsal_end->sals.sals[0]; |
f1310107 TJB |
10356 | |
10357 | end = find_breakpoint_range_end (sal_end); | |
10358 | if (sal_start.pc > end) | |
177b42fe | 10359 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10360 | |
10361 | length = end - sal_start.pc + 1; | |
10362 | if (length < 0) | |
10363 | /* Length overflowed. */ | |
10364 | error (_("Address range too large.")); | |
10365 | else if (length == 1) | |
10366 | { | |
10367 | /* This range is simple enough to be handled by | |
10368 | the `hbreak' command. */ | |
10369 | hbreak_command (addr_string_start, 1); | |
10370 | ||
10371 | do_cleanups (cleanup_bkpt); | |
10372 | ||
10373 | return; | |
10374 | } | |
10375 | ||
10376 | /* Now set up the breakpoint. */ | |
10377 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10378 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10379 | set_breakpoint_count (breakpoint_count + 1); |
10380 | b->number = breakpoint_count; | |
10381 | b->disposition = disp_donttouch; | |
f00aae0f KS |
10382 | b->location = copy_event_location (start_location); |
10383 | b->location_range_end = copy_event_location (end_location); | |
f1310107 TJB |
10384 | b->loc->length = length; |
10385 | ||
f8eba3c6 | 10386 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10387 | |
10388 | mention (b); | |
8d3788bd | 10389 | observer_notify_breakpoint_created (b); |
44702360 | 10390 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10391 | } |
10392 | ||
4a64f543 MS |
10393 | /* Return non-zero if EXP is verified as constant. Returned zero |
10394 | means EXP is variable. Also the constant detection may fail for | |
10395 | some constant expressions and in such case still falsely return | |
10396 | zero. */ | |
2e6e3d9c | 10397 | |
65d79d4b SDJ |
10398 | static int |
10399 | watchpoint_exp_is_const (const struct expression *exp) | |
10400 | { | |
10401 | int i = exp->nelts; | |
10402 | ||
10403 | while (i > 0) | |
10404 | { | |
10405 | int oplenp, argsp; | |
10406 | ||
10407 | /* We are only interested in the descriptor of each element. */ | |
10408 | operator_length (exp, i, &oplenp, &argsp); | |
10409 | i -= oplenp; | |
10410 | ||
10411 | switch (exp->elts[i].opcode) | |
10412 | { | |
10413 | case BINOP_ADD: | |
10414 | case BINOP_SUB: | |
10415 | case BINOP_MUL: | |
10416 | case BINOP_DIV: | |
10417 | case BINOP_REM: | |
10418 | case BINOP_MOD: | |
10419 | case BINOP_LSH: | |
10420 | case BINOP_RSH: | |
10421 | case BINOP_LOGICAL_AND: | |
10422 | case BINOP_LOGICAL_OR: | |
10423 | case BINOP_BITWISE_AND: | |
10424 | case BINOP_BITWISE_IOR: | |
10425 | case BINOP_BITWISE_XOR: | |
10426 | case BINOP_EQUAL: | |
10427 | case BINOP_NOTEQUAL: | |
10428 | case BINOP_LESS: | |
10429 | case BINOP_GTR: | |
10430 | case BINOP_LEQ: | |
10431 | case BINOP_GEQ: | |
10432 | case BINOP_REPEAT: | |
10433 | case BINOP_COMMA: | |
10434 | case BINOP_EXP: | |
10435 | case BINOP_MIN: | |
10436 | case BINOP_MAX: | |
10437 | case BINOP_INTDIV: | |
10438 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10439 | case TERNOP_COND: |
10440 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10441 | |
10442 | case OP_LONG: | |
10443 | case OP_DOUBLE: | |
10444 | case OP_DECFLOAT: | |
10445 | case OP_LAST: | |
10446 | case OP_COMPLEX: | |
10447 | case OP_STRING: | |
65d79d4b SDJ |
10448 | case OP_ARRAY: |
10449 | case OP_TYPE: | |
608b4967 TT |
10450 | case OP_TYPEOF: |
10451 | case OP_DECLTYPE: | |
6e72ca20 | 10452 | case OP_TYPEID: |
65d79d4b SDJ |
10453 | case OP_NAME: |
10454 | case OP_OBJC_NSSTRING: | |
10455 | ||
10456 | case UNOP_NEG: | |
10457 | case UNOP_LOGICAL_NOT: | |
10458 | case UNOP_COMPLEMENT: | |
10459 | case UNOP_ADDR: | |
10460 | case UNOP_HIGH: | |
aeaa2474 | 10461 | case UNOP_CAST: |
9eaf6705 TT |
10462 | |
10463 | case UNOP_CAST_TYPE: | |
10464 | case UNOP_REINTERPRET_CAST: | |
10465 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10466 | /* Unary, binary and ternary operators: We have to check |
10467 | their operands. If they are constant, then so is the | |
10468 | result of that operation. For instance, if A and B are | |
10469 | determined to be constants, then so is "A + B". | |
10470 | ||
10471 | UNOP_IND is one exception to the rule above, because the | |
10472 | value of *ADDR is not necessarily a constant, even when | |
10473 | ADDR is. */ | |
65d79d4b SDJ |
10474 | break; |
10475 | ||
10476 | case OP_VAR_VALUE: | |
10477 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10478 | |
65d79d4b | 10479 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10480 | possible that a buggy compiler could mark a variable as |
10481 | constant even when it is not, and TYPE_CONST would return | |
10482 | true in this case, while SYMBOL_CLASS wouldn't. | |
10483 | ||
10484 | We also have to check for function symbols because they | |
10485 | are always constant. */ | |
65d79d4b SDJ |
10486 | { |
10487 | struct symbol *s = exp->elts[i + 2].symbol; | |
10488 | ||
10489 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10490 | && SYMBOL_CLASS (s) != LOC_CONST | |
10491 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10492 | return 0; | |
10493 | break; | |
10494 | } | |
10495 | ||
10496 | /* The default action is to return 0 because we are using | |
10497 | the optimistic approach here: If we don't know something, | |
10498 | then it is not a constant. */ | |
10499 | default: | |
10500 | return 0; | |
10501 | } | |
10502 | } | |
10503 | ||
10504 | return 1; | |
10505 | } | |
10506 | ||
3a5c3e22 PA |
10507 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10508 | ||
10509 | static void | |
10510 | dtor_watchpoint (struct breakpoint *self) | |
10511 | { | |
10512 | struct watchpoint *w = (struct watchpoint *) self; | |
10513 | ||
10514 | xfree (w->cond_exp); | |
10515 | xfree (w->exp); | |
10516 | xfree (w->exp_string); | |
10517 | xfree (w->exp_string_reparse); | |
10518 | value_free (w->val); | |
10519 | ||
10520 | base_breakpoint_ops.dtor (self); | |
10521 | } | |
10522 | ||
348d480f PA |
10523 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10524 | ||
10525 | static void | |
10526 | re_set_watchpoint (struct breakpoint *b) | |
10527 | { | |
3a5c3e22 PA |
10528 | struct watchpoint *w = (struct watchpoint *) b; |
10529 | ||
348d480f PA |
10530 | /* Watchpoint can be either on expression using entirely global |
10531 | variables, or it can be on local variables. | |
10532 | ||
10533 | Watchpoints of the first kind are never auto-deleted, and even | |
10534 | persist across program restarts. Since they can use variables | |
10535 | from shared libraries, we need to reparse expression as libraries | |
10536 | are loaded and unloaded. | |
10537 | ||
10538 | Watchpoints on local variables can also change meaning as result | |
10539 | of solib event. For example, if a watchpoint uses both a local | |
10540 | and a global variables in expression, it's a local watchpoint, | |
10541 | but unloading of a shared library will make the expression | |
10542 | invalid. This is not a very common use case, but we still | |
10543 | re-evaluate expression, to avoid surprises to the user. | |
10544 | ||
10545 | Note that for local watchpoints, we re-evaluate it only if | |
10546 | watchpoints frame id is still valid. If it's not, it means the | |
10547 | watchpoint is out of scope and will be deleted soon. In fact, | |
10548 | I'm not sure we'll ever be called in this case. | |
10549 | ||
10550 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10551 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10552 | |
3a5c3e22 PA |
10553 | Don't do anything about disabled watchpoints, since they will be |
10554 | reevaluated again when enabled. */ | |
10555 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10556 | } |
10557 | ||
77b06cd7 TJB |
10558 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10559 | ||
10560 | static int | |
10561 | insert_watchpoint (struct bp_location *bl) | |
10562 | { | |
3a5c3e22 PA |
10563 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10564 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10565 | |
10566 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10567 | w->cond_exp); |
77b06cd7 TJB |
10568 | } |
10569 | ||
10570 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10571 | ||
10572 | static int | |
10573 | remove_watchpoint (struct bp_location *bl) | |
10574 | { | |
3a5c3e22 PA |
10575 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10576 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10577 | |
10578 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10579 | w->cond_exp); |
e09342b5 TJB |
10580 | } |
10581 | ||
e09342b5 | 10582 | static int |
348d480f | 10583 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10584 | struct address_space *aspace, CORE_ADDR bp_addr, |
10585 | const struct target_waitstatus *ws) | |
e09342b5 | 10586 | { |
348d480f | 10587 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10588 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10589 | |
348d480f PA |
10590 | /* Continuable hardware watchpoints are treated as non-existent if the |
10591 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10592 | some data address). Otherwise gdb won't stop on a break instruction | |
10593 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10594 | been defined. Also skip watchpoints which we know did not trigger | |
10595 | (did not match the data address). */ | |
10596 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10597 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10598 | return 0; |
9c06b0b4 | 10599 | |
348d480f | 10600 | return 1; |
9c06b0b4 TJB |
10601 | } |
10602 | ||
348d480f PA |
10603 | static void |
10604 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10605 | { |
348d480f | 10606 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10607 | |
348d480f | 10608 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10609 | } |
10610 | ||
10611 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10612 | hardware watchpoints. */ |
9c06b0b4 TJB |
10613 | |
10614 | static int | |
348d480f | 10615 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10616 | { |
3a5c3e22 PA |
10617 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10618 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10619 | |
10620 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10621 | } |
10622 | ||
10623 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10624 | hardware watchpoints. */ |
9c06b0b4 TJB |
10625 | |
10626 | static int | |
348d480f | 10627 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10628 | { |
efa80663 PA |
10629 | /* Read and access watchpoints only work with hardware support. */ |
10630 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10631 | } |
10632 | ||
9c06b0b4 | 10633 | static enum print_stop_action |
348d480f | 10634 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10635 | { |
348d480f PA |
10636 | struct cleanup *old_chain; |
10637 | struct breakpoint *b; | |
f99d8bf4 | 10638 | struct ui_file *stb; |
348d480f | 10639 | enum print_stop_action result; |
3a5c3e22 | 10640 | struct watchpoint *w; |
79a45e25 | 10641 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10642 | |
10643 | gdb_assert (bs->bp_location_at != NULL); | |
10644 | ||
348d480f | 10645 | b = bs->breakpoint_at; |
3a5c3e22 | 10646 | w = (struct watchpoint *) b; |
348d480f | 10647 | |
f99d8bf4 PA |
10648 | stb = mem_fileopen (); |
10649 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10650 | |
10651 | switch (b->type) | |
10652 | { | |
348d480f | 10653 | case bp_watchpoint: |
9c06b0b4 TJB |
10654 | case bp_hardware_watchpoint: |
10655 | annotate_watchpoint (b->number); | |
10656 | if (ui_out_is_mi_like_p (uiout)) | |
10657 | ui_out_field_string | |
10658 | (uiout, "reason", | |
10659 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10660 | mention (b); |
10661 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10662 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10663 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10664 | ui_out_field_stream (uiout, "old", stb); |
10665 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10666 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10667 | ui_out_field_stream (uiout, "new", stb); |
10668 | ui_out_text (uiout, "\n"); | |
10669 | /* More than one watchpoint may have been triggered. */ | |
10670 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10671 | break; |
10672 | ||
10673 | case bp_read_watchpoint: | |
10674 | if (ui_out_is_mi_like_p (uiout)) | |
10675 | ui_out_field_string | |
10676 | (uiout, "reason", | |
10677 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10678 | mention (b); |
10679 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10680 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10681 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10682 | ui_out_field_stream (uiout, "value", stb); |
10683 | ui_out_text (uiout, "\n"); | |
10684 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10685 | break; |
10686 | ||
10687 | case bp_access_watchpoint: | |
348d480f PA |
10688 | if (bs->old_val != NULL) |
10689 | { | |
10690 | annotate_watchpoint (b->number); | |
10691 | if (ui_out_is_mi_like_p (uiout)) | |
10692 | ui_out_field_string | |
10693 | (uiout, "reason", | |
10694 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10695 | mention (b); | |
10696 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10697 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10698 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10699 | ui_out_field_stream (uiout, "old", stb); |
10700 | ui_out_text (uiout, "\nNew value = "); | |
10701 | } | |
10702 | else | |
10703 | { | |
10704 | mention (b); | |
10705 | if (ui_out_is_mi_like_p (uiout)) | |
10706 | ui_out_field_string | |
10707 | (uiout, "reason", | |
10708 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10709 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10710 | ui_out_text (uiout, "\nValue = "); | |
10711 | } | |
f99d8bf4 | 10712 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10713 | ui_out_field_stream (uiout, "new", stb); |
10714 | ui_out_text (uiout, "\n"); | |
10715 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10716 | break; |
10717 | default: | |
348d480f | 10718 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10719 | } |
10720 | ||
348d480f PA |
10721 | do_cleanups (old_chain); |
10722 | return result; | |
10723 | } | |
10724 | ||
10725 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10726 | watchpoints. */ | |
10727 | ||
10728 | static void | |
10729 | print_mention_watchpoint (struct breakpoint *b) | |
10730 | { | |
10731 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10732 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10733 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10734 | |
10735 | switch (b->type) | |
10736 | { | |
10737 | case bp_watchpoint: | |
10738 | ui_out_text (uiout, "Watchpoint "); | |
10739 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10740 | break; | |
10741 | case bp_hardware_watchpoint: | |
10742 | ui_out_text (uiout, "Hardware watchpoint "); | |
10743 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10744 | break; | |
10745 | case bp_read_watchpoint: | |
10746 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10747 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10748 | break; | |
10749 | case bp_access_watchpoint: | |
10750 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10751 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10752 | break; | |
10753 | default: | |
10754 | internal_error (__FILE__, __LINE__, | |
10755 | _("Invalid hardware watchpoint type.")); | |
10756 | } | |
10757 | ||
10758 | ui_out_field_int (uiout, "number", b->number); | |
10759 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10760 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10761 | do_cleanups (ui_out_chain); |
10762 | } | |
10763 | ||
10764 | /* Implement the "print_recreate" breakpoint_ops method for | |
10765 | watchpoints. */ | |
10766 | ||
10767 | static void | |
10768 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10769 | { | |
3a5c3e22 PA |
10770 | struct watchpoint *w = (struct watchpoint *) b; |
10771 | ||
348d480f PA |
10772 | switch (b->type) |
10773 | { | |
10774 | case bp_watchpoint: | |
10775 | case bp_hardware_watchpoint: | |
10776 | fprintf_unfiltered (fp, "watch"); | |
10777 | break; | |
10778 | case bp_read_watchpoint: | |
10779 | fprintf_unfiltered (fp, "rwatch"); | |
10780 | break; | |
10781 | case bp_access_watchpoint: | |
10782 | fprintf_unfiltered (fp, "awatch"); | |
10783 | break; | |
10784 | default: | |
10785 | internal_error (__FILE__, __LINE__, | |
10786 | _("Invalid watchpoint type.")); | |
10787 | } | |
10788 | ||
3a5c3e22 | 10789 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10790 | print_recreate_thread (b, fp); |
348d480f PA |
10791 | } |
10792 | ||
427cd150 TT |
10793 | /* Implement the "explains_signal" breakpoint_ops method for |
10794 | watchpoints. */ | |
10795 | ||
47591c29 | 10796 | static int |
427cd150 TT |
10797 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10798 | { | |
10799 | /* A software watchpoint cannot cause a signal other than | |
10800 | GDB_SIGNAL_TRAP. */ | |
10801 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10802 | return 0; |
427cd150 | 10803 | |
47591c29 | 10804 | return 1; |
427cd150 TT |
10805 | } |
10806 | ||
348d480f PA |
10807 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10808 | ||
2060206e | 10809 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10810 | |
10811 | /* Implement the "insert" breakpoint_ops method for | |
10812 | masked hardware watchpoints. */ | |
10813 | ||
10814 | static int | |
10815 | insert_masked_watchpoint (struct bp_location *bl) | |
10816 | { | |
3a5c3e22 PA |
10817 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10818 | ||
10819 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10820 | bl->watchpoint_type); |
10821 | } | |
10822 | ||
10823 | /* Implement the "remove" breakpoint_ops method for | |
10824 | masked hardware watchpoints. */ | |
10825 | ||
10826 | static int | |
10827 | remove_masked_watchpoint (struct bp_location *bl) | |
10828 | { | |
3a5c3e22 PA |
10829 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10830 | ||
10831 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10832 | bl->watchpoint_type); |
10833 | } | |
10834 | ||
10835 | /* Implement the "resources_needed" breakpoint_ops method for | |
10836 | masked hardware watchpoints. */ | |
10837 | ||
10838 | static int | |
10839 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10840 | { | |
3a5c3e22 PA |
10841 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10842 | ||
10843 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10844 | } |
10845 | ||
10846 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10847 | masked hardware watchpoints. */ | |
10848 | ||
10849 | static int | |
10850 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10851 | { | |
10852 | return 0; | |
10853 | } | |
10854 | ||
10855 | /* Implement the "print_it" breakpoint_ops method for | |
10856 | masked hardware watchpoints. */ | |
10857 | ||
10858 | static enum print_stop_action | |
10859 | print_it_masked_watchpoint (bpstat bs) | |
10860 | { | |
10861 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10862 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10863 | |
10864 | /* Masked watchpoints have only one location. */ | |
10865 | gdb_assert (b->loc && b->loc->next == NULL); | |
10866 | ||
10867 | switch (b->type) | |
10868 | { | |
10869 | case bp_hardware_watchpoint: | |
10870 | annotate_watchpoint (b->number); | |
10871 | if (ui_out_is_mi_like_p (uiout)) | |
10872 | ui_out_field_string | |
10873 | (uiout, "reason", | |
10874 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
10875 | break; | |
10876 | ||
10877 | case bp_read_watchpoint: | |
10878 | if (ui_out_is_mi_like_p (uiout)) | |
10879 | ui_out_field_string | |
10880 | (uiout, "reason", | |
10881 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
10882 | break; | |
10883 | ||
10884 | case bp_access_watchpoint: | |
10885 | if (ui_out_is_mi_like_p (uiout)) | |
10886 | ui_out_field_string | |
10887 | (uiout, "reason", | |
10888 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10889 | break; | |
10890 | default: | |
10891 | internal_error (__FILE__, __LINE__, | |
10892 | _("Invalid hardware watchpoint type.")); | |
10893 | } | |
10894 | ||
10895 | mention (b); | |
9c06b0b4 TJB |
10896 | ui_out_text (uiout, _("\n\ |
10897 | Check the underlying instruction at PC for the memory\n\ | |
10898 | address and value which triggered this watchpoint.\n")); | |
10899 | ui_out_text (uiout, "\n"); | |
10900 | ||
10901 | /* More than one watchpoint may have been triggered. */ | |
10902 | return PRINT_UNKNOWN; | |
10903 | } | |
10904 | ||
10905 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10906 | masked hardware watchpoints. */ | |
10907 | ||
10908 | static void | |
10909 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10910 | struct ui_out *uiout) | |
10911 | { | |
3a5c3e22 PA |
10912 | struct watchpoint *w = (struct watchpoint *) b; |
10913 | ||
9c06b0b4 TJB |
10914 | /* Masked watchpoints have only one location. */ |
10915 | gdb_assert (b->loc && b->loc->next == NULL); | |
10916 | ||
10917 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 10918 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
10919 | ui_out_text (uiout, "\n"); |
10920 | } | |
10921 | ||
10922 | /* Implement the "print_mention" breakpoint_ops method for | |
10923 | masked hardware watchpoints. */ | |
10924 | ||
10925 | static void | |
10926 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10927 | { | |
3a5c3e22 | 10928 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10929 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
10930 | struct cleanup *ui_out_chain; |
10931 | ||
10932 | switch (b->type) | |
10933 | { | |
10934 | case bp_hardware_watchpoint: | |
10935 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
10936 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10937 | break; | |
10938 | case bp_read_watchpoint: | |
10939 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
10940 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10941 | break; | |
10942 | case bp_access_watchpoint: | |
10943 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
10944 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10945 | break; | |
10946 | default: | |
10947 | internal_error (__FILE__, __LINE__, | |
10948 | _("Invalid hardware watchpoint type.")); | |
10949 | } | |
10950 | ||
10951 | ui_out_field_int (uiout, "number", b->number); | |
10952 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10953 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
10954 | do_cleanups (ui_out_chain); |
10955 | } | |
10956 | ||
10957 | /* Implement the "print_recreate" breakpoint_ops method for | |
10958 | masked hardware watchpoints. */ | |
10959 | ||
10960 | static void | |
10961 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10962 | { | |
3a5c3e22 | 10963 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10964 | char tmp[40]; |
10965 | ||
10966 | switch (b->type) | |
10967 | { | |
10968 | case bp_hardware_watchpoint: | |
10969 | fprintf_unfiltered (fp, "watch"); | |
10970 | break; | |
10971 | case bp_read_watchpoint: | |
10972 | fprintf_unfiltered (fp, "rwatch"); | |
10973 | break; | |
10974 | case bp_access_watchpoint: | |
10975 | fprintf_unfiltered (fp, "awatch"); | |
10976 | break; | |
10977 | default: | |
10978 | internal_error (__FILE__, __LINE__, | |
10979 | _("Invalid hardware watchpoint type.")); | |
10980 | } | |
10981 | ||
3a5c3e22 PA |
10982 | sprintf_vma (tmp, w->hw_wp_mask); |
10983 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10984 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10985 | } |
10986 | ||
10987 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10988 | ||
2060206e | 10989 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10990 | |
10991 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10992 | ||
10993 | static int | |
10994 | is_masked_watchpoint (const struct breakpoint *b) | |
10995 | { | |
10996 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10997 | } | |
10998 | ||
53a5351d JM |
10999 | /* accessflag: hw_write: watch write, |
11000 | hw_read: watch read, | |
11001 | hw_access: watch access (read or write) */ | |
c906108c | 11002 | static void |
bbc13ae3 | 11003 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11004 | int just_location, int internal) |
c906108c | 11005 | { |
d983da9c | 11006 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11007 | struct expression *exp; |
270140bd | 11008 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11009 | struct value *val, *mark, *result; |
bb9d5f81 | 11010 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 11011 | struct frame_info *frame; |
bbc13ae3 KS |
11012 | const char *exp_start = NULL; |
11013 | const char *exp_end = NULL; | |
11014 | const char *tok, *end_tok; | |
9c06b0b4 | 11015 | int toklen = -1; |
bbc13ae3 KS |
11016 | const char *cond_start = NULL; |
11017 | const char *cond_end = NULL; | |
c906108c | 11018 | enum bptype bp_type; |
37e4754d | 11019 | int thread = -1; |
0cf6dd15 | 11020 | int pc = 0; |
9c06b0b4 TJB |
11021 | /* Flag to indicate whether we are going to use masks for |
11022 | the hardware watchpoint. */ | |
11023 | int use_mask = 0; | |
11024 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11025 | struct watchpoint *w; |
bbc13ae3 KS |
11026 | char *expression; |
11027 | struct cleanup *back_to; | |
c906108c | 11028 | |
37e4754d LM |
11029 | /* Make sure that we actually have parameters to parse. */ |
11030 | if (arg != NULL && arg[0] != '\0') | |
11031 | { | |
bbc13ae3 KS |
11032 | const char *value_start; |
11033 | ||
11034 | exp_end = arg + strlen (arg); | |
37e4754d | 11035 | |
9c06b0b4 TJB |
11036 | /* Look for "parameter value" pairs at the end |
11037 | of the arguments string. */ | |
bbc13ae3 | 11038 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11039 | { |
11040 | /* Skip whitespace at the end of the argument list. */ | |
11041 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11042 | tok--; | |
11043 | ||
11044 | /* Find the beginning of the last token. | |
11045 | This is the value of the parameter. */ | |
11046 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11047 | tok--; | |
11048 | value_start = tok + 1; | |
11049 | ||
11050 | /* Skip whitespace. */ | |
11051 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11052 | tok--; | |
11053 | ||
11054 | end_tok = tok; | |
11055 | ||
11056 | /* Find the beginning of the second to last token. | |
11057 | This is the parameter itself. */ | |
11058 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11059 | tok--; | |
11060 | tok++; | |
11061 | toklen = end_tok - tok + 1; | |
11062 | ||
61012eef | 11063 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 TJB |
11064 | { |
11065 | /* At this point we've found a "thread" token, which means | |
11066 | the user is trying to set a watchpoint that triggers | |
11067 | only in a specific thread. */ | |
11068 | char *endp; | |
37e4754d | 11069 | |
9c06b0b4 TJB |
11070 | if (thread != -1) |
11071 | error(_("You can specify only one thread.")); | |
37e4754d | 11072 | |
9c06b0b4 TJB |
11073 | /* Extract the thread ID from the next token. */ |
11074 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 11075 | |
9c06b0b4 TJB |
11076 | /* Check if the user provided a valid numeric value for the |
11077 | thread ID. */ | |
11078 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
11079 | error (_("Invalid thread ID specification %s."), value_start); | |
11080 | ||
11081 | /* Check if the thread actually exists. */ | |
11082 | if (!valid_thread_id (thread)) | |
af4908ba | 11083 | invalid_thread_id_error (thread); |
9c06b0b4 | 11084 | } |
61012eef | 11085 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
11086 | { |
11087 | /* We've found a "mask" token, which means the user wants to | |
11088 | create a hardware watchpoint that is going to have the mask | |
11089 | facility. */ | |
11090 | struct value *mask_value, *mark; | |
37e4754d | 11091 | |
9c06b0b4 TJB |
11092 | if (use_mask) |
11093 | error(_("You can specify only one mask.")); | |
37e4754d | 11094 | |
9c06b0b4 | 11095 | use_mask = just_location = 1; |
37e4754d | 11096 | |
9c06b0b4 TJB |
11097 | mark = value_mark (); |
11098 | mask_value = parse_to_comma_and_eval (&value_start); | |
11099 | mask = value_as_address (mask_value); | |
11100 | value_free_to_mark (mark); | |
11101 | } | |
11102 | else | |
11103 | /* We didn't recognize what we found. We should stop here. */ | |
11104 | break; | |
37e4754d | 11105 | |
9c06b0b4 TJB |
11106 | /* Truncate the string and get rid of the "parameter value" pair before |
11107 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11108 | exp_end = tok; |
9c06b0b4 | 11109 | } |
37e4754d | 11110 | } |
bbc13ae3 KS |
11111 | else |
11112 | exp_end = arg; | |
37e4754d | 11113 | |
bbc13ae3 KS |
11114 | /* Parse the rest of the arguments. From here on out, everything |
11115 | is in terms of a newly allocated string instead of the original | |
11116 | ARG. */ | |
c906108c | 11117 | innermost_block = NULL; |
bbc13ae3 KS |
11118 | expression = savestring (arg, exp_end - arg); |
11119 | back_to = make_cleanup (xfree, expression); | |
11120 | exp_start = arg = expression; | |
1bb9788d | 11121 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11122 | exp_end = arg; |
fa8a61dc TT |
11123 | /* Remove trailing whitespace from the expression before saving it. |
11124 | This makes the eventual display of the expression string a bit | |
11125 | prettier. */ | |
11126 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11127 | --exp_end; | |
11128 | ||
65d79d4b SDJ |
11129 | /* Checking if the expression is not constant. */ |
11130 | if (watchpoint_exp_is_const (exp)) | |
11131 | { | |
11132 | int len; | |
11133 | ||
11134 | len = exp_end - exp_start; | |
11135 | while (len > 0 && isspace (exp_start[len - 1])) | |
11136 | len--; | |
11137 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11138 | } | |
11139 | ||
c906108c SS |
11140 | exp_valid_block = innermost_block; |
11141 | mark = value_mark (); | |
3a1115a0 | 11142 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b | 11143 | |
bb9d5f81 PP |
11144 | if (val != NULL && just_location) |
11145 | { | |
11146 | saved_bitpos = value_bitpos (val); | |
11147 | saved_bitsize = value_bitsize (val); | |
11148 | } | |
11149 | ||
06a64a0b TT |
11150 | if (just_location) |
11151 | { | |
9c06b0b4 TJB |
11152 | int ret; |
11153 | ||
06a64a0b | 11154 | exp_valid_block = NULL; |
a1442452 | 11155 | val = value_addr (result); |
06a64a0b TT |
11156 | release_value (val); |
11157 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11158 | |
11159 | if (use_mask) | |
11160 | { | |
11161 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11162 | mask); | |
11163 | if (ret == -1) | |
11164 | error (_("This target does not support masked watchpoints.")); | |
11165 | else if (ret == -2) | |
11166 | error (_("Invalid mask or memory region.")); | |
11167 | } | |
06a64a0b TT |
11168 | } |
11169 | else if (val != NULL) | |
fa4727a6 | 11170 | release_value (val); |
c906108c | 11171 | |
bbc13ae3 KS |
11172 | tok = skip_spaces_const (arg); |
11173 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11174 | |
11175 | toklen = end_tok - tok; | |
11176 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11177 | { | |
2d134ed3 PA |
11178 | struct expression *cond; |
11179 | ||
60e1c644 | 11180 | innermost_block = NULL; |
c906108c | 11181 | tok = cond_start = end_tok + 1; |
1bb9788d | 11182 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11183 | |
11184 | /* The watchpoint expression may not be local, but the condition | |
11185 | may still be. E.g.: `watch global if local > 0'. */ | |
11186 | cond_exp_valid_block = innermost_block; | |
11187 | ||
2d134ed3 | 11188 | xfree (cond); |
c906108c SS |
11189 | cond_end = tok; |
11190 | } | |
11191 | if (*tok) | |
8a3fe4f8 | 11192 | error (_("Junk at end of command.")); |
c906108c | 11193 | |
d983da9c | 11194 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11195 | |
11196 | /* If the expression is "local", then set up a "watchpoint scope" | |
11197 | breakpoint at the point where we've left the scope of the watchpoint | |
11198 | expression. Create the scope breakpoint before the watchpoint, so | |
11199 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11200 | if (exp_valid_block && frame) |
d983da9c | 11201 | { |
edb3359d DJ |
11202 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11203 | { | |
11204 | scope_breakpoint | |
a6d9a66e UW |
11205 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11206 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11207 | bp_watchpoint_scope, |
11208 | &momentary_breakpoint_ops); | |
d983da9c | 11209 | |
edb3359d | 11210 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11211 | |
edb3359d DJ |
11212 | /* Automatically delete the breakpoint when it hits. */ |
11213 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11214 | |
edb3359d DJ |
11215 | /* Only break in the proper frame (help with recursion). */ |
11216 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11217 | |
edb3359d | 11218 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11219 | scope_breakpoint->loc->gdbarch |
11220 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11221 | scope_breakpoint->loc->requested_address |
11222 | = frame_unwind_caller_pc (frame); | |
11223 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11224 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11225 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11226 | scope_breakpoint->type); |
11227 | } | |
d983da9c DJ |
11228 | } |
11229 | ||
e8369a73 AB |
11230 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11231 | watchpoints here even if hardware watchpoints are turned off, a call | |
11232 | to update_watchpoint later in this function will cause the type to | |
11233 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11234 | ||
11235 | if (accessflag == hw_read) | |
11236 | bp_type = bp_read_watchpoint; | |
11237 | else if (accessflag == hw_access) | |
11238 | bp_type = bp_access_watchpoint; | |
11239 | else | |
11240 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11241 | |
11242 | w = XCNEW (struct watchpoint); | |
11243 | b = &w->base; | |
348d480f | 11244 | if (use_mask) |
3a5c3e22 PA |
11245 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11246 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11247 | else |
3a5c3e22 PA |
11248 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11249 | &watchpoint_breakpoint_ops); | |
37e4754d | 11250 | b->thread = thread; |
b5de0fa7 | 11251 | b->disposition = disp_donttouch; |
348d480f | 11252 | b->pspace = current_program_space; |
3a5c3e22 PA |
11253 | w->exp = exp; |
11254 | w->exp_valid_block = exp_valid_block; | |
11255 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11256 | if (just_location) |
11257 | { | |
11258 | struct type *t = value_type (val); | |
11259 | CORE_ADDR addr = value_as_address (val); | |
11260 | char *name; | |
11261 | ||
11262 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11263 | name = type_to_string (t); | |
11264 | ||
3a5c3e22 | 11265 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11266 | core_addr_to_string (addr)); |
06a64a0b TT |
11267 | xfree (name); |
11268 | ||
3a5c3e22 | 11269 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11270 | (int) (exp_end - exp_start), exp_start); |
11271 | ||
06a64a0b TT |
11272 | /* The above expression is in C. */ |
11273 | b->language = language_c; | |
11274 | } | |
11275 | else | |
3a5c3e22 | 11276 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11277 | |
11278 | if (use_mask) | |
11279 | { | |
3a5c3e22 | 11280 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11281 | } |
11282 | else | |
11283 | { | |
3a5c3e22 | 11284 | w->val = val; |
bb9d5f81 PP |
11285 | w->val_bitpos = saved_bitpos; |
11286 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11287 | w->val_valid = 1; |
9c06b0b4 | 11288 | } |
77b06cd7 | 11289 | |
c906108c SS |
11290 | if (cond_start) |
11291 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11292 | else | |
11293 | b->cond_string = 0; | |
c5aa993b | 11294 | |
c906108c | 11295 | if (frame) |
f6bc2008 | 11296 | { |
3a5c3e22 PA |
11297 | w->watchpoint_frame = get_frame_id (frame); |
11298 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11299 | } |
c906108c | 11300 | else |
f6bc2008 | 11301 | { |
3a5c3e22 PA |
11302 | w->watchpoint_frame = null_frame_id; |
11303 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11304 | } |
c906108c | 11305 | |
d983da9c | 11306 | if (scope_breakpoint != NULL) |
c906108c | 11307 | { |
d983da9c DJ |
11308 | /* The scope breakpoint is related to the watchpoint. We will |
11309 | need to act on them together. */ | |
11310 | b->related_breakpoint = scope_breakpoint; | |
11311 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11312 | } |
d983da9c | 11313 | |
06a64a0b TT |
11314 | if (!just_location) |
11315 | value_free_to_mark (mark); | |
2d134ed3 | 11316 | |
492d29ea | 11317 | TRY |
a9634178 TJB |
11318 | { |
11319 | /* Finally update the new watchpoint. This creates the locations | |
11320 | that should be inserted. */ | |
3a5c3e22 | 11321 | update_watchpoint (w, 1); |
a9634178 | 11322 | } |
492d29ea | 11323 | CATCH (e, RETURN_MASK_ALL) |
a9634178 TJB |
11324 | { |
11325 | delete_breakpoint (b); | |
11326 | throw_exception (e); | |
11327 | } | |
492d29ea | 11328 | END_CATCH |
a9634178 | 11329 | |
3ea46bff | 11330 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11331 | do_cleanups (back_to); |
c906108c SS |
11332 | } |
11333 | ||
e09342b5 | 11334 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11335 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11336 | |
c906108c | 11337 | static int |
a9634178 | 11338 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11339 | { |
11340 | int found_memory_cnt = 0; | |
2e70b7b9 | 11341 | struct value *head = v; |
c906108c SS |
11342 | |
11343 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11344 | if (!can_use_hw_watchpoints) |
c906108c | 11345 | return 0; |
c5aa993b | 11346 | |
5c44784c JM |
11347 | /* Make sure that the value of the expression depends only upon |
11348 | memory contents, and values computed from them within GDB. If we | |
11349 | find any register references or function calls, we can't use a | |
11350 | hardware watchpoint. | |
11351 | ||
11352 | The idea here is that evaluating an expression generates a series | |
11353 | of values, one holding the value of every subexpression. (The | |
11354 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11355 | a*b+c.) GDB's values hold almost enough information to establish | |
11356 | the criteria given above --- they identify memory lvalues, | |
11357 | register lvalues, computed values, etcetera. So we can evaluate | |
11358 | the expression, and then scan the chain of values that leaves | |
11359 | behind to decide whether we can detect any possible change to the | |
11360 | expression's final value using only hardware watchpoints. | |
11361 | ||
11362 | However, I don't think that the values returned by inferior | |
11363 | function calls are special in any way. So this function may not | |
11364 | notice that an expression involving an inferior function call | |
11365 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11366 | for (; v; v = value_next (v)) |
c906108c | 11367 | { |
5c44784c | 11368 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11369 | { |
8464be76 DJ |
11370 | if (v != head && value_lazy (v)) |
11371 | /* A lazy memory lvalue in the chain is one that GDB never | |
11372 | needed to fetch; we either just used its address (e.g., | |
11373 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11374 | in `a,b'). This doesn't apply to HEAD; if that is | |
11375 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11376 | ; |
53a5351d | 11377 | else |
5c44784c JM |
11378 | { |
11379 | /* Ahh, memory we actually used! Check if we can cover | |
11380 | it with hardware watchpoints. */ | |
df407dfe | 11381 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11382 | |
11383 | /* We only watch structs and arrays if user asked for it | |
11384 | explicitly, never if they just happen to appear in a | |
11385 | middle of some value chain. */ | |
11386 | if (v == head | |
11387 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11388 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11389 | { | |
42ae5230 | 11390 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11391 | int len; |
11392 | int num_regs; | |
11393 | ||
a9634178 | 11394 | len = (target_exact_watchpoints |
e09342b5 TJB |
11395 | && is_scalar_type_recursive (vtype))? |
11396 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11397 | |
e09342b5 TJB |
11398 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11399 | if (!num_regs) | |
2e70b7b9 MS |
11400 | return 0; |
11401 | else | |
e09342b5 | 11402 | found_memory_cnt += num_regs; |
2e70b7b9 | 11403 | } |
5c44784c | 11404 | } |
c5aa993b | 11405 | } |
5086187c AC |
11406 | else if (VALUE_LVAL (v) != not_lval |
11407 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11408 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11409 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11410 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11411 | } |
11412 | ||
11413 | /* The expression itself looks suitable for using a hardware | |
11414 | watchpoint, but give the target machine a chance to reject it. */ | |
11415 | return found_memory_cnt; | |
11416 | } | |
11417 | ||
8b93c638 | 11418 | void |
84f4c1fe | 11419 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11420 | { |
84f4c1fe | 11421 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11422 | } |
11423 | ||
06a64a0b TT |
11424 | /* A helper function that looks for the "-location" argument and then |
11425 | calls watch_command_1. */ | |
11426 | ||
11427 | static void | |
11428 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11429 | { | |
11430 | int just_location = 0; | |
11431 | ||
11432 | if (arg | |
11433 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11434 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11435 | { | |
e9cafbcc | 11436 | arg = skip_spaces (arg); |
06a64a0b TT |
11437 | just_location = 1; |
11438 | } | |
11439 | ||
84f4c1fe | 11440 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11441 | } |
8926118c | 11442 | |
c5aa993b | 11443 | static void |
fba45db2 | 11444 | watch_command (char *arg, int from_tty) |
c906108c | 11445 | { |
06a64a0b | 11446 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11447 | } |
11448 | ||
8b93c638 | 11449 | void |
84f4c1fe | 11450 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11451 | { |
84f4c1fe | 11452 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11453 | } |
8926118c | 11454 | |
c5aa993b | 11455 | static void |
fba45db2 | 11456 | rwatch_command (char *arg, int from_tty) |
c906108c | 11457 | { |
06a64a0b | 11458 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11459 | } |
11460 | ||
8b93c638 | 11461 | void |
84f4c1fe | 11462 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11463 | { |
84f4c1fe | 11464 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11465 | } |
8926118c | 11466 | |
c5aa993b | 11467 | static void |
fba45db2 | 11468 | awatch_command (char *arg, int from_tty) |
c906108c | 11469 | { |
06a64a0b | 11470 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11471 | } |
c906108c | 11472 | \f |
c5aa993b | 11473 | |
43ff13b4 | 11474 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
11475 | because it uses the mechanisms of breakpoints. */ |
11476 | ||
bfec99b2 PA |
11477 | struct until_break_command_continuation_args |
11478 | { | |
11479 | struct breakpoint *breakpoint; | |
11480 | struct breakpoint *breakpoint2; | |
186c406b | 11481 | int thread_num; |
bfec99b2 PA |
11482 | }; |
11483 | ||
43ff13b4 | 11484 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 11485 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 11486 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 11487 | command. */ |
c2c6d25f | 11488 | static void |
fa4cd53f | 11489 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 11490 | { |
bfec99b2 PA |
11491 | struct until_break_command_continuation_args *a = arg; |
11492 | ||
11493 | delete_breakpoint (a->breakpoint); | |
11494 | if (a->breakpoint2) | |
11495 | delete_breakpoint (a->breakpoint2); | |
186c406b | 11496 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
11497 | } |
11498 | ||
c906108c | 11499 | void |
ae66c1fc | 11500 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11501 | { |
11502 | struct symtabs_and_lines sals; | |
11503 | struct symtab_and_line sal; | |
8556afb4 PA |
11504 | struct frame_info *frame; |
11505 | struct gdbarch *frame_gdbarch; | |
11506 | struct frame_id stack_frame_id; | |
11507 | struct frame_id caller_frame_id; | |
c906108c | 11508 | struct breakpoint *breakpoint; |
f107f563 | 11509 | struct breakpoint *breakpoint2 = NULL; |
f00aae0f | 11510 | struct cleanup *old_chain, *cleanup; |
186c406b TT |
11511 | int thread; |
11512 | struct thread_info *tp; | |
f00aae0f | 11513 | struct event_location *location; |
c906108c | 11514 | |
70509625 | 11515 | clear_proceed_status (0); |
c906108c SS |
11516 | |
11517 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11518 | this function. */ |
c5aa993b | 11519 | |
f00aae0f KS |
11520 | location = string_to_event_location (&arg, current_language); |
11521 | cleanup = make_cleanup_delete_event_location (location); | |
11522 | ||
1bfeeb0f | 11523 | if (last_displayed_sal_is_valid ()) |
f00aae0f | 11524 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11525 | get_last_displayed_symtab (), |
f8eba3c6 | 11526 | get_last_displayed_line ()); |
c906108c | 11527 | else |
f00aae0f | 11528 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, |
f8eba3c6 | 11529 | (struct symtab *) NULL, 0); |
c5aa993b | 11530 | |
c906108c | 11531 | if (sals.nelts != 1) |
8a3fe4f8 | 11532 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11533 | |
c906108c | 11534 | sal = sals.sals[0]; |
4a64f543 | 11535 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11536 | |
c906108c | 11537 | if (*arg) |
8a3fe4f8 | 11538 | error (_("Junk at end of arguments.")); |
c5aa993b | 11539 | |
c906108c | 11540 | resolve_sal_pc (&sal); |
c5aa993b | 11541 | |
186c406b TT |
11542 | tp = inferior_thread (); |
11543 | thread = tp->num; | |
11544 | ||
883bc8d1 PA |
11545 | old_chain = make_cleanup (null_cleanup, NULL); |
11546 | ||
8556afb4 PA |
11547 | /* Note linespec handling above invalidates the frame chain. |
11548 | Installing a breakpoint also invalidates the frame chain (as it | |
11549 | may need to switch threads), so do any frame handling before | |
11550 | that. */ | |
11551 | ||
11552 | frame = get_selected_frame (NULL); | |
11553 | frame_gdbarch = get_frame_arch (frame); | |
11554 | stack_frame_id = get_stack_frame_id (frame); | |
11555 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11556 | |
ae66c1fc EZ |
11557 | /* Keep within the current frame, or in frames called by the current |
11558 | one. */ | |
edb3359d | 11559 | |
883bc8d1 | 11560 | if (frame_id_p (caller_frame_id)) |
c906108c | 11561 | { |
883bc8d1 PA |
11562 | struct symtab_and_line sal2; |
11563 | ||
11564 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11565 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 11566 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
11567 | sal2, |
11568 | caller_frame_id, | |
f107f563 VP |
11569 | bp_until); |
11570 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 11571 | |
883bc8d1 | 11572 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11573 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11574 | } |
c5aa993b | 11575 | |
c70a6932 JK |
11576 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11577 | frame = NULL; | |
11578 | ||
883bc8d1 PA |
11579 | if (anywhere) |
11580 | /* If the user told us to continue until a specified location, | |
11581 | we don't specify a frame at which we need to stop. */ | |
11582 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11583 | null_frame_id, bp_until); | |
11584 | else | |
11585 | /* Otherwise, specify the selected frame, because we want to stop | |
11586 | only at the very same frame. */ | |
11587 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11588 | stack_frame_id, bp_until); | |
11589 | make_cleanup_delete_breakpoint (breakpoint); | |
11590 | ||
64ce06e4 | 11591 | proceed (-1, GDB_SIGNAL_DEFAULT); |
f107f563 | 11592 | |
4a64f543 MS |
11593 | /* If we are running asynchronously, and proceed call above has |
11594 | actually managed to start the target, arrange for breakpoints to | |
11595 | be deleted when the target stops. Otherwise, we're already | |
11596 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 11597 | |
8ea051c5 | 11598 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 11599 | { |
bfec99b2 PA |
11600 | struct until_break_command_continuation_args *args; |
11601 | args = xmalloc (sizeof (*args)); | |
f107f563 | 11602 | |
bfec99b2 PA |
11603 | args->breakpoint = breakpoint; |
11604 | args->breakpoint2 = breakpoint2; | |
186c406b | 11605 | args->thread_num = thread; |
f107f563 VP |
11606 | |
11607 | discard_cleanups (old_chain); | |
95e54da7 PA |
11608 | add_continuation (inferior_thread (), |
11609 | until_break_command_continuation, args, | |
604ead4a | 11610 | xfree); |
f107f563 VP |
11611 | } |
11612 | else | |
c5aa993b | 11613 | do_cleanups (old_chain); |
f00aae0f KS |
11614 | |
11615 | do_cleanups (cleanup); | |
c906108c | 11616 | } |
ae66c1fc | 11617 | |
c906108c SS |
11618 | /* This function attempts to parse an optional "if <cond>" clause |
11619 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11620 | |
c906108c SS |
11621 | Else, it returns a pointer to the condition string. (It does not |
11622 | attempt to evaluate the string against a particular block.) And, | |
11623 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11624 | if clause in the arg string. */ |
53a5351d | 11625 | |
916703c0 | 11626 | char * |
fba45db2 | 11627 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11628 | { |
c5aa993b JM |
11629 | char *cond_string; |
11630 | ||
11631 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11632 | return NULL; |
c5aa993b | 11633 | |
4a64f543 | 11634 | /* Skip the "if" keyword. */ |
c906108c | 11635 | (*arg) += 2; |
c5aa993b | 11636 | |
c906108c | 11637 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11638 | condition string. */ |
e9cafbcc | 11639 | *arg = skip_spaces (*arg); |
c906108c | 11640 | cond_string = *arg; |
c5aa993b | 11641 | |
4a64f543 MS |
11642 | /* Assume that the condition occupies the remainder of the arg |
11643 | string. */ | |
c906108c | 11644 | (*arg) += strlen (cond_string); |
c5aa993b | 11645 | |
c906108c SS |
11646 | return cond_string; |
11647 | } | |
c5aa993b | 11648 | |
c906108c SS |
11649 | /* Commands to deal with catching events, such as signals, exceptions, |
11650 | process start/exit, etc. */ | |
c5aa993b JM |
11651 | |
11652 | typedef enum | |
11653 | { | |
44feb3ce TT |
11654 | catch_fork_temporary, catch_vfork_temporary, |
11655 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11656 | } |
11657 | catch_fork_kind; | |
11658 | ||
c906108c | 11659 | static void |
cc59ec59 MS |
11660 | catch_fork_command_1 (char *arg, int from_tty, |
11661 | struct cmd_list_element *command) | |
c906108c | 11662 | { |
a6d9a66e | 11663 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11664 | char *cond_string = NULL; |
44feb3ce TT |
11665 | catch_fork_kind fork_kind; |
11666 | int tempflag; | |
11667 | ||
11668 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11669 | tempflag = (fork_kind == catch_fork_temporary | |
11670 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11671 | |
44feb3ce TT |
11672 | if (!arg) |
11673 | arg = ""; | |
e9cafbcc | 11674 | arg = skip_spaces (arg); |
c5aa993b | 11675 | |
c906108c | 11676 | /* The allowed syntax is: |
c5aa993b JM |
11677 | catch [v]fork |
11678 | catch [v]fork if <cond> | |
11679 | ||
4a64f543 | 11680 | First, check if there's an if clause. */ |
c906108c | 11681 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11682 | |
c906108c | 11683 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11684 | error (_("Junk at end of arguments.")); |
c5aa993b | 11685 | |
c906108c | 11686 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11687 | and enable reporting of such events. */ |
c5aa993b JM |
11688 | switch (fork_kind) |
11689 | { | |
44feb3ce TT |
11690 | case catch_fork_temporary: |
11691 | case catch_fork_permanent: | |
a6d9a66e | 11692 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11693 | &catch_fork_breakpoint_ops); |
c906108c | 11694 | break; |
44feb3ce TT |
11695 | case catch_vfork_temporary: |
11696 | case catch_vfork_permanent: | |
a6d9a66e | 11697 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11698 | &catch_vfork_breakpoint_ops); |
c906108c | 11699 | break; |
c5aa993b | 11700 | default: |
8a3fe4f8 | 11701 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11702 | break; |
c5aa993b | 11703 | } |
c906108c SS |
11704 | } |
11705 | ||
11706 | static void | |
cc59ec59 MS |
11707 | catch_exec_command_1 (char *arg, int from_tty, |
11708 | struct cmd_list_element *command) | |
c906108c | 11709 | { |
b4d90040 | 11710 | struct exec_catchpoint *c; |
a6d9a66e | 11711 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11712 | int tempflag; |
c5aa993b | 11713 | char *cond_string = NULL; |
c906108c | 11714 | |
44feb3ce TT |
11715 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11716 | ||
11717 | if (!arg) | |
11718 | arg = ""; | |
e9cafbcc | 11719 | arg = skip_spaces (arg); |
c906108c SS |
11720 | |
11721 | /* The allowed syntax is: | |
c5aa993b JM |
11722 | catch exec |
11723 | catch exec if <cond> | |
c906108c | 11724 | |
4a64f543 | 11725 | First, check if there's an if clause. */ |
c906108c SS |
11726 | cond_string = ep_parse_optional_if_clause (&arg); |
11727 | ||
11728 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11729 | error (_("Junk at end of arguments.")); |
c906108c | 11730 | |
b4d90040 PA |
11731 | c = XNEW (struct exec_catchpoint); |
11732 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11733 | &catch_exec_breakpoint_ops); | |
11734 | c->exec_pathname = NULL; | |
11735 | ||
3ea46bff | 11736 | install_breakpoint (0, &c->base, 1); |
c906108c | 11737 | } |
c5aa993b | 11738 | |
9ac4176b | 11739 | void |
28010a5d PA |
11740 | init_ada_exception_breakpoint (struct breakpoint *b, |
11741 | struct gdbarch *gdbarch, | |
11742 | struct symtab_and_line sal, | |
11743 | char *addr_string, | |
c0a91b2b | 11744 | const struct breakpoint_ops *ops, |
28010a5d | 11745 | int tempflag, |
349774ef | 11746 | int enabled, |
28010a5d | 11747 | int from_tty) |
f7f9143b | 11748 | { |
f7f9143b JB |
11749 | if (from_tty) |
11750 | { | |
5af949e3 UW |
11751 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11752 | if (!loc_gdbarch) | |
11753 | loc_gdbarch = gdbarch; | |
11754 | ||
6c95b8df PA |
11755 | describe_other_breakpoints (loc_gdbarch, |
11756 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11757 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11758 | version for exception catchpoints, because two catchpoints | |
11759 | used for different exception names will use the same address. | |
11760 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11761 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11762 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11763 | the user what type of catchpoint it is. The above is good |
11764 | enough for now, though. */ | |
11765 | } | |
11766 | ||
28010a5d | 11767 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11768 | |
349774ef | 11769 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11770 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f00aae0f KS |
11771 | b->location = string_to_event_location (&addr_string, |
11772 | language_def (language_ada)); | |
f7f9143b | 11773 | b->language = language_ada; |
f7f9143b JB |
11774 | } |
11775 | ||
c906108c | 11776 | static void |
fba45db2 | 11777 | catch_command (char *arg, int from_tty) |
c906108c | 11778 | { |
44feb3ce | 11779 | error (_("Catch requires an event name.")); |
c906108c SS |
11780 | } |
11781 | \f | |
11782 | ||
11783 | static void | |
fba45db2 | 11784 | tcatch_command (char *arg, int from_tty) |
c906108c | 11785 | { |
44feb3ce | 11786 | error (_("Catch requires an event name.")); |
c906108c SS |
11787 | } |
11788 | ||
8a2c437b TT |
11789 | /* A qsort comparison function that sorts breakpoints in order. */ |
11790 | ||
11791 | static int | |
11792 | compare_breakpoints (const void *a, const void *b) | |
11793 | { | |
11794 | const breakpoint_p *ba = a; | |
11795 | uintptr_t ua = (uintptr_t) *ba; | |
11796 | const breakpoint_p *bb = b; | |
11797 | uintptr_t ub = (uintptr_t) *bb; | |
11798 | ||
11799 | if ((*ba)->number < (*bb)->number) | |
11800 | return -1; | |
11801 | else if ((*ba)->number > (*bb)->number) | |
11802 | return 1; | |
11803 | ||
11804 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11805 | the number 0. */ | |
11806 | if (ua < ub) | |
11807 | return -1; | |
94b0e70d | 11808 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11809 | } |
11810 | ||
80f8a6eb | 11811 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11812 | |
11813 | static void | |
fba45db2 | 11814 | clear_command (char *arg, int from_tty) |
c906108c | 11815 | { |
8a2c437b | 11816 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11817 | VEC(breakpoint_p) *found = 0; |
11818 | int ix; | |
c906108c SS |
11819 | int default_match; |
11820 | struct symtabs_and_lines sals; | |
11821 | struct symtab_and_line sal; | |
c906108c | 11822 | int i; |
8a2c437b | 11823 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11824 | |
11825 | if (arg) | |
11826 | { | |
39cf75f7 DE |
11827 | sals = decode_line_with_current_source (arg, |
11828 | (DECODE_LINE_FUNFIRSTLINE | |
11829 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 11830 | make_cleanup (xfree, sals.sals); |
c906108c SS |
11831 | default_match = 0; |
11832 | } | |
11833 | else | |
11834 | { | |
c5aa993b | 11835 | sals.sals = (struct symtab_and_line *) |
c906108c | 11836 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 11837 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11838 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11839 | |
11840 | /* Set sal's line, symtab, pc, and pspace to the values | |
11841 | corresponding to the last call to print_frame_info. If the | |
11842 | codepoint is not valid, this will set all the fields to 0. */ | |
11843 | get_last_displayed_sal (&sal); | |
c906108c | 11844 | if (sal.symtab == 0) |
8a3fe4f8 | 11845 | error (_("No source file specified.")); |
c906108c SS |
11846 | |
11847 | sals.sals[0] = sal; | |
11848 | sals.nelts = 1; | |
11849 | ||
11850 | default_match = 1; | |
11851 | } | |
11852 | ||
4a64f543 MS |
11853 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11854 | seems, because all existing breakpoints typically have both | |
11855 | file/line and pc set. So, if clear is given file/line, we can | |
11856 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11857 | |
11858 | We only support clearing given the address explicitly | |
11859 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11860 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11861 | due to optimization, all in one block. |
4a64f543 MS |
11862 | |
11863 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11864 | PC corresponding to the same file:line, the breakpoint won't |
11865 | be cleared. We probably can still clear the breakpoint, but | |
11866 | since the other PC value is never presented to user, user | |
11867 | can only find it by guessing, and it does not seem important | |
11868 | to support that. */ | |
11869 | ||
4a64f543 MS |
11870 | /* For each line spec given, delete bps which correspond to it. Do |
11871 | it in two passes, solely to preserve the current behavior that | |
11872 | from_tty is forced true if we delete more than one | |
11873 | breakpoint. */ | |
c906108c | 11874 | |
80f8a6eb | 11875 | found = NULL; |
8a2c437b | 11876 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
11877 | for (i = 0; i < sals.nelts; i++) |
11878 | { | |
05cba821 JK |
11879 | const char *sal_fullname; |
11880 | ||
c906108c | 11881 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11882 | If line given (pc == 0), clear all bpts on specified line. |
11883 | If defaulting, clear all bpts on default line | |
c906108c | 11884 | or at default pc. |
c5aa993b JM |
11885 | |
11886 | defaulting sal.pc != 0 tests to do | |
11887 | ||
11888 | 0 1 pc | |
11889 | 1 1 pc _and_ line | |
11890 | 0 0 line | |
11891 | 1 0 <can't happen> */ | |
c906108c SS |
11892 | |
11893 | sal = sals.sals[i]; | |
05cba821 JK |
11894 | sal_fullname = (sal.symtab == NULL |
11895 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11896 | |
4a64f543 | 11897 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11898 | ALL_BREAKPOINTS (b) |
c5aa993b | 11899 | { |
0d381245 | 11900 | int match = 0; |
4a64f543 | 11901 | /* Are we going to delete b? */ |
cc60f2e3 | 11902 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11903 | { |
11904 | struct bp_location *loc = b->loc; | |
11905 | for (; loc; loc = loc->next) | |
11906 | { | |
f8eba3c6 TT |
11907 | /* If the user specified file:line, don't allow a PC |
11908 | match. This matches historical gdb behavior. */ | |
11909 | int pc_match = (!sal.explicit_line | |
11910 | && sal.pc | |
11911 | && (loc->pspace == sal.pspace) | |
11912 | && (loc->address == sal.pc) | |
11913 | && (!section_is_overlay (loc->section) | |
11914 | || loc->section == sal.section)); | |
4aac40c8 TT |
11915 | int line_match = 0; |
11916 | ||
11917 | if ((default_match || sal.explicit_line) | |
2f202fde | 11918 | && loc->symtab != NULL |
05cba821 | 11919 | && sal_fullname != NULL |
4aac40c8 | 11920 | && sal.pspace == loc->pspace |
05cba821 JK |
11921 | && loc->line_number == sal.line |
11922 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11923 | sal_fullname) == 0) | |
11924 | line_match = 1; | |
4aac40c8 | 11925 | |
0d381245 VP |
11926 | if (pc_match || line_match) |
11927 | { | |
11928 | match = 1; | |
11929 | break; | |
11930 | } | |
11931 | } | |
11932 | } | |
11933 | ||
11934 | if (match) | |
d6e956e5 | 11935 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 11936 | } |
80f8a6eb | 11937 | } |
8a2c437b | 11938 | |
80f8a6eb | 11939 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 11940 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
11941 | { |
11942 | if (arg) | |
8a3fe4f8 | 11943 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11944 | else |
8a3fe4f8 | 11945 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11946 | } |
c906108c | 11947 | |
8a2c437b TT |
11948 | /* Remove duplicates from the vec. */ |
11949 | qsort (VEC_address (breakpoint_p, found), | |
11950 | VEC_length (breakpoint_p, found), | |
11951 | sizeof (breakpoint_p), | |
11952 | compare_breakpoints); | |
11953 | prev = VEC_index (breakpoint_p, found, 0); | |
11954 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
11955 | { | |
11956 | if (b == prev) | |
11957 | { | |
11958 | VEC_ordered_remove (breakpoint_p, found, ix); | |
11959 | --ix; | |
11960 | } | |
11961 | } | |
11962 | ||
d6e956e5 | 11963 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 11964 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11965 | if (from_tty) |
a3f17187 | 11966 | { |
d6e956e5 | 11967 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
11968 | printf_unfiltered (_("Deleted breakpoint ")); |
11969 | else | |
11970 | printf_unfiltered (_("Deleted breakpoints ")); | |
11971 | } | |
d6e956e5 VP |
11972 | |
11973 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 11974 | { |
c5aa993b | 11975 | if (from_tty) |
d6e956e5 VP |
11976 | printf_unfiltered ("%d ", b->number); |
11977 | delete_breakpoint (b); | |
c906108c | 11978 | } |
80f8a6eb MS |
11979 | if (from_tty) |
11980 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
11981 | |
11982 | do_cleanups (cleanups); | |
c906108c SS |
11983 | } |
11984 | \f | |
11985 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11986 | all breakpoints that are marked for deletion, whether hit or not. | |
11987 | This is called after any breakpoint is hit, or after errors. */ | |
11988 | ||
11989 | void | |
fba45db2 | 11990 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11991 | { |
35df4500 | 11992 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11993 | |
11994 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11995 | if (bs->breakpoint_at |
11996 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11997 | && bs->stop) |
f431efe5 | 11998 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11999 | |
35df4500 | 12000 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12001 | { |
b5de0fa7 | 12002 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12003 | delete_breakpoint (b); |
12004 | } | |
c906108c SS |
12005 | } |
12006 | ||
4a64f543 MS |
12007 | /* A comparison function for bp_location AP and BP being interfaced to |
12008 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12009 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 12010 | secondarily by ordering first permanent elements and |
4a64f543 | 12011 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 12012 | qsort being an unstable algorithm. */ |
876fa593 JK |
12013 | |
12014 | static int | |
494cfb0f | 12015 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12016 | { |
494cfb0f JK |
12017 | struct bp_location *a = *(void **) ap; |
12018 | struct bp_location *b = *(void **) bp; | |
876fa593 JK |
12019 | |
12020 | if (a->address != b->address) | |
12021 | return (a->address > b->address) - (a->address < b->address); | |
12022 | ||
dea2aa5f LM |
12023 | /* Sort locations at the same address by their pspace number, keeping |
12024 | locations of the same inferior (in a multi-inferior environment) | |
12025 | grouped. */ | |
12026 | ||
12027 | if (a->pspace->num != b->pspace->num) | |
12028 | return ((a->pspace->num > b->pspace->num) | |
12029 | - (a->pspace->num < b->pspace->num)); | |
12030 | ||
876fa593 | 12031 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
12032 | if (a->permanent != b->permanent) |
12033 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 12034 | |
c56a97f9 JK |
12035 | /* Make the internal GDB representation stable across GDB runs |
12036 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12037 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12038 | |
12039 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12040 | return ((a->owner->number > b->owner->number) |
12041 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12042 | |
12043 | return (a > b) - (a < b); | |
12044 | } | |
12045 | ||
876fa593 | 12046 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12047 | bp_location_shadow_len_after_address_max according to the current |
12048 | content of the bp_location array. */ | |
f7545552 TT |
12049 | |
12050 | static void | |
876fa593 | 12051 | bp_location_target_extensions_update (void) |
f7545552 | 12052 | { |
876fa593 JK |
12053 | struct bp_location *bl, **blp_tmp; |
12054 | ||
12055 | bp_location_placed_address_before_address_max = 0; | |
12056 | bp_location_shadow_len_after_address_max = 0; | |
12057 | ||
12058 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12059 | { | |
12060 | CORE_ADDR start, end, addr; | |
12061 | ||
12062 | if (!bp_location_has_shadow (bl)) | |
12063 | continue; | |
12064 | ||
12065 | start = bl->target_info.placed_address; | |
12066 | end = start + bl->target_info.shadow_len; | |
12067 | ||
12068 | gdb_assert (bl->address >= start); | |
12069 | addr = bl->address - start; | |
12070 | if (addr > bp_location_placed_address_before_address_max) | |
12071 | bp_location_placed_address_before_address_max = addr; | |
12072 | ||
12073 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12074 | ||
12075 | gdb_assert (bl->address < end); | |
12076 | addr = end - bl->address; | |
12077 | if (addr > bp_location_shadow_len_after_address_max) | |
12078 | bp_location_shadow_len_after_address_max = addr; | |
12079 | } | |
f7545552 TT |
12080 | } |
12081 | ||
1e4d1764 YQ |
12082 | /* Download tracepoint locations if they haven't been. */ |
12083 | ||
12084 | static void | |
12085 | download_tracepoint_locations (void) | |
12086 | { | |
7ed2c994 | 12087 | struct breakpoint *b; |
1e4d1764 YQ |
12088 | struct cleanup *old_chain; |
12089 | ||
12090 | if (!target_can_download_tracepoint ()) | |
12091 | return; | |
12092 | ||
12093 | old_chain = save_current_space_and_thread (); | |
12094 | ||
7ed2c994 | 12095 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12096 | { |
7ed2c994 | 12097 | struct bp_location *bl; |
1e4d1764 | 12098 | struct tracepoint *t; |
f2a8bc8a | 12099 | int bp_location_downloaded = 0; |
1e4d1764 | 12100 | |
7ed2c994 | 12101 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12102 | ? !may_insert_fast_tracepoints |
12103 | : !may_insert_tracepoints)) | |
12104 | continue; | |
12105 | ||
7ed2c994 YQ |
12106 | for (bl = b->loc; bl; bl = bl->next) |
12107 | { | |
12108 | /* In tracepoint, locations are _never_ duplicated, so | |
12109 | should_be_inserted is equivalent to | |
12110 | unduplicated_should_be_inserted. */ | |
12111 | if (!should_be_inserted (bl) || bl->inserted) | |
12112 | continue; | |
1e4d1764 | 12113 | |
7ed2c994 | 12114 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12115 | |
7ed2c994 | 12116 | target_download_tracepoint (bl); |
1e4d1764 | 12117 | |
7ed2c994 | 12118 | bl->inserted = 1; |
f2a8bc8a | 12119 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12120 | } |
12121 | t = (struct tracepoint *) b; | |
12122 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12123 | if (bp_location_downloaded) |
12124 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12125 | } |
12126 | ||
12127 | do_cleanups (old_chain); | |
12128 | } | |
12129 | ||
934709f0 PW |
12130 | /* Swap the insertion/duplication state between two locations. */ |
12131 | ||
12132 | static void | |
12133 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12134 | { | |
12135 | const int left_inserted = left->inserted; | |
12136 | const int left_duplicate = left->duplicate; | |
b775012e | 12137 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12138 | const struct bp_target_info left_target_info = left->target_info; |
12139 | ||
1e4d1764 YQ |
12140 | /* Locations of tracepoints can never be duplicated. */ |
12141 | if (is_tracepoint (left->owner)) | |
12142 | gdb_assert (!left->duplicate); | |
12143 | if (is_tracepoint (right->owner)) | |
12144 | gdb_assert (!right->duplicate); | |
12145 | ||
934709f0 PW |
12146 | left->inserted = right->inserted; |
12147 | left->duplicate = right->duplicate; | |
b775012e | 12148 | left->needs_update = right->needs_update; |
934709f0 PW |
12149 | left->target_info = right->target_info; |
12150 | right->inserted = left_inserted; | |
12151 | right->duplicate = left_duplicate; | |
b775012e | 12152 | right->needs_update = left_needs_update; |
934709f0 PW |
12153 | right->target_info = left_target_info; |
12154 | } | |
12155 | ||
b775012e LM |
12156 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12157 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12158 | conditions on the target's side. Such conditions need to be updated on | |
12159 | the target. */ | |
12160 | ||
12161 | static void | |
12162 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12163 | { | |
12164 | struct bp_location **locp = NULL, **loc2p; | |
12165 | struct bp_location *loc; | |
12166 | CORE_ADDR address = 0; | |
12167 | int pspace_num; | |
12168 | ||
12169 | address = bl->address; | |
12170 | pspace_num = bl->pspace->num; | |
12171 | ||
12172 | /* This is only meaningful if the target is | |
12173 | evaluating conditions and if the user has | |
12174 | opted for condition evaluation on the target's | |
12175 | side. */ | |
12176 | if (gdb_evaluates_breakpoint_condition_p () | |
12177 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12178 | return; | |
12179 | ||
12180 | /* Flag all breakpoint locations with this address and | |
12181 | the same program space as the location | |
12182 | as "its condition has changed". We need to | |
12183 | update the conditions on the target's side. */ | |
12184 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12185 | { | |
12186 | loc = *loc2p; | |
12187 | ||
12188 | if (!is_breakpoint (loc->owner) | |
12189 | || pspace_num != loc->pspace->num) | |
12190 | continue; | |
12191 | ||
12192 | /* Flag the location appropriately. We use a different state to | |
12193 | let everyone know that we already updated the set of locations | |
12194 | with addr bl->address and program space bl->pspace. This is so | |
12195 | we don't have to keep calling these functions just to mark locations | |
12196 | that have already been marked. */ | |
12197 | loc->condition_changed = condition_updated; | |
12198 | ||
12199 | /* Free the agent expression bytecode as well. We will compute | |
12200 | it later on. */ | |
12201 | if (loc->cond_bytecode) | |
12202 | { | |
12203 | free_agent_expr (loc->cond_bytecode); | |
12204 | loc->cond_bytecode = NULL; | |
12205 | } | |
12206 | } | |
12207 | } | |
44702360 PA |
12208 | /* Called whether new breakpoints are created, or existing breakpoints |
12209 | deleted, to update the global location list and recompute which | |
12210 | locations are duplicate of which. | |
b775012e | 12211 | |
04086b45 PA |
12212 | The INSERT_MODE flag determines whether locations may not, may, or |
12213 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12214 | info. */ | |
b60e7edf | 12215 | |
0d381245 | 12216 | static void |
44702360 | 12217 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12218 | { |
74960c60 | 12219 | struct breakpoint *b; |
876fa593 | 12220 | struct bp_location **locp, *loc; |
f7545552 | 12221 | struct cleanup *cleanups; |
b775012e LM |
12222 | /* Last breakpoint location address that was marked for update. */ |
12223 | CORE_ADDR last_addr = 0; | |
12224 | /* Last breakpoint location program space that was marked for update. */ | |
12225 | int last_pspace_num = -1; | |
f7545552 | 12226 | |
2d134ed3 PA |
12227 | /* Used in the duplicates detection below. When iterating over all |
12228 | bp_locations, points to the first bp_location of a given address. | |
12229 | Breakpoints and watchpoints of different types are never | |
12230 | duplicates of each other. Keep one pointer for each type of | |
12231 | breakpoint/watchpoint, so we only need to loop over all locations | |
12232 | once. */ | |
12233 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12234 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12235 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12236 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12237 | |
4a64f543 MS |
12238 | /* Saved former bp_location array which we compare against the newly |
12239 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12240 | struct bp_location **old_location, **old_locp; |
12241 | unsigned old_location_count; | |
12242 | ||
12243 | old_location = bp_location; | |
12244 | old_location_count = bp_location_count; | |
12245 | bp_location = NULL; | |
12246 | bp_location_count = 0; | |
12247 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12248 | |
74960c60 | 12249 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12250 | for (loc = b->loc; loc; loc = loc->next) |
12251 | bp_location_count++; | |
12252 | ||
12253 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
12254 | locp = bp_location; | |
12255 | ALL_BREAKPOINTS (b) | |
12256 | for (loc = b->loc; loc; loc = loc->next) | |
12257 | *locp++ = loc; | |
12258 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12259 | bp_location_compare); |
876fa593 JK |
12260 | |
12261 | bp_location_target_extensions_update (); | |
74960c60 | 12262 | |
4a64f543 MS |
12263 | /* Identify bp_location instances that are no longer present in the |
12264 | new list, and therefore should be freed. Note that it's not | |
12265 | necessary that those locations should be removed from inferior -- | |
12266 | if there's another location at the same address (previously | |
12267 | marked as duplicate), we don't need to remove/insert the | |
12268 | location. | |
876fa593 | 12269 | |
4a64f543 MS |
12270 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12271 | and former bp_location array state respectively. */ | |
876fa593 JK |
12272 | |
12273 | locp = bp_location; | |
12274 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12275 | old_locp++) | |
74960c60 | 12276 | { |
876fa593 | 12277 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12278 | struct bp_location **loc2p; |
876fa593 | 12279 | |
e5dd4106 | 12280 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12281 | not, we have to free it. */ |
c7d46a38 | 12282 | int found_object = 0; |
20874c92 VP |
12283 | /* Tells if the location should remain inserted in the target. */ |
12284 | int keep_in_target = 0; | |
12285 | int removed = 0; | |
876fa593 | 12286 | |
4a64f543 MS |
12287 | /* Skip LOCP entries which will definitely never be needed. |
12288 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12289 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12290 | && (*locp)->address < old_loc->address) |
876fa593 | 12291 | locp++; |
c7d46a38 PA |
12292 | |
12293 | for (loc2p = locp; | |
12294 | (loc2p < bp_location + bp_location_count | |
12295 | && (*loc2p)->address == old_loc->address); | |
12296 | loc2p++) | |
12297 | { | |
b775012e LM |
12298 | /* Check if this is a new/duplicated location or a duplicated |
12299 | location that had its condition modified. If so, we want to send | |
12300 | its condition to the target if evaluation of conditions is taking | |
12301 | place there. */ | |
12302 | if ((*loc2p)->condition_changed == condition_modified | |
12303 | && (last_addr != old_loc->address | |
12304 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12305 | { |
b775012e LM |
12306 | force_breakpoint_reinsertion (*loc2p); |
12307 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12308 | } |
b775012e LM |
12309 | |
12310 | if (*loc2p == old_loc) | |
12311 | found_object = 1; | |
c7d46a38 | 12312 | } |
74960c60 | 12313 | |
b775012e LM |
12314 | /* We have already handled this address, update it so that we don't |
12315 | have to go through updates again. */ | |
12316 | last_addr = old_loc->address; | |
12317 | ||
12318 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12319 | if (!found_object) | |
12320 | force_breakpoint_reinsertion (old_loc); | |
12321 | ||
4a64f543 MS |
12322 | /* If this location is no longer present, and inserted, look if |
12323 | there's maybe a new location at the same address. If so, | |
12324 | mark that one inserted, and don't remove this one. This is | |
12325 | needed so that we don't have a time window where a breakpoint | |
12326 | at certain location is not inserted. */ | |
74960c60 | 12327 | |
876fa593 | 12328 | if (old_loc->inserted) |
0d381245 | 12329 | { |
4a64f543 MS |
12330 | /* If the location is inserted now, we might have to remove |
12331 | it. */ | |
74960c60 | 12332 | |
876fa593 | 12333 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12334 | { |
4a64f543 MS |
12335 | /* The location is still present in the location list, |
12336 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12337 | keep_in_target = 1; |
74960c60 VP |
12338 | } |
12339 | else | |
12340 | { | |
b775012e LM |
12341 | /* This location still exists, but it won't be kept in the |
12342 | target since it may have been disabled. We proceed to | |
12343 | remove its target-side condition. */ | |
12344 | ||
4a64f543 MS |
12345 | /* The location is either no longer present, or got |
12346 | disabled. See if there's another location at the | |
12347 | same address, in which case we don't need to remove | |
12348 | this one from the target. */ | |
876fa593 | 12349 | |
2bdf28a0 | 12350 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12351 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12352 | { | |
876fa593 | 12353 | for (loc2p = locp; |
c7d46a38 PA |
12354 | (loc2p < bp_location + bp_location_count |
12355 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12356 | loc2p++) |
12357 | { | |
12358 | struct bp_location *loc2 = *loc2p; | |
12359 | ||
2d134ed3 | 12360 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12361 | { |
85d721b8 PA |
12362 | /* Read watchpoint locations are switched to |
12363 | access watchpoints, if the former are not | |
12364 | supported, but the latter are. */ | |
12365 | if (is_hardware_watchpoint (old_loc->owner)) | |
12366 | { | |
12367 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12368 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12369 | } | |
12370 | ||
934709f0 PW |
12371 | /* loc2 is a duplicated location. We need to check |
12372 | if it should be inserted in case it will be | |
12373 | unduplicated. */ | |
12374 | if (loc2 != old_loc | |
12375 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12376 | { |
934709f0 | 12377 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12378 | keep_in_target = 1; |
12379 | break; | |
12380 | } | |
876fa593 JK |
12381 | } |
12382 | } | |
12383 | } | |
74960c60 VP |
12384 | } |
12385 | ||
20874c92 VP |
12386 | if (!keep_in_target) |
12387 | { | |
876fa593 | 12388 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12389 | { |
4a64f543 MS |
12390 | /* This is just about all we can do. We could keep |
12391 | this location on the global list, and try to | |
12392 | remove it next time, but there's no particular | |
12393 | reason why we will succeed next time. | |
20874c92 | 12394 | |
4a64f543 MS |
12395 | Note that at this point, old_loc->owner is still |
12396 | valid, as delete_breakpoint frees the breakpoint | |
12397 | only after calling us. */ | |
3e43a32a MS |
12398 | printf_filtered (_("warning: Error removing " |
12399 | "breakpoint %d\n"), | |
876fa593 | 12400 | old_loc->owner->number); |
20874c92 VP |
12401 | } |
12402 | removed = 1; | |
12403 | } | |
0d381245 | 12404 | } |
74960c60 VP |
12405 | |
12406 | if (!found_object) | |
1c5cfe86 | 12407 | { |
fbea99ea | 12408 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12409 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12410 | { |
db82e815 PA |
12411 | /* This location was removed from the target. In |
12412 | non-stop mode, a race condition is possible where | |
12413 | we've removed a breakpoint, but stop events for that | |
12414 | breakpoint are already queued and will arrive later. | |
12415 | We apply an heuristic to be able to distinguish such | |
12416 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12417 | breakpoint location for a bit, and will retire it | |
12418 | after we see some number of events. The theory here | |
12419 | is that reporting of events should, "on the average", | |
12420 | be fair, so after a while we'll see events from all | |
12421 | threads that have anything of interest, and no longer | |
12422 | need to keep this breakpoint location around. We | |
12423 | don't hold locations forever so to reduce chances of | |
12424 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12425 | SIGTRAP. | |
12426 | ||
12427 | The heuristic failing can be disastrous on | |
12428 | decr_pc_after_break targets. | |
12429 | ||
12430 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12431 | if we fail to recognize a late breakpoint SIGTRAP, | |
12432 | because events_till_retirement has reached 0 too | |
12433 | soon, we'll fail to do the PC adjustment, and report | |
12434 | a random SIGTRAP to the user. When the user resumes | |
12435 | the inferior, it will most likely immediately crash | |
2dec564e | 12436 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12437 | corrupted, because of being resumed e.g., in the |
12438 | middle of a multi-byte instruction, or skipped a | |
12439 | one-byte instruction. This was actually seen happen | |
12440 | on native x86-linux, and should be less rare on | |
12441 | targets that do not support new thread events, like | |
12442 | remote, due to the heuristic depending on | |
12443 | thread_count. | |
12444 | ||
12445 | Mistaking a random SIGTRAP for a breakpoint trap | |
12446 | causes similar symptoms (PC adjustment applied when | |
12447 | it shouldn't), but then again, playing with SIGTRAPs | |
12448 | behind the debugger's back is asking for trouble. | |
12449 | ||
12450 | Since hardware watchpoint traps are always | |
12451 | distinguishable from other traps, so we don't need to | |
12452 | apply keep hardware watchpoint moribund locations | |
12453 | around. We simply always ignore hardware watchpoint | |
12454 | traps we can no longer explain. */ | |
12455 | ||
876fa593 JK |
12456 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12457 | old_loc->owner = NULL; | |
20874c92 | 12458 | |
876fa593 | 12459 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12460 | } |
12461 | else | |
f431efe5 PA |
12462 | { |
12463 | old_loc->owner = NULL; | |
12464 | decref_bp_location (&old_loc); | |
12465 | } | |
20874c92 | 12466 | } |
74960c60 | 12467 | } |
1c5cfe86 | 12468 | |
348d480f PA |
12469 | /* Rescan breakpoints at the same address and section, marking the |
12470 | first one as "first" and any others as "duplicates". This is so | |
12471 | that the bpt instruction is only inserted once. If we have a | |
12472 | permanent breakpoint at the same place as BPT, make that one the | |
12473 | official one, and the rest as duplicates. Permanent breakpoints | |
12474 | are sorted first for the same address. | |
12475 | ||
12476 | Do the same for hardware watchpoints, but also considering the | |
12477 | watchpoint's type (regular/access/read) and length. */ | |
12478 | ||
12479 | bp_loc_first = NULL; | |
12480 | wp_loc_first = NULL; | |
12481 | awp_loc_first = NULL; | |
12482 | rwp_loc_first = NULL; | |
12483 | ALL_BP_LOCATIONS (loc, locp) | |
12484 | { | |
12485 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12486 | non-NULL. */ | |
348d480f | 12487 | struct bp_location **loc_first_p; |
d3fbdd86 | 12488 | b = loc->owner; |
348d480f | 12489 | |
6f380991 | 12490 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12491 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12492 | /* Don't detect duplicate for tracepoint locations because they are |
12493 | never duplicated. See the comments in field `duplicate' of | |
12494 | `struct bp_location'. */ | |
348d480f | 12495 | || is_tracepoint (b)) |
b775012e LM |
12496 | { |
12497 | /* Clear the condition modification flag. */ | |
12498 | loc->condition_changed = condition_unchanged; | |
12499 | continue; | |
12500 | } | |
348d480f | 12501 | |
348d480f PA |
12502 | if (b->type == bp_hardware_watchpoint) |
12503 | loc_first_p = &wp_loc_first; | |
12504 | else if (b->type == bp_read_watchpoint) | |
12505 | loc_first_p = &rwp_loc_first; | |
12506 | else if (b->type == bp_access_watchpoint) | |
12507 | loc_first_p = &awp_loc_first; | |
12508 | else | |
12509 | loc_first_p = &bp_loc_first; | |
12510 | ||
12511 | if (*loc_first_p == NULL | |
12512 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12513 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12514 | { | |
12515 | *loc_first_p = loc; | |
12516 | loc->duplicate = 0; | |
b775012e LM |
12517 | |
12518 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12519 | { | |
12520 | loc->needs_update = 1; | |
12521 | /* Clear the condition modification flag. */ | |
12522 | loc->condition_changed = condition_unchanged; | |
12523 | } | |
348d480f PA |
12524 | continue; |
12525 | } | |
12526 | ||
934709f0 PW |
12527 | |
12528 | /* This and the above ensure the invariant that the first location | |
12529 | is not duplicated, and is the inserted one. | |
12530 | All following are marked as duplicated, and are not inserted. */ | |
12531 | if (loc->inserted) | |
12532 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12533 | loc->duplicate = 1; |
12534 | ||
b775012e LM |
12535 | /* Clear the condition modification flag. */ |
12536 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12537 | } |
12538 | ||
a25a5a45 | 12539 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12540 | { |
04086b45 | 12541 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12542 | insert_breakpoint_locations (); |
12543 | else | |
12544 | { | |
44702360 PA |
12545 | /* Even though the caller told us to not insert new |
12546 | locations, we may still need to update conditions on the | |
12547 | target's side of breakpoints that were already inserted | |
12548 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12549 | only update conditions for locations that are marked |
12550 | "needs_update". */ | |
12551 | update_inserted_breakpoint_locations (); | |
12552 | } | |
12553 | } | |
348d480f | 12554 | |
04086b45 | 12555 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12556 | download_tracepoint_locations (); |
12557 | ||
348d480f PA |
12558 | do_cleanups (cleanups); |
12559 | } | |
12560 | ||
12561 | void | |
12562 | breakpoint_retire_moribund (void) | |
12563 | { | |
12564 | struct bp_location *loc; | |
12565 | int ix; | |
12566 | ||
12567 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12568 | if (--(loc->events_till_retirement) == 0) | |
12569 | { | |
12570 | decref_bp_location (&loc); | |
12571 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12572 | --ix; | |
12573 | } | |
12574 | } | |
12575 | ||
12576 | static void | |
44702360 | 12577 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12578 | { |
348d480f | 12579 | |
492d29ea PA |
12580 | TRY |
12581 | { | |
12582 | update_global_location_list (insert_mode); | |
12583 | } | |
12584 | CATCH (e, RETURN_MASK_ERROR) | |
12585 | { | |
12586 | } | |
12587 | END_CATCH | |
348d480f PA |
12588 | } |
12589 | ||
12590 | /* Clear BKP from a BPS. */ | |
12591 | ||
12592 | static void | |
12593 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12594 | { | |
12595 | bpstat bs; | |
12596 | ||
12597 | for (bs = bps; bs; bs = bs->next) | |
12598 | if (bs->breakpoint_at == bpt) | |
12599 | { | |
12600 | bs->breakpoint_at = NULL; | |
12601 | bs->old_val = NULL; | |
12602 | /* bs->commands will be freed later. */ | |
12603 | } | |
12604 | } | |
12605 | ||
12606 | /* Callback for iterate_over_threads. */ | |
12607 | static int | |
12608 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12609 | { | |
12610 | struct breakpoint *bpt = data; | |
12611 | ||
12612 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12613 | return 0; | |
12614 | } | |
12615 | ||
12616 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12617 | callbacks. */ | |
12618 | ||
12619 | static void | |
12620 | say_where (struct breakpoint *b) | |
12621 | { | |
12622 | struct value_print_options opts; | |
12623 | ||
12624 | get_user_print_options (&opts); | |
12625 | ||
12626 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12627 | single string. */ | |
12628 | if (b->loc == NULL) | |
12629 | { | |
f00aae0f KS |
12630 | /* For pending locations, the output differs slightly based |
12631 | on b->extra_string. If this is non-NULL, it contains either | |
12632 | a condition or dprintf arguments. */ | |
12633 | if (b->extra_string == NULL) | |
12634 | { | |
12635 | printf_filtered (_(" (%s) pending."), | |
12636 | event_location_to_string (b->location)); | |
12637 | } | |
12638 | else if (b->type == bp_dprintf) | |
12639 | { | |
12640 | printf_filtered (_(" (%s,%s) pending."), | |
12641 | event_location_to_string (b->location), | |
12642 | b->extra_string); | |
12643 | } | |
12644 | else | |
12645 | { | |
12646 | printf_filtered (_(" (%s %s) pending."), | |
12647 | event_location_to_string (b->location), | |
12648 | b->extra_string); | |
12649 | } | |
348d480f PA |
12650 | } |
12651 | else | |
12652 | { | |
2f202fde | 12653 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12654 | { |
12655 | printf_filtered (" at "); | |
12656 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12657 | gdb_stdout); | |
12658 | } | |
2f202fde | 12659 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12660 | { |
12661 | /* If there is a single location, we can print the location | |
12662 | more nicely. */ | |
12663 | if (b->loc->next == NULL) | |
12664 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12665 | symtab_to_filename_for_display (b->loc->symtab), |
12666 | b->loc->line_number); | |
f8eba3c6 TT |
12667 | else |
12668 | /* This is not ideal, but each location may have a | |
12669 | different file name, and this at least reflects the | |
12670 | real situation somewhat. */ | |
f00aae0f KS |
12671 | printf_filtered (": %s.", |
12672 | event_location_to_string (b->location)); | |
f8eba3c6 | 12673 | } |
348d480f PA |
12674 | |
12675 | if (b->loc->next) | |
12676 | { | |
12677 | struct bp_location *loc = b->loc; | |
12678 | int n = 0; | |
12679 | for (; loc; loc = loc->next) | |
12680 | ++n; | |
12681 | printf_filtered (" (%d locations)", n); | |
12682 | } | |
12683 | } | |
12684 | } | |
12685 | ||
348d480f PA |
12686 | /* Default bp_location_ops methods. */ |
12687 | ||
12688 | static void | |
12689 | bp_location_dtor (struct bp_location *self) | |
12690 | { | |
12691 | xfree (self->cond); | |
b775012e LM |
12692 | if (self->cond_bytecode) |
12693 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12694 | xfree (self->function_name); |
8b4f3082 PA |
12695 | |
12696 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12697 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12698 | } |
12699 | ||
12700 | static const struct bp_location_ops bp_location_ops = | |
12701 | { | |
12702 | bp_location_dtor | |
12703 | }; | |
12704 | ||
2060206e PA |
12705 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12706 | inherit from. */ | |
348d480f | 12707 | |
2060206e PA |
12708 | static void |
12709 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12710 | { |
12711 | decref_counted_command_line (&self->commands); | |
12712 | xfree (self->cond_string); | |
fb81d016 | 12713 | xfree (self->extra_string); |
f8eba3c6 | 12714 | xfree (self->filter); |
f00aae0f KS |
12715 | delete_event_location (self->location); |
12716 | delete_event_location (self->location_range_end); | |
348d480f PA |
12717 | } |
12718 | ||
2060206e PA |
12719 | static struct bp_location * |
12720 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12721 | { |
12722 | struct bp_location *loc; | |
12723 | ||
12724 | loc = XNEW (struct bp_location); | |
12725 | init_bp_location (loc, &bp_location_ops, self); | |
12726 | return loc; | |
12727 | } | |
12728 | ||
2060206e PA |
12729 | static void |
12730 | base_breakpoint_re_set (struct breakpoint *b) | |
12731 | { | |
12732 | /* Nothing to re-set. */ | |
12733 | } | |
12734 | ||
12735 | #define internal_error_pure_virtual_called() \ | |
12736 | gdb_assert_not_reached ("pure virtual function called") | |
12737 | ||
12738 | static int | |
12739 | base_breakpoint_insert_location (struct bp_location *bl) | |
12740 | { | |
12741 | internal_error_pure_virtual_called (); | |
12742 | } | |
12743 | ||
12744 | static int | |
12745 | base_breakpoint_remove_location (struct bp_location *bl) | |
12746 | { | |
12747 | internal_error_pure_virtual_called (); | |
12748 | } | |
12749 | ||
12750 | static int | |
12751 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12752 | struct address_space *aspace, | |
09ac7c10 TT |
12753 | CORE_ADDR bp_addr, |
12754 | const struct target_waitstatus *ws) | |
2060206e PA |
12755 | { |
12756 | internal_error_pure_virtual_called (); | |
12757 | } | |
12758 | ||
12759 | static void | |
12760 | base_breakpoint_check_status (bpstat bs) | |
12761 | { | |
12762 | /* Always stop. */ | |
12763 | } | |
12764 | ||
12765 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12766 | errors. */ | |
12767 | ||
12768 | static int | |
12769 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12770 | { | |
12771 | internal_error_pure_virtual_called (); | |
12772 | } | |
12773 | ||
12774 | /* A "resources_needed" breakpoint_ops method that just internal | |
12775 | errors. */ | |
12776 | ||
12777 | static int | |
12778 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12779 | { | |
12780 | internal_error_pure_virtual_called (); | |
12781 | } | |
12782 | ||
12783 | static enum print_stop_action | |
12784 | base_breakpoint_print_it (bpstat bs) | |
12785 | { | |
12786 | internal_error_pure_virtual_called (); | |
12787 | } | |
12788 | ||
12789 | static void | |
12790 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12791 | struct ui_out *uiout) | |
12792 | { | |
12793 | /* nothing */ | |
12794 | } | |
12795 | ||
12796 | static void | |
12797 | base_breakpoint_print_mention (struct breakpoint *b) | |
12798 | { | |
12799 | internal_error_pure_virtual_called (); | |
12800 | } | |
12801 | ||
12802 | static void | |
12803 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12804 | { | |
12805 | internal_error_pure_virtual_called (); | |
12806 | } | |
12807 | ||
983af33b | 12808 | static void |
f00aae0f KS |
12809 | base_breakpoint_create_sals_from_location |
12810 | (const struct event_location *location, | |
12811 | struct linespec_result *canonical, | |
12812 | enum bptype type_wanted) | |
983af33b SDJ |
12813 | { |
12814 | internal_error_pure_virtual_called (); | |
12815 | } | |
12816 | ||
12817 | static void | |
12818 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12819 | struct linespec_result *c, | |
983af33b | 12820 | char *cond_string, |
e7e0cddf | 12821 | char *extra_string, |
983af33b SDJ |
12822 | enum bptype type_wanted, |
12823 | enum bpdisp disposition, | |
12824 | int thread, | |
12825 | int task, int ignore_count, | |
12826 | const struct breakpoint_ops *o, | |
12827 | int from_tty, int enabled, | |
44f238bb | 12828 | int internal, unsigned flags) |
983af33b SDJ |
12829 | { |
12830 | internal_error_pure_virtual_called (); | |
12831 | } | |
12832 | ||
12833 | static void | |
f00aae0f KS |
12834 | base_breakpoint_decode_location (struct breakpoint *b, |
12835 | const struct event_location *location, | |
983af33b SDJ |
12836 | struct symtabs_and_lines *sals) |
12837 | { | |
12838 | internal_error_pure_virtual_called (); | |
12839 | } | |
12840 | ||
ab04a2af TT |
12841 | /* The default 'explains_signal' method. */ |
12842 | ||
47591c29 | 12843 | static int |
427cd150 | 12844 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12845 | { |
47591c29 | 12846 | return 1; |
ab04a2af TT |
12847 | } |
12848 | ||
9d6e6e84 HZ |
12849 | /* The default "after_condition_true" method. */ |
12850 | ||
12851 | static void | |
12852 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12853 | { | |
12854 | /* Nothing to do. */ | |
12855 | } | |
12856 | ||
ab04a2af | 12857 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
12858 | { |
12859 | base_breakpoint_dtor, | |
12860 | base_breakpoint_allocate_location, | |
12861 | base_breakpoint_re_set, | |
12862 | base_breakpoint_insert_location, | |
12863 | base_breakpoint_remove_location, | |
12864 | base_breakpoint_breakpoint_hit, | |
12865 | base_breakpoint_check_status, | |
12866 | base_breakpoint_resources_needed, | |
12867 | base_breakpoint_works_in_software_mode, | |
12868 | base_breakpoint_print_it, | |
12869 | NULL, | |
12870 | base_breakpoint_print_one_detail, | |
12871 | base_breakpoint_print_mention, | |
983af33b | 12872 | base_breakpoint_print_recreate, |
5f700d83 | 12873 | base_breakpoint_create_sals_from_location, |
983af33b | 12874 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12875 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12876 | base_breakpoint_explains_signal, |
12877 | base_breakpoint_after_condition_true, | |
2060206e PA |
12878 | }; |
12879 | ||
12880 | /* Default breakpoint_ops methods. */ | |
12881 | ||
12882 | static void | |
348d480f PA |
12883 | bkpt_re_set (struct breakpoint *b) |
12884 | { | |
06edf0c0 | 12885 | /* FIXME: is this still reachable? */ |
f00aae0f | 12886 | if (event_location_empty_p (b->location)) |
06edf0c0 | 12887 | { |
f00aae0f | 12888 | /* Anything without a location can't be re-set. */ |
348d480f | 12889 | delete_breakpoint (b); |
06edf0c0 | 12890 | return; |
348d480f | 12891 | } |
06edf0c0 PA |
12892 | |
12893 | breakpoint_re_set_default (b); | |
348d480f PA |
12894 | } |
12895 | ||
2060206e | 12896 | static int |
348d480f PA |
12897 | bkpt_insert_location (struct bp_location *bl) |
12898 | { | |
12899 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
7c16b83e | 12900 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12901 | else |
7c16b83e | 12902 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12903 | } |
12904 | ||
2060206e | 12905 | static int |
348d480f PA |
12906 | bkpt_remove_location (struct bp_location *bl) |
12907 | { | |
12908 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12909 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12910 | else | |
7c16b83e | 12911 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12912 | } |
12913 | ||
2060206e | 12914 | static int |
348d480f | 12915 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
12916 | struct address_space *aspace, CORE_ADDR bp_addr, |
12917 | const struct target_waitstatus *ws) | |
348d480f | 12918 | { |
09ac7c10 | 12919 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12920 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12921 | return 0; |
12922 | ||
348d480f PA |
12923 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12924 | aspace, bp_addr)) | |
12925 | return 0; | |
12926 | ||
12927 | if (overlay_debugging /* unmapped overlay section */ | |
12928 | && section_is_overlay (bl->section) | |
12929 | && !section_is_mapped (bl->section)) | |
12930 | return 0; | |
12931 | ||
12932 | return 1; | |
12933 | } | |
12934 | ||
cd1608cc PA |
12935 | static int |
12936 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
12937 | struct address_space *aspace, CORE_ADDR bp_addr, | |
12938 | const struct target_waitstatus *ws) | |
12939 | { | |
12940 | if (dprintf_style == dprintf_style_agent | |
12941 | && target_can_run_breakpoint_commands ()) | |
12942 | { | |
12943 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12944 | for this address it must be for a breakpoint that happens to | |
12945 | be set at the same address. */ | |
12946 | return 0; | |
12947 | } | |
12948 | ||
12949 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12950 | } | |
12951 | ||
2060206e | 12952 | static int |
348d480f PA |
12953 | bkpt_resources_needed (const struct bp_location *bl) |
12954 | { | |
12955 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12956 | ||
12957 | return 1; | |
12958 | } | |
12959 | ||
2060206e | 12960 | static enum print_stop_action |
348d480f PA |
12961 | bkpt_print_it (bpstat bs) |
12962 | { | |
348d480f PA |
12963 | struct breakpoint *b; |
12964 | const struct bp_location *bl; | |
001c8c33 | 12965 | int bp_temp; |
79a45e25 | 12966 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12967 | |
12968 | gdb_assert (bs->bp_location_at != NULL); | |
12969 | ||
12970 | bl = bs->bp_location_at; | |
12971 | b = bs->breakpoint_at; | |
12972 | ||
001c8c33 PA |
12973 | bp_temp = b->disposition == disp_del; |
12974 | if (bl->address != bl->requested_address) | |
12975 | breakpoint_adjustment_warning (bl->requested_address, | |
12976 | bl->address, | |
12977 | b->number, 1); | |
12978 | annotate_breakpoint (b->number); | |
12979 | if (bp_temp) | |
12980 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
12981 | else | |
12982 | ui_out_text (uiout, "\nBreakpoint "); | |
12983 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 12984 | { |
001c8c33 PA |
12985 | ui_out_field_string (uiout, "reason", |
12986 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
12987 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 12988 | } |
001c8c33 PA |
12989 | ui_out_field_int (uiout, "bkptno", b->number); |
12990 | ui_out_text (uiout, ", "); | |
06edf0c0 | 12991 | |
001c8c33 | 12992 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12993 | } |
12994 | ||
2060206e | 12995 | static void |
06edf0c0 PA |
12996 | bkpt_print_mention (struct breakpoint *b) |
12997 | { | |
79a45e25 | 12998 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
12999 | return; |
13000 | ||
13001 | switch (b->type) | |
13002 | { | |
13003 | case bp_breakpoint: | |
13004 | case bp_gnu_ifunc_resolver: | |
13005 | if (b->disposition == disp_del) | |
13006 | printf_filtered (_("Temporary breakpoint")); | |
13007 | else | |
13008 | printf_filtered (_("Breakpoint")); | |
13009 | printf_filtered (_(" %d"), b->number); | |
13010 | if (b->type == bp_gnu_ifunc_resolver) | |
13011 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13012 | break; | |
13013 | case bp_hardware_breakpoint: | |
13014 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13015 | break; | |
e7e0cddf SS |
13016 | case bp_dprintf: |
13017 | printf_filtered (_("Dprintf %d"), b->number); | |
13018 | break; | |
06edf0c0 PA |
13019 | } |
13020 | ||
13021 | say_where (b); | |
13022 | } | |
13023 | ||
2060206e | 13024 | static void |
06edf0c0 PA |
13025 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13026 | { | |
13027 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13028 | fprintf_unfiltered (fp, "tbreak"); | |
13029 | else if (tp->type == bp_breakpoint) | |
13030 | fprintf_unfiltered (fp, "break"); | |
13031 | else if (tp->type == bp_hardware_breakpoint | |
13032 | && tp->disposition == disp_del) | |
13033 | fprintf_unfiltered (fp, "thbreak"); | |
13034 | else if (tp->type == bp_hardware_breakpoint) | |
13035 | fprintf_unfiltered (fp, "hbreak"); | |
13036 | else | |
13037 | internal_error (__FILE__, __LINE__, | |
13038 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13039 | ||
f00aae0f KS |
13040 | fprintf_unfiltered (fp, " %s", |
13041 | event_location_to_string (tp->location)); | |
13042 | ||
13043 | /* Print out extra_string if this breakpoint is pending. It might | |
13044 | contain, for example, conditions that were set by the user. */ | |
13045 | if (tp->loc == NULL && tp->extra_string != NULL) | |
13046 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
13047 | ||
dd11a36c | 13048 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13049 | } |
13050 | ||
983af33b | 13051 | static void |
f00aae0f KS |
13052 | bkpt_create_sals_from_location (const struct event_location *location, |
13053 | struct linespec_result *canonical, | |
13054 | enum bptype type_wanted) | |
983af33b | 13055 | { |
f00aae0f | 13056 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13057 | } |
13058 | ||
13059 | static void | |
13060 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13061 | struct linespec_result *canonical, | |
983af33b | 13062 | char *cond_string, |
e7e0cddf | 13063 | char *extra_string, |
983af33b SDJ |
13064 | enum bptype type_wanted, |
13065 | enum bpdisp disposition, | |
13066 | int thread, | |
13067 | int task, int ignore_count, | |
13068 | const struct breakpoint_ops *ops, | |
13069 | int from_tty, int enabled, | |
44f238bb | 13070 | int internal, unsigned flags) |
983af33b | 13071 | { |
023fa29b | 13072 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13073 | cond_string, extra_string, |
13074 | type_wanted, | |
983af33b SDJ |
13075 | disposition, thread, task, |
13076 | ignore_count, ops, from_tty, | |
44f238bb | 13077 | enabled, internal, flags); |
983af33b SDJ |
13078 | } |
13079 | ||
13080 | static void | |
f00aae0f KS |
13081 | bkpt_decode_location (struct breakpoint *b, |
13082 | const struct event_location *location, | |
983af33b SDJ |
13083 | struct symtabs_and_lines *sals) |
13084 | { | |
f00aae0f | 13085 | decode_location_default (b, location, sals); |
983af33b SDJ |
13086 | } |
13087 | ||
06edf0c0 PA |
13088 | /* Virtual table for internal breakpoints. */ |
13089 | ||
13090 | static void | |
13091 | internal_bkpt_re_set (struct breakpoint *b) | |
13092 | { | |
13093 | switch (b->type) | |
13094 | { | |
13095 | /* Delete overlay event and longjmp master breakpoints; they | |
13096 | will be reset later by breakpoint_re_set. */ | |
13097 | case bp_overlay_event: | |
13098 | case bp_longjmp_master: | |
13099 | case bp_std_terminate_master: | |
13100 | case bp_exception_master: | |
13101 | delete_breakpoint (b); | |
13102 | break; | |
13103 | ||
13104 | /* This breakpoint is special, it's set up when the inferior | |
13105 | starts and we really don't want to touch it. */ | |
13106 | case bp_shlib_event: | |
13107 | ||
13108 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13109 | it is set up, we do not want to touch it. */ | |
13110 | case bp_thread_event: | |
13111 | break; | |
13112 | } | |
13113 | } | |
13114 | ||
13115 | static void | |
13116 | internal_bkpt_check_status (bpstat bs) | |
13117 | { | |
a9b3a50f PA |
13118 | if (bs->breakpoint_at->type == bp_shlib_event) |
13119 | { | |
13120 | /* If requested, stop when the dynamic linker notifies GDB of | |
13121 | events. This allows the user to get control and place | |
13122 | breakpoints in initializer routines for dynamically loaded | |
13123 | objects (among other things). */ | |
13124 | bs->stop = stop_on_solib_events; | |
13125 | bs->print = stop_on_solib_events; | |
13126 | } | |
13127 | else | |
13128 | bs->stop = 0; | |
06edf0c0 PA |
13129 | } |
13130 | ||
13131 | static enum print_stop_action | |
13132 | internal_bkpt_print_it (bpstat bs) | |
13133 | { | |
06edf0c0 | 13134 | struct breakpoint *b; |
06edf0c0 | 13135 | |
06edf0c0 PA |
13136 | b = bs->breakpoint_at; |
13137 | ||
06edf0c0 PA |
13138 | switch (b->type) |
13139 | { | |
348d480f PA |
13140 | case bp_shlib_event: |
13141 | /* Did we stop because the user set the stop_on_solib_events | |
13142 | variable? (If so, we report this as a generic, "Stopped due | |
13143 | to shlib event" message.) */ | |
edcc5120 | 13144 | print_solib_event (0); |
348d480f PA |
13145 | break; |
13146 | ||
13147 | case bp_thread_event: | |
13148 | /* Not sure how we will get here. | |
13149 | GDB should not stop for these breakpoints. */ | |
13150 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13151 | break; |
13152 | ||
13153 | case bp_overlay_event: | |
13154 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13155 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13156 | break; |
13157 | ||
13158 | case bp_longjmp_master: | |
13159 | /* These should never be enabled. */ | |
13160 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13161 | break; |
13162 | ||
13163 | case bp_std_terminate_master: | |
13164 | /* These should never be enabled. */ | |
13165 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13166 | "gdb should not stop!\n")); | |
348d480f PA |
13167 | break; |
13168 | ||
13169 | case bp_exception_master: | |
13170 | /* These should never be enabled. */ | |
13171 | printf_filtered (_("Exception Master Breakpoint: " | |
13172 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13173 | break; |
13174 | } | |
13175 | ||
001c8c33 | 13176 | return PRINT_NOTHING; |
06edf0c0 PA |
13177 | } |
13178 | ||
13179 | static void | |
13180 | internal_bkpt_print_mention (struct breakpoint *b) | |
13181 | { | |
13182 | /* Nothing to mention. These breakpoints are internal. */ | |
13183 | } | |
13184 | ||
06edf0c0 PA |
13185 | /* Virtual table for momentary breakpoints */ |
13186 | ||
13187 | static void | |
13188 | momentary_bkpt_re_set (struct breakpoint *b) | |
13189 | { | |
13190 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13191 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13192 | Otherwise these should have been blown away via the cleanup chain |
13193 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13194 | } | |
13195 | ||
13196 | static void | |
13197 | momentary_bkpt_check_status (bpstat bs) | |
13198 | { | |
13199 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13200 | } | |
13201 | ||
13202 | static enum print_stop_action | |
13203 | momentary_bkpt_print_it (bpstat bs) | |
13204 | { | |
79a45e25 PA |
13205 | struct ui_out *uiout = current_uiout; |
13206 | ||
001c8c33 | 13207 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 13208 | { |
001c8c33 | 13209 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 13210 | |
001c8c33 PA |
13211 | switch (b->type) |
13212 | { | |
13213 | case bp_finish: | |
13214 | ui_out_field_string | |
13215 | (uiout, "reason", | |
13216 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
13217 | break; | |
348d480f | 13218 | |
001c8c33 PA |
13219 | case bp_until: |
13220 | ui_out_field_string | |
13221 | (uiout, "reason", | |
13222 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
13223 | break; | |
13224 | } | |
348d480f PA |
13225 | } |
13226 | ||
001c8c33 | 13227 | return PRINT_UNKNOWN; |
348d480f PA |
13228 | } |
13229 | ||
06edf0c0 PA |
13230 | static void |
13231 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13232 | { |
06edf0c0 | 13233 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13234 | } |
13235 | ||
e2e4d78b JK |
13236 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13237 | ||
13238 | It gets cleared already on the removal of the first one of such placed | |
13239 | breakpoints. This is OK as they get all removed altogether. */ | |
13240 | ||
13241 | static void | |
13242 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13243 | { | |
13244 | struct thread_info *tp = find_thread_id (self->thread); | |
13245 | ||
13246 | if (tp) | |
13247 | tp->initiating_frame = null_frame_id; | |
13248 | ||
13249 | momentary_breakpoint_ops.dtor (self); | |
13250 | } | |
13251 | ||
55aa24fb SDJ |
13252 | /* Specific methods for probe breakpoints. */ |
13253 | ||
13254 | static int | |
13255 | bkpt_probe_insert_location (struct bp_location *bl) | |
13256 | { | |
13257 | int v = bkpt_insert_location (bl); | |
13258 | ||
13259 | if (v == 0) | |
13260 | { | |
13261 | /* The insertion was successful, now let's set the probe's semaphore | |
13262 | if needed. */ | |
0ea5cda8 SDJ |
13263 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13264 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13265 | bl->probe.objfile, | |
13266 | bl->gdbarch); | |
55aa24fb SDJ |
13267 | } |
13268 | ||
13269 | return v; | |
13270 | } | |
13271 | ||
13272 | static int | |
13273 | bkpt_probe_remove_location (struct bp_location *bl) | |
13274 | { | |
13275 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13276 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13277 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13278 | bl->probe.objfile, | |
13279 | bl->gdbarch); | |
55aa24fb SDJ |
13280 | |
13281 | return bkpt_remove_location (bl); | |
13282 | } | |
13283 | ||
13284 | static void | |
f00aae0f | 13285 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13286 | struct linespec_result *canonical, |
f00aae0f | 13287 | enum bptype type_wanted) |
55aa24fb SDJ |
13288 | { |
13289 | struct linespec_sals lsal; | |
13290 | ||
f00aae0f KS |
13291 | lsal.sals = parse_probes (location, canonical); |
13292 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); | |
55aa24fb SDJ |
13293 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13294 | } | |
13295 | ||
13296 | static void | |
f00aae0f KS |
13297 | bkpt_probe_decode_location (struct breakpoint *b, |
13298 | const struct event_location *location, | |
55aa24fb SDJ |
13299 | struct symtabs_and_lines *sals) |
13300 | { | |
f00aae0f | 13301 | *sals = parse_probes (location, NULL); |
55aa24fb SDJ |
13302 | if (!sals->sals) |
13303 | error (_("probe not found")); | |
13304 | } | |
13305 | ||
348d480f | 13306 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13307 | |
348d480f PA |
13308 | static void |
13309 | tracepoint_re_set (struct breakpoint *b) | |
13310 | { | |
13311 | breakpoint_re_set_default (b); | |
13312 | } | |
876fa593 | 13313 | |
348d480f PA |
13314 | static int |
13315 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13316 | struct address_space *aspace, CORE_ADDR bp_addr, |
13317 | const struct target_waitstatus *ws) | |
348d480f PA |
13318 | { |
13319 | /* By definition, the inferior does not report stops at | |
13320 | tracepoints. */ | |
13321 | return 0; | |
74960c60 VP |
13322 | } |
13323 | ||
13324 | static void | |
348d480f PA |
13325 | tracepoint_print_one_detail (const struct breakpoint *self, |
13326 | struct ui_out *uiout) | |
74960c60 | 13327 | { |
d9b3f62e PA |
13328 | struct tracepoint *tp = (struct tracepoint *) self; |
13329 | if (tp->static_trace_marker_id) | |
348d480f PA |
13330 | { |
13331 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13332 | |
348d480f PA |
13333 | ui_out_text (uiout, "\tmarker id is "); |
13334 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13335 | tp->static_trace_marker_id); |
348d480f PA |
13336 | ui_out_text (uiout, "\n"); |
13337 | } | |
0d381245 VP |
13338 | } |
13339 | ||
a474d7c2 | 13340 | static void |
348d480f | 13341 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13342 | { |
79a45e25 | 13343 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13344 | return; |
cc59ec59 | 13345 | |
348d480f PA |
13346 | switch (b->type) |
13347 | { | |
13348 | case bp_tracepoint: | |
13349 | printf_filtered (_("Tracepoint")); | |
13350 | printf_filtered (_(" %d"), b->number); | |
13351 | break; | |
13352 | case bp_fast_tracepoint: | |
13353 | printf_filtered (_("Fast tracepoint")); | |
13354 | printf_filtered (_(" %d"), b->number); | |
13355 | break; | |
13356 | case bp_static_tracepoint: | |
13357 | printf_filtered (_("Static tracepoint")); | |
13358 | printf_filtered (_(" %d"), b->number); | |
13359 | break; | |
13360 | default: | |
13361 | internal_error (__FILE__, __LINE__, | |
13362 | _("unhandled tracepoint type %d"), (int) b->type); | |
13363 | } | |
13364 | ||
13365 | say_where (b); | |
a474d7c2 PA |
13366 | } |
13367 | ||
348d480f | 13368 | static void |
d9b3f62e | 13369 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13370 | { |
d9b3f62e PA |
13371 | struct tracepoint *tp = (struct tracepoint *) self; |
13372 | ||
13373 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13374 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13375 | if (self->type == bp_static_tracepoint) |
348d480f | 13376 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13377 | else if (self->type == bp_tracepoint) |
348d480f PA |
13378 | fprintf_unfiltered (fp, "trace"); |
13379 | else | |
13380 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13381 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13382 | |
f00aae0f KS |
13383 | fprintf_unfiltered (fp, " %s", |
13384 | event_location_to_string (self->location)); | |
d9b3f62e PA |
13385 | print_recreate_thread (self, fp); |
13386 | ||
13387 | if (tp->pass_count) | |
13388 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13389 | } |
13390 | ||
983af33b | 13391 | static void |
f00aae0f KS |
13392 | tracepoint_create_sals_from_location (const struct event_location *location, |
13393 | struct linespec_result *canonical, | |
13394 | enum bptype type_wanted) | |
983af33b | 13395 | { |
f00aae0f | 13396 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13397 | } |
13398 | ||
13399 | static void | |
13400 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13401 | struct linespec_result *canonical, | |
983af33b | 13402 | char *cond_string, |
e7e0cddf | 13403 | char *extra_string, |
983af33b SDJ |
13404 | enum bptype type_wanted, |
13405 | enum bpdisp disposition, | |
13406 | int thread, | |
13407 | int task, int ignore_count, | |
13408 | const struct breakpoint_ops *ops, | |
13409 | int from_tty, int enabled, | |
44f238bb | 13410 | int internal, unsigned flags) |
983af33b | 13411 | { |
023fa29b | 13412 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13413 | cond_string, extra_string, |
13414 | type_wanted, | |
983af33b SDJ |
13415 | disposition, thread, task, |
13416 | ignore_count, ops, from_tty, | |
44f238bb | 13417 | enabled, internal, flags); |
983af33b SDJ |
13418 | } |
13419 | ||
13420 | static void | |
f00aae0f KS |
13421 | tracepoint_decode_location (struct breakpoint *b, |
13422 | const struct event_location *location, | |
983af33b SDJ |
13423 | struct symtabs_and_lines *sals) |
13424 | { | |
f00aae0f | 13425 | decode_location_default (b, location, sals); |
983af33b SDJ |
13426 | } |
13427 | ||
2060206e | 13428 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13429 | |
55aa24fb SDJ |
13430 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13431 | static probe. */ | |
13432 | ||
13433 | static void | |
f00aae0f KS |
13434 | tracepoint_probe_create_sals_from_location |
13435 | (const struct event_location *location, | |
13436 | struct linespec_result *canonical, | |
13437 | enum bptype type_wanted) | |
55aa24fb SDJ |
13438 | { |
13439 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13440 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13441 | } |
13442 | ||
13443 | static void | |
f00aae0f KS |
13444 | tracepoint_probe_decode_location (struct breakpoint *b, |
13445 | const struct event_location *location, | |
55aa24fb SDJ |
13446 | struct symtabs_and_lines *sals) |
13447 | { | |
13448 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13449 | bkpt_probe_decode_location (b, location, sals); |
55aa24fb SDJ |
13450 | } |
13451 | ||
13452 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13453 | ||
5c2b4418 HZ |
13454 | /* Dprintf breakpoint_ops methods. */ |
13455 | ||
13456 | static void | |
13457 | dprintf_re_set (struct breakpoint *b) | |
13458 | { | |
13459 | breakpoint_re_set_default (b); | |
13460 | ||
f00aae0f KS |
13461 | /* extra_string should never be non-NULL for dprintf. */ |
13462 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13463 | |
13464 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13465 | 2 - create a dprintf, which resolves fine. | |
13466 | 3 - disconnect from target 1 | |
13467 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13468 | ||
13469 | After steps #3/#4, you'll want the dprintf command list to | |
13470 | be updated, because target 1 and 2 may well return different | |
13471 | answers for target_can_run_breakpoint_commands(). | |
13472 | Given absence of finer grained resetting, we get to do | |
13473 | it all the time. */ | |
13474 | if (b->extra_string != NULL) | |
13475 | update_dprintf_command_list (b); | |
13476 | } | |
13477 | ||
2d9442cc HZ |
13478 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13479 | ||
13480 | static void | |
13481 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13482 | { | |
f00aae0f KS |
13483 | fprintf_unfiltered (fp, "dprintf %s,%s", |
13484 | event_location_to_string (tp->location), | |
2d9442cc HZ |
13485 | tp->extra_string); |
13486 | print_recreate_thread (tp, fp); | |
13487 | } | |
13488 | ||
9d6e6e84 HZ |
13489 | /* Implement the "after_condition_true" breakpoint_ops method for |
13490 | dprintf. | |
13491 | ||
13492 | dprintf's are implemented with regular commands in their command | |
13493 | list, but we run the commands here instead of before presenting the | |
13494 | stop to the user, as dprintf's don't actually cause a stop. This | |
13495 | also makes it so that the commands of multiple dprintfs at the same | |
13496 | address are all handled. */ | |
13497 | ||
13498 | static void | |
13499 | dprintf_after_condition_true (struct bpstats *bs) | |
13500 | { | |
13501 | struct cleanup *old_chain; | |
13502 | struct bpstats tmp_bs = { NULL }; | |
13503 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13504 | ||
13505 | /* dprintf's never cause a stop. This wasn't set in the | |
13506 | check_status hook instead because that would make the dprintf's | |
13507 | condition not be evaluated. */ | |
13508 | bs->stop = 0; | |
13509 | ||
13510 | /* Run the command list here. Take ownership of it instead of | |
13511 | copying. We never want these commands to run later in | |
13512 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13513 | be set at same address as this dprintf, or even if running the | |
13514 | commands here throws. */ | |
13515 | tmp_bs.commands = bs->commands; | |
13516 | bs->commands = NULL; | |
13517 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13518 | ||
13519 | bpstat_do_actions_1 (&tmp_bs_p); | |
13520 | ||
13521 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13522 | bpstat_do_actions_1 may return early without processing the whole | |
13523 | list. */ | |
13524 | do_cleanups (old_chain); | |
13525 | } | |
13526 | ||
983af33b SDJ |
13527 | /* The breakpoint_ops structure to be used on static tracepoints with |
13528 | markers (`-m'). */ | |
13529 | ||
13530 | static void | |
f00aae0f | 13531 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13532 | struct linespec_result *canonical, |
f00aae0f | 13533 | enum bptype type_wanted) |
983af33b SDJ |
13534 | { |
13535 | struct linespec_sals lsal; | |
f00aae0f KS |
13536 | const char *arg_start, *arg; |
13537 | char *str; | |
13538 | struct cleanup *cleanup; | |
983af33b | 13539 | |
f00aae0f KS |
13540 | arg = arg_start = get_linespec_location (location); |
13541 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13542 | |
f00aae0f KS |
13543 | str = savestring (arg_start, arg - arg_start); |
13544 | cleanup = make_cleanup (xfree, str); | |
13545 | canonical->location = new_linespec_location (&str); | |
13546 | do_cleanups (cleanup); | |
983af33b | 13547 | |
f00aae0f | 13548 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
983af33b SDJ |
13549 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13550 | } | |
13551 | ||
13552 | static void | |
13553 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13554 | struct linespec_result *canonical, | |
983af33b | 13555 | char *cond_string, |
e7e0cddf | 13556 | char *extra_string, |
983af33b SDJ |
13557 | enum bptype type_wanted, |
13558 | enum bpdisp disposition, | |
13559 | int thread, | |
13560 | int task, int ignore_count, | |
13561 | const struct breakpoint_ops *ops, | |
13562 | int from_tty, int enabled, | |
44f238bb | 13563 | int internal, unsigned flags) |
983af33b SDJ |
13564 | { |
13565 | int i; | |
52d361e1 YQ |
13566 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13567 | canonical->sals, 0); | |
983af33b SDJ |
13568 | |
13569 | /* If the user is creating a static tracepoint by marker id | |
13570 | (strace -m MARKER_ID), then store the sals index, so that | |
13571 | breakpoint_re_set can try to match up which of the newly | |
13572 | found markers corresponds to this one, and, don't try to | |
13573 | expand multiple locations for each sal, given than SALS | |
13574 | already should contain all sals for MARKER_ID. */ | |
13575 | ||
13576 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13577 | { | |
13578 | struct symtabs_and_lines expanded; | |
13579 | struct tracepoint *tp; | |
13580 | struct cleanup *old_chain; | |
f00aae0f | 13581 | struct event_location *location; |
983af33b SDJ |
13582 | |
13583 | expanded.nelts = 1; | |
13584 | expanded.sals = &lsal->sals.sals[i]; | |
13585 | ||
f00aae0f KS |
13586 | location = copy_event_location (canonical->location); |
13587 | old_chain = make_cleanup_delete_event_location (location); | |
983af33b SDJ |
13588 | |
13589 | tp = XCNEW (struct tracepoint); | |
13590 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
f00aae0f | 13591 | location, NULL, |
e7e0cddf SS |
13592 | cond_string, extra_string, |
13593 | type_wanted, disposition, | |
983af33b | 13594 | thread, task, ignore_count, ops, |
44f238bb | 13595 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13596 | canonical->special_display); |
13597 | /* Given that its possible to have multiple markers with | |
13598 | the same string id, if the user is creating a static | |
13599 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13600 | store the sals index, so that breakpoint_re_set can | |
13601 | try to match up which of the newly found markers | |
13602 | corresponds to this one */ | |
13603 | tp->static_trace_marker_id_idx = i; | |
13604 | ||
13605 | install_breakpoint (internal, &tp->base, 0); | |
13606 | ||
13607 | discard_cleanups (old_chain); | |
13608 | } | |
13609 | } | |
13610 | ||
13611 | static void | |
f00aae0f KS |
13612 | strace_marker_decode_location (struct breakpoint *b, |
13613 | const struct event_location *location, | |
983af33b SDJ |
13614 | struct symtabs_and_lines *sals) |
13615 | { | |
13616 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13617 | const char *s = get_linespec_location (location); |
983af33b | 13618 | |
f00aae0f | 13619 | *sals = decode_static_tracepoint_spec (&s); |
983af33b SDJ |
13620 | if (sals->nelts > tp->static_trace_marker_id_idx) |
13621 | { | |
13622 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13623 | sals->nelts = 1; | |
13624 | } | |
13625 | else | |
13626 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13627 | } | |
13628 | ||
13629 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13630 | ||
13631 | static int | |
13632 | strace_marker_p (struct breakpoint *b) | |
13633 | { | |
13634 | return b->ops == &strace_marker_breakpoint_ops; | |
13635 | } | |
13636 | ||
53a5351d | 13637 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13638 | structures. */ |
c906108c SS |
13639 | |
13640 | void | |
fba45db2 | 13641 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13642 | { |
52f0bd74 | 13643 | struct breakpoint *b; |
c906108c | 13644 | |
8a3fe4f8 | 13645 | gdb_assert (bpt != NULL); |
c906108c | 13646 | |
4a64f543 MS |
13647 | /* Has this bp already been deleted? This can happen because |
13648 | multiple lists can hold pointers to bp's. bpstat lists are | |
13649 | especial culprits. | |
13650 | ||
13651 | One example of this happening is a watchpoint's scope bp. When | |
13652 | the scope bp triggers, we notice that the watchpoint is out of | |
13653 | scope, and delete it. We also delete its scope bp. But the | |
13654 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13655 | That bpstat is then checked for auto-deleting bp's, which are | |
13656 | deleted. | |
13657 | ||
13658 | A real solution to this problem might involve reference counts in | |
13659 | bp's, and/or giving them pointers back to their referencing | |
13660 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13661 | storage when no more references were extent. A cheaper bandaid | |
13662 | was chosen. */ | |
c906108c SS |
13663 | if (bpt->type == bp_none) |
13664 | return; | |
13665 | ||
4a64f543 MS |
13666 | /* At least avoid this stale reference until the reference counting |
13667 | of breakpoints gets resolved. */ | |
d0fb5eae | 13668 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13669 | { |
d0fb5eae | 13670 | struct breakpoint *related; |
3a5c3e22 | 13671 | struct watchpoint *w; |
d0fb5eae JK |
13672 | |
13673 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13674 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13675 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13676 | w = (struct watchpoint *) bpt; |
13677 | else | |
13678 | w = NULL; | |
13679 | if (w != NULL) | |
13680 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13681 | |
13682 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13683 | for (related = bpt; related->related_breakpoint != bpt; | |
13684 | related = related->related_breakpoint); | |
13685 | related->related_breakpoint = bpt->related_breakpoint; | |
13686 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13687 | } |
13688 | ||
a9634178 TJB |
13689 | /* watch_command_1 creates a watchpoint but only sets its number if |
13690 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13691 | a problem in that process, we'll be asked to delete the half-created | |
13692 | watchpoint. In that case, don't announce the deletion. */ | |
13693 | if (bpt->number) | |
13694 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13695 | |
c906108c SS |
13696 | if (breakpoint_chain == bpt) |
13697 | breakpoint_chain = bpt->next; | |
13698 | ||
c906108c SS |
13699 | ALL_BREAKPOINTS (b) |
13700 | if (b->next == bpt) | |
c5aa993b JM |
13701 | { |
13702 | b->next = bpt->next; | |
13703 | break; | |
13704 | } | |
c906108c | 13705 | |
f431efe5 PA |
13706 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13707 | been freed. */ | |
13708 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13709 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13710 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13711 | commands are associated with the bpstat; if we remove it here, | |
13712 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13713 | event-top.c won't do anything, and temporary breakpoints with | |
13714 | commands won't work. */ | |
13715 | ||
13716 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13717 | ||
4a64f543 MS |
13718 | /* Now that breakpoint is removed from breakpoint list, update the |
13719 | global location list. This will remove locations that used to | |
13720 | belong to this breakpoint. Do this before freeing the breakpoint | |
13721 | itself, since remove_breakpoint looks at location's owner. It | |
13722 | might be better design to have location completely | |
13723 | self-contained, but it's not the case now. */ | |
44702360 | 13724 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13725 | |
348d480f | 13726 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13727 | /* On the chance that someone will soon try again to delete this |
13728 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13729 | bpt->type = bp_none; |
b8c9b27d | 13730 | xfree (bpt); |
c906108c SS |
13731 | } |
13732 | ||
4d6140d9 AC |
13733 | static void |
13734 | do_delete_breakpoint_cleanup (void *b) | |
13735 | { | |
13736 | delete_breakpoint (b); | |
13737 | } | |
13738 | ||
13739 | struct cleanup * | |
13740 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13741 | { | |
13742 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13743 | } | |
13744 | ||
51be5b68 PA |
13745 | /* Iterator function to call a user-provided callback function once |
13746 | for each of B and its related breakpoints. */ | |
13747 | ||
13748 | static void | |
13749 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13750 | void (*function) (struct breakpoint *, | |
13751 | void *), | |
13752 | void *data) | |
13753 | { | |
13754 | struct breakpoint *related; | |
13755 | ||
13756 | related = b; | |
13757 | do | |
13758 | { | |
13759 | struct breakpoint *next; | |
13760 | ||
13761 | /* FUNCTION may delete RELATED. */ | |
13762 | next = related->related_breakpoint; | |
13763 | ||
13764 | if (next == related) | |
13765 | { | |
13766 | /* RELATED is the last ring entry. */ | |
13767 | function (related, data); | |
13768 | ||
13769 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13770 | B. There's nothing left to do anyway, so just break | |
13771 | out. */ | |
13772 | break; | |
13773 | } | |
13774 | else | |
13775 | function (related, data); | |
13776 | ||
13777 | related = next; | |
13778 | } | |
13779 | while (related != b); | |
13780 | } | |
95a42b64 TT |
13781 | |
13782 | static void | |
13783 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13784 | { | |
13785 | delete_breakpoint (b); | |
13786 | } | |
13787 | ||
51be5b68 PA |
13788 | /* A callback for map_breakpoint_numbers that calls |
13789 | delete_breakpoint. */ | |
13790 | ||
13791 | static void | |
13792 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13793 | { | |
13794 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13795 | } | |
13796 | ||
c906108c | 13797 | void |
fba45db2 | 13798 | delete_command (char *arg, int from_tty) |
c906108c | 13799 | { |
35df4500 | 13800 | struct breakpoint *b, *b_tmp; |
c906108c | 13801 | |
ea9365bb TT |
13802 | dont_repeat (); |
13803 | ||
c906108c SS |
13804 | if (arg == 0) |
13805 | { | |
13806 | int breaks_to_delete = 0; | |
13807 | ||
46c6471b PA |
13808 | /* Delete all breakpoints if no argument. Do not delete |
13809 | internal breakpoints, these have to be deleted with an | |
13810 | explicit breakpoint number argument. */ | |
c5aa993b | 13811 | ALL_BREAKPOINTS (b) |
46c6471b | 13812 | if (user_breakpoint_p (b)) |
973d738b DJ |
13813 | { |
13814 | breaks_to_delete = 1; | |
13815 | break; | |
13816 | } | |
c906108c SS |
13817 | |
13818 | /* Ask user only if there are some breakpoints to delete. */ | |
13819 | if (!from_tty | |
e2e0b3e5 | 13820 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13821 | { |
35df4500 | 13822 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13823 | if (user_breakpoint_p (b)) |
c5aa993b | 13824 | delete_breakpoint (b); |
c906108c SS |
13825 | } |
13826 | } | |
13827 | else | |
51be5b68 | 13828 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13829 | } |
13830 | ||
0d381245 VP |
13831 | static int |
13832 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 13833 | { |
0d381245 | 13834 | for (; loc; loc = loc->next) |
8645ff69 UW |
13835 | if (!loc->shlib_disabled |
13836 | && !loc->pspace->executing_startup) | |
0d381245 VP |
13837 | return 0; |
13838 | return 1; | |
fe3f5fa8 VP |
13839 | } |
13840 | ||
776592bf DE |
13841 | /* Subroutine of update_breakpoint_locations to simplify it. |
13842 | Return non-zero if multiple fns in list LOC have the same name. | |
13843 | Null names are ignored. */ | |
13844 | ||
13845 | static int | |
13846 | ambiguous_names_p (struct bp_location *loc) | |
13847 | { | |
13848 | struct bp_location *l; | |
13849 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13850 | (int (*) (const void *, |
13851 | const void *)) streq, | |
776592bf DE |
13852 | NULL, xcalloc, xfree); |
13853 | ||
13854 | for (l = loc; l != NULL; l = l->next) | |
13855 | { | |
13856 | const char **slot; | |
13857 | const char *name = l->function_name; | |
13858 | ||
13859 | /* Allow for some names to be NULL, ignore them. */ | |
13860 | if (name == NULL) | |
13861 | continue; | |
13862 | ||
13863 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13864 | INSERT); | |
4a64f543 MS |
13865 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13866 | returns NULL. */ | |
776592bf DE |
13867 | if (*slot != NULL) |
13868 | { | |
13869 | htab_delete (htab); | |
13870 | return 1; | |
13871 | } | |
13872 | *slot = name; | |
13873 | } | |
13874 | ||
13875 | htab_delete (htab); | |
13876 | return 0; | |
13877 | } | |
13878 | ||
0fb4aa4b PA |
13879 | /* When symbols change, it probably means the sources changed as well, |
13880 | and it might mean the static tracepoint markers are no longer at | |
13881 | the same address or line numbers they used to be at last we | |
13882 | checked. Losing your static tracepoints whenever you rebuild is | |
13883 | undesirable. This function tries to resync/rematch gdb static | |
13884 | tracepoints with the markers on the target, for static tracepoints | |
13885 | that have not been set by marker id. Static tracepoint that have | |
13886 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13887 | The heuristic is: | |
13888 | ||
13889 | 1) For a tracepoint set at a specific address, look for a marker at | |
13890 | the old PC. If one is found there, assume to be the same marker. | |
13891 | If the name / string id of the marker found is different from the | |
13892 | previous known name, assume that means the user renamed the marker | |
13893 | in the sources, and output a warning. | |
13894 | ||
13895 | 2) For a tracepoint set at a given line number, look for a marker | |
13896 | at the new address of the old line number. If one is found there, | |
13897 | assume to be the same marker. If the name / string id of the | |
13898 | marker found is different from the previous known name, assume that | |
13899 | means the user renamed the marker in the sources, and output a | |
13900 | warning. | |
13901 | ||
13902 | 3) If a marker is no longer found at the same address or line, it | |
13903 | may mean the marker no longer exists. But it may also just mean | |
13904 | the code changed a bit. Maybe the user added a few lines of code | |
13905 | that made the marker move up or down (in line number terms). Ask | |
13906 | the target for info about the marker with the string id as we knew | |
13907 | it. If found, update line number and address in the matching | |
13908 | static tracepoint. This will get confused if there's more than one | |
13909 | marker with the same ID (possible in UST, although unadvised | |
13910 | precisely because it confuses tools). */ | |
13911 | ||
13912 | static struct symtab_and_line | |
13913 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13914 | { | |
d9b3f62e | 13915 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13916 | struct static_tracepoint_marker marker; |
13917 | CORE_ADDR pc; | |
0fb4aa4b PA |
13918 | |
13919 | pc = sal.pc; | |
13920 | if (sal.line) | |
13921 | find_line_pc (sal.symtab, sal.line, &pc); | |
13922 | ||
13923 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13924 | { | |
d9b3f62e | 13925 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
13926 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
13927 | b->number, | |
d9b3f62e | 13928 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 13929 | |
d9b3f62e PA |
13930 | xfree (tp->static_trace_marker_id); |
13931 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
13932 | release_static_tracepoint_marker (&marker); |
13933 | ||
13934 | return sal; | |
13935 | } | |
13936 | ||
13937 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13938 | by string ID. */ | |
13939 | if (!sal.explicit_pc | |
13940 | && sal.line != 0 | |
13941 | && sal.symtab != NULL | |
d9b3f62e | 13942 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
13943 | { |
13944 | VEC(static_tracepoint_marker_p) *markers; | |
13945 | ||
13946 | markers | |
d9b3f62e | 13947 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
13948 | |
13949 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
13950 | { | |
f00aae0f | 13951 | char *p, *tmp; |
80e1d417 | 13952 | struct symtab_and_line sal2; |
0fb4aa4b | 13953 | struct symbol *sym; |
80e1d417 | 13954 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13955 | struct ui_out *uiout = current_uiout; |
f00aae0f | 13956 | struct cleanup *cleanup; |
0fb4aa4b | 13957 | |
80e1d417 | 13958 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 13959 | |
d9b3f62e | 13960 | xfree (tp->static_trace_marker_id); |
80e1d417 | 13961 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
13962 | |
13963 | warning (_("marker for static tracepoint %d (%s) not " | |
13964 | "found at previous line number"), | |
d9b3f62e | 13965 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 13966 | |
80e1d417 | 13967 | init_sal (&sal2); |
0fb4aa4b | 13968 | |
80e1d417 | 13969 | sal2.pc = tpmarker->address; |
0fb4aa4b | 13970 | |
80e1d417 AS |
13971 | sal2 = find_pc_line (tpmarker->address, 0); |
13972 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
13973 | ui_out_text (uiout, "Now in "); |
13974 | if (sym) | |
13975 | { | |
13976 | ui_out_field_string (uiout, "func", | |
13977 | SYMBOL_PRINT_NAME (sym)); | |
13978 | ui_out_text (uiout, " at "); | |
13979 | } | |
05cba821 JK |
13980 | ui_out_field_string (uiout, "file", |
13981 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
13982 | ui_out_text (uiout, ":"); |
13983 | ||
13984 | if (ui_out_is_mi_like_p (uiout)) | |
13985 | { | |
0b0865da | 13986 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13987 | |
f35a17b5 | 13988 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
13989 | } |
13990 | ||
80e1d417 | 13991 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
13992 | ui_out_text (uiout, "\n"); |
13993 | ||
80e1d417 | 13994 | b->loc->line_number = sal2.line; |
2f202fde | 13995 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 13996 | |
f00aae0f KS |
13997 | delete_event_location (b->location); |
13998 | p = tmp = xstrprintf ("%s:%d", | |
13999 | symtab_to_filename_for_display (sal2.symtab), | |
14000 | b->loc->line_number); | |
14001 | cleanup = make_cleanup (xfree, tmp); | |
14002 | b->location = new_linespec_location (&tmp); | |
14003 | do_cleanups (cleanup); | |
0fb4aa4b PA |
14004 | |
14005 | /* Might be nice to check if function changed, and warn if | |
14006 | so. */ | |
14007 | ||
80e1d417 | 14008 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14009 | } |
14010 | } | |
14011 | return sal; | |
14012 | } | |
14013 | ||
8d3788bd VP |
14014 | /* Returns 1 iff locations A and B are sufficiently same that |
14015 | we don't need to report breakpoint as changed. */ | |
14016 | ||
14017 | static int | |
14018 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14019 | { | |
14020 | while (a && b) | |
14021 | { | |
14022 | if (a->address != b->address) | |
14023 | return 0; | |
14024 | ||
14025 | if (a->shlib_disabled != b->shlib_disabled) | |
14026 | return 0; | |
14027 | ||
14028 | if (a->enabled != b->enabled) | |
14029 | return 0; | |
14030 | ||
14031 | a = a->next; | |
14032 | b = b->next; | |
14033 | } | |
14034 | ||
14035 | if ((a == NULL) != (b == NULL)) | |
14036 | return 0; | |
14037 | ||
14038 | return 1; | |
14039 | } | |
14040 | ||
f1310107 TJB |
14041 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
14042 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
14043 | a ranged breakpoint. */ | |
14044 | ||
0e30163f | 14045 | void |
0d381245 | 14046 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
14047 | struct symtabs_and_lines sals, |
14048 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14049 | { |
14050 | int i; | |
0d381245 VP |
14051 | struct bp_location *existing_locations = b->loc; |
14052 | ||
f8eba3c6 TT |
14053 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14054 | { | |
14055 | /* Ranged breakpoints have only one start location and one end | |
14056 | location. */ | |
14057 | b->enable_state = bp_disabled; | |
44702360 | 14058 | update_global_location_list (UGLL_MAY_INSERT); |
f8eba3c6 TT |
14059 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14060 | "multiple locations found\n"), | |
14061 | b->number); | |
14062 | return; | |
14063 | } | |
f1310107 | 14064 | |
4a64f543 MS |
14065 | /* If there's no new locations, and all existing locations are |
14066 | pending, don't do anything. This optimizes the common case where | |
14067 | all locations are in the same shared library, that was unloaded. | |
14068 | We'd like to retain the location, so that when the library is | |
14069 | loaded again, we don't loose the enabled/disabled status of the | |
14070 | individual locations. */ | |
0d381245 | 14071 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
14072 | return; |
14073 | ||
fe3f5fa8 VP |
14074 | b->loc = NULL; |
14075 | ||
0d381245 | 14076 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14077 | { |
f8eba3c6 TT |
14078 | struct bp_location *new_loc; |
14079 | ||
14080 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14081 | ||
14082 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14083 | |
0d381245 VP |
14084 | /* Reparse conditions, they might contain references to the |
14085 | old symtab. */ | |
14086 | if (b->cond_string != NULL) | |
14087 | { | |
bbc13ae3 | 14088 | const char *s; |
fe3f5fa8 | 14089 | |
0d381245 | 14090 | s = b->cond_string; |
492d29ea | 14091 | TRY |
0d381245 | 14092 | { |
1bb9788d TT |
14093 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14094 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14095 | 0); |
14096 | } | |
492d29ea | 14097 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 14098 | { |
3e43a32a MS |
14099 | warning (_("failed to reevaluate condition " |
14100 | "for breakpoint %d: %s"), | |
0d381245 VP |
14101 | b->number, e.message); |
14102 | new_loc->enabled = 0; | |
14103 | } | |
492d29ea | 14104 | END_CATCH |
0d381245 | 14105 | } |
fe3f5fa8 | 14106 | |
f1310107 TJB |
14107 | if (sals_end.nelts) |
14108 | { | |
14109 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14110 | ||
14111 | new_loc->length = end - sals.sals[0].pc + 1; | |
14112 | } | |
0d381245 | 14113 | } |
fe3f5fa8 | 14114 | |
4a64f543 MS |
14115 | /* If possible, carry over 'disable' status from existing |
14116 | breakpoints. */ | |
0d381245 VP |
14117 | { |
14118 | struct bp_location *e = existing_locations; | |
776592bf DE |
14119 | /* If there are multiple breakpoints with the same function name, |
14120 | e.g. for inline functions, comparing function names won't work. | |
14121 | Instead compare pc addresses; this is just a heuristic as things | |
14122 | may have moved, but in practice it gives the correct answer | |
14123 | often enough until a better solution is found. */ | |
14124 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14125 | ||
0d381245 VP |
14126 | for (; e; e = e->next) |
14127 | { | |
14128 | if (!e->enabled && e->function_name) | |
14129 | { | |
14130 | struct bp_location *l = b->loc; | |
776592bf DE |
14131 | if (have_ambiguous_names) |
14132 | { | |
14133 | for (; l; l = l->next) | |
f1310107 | 14134 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14135 | { |
14136 | l->enabled = 0; | |
14137 | break; | |
14138 | } | |
14139 | } | |
14140 | else | |
14141 | { | |
14142 | for (; l; l = l->next) | |
14143 | if (l->function_name | |
14144 | && strcmp (e->function_name, l->function_name) == 0) | |
14145 | { | |
14146 | l->enabled = 0; | |
14147 | break; | |
14148 | } | |
14149 | } | |
0d381245 VP |
14150 | } |
14151 | } | |
14152 | } | |
fe3f5fa8 | 14153 | |
8d3788bd VP |
14154 | if (!locations_are_equal (existing_locations, b->loc)) |
14155 | observer_notify_breakpoint_modified (b); | |
14156 | ||
44702360 | 14157 | update_global_location_list (UGLL_MAY_INSERT); |
fe3f5fa8 VP |
14158 | } |
14159 | ||
f00aae0f | 14160 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
14161 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
14162 | ||
14163 | static struct symtabs_and_lines | |
f00aae0f KS |
14164 | location_to_sals (struct breakpoint *b, struct event_location *location, |
14165 | int *found) | |
ef23e705 | 14166 | { |
02d20e4a | 14167 | struct symtabs_and_lines sals = {0}; |
492d29ea | 14168 | struct gdb_exception exception = exception_none; |
ef23e705 | 14169 | |
983af33b | 14170 | gdb_assert (b->ops != NULL); |
ef23e705 | 14171 | |
492d29ea | 14172 | TRY |
ef23e705 | 14173 | { |
f00aae0f | 14174 | b->ops->decode_location (b, location, &sals); |
ef23e705 | 14175 | } |
492d29ea | 14176 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14177 | { |
14178 | int not_found_and_ok = 0; | |
492d29ea PA |
14179 | |
14180 | exception = e; | |
14181 | ||
ef23e705 TJB |
14182 | /* For pending breakpoints, it's expected that parsing will |
14183 | fail until the right shared library is loaded. User has | |
14184 | already told to create pending breakpoints and don't need | |
14185 | extra messages. If breakpoint is in bp_shlib_disabled | |
14186 | state, then user already saw the message about that | |
14187 | breakpoint being disabled, and don't want to see more | |
14188 | errors. */ | |
58438ac1 | 14189 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14190 | && (b->condition_not_parsed |
14191 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14192 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14193 | || b->enable_state == bp_disabled)) |
14194 | not_found_and_ok = 1; | |
14195 | ||
14196 | if (!not_found_and_ok) | |
14197 | { | |
14198 | /* We surely don't want to warn about the same breakpoint | |
14199 | 10 times. One solution, implemented here, is disable | |
14200 | the breakpoint on error. Another solution would be to | |
14201 | have separate 'warning emitted' flag. Since this | |
14202 | happens only when a binary has changed, I don't know | |
14203 | which approach is better. */ | |
14204 | b->enable_state = bp_disabled; | |
14205 | throw_exception (e); | |
14206 | } | |
14207 | } | |
492d29ea | 14208 | END_CATCH |
ef23e705 | 14209 | |
492d29ea | 14210 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14211 | { |
f8eba3c6 | 14212 | int i; |
ef23e705 | 14213 | |
f8eba3c6 TT |
14214 | for (i = 0; i < sals.nelts; ++i) |
14215 | resolve_sal_pc (&sals.sals[i]); | |
f00aae0f | 14216 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14217 | { |
ed1d1739 KS |
14218 | char *cond_string, *extra_string; |
14219 | int thread, task; | |
ef23e705 | 14220 | |
f00aae0f | 14221 | find_condition_and_thread (b->extra_string, sals.sals[0].pc, |
e7e0cddf SS |
14222 | &cond_string, &thread, &task, |
14223 | &extra_string); | |
f00aae0f | 14224 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14225 | if (cond_string) |
14226 | b->cond_string = cond_string; | |
14227 | b->thread = thread; | |
14228 | b->task = task; | |
e7e0cddf | 14229 | if (extra_string) |
f00aae0f KS |
14230 | { |
14231 | xfree (b->extra_string); | |
14232 | b->extra_string = extra_string; | |
14233 | } | |
ef23e705 TJB |
14234 | b->condition_not_parsed = 0; |
14235 | } | |
14236 | ||
983af33b | 14237 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14238 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14239 | |
58438ac1 TT |
14240 | *found = 1; |
14241 | } | |
14242 | else | |
14243 | *found = 0; | |
ef23e705 TJB |
14244 | |
14245 | return sals; | |
14246 | } | |
14247 | ||
348d480f PA |
14248 | /* The default re_set method, for typical hardware or software |
14249 | breakpoints. Reevaluate the breakpoint and recreate its | |
14250 | locations. */ | |
14251 | ||
14252 | static void | |
28010a5d | 14253 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14254 | { |
14255 | int found; | |
f1310107 | 14256 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14257 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14258 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 | 14259 | |
f00aae0f | 14260 | sals = location_to_sals (b, b->location, &found); |
ef23e705 TJB |
14261 | if (found) |
14262 | { | |
14263 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14264 | expanded = sals; |
ef23e705 TJB |
14265 | } |
14266 | ||
f00aae0f | 14267 | if (b->location_range_end != NULL) |
f1310107 | 14268 | { |
f00aae0f | 14269 | sals_end = location_to_sals (b, b->location_range_end, &found); |
f1310107 TJB |
14270 | if (found) |
14271 | { | |
14272 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14273 | expanded_end = sals_end; |
f1310107 TJB |
14274 | } |
14275 | } | |
14276 | ||
14277 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14278 | } |
14279 | ||
983af33b SDJ |
14280 | /* Default method for creating SALs from an address string. It basically |
14281 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14282 | ||
14283 | static void | |
f00aae0f KS |
14284 | create_sals_from_location_default (const struct event_location *location, |
14285 | struct linespec_result *canonical, | |
14286 | enum bptype type_wanted) | |
983af33b | 14287 | { |
f00aae0f | 14288 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14289 | } |
14290 | ||
14291 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14292 | function for the `create_breakpoints_sal' method of | |
14293 | breakpoint_ops. */ | |
14294 | ||
14295 | static void | |
14296 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14297 | struct linespec_result *canonical, | |
983af33b | 14298 | char *cond_string, |
e7e0cddf | 14299 | char *extra_string, |
983af33b SDJ |
14300 | enum bptype type_wanted, |
14301 | enum bpdisp disposition, | |
14302 | int thread, | |
14303 | int task, int ignore_count, | |
14304 | const struct breakpoint_ops *ops, | |
14305 | int from_tty, int enabled, | |
44f238bb | 14306 | int internal, unsigned flags) |
983af33b SDJ |
14307 | { |
14308 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14309 | extra_string, |
983af33b SDJ |
14310 | type_wanted, disposition, |
14311 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14312 | enabled, internal, flags); |
983af33b SDJ |
14313 | } |
14314 | ||
14315 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14316 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b SDJ |
14317 | |
14318 | static void | |
f00aae0f KS |
14319 | decode_location_default (struct breakpoint *b, |
14320 | const struct event_location *location, | |
983af33b SDJ |
14321 | struct symtabs_and_lines *sals) |
14322 | { | |
14323 | struct linespec_result canonical; | |
14324 | ||
14325 | init_linespec_result (&canonical); | |
f00aae0f | 14326 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, |
983af33b SDJ |
14327 | (struct symtab *) NULL, 0, |
14328 | &canonical, multiple_symbols_all, | |
14329 | b->filter); | |
14330 | ||
14331 | /* We should get 0 or 1 resulting SALs. */ | |
14332 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14333 | ||
14334 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14335 | { | |
14336 | struct linespec_sals *lsal; | |
14337 | ||
14338 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14339 | *sals = lsal->sals; | |
14340 | /* Arrange it so the destructor does not free the | |
14341 | contents. */ | |
14342 | lsal->sals.sals = NULL; | |
14343 | } | |
14344 | ||
14345 | destroy_linespec_result (&canonical); | |
14346 | } | |
14347 | ||
28010a5d PA |
14348 | /* Prepare the global context for a re-set of breakpoint B. */ |
14349 | ||
14350 | static struct cleanup * | |
14351 | prepare_re_set_context (struct breakpoint *b) | |
14352 | { | |
14353 | struct cleanup *cleanups; | |
14354 | ||
14355 | input_radix = b->input_radix; | |
14356 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14357 | if (b->pspace != NULL) |
14358 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14359 | set_language (b->language); |
14360 | ||
14361 | return cleanups; | |
ef23e705 TJB |
14362 | } |
14363 | ||
c906108c SS |
14364 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14365 | The value we return ends up being the return value from catch_errors. | |
14366 | Unused in this case. */ | |
14367 | ||
14368 | static int | |
4efb68b1 | 14369 | breakpoint_re_set_one (void *bint) |
c906108c | 14370 | { |
4a64f543 | 14371 | /* Get past catch_errs. */ |
53a5351d | 14372 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14373 | struct cleanup *cleanups; |
c906108c | 14374 | |
348d480f PA |
14375 | cleanups = prepare_re_set_context (b); |
14376 | b->ops->re_set (b); | |
14377 | do_cleanups (cleanups); | |
c906108c SS |
14378 | return 0; |
14379 | } | |
14380 | ||
69de3c6a | 14381 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14382 | void |
69de3c6a | 14383 | breakpoint_re_set (void) |
c906108c | 14384 | { |
35df4500 | 14385 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14386 | enum language save_language; |
14387 | int save_input_radix; | |
6c95b8df | 14388 | struct cleanup *old_chain; |
c5aa993b | 14389 | |
c906108c SS |
14390 | save_language = current_language->la_language; |
14391 | save_input_radix = input_radix; | |
6c95b8df PA |
14392 | old_chain = save_current_program_space (); |
14393 | ||
35df4500 | 14394 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14395 | { |
4a64f543 | 14396 | /* Format possible error msg. */ |
fe3f5fa8 | 14397 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14398 | b->number); |
14399 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14400 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14401 | do_cleanups (cleanups); |
c5aa993b | 14402 | } |
c906108c SS |
14403 | set_language (save_language); |
14404 | input_radix = save_input_radix; | |
e62c965a | 14405 | |
0756c555 | 14406 | jit_breakpoint_re_set (); |
4efc6507 | 14407 | |
6c95b8df PA |
14408 | do_cleanups (old_chain); |
14409 | ||
af02033e PP |
14410 | create_overlay_event_breakpoint (); |
14411 | create_longjmp_master_breakpoint (); | |
14412 | create_std_terminate_master_breakpoint (); | |
186c406b | 14413 | create_exception_master_breakpoint (); |
c906108c SS |
14414 | } |
14415 | \f | |
c906108c SS |
14416 | /* Reset the thread number of this breakpoint: |
14417 | ||
14418 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14419 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14420 | void |
fba45db2 | 14421 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14422 | { |
14423 | if (b->thread != -1) | |
14424 | { | |
39f77062 KB |
14425 | if (in_thread_list (inferior_ptid)) |
14426 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14427 | |
14428 | /* We're being called after following a fork. The new fork is | |
14429 | selected as current, and unless this was a vfork will have a | |
14430 | different program space from the original thread. Reset that | |
14431 | as well. */ | |
14432 | b->loc->pspace = current_program_space; | |
c906108c SS |
14433 | } |
14434 | } | |
14435 | ||
03ac34d5 MS |
14436 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14437 | If from_tty is nonzero, it prints a message to that effect, | |
14438 | which ends with a period (no newline). */ | |
14439 | ||
c906108c | 14440 | void |
fba45db2 | 14441 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14442 | { |
52f0bd74 | 14443 | struct breakpoint *b; |
c906108c SS |
14444 | |
14445 | if (count < 0) | |
14446 | count = 0; | |
14447 | ||
14448 | ALL_BREAKPOINTS (b) | |
14449 | if (b->number == bptnum) | |
c5aa993b | 14450 | { |
d77f58be SS |
14451 | if (is_tracepoint (b)) |
14452 | { | |
14453 | if (from_tty && count != 0) | |
14454 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14455 | bptnum); | |
14456 | return; | |
14457 | } | |
14458 | ||
c5aa993b | 14459 | b->ignore_count = count; |
221ea385 KS |
14460 | if (from_tty) |
14461 | { | |
14462 | if (count == 0) | |
3e43a32a MS |
14463 | printf_filtered (_("Will stop next time " |
14464 | "breakpoint %d is reached."), | |
221ea385 KS |
14465 | bptnum); |
14466 | else if (count == 1) | |
a3f17187 | 14467 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14468 | bptnum); |
14469 | else | |
3e43a32a MS |
14470 | printf_filtered (_("Will ignore next %d " |
14471 | "crossings of breakpoint %d."), | |
221ea385 KS |
14472 | count, bptnum); |
14473 | } | |
8d3788bd | 14474 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14475 | return; |
14476 | } | |
c906108c | 14477 | |
8a3fe4f8 | 14478 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14479 | } |
14480 | ||
c906108c SS |
14481 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14482 | ||
14483 | static void | |
fba45db2 | 14484 | ignore_command (char *args, int from_tty) |
c906108c SS |
14485 | { |
14486 | char *p = args; | |
52f0bd74 | 14487 | int num; |
c906108c SS |
14488 | |
14489 | if (p == 0) | |
e2e0b3e5 | 14490 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14491 | |
c906108c | 14492 | num = get_number (&p); |
5c44784c | 14493 | if (num == 0) |
8a3fe4f8 | 14494 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14495 | if (*p == 0) |
8a3fe4f8 | 14496 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14497 | |
14498 | set_ignore_count (num, | |
14499 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14500 | from_tty); | |
221ea385 KS |
14501 | if (from_tty) |
14502 | printf_filtered ("\n"); | |
c906108c SS |
14503 | } |
14504 | \f | |
14505 | /* Call FUNCTION on each of the breakpoints | |
14506 | whose numbers are given in ARGS. */ | |
14507 | ||
14508 | static void | |
95a42b64 TT |
14509 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14510 | void *), | |
14511 | void *data) | |
c906108c | 14512 | { |
52f0bd74 AC |
14513 | int num; |
14514 | struct breakpoint *b, *tmp; | |
11cf8741 | 14515 | int match; |
197f0a60 | 14516 | struct get_number_or_range_state state; |
c906108c | 14517 | |
b9d61307 | 14518 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14519 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14520 | |
197f0a60 TT |
14521 | init_number_or_range (&state, args); |
14522 | ||
14523 | while (!state.finished) | |
c906108c | 14524 | { |
e799154c | 14525 | const char *p = state.string; |
197f0a60 | 14526 | |
11cf8741 | 14527 | match = 0; |
c5aa993b | 14528 | |
197f0a60 | 14529 | num = get_number_or_range (&state); |
5c44784c | 14530 | if (num == 0) |
c5aa993b | 14531 | { |
8a3fe4f8 | 14532 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14533 | } |
14534 | else | |
14535 | { | |
14536 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14537 | if (b->number == num) | |
14538 | { | |
11cf8741 | 14539 | match = 1; |
cdac0397 | 14540 | function (b, data); |
11cf8741 | 14541 | break; |
5c44784c | 14542 | } |
11cf8741 | 14543 | if (match == 0) |
a3f17187 | 14544 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14545 | } |
c906108c SS |
14546 | } |
14547 | } | |
14548 | ||
0d381245 VP |
14549 | static struct bp_location * |
14550 | find_location_by_number (char *number) | |
14551 | { | |
14552 | char *dot = strchr (number, '.'); | |
14553 | char *p1; | |
14554 | int bp_num; | |
14555 | int loc_num; | |
14556 | struct breakpoint *b; | |
14557 | struct bp_location *loc; | |
14558 | ||
14559 | *dot = '\0'; | |
14560 | ||
14561 | p1 = number; | |
197f0a60 | 14562 | bp_num = get_number (&p1); |
0d381245 VP |
14563 | if (bp_num == 0) |
14564 | error (_("Bad breakpoint number '%s'"), number); | |
14565 | ||
14566 | ALL_BREAKPOINTS (b) | |
14567 | if (b->number == bp_num) | |
14568 | { | |
14569 | break; | |
14570 | } | |
14571 | ||
14572 | if (!b || b->number != bp_num) | |
14573 | error (_("Bad breakpoint number '%s'"), number); | |
14574 | ||
14575 | p1 = dot+1; | |
197f0a60 | 14576 | loc_num = get_number (&p1); |
0d381245 VP |
14577 | if (loc_num == 0) |
14578 | error (_("Bad breakpoint location number '%s'"), number); | |
14579 | ||
14580 | --loc_num; | |
14581 | loc = b->loc; | |
14582 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14583 | ; | |
14584 | if (!loc) | |
14585 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14586 | ||
14587 | return loc; | |
14588 | } | |
14589 | ||
14590 | ||
1900040c MS |
14591 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14592 | If from_tty is nonzero, it prints a message to that effect, | |
14593 | which ends with a period (no newline). */ | |
14594 | ||
c906108c | 14595 | void |
fba45db2 | 14596 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14597 | { |
14598 | /* Never disable a watchpoint scope breakpoint; we want to | |
14599 | hit them when we leave scope so we can delete both the | |
14600 | watchpoint and its scope breakpoint at that time. */ | |
14601 | if (bpt->type == bp_watchpoint_scope) | |
14602 | return; | |
14603 | ||
b5de0fa7 | 14604 | bpt->enable_state = bp_disabled; |
c906108c | 14605 | |
b775012e LM |
14606 | /* Mark breakpoint locations modified. */ |
14607 | mark_breakpoint_modified (bpt); | |
14608 | ||
d248b706 KY |
14609 | if (target_supports_enable_disable_tracepoint () |
14610 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14611 | { | |
14612 | struct bp_location *location; | |
14613 | ||
14614 | for (location = bpt->loc; location; location = location->next) | |
14615 | target_disable_tracepoint (location); | |
14616 | } | |
14617 | ||
44702360 | 14618 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14619 | |
8d3788bd | 14620 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14621 | } |
14622 | ||
51be5b68 PA |
14623 | /* A callback for iterate_over_related_breakpoints. */ |
14624 | ||
14625 | static void | |
14626 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14627 | { | |
14628 | disable_breakpoint (b); | |
14629 | } | |
14630 | ||
95a42b64 TT |
14631 | /* A callback for map_breakpoint_numbers that calls |
14632 | disable_breakpoint. */ | |
14633 | ||
14634 | static void | |
14635 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14636 | { | |
51be5b68 | 14637 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14638 | } |
14639 | ||
c906108c | 14640 | static void |
fba45db2 | 14641 | disable_command (char *args, int from_tty) |
c906108c | 14642 | { |
c906108c | 14643 | if (args == 0) |
46c6471b PA |
14644 | { |
14645 | struct breakpoint *bpt; | |
14646 | ||
14647 | ALL_BREAKPOINTS (bpt) | |
14648 | if (user_breakpoint_p (bpt)) | |
14649 | disable_breakpoint (bpt); | |
14650 | } | |
9eaabc75 | 14651 | else |
0d381245 | 14652 | { |
9eaabc75 MW |
14653 | char *num = extract_arg (&args); |
14654 | ||
14655 | while (num) | |
d248b706 | 14656 | { |
9eaabc75 | 14657 | if (strchr (num, '.')) |
b775012e | 14658 | { |
9eaabc75 MW |
14659 | struct bp_location *loc = find_location_by_number (num); |
14660 | ||
14661 | if (loc) | |
14662 | { | |
14663 | if (loc->enabled) | |
14664 | { | |
14665 | loc->enabled = 0; | |
14666 | mark_breakpoint_location_modified (loc); | |
14667 | } | |
14668 | if (target_supports_enable_disable_tracepoint () | |
14669 | && current_trace_status ()->running && loc->owner | |
14670 | && is_tracepoint (loc->owner)) | |
14671 | target_disable_tracepoint (loc); | |
14672 | } | |
44702360 | 14673 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14674 | } |
9eaabc75 MW |
14675 | else |
14676 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14677 | num = extract_arg (&args); | |
d248b706 | 14678 | } |
0d381245 | 14679 | } |
c906108c SS |
14680 | } |
14681 | ||
14682 | static void | |
816338b5 SS |
14683 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14684 | int count) | |
c906108c | 14685 | { |
afe38095 | 14686 | int target_resources_ok; |
c906108c SS |
14687 | |
14688 | if (bpt->type == bp_hardware_breakpoint) | |
14689 | { | |
14690 | int i; | |
c5aa993b | 14691 | i = hw_breakpoint_used_count (); |
53a5351d | 14692 | target_resources_ok = |
d92524f1 | 14693 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14694 | i + 1, 0); |
c906108c | 14695 | if (target_resources_ok == 0) |
8a3fe4f8 | 14696 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14697 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14698 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14699 | } |
14700 | ||
cc60f2e3 | 14701 | if (is_watchpoint (bpt)) |
c906108c | 14702 | { |
d07205c2 | 14703 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14704 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14705 | |
492d29ea | 14706 | TRY |
c906108c | 14707 | { |
3a5c3e22 PA |
14708 | struct watchpoint *w = (struct watchpoint *) bpt; |
14709 | ||
1e718ff1 TJB |
14710 | orig_enable_state = bpt->enable_state; |
14711 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14712 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14713 | } |
492d29ea | 14714 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14715 | { |
1e718ff1 | 14716 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14717 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14718 | bpt->number); | |
14719 | return; | |
c5aa993b | 14720 | } |
492d29ea | 14721 | END_CATCH |
c906108c | 14722 | } |
0101ce28 | 14723 | |
b775012e LM |
14724 | bpt->enable_state = bp_enabled; |
14725 | ||
14726 | /* Mark breakpoint locations modified. */ | |
14727 | mark_breakpoint_modified (bpt); | |
14728 | ||
d248b706 KY |
14729 | if (target_supports_enable_disable_tracepoint () |
14730 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14731 | { | |
14732 | struct bp_location *location; | |
14733 | ||
14734 | for (location = bpt->loc; location; location = location->next) | |
14735 | target_enable_tracepoint (location); | |
14736 | } | |
14737 | ||
b4c291bb | 14738 | bpt->disposition = disposition; |
816338b5 | 14739 | bpt->enable_count = count; |
44702360 | 14740 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14741 | |
8d3788bd | 14742 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14743 | } |
14744 | ||
fe3f5fa8 | 14745 | |
c906108c | 14746 | void |
fba45db2 | 14747 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14748 | { |
816338b5 | 14749 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14750 | } |
14751 | ||
14752 | static void | |
14753 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14754 | { | |
14755 | enable_breakpoint (bpt); | |
c906108c SS |
14756 | } |
14757 | ||
95a42b64 TT |
14758 | /* A callback for map_breakpoint_numbers that calls |
14759 | enable_breakpoint. */ | |
14760 | ||
14761 | static void | |
14762 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14763 | { | |
51be5b68 | 14764 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14765 | } |
14766 | ||
c906108c SS |
14767 | /* The enable command enables the specified breakpoints (or all defined |
14768 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14769 | in stopping the inferior. */ |
c906108c | 14770 | |
c906108c | 14771 | static void |
fba45db2 | 14772 | enable_command (char *args, int from_tty) |
c906108c | 14773 | { |
c906108c | 14774 | if (args == 0) |
46c6471b PA |
14775 | { |
14776 | struct breakpoint *bpt; | |
14777 | ||
14778 | ALL_BREAKPOINTS (bpt) | |
14779 | if (user_breakpoint_p (bpt)) | |
14780 | enable_breakpoint (bpt); | |
14781 | } | |
9eaabc75 | 14782 | else |
0d381245 | 14783 | { |
9eaabc75 MW |
14784 | char *num = extract_arg (&args); |
14785 | ||
14786 | while (num) | |
d248b706 | 14787 | { |
9eaabc75 | 14788 | if (strchr (num, '.')) |
b775012e | 14789 | { |
9eaabc75 MW |
14790 | struct bp_location *loc = find_location_by_number (num); |
14791 | ||
14792 | if (loc) | |
14793 | { | |
14794 | if (!loc->enabled) | |
14795 | { | |
14796 | loc->enabled = 1; | |
14797 | mark_breakpoint_location_modified (loc); | |
14798 | } | |
14799 | if (target_supports_enable_disable_tracepoint () | |
14800 | && current_trace_status ()->running && loc->owner | |
14801 | && is_tracepoint (loc->owner)) | |
14802 | target_enable_tracepoint (loc); | |
14803 | } | |
44702360 | 14804 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 14805 | } |
9eaabc75 MW |
14806 | else |
14807 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
14808 | num = extract_arg (&args); | |
d248b706 | 14809 | } |
0d381245 | 14810 | } |
c906108c SS |
14811 | } |
14812 | ||
816338b5 SS |
14813 | /* This struct packages up disposition data for application to multiple |
14814 | breakpoints. */ | |
14815 | ||
14816 | struct disp_data | |
14817 | { | |
14818 | enum bpdisp disp; | |
14819 | int count; | |
14820 | }; | |
14821 | ||
c906108c | 14822 | static void |
51be5b68 PA |
14823 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14824 | { | |
816338b5 | 14825 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14826 | |
816338b5 | 14827 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
14828 | } |
14829 | ||
14830 | static void | |
14831 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 14832 | { |
816338b5 | 14833 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
14834 | |
14835 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14836 | } |
14837 | ||
c906108c | 14838 | static void |
fba45db2 | 14839 | enable_once_command (char *args, int from_tty) |
c906108c | 14840 | { |
51be5b68 | 14841 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
14842 | } |
14843 | ||
816338b5 SS |
14844 | static void |
14845 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
14846 | { | |
14847 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
14848 | ||
14849 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
14850 | } | |
14851 | ||
14852 | static void | |
14853 | enable_count_command (char *args, int from_tty) | |
14854 | { | |
b9d61307 SM |
14855 | int count; |
14856 | ||
14857 | if (args == NULL) | |
14858 | error_no_arg (_("hit count")); | |
14859 | ||
14860 | count = get_number (&args); | |
816338b5 SS |
14861 | |
14862 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
14863 | } | |
14864 | ||
c906108c | 14865 | static void |
51be5b68 | 14866 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 14867 | { |
816338b5 | 14868 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
14869 | |
14870 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14871 | } |
14872 | ||
c906108c | 14873 | static void |
fba45db2 | 14874 | enable_delete_command (char *args, int from_tty) |
c906108c | 14875 | { |
51be5b68 | 14876 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
14877 | } |
14878 | \f | |
fa8d40ab JJ |
14879 | static void |
14880 | set_breakpoint_cmd (char *args, int from_tty) | |
14881 | { | |
14882 | } | |
14883 | ||
14884 | static void | |
14885 | show_breakpoint_cmd (char *args, int from_tty) | |
14886 | { | |
14887 | } | |
14888 | ||
1f3b5d1b PP |
14889 | /* Invalidate last known value of any hardware watchpoint if |
14890 | the memory which that value represents has been written to by | |
14891 | GDB itself. */ | |
14892 | ||
14893 | static void | |
8de0566d YQ |
14894 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14895 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14896 | const bfd_byte *data) |
14897 | { | |
14898 | struct breakpoint *bp; | |
14899 | ||
14900 | ALL_BREAKPOINTS (bp) | |
14901 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14902 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14903 | { |
3a5c3e22 | 14904 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14905 | |
3a5c3e22 PA |
14906 | if (wp->val_valid && wp->val) |
14907 | { | |
14908 | struct bp_location *loc; | |
14909 | ||
14910 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14911 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14912 | && loc->address + loc->length > addr | |
14913 | && addr + len > loc->address) | |
14914 | { | |
14915 | value_free (wp->val); | |
14916 | wp->val = NULL; | |
14917 | wp->val_valid = 0; | |
14918 | } | |
14919 | } | |
1f3b5d1b PP |
14920 | } |
14921 | } | |
14922 | ||
8181d85f DJ |
14923 | /* Create and insert a breakpoint for software single step. */ |
14924 | ||
14925 | void | |
6c95b8df | 14926 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
14927 | struct address_space *aspace, |
14928 | CORE_ADDR next_pc) | |
8181d85f | 14929 | { |
7c16b83e PA |
14930 | struct thread_info *tp = inferior_thread (); |
14931 | struct symtab_and_line sal; | |
14932 | CORE_ADDR pc = next_pc; | |
8181d85f | 14933 | |
34b7e8a6 PA |
14934 | if (tp->control.single_step_breakpoints == NULL) |
14935 | { | |
14936 | tp->control.single_step_breakpoints | |
14937 | = new_single_step_breakpoint (tp->num, gdbarch); | |
14938 | } | |
8181d85f | 14939 | |
7c16b83e PA |
14940 | sal = find_pc_line (pc, 0); |
14941 | sal.pc = pc; | |
14942 | sal.section = find_pc_overlay (pc); | |
14943 | sal.explicit_pc = 1; | |
34b7e8a6 | 14944 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14945 | |
7c16b83e | 14946 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14947 | } |
14948 | ||
34b7e8a6 | 14949 | /* See breakpoint.h. */ |
f02253f1 HZ |
14950 | |
14951 | int | |
7c16b83e PA |
14952 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
14953 | struct address_space *aspace, | |
14954 | CORE_ADDR pc) | |
1aafd4da | 14955 | { |
7c16b83e | 14956 | struct bp_location *loc; |
1aafd4da | 14957 | |
7c16b83e PA |
14958 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14959 | if (loc->inserted | |
14960 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14961 | return 1; | |
1aafd4da | 14962 | |
7c16b83e | 14963 | return 0; |
ef370185 JB |
14964 | } |
14965 | ||
14966 | /* Check whether a software single-step breakpoint is inserted at | |
14967 | PC. */ | |
14968 | ||
14969 | int | |
14970 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
14971 | CORE_ADDR pc) | |
14972 | { | |
34b7e8a6 PA |
14973 | struct breakpoint *bpt; |
14974 | ||
14975 | ALL_BREAKPOINTS (bpt) | |
14976 | { | |
14977 | if (bpt->type == bp_single_step | |
14978 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14979 | return 1; | |
14980 | } | |
14981 | return 0; | |
1aafd4da UW |
14982 | } |
14983 | ||
1042e4c0 SS |
14984 | /* Tracepoint-specific operations. */ |
14985 | ||
14986 | /* Set tracepoint count to NUM. */ | |
14987 | static void | |
14988 | set_tracepoint_count (int num) | |
14989 | { | |
14990 | tracepoint_count = num; | |
4fa62494 | 14991 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14992 | } |
14993 | ||
70221824 | 14994 | static void |
1042e4c0 SS |
14995 | trace_command (char *arg, int from_tty) |
14996 | { | |
55aa24fb | 14997 | struct breakpoint_ops *ops; |
f00aae0f KS |
14998 | struct event_location *location; |
14999 | struct cleanup *back_to; | |
55aa24fb SDJ |
15000 | const char *arg_cp = arg; |
15001 | ||
f00aae0f KS |
15002 | location = string_to_event_location (&arg, current_language); |
15003 | back_to = make_cleanup_delete_event_location (location); | |
15004 | if (arg_cp != NULL && probe_linespec_to_ops (&arg_cp) != NULL) | |
55aa24fb SDJ |
15005 | ops = &tracepoint_probe_breakpoint_ops; |
15006 | else | |
15007 | ops = &tracepoint_breakpoint_ops; | |
15008 | ||
558a9d82 | 15009 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15010 | location, |
15011 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15012 | 0 /* tempflag */, |
15013 | bp_tracepoint /* type_wanted */, | |
15014 | 0 /* Ignore count */, | |
15015 | pending_break_support, | |
15016 | ops, | |
15017 | from_tty, | |
15018 | 1 /* enabled */, | |
15019 | 0 /* internal */, 0); | |
f00aae0f | 15020 | do_cleanups (back_to); |
1042e4c0 SS |
15021 | } |
15022 | ||
70221824 | 15023 | static void |
7a697b8d SS |
15024 | ftrace_command (char *arg, int from_tty) |
15025 | { | |
f00aae0f KS |
15026 | struct event_location *location; |
15027 | struct cleanup *back_to; | |
15028 | ||
15029 | location = string_to_event_location (&arg, current_language); | |
15030 | back_to = make_cleanup_delete_event_location (location); | |
558a9d82 | 15031 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15032 | location, |
15033 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15034 | 0 /* tempflag */, |
15035 | bp_fast_tracepoint /* type_wanted */, | |
15036 | 0 /* Ignore count */, | |
15037 | pending_break_support, | |
15038 | &tracepoint_breakpoint_ops, | |
15039 | from_tty, | |
15040 | 1 /* enabled */, | |
15041 | 0 /* internal */, 0); | |
f00aae0f | 15042 | do_cleanups (back_to); |
0fb4aa4b PA |
15043 | } |
15044 | ||
15045 | /* strace command implementation. Creates a static tracepoint. */ | |
15046 | ||
70221824 | 15047 | static void |
0fb4aa4b PA |
15048 | strace_command (char *arg, int from_tty) |
15049 | { | |
983af33b | 15050 | struct breakpoint_ops *ops; |
f00aae0f KS |
15051 | struct event_location *location; |
15052 | struct cleanup *back_to; | |
983af33b SDJ |
15053 | |
15054 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15055 | or with a normal static tracepoint. */ | |
61012eef | 15056 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
15057 | { |
15058 | ops = &strace_marker_breakpoint_ops; | |
15059 | location = new_linespec_location (&arg); | |
15060 | } | |
983af33b | 15061 | else |
f00aae0f KS |
15062 | { |
15063 | ops = &tracepoint_breakpoint_ops; | |
15064 | location = string_to_event_location (&arg, current_language); | |
15065 | } | |
983af33b | 15066 | |
f00aae0f | 15067 | back_to = make_cleanup_delete_event_location (location); |
558a9d82 | 15068 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15069 | location, |
15070 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15071 | 0 /* tempflag */, |
15072 | bp_static_tracepoint /* type_wanted */, | |
15073 | 0 /* Ignore count */, | |
15074 | pending_break_support, | |
15075 | ops, | |
15076 | from_tty, | |
15077 | 1 /* enabled */, | |
15078 | 0 /* internal */, 0); | |
f00aae0f | 15079 | do_cleanups (back_to); |
7a697b8d SS |
15080 | } |
15081 | ||
409873ef SS |
15082 | /* Set up a fake reader function that gets command lines from a linked |
15083 | list that was acquired during tracepoint uploading. */ | |
15084 | ||
15085 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15086 | static int next_cmd; |
409873ef SS |
15087 | |
15088 | static char * | |
15089 | read_uploaded_action (void) | |
15090 | { | |
15091 | char *rslt; | |
15092 | ||
3149d8c1 | 15093 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15094 | |
3149d8c1 | 15095 | next_cmd++; |
409873ef SS |
15096 | |
15097 | return rslt; | |
15098 | } | |
15099 | ||
00bf0b85 SS |
15100 | /* Given information about a tracepoint as recorded on a target (which |
15101 | can be either a live system or a trace file), attempt to create an | |
15102 | equivalent GDB tracepoint. This is not a reliable process, since | |
15103 | the target does not necessarily have all the information used when | |
15104 | the tracepoint was originally defined. */ | |
15105 | ||
d9b3f62e | 15106 | struct tracepoint * |
00bf0b85 | 15107 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15108 | { |
409873ef | 15109 | char *addr_str, small_buf[100]; |
d9b3f62e | 15110 | struct tracepoint *tp; |
f00aae0f KS |
15111 | struct event_location *location; |
15112 | struct cleanup *cleanup; | |
fd9b8c24 | 15113 | |
409873ef SS |
15114 | if (utp->at_string) |
15115 | addr_str = utp->at_string; | |
15116 | else | |
15117 | { | |
15118 | /* In the absence of a source location, fall back to raw | |
15119 | address. Since there is no way to confirm that the address | |
15120 | means the same thing as when the trace was started, warn the | |
15121 | user. */ | |
3e43a32a MS |
15122 | warning (_("Uploaded tracepoint %d has no " |
15123 | "source location, using raw address"), | |
409873ef | 15124 | utp->number); |
8c042590 | 15125 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15126 | addr_str = small_buf; |
15127 | } | |
15128 | ||
15129 | /* There's not much we can do with a sequence of bytecodes. */ | |
15130 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15131 | warning (_("Uploaded tracepoint %d condition " |
15132 | "has no source form, ignoring it"), | |
409873ef | 15133 | utp->number); |
d5551862 | 15134 | |
f00aae0f KS |
15135 | location = string_to_event_location (&addr_str, current_language); |
15136 | cleanup = make_cleanup_delete_event_location (location); | |
8cdf0e15 | 15137 | if (!create_breakpoint (get_current_arch (), |
f00aae0f KS |
15138 | location, |
15139 | utp->cond_string, -1, addr_str, | |
e7e0cddf | 15140 | 0 /* parse cond/thread */, |
8cdf0e15 | 15141 | 0 /* tempflag */, |
0fb4aa4b | 15142 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15143 | 0 /* Ignore count */, |
15144 | pending_break_support, | |
348d480f | 15145 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15146 | 0 /* from_tty */, |
84f4c1fe | 15147 | utp->enabled /* enabled */, |
44f238bb PA |
15148 | 0 /* internal */, |
15149 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
f00aae0f KS |
15150 | { |
15151 | do_cleanups (cleanup); | |
15152 | return NULL; | |
15153 | } | |
15154 | ||
15155 | do_cleanups (cleanup); | |
fd9b8c24 | 15156 | |
409873ef | 15157 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15158 | tp = get_tracepoint (tracepoint_count); |
15159 | gdb_assert (tp != NULL); | |
d5551862 | 15160 | |
00bf0b85 SS |
15161 | if (utp->pass > 0) |
15162 | { | |
8c042590 PM |
15163 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15164 | tp->base.number); | |
00bf0b85 | 15165 | |
409873ef | 15166 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15167 | } |
15168 | ||
409873ef SS |
15169 | /* If we have uploaded versions of the original commands, set up a |
15170 | special-purpose "reader" function and call the usual command line | |
15171 | reader, then pass the result to the breakpoint command-setting | |
15172 | function. */ | |
3149d8c1 | 15173 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15174 | { |
409873ef | 15175 | struct command_line *cmd_list; |
00bf0b85 | 15176 | |
409873ef | 15177 | this_utp = utp; |
3149d8c1 | 15178 | next_cmd = 0; |
d5551862 | 15179 | |
409873ef SS |
15180 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15181 | ||
d9b3f62e | 15182 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15183 | } |
3149d8c1 SS |
15184 | else if (!VEC_empty (char_ptr, utp->actions) |
15185 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15186 | warning (_("Uploaded tracepoint %d actions " |
15187 | "have no source form, ignoring them"), | |
409873ef | 15188 | utp->number); |
00bf0b85 | 15189 | |
f196051f SS |
15190 | /* Copy any status information that might be available. */ |
15191 | tp->base.hit_count = utp->hit_count; | |
15192 | tp->traceframe_usage = utp->traceframe_usage; | |
15193 | ||
00bf0b85 | 15194 | return tp; |
d9b3f62e | 15195 | } |
00bf0b85 | 15196 | |
1042e4c0 SS |
15197 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15198 | omitted. */ | |
15199 | ||
15200 | static void | |
e5a67952 | 15201 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15202 | { |
79a45e25 | 15203 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15204 | int num_printed; |
1042e4c0 | 15205 | |
e5a67952 | 15206 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15207 | |
15208 | if (num_printed == 0) | |
1042e4c0 | 15209 | { |
e5a67952 | 15210 | if (args == NULL || *args == '\0') |
d77f58be SS |
15211 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15212 | else | |
e5a67952 | 15213 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15214 | } |
ad443146 SS |
15215 | |
15216 | default_collect_info (); | |
1042e4c0 SS |
15217 | } |
15218 | ||
4a64f543 | 15219 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15220 | Not supported by all targets. */ |
15221 | static void | |
15222 | enable_trace_command (char *args, int from_tty) | |
15223 | { | |
15224 | enable_command (args, from_tty); | |
15225 | } | |
15226 | ||
4a64f543 | 15227 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15228 | Not supported by all targets. */ |
15229 | static void | |
15230 | disable_trace_command (char *args, int from_tty) | |
15231 | { | |
15232 | disable_command (args, from_tty); | |
15233 | } | |
15234 | ||
4a64f543 | 15235 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15236 | static void |
15237 | delete_trace_command (char *arg, int from_tty) | |
15238 | { | |
35df4500 | 15239 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15240 | |
15241 | dont_repeat (); | |
15242 | ||
15243 | if (arg == 0) | |
15244 | { | |
15245 | int breaks_to_delete = 0; | |
15246 | ||
15247 | /* Delete all breakpoints if no argument. | |
15248 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15249 | have to be deleted with an explicit breakpoint number |
15250 | argument. */ | |
1042e4c0 | 15251 | ALL_TRACEPOINTS (b) |
46c6471b | 15252 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15253 | { |
15254 | breaks_to_delete = 1; | |
15255 | break; | |
15256 | } | |
1042e4c0 SS |
15257 | |
15258 | /* Ask user only if there are some breakpoints to delete. */ | |
15259 | if (!from_tty | |
15260 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15261 | { | |
35df4500 | 15262 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15263 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15264 | delete_breakpoint (b); |
1042e4c0 SS |
15265 | } |
15266 | } | |
15267 | else | |
51be5b68 | 15268 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15269 | } |
15270 | ||
197f0a60 TT |
15271 | /* Helper function for trace_pass_command. */ |
15272 | ||
15273 | static void | |
d9b3f62e | 15274 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15275 | { |
d9b3f62e | 15276 | tp->pass_count = count; |
6f6484cd | 15277 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15278 | if (from_tty) |
15279 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15280 | tp->base.number, count); |
197f0a60 TT |
15281 | } |
15282 | ||
1042e4c0 SS |
15283 | /* Set passcount for tracepoint. |
15284 | ||
15285 | First command argument is passcount, second is tracepoint number. | |
15286 | If tracepoint number omitted, apply to most recently defined. | |
15287 | Also accepts special argument "all". */ | |
15288 | ||
15289 | static void | |
15290 | trace_pass_command (char *args, int from_tty) | |
15291 | { | |
d9b3f62e | 15292 | struct tracepoint *t1; |
1042e4c0 | 15293 | unsigned int count; |
1042e4c0 SS |
15294 | |
15295 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15296 | error (_("passcount command requires an " |
15297 | "argument (count + optional TP num)")); | |
1042e4c0 | 15298 | |
4a64f543 | 15299 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15300 | |
529480d0 | 15301 | args = skip_spaces (args); |
1042e4c0 SS |
15302 | if (*args && strncasecmp (args, "all", 3) == 0) |
15303 | { | |
d9b3f62e PA |
15304 | struct breakpoint *b; |
15305 | ||
1042e4c0 | 15306 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15307 | if (*args) |
15308 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15309 | |
d9b3f62e | 15310 | ALL_TRACEPOINTS (b) |
197f0a60 | 15311 | { |
d9b3f62e | 15312 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15313 | trace_pass_set_count (t1, count, from_tty); |
15314 | } | |
15315 | } | |
15316 | else if (*args == '\0') | |
1042e4c0 | 15317 | { |
5fa1d40e | 15318 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15319 | if (t1) |
197f0a60 TT |
15320 | trace_pass_set_count (t1, count, from_tty); |
15321 | } | |
15322 | else | |
15323 | { | |
15324 | struct get_number_or_range_state state; | |
15325 | ||
15326 | init_number_or_range (&state, args); | |
15327 | while (!state.finished) | |
1042e4c0 | 15328 | { |
5fa1d40e | 15329 | t1 = get_tracepoint_by_number (&args, &state); |
197f0a60 TT |
15330 | if (t1) |
15331 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15332 | } |
15333 | } | |
1042e4c0 SS |
15334 | } |
15335 | ||
d9b3f62e | 15336 | struct tracepoint * |
1042e4c0 SS |
15337 | get_tracepoint (int num) |
15338 | { | |
15339 | struct breakpoint *t; | |
15340 | ||
15341 | ALL_TRACEPOINTS (t) | |
15342 | if (t->number == num) | |
d9b3f62e | 15343 | return (struct tracepoint *) t; |
1042e4c0 SS |
15344 | |
15345 | return NULL; | |
15346 | } | |
15347 | ||
d5551862 SS |
15348 | /* Find the tracepoint with the given target-side number (which may be |
15349 | different from the tracepoint number after disconnecting and | |
15350 | reconnecting). */ | |
15351 | ||
d9b3f62e | 15352 | struct tracepoint * |
d5551862 SS |
15353 | get_tracepoint_by_number_on_target (int num) |
15354 | { | |
d9b3f62e | 15355 | struct breakpoint *b; |
d5551862 | 15356 | |
d9b3f62e PA |
15357 | ALL_TRACEPOINTS (b) |
15358 | { | |
15359 | struct tracepoint *t = (struct tracepoint *) b; | |
15360 | ||
15361 | if (t->number_on_target == num) | |
15362 | return t; | |
15363 | } | |
d5551862 SS |
15364 | |
15365 | return NULL; | |
15366 | } | |
15367 | ||
1042e4c0 | 15368 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15369 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15370 | If the argument is missing, the most recent tracepoint |
15371 | (tracepoint_count) is returned. */ | |
15372 | ||
d9b3f62e | 15373 | struct tracepoint * |
197f0a60 | 15374 | get_tracepoint_by_number (char **arg, |
5fa1d40e | 15375 | struct get_number_or_range_state *state) |
1042e4c0 | 15376 | { |
1042e4c0 SS |
15377 | struct breakpoint *t; |
15378 | int tpnum; | |
15379 | char *instring = arg == NULL ? NULL : *arg; | |
15380 | ||
197f0a60 TT |
15381 | if (state) |
15382 | { | |
15383 | gdb_assert (!state->finished); | |
15384 | tpnum = get_number_or_range (state); | |
15385 | } | |
15386 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15387 | tpnum = tracepoint_count; |
1042e4c0 | 15388 | else |
197f0a60 | 15389 | tpnum = get_number (arg); |
1042e4c0 SS |
15390 | |
15391 | if (tpnum <= 0) | |
15392 | { | |
15393 | if (instring && *instring) | |
15394 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15395 | instring); | |
15396 | else | |
5fa1d40e | 15397 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15398 | return NULL; |
15399 | } | |
15400 | ||
15401 | ALL_TRACEPOINTS (t) | |
15402 | if (t->number == tpnum) | |
15403 | { | |
d9b3f62e | 15404 | return (struct tracepoint *) t; |
1042e4c0 SS |
15405 | } |
15406 | ||
1042e4c0 SS |
15407 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15408 | return NULL; | |
15409 | } | |
15410 | ||
d9b3f62e PA |
15411 | void |
15412 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15413 | { | |
15414 | if (b->thread != -1) | |
15415 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15416 | ||
15417 | if (b->task != 0) | |
15418 | fprintf_unfiltered (fp, " task %d", b->task); | |
15419 | ||
15420 | fprintf_unfiltered (fp, "\n"); | |
15421 | } | |
15422 | ||
6149aea9 PA |
15423 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15424 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15425 | on each breakpoint and only include the ones for which it returns | |
15426 | non-zero. */ | |
15427 | ||
1042e4c0 | 15428 | static void |
6149aea9 PA |
15429 | save_breakpoints (char *filename, int from_tty, |
15430 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15431 | { |
15432 | struct breakpoint *tp; | |
6149aea9 | 15433 | int any = 0; |
1042e4c0 | 15434 | struct cleanup *cleanup; |
a7bdde9e | 15435 | struct ui_file *fp; |
6149aea9 | 15436 | int extra_trace_bits = 0; |
1042e4c0 | 15437 | |
6149aea9 PA |
15438 | if (filename == 0 || *filename == 0) |
15439 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15440 | |
15441 | /* See if we have anything to save. */ | |
6149aea9 | 15442 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15443 | { |
6149aea9 | 15444 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15445 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15446 | continue; |
15447 | ||
15448 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15449 | if (filter && !filter (tp)) | |
15450 | continue; | |
15451 | ||
15452 | any = 1; | |
15453 | ||
15454 | if (is_tracepoint (tp)) | |
15455 | { | |
15456 | extra_trace_bits = 1; | |
15457 | ||
15458 | /* We can stop searching. */ | |
15459 | break; | |
15460 | } | |
1042e4c0 | 15461 | } |
6149aea9 PA |
15462 | |
15463 | if (!any) | |
1042e4c0 | 15464 | { |
6149aea9 | 15465 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15466 | return; |
15467 | } | |
15468 | ||
c718be47 PA |
15469 | filename = tilde_expand (filename); |
15470 | cleanup = make_cleanup (xfree, filename); | |
15471 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15472 | if (!fp) |
6149aea9 PA |
15473 | error (_("Unable to open file '%s' for saving (%s)"), |
15474 | filename, safe_strerror (errno)); | |
a7bdde9e | 15475 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15476 | |
6149aea9 PA |
15477 | if (extra_trace_bits) |
15478 | save_trace_state_variables (fp); | |
8bf6485c | 15479 | |
6149aea9 | 15480 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15481 | { |
6149aea9 | 15482 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15483 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15484 | continue; |
8bf6485c | 15485 | |
6149aea9 PA |
15486 | /* If we have a filter, only save the breakpoints it accepts. */ |
15487 | if (filter && !filter (tp)) | |
15488 | continue; | |
15489 | ||
348d480f | 15490 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15491 | |
6149aea9 PA |
15492 | /* Note, we can't rely on tp->number for anything, as we can't |
15493 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15494 | instead. */ | |
15495 | ||
15496 | if (tp->cond_string) | |
15497 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15498 | ||
15499 | if (tp->ignore_count) | |
15500 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15501 | ||
2d9442cc | 15502 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15503 | { |
6c63c96a | 15504 | struct gdb_exception exception; |
a7bdde9e | 15505 | |
6149aea9 | 15506 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15507 | |
79a45e25 | 15508 | ui_out_redirect (current_uiout, fp); |
492d29ea | 15509 | TRY |
1042e4c0 | 15510 | { |
79a45e25 | 15511 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15512 | } |
492d29ea PA |
15513 | CATCH (ex, RETURN_MASK_ALL) |
15514 | { | |
6c63c96a | 15515 | ui_out_redirect (current_uiout, NULL); |
492d29ea PA |
15516 | throw_exception (ex); |
15517 | } | |
15518 | END_CATCH | |
1042e4c0 | 15519 | |
6c63c96a | 15520 | ui_out_redirect (current_uiout, NULL); |
a7bdde9e | 15521 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15522 | } |
6149aea9 PA |
15523 | |
15524 | if (tp->enable_state == bp_disabled) | |
99894e11 | 15525 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
6149aea9 PA |
15526 | |
15527 | /* If this is a multi-location breakpoint, check if the locations | |
15528 | should be individually disabled. Watchpoint locations are | |
15529 | special, and not user visible. */ | |
15530 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15531 | { | |
15532 | struct bp_location *loc; | |
15533 | int n = 1; | |
15534 | ||
15535 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15536 | if (!loc->enabled) | |
15537 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15538 | } | |
1042e4c0 | 15539 | } |
8bf6485c | 15540 | |
6149aea9 | 15541 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15542 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15543 | ||
1042e4c0 | 15544 | if (from_tty) |
6149aea9 | 15545 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15546 | do_cleanups (cleanup); |
6149aea9 PA |
15547 | } |
15548 | ||
15549 | /* The `save breakpoints' command. */ | |
15550 | ||
15551 | static void | |
15552 | save_breakpoints_command (char *args, int from_tty) | |
15553 | { | |
15554 | save_breakpoints (args, from_tty, NULL); | |
15555 | } | |
15556 | ||
15557 | /* The `save tracepoints' command. */ | |
15558 | ||
15559 | static void | |
15560 | save_tracepoints_command (char *args, int from_tty) | |
15561 | { | |
15562 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15563 | } |
15564 | ||
15565 | /* Create a vector of all tracepoints. */ | |
15566 | ||
15567 | VEC(breakpoint_p) * | |
eeae04df | 15568 | all_tracepoints (void) |
1042e4c0 SS |
15569 | { |
15570 | VEC(breakpoint_p) *tp_vec = 0; | |
15571 | struct breakpoint *tp; | |
15572 | ||
15573 | ALL_TRACEPOINTS (tp) | |
15574 | { | |
15575 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15576 | } | |
15577 | ||
15578 | return tp_vec; | |
15579 | } | |
15580 | ||
c906108c | 15581 | \f |
4a64f543 MS |
15582 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15583 | commands. It is defined as a macro to prevent duplication. | |
15584 | COMMAND should be a string constant containing the name of the | |
15585 | command. */ | |
31e2b00f | 15586 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15587 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15588 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15589 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15590 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15591 | `-probe-dtrace' (for a DTrace probe).\n\ | |
31e2b00f AS |
15592 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
15593 | If a line number is specified, break at start of code for that line.\n\ | |
15594 | If a function is specified, break at start of code for that function.\n\ | |
15595 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
15596 | With no LOCATION, uses current execution address of the selected\n\ |
15597 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15598 | \n\ |
15599 | THREADNUM is the number from \"info threads\".\n\ | |
15600 | CONDITION is a boolean expression.\n\ | |
15601 | \n\ | |
d41c0fc8 PA |
15602 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15603 | conditions are different.\n\ | |
31e2b00f AS |
15604 | \n\ |
15605 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15606 | ||
44feb3ce TT |
15607 | /* List of subcommands for "catch". */ |
15608 | static struct cmd_list_element *catch_cmdlist; | |
15609 | ||
15610 | /* List of subcommands for "tcatch". */ | |
15611 | static struct cmd_list_element *tcatch_cmdlist; | |
15612 | ||
9ac4176b | 15613 | void |
44feb3ce | 15614 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 15615 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15616 | completer_ftype *completer, |
44feb3ce TT |
15617 | void *user_data_catch, |
15618 | void *user_data_tcatch) | |
15619 | { | |
15620 | struct cmd_list_element *command; | |
15621 | ||
15622 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15623 | &catch_cmdlist); | |
15624 | set_cmd_sfunc (command, sfunc); | |
15625 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15626 | set_cmd_completer (command, completer); |
44feb3ce TT |
15627 | |
15628 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15629 | &tcatch_cmdlist); | |
15630 | set_cmd_sfunc (command, sfunc); | |
15631 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15632 | set_cmd_completer (command, completer); |
44feb3ce TT |
15633 | } |
15634 | ||
6149aea9 PA |
15635 | static void |
15636 | save_command (char *arg, int from_tty) | |
15637 | { | |
3e43a32a MS |
15638 | printf_unfiltered (_("\"save\" must be followed by " |
15639 | "the name of a save subcommand.\n")); | |
635c7e8a | 15640 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15641 | } |
15642 | ||
84f4c1fe PM |
15643 | struct breakpoint * |
15644 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15645 | void *data) | |
15646 | { | |
35df4500 | 15647 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15648 | |
35df4500 | 15649 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15650 | { |
15651 | if ((*callback) (b, data)) | |
15652 | return b; | |
15653 | } | |
15654 | ||
15655 | return NULL; | |
15656 | } | |
15657 | ||
0574c78f GB |
15658 | /* Zero if any of the breakpoint's locations could be a location where |
15659 | functions have been inlined, nonzero otherwise. */ | |
15660 | ||
15661 | static int | |
15662 | is_non_inline_function (struct breakpoint *b) | |
15663 | { | |
15664 | /* The shared library event breakpoint is set on the address of a | |
15665 | non-inline function. */ | |
15666 | if (b->type == bp_shlib_event) | |
15667 | return 1; | |
15668 | ||
15669 | return 0; | |
15670 | } | |
15671 | ||
15672 | /* Nonzero if the specified PC cannot be a location where functions | |
15673 | have been inlined. */ | |
15674 | ||
15675 | int | |
09ac7c10 TT |
15676 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15677 | const struct target_waitstatus *ws) | |
0574c78f GB |
15678 | { |
15679 | struct breakpoint *b; | |
15680 | struct bp_location *bl; | |
15681 | ||
15682 | ALL_BREAKPOINTS (b) | |
15683 | { | |
15684 | if (!is_non_inline_function (b)) | |
15685 | continue; | |
15686 | ||
15687 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15688 | { | |
15689 | if (!bl->shlib_disabled | |
09ac7c10 | 15690 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15691 | return 1; |
15692 | } | |
15693 | } | |
15694 | ||
15695 | return 0; | |
15696 | } | |
15697 | ||
2f202fde JK |
15698 | /* Remove any references to OBJFILE which is going to be freed. */ |
15699 | ||
15700 | void | |
15701 | breakpoint_free_objfile (struct objfile *objfile) | |
15702 | { | |
15703 | struct bp_location **locp, *loc; | |
15704 | ||
15705 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15706 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15707 | loc->symtab = NULL; |
15708 | } | |
15709 | ||
2060206e PA |
15710 | void |
15711 | initialize_breakpoint_ops (void) | |
15712 | { | |
15713 | static int initialized = 0; | |
15714 | ||
15715 | struct breakpoint_ops *ops; | |
15716 | ||
15717 | if (initialized) | |
15718 | return; | |
15719 | initialized = 1; | |
15720 | ||
15721 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15722 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15723 | internal and momentary breakpoints, etc.). */ | |
15724 | ops = &bkpt_base_breakpoint_ops; | |
15725 | *ops = base_breakpoint_ops; | |
15726 | ops->re_set = bkpt_re_set; | |
15727 | ops->insert_location = bkpt_insert_location; | |
15728 | ops->remove_location = bkpt_remove_location; | |
15729 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15730 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15731 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15732 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15733 | |
15734 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15735 | ops = &bkpt_breakpoint_ops; | |
15736 | *ops = bkpt_base_breakpoint_ops; | |
15737 | ops->re_set = bkpt_re_set; | |
15738 | ops->resources_needed = bkpt_resources_needed; | |
15739 | ops->print_it = bkpt_print_it; | |
15740 | ops->print_mention = bkpt_print_mention; | |
15741 | ops->print_recreate = bkpt_print_recreate; | |
15742 | ||
15743 | /* Ranged breakpoints. */ | |
15744 | ops = &ranged_breakpoint_ops; | |
15745 | *ops = bkpt_breakpoint_ops; | |
15746 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15747 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15748 | ops->print_it = print_it_ranged_breakpoint; | |
15749 | ops->print_one = print_one_ranged_breakpoint; | |
15750 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15751 | ops->print_mention = print_mention_ranged_breakpoint; | |
15752 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15753 | ||
15754 | /* Internal breakpoints. */ | |
15755 | ops = &internal_breakpoint_ops; | |
15756 | *ops = bkpt_base_breakpoint_ops; | |
15757 | ops->re_set = internal_bkpt_re_set; | |
15758 | ops->check_status = internal_bkpt_check_status; | |
15759 | ops->print_it = internal_bkpt_print_it; | |
15760 | ops->print_mention = internal_bkpt_print_mention; | |
15761 | ||
15762 | /* Momentary breakpoints. */ | |
15763 | ops = &momentary_breakpoint_ops; | |
15764 | *ops = bkpt_base_breakpoint_ops; | |
15765 | ops->re_set = momentary_bkpt_re_set; | |
15766 | ops->check_status = momentary_bkpt_check_status; | |
15767 | ops->print_it = momentary_bkpt_print_it; | |
15768 | ops->print_mention = momentary_bkpt_print_mention; | |
15769 | ||
e2e4d78b JK |
15770 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
15771 | ops = &longjmp_breakpoint_ops; | |
15772 | *ops = momentary_breakpoint_ops; | |
15773 | ops->dtor = longjmp_bkpt_dtor; | |
15774 | ||
55aa24fb SDJ |
15775 | /* Probe breakpoints. */ |
15776 | ops = &bkpt_probe_breakpoint_ops; | |
15777 | *ops = bkpt_breakpoint_ops; | |
15778 | ops->insert_location = bkpt_probe_insert_location; | |
15779 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15780 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15781 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15782 | |
2060206e PA |
15783 | /* Watchpoints. */ |
15784 | ops = &watchpoint_breakpoint_ops; | |
15785 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 15786 | ops->dtor = dtor_watchpoint; |
2060206e PA |
15787 | ops->re_set = re_set_watchpoint; |
15788 | ops->insert_location = insert_watchpoint; | |
15789 | ops->remove_location = remove_watchpoint; | |
15790 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15791 | ops->check_status = check_status_watchpoint; | |
15792 | ops->resources_needed = resources_needed_watchpoint; | |
15793 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15794 | ops->print_it = print_it_watchpoint; | |
15795 | ops->print_mention = print_mention_watchpoint; | |
15796 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15797 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15798 | |
15799 | /* Masked watchpoints. */ | |
15800 | ops = &masked_watchpoint_breakpoint_ops; | |
15801 | *ops = watchpoint_breakpoint_ops; | |
15802 | ops->insert_location = insert_masked_watchpoint; | |
15803 | ops->remove_location = remove_masked_watchpoint; | |
15804 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15805 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15806 | ops->print_it = print_it_masked_watchpoint; | |
15807 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15808 | ops->print_mention = print_mention_masked_watchpoint; | |
15809 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15810 | ||
15811 | /* Tracepoints. */ | |
15812 | ops = &tracepoint_breakpoint_ops; | |
15813 | *ops = base_breakpoint_ops; | |
15814 | ops->re_set = tracepoint_re_set; | |
15815 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15816 | ops->print_one_detail = tracepoint_print_one_detail; | |
15817 | ops->print_mention = tracepoint_print_mention; | |
15818 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15819 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15820 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15821 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15822 | |
55aa24fb SDJ |
15823 | /* Probe tracepoints. */ |
15824 | ops = &tracepoint_probe_breakpoint_ops; | |
15825 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15826 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15827 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15828 | |
983af33b SDJ |
15829 | /* Static tracepoints with marker (`-m'). */ |
15830 | ops = &strace_marker_breakpoint_ops; | |
15831 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15832 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15833 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15834 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15835 | |
15836 | /* Fork catchpoints. */ | |
15837 | ops = &catch_fork_breakpoint_ops; | |
15838 | *ops = base_breakpoint_ops; | |
15839 | ops->insert_location = insert_catch_fork; | |
15840 | ops->remove_location = remove_catch_fork; | |
15841 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15842 | ops->print_it = print_it_catch_fork; | |
15843 | ops->print_one = print_one_catch_fork; | |
15844 | ops->print_mention = print_mention_catch_fork; | |
15845 | ops->print_recreate = print_recreate_catch_fork; | |
15846 | ||
15847 | /* Vfork catchpoints. */ | |
15848 | ops = &catch_vfork_breakpoint_ops; | |
15849 | *ops = base_breakpoint_ops; | |
15850 | ops->insert_location = insert_catch_vfork; | |
15851 | ops->remove_location = remove_catch_vfork; | |
15852 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15853 | ops->print_it = print_it_catch_vfork; | |
15854 | ops->print_one = print_one_catch_vfork; | |
15855 | ops->print_mention = print_mention_catch_vfork; | |
15856 | ops->print_recreate = print_recreate_catch_vfork; | |
15857 | ||
15858 | /* Exec catchpoints. */ | |
15859 | ops = &catch_exec_breakpoint_ops; | |
15860 | *ops = base_breakpoint_ops; | |
15861 | ops->dtor = dtor_catch_exec; | |
15862 | ops->insert_location = insert_catch_exec; | |
15863 | ops->remove_location = remove_catch_exec; | |
15864 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15865 | ops->print_it = print_it_catch_exec; | |
15866 | ops->print_one = print_one_catch_exec; | |
15867 | ops->print_mention = print_mention_catch_exec; | |
15868 | ops->print_recreate = print_recreate_catch_exec; | |
15869 | ||
edcc5120 TT |
15870 | /* Solib-related catchpoints. */ |
15871 | ops = &catch_solib_breakpoint_ops; | |
15872 | *ops = base_breakpoint_ops; | |
15873 | ops->dtor = dtor_catch_solib; | |
15874 | ops->insert_location = insert_catch_solib; | |
15875 | ops->remove_location = remove_catch_solib; | |
15876 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15877 | ops->check_status = check_status_catch_solib; | |
15878 | ops->print_it = print_it_catch_solib; | |
15879 | ops->print_one = print_one_catch_solib; | |
15880 | ops->print_mention = print_mention_catch_solib; | |
15881 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15882 | |
15883 | ops = &dprintf_breakpoint_ops; | |
15884 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15885 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15886 | ops->resources_needed = bkpt_resources_needed; |
15887 | ops->print_it = bkpt_print_it; | |
15888 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15889 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15890 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15891 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15892 | } |
15893 | ||
8bfd80db YQ |
15894 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15895 | ||
15896 | static struct cmd_list_element *enablebreaklist = NULL; | |
15897 | ||
c906108c | 15898 | void |
fba45db2 | 15899 | _initialize_breakpoint (void) |
c906108c SS |
15900 | { |
15901 | struct cmd_list_element *c; | |
15902 | ||
2060206e PA |
15903 | initialize_breakpoint_ops (); |
15904 | ||
84acb35a | 15905 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 15906 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 15907 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 15908 | |
55aa24fb SDJ |
15909 | breakpoint_objfile_key |
15910 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 15911 | |
c906108c SS |
15912 | breakpoint_chain = 0; |
15913 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15914 | before a breakpoint is set. */ | |
15915 | breakpoint_count = 0; | |
15916 | ||
1042e4c0 SS |
15917 | tracepoint_count = 0; |
15918 | ||
1bedd215 AC |
15919 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15920 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15921 | Usage is `ignore N COUNT'.")); | |
c906108c | 15922 | |
1bedd215 AC |
15923 | add_com ("commands", class_breakpoint, commands_command, _("\ |
15924 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
15925 | Give breakpoint number as argument after \"commands\".\n\ |
15926 | With no argument, the targeted breakpoint is the last one set.\n\ | |
15927 | The commands themselves follow starting on the next line.\n\ | |
15928 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15929 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15930 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15931 | |
d55637df | 15932 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 15933 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 15934 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15935 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 15936 | set_cmd_completer (c, condition_completer); |
c906108c | 15937 | |
1bedd215 | 15938 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15939 | Set a temporary breakpoint.\n\ |
c906108c SS |
15940 | Like \"break\" except the breakpoint is only temporary,\n\ |
15941 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15942 | by using \"enable delete\" on the breakpoint number.\n\ |
15943 | \n" | |
15944 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15945 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15946 | |
1bedd215 | 15947 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15948 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15949 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15950 | some target hardware may not have this support.\n\ |
15951 | \n" | |
15952 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15953 | set_cmd_completer (c, location_completer); |
c906108c | 15954 | |
1bedd215 | 15955 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15956 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15957 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15958 | so it will be deleted when hit.\n\ |
15959 | \n" | |
15960 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15961 | set_cmd_completer (c, location_completer); |
c906108c | 15962 | |
1bedd215 AC |
15963 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
15964 | Enable some breakpoints.\n\ | |
c906108c SS |
15965 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15966 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15967 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15968 | With a subcommand you can enable temporarily."), |
c906108c | 15969 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15970 | |
15971 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15972 | ||
84951ab5 | 15973 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 15974 | Enable some breakpoints.\n\ |
c906108c SS |
15975 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15976 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15977 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 15978 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15979 | |
1a966eab AC |
15980 | add_cmd ("once", no_class, enable_once_command, _("\ |
15981 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15982 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
15983 | &enablebreaklist); |
15984 | ||
1a966eab AC |
15985 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15986 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15987 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15988 | &enablebreaklist); |
15989 | ||
816338b5 SS |
15990 | add_cmd ("count", no_class, enable_count_command, _("\ |
15991 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15992 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15993 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15994 | &enablebreaklist); | |
15995 | ||
1a966eab AC |
15996 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15997 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15998 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15999 | &enablelist); |
16000 | ||
1a966eab AC |
16001 | add_cmd ("once", no_class, enable_once_command, _("\ |
16002 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16003 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16004 | &enablelist); |
16005 | ||
16006 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16007 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16008 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16009 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16010 | &enablelist); |
16011 | ||
1bedd215 AC |
16012 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16013 | Disable some breakpoints.\n\ | |
c906108c SS |
16014 | Arguments are breakpoint numbers with spaces in between.\n\ |
16015 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16016 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16017 | &disablelist, "disable ", 1, &cmdlist); |
16018 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16019 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 16020 | |
1a966eab AC |
16021 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16022 | Disable some breakpoints.\n\ | |
c906108c SS |
16023 | Arguments are breakpoint numbers with spaces in between.\n\ |
16024 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16025 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16026 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16027 | &disablelist); |
16028 | ||
1bedd215 AC |
16029 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16030 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16031 | Arguments are breakpoint numbers with spaces in between.\n\ |
16032 | To delete all breakpoints, give no argument.\n\ | |
16033 | \n\ | |
16034 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16035 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16036 | &deletelist, "delete ", 1, &cmdlist); |
16037 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16038 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16039 | |
1a966eab AC |
16040 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16041 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16042 | Arguments are breakpoint numbers with spaces in between.\n\ |
16043 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16044 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16045 | &deletelist); |
16046 | ||
1bedd215 AC |
16047 | add_com ("clear", class_breakpoint, clear_command, _("\ |
16048 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
16049 | Argument may be line number, function name, or \"*\" and an address.\n\ |
16050 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
16051 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
16052 | If an address is specified, breakpoints at that address are cleared.\n\ |
16053 | \n\ | |
16054 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
16055 | is executing in.\n\ |
16056 | \n\ | |
1bedd215 | 16057 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16058 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16059 | |
1bedd215 | 16060 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
16061 | Set breakpoint at specified line or function.\n" |
16062 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 16063 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16064 | |
c906108c SS |
16065 | add_com_alias ("b", "break", class_run, 1); |
16066 | add_com_alias ("br", "break", class_run, 1); | |
16067 | add_com_alias ("bre", "break", class_run, 1); | |
16068 | add_com_alias ("brea", "break", class_run, 1); | |
16069 | ||
c906108c SS |
16070 | if (dbx_commands) |
16071 | { | |
1bedd215 AC |
16072 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16073 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16074 | &stoplist, "stop ", 1, &cmdlist); |
16075 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16076 | _("Break in function or address."), &stoplist); |
c5aa993b | 16077 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16078 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16079 | add_com ("status", class_info, breakpoints_info, _("\ |
16080 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16081 | The \"Type\" column indicates one of:\n\ |
16082 | \tbreakpoint - normal breakpoint\n\ | |
16083 | \twatchpoint - watchpoint\n\ | |
16084 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16085 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16086 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16087 | address and file/line number respectively.\n\ |
16088 | \n\ | |
16089 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16090 | are set to the address of the last breakpoint listed unless the command\n\ |
16091 | is prefixed with \"server \".\n\n\ | |
c906108c | 16092 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16093 | breakpoint set.")); |
c906108c SS |
16094 | } |
16095 | ||
1bedd215 | 16096 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16097 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16098 | The \"Type\" column indicates one of:\n\ |
16099 | \tbreakpoint - normal breakpoint\n\ | |
16100 | \twatchpoint - watchpoint\n\ | |
16101 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16102 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16103 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16104 | address and file/line number respectively.\n\ |
16105 | \n\ | |
16106 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16107 | are set to the address of the last breakpoint listed unless the command\n\ |
16108 | is prefixed with \"server \".\n\n\ | |
c906108c | 16109 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16110 | breakpoint set.")); |
c906108c | 16111 | |
6b04bdb7 MS |
16112 | add_info_alias ("b", "breakpoints", 1); |
16113 | ||
1a966eab AC |
16114 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16115 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16116 | The \"Type\" column indicates one of:\n\ |
16117 | \tbreakpoint - normal breakpoint\n\ | |
16118 | \twatchpoint - watchpoint\n\ | |
16119 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16120 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16121 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16122 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16123 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16124 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16125 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16126 | address and file/line number respectively.\n\ |
16127 | \n\ | |
16128 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16129 | are set to the address of the last breakpoint listed unless the command\n\ |
16130 | is prefixed with \"server \".\n\n\ | |
c906108c | 16131 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16132 | breakpoint set."), |
c906108c SS |
16133 | &maintenanceinfolist); |
16134 | ||
44feb3ce TT |
16135 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16136 | Set catchpoints to catch events."), | |
16137 | &catch_cmdlist, "catch ", | |
16138 | 0/*allow-unknown*/, &cmdlist); | |
16139 | ||
16140 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16141 | Set temporary catchpoints to catch events."), | |
16142 | &tcatch_cmdlist, "tcatch ", | |
16143 | 0/*allow-unknown*/, &cmdlist); | |
16144 | ||
44feb3ce TT |
16145 | add_catch_command ("fork", _("Catch calls to fork."), |
16146 | catch_fork_command_1, | |
a96d9b2e | 16147 | NULL, |
44feb3ce TT |
16148 | (void *) (uintptr_t) catch_fork_permanent, |
16149 | (void *) (uintptr_t) catch_fork_temporary); | |
16150 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16151 | catch_fork_command_1, | |
a96d9b2e | 16152 | NULL, |
44feb3ce TT |
16153 | (void *) (uintptr_t) catch_vfork_permanent, |
16154 | (void *) (uintptr_t) catch_vfork_temporary); | |
16155 | add_catch_command ("exec", _("Catch calls to exec."), | |
16156 | catch_exec_command_1, | |
a96d9b2e SDJ |
16157 | NULL, |
16158 | CATCH_PERMANENT, | |
16159 | CATCH_TEMPORARY); | |
edcc5120 TT |
16160 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16161 | Usage: catch load [REGEX]\n\ | |
16162 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16163 | catch_load_command_1, | |
16164 | NULL, | |
16165 | CATCH_PERMANENT, | |
16166 | CATCH_TEMPORARY); | |
16167 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16168 | Usage: catch unload [REGEX]\n\ | |
16169 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16170 | catch_unload_command_1, | |
16171 | NULL, | |
16172 | CATCH_PERMANENT, | |
16173 | CATCH_TEMPORARY); | |
c5aa993b | 16174 | |
1bedd215 AC |
16175 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16176 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16177 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16178 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16179 | an expression changes.\n\ |
16180 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16181 | the memory to which it refers.")); | |
65d12d83 | 16182 | set_cmd_completer (c, expression_completer); |
c906108c | 16183 | |
1bedd215 AC |
16184 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16185 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16186 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16187 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16188 | an expression is read.\n\ |
16189 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16190 | the memory to which it refers.")); | |
65d12d83 | 16191 | set_cmd_completer (c, expression_completer); |
c906108c | 16192 | |
1bedd215 AC |
16193 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16194 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16195 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16196 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16197 | an expression is either read or written.\n\ |
16198 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16199 | the memory to which it refers.")); | |
65d12d83 | 16200 | set_cmd_completer (c, expression_completer); |
c906108c | 16201 | |
d77f58be | 16202 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16203 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16204 | |
920d2a44 AC |
16205 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16206 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16207 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16208 | &can_use_hw_watchpoints, _("\ | |
16209 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16210 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16211 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16212 | such is available. (However, any hardware watchpoints that were\n\ | |
16213 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16214 | hardware.)"), |
16215 | NULL, | |
920d2a44 | 16216 | show_can_use_hw_watchpoints, |
85c07804 | 16217 | &setlist, &showlist); |
c906108c SS |
16218 | |
16219 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16220 | |
1042e4c0 SS |
16221 | /* Tracepoint manipulation commands. */ |
16222 | ||
16223 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
16224 | Set a tracepoint at specified line or function.\n\ | |
16225 | \n" | |
16226 | BREAK_ARGS_HELP ("trace") "\n\ | |
16227 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16228 | set_cmd_completer (c, location_completer); | |
16229 | ||
16230 | add_com_alias ("tp", "trace", class_alias, 0); | |
16231 | add_com_alias ("tr", "trace", class_alias, 1); | |
16232 | add_com_alias ("tra", "trace", class_alias, 1); | |
16233 | add_com_alias ("trac", "trace", class_alias, 1); | |
16234 | ||
7a697b8d SS |
16235 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
16236 | Set a fast tracepoint at specified line or function.\n\ | |
16237 | \n" | |
16238 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16239 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16240 | set_cmd_completer (c, location_completer); | |
16241 | ||
0fb4aa4b PA |
16242 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
16243 | Set a static tracepoint at specified line, function or marker.\n\ | |
16244 | \n\ | |
16245 | strace [LOCATION] [if CONDITION]\n\ | |
16246 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
16247 | or -m MARKER_ID.\n\ | |
16248 | If a line number is specified, probe the marker at start of code\n\ | |
16249 | for that line. If a function is specified, probe the marker at start\n\ | |
16250 | of code for that function. If an address is specified, probe the marker\n\ | |
16251 | at that exact address. If a marker id is specified, probe the marker\n\ | |
16252 | with that name. With no LOCATION, uses current execution address of\n\ | |
16253 | the selected stack frame.\n\ | |
16254 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
16255 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16256 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16257 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16258 | \n\ | |
16259 | CONDITION is a boolean expression.\n\ | |
16260 | \n\ | |
d41c0fc8 PA |
16261 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16262 | conditions are different.\n\ | |
0fb4aa4b PA |
16263 | \n\ |
16264 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16265 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16266 | set_cmd_completer (c, location_completer); | |
16267 | ||
1042e4c0 | 16268 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16269 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16270 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16271 | last tracepoint set.")); | |
16272 | ||
16273 | add_info_alias ("tp", "tracepoints", 1); | |
16274 | ||
16275 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16276 | Delete specified tracepoints.\n\ | |
16277 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16278 | No argument means delete all tracepoints."), | |
16279 | &deletelist); | |
7e20dfcd | 16280 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16281 | |
16282 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16283 | Disable specified tracepoints.\n\ | |
16284 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16285 | No argument means disable all tracepoints."), | |
16286 | &disablelist); | |
16287 | deprecate_cmd (c, "disable"); | |
16288 | ||
16289 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16290 | Enable specified tracepoints.\n\ | |
16291 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16292 | No argument means enable all tracepoints."), | |
16293 | &enablelist); | |
16294 | deprecate_cmd (c, "enable"); | |
16295 | ||
16296 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16297 | Set the passcount for a tracepoint.\n\ | |
16298 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16299 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16300 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16301 | ||
6149aea9 PA |
16302 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16303 | _("Save breakpoint definitions as a script."), | |
16304 | &save_cmdlist, "save ", | |
16305 | 0/*allow-unknown*/, &cmdlist); | |
16306 | ||
16307 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16308 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16309 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16310 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16311 | session to restore them."), | |
16312 | &save_cmdlist); | |
16313 | set_cmd_completer (c, filename_completer); | |
16314 | ||
16315 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16316 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16317 | Use the 'source' command in another debug session to restore them."), |
16318 | &save_cmdlist); | |
1042e4c0 SS |
16319 | set_cmd_completer (c, filename_completer); |
16320 | ||
6149aea9 PA |
16321 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16322 | deprecate_cmd (c, "save tracepoints"); | |
16323 | ||
1bedd215 | 16324 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16325 | Breakpoint specific settings\n\ |
16326 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16327 | pending breakpoint behavior"), |
fa8d40ab JJ |
16328 | &breakpoint_set_cmdlist, "set breakpoint ", |
16329 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16330 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16331 | Breakpoint specific settings\n\ |
16332 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16333 | pending breakpoint behavior"), |
fa8d40ab JJ |
16334 | &breakpoint_show_cmdlist, "show breakpoint ", |
16335 | 0/*allow-unknown*/, &showlist); | |
16336 | ||
7915a72c AC |
16337 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16338 | &pending_break_support, _("\ | |
16339 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16340 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16341 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16342 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16343 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16344 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16345 | NULL, |
920d2a44 | 16346 | show_pending_break_support, |
6e1d7d6c AC |
16347 | &breakpoint_set_cmdlist, |
16348 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16349 | |
16350 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16351 | |
16352 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16353 | &automatic_hardware_breakpoints, _("\ | |
16354 | Set automatic usage of hardware breakpoints."), _("\ | |
16355 | Show automatic usage of hardware breakpoints."), _("\ | |
16356 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16357 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16358 | a warning will be emitted for such breakpoints."), | |
16359 | NULL, | |
16360 | show_automatic_hardware_breakpoints, | |
16361 | &breakpoint_set_cmdlist, | |
16362 | &breakpoint_show_cmdlist); | |
74960c60 | 16363 | |
a25a5a45 PA |
16364 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16365 | &always_inserted_mode, _("\ | |
74960c60 VP |
16366 | Set mode for inserting breakpoints."), _("\ |
16367 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16368 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16369 | they're created, kept inserted even when execution stops, and removed\n\ | |
16370 | only when the user deletes them. When this mode is off (the default),\n\ | |
16371 | breakpoints are inserted only when execution continues, and removed\n\ | |
16372 | when execution stops."), | |
72d0e2c5 YQ |
16373 | NULL, |
16374 | &show_always_inserted_mode, | |
16375 | &breakpoint_set_cmdlist, | |
16376 | &breakpoint_show_cmdlist); | |
f1310107 | 16377 | |
b775012e LM |
16378 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16379 | condition_evaluation_enums, | |
16380 | &condition_evaluation_mode_1, _("\ | |
16381 | Set mode of breakpoint condition evaluation."), _("\ | |
16382 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16383 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16384 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16385 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16386 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16387 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16388 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16389 | be set to \"gdb\""), | |
16390 | &set_condition_evaluation_mode, | |
16391 | &show_condition_evaluation_mode, | |
16392 | &breakpoint_set_cmdlist, | |
16393 | &breakpoint_show_cmdlist); | |
16394 | ||
f1310107 TJB |
16395 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16396 | Set a breakpoint for an address range.\n\ | |
16397 | break-range START-LOCATION, END-LOCATION\n\ | |
16398 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16399 | LINENUM, for that line in the current file,\n\ | |
16400 | FILE:LINENUM, for that line in that file,\n\ | |
16401 | +OFFSET, for that number of lines after the current line\n\ | |
16402 | or the start of the range\n\ | |
16403 | FUNCTION, for the first line in that function,\n\ | |
16404 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16405 | *ADDRESS, for the instruction at that address.\n\ | |
16406 | \n\ | |
16407 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16408 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16409 | range (including START-LOCATION and END-LOCATION).")); | |
16410 | ||
e7e0cddf SS |
16411 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
16412 | Set a dynamic printf at specified line or function.\n\ | |
16413 | dprintf location,format string,arg1,arg2,...\n\ | |
16414 | location may be a line number, function name, or \"*\" and an address.\n\ | |
16415 | If a line number is specified, break at start of code for that line.\n\ | |
0e4777df | 16416 | If a function is specified, break at start of code for that function.")); |
e7e0cddf SS |
16417 | set_cmd_completer (c, location_completer); |
16418 | ||
16419 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16420 | dprintf_style_enums, &dprintf_style, _("\ | |
16421 | Set the style of usage for dynamic printf."), _("\ | |
16422 | Show the style of usage for dynamic printf."), _("\ | |
16423 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16424 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16425 | console, as with the \"printf\" command.\n\ | |
16426 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16427 | program; by default printf(), but you can choose a different function or\n\ | |
16428 | output stream by setting dprintf-function and dprintf-channel."), | |
16429 | update_dprintf_commands, NULL, | |
16430 | &setlist, &showlist); | |
16431 | ||
16432 | dprintf_function = xstrdup ("printf"); | |
16433 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16434 | &dprintf_function, _("\ | |
16435 | Set the function to use for dynamic printf"), _("\ | |
16436 | Show the function to use for dynamic printf"), NULL, | |
16437 | update_dprintf_commands, NULL, | |
16438 | &setlist, &showlist); | |
16439 | ||
16440 | dprintf_channel = xstrdup (""); | |
16441 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16442 | &dprintf_channel, _("\ | |
16443 | Set the channel to use for dynamic printf"), _("\ | |
16444 | Show the channel to use for dynamic printf"), NULL, | |
16445 | update_dprintf_commands, NULL, | |
16446 | &setlist, &showlist); | |
16447 | ||
d3ce09f5 SS |
16448 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16449 | &disconnected_dprintf, _("\ | |
16450 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16451 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16452 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16453 | even if GDB disconnects or detaches from the target."), | |
16454 | NULL, | |
16455 | NULL, | |
16456 | &setlist, &showlist); | |
16457 | ||
16458 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16459 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16460 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16461 | ||
765dc015 | 16462 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16463 | |
16464 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16465 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16466 | } |