Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
ecd75fc8 | 3 | Copyright (C) 1986-2014 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" |
a96d9b2e | 59 | #include "xml-syscall.h" |
65d79d4b | 60 | #include "parser-defs.h" |
55aa24fb SDJ |
61 | #include "gdb_regex.h" |
62 | #include "probe.h" | |
e9cafbcc | 63 | #include "cli/cli-utils.h" |
be34f849 | 64 | #include "continuations.h" |
1bfeeb0f JL |
65 | #include "stack.h" |
66 | #include "skip.h" | |
b775012e | 67 | #include "ax-gdb.h" |
e2e4d78b | 68 | #include "dummy-frame.h" |
c906108c | 69 | |
d3ce09f5 SS |
70 | #include "format.h" |
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 | ||
983af33b SDJ |
112 | static void create_sals_from_address_default (char **, |
113 | struct linespec_result *, | |
114 | enum bptype, char *, | |
115 | char **); | |
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 SDJ |
124 | |
125 | static void decode_linespec_default (struct breakpoint *, char **, | |
126 | struct symtabs_and_lines *); | |
127 | ||
a14ed312 | 128 | static void clear_command (char *, int); |
c906108c | 129 | |
a14ed312 | 130 | static void catch_command (char *, int); |
c906108c | 131 | |
a9634178 | 132 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 133 | |
98deb0da | 134 | static void break_command_1 (char *, int, int); |
c906108c | 135 | |
a14ed312 | 136 | static void mention (struct breakpoint *); |
c906108c | 137 | |
348d480f PA |
138 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
139 | enum bptype, | |
c0a91b2b | 140 | const struct breakpoint_ops *); |
3742cc8b YQ |
141 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
142 | const struct symtab_and_line *); | |
143 | ||
4a64f543 MS |
144 | /* This function is used in gdbtk sources and thus can not be made |
145 | static. */ | |
63c252f8 | 146 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 147 | struct symtab_and_line, |
c0a91b2b TT |
148 | enum bptype, |
149 | const struct breakpoint_ops *); | |
c906108c | 150 | |
06edf0c0 PA |
151 | static struct breakpoint * |
152 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
153 | enum bptype type, | |
a1aa2221 LM |
154 | const struct breakpoint_ops *ops, |
155 | int loc_enabled); | |
06edf0c0 | 156 | |
76897487 KB |
157 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
158 | ||
a6d9a66e UW |
159 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
160 | CORE_ADDR bpaddr, | |
88f7da05 | 161 | enum bptype bptype); |
76897487 | 162 | |
6c95b8df PA |
163 | static void describe_other_breakpoints (struct gdbarch *, |
164 | struct program_space *, CORE_ADDR, | |
5af949e3 | 165 | struct obj_section *, int); |
c906108c | 166 | |
85d721b8 PA |
167 | static int watchpoint_locations_match (struct bp_location *loc1, |
168 | struct bp_location *loc2); | |
169 | ||
f1310107 TJB |
170 | static int breakpoint_location_address_match (struct bp_location *bl, |
171 | struct address_space *aspace, | |
172 | CORE_ADDR addr); | |
173 | ||
a14ed312 | 174 | static void breakpoints_info (char *, int); |
c906108c | 175 | |
d77f58be SS |
176 | static void watchpoints_info (char *, int); |
177 | ||
e5a67952 MS |
178 | static int breakpoint_1 (char *, int, |
179 | int (*) (const struct breakpoint *)); | |
c906108c | 180 | |
4efb68b1 | 181 | static int breakpoint_cond_eval (void *); |
c906108c | 182 | |
4efb68b1 | 183 | static void cleanup_executing_breakpoints (void *); |
c906108c | 184 | |
a14ed312 | 185 | static void commands_command (char *, int); |
c906108c | 186 | |
a14ed312 | 187 | static void condition_command (char *, int); |
c906108c | 188 | |
c5aa993b JM |
189 | typedef enum |
190 | { | |
191 | mark_inserted, | |
192 | mark_uninserted | |
193 | } | |
194 | insertion_state_t; | |
c906108c | 195 | |
0bde7532 | 196 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 197 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 198 | |
e514a9d6 | 199 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 200 | |
4efb68b1 | 201 | static int watchpoint_check (void *); |
c906108c | 202 | |
a14ed312 | 203 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 204 | |
a14ed312 | 205 | static int hw_breakpoint_used_count (void); |
c906108c | 206 | |
a1398e0c PA |
207 | static int hw_watchpoint_use_count (struct breakpoint *); |
208 | ||
209 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
210 | enum bptype type, | |
211 | int *other_type_used); | |
c906108c | 212 | |
a14ed312 | 213 | static void hbreak_command (char *, int); |
c906108c | 214 | |
a14ed312 | 215 | static void thbreak_command (char *, int); |
c906108c | 216 | |
816338b5 SS |
217 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
218 | int count); | |
c906108c | 219 | |
a14ed312 | 220 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 221 | |
a14ed312 | 222 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 223 | |
a14ed312 | 224 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 225 | |
a14ed312 | 226 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 227 | |
d03285ec UW |
228 | static void detach_single_step_breakpoints (void); |
229 | ||
ef370185 JB |
230 | static int find_single_step_breakpoint (struct address_space *aspace, |
231 | CORE_ADDR pc); | |
232 | ||
fe3f5fa8 | 233 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
234 | static void incref_bp_location (struct bp_location *loc); |
235 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 236 | |
39d61571 | 237 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 238 | |
44702360 PA |
239 | /* update_global_location_list's modes of operation wrt to whether to |
240 | insert locations now. */ | |
241 | enum ugll_insert_mode | |
242 | { | |
243 | /* Don't insert any breakpoint locations into the inferior, only | |
244 | remove already-inserted locations that no longer should be | |
245 | inserted. Functions that delete a breakpoint or breakpoints | |
246 | should specify this mode, so that deleting a breakpoint doesn't | |
247 | have the side effect of inserting the locations of other | |
248 | breakpoints that are marked not-inserted, but should_be_inserted | |
249 | returns true on them. | |
250 | ||
251 | This behavior is useful is situations close to tear-down -- e.g., | |
252 | after an exec, while the target still has execution, but | |
253 | breakpoint shadows of the previous executable image should *NOT* | |
254 | be restored to the new image; or before detaching, where the | |
255 | target still has execution and wants to delete breakpoints from | |
256 | GDB's lists, and all breakpoints had already been removed from | |
257 | the inferior. */ | |
258 | UGLL_DONT_INSERT, | |
259 | ||
a25a5a45 PA |
260 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
261 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
262 | UGLL_MAY_INSERT, |
263 | ||
a25a5a45 PA |
264 | /* Insert locations now, irrespective of |
265 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
266 | stopped right now, and the user did "continue". We need to | |
267 | insert breakpoints _before_ resuming the target, but | |
268 | UGLL_MAY_INSERT wouldn't insert them, because | |
269 | breakpoints_should_be_inserted_now returns false at that point, | |
270 | as no thread is running yet. */ | |
04086b45 | 271 | UGLL_INSERT |
44702360 PA |
272 | }; |
273 | ||
274 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 275 | |
44702360 | 276 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 277 | |
d77f58be | 278 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
279 | |
280 | static void insert_breakpoint_locations (void); | |
a5606eee | 281 | |
a96d9b2e SDJ |
282 | static int syscall_catchpoint_p (struct breakpoint *b); |
283 | ||
1042e4c0 SS |
284 | static void tracepoints_info (char *, int); |
285 | ||
286 | static void delete_trace_command (char *, int); | |
287 | ||
288 | static void enable_trace_command (char *, int); | |
289 | ||
290 | static void disable_trace_command (char *, int); | |
291 | ||
292 | static void trace_pass_command (char *, int); | |
293 | ||
558a9d82 YQ |
294 | static void set_tracepoint_count (int num); |
295 | ||
9c06b0b4 TJB |
296 | static int is_masked_watchpoint (const struct breakpoint *b); |
297 | ||
b775012e LM |
298 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
299 | ||
983af33b SDJ |
300 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
301 | otherwise. */ | |
302 | ||
303 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 304 | |
2060206e PA |
305 | /* The abstract base class all breakpoint_ops structures inherit |
306 | from. */ | |
ab04a2af | 307 | struct breakpoint_ops base_breakpoint_ops; |
2060206e PA |
308 | |
309 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
310 | that are implemented on top of software or hardware breakpoints | |
311 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
312 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
313 | ||
314 | /* Internal breakpoints class type. */ | |
06edf0c0 | 315 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
316 | |
317 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
318 | static struct breakpoint_ops momentary_breakpoint_ops; |
319 | ||
e2e4d78b JK |
320 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
321 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
322 | ||
2060206e PA |
323 | /* The breakpoint_ops structure to be used in regular user created |
324 | breakpoints. */ | |
325 | struct breakpoint_ops bkpt_breakpoint_ops; | |
326 | ||
55aa24fb SDJ |
327 | /* Breakpoints set on probes. */ |
328 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
329 | ||
e7e0cddf | 330 | /* Dynamic printf class type. */ |
c5867ab6 | 331 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 332 | |
9d497a19 PA |
333 | /* One (or perhaps two) breakpoints used for software single |
334 | stepping. */ | |
335 | ||
336 | static void *single_step_breakpoints[2]; | |
337 | static struct gdbarch *single_step_gdbarch[2]; | |
338 | ||
d3ce09f5 SS |
339 | /* The style in which to perform a dynamic printf. This is a user |
340 | option because different output options have different tradeoffs; | |
341 | if GDB does the printing, there is better error handling if there | |
342 | is a problem with any of the arguments, but using an inferior | |
343 | function lets you have special-purpose printers and sending of | |
344 | output to the same place as compiled-in print functions. */ | |
345 | ||
346 | static const char dprintf_style_gdb[] = "gdb"; | |
347 | static const char dprintf_style_call[] = "call"; | |
348 | static const char dprintf_style_agent[] = "agent"; | |
349 | static const char *const dprintf_style_enums[] = { | |
350 | dprintf_style_gdb, | |
351 | dprintf_style_call, | |
352 | dprintf_style_agent, | |
353 | NULL | |
354 | }; | |
355 | static const char *dprintf_style = dprintf_style_gdb; | |
356 | ||
357 | /* The function to use for dynamic printf if the preferred style is to | |
358 | call into the inferior. The value is simply a string that is | |
359 | copied into the command, so it can be anything that GDB can | |
360 | evaluate to a callable address, not necessarily a function name. */ | |
361 | ||
362 | static char *dprintf_function = ""; | |
363 | ||
364 | /* The channel to use for dynamic printf if the preferred style is to | |
365 | call into the inferior; if a nonempty string, it will be passed to | |
366 | the call as the first argument, with the format string as the | |
367 | second. As with the dprintf function, this can be anything that | |
368 | GDB knows how to evaluate, so in addition to common choices like | |
369 | "stderr", this could be an app-specific expression like | |
370 | "mystreams[curlogger]". */ | |
371 | ||
372 | static char *dprintf_channel = ""; | |
373 | ||
374 | /* True if dprintf commands should continue to operate even if GDB | |
375 | has disconnected. */ | |
376 | static int disconnected_dprintf = 1; | |
377 | ||
5cea2a26 PA |
378 | /* A reference-counted struct command_line. This lets multiple |
379 | breakpoints share a single command list. */ | |
380 | struct counted_command_line | |
381 | { | |
382 | /* The reference count. */ | |
383 | int refc; | |
384 | ||
385 | /* The command list. */ | |
386 | struct command_line *commands; | |
387 | }; | |
388 | ||
389 | struct command_line * | |
390 | breakpoint_commands (struct breakpoint *b) | |
391 | { | |
392 | return b->commands ? b->commands->commands : NULL; | |
393 | } | |
3daf8fe5 | 394 | |
f3b1572e PA |
395 | /* Flag indicating that a command has proceeded the inferior past the |
396 | current breakpoint. */ | |
397 | ||
398 | static int breakpoint_proceeded; | |
399 | ||
956a9fb9 | 400 | const char * |
2cec12e5 AR |
401 | bpdisp_text (enum bpdisp disp) |
402 | { | |
4a64f543 MS |
403 | /* NOTE: the following values are a part of MI protocol and |
404 | represent values of 'disp' field returned when inferior stops at | |
405 | a breakpoint. */ | |
bc043ef3 | 406 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 407 | |
2cec12e5 AR |
408 | return bpdisps[(int) disp]; |
409 | } | |
c906108c | 410 | |
4a64f543 | 411 | /* Prototypes for exported functions. */ |
c906108c | 412 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 413 | if such is available. */ |
c906108c SS |
414 | static int can_use_hw_watchpoints; |
415 | ||
920d2a44 AC |
416 | static void |
417 | show_can_use_hw_watchpoints (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 willingness to use " | |
423 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
424 | value); |
425 | } | |
426 | ||
fa8d40ab JJ |
427 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
428 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 429 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
430 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
431 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
432 | static void |
433 | show_pending_break_support (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 | _("Debugger's behavior regarding " | |
439 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
440 | value); |
441 | } | |
fa8d40ab | 442 | |
765dc015 | 443 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 444 | set with "break" but falling in read-only memory. |
765dc015 VP |
445 | If 0, gdb will warn about such breakpoints, but won't automatically |
446 | use hardware breakpoints. */ | |
447 | static int automatic_hardware_breakpoints; | |
448 | static void | |
449 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
450 | struct cmd_list_element *c, | |
451 | const char *value) | |
452 | { | |
3e43a32a MS |
453 | fprintf_filtered (file, |
454 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
455 | value); |
456 | } | |
457 | ||
a25a5a45 PA |
458 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
459 | stopped, and immediately inserts any new breakpoints as soon as | |
460 | they're created. If off (default), GDB keeps breakpoints off of | |
461 | the target as long as possible. That is, it delays inserting | |
462 | breakpoints until the next resume, and removes them again when the | |
463 | target fully stops. This is a bit safer in case GDB crashes while | |
464 | processing user input. */ | |
465 | static int always_inserted_mode = 0; | |
72d0e2c5 | 466 | |
33e5cbd6 | 467 | static void |
74960c60 | 468 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 469 | struct cmd_list_element *c, const char *value) |
74960c60 | 470 | { |
a25a5a45 PA |
471 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
472 | value); | |
74960c60 VP |
473 | } |
474 | ||
b57bacec PA |
475 | /* See breakpoint.h. */ |
476 | ||
33e5cbd6 | 477 | int |
a25a5a45 | 478 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 479 | { |
a25a5a45 PA |
480 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
481 | { | |
482 | /* If breakpoints are global, they should be inserted even if no | |
483 | thread under gdb's control is running, or even if there are | |
484 | no threads under GDB's control yet. */ | |
485 | return 1; | |
486 | } | |
487 | else if (target_has_execution) | |
488 | { | |
a25a5a45 PA |
489 | if (always_inserted_mode) |
490 | { | |
491 | /* The user wants breakpoints inserted even if all threads | |
492 | are stopped. */ | |
493 | return 1; | |
494 | } | |
495 | ||
b57bacec PA |
496 | if (threads_are_executing ()) |
497 | return 1; | |
a25a5a45 PA |
498 | } |
499 | return 0; | |
33e5cbd6 | 500 | } |
765dc015 | 501 | |
b775012e LM |
502 | static const char condition_evaluation_both[] = "host or target"; |
503 | ||
504 | /* Modes for breakpoint condition evaluation. */ | |
505 | static const char condition_evaluation_auto[] = "auto"; | |
506 | static const char condition_evaluation_host[] = "host"; | |
507 | static const char condition_evaluation_target[] = "target"; | |
508 | static const char *const condition_evaluation_enums[] = { | |
509 | condition_evaluation_auto, | |
510 | condition_evaluation_host, | |
511 | condition_evaluation_target, | |
512 | NULL | |
513 | }; | |
514 | ||
515 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
516 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
517 | ||
518 | /* Global that we use to display information to the user (gets its value from | |
519 | condition_evaluation_mode_1. */ | |
520 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
521 | ||
522 | /* Translate a condition evaluation mode MODE into either "host" | |
523 | or "target". This is used mostly to translate from "auto" to the | |
524 | real setting that is being used. It returns the translated | |
525 | evaluation mode. */ | |
526 | ||
527 | static const char * | |
528 | translate_condition_evaluation_mode (const char *mode) | |
529 | { | |
530 | if (mode == condition_evaluation_auto) | |
531 | { | |
532 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
533 | return condition_evaluation_target; | |
534 | else | |
535 | return condition_evaluation_host; | |
536 | } | |
537 | else | |
538 | return mode; | |
539 | } | |
540 | ||
541 | /* Discovers what condition_evaluation_auto translates to. */ | |
542 | ||
543 | static const char * | |
544 | breakpoint_condition_evaluation_mode (void) | |
545 | { | |
546 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
547 | } | |
548 | ||
549 | /* Return true if GDB should evaluate breakpoint conditions or false | |
550 | otherwise. */ | |
551 | ||
552 | static int | |
553 | gdb_evaluates_breakpoint_condition_p (void) | |
554 | { | |
555 | const char *mode = breakpoint_condition_evaluation_mode (); | |
556 | ||
557 | return (mode == condition_evaluation_host); | |
558 | } | |
559 | ||
a14ed312 | 560 | void _initialize_breakpoint (void); |
c906108c | 561 | |
c906108c SS |
562 | /* Are we executing breakpoint commands? */ |
563 | static int executing_breakpoint_commands; | |
564 | ||
c02f5703 MS |
565 | /* Are overlay event breakpoints enabled? */ |
566 | static int overlay_events_enabled; | |
567 | ||
e09342b5 TJB |
568 | /* See description in breakpoint.h. */ |
569 | int target_exact_watchpoints = 0; | |
570 | ||
c906108c | 571 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 572 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 573 | current breakpoint. */ |
c906108c | 574 | |
5c44784c | 575 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 576 | |
5c44784c JM |
577 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
578 | for (B = breakpoint_chain; \ | |
579 | B ? (TMP=B->next, 1): 0; \ | |
580 | B = TMP) | |
c906108c | 581 | |
4a64f543 MS |
582 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
583 | not provided so update_global_location_list must not be called | |
584 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 585 | |
876fa593 JK |
586 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
587 | for (BP_TMP = bp_location; \ | |
588 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
589 | BP_TMP++) | |
7cc221ef | 590 | |
b775012e LM |
591 | /* Iterates through locations with address ADDRESS for the currently selected |
592 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
593 | to where the loop should start from. | |
594 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
595 | appropriate location to start with. */ | |
596 | ||
597 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
598 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
599 | BP_LOCP_TMP = BP_LOCP_START; \ | |
600 | BP_LOCP_START \ | |
601 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
602 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
603 | BP_LOCP_TMP++) | |
604 | ||
1042e4c0 SS |
605 | /* Iterator for tracepoints only. */ |
606 | ||
607 | #define ALL_TRACEPOINTS(B) \ | |
608 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 609 | if (is_tracepoint (B)) |
1042e4c0 | 610 | |
7cc221ef | 611 | /* Chains of all breakpoints defined. */ |
c906108c SS |
612 | |
613 | struct breakpoint *breakpoint_chain; | |
614 | ||
876fa593 JK |
615 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
616 | ||
617 | static struct bp_location **bp_location; | |
618 | ||
619 | /* Number of elements of BP_LOCATION. */ | |
620 | ||
621 | static unsigned bp_location_count; | |
622 | ||
4a64f543 MS |
623 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
624 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
625 | result from bp_location_has_shadow. You can use it for roughly | |
626 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
627 | an address you need to read. */ | |
876fa593 JK |
628 | |
629 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
630 | ||
4a64f543 MS |
631 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
632 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
633 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
634 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
635 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
636 | |
637 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 638 | |
4a64f543 MS |
639 | /* The locations that no longer correspond to any breakpoint, unlinked |
640 | from bp_location array, but for which a hit may still be reported | |
641 | by a target. */ | |
20874c92 VP |
642 | VEC(bp_location_p) *moribund_locations = NULL; |
643 | ||
c906108c SS |
644 | /* Number of last breakpoint made. */ |
645 | ||
95a42b64 TT |
646 | static int breakpoint_count; |
647 | ||
86b17b60 PA |
648 | /* The value of `breakpoint_count' before the last command that |
649 | created breakpoints. If the last (break-like) command created more | |
650 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
651 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
652 | static int prev_breakpoint_count; | |
c906108c | 653 | |
1042e4c0 SS |
654 | /* Number of last tracepoint made. */ |
655 | ||
95a42b64 | 656 | static int tracepoint_count; |
1042e4c0 | 657 | |
6149aea9 PA |
658 | static struct cmd_list_element *breakpoint_set_cmdlist; |
659 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 660 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 661 | |
468d015d JJ |
662 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
663 | static int | |
664 | breakpoint_enabled (struct breakpoint *b) | |
665 | { | |
0d381245 | 666 | return (b->enable_state == bp_enabled); |
468d015d JJ |
667 | } |
668 | ||
c906108c SS |
669 | /* Set breakpoint count to NUM. */ |
670 | ||
95a42b64 | 671 | static void |
fba45db2 | 672 | set_breakpoint_count (int num) |
c906108c | 673 | { |
86b17b60 | 674 | prev_breakpoint_count = breakpoint_count; |
c906108c | 675 | breakpoint_count = num; |
4fa62494 | 676 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
677 | } |
678 | ||
86b17b60 PA |
679 | /* Used by `start_rbreak_breakpoints' below, to record the current |
680 | breakpoint count before "rbreak" creates any breakpoint. */ | |
681 | static int rbreak_start_breakpoint_count; | |
682 | ||
95a42b64 TT |
683 | /* Called at the start an "rbreak" command to record the first |
684 | breakpoint made. */ | |
86b17b60 | 685 | |
95a42b64 TT |
686 | void |
687 | start_rbreak_breakpoints (void) | |
688 | { | |
86b17b60 | 689 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
690 | } |
691 | ||
692 | /* Called at the end of an "rbreak" command to record the last | |
693 | breakpoint made. */ | |
86b17b60 | 694 | |
95a42b64 TT |
695 | void |
696 | end_rbreak_breakpoints (void) | |
697 | { | |
86b17b60 | 698 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
699 | } |
700 | ||
4a64f543 | 701 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
702 | |
703 | void | |
fba45db2 | 704 | clear_breakpoint_hit_counts (void) |
c906108c SS |
705 | { |
706 | struct breakpoint *b; | |
707 | ||
708 | ALL_BREAKPOINTS (b) | |
709 | b->hit_count = 0; | |
710 | } | |
711 | ||
9add0f1b TT |
712 | /* Allocate a new counted_command_line with reference count of 1. |
713 | The new structure owns COMMANDS. */ | |
714 | ||
715 | static struct counted_command_line * | |
716 | alloc_counted_command_line (struct command_line *commands) | |
717 | { | |
718 | struct counted_command_line *result | |
719 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 720 | |
9add0f1b TT |
721 | result->refc = 1; |
722 | result->commands = commands; | |
723 | return result; | |
724 | } | |
725 | ||
726 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
727 | ||
728 | static void | |
729 | incref_counted_command_line (struct counted_command_line *cmd) | |
730 | { | |
731 | if (cmd) | |
732 | ++cmd->refc; | |
733 | } | |
734 | ||
735 | /* Decrement reference count. If the reference count reaches 0, | |
736 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
737 | nothing if *CMDP is NULL. */ | |
738 | ||
739 | static void | |
740 | decref_counted_command_line (struct counted_command_line **cmdp) | |
741 | { | |
742 | if (*cmdp) | |
743 | { | |
744 | if (--(*cmdp)->refc == 0) | |
745 | { | |
746 | free_command_lines (&(*cmdp)->commands); | |
747 | xfree (*cmdp); | |
748 | } | |
749 | *cmdp = NULL; | |
750 | } | |
751 | } | |
752 | ||
753 | /* A cleanup function that calls decref_counted_command_line. */ | |
754 | ||
755 | static void | |
756 | do_cleanup_counted_command_line (void *arg) | |
757 | { | |
758 | decref_counted_command_line (arg); | |
759 | } | |
760 | ||
761 | /* Create a cleanup that calls decref_counted_command_line on the | |
762 | argument. */ | |
763 | ||
764 | static struct cleanup * | |
765 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
766 | { | |
767 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
768 | } | |
769 | ||
c906108c | 770 | \f |
48cb2d85 VP |
771 | /* Return the breakpoint with the specified number, or NULL |
772 | if the number does not refer to an existing breakpoint. */ | |
773 | ||
774 | struct breakpoint * | |
775 | get_breakpoint (int num) | |
776 | { | |
777 | struct breakpoint *b; | |
778 | ||
779 | ALL_BREAKPOINTS (b) | |
780 | if (b->number == num) | |
781 | return b; | |
782 | ||
783 | return NULL; | |
784 | } | |
5c44784c | 785 | |
c906108c | 786 | \f |
adc36818 | 787 | |
b775012e LM |
788 | /* Mark locations as "conditions have changed" in case the target supports |
789 | evaluating conditions on its side. */ | |
790 | ||
791 | static void | |
792 | mark_breakpoint_modified (struct breakpoint *b) | |
793 | { | |
794 | struct bp_location *loc; | |
795 | ||
796 | /* This is only meaningful if the target is | |
797 | evaluating conditions and if the user has | |
798 | opted for condition evaluation on the target's | |
799 | side. */ | |
800 | if (gdb_evaluates_breakpoint_condition_p () | |
801 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
802 | return; | |
803 | ||
804 | if (!is_breakpoint (b)) | |
805 | return; | |
806 | ||
807 | for (loc = b->loc; loc; loc = loc->next) | |
808 | loc->condition_changed = condition_modified; | |
809 | } | |
810 | ||
811 | /* Mark location as "conditions have changed" in case the target supports | |
812 | evaluating conditions on its side. */ | |
813 | ||
814 | static void | |
815 | mark_breakpoint_location_modified (struct bp_location *loc) | |
816 | { | |
817 | /* This is only meaningful if the target is | |
818 | evaluating conditions and if the user has | |
819 | opted for condition evaluation on the target's | |
820 | side. */ | |
821 | if (gdb_evaluates_breakpoint_condition_p () | |
822 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
823 | ||
824 | return; | |
825 | ||
826 | if (!is_breakpoint (loc->owner)) | |
827 | return; | |
828 | ||
829 | loc->condition_changed = condition_modified; | |
830 | } | |
831 | ||
832 | /* Sets the condition-evaluation mode using the static global | |
833 | condition_evaluation_mode. */ | |
834 | ||
835 | static void | |
836 | set_condition_evaluation_mode (char *args, int from_tty, | |
837 | struct cmd_list_element *c) | |
838 | { | |
b775012e LM |
839 | const char *old_mode, *new_mode; |
840 | ||
841 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
842 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
843 | { | |
844 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
845 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
846 | "Using host evaluation mode instead.")); | |
847 | return; | |
848 | } | |
849 | ||
850 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
851 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
852 | ||
abf1152a JK |
853 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
854 | settings was "auto". */ | |
855 | condition_evaluation_mode = condition_evaluation_mode_1; | |
856 | ||
b775012e LM |
857 | /* Only update the mode if the user picked a different one. */ |
858 | if (new_mode != old_mode) | |
859 | { | |
860 | struct bp_location *loc, **loc_tmp; | |
861 | /* If the user switched to a different evaluation mode, we | |
862 | need to synch the changes with the target as follows: | |
863 | ||
864 | "host" -> "target": Send all (valid) conditions to the target. | |
865 | "target" -> "host": Remove all the conditions from the target. | |
866 | */ | |
867 | ||
b775012e LM |
868 | if (new_mode == condition_evaluation_target) |
869 | { | |
870 | /* Mark everything modified and synch conditions with the | |
871 | target. */ | |
872 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
873 | mark_breakpoint_location_modified (loc); | |
874 | } | |
875 | else | |
876 | { | |
877 | /* Manually mark non-duplicate locations to synch conditions | |
878 | with the target. We do this to remove all the conditions the | |
879 | target knows about. */ | |
880 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
881 | if (is_breakpoint (loc->owner) && loc->inserted) | |
882 | loc->needs_update = 1; | |
883 | } | |
884 | ||
885 | /* Do the update. */ | |
44702360 | 886 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
887 | } |
888 | ||
889 | return; | |
890 | } | |
891 | ||
892 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
893 | what "auto" is translating to. */ | |
894 | ||
895 | static void | |
896 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
897 | struct cmd_list_element *c, const char *value) | |
898 | { | |
899 | if (condition_evaluation_mode == condition_evaluation_auto) | |
900 | fprintf_filtered (file, | |
901 | _("Breakpoint condition evaluation " | |
902 | "mode is %s (currently %s).\n"), | |
903 | value, | |
904 | breakpoint_condition_evaluation_mode ()); | |
905 | else | |
906 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
907 | value); | |
908 | } | |
909 | ||
910 | /* A comparison function for bp_location AP and BP that is used by | |
911 | bsearch. This comparison function only cares about addresses, unlike | |
912 | the more general bp_location_compare function. */ | |
913 | ||
914 | static int | |
915 | bp_location_compare_addrs (const void *ap, const void *bp) | |
916 | { | |
917 | struct bp_location *a = *(void **) ap; | |
918 | struct bp_location *b = *(void **) bp; | |
919 | ||
920 | if (a->address == b->address) | |
921 | return 0; | |
922 | else | |
923 | return ((a->address > b->address) - (a->address < b->address)); | |
924 | } | |
925 | ||
926 | /* Helper function to skip all bp_locations with addresses | |
927 | less than ADDRESS. It returns the first bp_location that | |
928 | is greater than or equal to ADDRESS. If none is found, just | |
929 | return NULL. */ | |
930 | ||
931 | static struct bp_location ** | |
932 | get_first_locp_gte_addr (CORE_ADDR address) | |
933 | { | |
934 | struct bp_location dummy_loc; | |
935 | struct bp_location *dummy_locp = &dummy_loc; | |
936 | struct bp_location **locp_found = NULL; | |
937 | ||
938 | /* Initialize the dummy location's address field. */ | |
939 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
940 | dummy_loc.address = address; | |
941 | ||
942 | /* Find a close match to the first location at ADDRESS. */ | |
943 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, | |
944 | sizeof (struct bp_location **), | |
945 | bp_location_compare_addrs); | |
946 | ||
947 | /* Nothing was found, nothing left to do. */ | |
948 | if (locp_found == NULL) | |
949 | return NULL; | |
950 | ||
951 | /* We may have found a location that is at ADDRESS but is not the first in the | |
952 | location's list. Go backwards (if possible) and locate the first one. */ | |
953 | while ((locp_found - 1) >= bp_location | |
954 | && (*(locp_found - 1))->address == address) | |
955 | locp_found--; | |
956 | ||
957 | return locp_found; | |
958 | } | |
959 | ||
adc36818 PM |
960 | void |
961 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
962 | int from_tty) | |
963 | { | |
3a5c3e22 PA |
964 | xfree (b->cond_string); |
965 | b->cond_string = NULL; | |
adc36818 | 966 | |
3a5c3e22 | 967 | if (is_watchpoint (b)) |
adc36818 | 968 | { |
3a5c3e22 PA |
969 | struct watchpoint *w = (struct watchpoint *) b; |
970 | ||
971 | xfree (w->cond_exp); | |
972 | w->cond_exp = NULL; | |
973 | } | |
974 | else | |
975 | { | |
976 | struct bp_location *loc; | |
977 | ||
978 | for (loc = b->loc; loc; loc = loc->next) | |
979 | { | |
980 | xfree (loc->cond); | |
981 | loc->cond = NULL; | |
b775012e LM |
982 | |
983 | /* No need to free the condition agent expression | |
984 | bytecode (if we have one). We will handle this | |
985 | when we go through update_global_location_list. */ | |
3a5c3e22 | 986 | } |
adc36818 | 987 | } |
adc36818 PM |
988 | |
989 | if (*exp == 0) | |
990 | { | |
991 | if (from_tty) | |
992 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
993 | } | |
994 | else | |
995 | { | |
bbc13ae3 | 996 | const char *arg = exp; |
cc59ec59 | 997 | |
adc36818 PM |
998 | /* I don't know if it matters whether this is the string the user |
999 | typed in or the decompiled expression. */ | |
1000 | b->cond_string = xstrdup (arg); | |
1001 | b->condition_not_parsed = 0; | |
1002 | ||
1003 | if (is_watchpoint (b)) | |
1004 | { | |
3a5c3e22 PA |
1005 | struct watchpoint *w = (struct watchpoint *) b; |
1006 | ||
adc36818 PM |
1007 | innermost_block = NULL; |
1008 | arg = exp; | |
1bb9788d | 1009 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1010 | if (*arg) |
1011 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1012 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1013 | } |
1014 | else | |
1015 | { | |
3a5c3e22 PA |
1016 | struct bp_location *loc; |
1017 | ||
adc36818 PM |
1018 | for (loc = b->loc; loc; loc = loc->next) |
1019 | { | |
1020 | arg = exp; | |
1021 | loc->cond = | |
1bb9788d TT |
1022 | parse_exp_1 (&arg, loc->address, |
1023 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1024 | if (*arg) |
1025 | error (_("Junk at end of expression")); | |
1026 | } | |
1027 | } | |
1028 | } | |
b775012e LM |
1029 | mark_breakpoint_modified (b); |
1030 | ||
8d3788bd | 1031 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1032 | } |
1033 | ||
d55637df TT |
1034 | /* Completion for the "condition" command. */ |
1035 | ||
1036 | static VEC (char_ptr) * | |
6f937416 PA |
1037 | condition_completer (struct cmd_list_element *cmd, |
1038 | const char *text, const char *word) | |
d55637df | 1039 | { |
6f937416 | 1040 | const char *space; |
d55637df | 1041 | |
6f937416 PA |
1042 | text = skip_spaces_const (text); |
1043 | space = skip_to_space_const (text); | |
d55637df TT |
1044 | if (*space == '\0') |
1045 | { | |
1046 | int len; | |
1047 | struct breakpoint *b; | |
1048 | VEC (char_ptr) *result = NULL; | |
1049 | ||
1050 | if (text[0] == '$') | |
1051 | { | |
1052 | /* We don't support completion of history indices. */ | |
1053 | if (isdigit (text[1])) | |
1054 | return NULL; | |
1055 | return complete_internalvar (&text[1]); | |
1056 | } | |
1057 | ||
1058 | /* We're completing the breakpoint number. */ | |
1059 | len = strlen (text); | |
1060 | ||
1061 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1062 | { |
1063 | char number[50]; | |
1064 | ||
1065 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1066 | ||
1067 | if (strncmp (number, text, len) == 0) | |
1068 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1069 | } | |
d55637df TT |
1070 | |
1071 | return result; | |
1072 | } | |
1073 | ||
1074 | /* We're completing the expression part. */ | |
6f937416 | 1075 | text = skip_spaces_const (space); |
d55637df TT |
1076 | return expression_completer (cmd, text, word); |
1077 | } | |
1078 | ||
c906108c SS |
1079 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1080 | ||
1081 | static void | |
fba45db2 | 1082 | condition_command (char *arg, int from_tty) |
c906108c | 1083 | { |
52f0bd74 | 1084 | struct breakpoint *b; |
c906108c | 1085 | char *p; |
52f0bd74 | 1086 | int bnum; |
c906108c SS |
1087 | |
1088 | if (arg == 0) | |
e2e0b3e5 | 1089 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1090 | |
1091 | p = arg; | |
1092 | bnum = get_number (&p); | |
5c44784c | 1093 | if (bnum == 0) |
8a3fe4f8 | 1094 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1095 | |
1096 | ALL_BREAKPOINTS (b) | |
1097 | if (b->number == bnum) | |
2f069f6f | 1098 | { |
6dddc817 DE |
1099 | /* Check if this breakpoint has a "stop" method implemented in an |
1100 | extension language. This method and conditions entered into GDB | |
1101 | from the CLI are mutually exclusive. */ | |
1102 | const struct extension_language_defn *extlang | |
1103 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1104 | ||
1105 | if (extlang != NULL) | |
1106 | { | |
1107 | error (_("Only one stop condition allowed. There is currently" | |
1108 | " a %s stop condition defined for this breakpoint."), | |
1109 | ext_lang_capitalized_name (extlang)); | |
1110 | } | |
2566ad2d | 1111 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1112 | |
1113 | if (is_breakpoint (b)) | |
44702360 | 1114 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1115 | |
2f069f6f JB |
1116 | return; |
1117 | } | |
c906108c | 1118 | |
8a3fe4f8 | 1119 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1120 | } |
1121 | ||
a7bdde9e VP |
1122 | /* Check that COMMAND do not contain commands that are suitable |
1123 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1124 | Throw if any such commands is found. */ |
1125 | ||
a7bdde9e VP |
1126 | static void |
1127 | check_no_tracepoint_commands (struct command_line *commands) | |
1128 | { | |
1129 | struct command_line *c; | |
cc59ec59 | 1130 | |
a7bdde9e VP |
1131 | for (c = commands; c; c = c->next) |
1132 | { | |
1133 | int i; | |
1134 | ||
1135 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1136 | error (_("The 'while-stepping' command can " |
1137 | "only be used for tracepoints")); | |
a7bdde9e VP |
1138 | |
1139 | for (i = 0; i < c->body_count; ++i) | |
1140 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1141 | ||
1142 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1143 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1144 | command directly. */ |
1145 | if (strstr (c->line, "collect ") == c->line) | |
1146 | error (_("The 'collect' command can only be used for tracepoints")); | |
1147 | ||
51661e93 VP |
1148 | if (strstr (c->line, "teval ") == c->line) |
1149 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1150 | } |
1151 | } | |
1152 | ||
d77f58be SS |
1153 | /* Encapsulate tests for different types of tracepoints. */ |
1154 | ||
d9b3f62e PA |
1155 | static int |
1156 | is_tracepoint_type (enum bptype type) | |
1157 | { | |
1158 | return (type == bp_tracepoint | |
1159 | || type == bp_fast_tracepoint | |
1160 | || type == bp_static_tracepoint); | |
1161 | } | |
1162 | ||
a7bdde9e | 1163 | int |
d77f58be | 1164 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1165 | { |
d9b3f62e | 1166 | return is_tracepoint_type (b->type); |
a7bdde9e | 1167 | } |
d9b3f62e | 1168 | |
e5dd4106 | 1169 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1170 | breakpoint. This function will throw an exception if a problem is |
1171 | found. */ | |
48cb2d85 | 1172 | |
95a42b64 TT |
1173 | static void |
1174 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1175 | struct command_line *commands) | |
48cb2d85 | 1176 | { |
d77f58be | 1177 | if (is_tracepoint (b)) |
a7bdde9e | 1178 | { |
c9a6ce02 | 1179 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1180 | struct command_line *c; |
1181 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1182 | |
1183 | /* Reset the while-stepping step count. The previous commands | |
1184 | might have included a while-stepping action, while the new | |
1185 | ones might not. */ | |
1186 | t->step_count = 0; | |
1187 | ||
1188 | /* We need to verify that each top-level element of commands is | |
1189 | valid for tracepoints, that there's at most one | |
1190 | while-stepping element, and that the while-stepping's body | |
1191 | has valid tracing commands excluding nested while-stepping. | |
1192 | We also need to validate the tracepoint action line in the | |
1193 | context of the tracepoint --- validate_actionline actually | |
1194 | has side effects, like setting the tracepoint's | |
1195 | while-stepping STEP_COUNT, in addition to checking if the | |
1196 | collect/teval actions parse and make sense in the | |
1197 | tracepoint's context. */ | |
a7bdde9e VP |
1198 | for (c = commands; c; c = c->next) |
1199 | { | |
a7bdde9e VP |
1200 | if (c->control_type == while_stepping_control) |
1201 | { | |
1202 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1203 | error (_("The 'while-stepping' command " |
1204 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1205 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1206 | error (_("The 'while-stepping' command " |
1207 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1208 | |
1209 | if (while_stepping) | |
3e43a32a MS |
1210 | error (_("The 'while-stepping' command " |
1211 | "can be used only once")); | |
a7bdde9e VP |
1212 | else |
1213 | while_stepping = c; | |
1214 | } | |
c9a6ce02 PA |
1215 | |
1216 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1217 | } |
1218 | if (while_stepping) | |
1219 | { | |
1220 | struct command_line *c2; | |
1221 | ||
1222 | gdb_assert (while_stepping->body_count == 1); | |
1223 | c2 = while_stepping->body_list[0]; | |
1224 | for (; c2; c2 = c2->next) | |
1225 | { | |
a7bdde9e VP |
1226 | if (c2->control_type == while_stepping_control) |
1227 | error (_("The 'while-stepping' command cannot be nested")); | |
1228 | } | |
1229 | } | |
1230 | } | |
1231 | else | |
1232 | { | |
1233 | check_no_tracepoint_commands (commands); | |
1234 | } | |
95a42b64 TT |
1235 | } |
1236 | ||
0fb4aa4b PA |
1237 | /* Return a vector of all the static tracepoints set at ADDR. The |
1238 | caller is responsible for releasing the vector. */ | |
1239 | ||
1240 | VEC(breakpoint_p) * | |
1241 | static_tracepoints_here (CORE_ADDR addr) | |
1242 | { | |
1243 | struct breakpoint *b; | |
1244 | VEC(breakpoint_p) *found = 0; | |
1245 | struct bp_location *loc; | |
1246 | ||
1247 | ALL_BREAKPOINTS (b) | |
1248 | if (b->type == bp_static_tracepoint) | |
1249 | { | |
1250 | for (loc = b->loc; loc; loc = loc->next) | |
1251 | if (loc->address == addr) | |
1252 | VEC_safe_push(breakpoint_p, found, b); | |
1253 | } | |
1254 | ||
1255 | return found; | |
1256 | } | |
1257 | ||
95a42b64 | 1258 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1259 | validate that only allowed commands are included. */ |
95a42b64 TT |
1260 | |
1261 | void | |
4a64f543 MS |
1262 | breakpoint_set_commands (struct breakpoint *b, |
1263 | struct command_line *commands) | |
95a42b64 TT |
1264 | { |
1265 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1266 | |
9add0f1b TT |
1267 | decref_counted_command_line (&b->commands); |
1268 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1269 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1270 | } |
1271 | ||
45a43567 TT |
1272 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1273 | is not the same as the "silent" that may appear in the breakpoint's | |
1274 | commands. */ | |
1275 | ||
1276 | void | |
1277 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1278 | { | |
1279 | int old_silent = b->silent; | |
1280 | ||
1281 | b->silent = silent; | |
1282 | if (old_silent != silent) | |
8d3788bd | 1283 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1284 | } |
1285 | ||
1286 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1287 | breakpoint work for any thread. */ | |
1288 | ||
1289 | void | |
1290 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1291 | { | |
1292 | int old_thread = b->thread; | |
1293 | ||
1294 | b->thread = thread; | |
1295 | if (old_thread != thread) | |
8d3788bd | 1296 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1297 | } |
1298 | ||
1299 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1300 | breakpoint work for any task. */ | |
1301 | ||
1302 | void | |
1303 | breakpoint_set_task (struct breakpoint *b, int task) | |
1304 | { | |
1305 | int old_task = b->task; | |
1306 | ||
1307 | b->task = task; | |
1308 | if (old_task != task) | |
8d3788bd | 1309 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1310 | } |
1311 | ||
95a42b64 TT |
1312 | void |
1313 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1314 | { |
1315 | struct breakpoint *b = closure; | |
cc59ec59 | 1316 | |
6f937416 | 1317 | validate_actionline (line, b); |
a7bdde9e VP |
1318 | } |
1319 | ||
95a42b64 TT |
1320 | /* A structure used to pass information through |
1321 | map_breakpoint_numbers. */ | |
1322 | ||
1323 | struct commands_info | |
1324 | { | |
1325 | /* True if the command was typed at a tty. */ | |
1326 | int from_tty; | |
86b17b60 PA |
1327 | |
1328 | /* The breakpoint range spec. */ | |
1329 | char *arg; | |
1330 | ||
95a42b64 TT |
1331 | /* Non-NULL if the body of the commands are being read from this |
1332 | already-parsed command. */ | |
1333 | struct command_line *control; | |
86b17b60 | 1334 | |
95a42b64 TT |
1335 | /* The command lines read from the user, or NULL if they have not |
1336 | yet been read. */ | |
1337 | struct counted_command_line *cmd; | |
1338 | }; | |
1339 | ||
1340 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1341 | commands_command. */ | |
1342 | ||
c906108c | 1343 | static void |
95a42b64 | 1344 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1345 | { |
95a42b64 | 1346 | struct commands_info *info = data; |
c906108c | 1347 | |
95a42b64 TT |
1348 | if (info->cmd == NULL) |
1349 | { | |
1350 | struct command_line *l; | |
5c44784c | 1351 | |
95a42b64 TT |
1352 | if (info->control != NULL) |
1353 | l = copy_command_lines (info->control->body_list[0]); | |
1354 | else | |
86b17b60 PA |
1355 | { |
1356 | struct cleanup *old_chain; | |
1357 | char *str; | |
c5aa993b | 1358 | |
3e43a32a MS |
1359 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1360 | "%s, one per line."), | |
86b17b60 PA |
1361 | info->arg); |
1362 | ||
1363 | old_chain = make_cleanup (xfree, str); | |
1364 | ||
1365 | l = read_command_lines (str, | |
1366 | info->from_tty, 1, | |
d77f58be | 1367 | (is_tracepoint (b) |
86b17b60 PA |
1368 | ? check_tracepoint_command : 0), |
1369 | b); | |
1370 | ||
1371 | do_cleanups (old_chain); | |
1372 | } | |
a7bdde9e | 1373 | |
95a42b64 TT |
1374 | info->cmd = alloc_counted_command_line (l); |
1375 | } | |
1376 | ||
1377 | /* If a breakpoint was on the list more than once, we don't need to | |
1378 | do anything. */ | |
1379 | if (b->commands != info->cmd) | |
1380 | { | |
1381 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1382 | incref_counted_command_line (info->cmd); | |
1383 | decref_counted_command_line (&b->commands); | |
1384 | b->commands = info->cmd; | |
8d3788bd | 1385 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1386 | } |
95a42b64 TT |
1387 | } |
1388 | ||
1389 | static void | |
4a64f543 MS |
1390 | commands_command_1 (char *arg, int from_tty, |
1391 | struct command_line *control) | |
95a42b64 TT |
1392 | { |
1393 | struct cleanup *cleanups; | |
1394 | struct commands_info info; | |
1395 | ||
1396 | info.from_tty = from_tty; | |
1397 | info.control = control; | |
1398 | info.cmd = NULL; | |
1399 | /* If we read command lines from the user, then `info' will hold an | |
1400 | extra reference to the commands that we must clean up. */ | |
1401 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1402 | ||
1403 | if (arg == NULL || !*arg) | |
1404 | { | |
86b17b60 | 1405 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1406 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1407 | breakpoint_count); | |
95a42b64 TT |
1408 | else if (breakpoint_count > 0) |
1409 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1410 | else |
1411 | { | |
1412 | /* So that we don't try to free the incoming non-NULL | |
1413 | argument in the cleanup below. Mapping breakpoint | |
1414 | numbers will fail in this case. */ | |
1415 | arg = NULL; | |
1416 | } | |
95a42b64 | 1417 | } |
9766ced4 SS |
1418 | else |
1419 | /* The command loop has some static state, so we need to preserve | |
1420 | our argument. */ | |
1421 | arg = xstrdup (arg); | |
86b17b60 PA |
1422 | |
1423 | if (arg != NULL) | |
1424 | make_cleanup (xfree, arg); | |
1425 | ||
1426 | info.arg = arg; | |
95a42b64 TT |
1427 | |
1428 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1429 | ||
1430 | if (info.cmd == NULL) | |
1431 | error (_("No breakpoints specified.")); | |
1432 | ||
1433 | do_cleanups (cleanups); | |
1434 | } | |
1435 | ||
1436 | static void | |
1437 | commands_command (char *arg, int from_tty) | |
1438 | { | |
1439 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1440 | } |
40c03ae8 EZ |
1441 | |
1442 | /* Like commands_command, but instead of reading the commands from | |
1443 | input stream, takes them from an already parsed command structure. | |
1444 | ||
1445 | This is used by cli-script.c to DTRT with breakpoint commands | |
1446 | that are part of if and while bodies. */ | |
1447 | enum command_control_type | |
1448 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1449 | { | |
95a42b64 TT |
1450 | commands_command_1 (arg, 0, cmd); |
1451 | return simple_control; | |
40c03ae8 | 1452 | } |
876fa593 JK |
1453 | |
1454 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1455 | ||
1456 | static int | |
1457 | bp_location_has_shadow (struct bp_location *bl) | |
1458 | { | |
1459 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1460 | return 0; | |
1461 | if (!bl->inserted) | |
1462 | return 0; | |
1463 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1464 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1465 | return 0; |
1466 | return 1; | |
1467 | } | |
1468 | ||
9d497a19 PA |
1469 | /* Update BUF, which is LEN bytes read from the target address |
1470 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1471 | contents. | |
1472 | ||
1473 | If READBUF is not NULL, this buffer must not overlap with the of | |
1474 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1475 | failed assertion internal error will be raised. */ | |
1476 | ||
1477 | static void | |
1478 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1479 | const gdb_byte *writebuf_org, | |
1480 | ULONGEST memaddr, LONGEST len, | |
1481 | struct bp_target_info *target_info, | |
1482 | struct gdbarch *gdbarch) | |
1483 | { | |
1484 | /* Now do full processing of the found relevant range of elements. */ | |
1485 | CORE_ADDR bp_addr = 0; | |
1486 | int bp_size = 0; | |
1487 | int bptoffset = 0; | |
1488 | ||
1489 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1490 | current_program_space->aspace, 0)) | |
1491 | { | |
1492 | /* The breakpoint is inserted in a different address space. */ | |
1493 | return; | |
1494 | } | |
1495 | ||
1496 | /* Addresses and length of the part of the breakpoint that | |
1497 | we need to copy. */ | |
1498 | bp_addr = target_info->placed_address; | |
1499 | bp_size = target_info->shadow_len; | |
1500 | ||
1501 | if (bp_addr + bp_size <= memaddr) | |
1502 | { | |
1503 | /* The breakpoint is entirely before the chunk of memory we are | |
1504 | reading. */ | |
1505 | return; | |
1506 | } | |
1507 | ||
1508 | if (bp_addr >= memaddr + len) | |
1509 | { | |
1510 | /* The breakpoint is entirely after the chunk of memory we are | |
1511 | reading. */ | |
1512 | return; | |
1513 | } | |
1514 | ||
1515 | /* Offset within shadow_contents. */ | |
1516 | if (bp_addr < memaddr) | |
1517 | { | |
1518 | /* Only copy the second part of the breakpoint. */ | |
1519 | bp_size -= memaddr - bp_addr; | |
1520 | bptoffset = memaddr - bp_addr; | |
1521 | bp_addr = memaddr; | |
1522 | } | |
1523 | ||
1524 | if (bp_addr + bp_size > memaddr + len) | |
1525 | { | |
1526 | /* Only copy the first part of the breakpoint. */ | |
1527 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1528 | } | |
1529 | ||
1530 | if (readbuf != NULL) | |
1531 | { | |
1532 | /* Verify that the readbuf buffer does not overlap with the | |
1533 | shadow_contents buffer. */ | |
1534 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1535 | || readbuf >= (target_info->shadow_contents | |
1536 | + target_info->shadow_len)); | |
1537 | ||
1538 | /* Update the read buffer with this inserted breakpoint's | |
1539 | shadow. */ | |
1540 | memcpy (readbuf + bp_addr - memaddr, | |
1541 | target_info->shadow_contents + bptoffset, bp_size); | |
1542 | } | |
1543 | else | |
1544 | { | |
1545 | const unsigned char *bp; | |
0d5ed153 MR |
1546 | CORE_ADDR addr = target_info->reqstd_address; |
1547 | int placed_size; | |
9d497a19 PA |
1548 | |
1549 | /* Update the shadow with what we want to write to memory. */ | |
1550 | memcpy (target_info->shadow_contents + bptoffset, | |
1551 | writebuf_org + bp_addr - memaddr, bp_size); | |
1552 | ||
1553 | /* Determine appropriate breakpoint contents and size for this | |
1554 | address. */ | |
0d5ed153 | 1555 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1556 | |
1557 | /* Update the final write buffer with this inserted | |
1558 | breakpoint's INSN. */ | |
1559 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1560 | } | |
1561 | } | |
1562 | ||
8defab1a | 1563 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1564 | by replacing any memory breakpoints with their shadowed contents. |
1565 | ||
35c63cd8 JB |
1566 | If READBUF is not NULL, this buffer must not overlap with any of |
1567 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1568 | a failed assertion internal error will be raised. | |
1569 | ||
876fa593 | 1570 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1571 | bl->address - bp_location_placed_address_before_address_max |
1572 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1573 | The range we were requested to resolve shadows for is: |
1574 | memaddr ... memaddr + len | |
1575 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1576 | memaddr + len <= (bl->address |
1577 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1578 | and: |
35df4500 | 1579 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1580 | |
8defab1a | 1581 | void |
f0ba3972 PA |
1582 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1583 | const gdb_byte *writebuf_org, | |
1584 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1585 | { |
4a64f543 MS |
1586 | /* Left boundary, right boundary and median element of our binary |
1587 | search. */ | |
876fa593 | 1588 | unsigned bc_l, bc_r, bc; |
9d497a19 | 1589 | size_t i; |
876fa593 | 1590 | |
4a64f543 MS |
1591 | /* Find BC_L which is a leftmost element which may affect BUF |
1592 | content. It is safe to report lower value but a failure to | |
1593 | report higher one. */ | |
876fa593 JK |
1594 | |
1595 | bc_l = 0; | |
1596 | bc_r = bp_location_count; | |
1597 | while (bc_l + 1 < bc_r) | |
1598 | { | |
35df4500 | 1599 | struct bp_location *bl; |
876fa593 JK |
1600 | |
1601 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1602 | bl = bp_location[bc]; |
876fa593 | 1603 | |
4a64f543 MS |
1604 | /* Check first BL->ADDRESS will not overflow due to the added |
1605 | constant. Then advance the left boundary only if we are sure | |
1606 | the BC element can in no way affect the BUF content (MEMADDR | |
1607 | to MEMADDR + LEN range). | |
876fa593 | 1608 | |
4a64f543 MS |
1609 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1610 | offset so that we cannot miss a breakpoint with its shadow | |
1611 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1612 | |
35df4500 TJB |
1613 | if ((bl->address + bp_location_shadow_len_after_address_max |
1614 | >= bl->address) | |
1615 | && (bl->address + bp_location_shadow_len_after_address_max | |
1616 | <= memaddr)) | |
876fa593 JK |
1617 | bc_l = bc; |
1618 | else | |
1619 | bc_r = bc; | |
1620 | } | |
1621 | ||
128070bb PA |
1622 | /* Due to the binary search above, we need to make sure we pick the |
1623 | first location that's at BC_L's address. E.g., if there are | |
1624 | multiple locations at the same address, BC_L may end up pointing | |
1625 | at a duplicate location, and miss the "master"/"inserted" | |
1626 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1627 | B: | |
1628 | ||
1629 | L1@A, L2@A, L3@B, ... | |
1630 | ||
1631 | BC_L could end up pointing at location L2, while the "master" | |
1632 | location could be L1. Since the `loc->inserted' flag is only set | |
1633 | on "master" locations, we'd forget to restore the shadow of L1 | |
1634 | and L2. */ | |
1635 | while (bc_l > 0 | |
1636 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1637 | bc_l--; | |
1638 | ||
876fa593 JK |
1639 | /* Now do full processing of the found relevant range of elements. */ |
1640 | ||
1641 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1642 | { |
35df4500 | 1643 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1644 | CORE_ADDR bp_addr = 0; |
1645 | int bp_size = 0; | |
1646 | int bptoffset = 0; | |
1647 | ||
35df4500 TJB |
1648 | /* bp_location array has BL->OWNER always non-NULL. */ |
1649 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1650 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1651 | bl->owner->number); |
ffce0d52 | 1652 | |
e5dd4106 | 1653 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1654 | content. */ |
1655 | ||
35df4500 TJB |
1656 | if (bl->address >= bp_location_placed_address_before_address_max |
1657 | && memaddr + len <= (bl->address | |
1658 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1659 | break; |
1660 | ||
35df4500 | 1661 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1662 | continue; |
6c95b8df | 1663 | |
9d497a19 PA |
1664 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1665 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1666 | } | |
c5aa993b | 1667 | |
9d497a19 PA |
1668 | /* Now process single-step breakpoints. These are not found in the |
1669 | bp_location array. */ | |
1670 | for (i = 0; i < 2; i++) | |
1671 | { | |
1672 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
c5aa993b | 1673 | |
9d497a19 PA |
1674 | if (bp_tgt != NULL) |
1675 | { | |
1676 | struct gdbarch *gdbarch = single_step_gdbarch[i]; | |
c5aa993b | 1677 | |
9d497a19 PA |
1678 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1679 | memaddr, len, bp_tgt, gdbarch); | |
1680 | } | |
1681 | } | |
c906108c | 1682 | } |
9d497a19 | 1683 | |
c906108c | 1684 | \f |
c5aa993b | 1685 | |
b775012e LM |
1686 | /* Return true if BPT is either a software breakpoint or a hardware |
1687 | breakpoint. */ | |
1688 | ||
1689 | int | |
1690 | is_breakpoint (const struct breakpoint *bpt) | |
1691 | { | |
1692 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1693 | || bpt->type == bp_hardware_breakpoint |
1694 | || bpt->type == bp_dprintf); | |
b775012e LM |
1695 | } |
1696 | ||
60e1c644 PA |
1697 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1698 | ||
a5606eee | 1699 | static int |
d77f58be | 1700 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1701 | { |
1702 | return (bpt->type == bp_hardware_watchpoint | |
1703 | || bpt->type == bp_read_watchpoint | |
1704 | || bpt->type == bp_access_watchpoint); | |
1705 | } | |
7270d8f2 | 1706 | |
60e1c644 PA |
1707 | /* Return true if BPT is of any watchpoint kind, hardware or |
1708 | software. */ | |
1709 | ||
3a5c3e22 | 1710 | int |
d77f58be | 1711 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1712 | { |
1713 | return (is_hardware_watchpoint (bpt) | |
1714 | || bpt->type == bp_watchpoint); | |
1715 | } | |
1716 | ||
3a5c3e22 PA |
1717 | /* Returns true if the current thread and its running state are safe |
1718 | to evaluate or update watchpoint B. Watchpoints on local | |
1719 | expressions need to be evaluated in the context of the thread that | |
1720 | was current when the watchpoint was created, and, that thread needs | |
1721 | to be stopped to be able to select the correct frame context. | |
1722 | Watchpoints on global expressions can be evaluated on any thread, | |
1723 | and in any state. It is presently left to the target allowing | |
1724 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1725 | |
1726 | static int | |
3a5c3e22 | 1727 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1728 | { |
d0d8b0c6 JK |
1729 | return (b->base.pspace == current_program_space |
1730 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1731 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1732 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1733 | } |
1734 | ||
d0fb5eae JK |
1735 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1736 | associated bp_watchpoint_scope breakpoint. */ | |
1737 | ||
1738 | static void | |
3a5c3e22 | 1739 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1740 | { |
3a5c3e22 | 1741 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1742 | |
1743 | if (b->related_breakpoint != b) | |
1744 | { | |
1745 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1746 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1747 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1748 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1749 | b->related_breakpoint = b; | |
1750 | } | |
1751 | b->disposition = disp_del_at_next_stop; | |
1752 | } | |
1753 | ||
bb9d5f81 PP |
1754 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1755 | watchpoint W. */ | |
1756 | ||
1757 | static struct value * | |
1758 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1759 | { | |
1760 | struct value *bit_val; | |
1761 | ||
1762 | if (val == NULL) | |
1763 | return NULL; | |
1764 | ||
1765 | bit_val = allocate_value (value_type (val)); | |
1766 | ||
1767 | unpack_value_bitfield (bit_val, | |
1768 | w->val_bitpos, | |
1769 | w->val_bitsize, | |
1770 | value_contents_for_printing (val), | |
1771 | value_offset (val), | |
1772 | val); | |
1773 | ||
1774 | return bit_val; | |
1775 | } | |
1776 | ||
567e1b4e JB |
1777 | /* Assuming that B is a watchpoint: |
1778 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1779 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1780 | - Evaluate the condition if there is one, and store the result |
1781 | in b->loc->cond. | |
a5606eee VP |
1782 | - Update the list of values that must be watched in B->loc. |
1783 | ||
4a64f543 MS |
1784 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1785 | nothing. If this is local watchpoint that is out of scope, delete | |
1786 | it. | |
1787 | ||
1788 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1789 | removed + inserted on each stop here. Normal breakpoints must | |
1790 | never be removed because they might be missed by a running thread | |
1791 | when debugging in non-stop mode. On the other hand, hardware | |
1792 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1793 | to each LWP since they are stored in each LWP's hardware debug | |
1794 | registers. Therefore, such LWP must be stopped first in order to | |
1795 | be able to modify its hardware watchpoints. | |
1796 | ||
1797 | Hardware watchpoints must be reset exactly once after being | |
1798 | presented to the user. It cannot be done sooner, because it would | |
1799 | reset the data used to present the watchpoint hit to the user. And | |
1800 | it must not be done later because it could display the same single | |
1801 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1802 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1803 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1804 | not user-visible - its hit is suppressed if the memory content has | |
1805 | not changed. | |
1806 | ||
1807 | The following constraints influence the location where we can reset | |
1808 | hardware watchpoints: | |
1809 | ||
1810 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1811 | called several times when GDB stops. | |
1812 | ||
1813 | [linux] | |
1814 | * Multiple hardware watchpoints can be hit at the same time, | |
1815 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1816 | hit at a time as the reason for stopping, and all the other hits | |
1817 | are presented later, one after the other, each time the user | |
1818 | requests the execution to be resumed. Execution is not resumed | |
1819 | for the threads still having pending hit event stored in | |
1820 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1821 | the inferior on the first stop the thread hit event is kept being | |
1822 | reported from its cached value by linux_nat_stopped_data_address | |
1823 | until the real thread resume happens after the watchpoint gets | |
1824 | presented and thus its LWP_INFO->STATUS gets reset. | |
1825 | ||
1826 | Therefore the hardware watchpoint hit can get safely reset on the | |
1827 | watchpoint removal from inferior. */ | |
a79d3c27 | 1828 | |
b40ce68a | 1829 | static void |
3a5c3e22 | 1830 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1831 | { |
a5606eee | 1832 | int within_current_scope; |
a5606eee | 1833 | struct frame_id saved_frame_id; |
66076460 | 1834 | int frame_saved; |
a5606eee | 1835 | |
f6bc2008 PA |
1836 | /* If this is a local watchpoint, we only want to check if the |
1837 | watchpoint frame is in scope if the current thread is the thread | |
1838 | that was used to create the watchpoint. */ | |
1839 | if (!watchpoint_in_thread_scope (b)) | |
1840 | return; | |
1841 | ||
3a5c3e22 | 1842 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1843 | return; |
1844 | ||
66076460 | 1845 | frame_saved = 0; |
a5606eee VP |
1846 | |
1847 | /* Determine if the watchpoint is within scope. */ | |
1848 | if (b->exp_valid_block == NULL) | |
1849 | within_current_scope = 1; | |
1850 | else | |
1851 | { | |
b5db5dfc UW |
1852 | struct frame_info *fi = get_current_frame (); |
1853 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1854 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1855 | ||
1856 | /* If we're in a function epilogue, unwinding may not work | |
1857 | properly, so do not attempt to recreate locations at this | |
1858 | point. See similar comments in watchpoint_check. */ | |
1859 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1860 | return; | |
66076460 DJ |
1861 | |
1862 | /* Save the current frame's ID so we can restore it after | |
1863 | evaluating the watchpoint expression on its own frame. */ | |
1864 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1865 | took a frame parameter, so that we didn't have to change the | |
1866 | selected frame. */ | |
1867 | frame_saved = 1; | |
1868 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1869 | ||
a5606eee VP |
1870 | fi = frame_find_by_id (b->watchpoint_frame); |
1871 | within_current_scope = (fi != NULL); | |
1872 | if (within_current_scope) | |
1873 | select_frame (fi); | |
1874 | } | |
1875 | ||
b5db5dfc UW |
1876 | /* We don't free locations. They are stored in the bp_location array |
1877 | and update_global_location_list will eventually delete them and | |
1878 | remove breakpoints if needed. */ | |
3a5c3e22 | 1879 | b->base.loc = NULL; |
b5db5dfc | 1880 | |
a5606eee VP |
1881 | if (within_current_scope && reparse) |
1882 | { | |
bbc13ae3 | 1883 | const char *s; |
d63d0675 | 1884 | |
a5606eee VP |
1885 | if (b->exp) |
1886 | { | |
1887 | xfree (b->exp); | |
1888 | b->exp = NULL; | |
1889 | } | |
d63d0675 | 1890 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1891 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1892 | /* If the meaning of expression itself changed, the old value is |
1893 | no longer relevant. We don't want to report a watchpoint hit | |
1894 | to the user when the old value and the new value may actually | |
1895 | be completely different objects. */ | |
1896 | value_free (b->val); | |
fa4727a6 DJ |
1897 | b->val = NULL; |
1898 | b->val_valid = 0; | |
60e1c644 PA |
1899 | |
1900 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1901 | expression is stored in the breakpoint object, not in the | |
1902 | locations (re)created below. */ | |
3a5c3e22 | 1903 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1904 | { |
1905 | if (b->cond_exp != NULL) | |
1906 | { | |
1907 | xfree (b->cond_exp); | |
1908 | b->cond_exp = NULL; | |
1909 | } | |
1910 | ||
3a5c3e22 | 1911 | s = b->base.cond_string; |
1bb9788d | 1912 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1913 | } |
a5606eee | 1914 | } |
a5606eee VP |
1915 | |
1916 | /* If we failed to parse the expression, for example because | |
1917 | it refers to a global variable in a not-yet-loaded shared library, | |
1918 | don't try to insert watchpoint. We don't automatically delete | |
1919 | such watchpoint, though, since failure to parse expression | |
1920 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1921 | if (!target_has_execution) |
2d134ed3 PA |
1922 | { |
1923 | /* Without execution, memory can't change. No use to try and | |
1924 | set watchpoint locations. The watchpoint will be reset when | |
1925 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1926 | if (!can_use_hw_watchpoints) |
1927 | { | |
1928 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1929 | b->base.type = bp_watchpoint; | |
1930 | else | |
638aa5a1 AB |
1931 | error (_("Can't set read/access watchpoint when " |
1932 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1933 | } |
2d134ed3 PA |
1934 | } |
1935 | else if (within_current_scope && b->exp) | |
a5606eee | 1936 | { |
0cf6dd15 | 1937 | int pc = 0; |
fa4727a6 | 1938 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1939 | struct program_space *frame_pspace; |
a5606eee | 1940 | |
3a1115a0 | 1941 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1942 | |
a5606eee VP |
1943 | /* Avoid setting b->val if it's already set. The meaning of |
1944 | b->val is 'the last value' user saw, and we should update | |
1945 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1946 | happens, the code that reports it updates b->val directly. |
1947 | We don't keep track of the memory value for masked | |
1948 | watchpoints. */ | |
3a5c3e22 | 1949 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 | 1950 | { |
bb9d5f81 PP |
1951 | if (b->val_bitsize != 0) |
1952 | { | |
1953 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1954 | if (v != NULL) | |
1955 | release_value (v); | |
1956 | } | |
fa4727a6 DJ |
1957 | b->val = v; |
1958 | b->val_valid = 1; | |
1959 | } | |
a5606eee | 1960 | |
2d134ed3 PA |
1961 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1962 | ||
a5606eee | 1963 | /* Look at each value on the value chain. */ |
9fa40276 | 1964 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1965 | { |
1966 | /* If it's a memory location, and GDB actually needed | |
1967 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1968 | must watch it. If the first value returned is |
1969 | still lazy, that means an error occurred reading it; | |
1970 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1971 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1972 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1973 | { |
1974 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1975 | |
a5606eee VP |
1976 | /* We only watch structs and arrays if user asked |
1977 | for it explicitly, never if they just happen to | |
1978 | appear in the middle of some value chain. */ | |
fa4727a6 | 1979 | if (v == result |
a5606eee VP |
1980 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1981 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1982 | { | |
1983 | CORE_ADDR addr; | |
744a8059 | 1984 | int type; |
a5606eee | 1985 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1986 | int bitpos = 0, bitsize = 0; |
1987 | ||
1988 | if (value_bitsize (v) != 0) | |
1989 | { | |
1990 | /* Extract the bit parameters out from the bitfield | |
1991 | sub-expression. */ | |
1992 | bitpos = value_bitpos (v); | |
1993 | bitsize = value_bitsize (v); | |
1994 | } | |
1995 | else if (v == result && b->val_bitsize != 0) | |
1996 | { | |
1997 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1998 | lvalue whose bit parameters are saved in the fields | |
1999 | VAL_BITPOS and VAL_BITSIZE. */ | |
2000 | bitpos = b->val_bitpos; | |
2001 | bitsize = b->val_bitsize; | |
2002 | } | |
a5606eee | 2003 | |
42ae5230 | 2004 | addr = value_address (v); |
bb9d5f81 PP |
2005 | if (bitsize != 0) |
2006 | { | |
2007 | /* Skip the bytes that don't contain the bitfield. */ | |
2008 | addr += bitpos / 8; | |
2009 | } | |
2010 | ||
a5606eee | 2011 | type = hw_write; |
3a5c3e22 | 2012 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 2013 | type = hw_read; |
3a5c3e22 | 2014 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 2015 | type = hw_access; |
3a5c3e22 PA |
2016 | |
2017 | loc = allocate_bp_location (&b->base); | |
2018 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2019 | ; |
2020 | *tmp = loc; | |
a6d9a66e | 2021 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2022 | |
2023 | loc->pspace = frame_pspace; | |
a5606eee | 2024 | loc->address = addr; |
bb9d5f81 PP |
2025 | |
2026 | if (bitsize != 0) | |
2027 | { | |
2028 | /* Just cover the bytes that make up the bitfield. */ | |
2029 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2030 | } | |
2031 | else | |
2032 | loc->length = TYPE_LENGTH (value_type (v)); | |
2033 | ||
a5606eee VP |
2034 | loc->watchpoint_type = type; |
2035 | } | |
2036 | } | |
9fa40276 TJB |
2037 | } |
2038 | ||
2039 | /* Change the type of breakpoint between hardware assisted or | |
2040 | an ordinary watchpoint depending on the hardware support | |
2041 | and free hardware slots. REPARSE is set when the inferior | |
2042 | is started. */ | |
a9634178 | 2043 | if (reparse) |
9fa40276 | 2044 | { |
e09342b5 | 2045 | int reg_cnt; |
9fa40276 TJB |
2046 | enum bp_loc_type loc_type; |
2047 | struct bp_location *bl; | |
a5606eee | 2048 | |
a9634178 | 2049 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2050 | |
2051 | if (reg_cnt) | |
9fa40276 TJB |
2052 | { |
2053 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2054 | enum bptype type; |
9fa40276 | 2055 | |
a9634178 TJB |
2056 | /* Use an exact watchpoint when there's only one memory region to be |
2057 | watched, and only one debug register is needed to watch it. */ | |
2058 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2059 | ||
9fa40276 | 2060 | /* We need to determine how many resources are already |
e09342b5 TJB |
2061 | used for all other hardware watchpoints plus this one |
2062 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2063 | this watchpoint in as well. */ |
2064 | ||
2065 | /* If this is a software watchpoint, we try to turn it | |
2066 | to a hardware one -- count resources as if B was of | |
2067 | hardware watchpoint type. */ | |
2068 | type = b->base.type; | |
2069 | if (type == bp_watchpoint) | |
2070 | type = bp_hardware_watchpoint; | |
2071 | ||
2072 | /* This watchpoint may or may not have been placed on | |
2073 | the list yet at this point (it won't be in the list | |
2074 | if we're trying to create it for the first time, | |
2075 | through watch_command), so always account for it | |
2076 | manually. */ | |
2077 | ||
2078 | /* Count resources used by all watchpoints except B. */ | |
2079 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
2080 | ||
2081 | /* Add in the resources needed for B. */ | |
2082 | i += hw_watchpoint_use_count (&b->base); | |
2083 | ||
2084 | target_resources_ok | |
2085 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2086 | if (target_resources_ok <= 0) |
a9634178 | 2087 | { |
3a5c3e22 | 2088 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
2089 | |
2090 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2091 | error (_("Target does not support this type of " |
2092 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2093 | else if (target_resources_ok < 0 && !sw_mode) |
2094 | error (_("There are not enough available hardware " | |
2095 | "resources for this watchpoint.")); | |
a1398e0c PA |
2096 | |
2097 | /* Downgrade to software watchpoint. */ | |
2098 | b->base.type = bp_watchpoint; | |
2099 | } | |
2100 | else | |
2101 | { | |
2102 | /* If this was a software watchpoint, we've just | |
2103 | found we have enough resources to turn it to a | |
2104 | hardware watchpoint. Otherwise, this is a | |
2105 | nop. */ | |
2106 | b->base.type = type; | |
a9634178 | 2107 | } |
9fa40276 | 2108 | } |
3a5c3e22 | 2109 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2110 | { |
2111 | if (!can_use_hw_watchpoints) | |
2112 | error (_("Can't set read/access watchpoint when " | |
2113 | "hardware watchpoints are disabled.")); | |
2114 | else | |
2115 | error (_("Expression cannot be implemented with " | |
2116 | "read/access watchpoint.")); | |
2117 | } | |
9fa40276 | 2118 | else |
3a5c3e22 | 2119 | b->base.type = bp_watchpoint; |
9fa40276 | 2120 | |
3a5c3e22 | 2121 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2122 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2123 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2124 | bl->loc_type = loc_type; |
2125 | } | |
2126 | ||
2127 | for (v = val_chain; v; v = next) | |
2128 | { | |
a5606eee VP |
2129 | next = value_next (v); |
2130 | if (v != b->val) | |
2131 | value_free (v); | |
2132 | } | |
2133 | ||
c7437ca6 PA |
2134 | /* If a software watchpoint is not watching any memory, then the |
2135 | above left it without any location set up. But, | |
2136 | bpstat_stop_status requires a location to be able to report | |
2137 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2138 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 2139 | { |
3a5c3e22 PA |
2140 | struct breakpoint *base = &b->base; |
2141 | base->loc = allocate_bp_location (base); | |
2142 | base->loc->pspace = frame_pspace; | |
2143 | base->loc->address = -1; | |
2144 | base->loc->length = -1; | |
2145 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 2146 | } |
a5606eee VP |
2147 | } |
2148 | else if (!within_current_scope) | |
7270d8f2 | 2149 | { |
ac74f770 MS |
2150 | printf_filtered (_("\ |
2151 | Watchpoint %d deleted because the program has left the block\n\ | |
2152 | in which its expression is valid.\n"), | |
3a5c3e22 | 2153 | b->base.number); |
d0fb5eae | 2154 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2155 | } |
a5606eee VP |
2156 | |
2157 | /* Restore the selected frame. */ | |
66076460 DJ |
2158 | if (frame_saved) |
2159 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2160 | } |
2161 | ||
a5606eee | 2162 | |
74960c60 | 2163 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2164 | inserted in the inferior. We don't differentiate the type of BL's owner |
2165 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2166 | breakpoint_ops is not defined, because in insert_bp_location, | |
2167 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2168 | static int |
35df4500 | 2169 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2170 | { |
35df4500 | 2171 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2172 | return 0; |
2173 | ||
35df4500 | 2174 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2175 | return 0; |
2176 | ||
35df4500 | 2177 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2178 | return 0; |
2179 | ||
f8eba3c6 TT |
2180 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2181 | return 0; | |
2182 | ||
56710373 PA |
2183 | /* This is set for example, when we're attached to the parent of a |
2184 | vfork, and have detached from the child. The child is running | |
2185 | free, and we expect it to do an exec or exit, at which point the | |
2186 | OS makes the parent schedulable again (and the target reports | |
2187 | that the vfork is done). Until the child is done with the shared | |
2188 | memory region, do not insert breakpoints in the parent, otherwise | |
2189 | the child could still trip on the parent's breakpoints. Since | |
2190 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2191 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2192 | return 0; |
2193 | ||
31e77af2 PA |
2194 | /* Don't insert a breakpoint if we're trying to step past its |
2195 | location. */ | |
2196 | if ((bl->loc_type == bp_loc_software_breakpoint | |
2197 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2198 | && stepping_past_instruction_at (bl->pspace->aspace, | |
2199 | bl->address)) | |
e558d7c1 PA |
2200 | { |
2201 | if (debug_infrun) | |
2202 | { | |
2203 | fprintf_unfiltered (gdb_stdlog, | |
2204 | "infrun: skipping breakpoint: " | |
2205 | "stepping past insn at: %s\n", | |
2206 | paddress (bl->gdbarch, bl->address)); | |
2207 | } | |
2208 | return 0; | |
2209 | } | |
31e77af2 | 2210 | |
74960c60 VP |
2211 | return 1; |
2212 | } | |
2213 | ||
934709f0 PW |
2214 | /* Same as should_be_inserted but does the check assuming |
2215 | that the location is not duplicated. */ | |
2216 | ||
2217 | static int | |
2218 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2219 | { | |
2220 | int result; | |
2221 | const int save_duplicate = bl->duplicate; | |
2222 | ||
2223 | bl->duplicate = 0; | |
2224 | result = should_be_inserted (bl); | |
2225 | bl->duplicate = save_duplicate; | |
2226 | return result; | |
2227 | } | |
2228 | ||
b775012e LM |
2229 | /* Parses a conditional described by an expression COND into an |
2230 | agent expression bytecode suitable for evaluation | |
2231 | by the bytecode interpreter. Return NULL if there was | |
2232 | any error during parsing. */ | |
2233 | ||
2234 | static struct agent_expr * | |
2235 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2236 | { | |
2237 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2238 | volatile struct gdb_exception ex; |
2239 | ||
2240 | if (!cond) | |
2241 | return NULL; | |
2242 | ||
2243 | /* We don't want to stop processing, so catch any errors | |
2244 | that may show up. */ | |
2245 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2246 | { | |
2247 | aexpr = gen_eval_for_expr (scope, cond); | |
2248 | } | |
2249 | ||
2250 | if (ex.reason < 0) | |
2251 | { | |
2252 | /* If we got here, it means the condition could not be parsed to a valid | |
2253 | bytecode expression and thus can't be evaluated on the target's side. | |
2254 | It's no use iterating through the conditions. */ | |
2255 | return NULL; | |
2256 | } | |
2257 | ||
2258 | /* We have a valid agent expression. */ | |
2259 | return aexpr; | |
2260 | } | |
2261 | ||
2262 | /* Based on location BL, create a list of breakpoint conditions to be | |
2263 | passed on to the target. If we have duplicated locations with different | |
2264 | conditions, we will add such conditions to the list. The idea is that the | |
2265 | target will evaluate the list of conditions and will only notify GDB when | |
2266 | one of them is true. */ | |
2267 | ||
2268 | static void | |
2269 | build_target_condition_list (struct bp_location *bl) | |
2270 | { | |
2271 | struct bp_location **locp = NULL, **loc2p; | |
2272 | int null_condition_or_parse_error = 0; | |
2273 | int modified = bl->needs_update; | |
2274 | struct bp_location *loc; | |
2275 | ||
8b4f3082 PA |
2276 | /* Release conditions left over from a previous insert. */ |
2277 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2278 | ||
b775012e LM |
2279 | /* This is only meaningful if the target is |
2280 | evaluating conditions and if the user has | |
2281 | opted for condition evaluation on the target's | |
2282 | side. */ | |
2283 | if (gdb_evaluates_breakpoint_condition_p () | |
2284 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2285 | return; | |
2286 | ||
2287 | /* Do a first pass to check for locations with no assigned | |
2288 | conditions or conditions that fail to parse to a valid agent expression | |
2289 | bytecode. If any of these happen, then it's no use to send conditions | |
2290 | to the target since this location will always trigger and generate a | |
2291 | response back to GDB. */ | |
2292 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2293 | { | |
2294 | loc = (*loc2p); | |
2295 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2296 | { | |
2297 | if (modified) | |
2298 | { | |
2299 | struct agent_expr *aexpr; | |
2300 | ||
2301 | /* Re-parse the conditions since something changed. In that | |
2302 | case we already freed the condition bytecodes (see | |
2303 | force_breakpoint_reinsertion). We just | |
2304 | need to parse the condition to bytecodes again. */ | |
2305 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2306 | loc->cond_bytecode = aexpr; | |
2307 | ||
2308 | /* Check if we managed to parse the conditional expression | |
2309 | correctly. If not, we will not send this condition | |
2310 | to the target. */ | |
2311 | if (aexpr) | |
2312 | continue; | |
2313 | } | |
2314 | ||
2315 | /* If we have a NULL bytecode expression, it means something | |
2316 | went wrong or we have a null condition expression. */ | |
2317 | if (!loc->cond_bytecode) | |
2318 | { | |
2319 | null_condition_or_parse_error = 1; | |
2320 | break; | |
2321 | } | |
2322 | } | |
2323 | } | |
2324 | ||
2325 | /* If any of these happened, it means we will have to evaluate the conditions | |
2326 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2327 | for all the other duplicate locations, thus we free all of them here. | |
2328 | ||
2329 | This is so we have a finer control over which locations' conditions are | |
2330 | being evaluated by GDB or the remote stub. */ | |
2331 | if (null_condition_or_parse_error) | |
2332 | { | |
2333 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2334 | { | |
2335 | loc = (*loc2p); | |
2336 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2337 | { | |
2338 | /* Only go as far as the first NULL bytecode is | |
2339 | located. */ | |
2340 | if (!loc->cond_bytecode) | |
2341 | return; | |
2342 | ||
2343 | free_agent_expr (loc->cond_bytecode); | |
2344 | loc->cond_bytecode = NULL; | |
2345 | } | |
2346 | } | |
2347 | } | |
2348 | ||
2349 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2350 | for this location's address. */ | |
2351 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2352 | { | |
2353 | loc = (*loc2p); | |
2354 | if (loc->cond | |
2355 | && is_breakpoint (loc->owner) | |
2356 | && loc->pspace->num == bl->pspace->num | |
2357 | && loc->owner->enable_state == bp_enabled | |
2358 | && loc->enabled) | |
2359 | /* Add the condition to the vector. This will be used later to send the | |
2360 | conditions to the target. */ | |
2361 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2362 | loc->cond_bytecode); | |
2363 | } | |
2364 | ||
2365 | return; | |
2366 | } | |
2367 | ||
d3ce09f5 SS |
2368 | /* Parses a command described by string CMD into an agent expression |
2369 | bytecode suitable for evaluation by the bytecode interpreter. | |
2370 | Return NULL if there was any error during parsing. */ | |
2371 | ||
2372 | static struct agent_expr * | |
2373 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2374 | { | |
2375 | struct cleanup *old_cleanups = 0; | |
2376 | struct expression *expr, **argvec; | |
2377 | struct agent_expr *aexpr = NULL; | |
d3ce09f5 | 2378 | volatile struct gdb_exception ex; |
bbc13ae3 KS |
2379 | const char *cmdrest; |
2380 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2381 | struct format_piece *fpieces; |
2382 | int nargs; | |
2383 | struct gdbarch *gdbarch = get_current_arch (); | |
2384 | ||
2385 | if (!cmd) | |
2386 | return NULL; | |
2387 | ||
2388 | cmdrest = cmd; | |
2389 | ||
2390 | if (*cmdrest == ',') | |
2391 | ++cmdrest; | |
bbc13ae3 | 2392 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2393 | |
2394 | if (*cmdrest++ != '"') | |
2395 | error (_("No format string following the location")); | |
2396 | ||
2397 | format_start = cmdrest; | |
2398 | ||
2399 | fpieces = parse_format_string (&cmdrest); | |
2400 | ||
2401 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2402 | ||
2403 | format_end = cmdrest; | |
2404 | ||
2405 | if (*cmdrest++ != '"') | |
2406 | error (_("Bad format string, non-terminated '\"'.")); | |
2407 | ||
bbc13ae3 | 2408 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2409 | |
2410 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2411 | error (_("Invalid argument syntax")); | |
2412 | ||
2413 | if (*cmdrest == ',') | |
2414 | cmdrest++; | |
bbc13ae3 | 2415 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2416 | |
2417 | /* For each argument, make an expression. */ | |
2418 | ||
2419 | argvec = (struct expression **) alloca (strlen (cmd) | |
2420 | * sizeof (struct expression *)); | |
2421 | ||
2422 | nargs = 0; | |
2423 | while (*cmdrest != '\0') | |
2424 | { | |
bbc13ae3 | 2425 | const char *cmd1; |
d3ce09f5 SS |
2426 | |
2427 | cmd1 = cmdrest; | |
2428 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2429 | argvec[nargs++] = expr; | |
2430 | cmdrest = cmd1; | |
2431 | if (*cmdrest == ',') | |
2432 | ++cmdrest; | |
2433 | } | |
2434 | ||
2435 | /* We don't want to stop processing, so catch any errors | |
2436 | that may show up. */ | |
2437 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2438 | { | |
2439 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2440 | format_start, format_end - format_start, | |
2441 | fpieces, nargs, argvec); | |
2442 | } | |
2443 | ||
752eb8b4 TT |
2444 | do_cleanups (old_cleanups); |
2445 | ||
d3ce09f5 SS |
2446 | if (ex.reason < 0) |
2447 | { | |
2448 | /* If we got here, it means the command could not be parsed to a valid | |
2449 | bytecode expression and thus can't be evaluated on the target's side. | |
2450 | It's no use iterating through the other commands. */ | |
2451 | return NULL; | |
2452 | } | |
2453 | ||
d3ce09f5 SS |
2454 | /* We have a valid agent expression, return it. */ |
2455 | return aexpr; | |
2456 | } | |
2457 | ||
2458 | /* Based on location BL, create a list of breakpoint commands to be | |
2459 | passed on to the target. If we have duplicated locations with | |
2460 | different commands, we will add any such to the list. */ | |
2461 | ||
2462 | static void | |
2463 | build_target_command_list (struct bp_location *bl) | |
2464 | { | |
2465 | struct bp_location **locp = NULL, **loc2p; | |
2466 | int null_command_or_parse_error = 0; | |
2467 | int modified = bl->needs_update; | |
2468 | struct bp_location *loc; | |
2469 | ||
8b4f3082 PA |
2470 | /* Release commands left over from a previous insert. */ |
2471 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2472 | ||
41fac0cf | 2473 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2474 | return; |
2475 | ||
41fac0cf PA |
2476 | /* For now, limit to agent-style dprintf breakpoints. */ |
2477 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2478 | return; |
2479 | ||
41fac0cf PA |
2480 | /* For now, if we have any duplicate location that isn't a dprintf, |
2481 | don't install the target-side commands, as that would make the | |
2482 | breakpoint not be reported to the core, and we'd lose | |
2483 | control. */ | |
2484 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2485 | { | |
2486 | loc = (*loc2p); | |
2487 | if (is_breakpoint (loc->owner) | |
2488 | && loc->pspace->num == bl->pspace->num | |
2489 | && loc->owner->type != bp_dprintf) | |
2490 | return; | |
2491 | } | |
2492 | ||
d3ce09f5 SS |
2493 | /* Do a first pass to check for locations with no assigned |
2494 | conditions or conditions that fail to parse to a valid agent expression | |
2495 | bytecode. If any of these happen, then it's no use to send conditions | |
2496 | to the target since this location will always trigger and generate a | |
2497 | response back to GDB. */ | |
2498 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2499 | { | |
2500 | loc = (*loc2p); | |
2501 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2502 | { | |
2503 | if (modified) | |
2504 | { | |
2505 | struct agent_expr *aexpr; | |
2506 | ||
2507 | /* Re-parse the commands since something changed. In that | |
2508 | case we already freed the command bytecodes (see | |
2509 | force_breakpoint_reinsertion). We just | |
2510 | need to parse the command to bytecodes again. */ | |
2511 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2512 | loc->owner->extra_string); | |
2513 | loc->cmd_bytecode = aexpr; | |
2514 | ||
2515 | if (!aexpr) | |
2516 | continue; | |
2517 | } | |
2518 | ||
2519 | /* If we have a NULL bytecode expression, it means something | |
2520 | went wrong or we have a null command expression. */ | |
2521 | if (!loc->cmd_bytecode) | |
2522 | { | |
2523 | null_command_or_parse_error = 1; | |
2524 | break; | |
2525 | } | |
2526 | } | |
2527 | } | |
2528 | ||
2529 | /* If anything failed, then we're not doing target-side commands, | |
2530 | and so clean up. */ | |
2531 | if (null_command_or_parse_error) | |
2532 | { | |
2533 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2534 | { | |
2535 | loc = (*loc2p); | |
2536 | if (is_breakpoint (loc->owner) | |
2537 | && loc->pspace->num == bl->pspace->num) | |
2538 | { | |
2539 | /* Only go as far as the first NULL bytecode is | |
2540 | located. */ | |
40fb6c5e | 2541 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2542 | return; |
2543 | ||
40fb6c5e HZ |
2544 | free_agent_expr (loc->cmd_bytecode); |
2545 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2546 | } |
2547 | } | |
2548 | } | |
2549 | ||
2550 | /* No NULL commands or failed bytecode generation. Build a command list | |
2551 | for this location's address. */ | |
2552 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2553 | { | |
2554 | loc = (*loc2p); | |
2555 | if (loc->owner->extra_string | |
2556 | && is_breakpoint (loc->owner) | |
2557 | && loc->pspace->num == bl->pspace->num | |
2558 | && loc->owner->enable_state == bp_enabled | |
2559 | && loc->enabled) | |
2560 | /* Add the command to the vector. This will be used later | |
2561 | to send the commands to the target. */ | |
2562 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2563 | loc->cmd_bytecode); | |
2564 | } | |
2565 | ||
2566 | bl->target_info.persist = 0; | |
2567 | /* Maybe flag this location as persistent. */ | |
2568 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2569 | bl->target_info.persist = 1; | |
2570 | } | |
2571 | ||
35df4500 TJB |
2572 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2573 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2574 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2575 | Returns 0 for success, 1 if the bp_location type is not supported or |
2576 | -1 for failure. | |
879bfdc2 | 2577 | |
4a64f543 MS |
2578 | NOTE drow/2003-09-09: This routine could be broken down to an |
2579 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2580 | static int |
35df4500 | 2581 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2582 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2583 | int *disabled_breaks, |
dd61ec5c MW |
2584 | int *hw_breakpoint_error, |
2585 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2586 | { |
0000e5cc PA |
2587 | enum errors bp_err = GDB_NO_ERROR; |
2588 | const char *bp_err_message = NULL; | |
c90a6fb7 | 2589 | volatile struct gdb_exception e; |
879bfdc2 | 2590 | |
b775012e | 2591 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2592 | return 0; |
2593 | ||
35c63cd8 JB |
2594 | /* Note we don't initialize bl->target_info, as that wipes out |
2595 | the breakpoint location's shadow_contents if the breakpoint | |
2596 | is still inserted at that location. This in turn breaks | |
2597 | target_read_memory which depends on these buffers when | |
2598 | a memory read is requested at the breakpoint location: | |
2599 | Once the target_info has been wiped, we fail to see that | |
2600 | we have a breakpoint inserted at that address and thus | |
2601 | read the breakpoint instead of returning the data saved in | |
2602 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2603 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2604 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2605 | bl->target_info.length = bl->length; |
8181d85f | 2606 | |
b775012e LM |
2607 | /* When working with target-side conditions, we must pass all the conditions |
2608 | for the same breakpoint address down to the target since GDB will not | |
2609 | insert those locations. With a list of breakpoint conditions, the target | |
2610 | can decide when to stop and notify GDB. */ | |
2611 | ||
2612 | if (is_breakpoint (bl->owner)) | |
2613 | { | |
2614 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2615 | build_target_command_list (bl); |
2616 | /* Reset the modification marker. */ | |
b775012e LM |
2617 | bl->needs_update = 0; |
2618 | } | |
2619 | ||
35df4500 TJB |
2620 | if (bl->loc_type == bp_loc_software_breakpoint |
2621 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2622 | { |
35df4500 | 2623 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2624 | { |
2625 | /* If the explicitly specified breakpoint type | |
2626 | is not hardware breakpoint, check the memory map to see | |
2627 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2628 | |
765dc015 VP |
2629 | Two important cases are: |
2630 | - location type is not hardware breakpoint, memory | |
2631 | is readonly. We change the type of the location to | |
2632 | hardware breakpoint. | |
4a64f543 MS |
2633 | - location type is hardware breakpoint, memory is |
2634 | read-write. This means we've previously made the | |
2635 | location hardware one, but then the memory map changed, | |
2636 | so we undo. | |
765dc015 | 2637 | |
4a64f543 MS |
2638 | When breakpoints are removed, remove_breakpoints will use |
2639 | location types we've just set here, the only possible | |
2640 | problem is that memory map has changed during running | |
2641 | program, but it's not going to work anyway with current | |
2642 | gdb. */ | |
765dc015 | 2643 | struct mem_region *mr |
0d5ed153 | 2644 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2645 | |
2646 | if (mr) | |
2647 | { | |
2648 | if (automatic_hardware_breakpoints) | |
2649 | { | |
765dc015 VP |
2650 | enum bp_loc_type new_type; |
2651 | ||
2652 | if (mr->attrib.mode != MEM_RW) | |
2653 | new_type = bp_loc_hardware_breakpoint; | |
2654 | else | |
2655 | new_type = bp_loc_software_breakpoint; | |
2656 | ||
35df4500 | 2657 | if (new_type != bl->loc_type) |
765dc015 VP |
2658 | { |
2659 | static int said = 0; | |
cc59ec59 | 2660 | |
35df4500 | 2661 | bl->loc_type = new_type; |
765dc015 VP |
2662 | if (!said) |
2663 | { | |
3e43a32a MS |
2664 | fprintf_filtered (gdb_stdout, |
2665 | _("Note: automatically using " | |
2666 | "hardware breakpoints for " | |
2667 | "read-only addresses.\n")); | |
765dc015 VP |
2668 | said = 1; |
2669 | } | |
2670 | } | |
2671 | } | |
35df4500 | 2672 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2673 | && mr->attrib.mode != MEM_RW) |
2674 | { | |
2675 | fprintf_unfiltered (tmp_error_stream, | |
2676 | _("Cannot insert breakpoint %d.\n" | |
2677 | "Cannot set software breakpoint " | |
2678 | "at read-only address %s\n"), | |
2679 | bl->owner->number, | |
2680 | paddress (bl->gdbarch, bl->address)); | |
2681 | return 1; | |
2682 | } | |
765dc015 VP |
2683 | } |
2684 | } | |
2685 | ||
879bfdc2 DJ |
2686 | /* First check to see if we have to handle an overlay. */ |
2687 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2688 | || bl->section == NULL |
2689 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2690 | { |
2691 | /* No overlay handling: just set the breakpoint. */ | |
dd61ec5c MW |
2692 | TRY_CATCH (e, RETURN_MASK_ALL) |
2693 | { | |
0000e5cc PA |
2694 | int val; |
2695 | ||
dd61ec5c | 2696 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2697 | if (val) |
2698 | bp_err = GENERIC_ERROR; | |
dd61ec5c MW |
2699 | } |
2700 | if (e.reason < 0) | |
2701 | { | |
0000e5cc PA |
2702 | bp_err = e.error; |
2703 | bp_err_message = e.message; | |
dd61ec5c | 2704 | } |
879bfdc2 DJ |
2705 | } |
2706 | else | |
2707 | { | |
4a64f543 | 2708 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2709 | Shall we set a breakpoint at the LMA? */ |
2710 | if (!overlay_events_enabled) | |
2711 | { | |
2712 | /* Yes -- overlay event support is not active, | |
2713 | so we must try to set a breakpoint at the LMA. | |
2714 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2715 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2716 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2717 | bl->owner->number); |
879bfdc2 DJ |
2718 | else |
2719 | { | |
35df4500 TJB |
2720 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2721 | bl->section); | |
879bfdc2 | 2722 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2723 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2724 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2725 | |
2726 | /* No overlay handling: just set the breakpoint. */ | |
2727 | TRY_CATCH (e, RETURN_MASK_ALL) | |
2728 | { | |
2729 | int val; | |
2730 | ||
2731 | val = target_insert_breakpoint (bl->gdbarch, | |
2732 | &bl->overlay_target_info); | |
2733 | if (val) | |
2734 | bp_err = GENERIC_ERROR; | |
2735 | } | |
2736 | if (e.reason < 0) | |
2737 | { | |
2738 | bp_err = e.error; | |
2739 | bp_err_message = e.message; | |
2740 | } | |
2741 | ||
2742 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2743 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2744 | "Overlay breakpoint %d " |
2745 | "failed: in ROM?\n", | |
35df4500 | 2746 | bl->owner->number); |
879bfdc2 DJ |
2747 | } |
2748 | } | |
2749 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2750 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2751 | { |
2752 | /* Yes. This overlay section is mapped into memory. */ | |
dd61ec5c MW |
2753 | TRY_CATCH (e, RETURN_MASK_ALL) |
2754 | { | |
0000e5cc PA |
2755 | int val; |
2756 | ||
dd61ec5c | 2757 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2758 | if (val) |
2759 | bp_err = GENERIC_ERROR; | |
dd61ec5c MW |
2760 | } |
2761 | if (e.reason < 0) | |
2762 | { | |
0000e5cc PA |
2763 | bp_err = e.error; |
2764 | bp_err_message = e.message; | |
dd61ec5c | 2765 | } |
879bfdc2 DJ |
2766 | } |
2767 | else | |
2768 | { | |
2769 | /* No. This breakpoint will not be inserted. | |
2770 | No error, but do not mark the bp as 'inserted'. */ | |
2771 | return 0; | |
2772 | } | |
2773 | } | |
2774 | ||
0000e5cc | 2775 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2776 | { |
2777 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2778 | |
2779 | /* In some cases, we might not be able to insert a | |
2780 | breakpoint in a shared library that has already been | |
2781 | removed, but we have not yet processed the shlib unload | |
2782 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2783 | breakpoint insertion themselves can't tell why the |
2784 | breakpoint insertion failed (e.g., the remote target | |
2785 | doesn't define error codes), so we must treat generic | |
2786 | errors as memory errors. */ | |
0000e5cc | 2787 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2788 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2789 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2790 | || shared_objfile_contains_address_p (bl->pspace, |
2791 | bl->address))) | |
879bfdc2 | 2792 | { |
4a64f543 | 2793 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2794 | bl->shlib_disabled = 1; |
8d3788bd | 2795 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2796 | if (!*disabled_breaks) |
2797 | { | |
2798 | fprintf_unfiltered (tmp_error_stream, | |
2799 | "Cannot insert breakpoint %d.\n", | |
2800 | bl->owner->number); | |
2801 | fprintf_unfiltered (tmp_error_stream, | |
2802 | "Temporarily disabling shared " | |
2803 | "library breakpoints:\n"); | |
2804 | } | |
2805 | *disabled_breaks = 1; | |
879bfdc2 | 2806 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2807 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2808 | return 0; |
879bfdc2 DJ |
2809 | } |
2810 | else | |
879bfdc2 | 2811 | { |
35df4500 | 2812 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2813 | { |
0000e5cc PA |
2814 | *hw_breakpoint_error = 1; |
2815 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2816 | fprintf_unfiltered (tmp_error_stream, |
2817 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2818 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2819 | if (bp_err_message != NULL) | |
2820 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2821 | } |
2822 | else | |
2823 | { | |
0000e5cc PA |
2824 | if (bp_err_message == NULL) |
2825 | { | |
2826 | char *message | |
2827 | = memory_error_message (TARGET_XFER_E_IO, | |
2828 | bl->gdbarch, bl->address); | |
2829 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2830 | ||
2831 | fprintf_unfiltered (tmp_error_stream, | |
2832 | "Cannot insert breakpoint %d.\n" | |
2833 | "%s\n", | |
2834 | bl->owner->number, message); | |
2835 | do_cleanups (old_chain); | |
2836 | } | |
2837 | else | |
2838 | { | |
2839 | fprintf_unfiltered (tmp_error_stream, | |
2840 | "Cannot insert breakpoint %d: %s\n", | |
2841 | bl->owner->number, | |
2842 | bp_err_message); | |
2843 | } | |
879bfdc2 | 2844 | } |
0000e5cc | 2845 | return 1; |
879bfdc2 DJ |
2846 | |
2847 | } | |
2848 | } | |
2849 | else | |
35df4500 | 2850 | bl->inserted = 1; |
879bfdc2 | 2851 | |
0000e5cc | 2852 | return 0; |
879bfdc2 DJ |
2853 | } |
2854 | ||
35df4500 | 2855 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2856 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2857 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2858 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2859 | { |
0000e5cc PA |
2860 | int val; |
2861 | ||
77b06cd7 TJB |
2862 | gdb_assert (bl->owner->ops != NULL |
2863 | && bl->owner->ops->insert_location != NULL); | |
2864 | ||
2865 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2866 | |
2867 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2868 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2869 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2870 | { |
2871 | struct bp_location *loc, **loc_temp; | |
2872 | ||
2873 | /* But don't try to insert it, if there's already another | |
2874 | hw_access location that would be considered a duplicate | |
2875 | of this one. */ | |
2876 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2877 | if (loc != bl |
85d721b8 | 2878 | && loc->watchpoint_type == hw_access |
35df4500 | 2879 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2880 | { |
35df4500 TJB |
2881 | bl->duplicate = 1; |
2882 | bl->inserted = 1; | |
2883 | bl->target_info = loc->target_info; | |
2884 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2885 | val = 0; |
2886 | break; | |
2887 | } | |
2888 | ||
2889 | if (val == 1) | |
2890 | { | |
77b06cd7 TJB |
2891 | bl->watchpoint_type = hw_access; |
2892 | val = bl->owner->ops->insert_location (bl); | |
2893 | ||
2894 | if (val) | |
2895 | /* Back to the original value. */ | |
2896 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2897 | } |
2898 | } | |
2899 | ||
35df4500 | 2900 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2901 | } |
2902 | ||
35df4500 | 2903 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2904 | { |
0000e5cc PA |
2905 | int val; |
2906 | ||
77b06cd7 TJB |
2907 | gdb_assert (bl->owner->ops != NULL |
2908 | && bl->owner->ops->insert_location != NULL); | |
2909 | ||
2910 | val = bl->owner->ops->insert_location (bl); | |
2911 | if (val) | |
2912 | { | |
2913 | bl->owner->enable_state = bp_disabled; | |
2914 | ||
2915 | if (val == 1) | |
2916 | warning (_("\ | |
2917 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2918 | of catchpoint."), bl->owner->number); | |
2919 | else | |
2920 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2921 | } | |
2922 | ||
2923 | bl->inserted = (val == 0); | |
1640b821 DJ |
2924 | |
2925 | /* We've already printed an error message if there was a problem | |
2926 | inserting this catchpoint, and we've disabled the catchpoint, | |
2927 | so just return success. */ | |
2928 | return 0; | |
879bfdc2 DJ |
2929 | } |
2930 | ||
2931 | return 0; | |
2932 | } | |
2933 | ||
6c95b8df PA |
2934 | /* This function is called when program space PSPACE is about to be |
2935 | deleted. It takes care of updating breakpoints to not reference | |
2936 | PSPACE anymore. */ | |
2937 | ||
2938 | void | |
2939 | breakpoint_program_space_exit (struct program_space *pspace) | |
2940 | { | |
2941 | struct breakpoint *b, *b_temp; | |
876fa593 | 2942 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2943 | |
2944 | /* Remove any breakpoint that was set through this program space. */ | |
2945 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2946 | { | |
2947 | if (b->pspace == pspace) | |
2948 | delete_breakpoint (b); | |
2949 | } | |
2950 | ||
2951 | /* Breakpoints set through other program spaces could have locations | |
2952 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2953 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2954 | { |
2955 | struct bp_location *tmp; | |
2956 | ||
2957 | if (loc->pspace == pspace) | |
2958 | { | |
2bdf28a0 | 2959 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2960 | if (loc->owner->loc == loc) |
2961 | loc->owner->loc = loc->next; | |
2962 | else | |
2963 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2964 | if (tmp->next == loc) | |
2965 | { | |
2966 | tmp->next = loc->next; | |
2967 | break; | |
2968 | } | |
2969 | } | |
2970 | } | |
2971 | ||
2972 | /* Now update the global location list to permanently delete the | |
2973 | removed locations above. */ | |
44702360 | 2974 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2975 | } |
2976 | ||
74960c60 VP |
2977 | /* Make sure all breakpoints are inserted in inferior. |
2978 | Throws exception on any error. | |
2979 | A breakpoint that is already inserted won't be inserted | |
2980 | again, so calling this function twice is safe. */ | |
2981 | void | |
2982 | insert_breakpoints (void) | |
2983 | { | |
2984 | struct breakpoint *bpt; | |
2985 | ||
2986 | ALL_BREAKPOINTS (bpt) | |
2987 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2988 | { |
2989 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2990 | ||
2991 | update_watchpoint (w, 0 /* don't reparse. */); | |
2992 | } | |
74960c60 | 2993 | |
04086b45 PA |
2994 | /* Updating watchpoints creates new locations, so update the global |
2995 | location list. Explicitly tell ugll to insert locations and | |
2996 | ignore breakpoints_always_inserted_mode. */ | |
2997 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
2998 | } |
2999 | ||
20388dd6 YQ |
3000 | /* Invoke CALLBACK for each of bp_location. */ |
3001 | ||
3002 | void | |
3003 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3004 | { | |
3005 | struct bp_location *loc, **loc_tmp; | |
3006 | ||
3007 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3008 | { | |
3009 | callback (loc, NULL); | |
3010 | } | |
3011 | } | |
3012 | ||
b775012e LM |
3013 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3014 | target. It is the case with deleting and disabling of breakpoints when using | |
3015 | always-inserted mode. */ | |
3016 | ||
3017 | static void | |
3018 | update_inserted_breakpoint_locations (void) | |
3019 | { | |
3020 | struct bp_location *bl, **blp_tmp; | |
3021 | int error_flag = 0; | |
3022 | int val = 0; | |
3023 | int disabled_breaks = 0; | |
3024 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3025 | int hw_bp_details_reported = 0; |
b775012e LM |
3026 | |
3027 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
3028 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
3029 | ||
3030 | /* Explicitly mark the warning -- this will only be printed if | |
3031 | there was an error. */ | |
3032 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
3033 | ||
3034 | save_current_space_and_thread (); | |
3035 | ||
3036 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3037 | { | |
3038 | /* We only want to update software breakpoints and hardware | |
3039 | breakpoints. */ | |
3040 | if (!is_breakpoint (bl->owner)) | |
3041 | continue; | |
3042 | ||
3043 | /* We only want to update locations that are already inserted | |
3044 | and need updating. This is to avoid unwanted insertion during | |
3045 | deletion of breakpoints. */ | |
3046 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3047 | continue; | |
3048 | ||
3049 | switch_to_program_space_and_thread (bl->pspace); | |
3050 | ||
3051 | /* For targets that support global breakpoints, there's no need | |
3052 | to select an inferior to insert breakpoint to. In fact, even | |
3053 | if we aren't attached to any process yet, we should still | |
3054 | insert breakpoints. */ | |
f5656ead | 3055 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3056 | && ptid_equal (inferior_ptid, null_ptid)) |
3057 | continue; | |
3058 | ||
3059 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 3060 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3061 | if (val) |
3062 | error_flag = val; | |
3063 | } | |
3064 | ||
3065 | if (error_flag) | |
3066 | { | |
3067 | target_terminal_ours_for_output (); | |
3068 | error_stream (tmp_error_stream); | |
3069 | } | |
3070 | ||
3071 | do_cleanups (cleanups); | |
3072 | } | |
3073 | ||
c30eee59 | 3074 | /* Used when starting or continuing the program. */ |
c906108c | 3075 | |
74960c60 VP |
3076 | static void |
3077 | insert_breakpoint_locations (void) | |
c906108c | 3078 | { |
a5606eee | 3079 | struct breakpoint *bpt; |
35df4500 | 3080 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3081 | int error_flag = 0; |
c906108c | 3082 | int val = 0; |
3fbb6ffa | 3083 | int disabled_breaks = 0; |
81d0cc19 | 3084 | int hw_breakpoint_error = 0; |
dd61ec5c | 3085 | int hw_bp_error_explained_already = 0; |
c906108c | 3086 | |
81d0cc19 | 3087 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 3088 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 3089 | |
81d0cc19 GS |
3090 | /* Explicitly mark the warning -- this will only be printed if |
3091 | there was an error. */ | |
3092 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
3093 | |
3094 | save_current_space_and_thread (); | |
3095 | ||
35df4500 | 3096 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3097 | { |
b775012e | 3098 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3099 | continue; |
3100 | ||
4a64f543 MS |
3101 | /* There is no point inserting thread-specific breakpoints if |
3102 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3103 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
3104 | if (bl->owner->thread != -1 |
3105 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
3106 | continue; |
3107 | ||
35df4500 | 3108 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3109 | |
3110 | /* For targets that support global breakpoints, there's no need | |
3111 | to select an inferior to insert breakpoint to. In fact, even | |
3112 | if we aren't attached to any process yet, we should still | |
3113 | insert breakpoints. */ | |
f5656ead | 3114 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3115 | && ptid_equal (inferior_ptid, null_ptid)) |
3116 | continue; | |
3117 | ||
3fbb6ffa | 3118 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3119 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3120 | if (val) |
eacd795a | 3121 | error_flag = val; |
879bfdc2 | 3122 | } |
c906108c | 3123 | |
4a64f543 MS |
3124 | /* If we failed to insert all locations of a watchpoint, remove |
3125 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3126 | ALL_BREAKPOINTS (bpt) |
3127 | { | |
3128 | int some_failed = 0; | |
3129 | struct bp_location *loc; | |
3130 | ||
3131 | if (!is_hardware_watchpoint (bpt)) | |
3132 | continue; | |
3133 | ||
d6b74ac4 | 3134 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3135 | continue; |
74960c60 VP |
3136 | |
3137 | if (bpt->disposition == disp_del_at_next_stop) | |
3138 | continue; | |
a5606eee VP |
3139 | |
3140 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3141 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3142 | { |
3143 | some_failed = 1; | |
3144 | break; | |
3145 | } | |
3146 | if (some_failed) | |
3147 | { | |
3148 | for (loc = bpt->loc; loc; loc = loc->next) | |
3149 | if (loc->inserted) | |
3150 | remove_breakpoint (loc, mark_uninserted); | |
3151 | ||
3152 | hw_breakpoint_error = 1; | |
3153 | fprintf_unfiltered (tmp_error_stream, | |
3154 | "Could not insert hardware watchpoint %d.\n", | |
3155 | bpt->number); | |
eacd795a | 3156 | error_flag = -1; |
a5606eee VP |
3157 | } |
3158 | } | |
3159 | ||
eacd795a | 3160 | if (error_flag) |
81d0cc19 GS |
3161 | { |
3162 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3163 | message about possibly exhausted resources. */ | |
dd61ec5c | 3164 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3165 | { |
c6510018 MS |
3166 | fprintf_unfiltered (tmp_error_stream, |
3167 | "Could not insert hardware breakpoints:\n\ | |
3168 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3169 | } |
81d0cc19 GS |
3170 | target_terminal_ours_for_output (); |
3171 | error_stream (tmp_error_stream); | |
3172 | } | |
f7545552 TT |
3173 | |
3174 | do_cleanups (cleanups); | |
c906108c SS |
3175 | } |
3176 | ||
c30eee59 TJB |
3177 | /* Used when the program stops. |
3178 | Returns zero if successful, or non-zero if there was a problem | |
3179 | removing a breakpoint location. */ | |
3180 | ||
c906108c | 3181 | int |
fba45db2 | 3182 | remove_breakpoints (void) |
c906108c | 3183 | { |
35df4500 | 3184 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3185 | int val = 0; |
c906108c | 3186 | |
35df4500 | 3187 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3188 | { |
1e4d1764 | 3189 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 3190 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 3191 | } |
3a1bae8e | 3192 | return val; |
c906108c SS |
3193 | } |
3194 | ||
49fa26b0 PA |
3195 | /* When a thread exits, remove breakpoints that are related to |
3196 | that thread. */ | |
3197 | ||
3198 | static void | |
3199 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3200 | { | |
3201 | struct breakpoint *b, *b_tmp; | |
3202 | ||
3203 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3204 | { | |
96181529 | 3205 | if (b->thread == tp->num && user_breakpoint_p (b)) |
49fa26b0 PA |
3206 | { |
3207 | b->disposition = disp_del_at_next_stop; | |
3208 | ||
3209 | printf_filtered (_("\ | |
46ecd527 | 3210 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
49fa26b0 PA |
3211 | b->number, tp->num); |
3212 | ||
3213 | /* Hide it from the user. */ | |
3214 | b->number = 0; | |
3215 | } | |
3216 | } | |
3217 | } | |
3218 | ||
6c95b8df PA |
3219 | /* Remove breakpoints of process PID. */ |
3220 | ||
3221 | int | |
3222 | remove_breakpoints_pid (int pid) | |
3223 | { | |
35df4500 | 3224 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3225 | int val; |
3226 | struct inferior *inf = find_inferior_pid (pid); | |
3227 | ||
35df4500 | 3228 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3229 | { |
35df4500 | 3230 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3231 | continue; |
3232 | ||
d3ce09f5 SS |
3233 | if (bl->owner->type == bp_dprintf) |
3234 | continue; | |
3235 | ||
35df4500 | 3236 | if (bl->inserted) |
6c95b8df | 3237 | { |
35df4500 | 3238 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
3239 | if (val != 0) |
3240 | return val; | |
3241 | } | |
3242 | } | |
3243 | return 0; | |
3244 | } | |
3245 | ||
c906108c | 3246 | int |
fba45db2 | 3247 | reattach_breakpoints (int pid) |
c906108c | 3248 | { |
6c95b8df | 3249 | struct cleanup *old_chain; |
35df4500 | 3250 | struct bp_location *bl, **blp_tmp; |
c906108c | 3251 | int val; |
86b887df | 3252 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3253 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3254 | struct inferior *inf; |
3255 | struct thread_info *tp; | |
3256 | ||
3257 | tp = any_live_thread_of_process (pid); | |
3258 | if (tp == NULL) | |
3259 | return 1; | |
3260 | ||
3261 | inf = find_inferior_pid (pid); | |
3262 | old_chain = save_inferior_ptid (); | |
3263 | ||
3264 | inferior_ptid = tp->ptid; | |
a4954f26 | 3265 | |
86b887df | 3266 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3267 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3268 | |
35df4500 | 3269 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3270 | { |
35df4500 | 3271 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3272 | continue; |
3273 | ||
35df4500 | 3274 | if (bl->inserted) |
c5aa993b | 3275 | { |
35df4500 | 3276 | bl->inserted = 0; |
dd61ec5c | 3277 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3278 | if (val != 0) |
3279 | { | |
ce696e05 | 3280 | do_cleanups (old_chain); |
c5aa993b JM |
3281 | return val; |
3282 | } | |
3283 | } | |
3284 | } | |
ce696e05 | 3285 | do_cleanups (old_chain); |
c906108c SS |
3286 | return 0; |
3287 | } | |
3288 | ||
e58b0e63 PA |
3289 | static int internal_breakpoint_number = -1; |
3290 | ||
84f4c1fe PM |
3291 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3292 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3293 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3294 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3295 | breakpoint_count and that value incremented. Internal breakpoints |
3296 | do not set the internal var bpnum. */ | |
3297 | static void | |
3298 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3299 | { | |
3300 | if (internal) | |
3301 | b->number = internal_breakpoint_number--; | |
3302 | else | |
3303 | { | |
3304 | set_breakpoint_count (breakpoint_count + 1); | |
3305 | b->number = breakpoint_count; | |
3306 | } | |
3307 | } | |
3308 | ||
e62c965a | 3309 | static struct breakpoint * |
a6d9a66e | 3310 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3311 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3312 | const struct breakpoint_ops *ops) |
e62c965a | 3313 | { |
e62c965a PP |
3314 | struct symtab_and_line sal; |
3315 | struct breakpoint *b; | |
3316 | ||
4a64f543 | 3317 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3318 | |
3319 | sal.pc = address; | |
3320 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3321 | sal.pspace = current_program_space; |
e62c965a | 3322 | |
06edf0c0 | 3323 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3324 | b->number = internal_breakpoint_number--; |
3325 | b->disposition = disp_donttouch; | |
3326 | ||
3327 | return b; | |
3328 | } | |
3329 | ||
17450429 PP |
3330 | static const char *const longjmp_names[] = |
3331 | { | |
3332 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3333 | }; | |
3334 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3335 | ||
3336 | /* Per-objfile data private to breakpoint.c. */ | |
3337 | struct breakpoint_objfile_data | |
3338 | { | |
3339 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3340 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3341 | |
3342 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3343 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3344 | |
28106bc2 SDJ |
3345 | /* True if we have looked for longjmp probes. */ |
3346 | int longjmp_searched; | |
3347 | ||
3348 | /* SystemTap probe points for longjmp (if any). */ | |
3349 | VEC (probe_p) *longjmp_probes; | |
3350 | ||
17450429 | 3351 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3352 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3353 | |
3354 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3355 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3356 | |
3357 | /* True if we have looked for exception probes. */ | |
3358 | int exception_searched; | |
3359 | ||
3360 | /* SystemTap probe points for unwinding (if any). */ | |
3361 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3362 | }; |
3363 | ||
3364 | static const struct objfile_data *breakpoint_objfile_key; | |
3365 | ||
3366 | /* Minimal symbol not found sentinel. */ | |
3367 | static struct minimal_symbol msym_not_found; | |
3368 | ||
3369 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3370 | ||
3371 | static int | |
3372 | msym_not_found_p (const struct minimal_symbol *msym) | |
3373 | { | |
3374 | return msym == &msym_not_found; | |
3375 | } | |
3376 | ||
3377 | /* Return per-objfile data needed by breakpoint.c. | |
3378 | Allocate the data if necessary. */ | |
3379 | ||
3380 | static struct breakpoint_objfile_data * | |
3381 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3382 | { | |
3383 | struct breakpoint_objfile_data *bp_objfile_data; | |
3384 | ||
3385 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
3386 | if (bp_objfile_data == NULL) | |
3387 | { | |
3388 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
3389 | sizeof (*bp_objfile_data)); | |
3390 | ||
3391 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3392 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3393 | } | |
3394 | return bp_objfile_data; | |
3395 | } | |
3396 | ||
28106bc2 SDJ |
3397 | static void |
3398 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3399 | { | |
3400 | struct breakpoint_objfile_data *bp_objfile_data = data; | |
3401 | ||
3402 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3403 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3404 | } | |
3405 | ||
e62c965a | 3406 | static void |
af02033e | 3407 | create_overlay_event_breakpoint (void) |
e62c965a | 3408 | { |
69de3c6a | 3409 | struct objfile *objfile; |
af02033e | 3410 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3411 | |
69de3c6a PP |
3412 | ALL_OBJFILES (objfile) |
3413 | { | |
3414 | struct breakpoint *b; | |
17450429 PP |
3415 | struct breakpoint_objfile_data *bp_objfile_data; |
3416 | CORE_ADDR addr; | |
69de3c6a | 3417 | |
17450429 PP |
3418 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3419 | ||
3b7344d5 | 3420 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3421 | continue; |
3422 | ||
3b7344d5 | 3423 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3424 | { |
3b7344d5 | 3425 | struct bound_minimal_symbol m; |
17450429 PP |
3426 | |
3427 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3428 | if (m.minsym == NULL) |
17450429 PP |
3429 | { |
3430 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3431 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3432 | continue; |
3433 | } | |
3434 | bp_objfile_data->overlay_msym = m; | |
3435 | } | |
e62c965a | 3436 | |
77e371c0 | 3437 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3438 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3439 | bp_overlay_event, |
3440 | &internal_breakpoint_ops); | |
69de3c6a | 3441 | b->addr_string = xstrdup (func_name); |
e62c965a | 3442 | |
69de3c6a PP |
3443 | if (overlay_debugging == ovly_auto) |
3444 | { | |
3445 | b->enable_state = bp_enabled; | |
3446 | overlay_events_enabled = 1; | |
3447 | } | |
3448 | else | |
3449 | { | |
3450 | b->enable_state = bp_disabled; | |
3451 | overlay_events_enabled = 0; | |
3452 | } | |
e62c965a | 3453 | } |
44702360 | 3454 | update_global_location_list (UGLL_MAY_INSERT); |
e62c965a PP |
3455 | } |
3456 | ||
0fd8e87f | 3457 | static void |
af02033e | 3458 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3459 | { |
6c95b8df | 3460 | struct program_space *pspace; |
6c95b8df PA |
3461 | struct cleanup *old_chain; |
3462 | ||
3463 | old_chain = save_current_program_space (); | |
0fd8e87f | 3464 | |
6c95b8df | 3465 | ALL_PSPACES (pspace) |
af02033e PP |
3466 | { |
3467 | struct objfile *objfile; | |
3468 | ||
3469 | set_current_program_space (pspace); | |
3470 | ||
3471 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3472 | { |
af02033e PP |
3473 | int i; |
3474 | struct gdbarch *gdbarch; | |
17450429 | 3475 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3476 | |
af02033e | 3477 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3478 | |
17450429 PP |
3479 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3480 | ||
28106bc2 SDJ |
3481 | if (!bp_objfile_data->longjmp_searched) |
3482 | { | |
25f9533e SDJ |
3483 | VEC (probe_p) *ret; |
3484 | ||
3485 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3486 | if (ret != NULL) | |
3487 | { | |
3488 | /* We are only interested in checking one element. */ | |
3489 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3490 | ||
3491 | if (!can_evaluate_probe_arguments (p)) | |
3492 | { | |
3493 | /* We cannot use the probe interface here, because it does | |
3494 | not know how to evaluate arguments. */ | |
3495 | VEC_free (probe_p, ret); | |
3496 | ret = NULL; | |
3497 | } | |
3498 | } | |
3499 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3500 | bp_objfile_data->longjmp_searched = 1; |
3501 | } | |
3502 | ||
3503 | if (bp_objfile_data->longjmp_probes != NULL) | |
3504 | { | |
3505 | int i; | |
3506 | struct probe *probe; | |
3507 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3508 | ||
3509 | for (i = 0; | |
3510 | VEC_iterate (probe_p, | |
3511 | bp_objfile_data->longjmp_probes, | |
3512 | i, probe); | |
3513 | ++i) | |
3514 | { | |
3515 | struct breakpoint *b; | |
3516 | ||
729662a5 TT |
3517 | b = create_internal_breakpoint (gdbarch, |
3518 | get_probe_address (probe, | |
3519 | objfile), | |
28106bc2 SDJ |
3520 | bp_longjmp_master, |
3521 | &internal_breakpoint_ops); | |
3522 | b->addr_string = xstrdup ("-probe-stap libc:longjmp"); | |
3523 | b->enable_state = bp_disabled; | |
3524 | } | |
3525 | ||
3526 | continue; | |
3527 | } | |
3528 | ||
0569175e TSD |
3529 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3530 | continue; | |
3531 | ||
17450429 | 3532 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3533 | { |
3534 | struct breakpoint *b; | |
af02033e | 3535 | const char *func_name; |
17450429 | 3536 | CORE_ADDR addr; |
6c95b8df | 3537 | |
3b7344d5 | 3538 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3539 | continue; |
0fd8e87f | 3540 | |
17450429 | 3541 | func_name = longjmp_names[i]; |
3b7344d5 | 3542 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3543 | { |
3b7344d5 | 3544 | struct bound_minimal_symbol m; |
17450429 PP |
3545 | |
3546 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3547 | if (m.minsym == NULL) |
17450429 PP |
3548 | { |
3549 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3550 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3551 | continue; |
3552 | } | |
3553 | bp_objfile_data->longjmp_msym[i] = m; | |
3554 | } | |
3555 | ||
77e371c0 | 3556 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3557 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3558 | &internal_breakpoint_ops); | |
af02033e PP |
3559 | b->addr_string = xstrdup (func_name); |
3560 | b->enable_state = bp_disabled; | |
3561 | } | |
0fd8e87f | 3562 | } |
af02033e | 3563 | } |
44702360 | 3564 | update_global_location_list (UGLL_MAY_INSERT); |
6c95b8df PA |
3565 | |
3566 | do_cleanups (old_chain); | |
0fd8e87f UW |
3567 | } |
3568 | ||
af02033e | 3569 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3570 | static void |
af02033e | 3571 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3572 | { |
3573 | struct program_space *pspace; | |
aa7d318d | 3574 | struct cleanup *old_chain; |
af02033e | 3575 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3576 | |
3577 | old_chain = save_current_program_space (); | |
3578 | ||
3579 | ALL_PSPACES (pspace) | |
17450429 PP |
3580 | { |
3581 | struct objfile *objfile; | |
3582 | CORE_ADDR addr; | |
3583 | ||
3584 | set_current_program_space (pspace); | |
3585 | ||
aa7d318d TT |
3586 | ALL_OBJFILES (objfile) |
3587 | { | |
3588 | struct breakpoint *b; | |
17450429 | 3589 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 3590 | |
17450429 | 3591 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3592 | |
3b7344d5 | 3593 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3594 | continue; |
3595 | ||
3b7344d5 | 3596 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3597 | { |
3b7344d5 | 3598 | struct bound_minimal_symbol m; |
17450429 PP |
3599 | |
3600 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3601 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3602 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3603 | { |
3604 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3605 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3606 | continue; |
3607 | } | |
3608 | bp_objfile_data->terminate_msym = m; | |
3609 | } | |
aa7d318d | 3610 | |
77e371c0 | 3611 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3612 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3613 | bp_std_terminate_master, |
3614 | &internal_breakpoint_ops); | |
aa7d318d TT |
3615 | b->addr_string = xstrdup (func_name); |
3616 | b->enable_state = bp_disabled; | |
3617 | } | |
17450429 PP |
3618 | } |
3619 | ||
44702360 | 3620 | update_global_location_list (UGLL_MAY_INSERT); |
aa7d318d TT |
3621 | |
3622 | do_cleanups (old_chain); | |
3623 | } | |
3624 | ||
186c406b TT |
3625 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3626 | ||
70221824 | 3627 | static void |
186c406b TT |
3628 | create_exception_master_breakpoint (void) |
3629 | { | |
3630 | struct objfile *objfile; | |
17450429 | 3631 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3632 | |
3633 | ALL_OBJFILES (objfile) | |
3634 | { | |
17450429 PP |
3635 | struct breakpoint *b; |
3636 | struct gdbarch *gdbarch; | |
3637 | struct breakpoint_objfile_data *bp_objfile_data; | |
3638 | CORE_ADDR addr; | |
3639 | ||
3640 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3641 | ||
28106bc2 SDJ |
3642 | /* We prefer the SystemTap probe point if it exists. */ |
3643 | if (!bp_objfile_data->exception_searched) | |
3644 | { | |
25f9533e SDJ |
3645 | VEC (probe_p) *ret; |
3646 | ||
3647 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3648 | ||
3649 | if (ret != NULL) | |
3650 | { | |
3651 | /* We are only interested in checking one element. */ | |
3652 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3653 | ||
3654 | if (!can_evaluate_probe_arguments (p)) | |
3655 | { | |
3656 | /* We cannot use the probe interface here, because it does | |
3657 | not know how to evaluate arguments. */ | |
3658 | VEC_free (probe_p, ret); | |
3659 | ret = NULL; | |
3660 | } | |
3661 | } | |
3662 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3663 | bp_objfile_data->exception_searched = 1; |
3664 | } | |
3665 | ||
3666 | if (bp_objfile_data->exception_probes != NULL) | |
3667 | { | |
3668 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3669 | int i; | |
3670 | struct probe *probe; | |
3671 | ||
3672 | for (i = 0; | |
3673 | VEC_iterate (probe_p, | |
3674 | bp_objfile_data->exception_probes, | |
3675 | i, probe); | |
3676 | ++i) | |
3677 | { | |
3678 | struct breakpoint *b; | |
3679 | ||
729662a5 TT |
3680 | b = create_internal_breakpoint (gdbarch, |
3681 | get_probe_address (probe, | |
3682 | objfile), | |
28106bc2 SDJ |
3683 | bp_exception_master, |
3684 | &internal_breakpoint_ops); | |
3685 | b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); | |
3686 | b->enable_state = bp_disabled; | |
3687 | } | |
3688 | ||
3689 | continue; | |
3690 | } | |
3691 | ||
3692 | /* Otherwise, try the hook function. */ | |
3693 | ||
3b7344d5 | 3694 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3695 | continue; |
3696 | ||
3697 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3698 | |
3b7344d5 | 3699 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3700 | { |
3b7344d5 | 3701 | struct bound_minimal_symbol debug_hook; |
186c406b | 3702 | |
17450429 | 3703 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3704 | if (debug_hook.minsym == NULL) |
17450429 | 3705 | { |
3b7344d5 | 3706 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3707 | continue; |
3708 | } | |
3709 | ||
3710 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3711 | } |
17450429 | 3712 | |
77e371c0 | 3713 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3714 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3715 | ¤t_target); | |
06edf0c0 PA |
3716 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3717 | &internal_breakpoint_ops); | |
17450429 PP |
3718 | b->addr_string = xstrdup (func_name); |
3719 | b->enable_state = bp_disabled; | |
186c406b TT |
3720 | } |
3721 | ||
44702360 | 3722 | update_global_location_list (UGLL_MAY_INSERT); |
186c406b TT |
3723 | } |
3724 | ||
c906108c | 3725 | void |
fba45db2 | 3726 | update_breakpoints_after_exec (void) |
c906108c | 3727 | { |
35df4500 | 3728 | struct breakpoint *b, *b_tmp; |
876fa593 | 3729 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3730 | |
25b22b0a PA |
3731 | /* We're about to delete breakpoints from GDB's lists. If the |
3732 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3733 | writing the breakpoints' "shadow contents" back into memory. The | |
3734 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3735 | do that. Instead, the target is responsible from marking | |
3736 | breakpoints out as soon as it detects an exec. We don't do that | |
3737 | here instead, because there may be other attempts to delete | |
3738 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3739 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3740 | if (bploc->pspace == current_program_space) |
3741 | gdb_assert (!bploc->inserted); | |
c906108c | 3742 | |
35df4500 | 3743 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3744 | { |
6c95b8df PA |
3745 | if (b->pspace != current_program_space) |
3746 | continue; | |
3747 | ||
4a64f543 | 3748 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3749 | if (b->type == bp_shlib_event) |
3750 | { | |
3751 | delete_breakpoint (b); | |
3752 | continue; | |
3753 | } | |
c906108c | 3754 | |
4a64f543 | 3755 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3756 | if (b->type == bp_jit_event) |
3757 | { | |
3758 | delete_breakpoint (b); | |
3759 | continue; | |
3760 | } | |
3761 | ||
1900040c | 3762 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3763 | as must overlay event and longjmp master breakpoints. */ |
3764 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3765 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3766 | || b->type == bp_exception_master) | |
c4093a6a JM |
3767 | { |
3768 | delete_breakpoint (b); | |
3769 | continue; | |
3770 | } | |
3771 | ||
4a64f543 | 3772 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3773 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3774 | { |
3775 | delete_breakpoint (b); | |
3776 | continue; | |
3777 | } | |
3778 | ||
611c83ae PA |
3779 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3780 | after an exec. */ | |
186c406b | 3781 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3782 | || b->type == bp_longjmp_call_dummy |
186c406b | 3783 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3784 | { |
3785 | delete_breakpoint (b); | |
3786 | continue; | |
3787 | } | |
3788 | ||
ce78b96d JB |
3789 | if (b->type == bp_catchpoint) |
3790 | { | |
3791 | /* For now, none of the bp_catchpoint breakpoints need to | |
3792 | do anything at this point. In the future, if some of | |
3793 | the catchpoints need to something, we will need to add | |
3794 | a new method, and call this method from here. */ | |
3795 | continue; | |
3796 | } | |
3797 | ||
c5aa993b JM |
3798 | /* bp_finish is a special case. The only way we ought to be able |
3799 | to see one of these when an exec() has happened, is if the user | |
3800 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3801 | carries them to the call-site of the current callee, by setting | |
3802 | a temporary bp there and resuming. But in this case, the finish | |
3803 | will carry them entirely through the vfork & exec. | |
3804 | ||
3805 | We don't want to allow a bp_finish to remain inserted now. But | |
3806 | we can't safely delete it, 'cause finish_command has a handle to | |
3807 | the bp on a bpstat, and will later want to delete it. There's a | |
3808 | chance (and I've seen it happen) that if we delete the bp_finish | |
3809 | here, that its storage will get reused by the time finish_command | |
3810 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3811 | We really must allow finish_command to delete a bp_finish. | |
3812 | ||
e5dd4106 | 3813 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3814 | it's safe to delete something others may have handles to?" |
3815 | problem, what we'll do here is just uninsert the bp_finish, and | |
3816 | let finish_command delete it. | |
3817 | ||
3818 | (We know the bp_finish is "doomed" in the sense that it's | |
3819 | momentary, and will be deleted as soon as finish_command sees | |
3820 | the inferior stopped. So it doesn't matter that the bp's | |
3821 | address is probably bogus in the new a.out, unlike e.g., the | |
3822 | solib breakpoints.) */ | |
c5aa993b | 3823 | |
c5aa993b JM |
3824 | if (b->type == bp_finish) |
3825 | { | |
3826 | continue; | |
3827 | } | |
3828 | ||
3829 | /* Without a symbolic address, we have little hope of the | |
3830 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3831 | a.out. */ |
c5aa993b JM |
3832 | if (b->addr_string == NULL) |
3833 | { | |
3834 | delete_breakpoint (b); | |
3835 | continue; | |
3836 | } | |
c5aa993b | 3837 | } |
c906108c SS |
3838 | } |
3839 | ||
3840 | int | |
d80ee84f | 3841 | detach_breakpoints (ptid_t ptid) |
c906108c | 3842 | { |
35df4500 | 3843 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3844 | int val = 0; |
ce696e05 | 3845 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3846 | struct inferior *inf = current_inferior (); |
c5aa993b | 3847 | |
dfd4cc63 | 3848 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3849 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3850 | |
6c95b8df | 3851 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3852 | inferior_ptid = ptid; |
35df4500 | 3853 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3854 | { |
35df4500 | 3855 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3856 | continue; |
3857 | ||
bd9673a4 PW |
3858 | /* This function must physically remove breakpoints locations |
3859 | from the specified ptid, without modifying the breakpoint | |
3860 | package's state. Locations of type bp_loc_other are only | |
3861 | maintained at GDB side. So, there is no need to remove | |
3862 | these bp_loc_other locations. Moreover, removing these | |
3863 | would modify the breakpoint package's state. */ | |
3864 | if (bl->loc_type == bp_loc_other) | |
3865 | continue; | |
3866 | ||
35df4500 TJB |
3867 | if (bl->inserted) |
3868 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3869 | } |
d03285ec UW |
3870 | |
3871 | /* Detach single-step breakpoints as well. */ | |
3872 | detach_single_step_breakpoints (); | |
3873 | ||
ce696e05 | 3874 | do_cleanups (old_chain); |
3a1bae8e | 3875 | return val; |
c906108c SS |
3876 | } |
3877 | ||
35df4500 | 3878 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3879 | Note that this is used to detach breakpoints from a child fork. |
3880 | When we get here, the child isn't in the inferior list, and neither | |
3881 | do we have objects to represent its address space --- we should | |
35df4500 | 3882 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3883 | |
c906108c | 3884 | static int |
35df4500 | 3885 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3886 | { |
3887 | int val; | |
c5aa993b | 3888 | |
35df4500 TJB |
3889 | /* BL is never in moribund_locations by our callers. */ |
3890 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3891 | |
35df4500 | 3892 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
3893 | /* Permanent breakpoints cannot be inserted or removed. */ |
3894 | return 0; | |
3895 | ||
74960c60 VP |
3896 | /* The type of none suggests that owner is actually deleted. |
3897 | This should not ever happen. */ | |
35df4500 | 3898 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3899 | |
35df4500 TJB |
3900 | if (bl->loc_type == bp_loc_software_breakpoint |
3901 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3902 | { |
c02f5703 MS |
3903 | /* "Normal" instruction breakpoint: either the standard |
3904 | trap-instruction bp (bp_breakpoint), or a | |
3905 | bp_hardware_breakpoint. */ | |
3906 | ||
3907 | /* First check to see if we have to handle an overlay. */ | |
3908 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3909 | || bl->section == NULL |
3910 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3911 | { |
3912 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3913 | |
3914 | /* If we're trying to uninsert a memory breakpoint that we | |
3915 | know is set in a dynamic object that is marked | |
3916 | shlib_disabled, then either the dynamic object was | |
3917 | removed with "remove-symbol-file" or with | |
3918 | "nosharedlibrary". In the former case, we don't know | |
3919 | whether another dynamic object might have loaded over the | |
3920 | breakpoint's address -- the user might well let us know | |
3921 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3922 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3923 | list of dynamically loaded objects). If we have the |
3924 | breakpoint's shadow memory, that is, this is a software | |
3925 | breakpoint managed by GDB, check whether the breakpoint | |
3926 | is still inserted in memory, to avoid overwriting wrong | |
3927 | code with stale saved shadow contents. Note that HW | |
3928 | breakpoints don't have shadow memory, as they're | |
3929 | implemented using a mechanism that is not dependent on | |
3930 | being able to modify the target's memory, and as such | |
3931 | they should always be removed. */ | |
3932 | if (bl->shlib_disabled | |
3933 | && bl->target_info.shadow_len != 0 | |
3934 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3935 | val = 0; | |
3936 | else | |
3937 | val = bl->owner->ops->remove_location (bl); | |
c02f5703 | 3938 | } |
c906108c SS |
3939 | else |
3940 | { | |
4a64f543 | 3941 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3942 | Did we set a breakpoint at the LMA? */ |
3943 | if (!overlay_events_enabled) | |
3944 | { | |
3945 | /* Yes -- overlay event support is not active, so we | |
3946 | should have set a breakpoint at the LMA. Remove it. | |
3947 | */ | |
c02f5703 MS |
3948 | /* Ignore any failures: if the LMA is in ROM, we will |
3949 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3950 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3951 | target_remove_hw_breakpoint (bl->gdbarch, | |
3952 | &bl->overlay_target_info); | |
c02f5703 | 3953 | else |
35df4500 TJB |
3954 | target_remove_breakpoint (bl->gdbarch, |
3955 | &bl->overlay_target_info); | |
c02f5703 MS |
3956 | } |
3957 | /* Did we set a breakpoint at the VMA? | |
3958 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3959 | if (bl->inserted) |
c906108c | 3960 | { |
c02f5703 MS |
3961 | /* Yes -- remove it. Previously we did not bother to |
3962 | remove the breakpoint if the section had been | |
3963 | unmapped, but let's not rely on that being safe. We | |
3964 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3965 | |
3966 | /* However, we should remove *software* breakpoints only | |
3967 | if the section is still mapped, or else we overwrite | |
3968 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3969 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3970 | || section_is_mapped (bl->section)) | |
3971 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3972 | else |
3973 | val = 0; | |
c906108c | 3974 | } |
c02f5703 MS |
3975 | else |
3976 | { | |
3977 | /* No -- not inserted, so no need to remove. No error. */ | |
3978 | val = 0; | |
3979 | } | |
c906108c | 3980 | } |
879d1e6b | 3981 | |
08351840 PA |
3982 | /* In some cases, we might not be able to remove a breakpoint in |
3983 | a shared library that has already been removed, but we have | |
3984 | not yet processed the shlib unload event. Similarly for an | |
3985 | unloaded add-symbol-file object - the user might not yet have | |
3986 | had the chance to remove-symbol-file it. shlib_disabled will | |
3987 | be set if the library/object has already been removed, but | |
3988 | the breakpoint hasn't been uninserted yet, e.g., after | |
3989 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3990 | always-inserted mode. */ | |
076855f9 | 3991 | if (val |
08351840 PA |
3992 | && (bl->loc_type == bp_loc_software_breakpoint |
3993 | && (bl->shlib_disabled | |
3994 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3995 | || shared_objfile_contains_address_p (bl->pspace, |
3996 | bl->address)))) | |
879d1e6b UW |
3997 | val = 0; |
3998 | ||
c906108c SS |
3999 | if (val) |
4000 | return val; | |
35df4500 | 4001 | bl->inserted = (is == mark_inserted); |
c906108c | 4002 | } |
35df4500 | 4003 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4004 | { |
77b06cd7 TJB |
4005 | gdb_assert (bl->owner->ops != NULL |
4006 | && bl->owner->ops->remove_location != NULL); | |
4007 | ||
35df4500 | 4008 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 4009 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 4010 | |
c906108c | 4011 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 4012 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 4013 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4014 | bl->owner->number); |
c906108c | 4015 | } |
35df4500 TJB |
4016 | else if (bl->owner->type == bp_catchpoint |
4017 | && breakpoint_enabled (bl->owner) | |
4018 | && !bl->duplicate) | |
ce78b96d | 4019 | { |
77b06cd7 TJB |
4020 | gdb_assert (bl->owner->ops != NULL |
4021 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4022 | |
77b06cd7 | 4023 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
4024 | if (val) |
4025 | return val; | |
77b06cd7 | 4026 | |
35df4500 | 4027 | bl->inserted = (is == mark_inserted); |
ce78b96d | 4028 | } |
c906108c SS |
4029 | |
4030 | return 0; | |
4031 | } | |
4032 | ||
6c95b8df | 4033 | static int |
35df4500 | 4034 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
4035 | { |
4036 | int ret; | |
4037 | struct cleanup *old_chain; | |
4038 | ||
35df4500 TJB |
4039 | /* BL is never in moribund_locations by our callers. */ |
4040 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4041 | |
35df4500 | 4042 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
4043 | /* Permanent breakpoints cannot be inserted or removed. */ |
4044 | return 0; | |
4045 | ||
4046 | /* The type of none suggests that owner is actually deleted. | |
4047 | This should not ever happen. */ | |
35df4500 | 4048 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4049 | |
4050 | old_chain = save_current_space_and_thread (); | |
4051 | ||
35df4500 | 4052 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4053 | |
35df4500 | 4054 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
4055 | |
4056 | do_cleanups (old_chain); | |
4057 | return ret; | |
4058 | } | |
4059 | ||
c906108c SS |
4060 | /* Clear the "inserted" flag in all breakpoints. */ |
4061 | ||
25b22b0a | 4062 | void |
fba45db2 | 4063 | mark_breakpoints_out (void) |
c906108c | 4064 | { |
35df4500 | 4065 | struct bp_location *bl, **blp_tmp; |
c906108c | 4066 | |
35df4500 TJB |
4067 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4068 | if (bl->pspace == current_program_space) | |
4069 | bl->inserted = 0; | |
c906108c SS |
4070 | } |
4071 | ||
53a5351d JM |
4072 | /* Clear the "inserted" flag in all breakpoints and delete any |
4073 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4074 | |
4075 | Plus other such housekeeping that has to be done for breakpoints | |
4076 | between runs. | |
4077 | ||
53a5351d JM |
4078 | Note: this function gets called at the end of a run (by |
4079 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4080 | init_wait_for_inferior). */ |
c906108c SS |
4081 | |
4082 | ||
4083 | ||
4084 | void | |
fba45db2 | 4085 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4086 | { |
35df4500 TJB |
4087 | struct breakpoint *b, *b_tmp; |
4088 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 4089 | int ix; |
6c95b8df | 4090 | struct program_space *pspace = current_program_space; |
c906108c | 4091 | |
50c71eaf PA |
4092 | /* If breakpoint locations are shared across processes, then there's |
4093 | nothing to do. */ | |
f5656ead | 4094 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4095 | return; |
4096 | ||
35df4500 | 4097 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 4098 | { |
35df4500 TJB |
4099 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
4100 | if (bl->pspace == pspace | |
4101 | && bl->owner->enable_state != bp_permanent) | |
4102 | bl->inserted = 0; | |
6c95b8df | 4103 | } |
075f6582 | 4104 | |
35df4500 | 4105 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4106 | { |
6c95b8df PA |
4107 | if (b->loc && b->loc->pspace != pspace) |
4108 | continue; | |
4109 | ||
c5aa993b JM |
4110 | switch (b->type) |
4111 | { | |
4112 | case bp_call_dummy: | |
e2e4d78b | 4113 | case bp_longjmp_call_dummy: |
c906108c | 4114 | |
c5aa993b | 4115 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4116 | cause problems when the inferior is rerun, so we better get |
4117 | rid of it. */ | |
4118 | ||
4119 | case bp_watchpoint_scope: | |
4120 | ||
4121 | /* Also get rid of scope breakpoints. */ | |
4122 | ||
4123 | case bp_shlib_event: | |
4124 | ||
4125 | /* Also remove solib event breakpoints. Their addresses may | |
4126 | have changed since the last time we ran the program. | |
4127 | Actually we may now be debugging against different target; | |
4128 | and so the solib backend that installed this breakpoint may | |
4129 | not be used in by the target. E.g., | |
4130 | ||
4131 | (gdb) file prog-linux | |
4132 | (gdb) run # native linux target | |
4133 | ... | |
4134 | (gdb) kill | |
4135 | (gdb) file prog-win.exe | |
4136 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4137 | */ | |
c906108c | 4138 | |
f59f708a PA |
4139 | case bp_step_resume: |
4140 | ||
4141 | /* Also remove step-resume breakpoints. */ | |
4142 | ||
c5aa993b JM |
4143 | delete_breakpoint (b); |
4144 | break; | |
c906108c | 4145 | |
c5aa993b JM |
4146 | case bp_watchpoint: |
4147 | case bp_hardware_watchpoint: | |
4148 | case bp_read_watchpoint: | |
4149 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4150 | { |
4151 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4152 | |
3a5c3e22 PA |
4153 | /* Likewise for watchpoints on local expressions. */ |
4154 | if (w->exp_valid_block != NULL) | |
4155 | delete_breakpoint (b); | |
4156 | else if (context == inf_starting) | |
4157 | { | |
4158 | /* Reset val field to force reread of starting value in | |
4159 | insert_breakpoints. */ | |
4160 | if (w->val) | |
4161 | value_free (w->val); | |
4162 | w->val = NULL; | |
4163 | w->val_valid = 0; | |
c860120c | 4164 | } |
3a5c3e22 | 4165 | } |
c5aa993b JM |
4166 | break; |
4167 | default: | |
c5aa993b JM |
4168 | break; |
4169 | } | |
4170 | } | |
1c5cfe86 PA |
4171 | |
4172 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4173 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4174 | decref_bp_location (&bl); | |
1c5cfe86 | 4175 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4176 | } |
4177 | ||
6c95b8df PA |
4178 | /* These functions concern about actual breakpoints inserted in the |
4179 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4180 | we need to hop over the bkpt --- so we check for address space | |
4181 | match, not program space. */ | |
4182 | ||
c2c6d25f JM |
4183 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4184 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4185 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4186 | permanent breakpoint. | |
4187 | - When continuing from a location with an ordinary breakpoint, we | |
4188 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4189 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4190 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4191 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4192 | |
c2c6d25f | 4193 | enum breakpoint_here |
6c95b8df | 4194 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4195 | { |
35df4500 | 4196 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4197 | int any_breakpoint_here = 0; |
c906108c | 4198 | |
35df4500 | 4199 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4200 | { |
35df4500 TJB |
4201 | if (bl->loc_type != bp_loc_software_breakpoint |
4202 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4203 | continue; |
4204 | ||
f1310107 | 4205 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
4206 | if ((breakpoint_enabled (bl->owner) |
4207 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 4208 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4209 | { |
4210 | if (overlay_debugging | |
35df4500 TJB |
4211 | && section_is_overlay (bl->section) |
4212 | && !section_is_mapped (bl->section)) | |
075f6582 | 4213 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 4214 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
4215 | return permanent_breakpoint_here; |
4216 | else | |
4217 | any_breakpoint_here = 1; | |
4218 | } | |
4219 | } | |
c906108c | 4220 | |
c2c6d25f | 4221 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
4222 | } |
4223 | ||
1c5cfe86 PA |
4224 | /* Return true if there's a moribund breakpoint at PC. */ |
4225 | ||
4226 | int | |
6c95b8df | 4227 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4228 | { |
4229 | struct bp_location *loc; | |
4230 | int ix; | |
4231 | ||
4232 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4233 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4234 | return 1; |
4235 | ||
4236 | return 0; | |
4237 | } | |
c2c6d25f | 4238 | |
c36b740a | 4239 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
4240 | inserted using regular breakpoint_chain / bp_location array |
4241 | mechanism. This does not check for single-step breakpoints, which | |
4242 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
4243 | |
4244 | int | |
4a64f543 MS |
4245 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
4246 | CORE_ADDR pc) | |
c906108c | 4247 | { |
35df4500 | 4248 | struct bp_location *bl, **blp_tmp; |
c906108c | 4249 | |
35df4500 | 4250 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4251 | { |
35df4500 TJB |
4252 | if (bl->loc_type != bp_loc_software_breakpoint |
4253 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4254 | continue; |
4255 | ||
35df4500 | 4256 | if (bl->inserted |
f1310107 | 4257 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4258 | { |
4259 | if (overlay_debugging | |
35df4500 TJB |
4260 | && section_is_overlay (bl->section) |
4261 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
4262 | continue; /* unmapped overlay -- can't be a match */ |
4263 | else | |
4264 | return 1; | |
4265 | } | |
c5aa993b | 4266 | } |
c36b740a VP |
4267 | return 0; |
4268 | } | |
4269 | ||
4270 | /* Returns non-zero iff there's either regular breakpoint | |
4271 | or a single step breakpoint inserted at PC. */ | |
4272 | ||
4273 | int | |
6c95b8df | 4274 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 4275 | { |
6c95b8df | 4276 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 4277 | return 1; |
c906108c | 4278 | |
6c95b8df | 4279 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
4280 | return 1; |
4281 | ||
c906108c SS |
4282 | return 0; |
4283 | } | |
4284 | ||
ef370185 JB |
4285 | /* Ignoring deprecated raw breakpoints, return non-zero iff there is a |
4286 | software breakpoint inserted at PC. */ | |
4fa8626c | 4287 | |
ef370185 JB |
4288 | static struct bp_location * |
4289 | find_non_raw_software_breakpoint_inserted_here (struct address_space *aspace, | |
4290 | CORE_ADDR pc) | |
4fa8626c | 4291 | { |
35df4500 | 4292 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 4293 | |
35df4500 | 4294 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 4295 | { |
35df4500 | 4296 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4297 | continue; |
4298 | ||
35df4500 TJB |
4299 | if (bl->inserted |
4300 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 4301 | aspace, pc)) |
4fa8626c DJ |
4302 | { |
4303 | if (overlay_debugging | |
35df4500 TJB |
4304 | && section_is_overlay (bl->section) |
4305 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
4306 | continue; /* unmapped overlay -- can't be a match */ |
4307 | else | |
ef370185 | 4308 | return bl; |
4fa8626c DJ |
4309 | } |
4310 | } | |
4311 | ||
ef370185 JB |
4312 | return NULL; |
4313 | } | |
4314 | ||
4315 | /* This function returns non-zero iff there is a software breakpoint | |
4316 | inserted at PC. */ | |
4317 | ||
4318 | int | |
4319 | software_breakpoint_inserted_here_p (struct address_space *aspace, | |
4320 | CORE_ADDR pc) | |
4321 | { | |
4322 | if (find_non_raw_software_breakpoint_inserted_here (aspace, pc) != NULL) | |
4323 | return 1; | |
4324 | ||
1aafd4da | 4325 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 4326 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
4327 | return 1; |
4328 | ||
4fa8626c DJ |
4329 | return 0; |
4330 | } | |
4331 | ||
9093389c PA |
4332 | int |
4333 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4334 | CORE_ADDR addr, ULONGEST len) | |
4335 | { | |
4336 | struct breakpoint *bpt; | |
4337 | ||
4338 | ALL_BREAKPOINTS (bpt) | |
4339 | { | |
4340 | struct bp_location *loc; | |
4341 | ||
4342 | if (bpt->type != bp_hardware_watchpoint | |
4343 | && bpt->type != bp_access_watchpoint) | |
4344 | continue; | |
4345 | ||
4346 | if (!breakpoint_enabled (bpt)) | |
4347 | continue; | |
4348 | ||
4349 | for (loc = bpt->loc; loc; loc = loc->next) | |
4350 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4351 | { | |
4352 | CORE_ADDR l, h; | |
4353 | ||
4354 | /* Check for intersection. */ | |
4355 | l = max (loc->address, addr); | |
4356 | h = min (loc->address + loc->length, addr + len); | |
4357 | if (l < h) | |
4358 | return 1; | |
4359 | } | |
4360 | } | |
4361 | return 0; | |
4362 | } | |
4363 | ||
075f6582 DJ |
4364 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
4365 | PC is valid for process/thread PTID. */ | |
c906108c SS |
4366 | |
4367 | int | |
6c95b8df PA |
4368 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
4369 | ptid_t ptid) | |
c906108c | 4370 | { |
35df4500 | 4371 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 4372 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 4373 | int thread = -1; |
4a306c9a | 4374 | int task = 0; |
a6f1cd96 | 4375 | |
35df4500 | 4376 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4377 | { |
35df4500 TJB |
4378 | if (bl->loc_type != bp_loc_software_breakpoint |
4379 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4380 | continue; |
4381 | ||
35df4500 TJB |
4382 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
4383 | if (!breakpoint_enabled (bl->owner) | |
4384 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
4385 | continue; |
4386 | ||
f1310107 | 4387 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
4388 | continue; |
4389 | ||
35df4500 | 4390 | if (bl->owner->thread != -1) |
075f6582 | 4391 | { |
a6f1cd96 JB |
4392 | /* This is a thread-specific breakpoint. Check that ptid |
4393 | matches that thread. If thread hasn't been computed yet, | |
4394 | it is now time to do so. */ | |
4395 | if (thread == -1) | |
4396 | thread = pid_to_thread_id (ptid); | |
35df4500 | 4397 | if (bl->owner->thread != thread) |
a6f1cd96 | 4398 | continue; |
075f6582 | 4399 | } |
a6f1cd96 | 4400 | |
35df4500 | 4401 | if (bl->owner->task != 0) |
4a306c9a JB |
4402 | { |
4403 | /* This is a task-specific breakpoint. Check that ptid | |
4404 | matches that task. If task hasn't been computed yet, | |
4405 | it is now time to do so. */ | |
4406 | if (task == 0) | |
4407 | task = ada_get_task_number (ptid); | |
35df4500 | 4408 | if (bl->owner->task != task) |
4a306c9a JB |
4409 | continue; |
4410 | } | |
4411 | ||
a6f1cd96 | 4412 | if (overlay_debugging |
35df4500 TJB |
4413 | && section_is_overlay (bl->section) |
4414 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
4415 | continue; /* unmapped overlay -- can't be a match */ |
4416 | ||
4417 | return 1; | |
c5aa993b | 4418 | } |
c906108c SS |
4419 | |
4420 | return 0; | |
4421 | } | |
c906108c | 4422 | \f |
c5aa993b | 4423 | |
c906108c SS |
4424 | /* bpstat stuff. External routines' interfaces are documented |
4425 | in breakpoint.h. */ | |
4426 | ||
4427 | int | |
c326b90e | 4428 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4429 | { |
533be4dd | 4430 | return (ep->type == bp_catchpoint); |
c906108c SS |
4431 | } |
4432 | ||
f431efe5 PA |
4433 | /* Frees any storage that is part of a bpstat. Does not walk the |
4434 | 'next' chain. */ | |
4435 | ||
4436 | static void | |
198757a8 VP |
4437 | bpstat_free (bpstat bs) |
4438 | { | |
4439 | if (bs->old_val != NULL) | |
4440 | value_free (bs->old_val); | |
9add0f1b | 4441 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4442 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4443 | xfree (bs); |
4444 | } | |
4445 | ||
c906108c SS |
4446 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4447 | Also free any storage that is part of a bpstat. */ | |
4448 | ||
4449 | void | |
fba45db2 | 4450 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4451 | { |
4452 | bpstat p; | |
4453 | bpstat q; | |
4454 | ||
4455 | if (bsp == 0) | |
4456 | return; | |
4457 | p = *bsp; | |
4458 | while (p != NULL) | |
4459 | { | |
4460 | q = p->next; | |
198757a8 | 4461 | bpstat_free (p); |
c906108c SS |
4462 | p = q; |
4463 | } | |
4464 | *bsp = NULL; | |
4465 | } | |
4466 | ||
4467 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4468 | is part of the bpstat is copied as well. */ | |
4469 | ||
4470 | bpstat | |
fba45db2 | 4471 | bpstat_copy (bpstat bs) |
c906108c SS |
4472 | { |
4473 | bpstat p = NULL; | |
4474 | bpstat tmp; | |
4475 | bpstat retval = NULL; | |
4476 | ||
4477 | if (bs == NULL) | |
4478 | return bs; | |
4479 | ||
4480 | for (; bs != NULL; bs = bs->next) | |
4481 | { | |
4482 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4483 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4484 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4485 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4486 | if (bs->old_val != NULL) |
3c3185ac JK |
4487 | { |
4488 | tmp->old_val = value_copy (bs->old_val); | |
4489 | release_value (tmp->old_val); | |
4490 | } | |
31cc81e9 | 4491 | |
c906108c SS |
4492 | if (p == NULL) |
4493 | /* This is the first thing in the chain. */ | |
4494 | retval = tmp; | |
4495 | else | |
4496 | p->next = tmp; | |
4497 | p = tmp; | |
4498 | } | |
4499 | p->next = NULL; | |
4500 | return retval; | |
4501 | } | |
4502 | ||
4a64f543 | 4503 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4504 | |
4505 | bpstat | |
fba45db2 | 4506 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4507 | { |
c5aa993b JM |
4508 | if (bsp == NULL) |
4509 | return NULL; | |
c906108c | 4510 | |
c5aa993b JM |
4511 | for (; bsp != NULL; bsp = bsp->next) |
4512 | { | |
f431efe5 | 4513 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4514 | return bsp; |
4515 | } | |
c906108c SS |
4516 | return NULL; |
4517 | } | |
4518 | ||
ab04a2af TT |
4519 | /* See breakpoint.h. */ |
4520 | ||
47591c29 | 4521 | int |
427cd150 | 4522 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4523 | { |
ab04a2af TT |
4524 | for (; bsp != NULL; bsp = bsp->next) |
4525 | { | |
427cd150 TT |
4526 | if (bsp->breakpoint_at == NULL) |
4527 | { | |
4528 | /* A moribund location can never explain a signal other than | |
4529 | GDB_SIGNAL_TRAP. */ | |
4530 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4531 | return 1; |
427cd150 TT |
4532 | } |
4533 | else | |
47591c29 PA |
4534 | { |
4535 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4536 | sig)) | |
4537 | return 1; | |
4538 | } | |
ab04a2af TT |
4539 | } |
4540 | ||
47591c29 | 4541 | return 0; |
ab04a2af TT |
4542 | } |
4543 | ||
4a64f543 MS |
4544 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4545 | stopped at. *BSP upon return is a bpstat which points to the | |
4546 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4547 | good for anything but further calls to bpstat_num). | |
4548 | ||
8671a17b PA |
4549 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4550 | Return -1 if stopped at a breakpoint that has been deleted since | |
4551 | we set it. | |
4552 | Return 1 otherwise. */ | |
c906108c SS |
4553 | |
4554 | int | |
8671a17b | 4555 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4556 | { |
4557 | struct breakpoint *b; | |
4558 | ||
4559 | if ((*bsp) == NULL) | |
4560 | return 0; /* No more breakpoint values */ | |
8671a17b | 4561 | |
4a64f543 MS |
4562 | /* We assume we'll never have several bpstats that correspond to a |
4563 | single breakpoint -- otherwise, this function might return the | |
4564 | same number more than once and this will look ugly. */ | |
f431efe5 | 4565 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4566 | *bsp = (*bsp)->next; |
4567 | if (b == NULL) | |
4568 | return -1; /* breakpoint that's been deleted since */ | |
4569 | ||
4570 | *num = b->number; /* We have its number */ | |
4571 | return 1; | |
c906108c SS |
4572 | } |
4573 | ||
e93ca019 | 4574 | /* See breakpoint.h. */ |
c906108c SS |
4575 | |
4576 | void | |
e93ca019 | 4577 | bpstat_clear_actions (void) |
c906108c | 4578 | { |
e93ca019 JK |
4579 | struct thread_info *tp; |
4580 | bpstat bs; | |
4581 | ||
4582 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4583 | return; | |
4584 | ||
4585 | tp = find_thread_ptid (inferior_ptid); | |
4586 | if (tp == NULL) | |
4587 | return; | |
4588 | ||
4589 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4590 | { |
9add0f1b | 4591 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4592 | |
c906108c SS |
4593 | if (bs->old_val != NULL) |
4594 | { | |
4595 | value_free (bs->old_val); | |
4596 | bs->old_val = NULL; | |
4597 | } | |
4598 | } | |
4599 | } | |
4600 | ||
f3b1572e PA |
4601 | /* Called when a command is about to proceed the inferior. */ |
4602 | ||
4603 | static void | |
4604 | breakpoint_about_to_proceed (void) | |
4605 | { | |
4606 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4607 | { | |
4608 | struct thread_info *tp = inferior_thread (); | |
4609 | ||
4610 | /* Allow inferior function calls in breakpoint commands to not | |
4611 | interrupt the command list. When the call finishes | |
4612 | successfully, the inferior will be standing at the same | |
4613 | breakpoint as if nothing happened. */ | |
16c381f0 | 4614 | if (tp->control.in_infcall) |
f3b1572e PA |
4615 | return; |
4616 | } | |
4617 | ||
4618 | breakpoint_proceeded = 1; | |
4619 | } | |
4620 | ||
4a64f543 MS |
4621 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4622 | command. */ | |
c906108c | 4623 | static void |
4efb68b1 | 4624 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4625 | { |
4626 | executing_breakpoint_commands = 0; | |
4627 | } | |
4628 | ||
abf85f46 JK |
4629 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4630 | or its equivalent. */ | |
4631 | ||
4632 | static int | |
4633 | command_line_is_silent (struct command_line *cmd) | |
4634 | { | |
4635 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
4636 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
4637 | } | |
4638 | ||
4a64f543 MS |
4639 | /* Execute all the commands associated with all the breakpoints at |
4640 | this location. Any of these commands could cause the process to | |
4641 | proceed beyond this point, etc. We look out for such changes by | |
4642 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4643 | |
347bddb7 PA |
4644 | Returns true if a breakpoint command resumed the inferior. In that |
4645 | case, it is the caller's responsibility to recall it again with the | |
4646 | bpstat of the current thread. */ | |
4647 | ||
4648 | static int | |
4649 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4650 | { |
4651 | bpstat bs; | |
4652 | struct cleanup *old_chain; | |
347bddb7 | 4653 | int again = 0; |
c906108c SS |
4654 | |
4655 | /* Avoid endless recursion if a `source' command is contained | |
4656 | in bs->commands. */ | |
4657 | if (executing_breakpoint_commands) | |
347bddb7 | 4658 | return 0; |
c906108c SS |
4659 | |
4660 | executing_breakpoint_commands = 1; | |
4661 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4662 | ||
cf6c5ffb TT |
4663 | prevent_dont_repeat (); |
4664 | ||
4a64f543 | 4665 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4666 | bs = *bsp; |
4667 | ||
4668 | breakpoint_proceeded = 0; | |
4669 | for (; bs != NULL; bs = bs->next) | |
4670 | { | |
9add0f1b | 4671 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4672 | struct command_line *cmd; |
4673 | struct cleanup *this_cmd_tree_chain; | |
4674 | ||
4675 | /* Take ownership of the BSP's command tree, if it has one. | |
4676 | ||
4677 | The command tree could legitimately contain commands like | |
4678 | 'step' and 'next', which call clear_proceed_status, which | |
4679 | frees stop_bpstat's command tree. To make sure this doesn't | |
4680 | free the tree we're executing out from under us, we need to | |
4681 | take ownership of the tree ourselves. Since a given bpstat's | |
4682 | commands are only executed once, we don't need to copy it; we | |
4683 | can clear the pointer in the bpstat, and make sure we free | |
4684 | the tree when we're done. */ | |
9add0f1b TT |
4685 | ccmd = bs->commands; |
4686 | bs->commands = NULL; | |
abf85f46 JK |
4687 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4688 | cmd = ccmd ? ccmd->commands : NULL; | |
4689 | if (command_line_is_silent (cmd)) | |
4690 | { | |
4691 | /* The action has been already done by bpstat_stop_status. */ | |
4692 | cmd = cmd->next; | |
4693 | } | |
6c50ab1c | 4694 | |
c906108c SS |
4695 | while (cmd != NULL) |
4696 | { | |
4697 | execute_control_command (cmd); | |
4698 | ||
4699 | if (breakpoint_proceeded) | |
4700 | break; | |
4701 | else | |
4702 | cmd = cmd->next; | |
4703 | } | |
6c50ab1c JB |
4704 | |
4705 | /* We can free this command tree now. */ | |
4706 | do_cleanups (this_cmd_tree_chain); | |
4707 | ||
c906108c | 4708 | if (breakpoint_proceeded) |
32c1e744 VP |
4709 | { |
4710 | if (target_can_async_p ()) | |
347bddb7 PA |
4711 | /* If we are in async mode, then the target might be still |
4712 | running, not stopped at any breakpoint, so nothing for | |
4713 | us to do here -- just return to the event loop. */ | |
4714 | ; | |
32c1e744 VP |
4715 | else |
4716 | /* In sync mode, when execute_control_command returns | |
4717 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4718 | Breakpoint commands for that stop were not run, since |
4719 | execute_command does not run breakpoint commands -- | |
4720 | only command_line_handler does, but that one is not | |
4721 | involved in execution of breakpoint commands. So, we | |
4722 | can now execute breakpoint commands. It should be | |
4723 | noted that making execute_command do bpstat actions is | |
4724 | not an option -- in this case we'll have recursive | |
4725 | invocation of bpstat for each breakpoint with a | |
4726 | command, and can easily blow up GDB stack. Instead, we | |
4727 | return true, which will trigger the caller to recall us | |
4728 | with the new stop_bpstat. */ | |
4729 | again = 1; | |
4730 | break; | |
32c1e744 | 4731 | } |
c906108c | 4732 | } |
c2b8ed2c | 4733 | do_cleanups (old_chain); |
347bddb7 PA |
4734 | return again; |
4735 | } | |
4736 | ||
4737 | void | |
4738 | bpstat_do_actions (void) | |
4739 | { | |
353d1d73 JK |
4740 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4741 | ||
347bddb7 PA |
4742 | /* Do any commands attached to breakpoint we are stopped at. */ |
4743 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4744 | && target_has_execution | |
4745 | && !is_exited (inferior_ptid) | |
4746 | && !is_executing (inferior_ptid)) | |
4747 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4748 | and only return when it is stopped at the next breakpoint, we | |
4749 | keep doing breakpoint actions until it returns false to | |
4750 | indicate the inferior was not resumed. */ | |
16c381f0 | 4751 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4752 | break; |
353d1d73 JK |
4753 | |
4754 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4755 | } |
4756 | ||
fa4727a6 DJ |
4757 | /* Print out the (old or new) value associated with a watchpoint. */ |
4758 | ||
4759 | static void | |
4760 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4761 | { | |
4762 | if (val == NULL) | |
4763 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4764 | else | |
79a45b7d TT |
4765 | { |
4766 | struct value_print_options opts; | |
4767 | get_user_print_options (&opts); | |
4768 | value_print (val, stream, &opts); | |
4769 | } | |
fa4727a6 DJ |
4770 | } |
4771 | ||
e514a9d6 | 4772 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4773 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4774 | 'print_it' in the bpstat structure. Under some circumstances we |
4775 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4776 | normal_stop(). */ |
e514a9d6 JM |
4777 | |
4778 | static enum print_stop_action | |
4779 | print_bp_stop_message (bpstat bs) | |
4780 | { | |
4781 | switch (bs->print_it) | |
4782 | { | |
4783 | case print_it_noop: | |
4a64f543 | 4784 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4785 | return PRINT_UNKNOWN; |
4786 | break; | |
4787 | ||
4788 | case print_it_done: | |
4789 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4790 | relevant messages. */ |
e514a9d6 JM |
4791 | return PRINT_SRC_AND_LOC; |
4792 | break; | |
4793 | ||
4794 | case print_it_normal: | |
4f8d1dc6 | 4795 | { |
f431efe5 PA |
4796 | struct breakpoint *b = bs->breakpoint_at; |
4797 | ||
1a6a67de TJB |
4798 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4799 | which has since been deleted. */ | |
4800 | if (b == NULL) | |
4801 | return PRINT_UNKNOWN; | |
4802 | ||
348d480f PA |
4803 | /* Normal case. Call the breakpoint's print_it method. */ |
4804 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4805 | } |
348d480f | 4806 | break; |
3086aeae | 4807 | |
e514a9d6 | 4808 | default: |
8e65ff28 | 4809 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4810 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4811 | break; |
c906108c | 4812 | } |
c906108c SS |
4813 | } |
4814 | ||
edcc5120 TT |
4815 | /* A helper function that prints a shared library stopped event. */ |
4816 | ||
4817 | static void | |
4818 | print_solib_event (int is_catchpoint) | |
4819 | { | |
4820 | int any_deleted | |
4821 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4822 | int any_added | |
4823 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4824 | ||
4825 | if (!is_catchpoint) | |
4826 | { | |
4827 | if (any_added || any_deleted) | |
4828 | ui_out_text (current_uiout, | |
4829 | _("Stopped due to shared library event:\n")); | |
4830 | else | |
4831 | ui_out_text (current_uiout, | |
4832 | _("Stopped due to shared library event (no " | |
4833 | "libraries added or removed)\n")); | |
4834 | } | |
4835 | ||
4836 | if (ui_out_is_mi_like_p (current_uiout)) | |
4837 | ui_out_field_string (current_uiout, "reason", | |
4838 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4839 | ||
4840 | if (any_deleted) | |
4841 | { | |
4842 | struct cleanup *cleanup; | |
4843 | char *name; | |
4844 | int ix; | |
4845 | ||
4846 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4847 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4848 | "removed"); | |
4849 | for (ix = 0; | |
4850 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4851 | ix, name); | |
4852 | ++ix) | |
4853 | { | |
4854 | if (ix > 0) | |
4855 | ui_out_text (current_uiout, " "); | |
4856 | ui_out_field_string (current_uiout, "library", name); | |
4857 | ui_out_text (current_uiout, "\n"); | |
4858 | } | |
4859 | ||
4860 | do_cleanups (cleanup); | |
4861 | } | |
4862 | ||
4863 | if (any_added) | |
4864 | { | |
4865 | struct so_list *iter; | |
4866 | int ix; | |
4867 | struct cleanup *cleanup; | |
4868 | ||
4869 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4870 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4871 | "added"); | |
4872 | for (ix = 0; | |
4873 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4874 | ix, iter); | |
4875 | ++ix) | |
4876 | { | |
4877 | if (ix > 0) | |
4878 | ui_out_text (current_uiout, " "); | |
4879 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4880 | ui_out_text (current_uiout, "\n"); | |
4881 | } | |
4882 | ||
4883 | do_cleanups (cleanup); | |
4884 | } | |
4885 | } | |
4886 | ||
e514a9d6 JM |
4887 | /* Print a message indicating what happened. This is called from |
4888 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4889 | list - a list of the eventpoints that caused this stop. KIND is |
4890 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4891 | routine calls the generic print routine for printing a message |
4892 | about reasons for stopping. This will print (for example) the | |
4893 | "Breakpoint n," part of the output. The return value of this | |
4894 | routine is one of: | |
c906108c | 4895 | |
4a64f543 | 4896 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4897 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4898 | code to print the location. An example is |
c5aa993b JM |
4899 | "Breakpoint 1, " which should be followed by |
4900 | the location. | |
917317f4 | 4901 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4902 | to also print the location part of the message. |
4903 | An example is the catch/throw messages, which | |
4a64f543 | 4904 | don't require a location appended to the end. |
917317f4 | 4905 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4906 | further info to be printed. */ |
c906108c | 4907 | |
917317f4 | 4908 | enum print_stop_action |
36dfb11c | 4909 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4910 | { |
4911 | int val; | |
c5aa993b | 4912 | |
c906108c | 4913 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4914 | (Currently all watchpoints go on the bpstat whether hit or not. |
4915 | That probably could (should) be changed, provided care is taken | |
c906108c | 4916 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4917 | for (; bs; bs = bs->next) |
4918 | { | |
4919 | val = print_bp_stop_message (bs); | |
4920 | if (val == PRINT_SRC_ONLY | |
4921 | || val == PRINT_SRC_AND_LOC | |
4922 | || val == PRINT_NOTHING) | |
4923 | return val; | |
4924 | } | |
c906108c | 4925 | |
36dfb11c TT |
4926 | /* If we had hit a shared library event breakpoint, |
4927 | print_bp_stop_message would print out this message. If we hit an | |
4928 | OS-level shared library event, do the same thing. */ | |
4929 | if (kind == TARGET_WAITKIND_LOADED) | |
4930 | { | |
edcc5120 | 4931 | print_solib_event (0); |
36dfb11c TT |
4932 | return PRINT_NOTHING; |
4933 | } | |
4934 | ||
e514a9d6 | 4935 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4936 | with and nothing was printed. */ |
917317f4 | 4937 | return PRINT_UNKNOWN; |
c906108c SS |
4938 | } |
4939 | ||
c42bd95a DE |
4940 | /* Evaluate the expression EXP and return 1 if value is zero. |
4941 | This returns the inverse of the condition because it is called | |
4942 | from catch_errors which returns 0 if an exception happened, and if an | |
4943 | exception happens we want execution to stop. | |
4a64f543 | 4944 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4945 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4946 | |
4947 | static int | |
4efb68b1 | 4948 | breakpoint_cond_eval (void *exp) |
c906108c | 4949 | { |
278cd55f | 4950 | struct value *mark = value_mark (); |
c5aa993b | 4951 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4952 | |
c906108c SS |
4953 | value_free_to_mark (mark); |
4954 | return i; | |
4955 | } | |
4956 | ||
5760d0ab | 4957 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4958 | |
4959 | static bpstat | |
5760d0ab | 4960 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4961 | { |
4962 | bpstat bs; | |
4963 | ||
4964 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4965 | bs->next = NULL; |
4966 | **bs_link_pointer = bs; | |
4967 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4968 | bs->breakpoint_at = bl->owner; |
4969 | bs->bp_location_at = bl; | |
4970 | incref_bp_location (bl); | |
c906108c SS |
4971 | /* If the condition is false, etc., don't do the commands. */ |
4972 | bs->commands = NULL; | |
4973 | bs->old_val = NULL; | |
4974 | bs->print_it = print_it_normal; | |
4975 | return bs; | |
4976 | } | |
4977 | \f | |
d983da9c DJ |
4978 | /* The target has stopped with waitstatus WS. Check if any hardware |
4979 | watchpoints have triggered, according to the target. */ | |
4980 | ||
4981 | int | |
4982 | watchpoints_triggered (struct target_waitstatus *ws) | |
4983 | { | |
d92524f1 | 4984 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4985 | CORE_ADDR addr; |
4986 | struct breakpoint *b; | |
4987 | ||
4988 | if (!stopped_by_watchpoint) | |
4989 | { | |
4990 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4991 | as not triggered. */ | |
4992 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4993 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4994 | { |
4995 | struct watchpoint *w = (struct watchpoint *) b; | |
4996 | ||
4997 | w->watchpoint_triggered = watch_triggered_no; | |
4998 | } | |
d983da9c DJ |
4999 | |
5000 | return 0; | |
5001 | } | |
5002 | ||
5003 | if (!target_stopped_data_address (¤t_target, &addr)) | |
5004 | { | |
5005 | /* We were stopped by a watchpoint, but we don't know where. | |
5006 | Mark all watchpoints as unknown. */ | |
5007 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5008 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5009 | { |
5010 | struct watchpoint *w = (struct watchpoint *) b; | |
5011 | ||
5012 | w->watchpoint_triggered = watch_triggered_unknown; | |
5013 | } | |
d983da9c | 5014 | |
3c4797ba | 5015 | return 1; |
d983da9c DJ |
5016 | } |
5017 | ||
5018 | /* The target could report the data address. Mark watchpoints | |
5019 | affected by this data address as triggered, and all others as not | |
5020 | triggered. */ | |
5021 | ||
5022 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5023 | if (is_hardware_watchpoint (b)) |
d983da9c | 5024 | { |
3a5c3e22 | 5025 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 5026 | struct bp_location *loc; |
d983da9c | 5027 | |
3a5c3e22 | 5028 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 5029 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 5030 | { |
3a5c3e22 | 5031 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 5032 | { |
3a5c3e22 PA |
5033 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
5034 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
5035 | |
5036 | if (newaddr == start) | |
5037 | { | |
3a5c3e22 | 5038 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5039 | break; |
5040 | } | |
5041 | } | |
5042 | /* Exact match not required. Within range is sufficient. */ | |
5043 | else if (target_watchpoint_addr_within_range (¤t_target, | |
5044 | addr, loc->address, | |
5045 | loc->length)) | |
5046 | { | |
3a5c3e22 | 5047 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5048 | break; |
5049 | } | |
5050 | } | |
d983da9c DJ |
5051 | } |
5052 | ||
5053 | return 1; | |
5054 | } | |
5055 | ||
c906108c SS |
5056 | /* Possible return values for watchpoint_check (this can't be an enum |
5057 | because of check_errors). */ | |
5058 | /* The watchpoint has been deleted. */ | |
5059 | #define WP_DELETED 1 | |
5060 | /* The value has changed. */ | |
5061 | #define WP_VALUE_CHANGED 2 | |
5062 | /* The value has not changed. */ | |
5063 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5064 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5065 | #define WP_IGNORE 4 | |
c906108c SS |
5066 | |
5067 | #define BP_TEMPFLAG 1 | |
5068 | #define BP_HARDWAREFLAG 2 | |
5069 | ||
4a64f543 MS |
5070 | /* Evaluate watchpoint condition expression and check if its value |
5071 | changed. | |
553e4c11 JB |
5072 | |
5073 | P should be a pointer to struct bpstat, but is defined as a void * | |
5074 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5075 | |
5076 | static int | |
4efb68b1 | 5077 | watchpoint_check (void *p) |
c906108c SS |
5078 | { |
5079 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5080 | struct watchpoint *b; |
c906108c SS |
5081 | struct frame_info *fr; |
5082 | int within_current_scope; | |
5083 | ||
f431efe5 | 5084 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5085 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5086 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5087 | |
f6bc2008 PA |
5088 | /* If this is a local watchpoint, we only want to check if the |
5089 | watchpoint frame is in scope if the current thread is the thread | |
5090 | that was used to create the watchpoint. */ | |
5091 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5092 | return WP_IGNORE; |
f6bc2008 | 5093 | |
c906108c SS |
5094 | if (b->exp_valid_block == NULL) |
5095 | within_current_scope = 1; | |
5096 | else | |
5097 | { | |
edb3359d DJ |
5098 | struct frame_info *frame = get_current_frame (); |
5099 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5100 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5101 | ||
4a64f543 MS |
5102 | /* in_function_epilogue_p() returns a non-zero value if we're |
5103 | still in the function but the stack frame has already been | |
5104 | invalidated. Since we can't rely on the values of local | |
5105 | variables after the stack has been destroyed, we are treating | |
5106 | the watchpoint in that state as `not changed' without further | |
5107 | checking. Don't mark watchpoints as changed if the current | |
5108 | frame is in an epilogue - even if they are in some other | |
5109 | frame, our view of the stack is likely to be wrong and | |
5110 | frame_find_by_id could error out. */ | |
a0f49112 | 5111 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 5112 | return WP_IGNORE; |
a0f49112 | 5113 | |
101dcfbe | 5114 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5115 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5116 | |
5117 | /* If we've gotten confused in the unwinder, we might have | |
5118 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5119 | if (within_current_scope) |
5120 | { | |
5121 | struct symbol *function; | |
5122 | ||
5123 | function = get_frame_function (fr); | |
5124 | if (function == NULL | |
5125 | || !contained_in (b->exp_valid_block, | |
5126 | SYMBOL_BLOCK_VALUE (function))) | |
5127 | within_current_scope = 0; | |
5128 | } | |
69fbadd5 | 5129 | |
edb3359d | 5130 | if (within_current_scope) |
c906108c SS |
5131 | /* If we end up stopping, the current frame will get selected |
5132 | in normal_stop. So this call to select_frame won't affect | |
5133 | the user. */ | |
0f7d239c | 5134 | select_frame (fr); |
c906108c | 5135 | } |
c5aa993b | 5136 | |
c906108c SS |
5137 | if (within_current_scope) |
5138 | { | |
4a64f543 MS |
5139 | /* We use value_{,free_to_}mark because it could be a *long* |
5140 | time before we return to the command level and call | |
5141 | free_all_values. We can't call free_all_values because we | |
5142 | might be in the middle of evaluating a function call. */ | |
c906108c | 5143 | |
0cf6dd15 | 5144 | int pc = 0; |
9c06b0b4 | 5145 | struct value *mark; |
fa4727a6 DJ |
5146 | struct value *new_val; |
5147 | ||
3a5c3e22 | 5148 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5149 | /* Since we don't know the exact trigger address (from |
5150 | stopped_data_address), just tell the user we've triggered | |
5151 | a mask watchpoint. */ | |
5152 | return WP_VALUE_CHANGED; | |
5153 | ||
5154 | mark = value_mark (); | |
3a1115a0 | 5155 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5156 | |
bb9d5f81 PP |
5157 | if (b->val_bitsize != 0) |
5158 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5159 | ||
4a64f543 MS |
5160 | /* We use value_equal_contents instead of value_equal because |
5161 | the latter coerces an array to a pointer, thus comparing just | |
5162 | the address of the array instead of its contents. This is | |
5163 | not what we want. */ | |
fa4727a6 | 5164 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5165 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5166 | { |
fa4727a6 DJ |
5167 | if (new_val != NULL) |
5168 | { | |
5169 | release_value (new_val); | |
5170 | value_free_to_mark (mark); | |
5171 | } | |
c906108c SS |
5172 | bs->old_val = b->val; |
5173 | b->val = new_val; | |
fa4727a6 | 5174 | b->val_valid = 1; |
c906108c SS |
5175 | return WP_VALUE_CHANGED; |
5176 | } | |
5177 | else | |
5178 | { | |
60e1c644 | 5179 | /* Nothing changed. */ |
c906108c | 5180 | value_free_to_mark (mark); |
c906108c SS |
5181 | return WP_VALUE_NOT_CHANGED; |
5182 | } | |
5183 | } | |
5184 | else | |
5185 | { | |
79a45e25 PA |
5186 | struct ui_out *uiout = current_uiout; |
5187 | ||
c906108c | 5188 | /* This seems like the only logical thing to do because |
c5aa993b JM |
5189 | if we temporarily ignored the watchpoint, then when |
5190 | we reenter the block in which it is valid it contains | |
5191 | garbage (in the case of a function, it may have two | |
5192 | garbage values, one before and one after the prologue). | |
5193 | So we can't even detect the first assignment to it and | |
5194 | watch after that (since the garbage may or may not equal | |
5195 | the first value assigned). */ | |
348d480f PA |
5196 | /* We print all the stop information in |
5197 | breakpoint_ops->print_it, but in this case, by the time we | |
5198 | call breakpoint_ops->print_it this bp will be deleted | |
5199 | already. So we have no choice but print the information | |
5200 | here. */ | |
9dc5e2a9 | 5201 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
5202 | ui_out_field_string |
5203 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 5204 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 5205 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
5206 | ui_out_text (uiout, |
5207 | " deleted because the program has left the block in\n\ | |
8b93c638 | 5208 | which its expression is valid.\n"); |
4ce44c66 | 5209 | |
cdac0397 | 5210 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5211 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5212 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5213 | |
5214 | return WP_DELETED; | |
5215 | } | |
5216 | } | |
5217 | ||
18a18393 | 5218 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5219 | breakpoint location BL. This function does not check if we should |
5220 | stop, only if BL explains the stop. */ | |
5221 | ||
18a18393 | 5222 | static int |
6c95b8df | 5223 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5224 | struct address_space *aspace, CORE_ADDR bp_addr, |
5225 | const struct target_waitstatus *ws) | |
18a18393 VP |
5226 | { |
5227 | struct breakpoint *b = bl->owner; | |
5228 | ||
348d480f | 5229 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5230 | gdb_assert (b != NULL); |
5231 | ||
09ac7c10 | 5232 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5233 | } |
5234 | ||
3a5c3e22 PA |
5235 | /* Determine if the watched values have actually changed, and we |
5236 | should stop. If not, set BS->stop to 0. */ | |
5237 | ||
18a18393 VP |
5238 | static void |
5239 | bpstat_check_watchpoint (bpstat bs) | |
5240 | { | |
2bdf28a0 | 5241 | const struct bp_location *bl; |
3a5c3e22 | 5242 | struct watchpoint *b; |
2bdf28a0 JK |
5243 | |
5244 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5245 | bl = bs->bp_location_at; |
2bdf28a0 | 5246 | gdb_assert (bl != NULL); |
3a5c3e22 | 5247 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5248 | gdb_assert (b != NULL); |
18a18393 | 5249 | |
18a18393 | 5250 | { |
18a18393 VP |
5251 | int must_check_value = 0; |
5252 | ||
3a5c3e22 | 5253 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5254 | /* For a software watchpoint, we must always check the |
5255 | watched value. */ | |
5256 | must_check_value = 1; | |
5257 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5258 | /* We have a hardware watchpoint (read, write, or access) | |
5259 | and the target earlier reported an address watched by | |
5260 | this watchpoint. */ | |
5261 | must_check_value = 1; | |
5262 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5263 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5264 | /* We were stopped by a hardware watchpoint, but the target could |
5265 | not report the data address. We must check the watchpoint's | |
5266 | value. Access and read watchpoints are out of luck; without | |
5267 | a data address, we can't figure it out. */ | |
5268 | must_check_value = 1; | |
3a5c3e22 | 5269 | |
18a18393 VP |
5270 | if (must_check_value) |
5271 | { | |
3e43a32a MS |
5272 | char *message |
5273 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5274 | b->base.number); |
18a18393 VP |
5275 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5276 | int e = catch_errors (watchpoint_check, bs, message, | |
5277 | RETURN_MASK_ALL); | |
5278 | do_cleanups (cleanups); | |
5279 | switch (e) | |
5280 | { | |
5281 | case WP_DELETED: | |
5282 | /* We've already printed what needs to be printed. */ | |
5283 | bs->print_it = print_it_done; | |
5284 | /* Stop. */ | |
5285 | break; | |
60e1c644 PA |
5286 | case WP_IGNORE: |
5287 | bs->print_it = print_it_noop; | |
5288 | bs->stop = 0; | |
5289 | break; | |
18a18393 | 5290 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5291 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5292 | { |
85d721b8 PA |
5293 | /* There are two cases to consider here: |
5294 | ||
4a64f543 | 5295 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5296 | In that case, trust the target, and always report |
5297 | the watchpoint hit to the user. Even though | |
5298 | reads don't cause value changes, the value may | |
5299 | have changed since the last time it was read, and | |
5300 | since we're not trapping writes, we will not see | |
5301 | those, and as such we should ignore our notion of | |
5302 | old value. | |
5303 | ||
4a64f543 | 5304 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5305 | reads and writes. There are two ways this may |
5306 | happen: | |
5307 | ||
4a64f543 | 5308 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5309 | reads only, but can break on accesses (reads or |
5310 | writes), such as e.g., x86. We detect this case | |
5311 | at the time we try to insert read watchpoints. | |
5312 | ||
4a64f543 | 5313 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5314 | watchpoints, but, the user set an access or write |
5315 | watchpoint watching the same memory as this read | |
5316 | watchpoint. | |
5317 | ||
5318 | If we're watching memory writes as well as reads, | |
5319 | ignore watchpoint hits when we find that the | |
5320 | value hasn't changed, as reads don't cause | |
5321 | changes. This still gives false positives when | |
5322 | the program writes the same value to memory as | |
5323 | what there was already in memory (we will confuse | |
5324 | it for a read), but it's much better than | |
5325 | nothing. */ | |
5326 | ||
5327 | int other_write_watchpoint = 0; | |
5328 | ||
5329 | if (bl->watchpoint_type == hw_read) | |
5330 | { | |
5331 | struct breakpoint *other_b; | |
5332 | ||
5333 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5334 | if (other_b->type == bp_hardware_watchpoint |
5335 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5336 | { |
3a5c3e22 PA |
5337 | struct watchpoint *other_w = |
5338 | (struct watchpoint *) other_b; | |
5339 | ||
5340 | if (other_w->watchpoint_triggered | |
5341 | == watch_triggered_yes) | |
5342 | { | |
5343 | other_write_watchpoint = 1; | |
5344 | break; | |
5345 | } | |
85d721b8 PA |
5346 | } |
5347 | } | |
5348 | ||
5349 | if (other_write_watchpoint | |
5350 | || bl->watchpoint_type == hw_access) | |
5351 | { | |
5352 | /* We're watching the same memory for writes, | |
5353 | and the value changed since the last time we | |
5354 | updated it, so this trap must be for a write. | |
5355 | Ignore it. */ | |
5356 | bs->print_it = print_it_noop; | |
5357 | bs->stop = 0; | |
5358 | } | |
18a18393 VP |
5359 | } |
5360 | break; | |
5361 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5362 | if (b->base.type == bp_hardware_watchpoint |
5363 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5364 | { |
5365 | /* Don't stop: write watchpoints shouldn't fire if | |
5366 | the value hasn't changed. */ | |
5367 | bs->print_it = print_it_noop; | |
5368 | bs->stop = 0; | |
5369 | } | |
5370 | /* Stop. */ | |
5371 | break; | |
5372 | default: | |
5373 | /* Can't happen. */ | |
5374 | case 0: | |
5375 | /* Error from catch_errors. */ | |
3a5c3e22 | 5376 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5377 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5378 | /* We've already printed what needs to be printed. */ |
5379 | bs->print_it = print_it_done; | |
5380 | break; | |
5381 | } | |
5382 | } | |
5383 | else /* must_check_value == 0 */ | |
5384 | { | |
5385 | /* This is a case where some watchpoint(s) triggered, but | |
5386 | not at the address of this watchpoint, or else no | |
5387 | watchpoint triggered after all. So don't print | |
5388 | anything for this watchpoint. */ | |
5389 | bs->print_it = print_it_noop; | |
5390 | bs->stop = 0; | |
5391 | } | |
5392 | } | |
5393 | } | |
5394 | ||
7d4df6a4 DE |
5395 | /* For breakpoints that are currently marked as telling gdb to stop, |
5396 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5397 | of breakpoint referred to by BS. If we should not stop for this |
5398 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5399 | |
18a18393 VP |
5400 | static void |
5401 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5402 | { | |
2bdf28a0 JK |
5403 | const struct bp_location *bl; |
5404 | struct breakpoint *b; | |
7d4df6a4 DE |
5405 | int value_is_zero = 0; |
5406 | struct expression *cond; | |
5407 | ||
5408 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5409 | |
5410 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5411 | bl = bs->bp_location_at; |
2bdf28a0 | 5412 | gdb_assert (bl != NULL); |
f431efe5 | 5413 | b = bs->breakpoint_at; |
2bdf28a0 | 5414 | gdb_assert (b != NULL); |
18a18393 | 5415 | |
b775012e LM |
5416 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5417 | need to do so again since GDB does not know if we stopped due to a | |
5418 | breakpoint or a single step breakpoint. */ | |
5419 | ||
18a18393 | 5420 | if (frame_id_p (b->frame_id) |
edb3359d | 5421 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5422 | { |
7d4df6a4 DE |
5423 | bs->stop = 0; |
5424 | return; | |
5425 | } | |
60e1c644 | 5426 | |
12ab52e9 PA |
5427 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5428 | evaluating the condition if this isn't the specified | |
5429 | thread/task. */ | |
5430 | if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid)) | |
5431 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) | |
5432 | ||
6c1b0f7b DE |
5433 | { |
5434 | bs->stop = 0; | |
5435 | return; | |
5436 | } | |
5437 | ||
6dddc817 DE |
5438 | /* Evaluate extension language breakpoints that have a "stop" method |
5439 | implemented. */ | |
5440 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5441 | |
7d4df6a4 DE |
5442 | if (is_watchpoint (b)) |
5443 | { | |
5444 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5445 | |
7d4df6a4 DE |
5446 | cond = w->cond_exp; |
5447 | } | |
5448 | else | |
5449 | cond = bl->cond; | |
60e1c644 | 5450 | |
7d4df6a4 DE |
5451 | if (cond && b->disposition != disp_del_at_next_stop) |
5452 | { | |
5453 | int within_current_scope = 1; | |
5454 | struct watchpoint * w; | |
60e1c644 | 5455 | |
7d4df6a4 DE |
5456 | /* We use value_mark and value_free_to_mark because it could |
5457 | be a long time before we return to the command level and | |
5458 | call free_all_values. We can't call free_all_values | |
5459 | because we might be in the middle of evaluating a | |
5460 | function call. */ | |
5461 | struct value *mark = value_mark (); | |
5462 | ||
5463 | if (is_watchpoint (b)) | |
5464 | w = (struct watchpoint *) b; | |
5465 | else | |
5466 | w = NULL; | |
5467 | ||
5468 | /* Need to select the frame, with all that implies so that | |
5469 | the conditions will have the right context. Because we | |
5470 | use the frame, we will not see an inlined function's | |
5471 | variables when we arrive at a breakpoint at the start | |
5472 | of the inlined function; the current frame will be the | |
5473 | call site. */ | |
5474 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5475 | select_frame (get_current_frame ()); | |
5476 | else | |
18a18393 | 5477 | { |
7d4df6a4 DE |
5478 | struct frame_info *frame; |
5479 | ||
5480 | /* For local watchpoint expressions, which particular | |
5481 | instance of a local is being watched matters, so we | |
5482 | keep track of the frame to evaluate the expression | |
5483 | in. To evaluate the condition however, it doesn't | |
5484 | really matter which instantiation of the function | |
5485 | where the condition makes sense triggers the | |
5486 | watchpoint. This allows an expression like "watch | |
5487 | global if q > 10" set in `func', catch writes to | |
5488 | global on all threads that call `func', or catch | |
5489 | writes on all recursive calls of `func' by a single | |
5490 | thread. We simply always evaluate the condition in | |
5491 | the innermost frame that's executing where it makes | |
5492 | sense to evaluate the condition. It seems | |
5493 | intuitive. */ | |
5494 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5495 | if (frame != NULL) | |
5496 | select_frame (frame); | |
5497 | else | |
5498 | within_current_scope = 0; | |
18a18393 | 5499 | } |
7d4df6a4 DE |
5500 | if (within_current_scope) |
5501 | value_is_zero | |
5502 | = catch_errors (breakpoint_cond_eval, cond, | |
5503 | "Error in testing breakpoint condition:\n", | |
5504 | RETURN_MASK_ALL); | |
5505 | else | |
18a18393 | 5506 | { |
7d4df6a4 DE |
5507 | warning (_("Watchpoint condition cannot be tested " |
5508 | "in the current scope")); | |
5509 | /* If we failed to set the right context for this | |
5510 | watchpoint, unconditionally report it. */ | |
5511 | value_is_zero = 0; | |
18a18393 | 5512 | } |
7d4df6a4 DE |
5513 | /* FIXME-someday, should give breakpoint #. */ |
5514 | value_free_to_mark (mark); | |
18a18393 | 5515 | } |
7d4df6a4 DE |
5516 | |
5517 | if (cond && value_is_zero) | |
5518 | { | |
5519 | bs->stop = 0; | |
5520 | } | |
7d4df6a4 DE |
5521 | else if (b->ignore_count > 0) |
5522 | { | |
5523 | b->ignore_count--; | |
5524 | bs->stop = 0; | |
5525 | /* Increase the hit count even though we don't stop. */ | |
5526 | ++(b->hit_count); | |
5527 | observer_notify_breakpoint_modified (b); | |
5528 | } | |
18a18393 VP |
5529 | } |
5530 | ||
5531 | ||
9709f61c | 5532 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5533 | BP_ADDR in thread PTID. |
c906108c | 5534 | |
d983da9c | 5535 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5536 | don't understand this stop. Result is a chain of bpstat's such |
5537 | that: | |
c906108c | 5538 | |
c5aa993b | 5539 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5540 | |
c5aa993b | 5541 | if we understand why we stopped, the result is not null. |
c906108c | 5542 | |
c5aa993b JM |
5543 | Each element of the chain refers to a particular breakpoint or |
5544 | watchpoint at which we have stopped. (We may have stopped for | |
5545 | several reasons concurrently.) | |
c906108c | 5546 | |
c5aa993b JM |
5547 | Each element of the chain has valid next, breakpoint_at, |
5548 | commands, FIXME??? fields. */ | |
c906108c SS |
5549 | |
5550 | bpstat | |
6c95b8df | 5551 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5552 | CORE_ADDR bp_addr, ptid_t ptid, |
5553 | const struct target_waitstatus *ws) | |
c906108c | 5554 | { |
0d381245 | 5555 | struct breakpoint *b = NULL; |
afe38095 | 5556 | struct bp_location *bl; |
20874c92 | 5557 | struct bp_location *loc; |
5760d0ab JK |
5558 | /* First item of allocated bpstat's. */ |
5559 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5560 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5561 | bpstat bs; |
20874c92 | 5562 | int ix; |
429374b8 | 5563 | int need_remove_insert; |
f431efe5 | 5564 | int removed_any; |
c906108c | 5565 | |
f431efe5 PA |
5566 | /* First, build the bpstat chain with locations that explain a |
5567 | target stop, while being careful to not set the target running, | |
5568 | as that may invalidate locations (in particular watchpoint | |
5569 | locations are recreated). Resuming will happen here with | |
5570 | breakpoint conditions or watchpoint expressions that include | |
5571 | inferior function calls. */ | |
c5aa993b | 5572 | |
429374b8 JK |
5573 | ALL_BREAKPOINTS (b) |
5574 | { | |
5575 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
5576 | continue; | |
a5606eee | 5577 | |
429374b8 JK |
5578 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5579 | { | |
4a64f543 MS |
5580 | /* For hardware watchpoints, we look only at the first |
5581 | location. The watchpoint_check function will work on the | |
5582 | entire expression, not the individual locations. For | |
5583 | read watchpoints, the watchpoints_triggered function has | |
5584 | checked all locations already. */ | |
429374b8 JK |
5585 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5586 | break; | |
18a18393 | 5587 | |
f6592439 | 5588 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5589 | continue; |
c5aa993b | 5590 | |
09ac7c10 | 5591 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5592 | continue; |
c5aa993b | 5593 | |
4a64f543 MS |
5594 | /* Come here if it's a watchpoint, or if the break address |
5595 | matches. */ | |
c5aa993b | 5596 | |
4a64f543 MS |
5597 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5598 | explain stop. */ | |
c5aa993b | 5599 | |
f431efe5 PA |
5600 | /* Assume we stop. Should we find a watchpoint that is not |
5601 | actually triggered, or if the condition of the breakpoint | |
5602 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5603 | bs->stop = 1; |
5604 | bs->print = 1; | |
d983da9c | 5605 | |
f431efe5 PA |
5606 | /* If this is a scope breakpoint, mark the associated |
5607 | watchpoint as triggered so that we will handle the | |
5608 | out-of-scope event. We'll get to the watchpoint next | |
5609 | iteration. */ | |
d0fb5eae | 5610 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5611 | { |
5612 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5613 | ||
5614 | w->watchpoint_triggered = watch_triggered_yes; | |
5615 | } | |
f431efe5 PA |
5616 | } |
5617 | } | |
5618 | ||
5619 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
5620 | { | |
f1310107 | 5621 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 5622 | { |
5760d0ab | 5623 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
5624 | /* For hits of moribund locations, we should just proceed. */ |
5625 | bs->stop = 0; | |
5626 | bs->print = 0; | |
5627 | bs->print_it = print_it_noop; | |
5628 | } | |
5629 | } | |
5630 | ||
edcc5120 TT |
5631 | /* A bit of special processing for shlib breakpoints. We need to |
5632 | process solib loading here, so that the lists of loaded and | |
5633 | unloaded libraries are correct before we handle "catch load" and | |
5634 | "catch unload". */ | |
5635 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5636 | { | |
5d268276 | 5637 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5638 | { |
5639 | handle_solib_event (); | |
5640 | break; | |
5641 | } | |
5642 | } | |
5643 | ||
f431efe5 PA |
5644 | /* Now go through the locations that caused the target to stop, and |
5645 | check whether we're interested in reporting this stop to higher | |
5646 | layers, or whether we should resume the target transparently. */ | |
5647 | ||
5648 | removed_any = 0; | |
5649 | ||
5760d0ab | 5650 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5651 | { |
5652 | if (!bs->stop) | |
5653 | continue; | |
5654 | ||
f431efe5 | 5655 | b = bs->breakpoint_at; |
348d480f PA |
5656 | b->ops->check_status (bs); |
5657 | if (bs->stop) | |
28010a5d | 5658 | { |
348d480f | 5659 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5660 | |
429374b8 JK |
5661 | if (bs->stop) |
5662 | { | |
5663 | ++(b->hit_count); | |
8d3788bd | 5664 | observer_notify_breakpoint_modified (b); |
c906108c | 5665 | |
4a64f543 | 5666 | /* We will stop here. */ |
429374b8 JK |
5667 | if (b->disposition == disp_disable) |
5668 | { | |
816338b5 SS |
5669 | --(b->enable_count); |
5670 | if (b->enable_count <= 0 | |
5671 | && b->enable_state != bp_permanent) | |
429374b8 | 5672 | b->enable_state = bp_disabled; |
f431efe5 | 5673 | removed_any = 1; |
429374b8 JK |
5674 | } |
5675 | if (b->silent) | |
5676 | bs->print = 0; | |
5677 | bs->commands = b->commands; | |
9add0f1b | 5678 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5679 | if (command_line_is_silent (bs->commands |
5680 | ? bs->commands->commands : NULL)) | |
5681 | bs->print = 0; | |
9d6e6e84 HZ |
5682 | |
5683 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5684 | } |
5685 | ||
348d480f | 5686 | } |
a9b3a50f PA |
5687 | |
5688 | /* Print nothing for this entry if we don't stop or don't | |
5689 | print. */ | |
5690 | if (!bs->stop || !bs->print) | |
5691 | bs->print_it = print_it_noop; | |
429374b8 | 5692 | } |
876fa593 | 5693 | |
d983da9c DJ |
5694 | /* If we aren't stopping, the value of some hardware watchpoint may |
5695 | not have changed, but the intermediate memory locations we are | |
5696 | watching may have. Don't bother if we're stopping; this will get | |
5697 | done later. */ | |
d832cb68 | 5698 | need_remove_insert = 0; |
5760d0ab JK |
5699 | if (! bpstat_causes_stop (bs_head)) |
5700 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5701 | if (!bs->stop |
f431efe5 PA |
5702 | && bs->breakpoint_at |
5703 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5704 | { |
3a5c3e22 PA |
5705 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5706 | ||
5707 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5708 | need_remove_insert = 1; |
d983da9c DJ |
5709 | } |
5710 | ||
d832cb68 | 5711 | if (need_remove_insert) |
44702360 | 5712 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5713 | else if (removed_any) |
44702360 | 5714 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5715 | |
5760d0ab | 5716 | return bs_head; |
c906108c | 5717 | } |
628fe4e4 JK |
5718 | |
5719 | static void | |
5720 | handle_jit_event (void) | |
5721 | { | |
5722 | struct frame_info *frame; | |
5723 | struct gdbarch *gdbarch; | |
5724 | ||
5725 | /* Switch terminal for any messages produced by | |
5726 | breakpoint_re_set. */ | |
5727 | target_terminal_ours_for_output (); | |
5728 | ||
5729 | frame = get_current_frame (); | |
5730 | gdbarch = get_frame_arch (frame); | |
5731 | ||
5732 | jit_event_handler (gdbarch); | |
5733 | ||
5734 | target_terminal_inferior (); | |
5735 | } | |
5736 | ||
5737 | /* Prepare WHAT final decision for infrun. */ | |
5738 | ||
5739 | /* Decide what infrun needs to do with this bpstat. */ | |
5740 | ||
c906108c | 5741 | struct bpstat_what |
0e30163f | 5742 | bpstat_what (bpstat bs_head) |
c906108c | 5743 | { |
c906108c | 5744 | struct bpstat_what retval; |
628fe4e4 | 5745 | int jit_event = 0; |
0e30163f | 5746 | bpstat bs; |
c906108c | 5747 | |
628fe4e4 | 5748 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5749 | retval.call_dummy = STOP_NONE; |
186c406b | 5750 | retval.is_longjmp = 0; |
628fe4e4 | 5751 | |
0e30163f | 5752 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5753 | { |
628fe4e4 JK |
5754 | /* Extract this BS's action. After processing each BS, we check |
5755 | if its action overrides all we've seem so far. */ | |
5756 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5757 | enum bptype bptype; | |
5758 | ||
c906108c | 5759 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5760 | { |
5761 | /* I suspect this can happen if it was a momentary | |
5762 | breakpoint which has since been deleted. */ | |
5763 | bptype = bp_none; | |
5764 | } | |
20874c92 | 5765 | else |
f431efe5 | 5766 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5767 | |
5768 | switch (bptype) | |
c906108c SS |
5769 | { |
5770 | case bp_none: | |
628fe4e4 | 5771 | break; |
c906108c SS |
5772 | case bp_breakpoint: |
5773 | case bp_hardware_breakpoint: | |
5774 | case bp_until: | |
5775 | case bp_finish: | |
a9b3a50f | 5776 | case bp_shlib_event: |
c906108c SS |
5777 | if (bs->stop) |
5778 | { | |
5779 | if (bs->print) | |
628fe4e4 | 5780 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5781 | else |
628fe4e4 | 5782 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5783 | } |
5784 | else | |
628fe4e4 | 5785 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5786 | break; |
5787 | case bp_watchpoint: | |
5788 | case bp_hardware_watchpoint: | |
5789 | case bp_read_watchpoint: | |
5790 | case bp_access_watchpoint: | |
5791 | if (bs->stop) | |
5792 | { | |
5793 | if (bs->print) | |
628fe4e4 | 5794 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5795 | else |
628fe4e4 | 5796 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5797 | } |
5798 | else | |
628fe4e4 JK |
5799 | { |
5800 | /* There was a watchpoint, but we're not stopping. | |
5801 | This requires no further action. */ | |
5802 | } | |
c906108c SS |
5803 | break; |
5804 | case bp_longjmp: | |
e2e4d78b | 5805 | case bp_longjmp_call_dummy: |
186c406b | 5806 | case bp_exception: |
628fe4e4 | 5807 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
e2e4d78b | 5808 | retval.is_longjmp = bptype != bp_exception; |
c906108c SS |
5809 | break; |
5810 | case bp_longjmp_resume: | |
186c406b | 5811 | case bp_exception_resume: |
628fe4e4 | 5812 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 5813 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
5814 | break; |
5815 | case bp_step_resume: | |
5816 | if (bs->stop) | |
628fe4e4 JK |
5817 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5818 | else | |
c906108c | 5819 | { |
628fe4e4 JK |
5820 | /* It is for the wrong frame. */ |
5821 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5822 | } |
c906108c | 5823 | break; |
2c03e5be PA |
5824 | case bp_hp_step_resume: |
5825 | if (bs->stop) | |
5826 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5827 | else | |
5828 | { | |
5829 | /* It is for the wrong frame. */ | |
5830 | this_action = BPSTAT_WHAT_SINGLE; | |
5831 | } | |
5832 | break; | |
c906108c | 5833 | case bp_watchpoint_scope: |
c4093a6a | 5834 | case bp_thread_event: |
1900040c | 5835 | case bp_overlay_event: |
0fd8e87f | 5836 | case bp_longjmp_master: |
aa7d318d | 5837 | case bp_std_terminate_master: |
186c406b | 5838 | case bp_exception_master: |
628fe4e4 | 5839 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5840 | break; |
ce78b96d | 5841 | case bp_catchpoint: |
c5aa993b JM |
5842 | if (bs->stop) |
5843 | { | |
5844 | if (bs->print) | |
628fe4e4 | 5845 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5846 | else |
628fe4e4 | 5847 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5848 | } |
5849 | else | |
628fe4e4 JK |
5850 | { |
5851 | /* There was a catchpoint, but we're not stopping. | |
5852 | This requires no further action. */ | |
5853 | } | |
5854 | break; | |
628fe4e4 JK |
5855 | case bp_jit_event: |
5856 | jit_event = 1; | |
5857 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5858 | break; |
c906108c | 5859 | case bp_call_dummy: |
53a5351d JM |
5860 | /* Make sure the action is stop (silent or noisy), |
5861 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5862 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5863 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5864 | break; |
5865 | case bp_std_terminate: | |
5866 | /* Make sure the action is stop (silent or noisy), | |
5867 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5868 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5869 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5870 | break; |
1042e4c0 | 5871 | case bp_tracepoint: |
7a697b8d | 5872 | case bp_fast_tracepoint: |
0fb4aa4b | 5873 | case bp_static_tracepoint: |
1042e4c0 SS |
5874 | /* Tracepoint hits should not be reported back to GDB, and |
5875 | if one got through somehow, it should have been filtered | |
5876 | out already. */ | |
5877 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5878 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5879 | break; |
5880 | case bp_gnu_ifunc_resolver: | |
5881 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5882 | this_action = BPSTAT_WHAT_SINGLE; | |
5883 | break; | |
5884 | case bp_gnu_ifunc_resolver_return: | |
5885 | /* The breakpoint will be removed, execution will restart from the | |
5886 | PC of the former breakpoint. */ | |
5887 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5888 | break; | |
e7e0cddf SS |
5889 | |
5890 | case bp_dprintf: | |
a11cfd87 HZ |
5891 | if (bs->stop) |
5892 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5893 | else | |
5894 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5895 | break; |
5896 | ||
628fe4e4 JK |
5897 | default: |
5898 | internal_error (__FILE__, __LINE__, | |
5899 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5900 | } |
628fe4e4 JK |
5901 | |
5902 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5903 | } |
628fe4e4 | 5904 | |
0e30163f JK |
5905 | /* These operations may affect the bs->breakpoint_at state so they are |
5906 | delayed after MAIN_ACTION is decided above. */ | |
5907 | ||
628fe4e4 JK |
5908 | if (jit_event) |
5909 | { | |
5910 | if (debug_infrun) | |
5911 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5912 | ||
5913 | handle_jit_event (); | |
5914 | } | |
5915 | ||
0e30163f JK |
5916 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5917 | { | |
5918 | struct breakpoint *b = bs->breakpoint_at; | |
5919 | ||
5920 | if (b == NULL) | |
5921 | continue; | |
5922 | switch (b->type) | |
5923 | { | |
5924 | case bp_gnu_ifunc_resolver: | |
5925 | gnu_ifunc_resolver_stop (b); | |
5926 | break; | |
5927 | case bp_gnu_ifunc_resolver_return: | |
5928 | gnu_ifunc_resolver_return_stop (b); | |
5929 | break; | |
5930 | } | |
5931 | } | |
5932 | ||
c906108c SS |
5933 | return retval; |
5934 | } | |
5935 | ||
5936 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5937 | without hardware support). This isn't related to a specific bpstat, | |
5938 | just to things like whether watchpoints are set. */ | |
5939 | ||
c5aa993b | 5940 | int |
fba45db2 | 5941 | bpstat_should_step (void) |
c906108c SS |
5942 | { |
5943 | struct breakpoint *b; | |
cc59ec59 | 5944 | |
c906108c | 5945 | ALL_BREAKPOINTS (b) |
717a8278 | 5946 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5947 | return 1; |
c906108c SS |
5948 | return 0; |
5949 | } | |
5950 | ||
67822962 PA |
5951 | int |
5952 | bpstat_causes_stop (bpstat bs) | |
5953 | { | |
5954 | for (; bs != NULL; bs = bs->next) | |
5955 | if (bs->stop) | |
5956 | return 1; | |
5957 | ||
5958 | return 0; | |
5959 | } | |
5960 | ||
c906108c | 5961 | \f |
c5aa993b | 5962 | |
170b53b2 UW |
5963 | /* Compute a string of spaces suitable to indent the next line |
5964 | so it starts at the position corresponding to the table column | |
5965 | named COL_NAME in the currently active table of UIOUT. */ | |
5966 | ||
5967 | static char * | |
5968 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5969 | { | |
5970 | static char wrap_indent[80]; | |
5971 | int i, total_width, width, align; | |
5972 | char *text; | |
5973 | ||
5974 | total_width = 0; | |
5975 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5976 | { | |
5977 | if (strcmp (text, col_name) == 0) | |
5978 | { | |
5979 | gdb_assert (total_width < sizeof wrap_indent); | |
5980 | memset (wrap_indent, ' ', total_width); | |
5981 | wrap_indent[total_width] = 0; | |
5982 | ||
5983 | return wrap_indent; | |
5984 | } | |
5985 | ||
5986 | total_width += width + 1; | |
5987 | } | |
5988 | ||
5989 | return NULL; | |
5990 | } | |
5991 | ||
b775012e LM |
5992 | /* Determine if the locations of this breakpoint will have their conditions |
5993 | evaluated by the target, host or a mix of both. Returns the following: | |
5994 | ||
5995 | "host": Host evals condition. | |
5996 | "host or target": Host or Target evals condition. | |
5997 | "target": Target evals condition. | |
5998 | */ | |
5999 | ||
6000 | static const char * | |
6001 | bp_condition_evaluator (struct breakpoint *b) | |
6002 | { | |
6003 | struct bp_location *bl; | |
6004 | char host_evals = 0; | |
6005 | char target_evals = 0; | |
6006 | ||
6007 | if (!b) | |
6008 | return NULL; | |
6009 | ||
6010 | if (!is_breakpoint (b)) | |
6011 | return NULL; | |
6012 | ||
6013 | if (gdb_evaluates_breakpoint_condition_p () | |
6014 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6015 | return condition_evaluation_host; | |
6016 | ||
6017 | for (bl = b->loc; bl; bl = bl->next) | |
6018 | { | |
6019 | if (bl->cond_bytecode) | |
6020 | target_evals++; | |
6021 | else | |
6022 | host_evals++; | |
6023 | } | |
6024 | ||
6025 | if (host_evals && target_evals) | |
6026 | return condition_evaluation_both; | |
6027 | else if (target_evals) | |
6028 | return condition_evaluation_target; | |
6029 | else | |
6030 | return condition_evaluation_host; | |
6031 | } | |
6032 | ||
6033 | /* Determine the breakpoint location's condition evaluator. This is | |
6034 | similar to bp_condition_evaluator, but for locations. */ | |
6035 | ||
6036 | static const char * | |
6037 | bp_location_condition_evaluator (struct bp_location *bl) | |
6038 | { | |
6039 | if (bl && !is_breakpoint (bl->owner)) | |
6040 | return NULL; | |
6041 | ||
6042 | if (gdb_evaluates_breakpoint_condition_p () | |
6043 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6044 | return condition_evaluation_host; | |
6045 | ||
6046 | if (bl && bl->cond_bytecode) | |
6047 | return condition_evaluation_target; | |
6048 | else | |
6049 | return condition_evaluation_host; | |
6050 | } | |
6051 | ||
859825b8 JK |
6052 | /* Print the LOC location out of the list of B->LOC locations. */ |
6053 | ||
170b53b2 UW |
6054 | static void |
6055 | print_breakpoint_location (struct breakpoint *b, | |
6056 | struct bp_location *loc) | |
0d381245 | 6057 | { |
79a45e25 | 6058 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
6059 | struct cleanup *old_chain = save_current_program_space (); |
6060 | ||
859825b8 JK |
6061 | if (loc != NULL && loc->shlib_disabled) |
6062 | loc = NULL; | |
6063 | ||
6c95b8df PA |
6064 | if (loc != NULL) |
6065 | set_current_program_space (loc->pspace); | |
6066 | ||
56435ebe TT |
6067 | if (b->display_canonical) |
6068 | ui_out_field_string (uiout, "what", b->addr_string); | |
2f202fde | 6069 | else if (loc && loc->symtab) |
0d381245 VP |
6070 | { |
6071 | struct symbol *sym | |
6072 | = find_pc_sect_function (loc->address, loc->section); | |
6073 | if (sym) | |
6074 | { | |
6075 | ui_out_text (uiout, "in "); | |
6076 | ui_out_field_string (uiout, "func", | |
6077 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
6078 | ui_out_text (uiout, " "); |
6079 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
6080 | ui_out_text (uiout, "at "); | |
0d381245 | 6081 | } |
05cba821 JK |
6082 | ui_out_field_string (uiout, "file", |
6083 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 6084 | ui_out_text (uiout, ":"); |
05cba821 | 6085 | |
0d381245 | 6086 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
6087 | ui_out_field_string (uiout, "fullname", |
6088 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 6089 | |
f8eba3c6 | 6090 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 6091 | } |
859825b8 | 6092 | else if (loc) |
0d381245 | 6093 | { |
f99d8bf4 PA |
6094 | struct ui_file *stb = mem_fileopen (); |
6095 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 6096 | |
f99d8bf4 | 6097 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 6098 | demangle, ""); |
0d381245 | 6099 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
6100 | |
6101 | do_cleanups (stb_chain); | |
0d381245 | 6102 | } |
859825b8 JK |
6103 | else |
6104 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 6105 | |
b775012e LM |
6106 | if (loc && is_breakpoint (b) |
6107 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6108 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6109 | { | |
6110 | ui_out_text (uiout, " ("); | |
6111 | ui_out_field_string (uiout, "evaluated-by", | |
6112 | bp_location_condition_evaluator (loc)); | |
6113 | ui_out_text (uiout, ")"); | |
6114 | } | |
6115 | ||
6c95b8df | 6116 | do_cleanups (old_chain); |
0d381245 VP |
6117 | } |
6118 | ||
269b11a2 PA |
6119 | static const char * |
6120 | bptype_string (enum bptype type) | |
c906108c | 6121 | { |
c4093a6a JM |
6122 | struct ep_type_description |
6123 | { | |
6124 | enum bptype type; | |
6125 | char *description; | |
6126 | }; | |
6127 | static struct ep_type_description bptypes[] = | |
c906108c | 6128 | { |
c5aa993b JM |
6129 | {bp_none, "?deleted?"}, |
6130 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6131 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
6132 | {bp_until, "until"}, |
6133 | {bp_finish, "finish"}, | |
6134 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6135 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6136 | {bp_read_watchpoint, "read watchpoint"}, |
6137 | {bp_access_watchpoint, "acc watchpoint"}, | |
6138 | {bp_longjmp, "longjmp"}, | |
6139 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6140 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6141 | {bp_exception, "exception"}, |
6142 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6143 | {bp_step_resume, "step resume"}, |
2c03e5be | 6144 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6145 | {bp_watchpoint_scope, "watchpoint scope"}, |
6146 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6147 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6148 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6149 | {bp_thread_event, "thread events"}, |
1900040c | 6150 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6151 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6152 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6153 | {bp_exception_master, "exception master"}, |
ce78b96d | 6154 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6155 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6156 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6157 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6158 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6159 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6160 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6161 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6162 | }; |
269b11a2 PA |
6163 | |
6164 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6165 | || ((int) type != bptypes[(int) type].type)) | |
6166 | internal_error (__FILE__, __LINE__, | |
6167 | _("bptypes table does not describe type #%d."), | |
6168 | (int) type); | |
6169 | ||
6170 | return bptypes[(int) type].description; | |
6171 | } | |
6172 | ||
998580f1 MK |
6173 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6174 | For CLI, prefix the list with the string 'inf'. */ | |
6175 | ||
6176 | static void | |
6177 | output_thread_groups (struct ui_out *uiout, | |
6178 | const char *field_name, | |
6179 | VEC(int) *inf_num, | |
6180 | int mi_only) | |
6181 | { | |
752eb8b4 | 6182 | struct cleanup *back_to; |
998580f1 MK |
6183 | int is_mi = ui_out_is_mi_like_p (uiout); |
6184 | int inf; | |
6185 | int i; | |
6186 | ||
6187 | /* For backward compatibility, don't display inferiors in CLI unless | |
6188 | there are several. Always display them for MI. */ | |
6189 | if (!is_mi && mi_only) | |
6190 | return; | |
6191 | ||
752eb8b4 TT |
6192 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6193 | ||
998580f1 MK |
6194 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6195 | { | |
6196 | if (is_mi) | |
6197 | { | |
6198 | char mi_group[10]; | |
6199 | ||
6200 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6201 | ui_out_field_string (uiout, NULL, mi_group); | |
6202 | } | |
6203 | else | |
6204 | { | |
6205 | if (i == 0) | |
6206 | ui_out_text (uiout, " inf "); | |
6207 | else | |
6208 | ui_out_text (uiout, ", "); | |
6209 | ||
6210 | ui_out_text (uiout, plongest (inf)); | |
6211 | } | |
6212 | } | |
6213 | ||
6214 | do_cleanups (back_to); | |
6215 | } | |
6216 | ||
269b11a2 PA |
6217 | /* Print B to gdb_stdout. */ |
6218 | ||
6219 | static void | |
6220 | print_one_breakpoint_location (struct breakpoint *b, | |
6221 | struct bp_location *loc, | |
6222 | int loc_number, | |
6223 | struct bp_location **last_loc, | |
269b11a2 PA |
6224 | int allflag) |
6225 | { | |
6226 | struct command_line *l; | |
c2c6d25f | 6227 | static char bpenables[] = "nynny"; |
c906108c | 6228 | |
79a45e25 | 6229 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6230 | int header_of_multiple = 0; |
6231 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6232 | struct value_print_options opts; |
6233 | ||
6234 | get_user_print_options (&opts); | |
0d381245 VP |
6235 | |
6236 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6237 | /* See comment in print_one_breakpoint concerning treatment of |
6238 | breakpoints with single disabled location. */ | |
0d381245 VP |
6239 | if (loc == NULL |
6240 | && (b->loc != NULL | |
6241 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6242 | header_of_multiple = 1; | |
6243 | if (loc == NULL) | |
6244 | loc = b->loc; | |
6245 | ||
c4093a6a JM |
6246 | annotate_record (); |
6247 | ||
6248 | /* 1 */ | |
6249 | annotate_field (0); | |
0d381245 VP |
6250 | if (part_of_multiple) |
6251 | { | |
6252 | char *formatted; | |
0c6773c1 | 6253 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6254 | ui_out_field_string (uiout, "number", formatted); |
6255 | xfree (formatted); | |
6256 | } | |
6257 | else | |
6258 | { | |
6259 | ui_out_field_int (uiout, "number", b->number); | |
6260 | } | |
c4093a6a JM |
6261 | |
6262 | /* 2 */ | |
6263 | annotate_field (1); | |
0d381245 VP |
6264 | if (part_of_multiple) |
6265 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6266 | else |
6267 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6268 | |
6269 | /* 3 */ | |
6270 | annotate_field (2); | |
0d381245 VP |
6271 | if (part_of_multiple) |
6272 | ui_out_field_skip (uiout, "disp"); | |
6273 | else | |
2cec12e5 | 6274 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6275 | |
c4093a6a JM |
6276 | |
6277 | /* 4 */ | |
6278 | annotate_field (3); | |
0d381245 | 6279 | if (part_of_multiple) |
54e52265 | 6280 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6281 | else |
4a64f543 MS |
6282 | ui_out_field_fmt (uiout, "enabled", "%c", |
6283 | bpenables[(int) b->enable_state]); | |
54e52265 | 6284 | ui_out_spaces (uiout, 2); |
0d381245 | 6285 | |
c4093a6a JM |
6286 | |
6287 | /* 5 and 6 */ | |
3086aeae | 6288 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6289 | { |
4a64f543 MS |
6290 | /* Although the print_one can possibly print all locations, |
6291 | calling it here is not likely to get any nice result. So, | |
6292 | make sure there's just one location. */ | |
0d381245 | 6293 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6294 | b->ops->print_one (b, last_loc); |
0d381245 | 6295 | } |
3086aeae DJ |
6296 | else |
6297 | switch (b->type) | |
6298 | { | |
6299 | case bp_none: | |
6300 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6301 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6302 | break; |
c906108c | 6303 | |
3086aeae DJ |
6304 | case bp_watchpoint: |
6305 | case bp_hardware_watchpoint: | |
6306 | case bp_read_watchpoint: | |
6307 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6308 | { |
6309 | struct watchpoint *w = (struct watchpoint *) b; | |
6310 | ||
6311 | /* Field 4, the address, is omitted (which makes the columns | |
6312 | not line up too nicely with the headers, but the effect | |
6313 | is relatively readable). */ | |
6314 | if (opts.addressprint) | |
6315 | ui_out_field_skip (uiout, "addr"); | |
6316 | annotate_field (5); | |
6317 | ui_out_field_string (uiout, "what", w->exp_string); | |
6318 | } | |
3086aeae DJ |
6319 | break; |
6320 | ||
3086aeae DJ |
6321 | case bp_breakpoint: |
6322 | case bp_hardware_breakpoint: | |
6323 | case bp_until: | |
6324 | case bp_finish: | |
6325 | case bp_longjmp: | |
6326 | case bp_longjmp_resume: | |
e2e4d78b | 6327 | case bp_longjmp_call_dummy: |
186c406b TT |
6328 | case bp_exception: |
6329 | case bp_exception_resume: | |
3086aeae | 6330 | case bp_step_resume: |
2c03e5be | 6331 | case bp_hp_step_resume: |
3086aeae DJ |
6332 | case bp_watchpoint_scope: |
6333 | case bp_call_dummy: | |
aa7d318d | 6334 | case bp_std_terminate: |
3086aeae DJ |
6335 | case bp_shlib_event: |
6336 | case bp_thread_event: | |
6337 | case bp_overlay_event: | |
0fd8e87f | 6338 | case bp_longjmp_master: |
aa7d318d | 6339 | case bp_std_terminate_master: |
186c406b | 6340 | case bp_exception_master: |
1042e4c0 | 6341 | case bp_tracepoint: |
7a697b8d | 6342 | case bp_fast_tracepoint: |
0fb4aa4b | 6343 | case bp_static_tracepoint: |
e7e0cddf | 6344 | case bp_dprintf: |
4efc6507 | 6345 | case bp_jit_event: |
0e30163f JK |
6346 | case bp_gnu_ifunc_resolver: |
6347 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6348 | if (opts.addressprint) |
3086aeae DJ |
6349 | { |
6350 | annotate_field (4); | |
54e52265 | 6351 | if (header_of_multiple) |
0d381245 | 6352 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6353 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6354 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6355 | else |
5af949e3 UW |
6356 | ui_out_field_core_addr (uiout, "addr", |
6357 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6358 | } |
6359 | annotate_field (5); | |
0d381245 | 6360 | if (!header_of_multiple) |
170b53b2 | 6361 | print_breakpoint_location (b, loc); |
0d381245 | 6362 | if (b->loc) |
a6d9a66e | 6363 | *last_loc = b->loc; |
3086aeae DJ |
6364 | break; |
6365 | } | |
c906108c | 6366 | |
6c95b8df | 6367 | |
998580f1 | 6368 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6369 | { |
6370 | struct inferior *inf; | |
998580f1 MK |
6371 | VEC(int) *inf_num = NULL; |
6372 | int mi_only = 1; | |
6c95b8df | 6373 | |
998580f1 | 6374 | ALL_INFERIORS (inf) |
6c95b8df PA |
6375 | { |
6376 | if (inf->pspace == loc->pspace) | |
998580f1 | 6377 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6378 | } |
998580f1 MK |
6379 | |
6380 | /* For backward compatibility, don't display inferiors in CLI unless | |
6381 | there are several. Always display for MI. */ | |
6382 | if (allflag | |
6383 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6384 | && (number_of_program_spaces () > 1 | |
6385 | || number_of_inferiors () > 1) | |
6386 | /* LOC is for existing B, it cannot be in | |
6387 | moribund_locations and thus having NULL OWNER. */ | |
6388 | && loc->owner->type != bp_catchpoint)) | |
6389 | mi_only = 0; | |
6390 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6391 | VEC_free (int, inf_num); | |
6c95b8df PA |
6392 | } |
6393 | ||
4a306c9a | 6394 | if (!part_of_multiple) |
c4093a6a | 6395 | { |
4a306c9a JB |
6396 | if (b->thread != -1) |
6397 | { | |
6398 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6399 | "stop only in" line a little further down. */ |
4a306c9a JB |
6400 | ui_out_text (uiout, " thread "); |
6401 | ui_out_field_int (uiout, "thread", b->thread); | |
6402 | } | |
6403 | else if (b->task != 0) | |
6404 | { | |
6405 | ui_out_text (uiout, " task "); | |
6406 | ui_out_field_int (uiout, "task", b->task); | |
6407 | } | |
c4093a6a | 6408 | } |
f1310107 | 6409 | |
8b93c638 | 6410 | ui_out_text (uiout, "\n"); |
f1310107 | 6411 | |
348d480f | 6412 | if (!part_of_multiple) |
f1310107 TJB |
6413 | b->ops->print_one_detail (b, uiout); |
6414 | ||
0d381245 | 6415 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6416 | { |
6417 | annotate_field (6); | |
8b93c638 | 6418 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6419 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6420 | the frame ID. */ |
5af949e3 UW |
6421 | ui_out_field_core_addr (uiout, "frame", |
6422 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6423 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6424 | } |
6425 | ||
28010a5d | 6426 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6427 | { |
6428 | annotate_field (7); | |
d77f58be | 6429 | if (is_tracepoint (b)) |
1042e4c0 SS |
6430 | ui_out_text (uiout, "\ttrace only if "); |
6431 | else | |
6432 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6433 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6434 | |
6435 | /* Print whether the target is doing the breakpoint's condition | |
6436 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6437 | if (is_breakpoint (b) | |
6438 | && breakpoint_condition_evaluation_mode () | |
6439 | == condition_evaluation_target) | |
6440 | { | |
6441 | ui_out_text (uiout, " ("); | |
6442 | ui_out_field_string (uiout, "evaluated-by", | |
6443 | bp_condition_evaluator (b)); | |
6444 | ui_out_text (uiout, " evals)"); | |
6445 | } | |
0101ce28 JJ |
6446 | ui_out_text (uiout, "\n"); |
6447 | } | |
6448 | ||
0d381245 | 6449 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6450 | { |
4a64f543 | 6451 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6452 | ui_out_text (uiout, "\tstop only in thread "); |
6453 | ui_out_field_int (uiout, "thread", b->thread); | |
6454 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6455 | } |
6456 | ||
556ec64d YQ |
6457 | if (!part_of_multiple) |
6458 | { | |
6459 | if (b->hit_count) | |
31f56a27 YQ |
6460 | { |
6461 | /* FIXME should make an annotation for this. */ | |
6462 | if (is_catchpoint (b)) | |
6463 | ui_out_text (uiout, "\tcatchpoint"); | |
6464 | else if (is_tracepoint (b)) | |
6465 | ui_out_text (uiout, "\ttracepoint"); | |
6466 | else | |
6467 | ui_out_text (uiout, "\tbreakpoint"); | |
6468 | ui_out_text (uiout, " already hit "); | |
6469 | ui_out_field_int (uiout, "times", b->hit_count); | |
6470 | if (b->hit_count == 1) | |
6471 | ui_out_text (uiout, " time\n"); | |
6472 | else | |
6473 | ui_out_text (uiout, " times\n"); | |
6474 | } | |
556ec64d YQ |
6475 | else |
6476 | { | |
31f56a27 YQ |
6477 | /* Output the count also if it is zero, but only if this is mi. */ |
6478 | if (ui_out_is_mi_like_p (uiout)) | |
6479 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6480 | } |
6481 | } | |
8b93c638 | 6482 | |
0d381245 | 6483 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6484 | { |
6485 | annotate_field (8); | |
8b93c638 JM |
6486 | ui_out_text (uiout, "\tignore next "); |
6487 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6488 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6489 | } |
059fb39f | 6490 | |
816338b5 SS |
6491 | /* Note that an enable count of 1 corresponds to "enable once" |
6492 | behavior, which is reported by the combination of enablement and | |
6493 | disposition, so we don't need to mention it here. */ | |
6494 | if (!part_of_multiple && b->enable_count > 1) | |
6495 | { | |
6496 | annotate_field (8); | |
6497 | ui_out_text (uiout, "\tdisable after "); | |
6498 | /* Tweak the wording to clarify that ignore and enable counts | |
6499 | are distinct, and have additive effect. */ | |
6500 | if (b->ignore_count) | |
6501 | ui_out_text (uiout, "additional "); | |
6502 | else | |
6503 | ui_out_text (uiout, "next "); | |
6504 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6505 | ui_out_text (uiout, " hits\n"); | |
6506 | } | |
6507 | ||
f196051f SS |
6508 | if (!part_of_multiple && is_tracepoint (b)) |
6509 | { | |
6510 | struct tracepoint *tp = (struct tracepoint *) b; | |
6511 | ||
6512 | if (tp->traceframe_usage) | |
6513 | { | |
6514 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6515 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6516 | ui_out_text (uiout, " bytes\n"); | |
6517 | } | |
6518 | } | |
d3ce09f5 | 6519 | |
9add0f1b | 6520 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6521 | if (!part_of_multiple && l) |
c4093a6a | 6522 | { |
3b31d625 EZ |
6523 | struct cleanup *script_chain; |
6524 | ||
c4093a6a | 6525 | annotate_field (9); |
3b31d625 | 6526 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6527 | print_command_lines (uiout, l, 4); |
3b31d625 | 6528 | do_cleanups (script_chain); |
c4093a6a | 6529 | } |
d24317b4 | 6530 | |
d9b3f62e | 6531 | if (is_tracepoint (b)) |
1042e4c0 | 6532 | { |
d9b3f62e PA |
6533 | struct tracepoint *t = (struct tracepoint *) b; |
6534 | ||
6535 | if (!part_of_multiple && t->pass_count) | |
6536 | { | |
6537 | annotate_field (10); | |
6538 | ui_out_text (uiout, "\tpass count "); | |
6539 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6540 | ui_out_text (uiout, " \n"); | |
6541 | } | |
f2a8bc8a YQ |
6542 | |
6543 | /* Don't display it when tracepoint or tracepoint location is | |
6544 | pending. */ | |
6545 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6546 | { | |
6547 | annotate_field (11); | |
6548 | ||
6549 | if (ui_out_is_mi_like_p (uiout)) | |
6550 | ui_out_field_string (uiout, "installed", | |
6551 | loc->inserted ? "y" : "n"); | |
6552 | else | |
6553 | { | |
6554 | if (loc->inserted) | |
6555 | ui_out_text (uiout, "\t"); | |
6556 | else | |
6557 | ui_out_text (uiout, "\tnot "); | |
6558 | ui_out_text (uiout, "installed on target\n"); | |
6559 | } | |
6560 | } | |
1042e4c0 SS |
6561 | } |
6562 | ||
d24317b4 VP |
6563 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6564 | { | |
3a5c3e22 PA |
6565 | if (is_watchpoint (b)) |
6566 | { | |
6567 | struct watchpoint *w = (struct watchpoint *) b; | |
6568 | ||
6569 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6570 | } | |
6571 | else if (b->addr_string) | |
d24317b4 | 6572 | ui_out_field_string (uiout, "original-location", b->addr_string); |
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 VP |
6951 | ? " (disabled)" |
6952 | : b->enable_state == bp_permanent | |
6953 | ? " (permanent)" | |
6954 | : ""), | |
6955 | (others > 1) ? "," | |
6956 | : ((others == 1) ? " and" : "")); | |
6957 | } | |
a3f17187 | 6958 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6959 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6960 | printf_filtered (".\n"); |
6961 | } | |
6962 | } | |
6963 | \f | |
c906108c | 6964 | |
e4f237da KB |
6965 | /* Return true iff it is meaningful to use the address member of |
6966 | BPT. For some breakpoint types, the address member is irrelevant | |
6967 | and it makes no sense to attempt to compare it to other addresses | |
6968 | (or use it for any other purpose either). | |
6969 | ||
4a64f543 MS |
6970 | More specifically, each of the following breakpoint types will |
6971 | always have a zero valued address and we don't want to mark | |
6972 | breakpoints of any of these types to be a duplicate of an actual | |
6973 | breakpoint at address zero: | |
e4f237da KB |
6974 | |
6975 | bp_watchpoint | |
2d134ed3 PA |
6976 | bp_catchpoint |
6977 | ||
6978 | */ | |
e4f237da KB |
6979 | |
6980 | static int | |
6981 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6982 | { | |
6983 | enum bptype type = bpt->type; | |
6984 | ||
2d134ed3 PA |
6985 | return (type != bp_watchpoint && type != bp_catchpoint); |
6986 | } | |
6987 | ||
6988 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6989 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6990 | ||
6991 | static int | |
4a64f543 MS |
6992 | watchpoint_locations_match (struct bp_location *loc1, |
6993 | struct bp_location *loc2) | |
2d134ed3 | 6994 | { |
3a5c3e22 PA |
6995 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6996 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6997 | ||
6998 | /* Both of them must exist. */ | |
6999 | gdb_assert (w1 != NULL); | |
7000 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 7001 | |
4a64f543 MS |
7002 | /* If the target can evaluate the condition expression in hardware, |
7003 | then we we need to insert both watchpoints even if they are at | |
7004 | the same place. Otherwise the watchpoint will only trigger when | |
7005 | the condition of whichever watchpoint was inserted evaluates to | |
7006 | true, not giving a chance for GDB to check the condition of the | |
7007 | other watchpoint. */ | |
3a5c3e22 | 7008 | if ((w1->cond_exp |
4a64f543 MS |
7009 | && target_can_accel_watchpoint_condition (loc1->address, |
7010 | loc1->length, | |
0cf6dd15 | 7011 | loc1->watchpoint_type, |
3a5c3e22 PA |
7012 | w1->cond_exp)) |
7013 | || (w2->cond_exp | |
4a64f543 MS |
7014 | && target_can_accel_watchpoint_condition (loc2->address, |
7015 | loc2->length, | |
0cf6dd15 | 7016 | loc2->watchpoint_type, |
3a5c3e22 | 7017 | w2->cond_exp))) |
0cf6dd15 TJB |
7018 | return 0; |
7019 | ||
85d721b8 PA |
7020 | /* Note that this checks the owner's type, not the location's. In |
7021 | case the target does not support read watchpoints, but does | |
7022 | support access watchpoints, we'll have bp_read_watchpoint | |
7023 | watchpoints with hw_access locations. Those should be considered | |
7024 | duplicates of hw_read locations. The hw_read locations will | |
7025 | become hw_access locations later. */ | |
2d134ed3 PA |
7026 | return (loc1->owner->type == loc2->owner->type |
7027 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7028 | && loc1->address == loc2->address | |
7029 | && loc1->length == loc2->length); | |
e4f237da KB |
7030 | } |
7031 | ||
31e77af2 | 7032 | /* See breakpoint.h. */ |
6c95b8df | 7033 | |
31e77af2 | 7034 | int |
6c95b8df PA |
7035 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7036 | struct address_space *aspace2, CORE_ADDR addr2) | |
7037 | { | |
f5656ead | 7038 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7039 | || aspace1 == aspace2) |
7040 | && addr1 == addr2); | |
7041 | } | |
7042 | ||
f1310107 TJB |
7043 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7044 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7045 | matches ASPACE2. On targets that have global breakpoints, the address | |
7046 | space doesn't really matter. */ | |
7047 | ||
7048 | static int | |
7049 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7050 | int len1, struct address_space *aspace2, | |
7051 | CORE_ADDR addr2) | |
7052 | { | |
f5656ead | 7053 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7054 | || aspace1 == aspace2) |
7055 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7056 | } | |
7057 | ||
7058 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7059 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7060 | matches the breakpoint's address space. On targets that have global | |
7061 | breakpoints, the address space doesn't really matter. */ | |
7062 | ||
7063 | static int | |
7064 | breakpoint_location_address_match (struct bp_location *bl, | |
7065 | struct address_space *aspace, | |
7066 | CORE_ADDR addr) | |
7067 | { | |
7068 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7069 | aspace, addr) | |
7070 | || (bl->length | |
7071 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7072 | bl->address, bl->length, | |
7073 | aspace, addr))); | |
7074 | } | |
7075 | ||
1e4d1764 YQ |
7076 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7077 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7078 | true, otherwise returns false. */ | |
7079 | ||
7080 | static int | |
7081 | tracepoint_locations_match (struct bp_location *loc1, | |
7082 | struct bp_location *loc2) | |
7083 | { | |
7084 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7085 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7086 | locations at the same address of different tracepoints are regarded as | |
7087 | different locations. */ | |
7088 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7089 | else | |
7090 | return 0; | |
7091 | } | |
7092 | ||
2d134ed3 PA |
7093 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7094 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7095 | represent the same location. */ | |
7096 | ||
7097 | static int | |
4a64f543 MS |
7098 | breakpoint_locations_match (struct bp_location *loc1, |
7099 | struct bp_location *loc2) | |
2d134ed3 | 7100 | { |
2bdf28a0 JK |
7101 | int hw_point1, hw_point2; |
7102 | ||
7103 | /* Both of them must not be in moribund_locations. */ | |
7104 | gdb_assert (loc1->owner != NULL); | |
7105 | gdb_assert (loc2->owner != NULL); | |
7106 | ||
7107 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7108 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7109 | |
7110 | if (hw_point1 != hw_point2) | |
7111 | return 0; | |
7112 | else if (hw_point1) | |
7113 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7114 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7115 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7116 | else |
f1310107 TJB |
7117 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7118 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7119 | loc2->pspace->aspace, loc2->address) | |
7120 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7121 | } |
7122 | ||
76897487 KB |
7123 | static void |
7124 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7125 | int bnum, int have_bnum) | |
7126 | { | |
f63fbe86 MS |
7127 | /* The longest string possibly returned by hex_string_custom |
7128 | is 50 chars. These must be at least that big for safety. */ | |
7129 | char astr1[64]; | |
7130 | char astr2[64]; | |
76897487 | 7131 | |
bb599908 PH |
7132 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7133 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7134 | if (have_bnum) |
8a3fe4f8 | 7135 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7136 | bnum, astr1, astr2); |
7137 | else | |
8a3fe4f8 | 7138 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7139 | } |
7140 | ||
4a64f543 MS |
7141 | /* Adjust a breakpoint's address to account for architectural |
7142 | constraints on breakpoint placement. Return the adjusted address. | |
7143 | Note: Very few targets require this kind of adjustment. For most | |
7144 | targets, this function is simply the identity function. */ | |
76897487 KB |
7145 | |
7146 | static CORE_ADDR | |
a6d9a66e UW |
7147 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7148 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7149 | { |
a6d9a66e | 7150 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7151 | { |
7152 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7153 | return bpaddr; | |
7154 | } | |
88f7da05 KB |
7155 | else if (bptype == bp_watchpoint |
7156 | || bptype == bp_hardware_watchpoint | |
7157 | || bptype == bp_read_watchpoint | |
7158 | || bptype == bp_access_watchpoint | |
fe798b75 | 7159 | || bptype == bp_catchpoint) |
88f7da05 KB |
7160 | { |
7161 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7162 | have their addresses modified. */ | |
7163 | return bpaddr; | |
7164 | } | |
76897487 KB |
7165 | else |
7166 | { | |
7167 | CORE_ADDR adjusted_bpaddr; | |
7168 | ||
7169 | /* Some targets have architectural constraints on the placement | |
7170 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7171 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7172 | |
7173 | /* An adjusted breakpoint address can significantly alter | |
7174 | a user's expectations. Print a warning if an adjustment | |
7175 | is required. */ | |
7176 | if (adjusted_bpaddr != bpaddr) | |
7177 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7178 | ||
7179 | return adjusted_bpaddr; | |
7180 | } | |
7181 | } | |
7182 | ||
28010a5d PA |
7183 | void |
7184 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7185 | struct breakpoint *owner) | |
7cc221ef | 7186 | { |
7cc221ef DJ |
7187 | memset (loc, 0, sizeof (*loc)); |
7188 | ||
348d480f PA |
7189 | gdb_assert (ops != NULL); |
7190 | ||
28010a5d PA |
7191 | loc->ops = ops; |
7192 | loc->owner = owner; | |
511a6cd4 | 7193 | loc->cond = NULL; |
b775012e | 7194 | loc->cond_bytecode = NULL; |
0d381245 VP |
7195 | loc->shlib_disabled = 0; |
7196 | loc->enabled = 1; | |
e049a4b5 | 7197 | |
28010a5d | 7198 | switch (owner->type) |
e049a4b5 DJ |
7199 | { |
7200 | case bp_breakpoint: | |
7201 | case bp_until: | |
7202 | case bp_finish: | |
7203 | case bp_longjmp: | |
7204 | case bp_longjmp_resume: | |
e2e4d78b | 7205 | case bp_longjmp_call_dummy: |
186c406b TT |
7206 | case bp_exception: |
7207 | case bp_exception_resume: | |
e049a4b5 | 7208 | case bp_step_resume: |
2c03e5be | 7209 | case bp_hp_step_resume: |
e049a4b5 DJ |
7210 | case bp_watchpoint_scope: |
7211 | case bp_call_dummy: | |
aa7d318d | 7212 | case bp_std_terminate: |
e049a4b5 DJ |
7213 | case bp_shlib_event: |
7214 | case bp_thread_event: | |
7215 | case bp_overlay_event: | |
4efc6507 | 7216 | case bp_jit_event: |
0fd8e87f | 7217 | case bp_longjmp_master: |
aa7d318d | 7218 | case bp_std_terminate_master: |
186c406b | 7219 | case bp_exception_master: |
0e30163f JK |
7220 | case bp_gnu_ifunc_resolver: |
7221 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7222 | case bp_dprintf: |
e049a4b5 | 7223 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7224 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7225 | break; |
7226 | case bp_hardware_breakpoint: | |
7227 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7228 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7229 | break; |
7230 | case bp_hardware_watchpoint: | |
7231 | case bp_read_watchpoint: | |
7232 | case bp_access_watchpoint: | |
7233 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7234 | break; | |
7235 | case bp_watchpoint: | |
ce78b96d | 7236 | case bp_catchpoint: |
15c3d785 PA |
7237 | case bp_tracepoint: |
7238 | case bp_fast_tracepoint: | |
0fb4aa4b | 7239 | case bp_static_tracepoint: |
e049a4b5 DJ |
7240 | loc->loc_type = bp_loc_other; |
7241 | break; | |
7242 | default: | |
e2e0b3e5 | 7243 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7244 | } |
7245 | ||
f431efe5 | 7246 | loc->refc = 1; |
28010a5d PA |
7247 | } |
7248 | ||
7249 | /* Allocate a struct bp_location. */ | |
7250 | ||
7251 | static struct bp_location * | |
7252 | allocate_bp_location (struct breakpoint *bpt) | |
7253 | { | |
348d480f PA |
7254 | return bpt->ops->allocate_location (bpt); |
7255 | } | |
7cc221ef | 7256 | |
f431efe5 PA |
7257 | static void |
7258 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7259 | { |
348d480f | 7260 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7261 | xfree (loc); |
7262 | } | |
7263 | ||
f431efe5 PA |
7264 | /* Increment reference count. */ |
7265 | ||
7266 | static void | |
7267 | incref_bp_location (struct bp_location *bl) | |
7268 | { | |
7269 | ++bl->refc; | |
7270 | } | |
7271 | ||
7272 | /* Decrement reference count. If the reference count reaches 0, | |
7273 | destroy the bp_location. Sets *BLP to NULL. */ | |
7274 | ||
7275 | static void | |
7276 | decref_bp_location (struct bp_location **blp) | |
7277 | { | |
0807b50c PA |
7278 | gdb_assert ((*blp)->refc > 0); |
7279 | ||
f431efe5 PA |
7280 | if (--(*blp)->refc == 0) |
7281 | free_bp_location (*blp); | |
7282 | *blp = NULL; | |
7283 | } | |
7284 | ||
346774a9 | 7285 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7286 | |
346774a9 PA |
7287 | static void |
7288 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7289 | { |
346774a9 | 7290 | struct breakpoint *b1; |
c906108c | 7291 | |
346774a9 PA |
7292 | /* Add this breakpoint to the end of the chain so that a list of |
7293 | breakpoints will come out in order of increasing numbers. */ | |
7294 | ||
7295 | b1 = breakpoint_chain; | |
7296 | if (b1 == 0) | |
7297 | breakpoint_chain = b; | |
7298 | else | |
7299 | { | |
7300 | while (b1->next) | |
7301 | b1 = b1->next; | |
7302 | b1->next = b; | |
7303 | } | |
7304 | } | |
7305 | ||
7306 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7307 | ||
7308 | static void | |
7309 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7310 | struct gdbarch *gdbarch, | |
28010a5d | 7311 | enum bptype bptype, |
c0a91b2b | 7312 | const struct breakpoint_ops *ops) |
346774a9 | 7313 | { |
c906108c | 7314 | memset (b, 0, sizeof (*b)); |
2219d63c | 7315 | |
348d480f PA |
7316 | gdb_assert (ops != NULL); |
7317 | ||
28010a5d | 7318 | b->ops = ops; |
4d28f7a8 | 7319 | b->type = bptype; |
a6d9a66e | 7320 | b->gdbarch = gdbarch; |
c906108c SS |
7321 | b->language = current_language->la_language; |
7322 | b->input_radix = input_radix; | |
7323 | b->thread = -1; | |
b5de0fa7 | 7324 | b->enable_state = bp_enabled; |
c906108c SS |
7325 | b->next = 0; |
7326 | b->silent = 0; | |
7327 | b->ignore_count = 0; | |
7328 | b->commands = NULL; | |
818dd999 | 7329 | b->frame_id = null_frame_id; |
0d381245 | 7330 | b->condition_not_parsed = 0; |
84f4c1fe | 7331 | b->py_bp_object = NULL; |
d0fb5eae | 7332 | b->related_breakpoint = b; |
346774a9 PA |
7333 | } |
7334 | ||
7335 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7336 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7337 | |
7338 | static struct breakpoint * | |
7339 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7340 | enum bptype bptype, |
c0a91b2b | 7341 | const struct breakpoint_ops *ops) |
346774a9 PA |
7342 | { |
7343 | struct breakpoint *b = XNEW (struct breakpoint); | |
7344 | ||
348d480f | 7345 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7346 | add_to_breakpoint_chain (b); |
0d381245 VP |
7347 | return b; |
7348 | } | |
7349 | ||
0e30163f JK |
7350 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7351 | resolutions should be made as the user specified the location explicitly | |
7352 | enough. */ | |
7353 | ||
0d381245 | 7354 | static void |
0e30163f | 7355 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7356 | { |
2bdf28a0 JK |
7357 | gdb_assert (loc->owner != NULL); |
7358 | ||
0d381245 | 7359 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7360 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7361 | || is_tracepoint (loc->owner)) |
0d381245 | 7362 | { |
0e30163f | 7363 | int is_gnu_ifunc; |
2c02bd72 | 7364 | const char *function_name; |
6a3a010b | 7365 | CORE_ADDR func_addr; |
0e30163f | 7366 | |
2c02bd72 | 7367 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7368 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7369 | |
7370 | if (is_gnu_ifunc && !explicit_loc) | |
7371 | { | |
7372 | struct breakpoint *b = loc->owner; | |
7373 | ||
7374 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7375 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7376 | &loc->requested_address)) |
7377 | { | |
7378 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7379 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7380 | loc->requested_address, | |
7381 | b->type); | |
7382 | } | |
7383 | else if (b->type == bp_breakpoint && b->loc == loc | |
7384 | && loc->next == NULL && b->related_breakpoint == b) | |
7385 | { | |
7386 | /* Create only the whole new breakpoint of this type but do not | |
7387 | mess more complicated breakpoints with multiple locations. */ | |
7388 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7389 | /* Remember the resolver's address for use by the return |
7390 | breakpoint. */ | |
7391 | loc->related_address = func_addr; | |
0e30163f JK |
7392 | } |
7393 | } | |
7394 | ||
2c02bd72 DE |
7395 | if (function_name) |
7396 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7397 | } |
7398 | } | |
7399 | ||
a6d9a66e | 7400 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7401 | struct gdbarch * |
a6d9a66e UW |
7402 | get_sal_arch (struct symtab_and_line sal) |
7403 | { | |
7404 | if (sal.section) | |
7405 | return get_objfile_arch (sal.section->objfile); | |
7406 | if (sal.symtab) | |
7407 | return get_objfile_arch (sal.symtab->objfile); | |
7408 | ||
7409 | return NULL; | |
7410 | } | |
7411 | ||
346774a9 PA |
7412 | /* Low level routine for partially initializing a breakpoint of type |
7413 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7414 | file name, and line number are provided by SAL. |
0d381245 VP |
7415 | |
7416 | It is expected that the caller will complete the initialization of | |
7417 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7418 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7419 | |
346774a9 PA |
7420 | static void |
7421 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7422 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7423 | const struct breakpoint_ops *ops) |
0d381245 | 7424 | { |
28010a5d | 7425 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7426 | |
3742cc8b | 7427 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7428 | |
6c95b8df PA |
7429 | if (bptype != bp_catchpoint) |
7430 | gdb_assert (sal.pspace != NULL); | |
7431 | ||
f8eba3c6 TT |
7432 | /* Store the program space that was used to set the breakpoint, |
7433 | except for ordinary breakpoints, which are independent of the | |
7434 | program space. */ | |
7435 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7436 | b->pspace = sal.pspace; | |
346774a9 | 7437 | } |
c906108c | 7438 | |
346774a9 PA |
7439 | /* set_raw_breakpoint is a low level routine for allocating and |
7440 | partially initializing a breakpoint of type BPTYPE. The newly | |
7441 | created breakpoint's address, section, source file name, and line | |
7442 | number are provided by SAL. The newly created and partially | |
7443 | initialized breakpoint is added to the breakpoint chain and | |
7444 | is also returned as the value of this function. | |
7445 | ||
7446 | It is expected that the caller will complete the initialization of | |
7447 | the newly created breakpoint struct as well as output any status | |
7448 | information regarding the creation of a new breakpoint. In | |
7449 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7450 | number! Care should be taken to not allow an error to occur | |
7451 | prior to completing the initialization of the breakpoint. If this | |
7452 | should happen, a bogus breakpoint will be left on the chain. */ | |
7453 | ||
7454 | struct breakpoint * | |
7455 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7456 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7457 | const struct breakpoint_ops *ops) |
346774a9 PA |
7458 | { |
7459 | struct breakpoint *b = XNEW (struct breakpoint); | |
7460 | ||
348d480f | 7461 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7462 | add_to_breakpoint_chain (b); |
c906108c SS |
7463 | return b; |
7464 | } | |
7465 | ||
c2c6d25f JM |
7466 | |
7467 | /* Note that the breakpoint object B describes a permanent breakpoint | |
7468 | instruction, hard-wired into the inferior's code. */ | |
7469 | void | |
7470 | make_breakpoint_permanent (struct breakpoint *b) | |
7471 | { | |
0d381245 | 7472 | struct bp_location *bl; |
cc59ec59 | 7473 | |
b5de0fa7 | 7474 | b->enable_state = bp_permanent; |
c2c6d25f | 7475 | |
4a64f543 MS |
7476 | /* By definition, permanent breakpoints are already present in the |
7477 | code. Mark all locations as inserted. For now, | |
7478 | make_breakpoint_permanent is called in just one place, so it's | |
7479 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 7480 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
7481 | for (bl = b->loc; bl; bl = bl->next) |
7482 | bl->inserted = 1; | |
c2c6d25f JM |
7483 | } |
7484 | ||
53a5351d | 7485 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7486 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7487 | initiated the operation. */ | |
c906108c SS |
7488 | |
7489 | void | |
186c406b | 7490 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7491 | { |
35df4500 | 7492 | struct breakpoint *b, *b_tmp; |
186c406b | 7493 | int thread = tp->num; |
0fd8e87f UW |
7494 | |
7495 | /* To avoid having to rescan all objfile symbols at every step, | |
7496 | we maintain a list of continually-inserted but always disabled | |
7497 | longjmp "master" breakpoints. Here, we simply create momentary | |
7498 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7499 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7500 | if (b->pspace == current_program_space |
186c406b TT |
7501 | && (b->type == bp_longjmp_master |
7502 | || b->type == bp_exception_master)) | |
0fd8e87f | 7503 | { |
06edf0c0 PA |
7504 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7505 | struct breakpoint *clone; | |
cc59ec59 | 7506 | |
e2e4d78b JK |
7507 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7508 | after their removal. */ | |
06edf0c0 | 7509 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7510 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7511 | clone->thread = thread; |
7512 | } | |
186c406b TT |
7513 | |
7514 | tp->initiating_frame = frame; | |
c906108c SS |
7515 | } |
7516 | ||
611c83ae | 7517 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7518 | void |
611c83ae | 7519 | delete_longjmp_breakpoint (int thread) |
c906108c | 7520 | { |
35df4500 | 7521 | struct breakpoint *b, *b_tmp; |
c906108c | 7522 | |
35df4500 | 7523 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7524 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7525 | { |
7526 | if (b->thread == thread) | |
7527 | delete_breakpoint (b); | |
7528 | } | |
c906108c SS |
7529 | } |
7530 | ||
f59f708a PA |
7531 | void |
7532 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7533 | { | |
7534 | struct breakpoint *b, *b_tmp; | |
7535 | ||
7536 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7537 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7538 | { | |
7539 | if (b->thread == thread) | |
7540 | b->disposition = disp_del_at_next_stop; | |
7541 | } | |
7542 | } | |
7543 | ||
e2e4d78b JK |
7544 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7545 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7546 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7547 | breakpoints. */ | |
7548 | ||
7549 | struct breakpoint * | |
7550 | set_longjmp_breakpoint_for_call_dummy (void) | |
7551 | { | |
7552 | struct breakpoint *b, *retval = NULL; | |
7553 | ||
7554 | ALL_BREAKPOINTS (b) | |
7555 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7556 | { | |
7557 | struct breakpoint *new_b; | |
7558 | ||
7559 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7560 | &momentary_breakpoint_ops, |
7561 | 1); | |
e2e4d78b JK |
7562 | new_b->thread = pid_to_thread_id (inferior_ptid); |
7563 | ||
7564 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7565 | ||
7566 | gdb_assert (new_b->related_breakpoint == new_b); | |
7567 | if (retval == NULL) | |
7568 | retval = new_b; | |
7569 | new_b->related_breakpoint = retval; | |
7570 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7571 | retval = retval->related_breakpoint; | |
7572 | retval->related_breakpoint = new_b; | |
7573 | } | |
7574 | ||
7575 | return retval; | |
7576 | } | |
7577 | ||
7578 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7579 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7580 | stack. |
7581 | ||
7582 | You should call this function only at places where it is safe to currently | |
7583 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7584 | frames. */ | |
7585 | ||
7586 | void | |
b67a2c6f | 7587 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7588 | { |
7589 | struct breakpoint *b, *b_tmp; | |
7590 | ||
7591 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
b67a2c6f | 7592 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->num) |
e2e4d78b JK |
7593 | { |
7594 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7595 | ||
7596 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7597 | dummy_b = dummy_b->related_breakpoint; | |
7598 | if (dummy_b->type != bp_call_dummy | |
7599 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7600 | continue; | |
7601 | ||
b67a2c6f | 7602 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7603 | |
7604 | while (b->related_breakpoint != b) | |
7605 | { | |
7606 | if (b_tmp == b->related_breakpoint) | |
7607 | b_tmp = b->related_breakpoint->next; | |
7608 | delete_breakpoint (b->related_breakpoint); | |
7609 | } | |
7610 | delete_breakpoint (b); | |
7611 | } | |
7612 | } | |
7613 | ||
1900040c MS |
7614 | void |
7615 | enable_overlay_breakpoints (void) | |
7616 | { | |
52f0bd74 | 7617 | struct breakpoint *b; |
1900040c MS |
7618 | |
7619 | ALL_BREAKPOINTS (b) | |
7620 | if (b->type == bp_overlay_event) | |
7621 | { | |
7622 | b->enable_state = bp_enabled; | |
44702360 | 7623 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7624 | overlay_events_enabled = 1; |
1900040c MS |
7625 | } |
7626 | } | |
7627 | ||
7628 | void | |
7629 | disable_overlay_breakpoints (void) | |
7630 | { | |
52f0bd74 | 7631 | struct breakpoint *b; |
1900040c MS |
7632 | |
7633 | ALL_BREAKPOINTS (b) | |
7634 | if (b->type == bp_overlay_event) | |
7635 | { | |
7636 | b->enable_state = bp_disabled; | |
44702360 | 7637 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7638 | overlay_events_enabled = 0; |
1900040c MS |
7639 | } |
7640 | } | |
7641 | ||
aa7d318d TT |
7642 | /* Set an active std::terminate breakpoint for each std::terminate |
7643 | master breakpoint. */ | |
7644 | void | |
7645 | set_std_terminate_breakpoint (void) | |
7646 | { | |
35df4500 | 7647 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7648 | |
35df4500 | 7649 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7650 | if (b->pspace == current_program_space |
7651 | && b->type == bp_std_terminate_master) | |
7652 | { | |
06edf0c0 | 7653 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7654 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7655 | } |
7656 | } | |
7657 | ||
7658 | /* Delete all the std::terminate breakpoints. */ | |
7659 | void | |
7660 | delete_std_terminate_breakpoint (void) | |
7661 | { | |
35df4500 | 7662 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7663 | |
35df4500 | 7664 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7665 | if (b->type == bp_std_terminate) |
7666 | delete_breakpoint (b); | |
7667 | } | |
7668 | ||
c4093a6a | 7669 | struct breakpoint * |
a6d9a66e | 7670 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7671 | { |
7672 | struct breakpoint *b; | |
c4093a6a | 7673 | |
06edf0c0 PA |
7674 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7675 | &internal_breakpoint_ops); | |
7676 | ||
b5de0fa7 | 7677 | b->enable_state = bp_enabled; |
c4093a6a | 7678 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
7679 | b->addr_string |
7680 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 7681 | |
44702360 | 7682 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7683 | |
c4093a6a JM |
7684 | return b; |
7685 | } | |
7686 | ||
7687 | void | |
7688 | remove_thread_event_breakpoints (void) | |
7689 | { | |
35df4500 | 7690 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7691 | |
35df4500 | 7692 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7693 | if (b->type == bp_thread_event |
7694 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7695 | delete_breakpoint (b); |
7696 | } | |
7697 | ||
0101ce28 JJ |
7698 | struct lang_and_radix |
7699 | { | |
7700 | enum language lang; | |
7701 | int radix; | |
7702 | }; | |
7703 | ||
4efc6507 DE |
7704 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7705 | ||
7706 | struct breakpoint * | |
7707 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7708 | { | |
7709 | struct breakpoint *b; | |
7710 | ||
06edf0c0 PA |
7711 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7712 | &internal_breakpoint_ops); | |
44702360 | 7713 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
4efc6507 DE |
7714 | return b; |
7715 | } | |
0101ce28 | 7716 | |
03673fc7 PP |
7717 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7718 | ||
7719 | void | |
7720 | remove_jit_event_breakpoints (void) | |
7721 | { | |
7722 | struct breakpoint *b, *b_tmp; | |
7723 | ||
7724 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7725 | if (b->type == bp_jit_event | |
7726 | && b->loc->pspace == current_program_space) | |
7727 | delete_breakpoint (b); | |
7728 | } | |
7729 | ||
cae688ec JJ |
7730 | void |
7731 | remove_solib_event_breakpoints (void) | |
7732 | { | |
35df4500 | 7733 | struct breakpoint *b, *b_tmp; |
cae688ec | 7734 | |
35df4500 | 7735 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7736 | if (b->type == bp_shlib_event |
7737 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7738 | delete_breakpoint (b); |
7739 | } | |
7740 | ||
f37f681c PA |
7741 | /* See breakpoint.h. */ |
7742 | ||
7743 | void | |
7744 | remove_solib_event_breakpoints_at_next_stop (void) | |
7745 | { | |
7746 | struct breakpoint *b, *b_tmp; | |
7747 | ||
7748 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7749 | if (b->type == bp_shlib_event | |
7750 | && b->loc->pspace == current_program_space) | |
7751 | b->disposition = disp_del_at_next_stop; | |
7752 | } | |
7753 | ||
04086b45 PA |
7754 | /* Helper for create_solib_event_breakpoint / |
7755 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7756 | INSERT_MODE to pass through to update_global_location_list. */ | |
7757 | ||
7758 | static struct breakpoint * | |
7759 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7760 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7761 | { |
7762 | struct breakpoint *b; | |
7763 | ||
06edf0c0 PA |
7764 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7765 | &internal_breakpoint_ops); | |
04086b45 | 7766 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7767 | return b; |
7768 | } | |
7769 | ||
04086b45 PA |
7770 | struct breakpoint * |
7771 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7772 | { | |
7773 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7774 | } | |
7775 | ||
f37f681c PA |
7776 | /* See breakpoint.h. */ |
7777 | ||
7778 | struct breakpoint * | |
7779 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7780 | { | |
7781 | struct breakpoint *b; | |
7782 | ||
04086b45 PA |
7783 | /* Explicitly tell update_global_location_list to insert |
7784 | locations. */ | |
7785 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7786 | if (!b->loc->inserted) |
7787 | { | |
7788 | delete_breakpoint (b); | |
7789 | return NULL; | |
7790 | } | |
7791 | return b; | |
7792 | } | |
7793 | ||
cae688ec JJ |
7794 | /* Disable any breakpoints that are on code in shared libraries. Only |
7795 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7796 | ||
7797 | void | |
cb851954 | 7798 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7799 | { |
876fa593 | 7800 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7801 | |
876fa593 | 7802 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7803 | { |
2bdf28a0 | 7804 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7805 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7806 | |
4a64f543 MS |
7807 | /* We apply the check to all breakpoints, including disabled for |
7808 | those with loc->duplicate set. This is so that when breakpoint | |
7809 | becomes enabled, or the duplicate is removed, gdb will try to | |
7810 | insert all breakpoints. If we don't set shlib_disabled here, | |
7811 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7812 | if (((b->type == bp_breakpoint) |
508ccb1f | 7813 | || (b->type == bp_jit_event) |
1042e4c0 | 7814 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7815 | || (is_tracepoint (b))) |
6c95b8df | 7816 | && loc->pspace == current_program_space |
0d381245 | 7817 | && !loc->shlib_disabled |
6c95b8df | 7818 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7819 | ) |
0d381245 VP |
7820 | { |
7821 | loc->shlib_disabled = 1; | |
7822 | } | |
cae688ec JJ |
7823 | } |
7824 | } | |
7825 | ||
63644780 NB |
7826 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7827 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7828 | disabled ones can just stay disabled. */ | |
84acb35a | 7829 | |
75149521 | 7830 | static void |
84acb35a JJ |
7831 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7832 | { | |
876fa593 | 7833 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7834 | int disabled_shlib_breaks = 0; |
7835 | ||
c86cf029 VP |
7836 | /* SunOS a.out shared libraries are always mapped, so do not |
7837 | disable breakpoints; they will only be reported as unloaded | |
7838 | through clear_solib when GDB discards its shared library | |
7839 | list. See clear_solib for more information. */ | |
7840 | if (exec_bfd != NULL | |
7841 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7842 | return; | |
7843 | ||
876fa593 | 7844 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7845 | { |
2bdf28a0 | 7846 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7847 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7848 | |
1e4d1764 | 7849 | if (solib->pspace == loc->pspace |
e2dd7057 | 7850 | && !loc->shlib_disabled |
1e4d1764 YQ |
7851 | && (((b->type == bp_breakpoint |
7852 | || b->type == bp_jit_event | |
7853 | || b->type == bp_hardware_breakpoint) | |
7854 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7855 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7856 | || is_tracepoint (b)) | |
e2dd7057 | 7857 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7858 | { |
e2dd7057 PP |
7859 | loc->shlib_disabled = 1; |
7860 | /* At this point, we cannot rely on remove_breakpoint | |
7861 | succeeding so we must mark the breakpoint as not inserted | |
7862 | to prevent future errors occurring in remove_breakpoints. */ | |
7863 | loc->inserted = 0; | |
8d3788bd VP |
7864 | |
7865 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7866 | observer_notify_breakpoint_modified (b); | |
7867 | ||
e2dd7057 PP |
7868 | if (!disabled_shlib_breaks) |
7869 | { | |
7870 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7871 | warning (_("Temporarily disabling breakpoints " |
7872 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7873 | solib->so_name); |
84acb35a | 7874 | } |
e2dd7057 | 7875 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7876 | } |
7877 | } | |
84acb35a JJ |
7878 | } |
7879 | ||
63644780 NB |
7880 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7881 | notification of free_objfile. Only apply to enabled breakpoints, | |
7882 | disabled ones can just stay disabled. */ | |
7883 | ||
7884 | static void | |
7885 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7886 | { | |
7887 | struct breakpoint *b; | |
7888 | ||
7889 | if (objfile == NULL) | |
7890 | return; | |
7891 | ||
d03de421 PA |
7892 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7893 | managed by the user with add-symbol-file/remove-symbol-file. | |
7894 | Similarly to how breakpoints in shared libraries are handled in | |
7895 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7896 | shlib_disabled so they end up uninserted on the next global |
7897 | location list update. Shared libraries not loaded by the user | |
7898 | aren't handled here -- they're already handled in | |
7899 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7900 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7901 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7902 | main objfile). */ | |
7903 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7904 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7905 | return; |
7906 | ||
7907 | ALL_BREAKPOINTS (b) | |
7908 | { | |
7909 | struct bp_location *loc; | |
7910 | int bp_modified = 0; | |
7911 | ||
7912 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7913 | continue; | |
7914 | ||
7915 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7916 | { | |
7917 | CORE_ADDR loc_addr = loc->address; | |
7918 | ||
7919 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7920 | && loc->loc_type != bp_loc_software_breakpoint) | |
7921 | continue; | |
7922 | ||
7923 | if (loc->shlib_disabled != 0) | |
7924 | continue; | |
7925 | ||
7926 | if (objfile->pspace != loc->pspace) | |
7927 | continue; | |
7928 | ||
7929 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7930 | && loc->loc_type != bp_loc_software_breakpoint) | |
7931 | continue; | |
7932 | ||
7933 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7934 | { | |
7935 | loc->shlib_disabled = 1; | |
08351840 PA |
7936 | /* At this point, we don't know whether the object was |
7937 | unmapped from the inferior or not, so leave the | |
7938 | inserted flag alone. We'll handle failure to | |
7939 | uninsert quietly, in case the object was indeed | |
7940 | unmapped. */ | |
63644780 NB |
7941 | |
7942 | mark_breakpoint_location_modified (loc); | |
7943 | ||
7944 | bp_modified = 1; | |
7945 | } | |
7946 | } | |
7947 | ||
7948 | if (bp_modified) | |
7949 | observer_notify_breakpoint_modified (b); | |
7950 | } | |
7951 | } | |
7952 | ||
ce78b96d JB |
7953 | /* FORK & VFORK catchpoints. */ |
7954 | ||
e29a4733 PA |
7955 | /* An instance of this type is used to represent a fork or vfork |
7956 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
7957 | class; users downcast to "struct breakpoint *" when needed. A | |
7958 | breakpoint is really of this type iff its ops pointer points to | |
7959 | CATCH_FORK_BREAKPOINT_OPS. */ | |
7960 | ||
7961 | struct fork_catchpoint | |
7962 | { | |
7963 | /* The base class. */ | |
7964 | struct breakpoint base; | |
7965 | ||
7966 | /* Process id of a child process whose forking triggered this | |
7967 | catchpoint. This field is only valid immediately after this | |
7968 | catchpoint has triggered. */ | |
7969 | ptid_t forked_inferior_pid; | |
7970 | }; | |
7971 | ||
4a64f543 MS |
7972 | /* Implement the "insert" breakpoint_ops method for fork |
7973 | catchpoints. */ | |
ce78b96d | 7974 | |
77b06cd7 TJB |
7975 | static int |
7976 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7977 | { |
dfd4cc63 | 7978 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7979 | } |
7980 | ||
4a64f543 MS |
7981 | /* Implement the "remove" breakpoint_ops method for fork |
7982 | catchpoints. */ | |
ce78b96d JB |
7983 | |
7984 | static int | |
77b06cd7 | 7985 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 7986 | { |
dfd4cc63 | 7987 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7988 | } |
7989 | ||
7990 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7991 | catchpoints. */ | |
7992 | ||
7993 | static int | |
f1310107 | 7994 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7995 | struct address_space *aspace, CORE_ADDR bp_addr, |
7996 | const struct target_waitstatus *ws) | |
ce78b96d | 7997 | { |
e29a4733 PA |
7998 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7999 | ||
f90263c1 TT |
8000 | if (ws->kind != TARGET_WAITKIND_FORKED) |
8001 | return 0; | |
8002 | ||
8003 | c->forked_inferior_pid = ws->value.related_pid; | |
8004 | return 1; | |
ce78b96d JB |
8005 | } |
8006 | ||
4a64f543 MS |
8007 | /* Implement the "print_it" breakpoint_ops method for fork |
8008 | catchpoints. */ | |
ce78b96d JB |
8009 | |
8010 | static enum print_stop_action | |
348d480f | 8011 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8012 | { |
36dfb11c | 8013 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8014 | struct breakpoint *b = bs->breakpoint_at; |
8015 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8016 | |
ce78b96d | 8017 | annotate_catchpoint (b->number); |
36dfb11c TT |
8018 | if (b->disposition == disp_del) |
8019 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8020 | else | |
8021 | ui_out_text (uiout, "\nCatchpoint "); | |
8022 | if (ui_out_is_mi_like_p (uiout)) | |
8023 | { | |
8024 | ui_out_field_string (uiout, "reason", | |
8025 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
8026 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8027 | } | |
8028 | ui_out_field_int (uiout, "bkptno", b->number); | |
8029 | ui_out_text (uiout, " (forked process "); | |
8030 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8031 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8032 | return PRINT_SRC_AND_LOC; |
8033 | } | |
8034 | ||
4a64f543 MS |
8035 | /* Implement the "print_one" breakpoint_ops method for fork |
8036 | catchpoints. */ | |
ce78b96d JB |
8037 | |
8038 | static void | |
a6d9a66e | 8039 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8040 | { |
e29a4733 | 8041 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8042 | struct value_print_options opts; |
79a45e25 | 8043 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8044 | |
8045 | get_user_print_options (&opts); | |
8046 | ||
4a64f543 MS |
8047 | /* Field 4, the address, is omitted (which makes the columns not |
8048 | line up too nicely with the headers, but the effect is relatively | |
8049 | readable). */ | |
79a45b7d | 8050 | if (opts.addressprint) |
ce78b96d JB |
8051 | ui_out_field_skip (uiout, "addr"); |
8052 | annotate_field (5); | |
8053 | ui_out_text (uiout, "fork"); | |
e29a4733 | 8054 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8055 | { |
8056 | ui_out_text (uiout, ", process "); | |
8057 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8058 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8059 | ui_out_spaces (uiout, 1); |
8060 | } | |
8ac3646f TT |
8061 | |
8062 | if (ui_out_is_mi_like_p (uiout)) | |
8063 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
8064 | } |
8065 | ||
8066 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8067 | catchpoints. */ | |
8068 | ||
8069 | static void | |
8070 | print_mention_catch_fork (struct breakpoint *b) | |
8071 | { | |
8072 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8073 | } | |
8074 | ||
6149aea9 PA |
8075 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8076 | catchpoints. */ | |
8077 | ||
8078 | static void | |
8079 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8080 | { | |
8081 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8082 | print_recreate_thread (b, fp); |
6149aea9 PA |
8083 | } |
8084 | ||
ce78b96d JB |
8085 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8086 | ||
2060206e | 8087 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8088 | |
4a64f543 MS |
8089 | /* Implement the "insert" breakpoint_ops method for vfork |
8090 | catchpoints. */ | |
ce78b96d | 8091 | |
77b06cd7 TJB |
8092 | static int |
8093 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8094 | { |
dfd4cc63 | 8095 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8096 | } |
8097 | ||
4a64f543 MS |
8098 | /* Implement the "remove" breakpoint_ops method for vfork |
8099 | catchpoints. */ | |
ce78b96d JB |
8100 | |
8101 | static int | |
77b06cd7 | 8102 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 8103 | { |
dfd4cc63 | 8104 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8105 | } |
8106 | ||
8107 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8108 | catchpoints. */ | |
8109 | ||
8110 | static int | |
f1310107 | 8111 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8112 | struct address_space *aspace, CORE_ADDR bp_addr, |
8113 | const struct target_waitstatus *ws) | |
ce78b96d | 8114 | { |
e29a4733 PA |
8115 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8116 | ||
f90263c1 TT |
8117 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8118 | return 0; | |
8119 | ||
8120 | c->forked_inferior_pid = ws->value.related_pid; | |
8121 | return 1; | |
ce78b96d JB |
8122 | } |
8123 | ||
4a64f543 MS |
8124 | /* Implement the "print_it" breakpoint_ops method for vfork |
8125 | catchpoints. */ | |
ce78b96d JB |
8126 | |
8127 | static enum print_stop_action | |
348d480f | 8128 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8129 | { |
36dfb11c | 8130 | struct ui_out *uiout = current_uiout; |
348d480f | 8131 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8132 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8133 | ||
ce78b96d | 8134 | annotate_catchpoint (b->number); |
36dfb11c TT |
8135 | if (b->disposition == disp_del) |
8136 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8137 | else | |
8138 | ui_out_text (uiout, "\nCatchpoint "); | |
8139 | if (ui_out_is_mi_like_p (uiout)) | |
8140 | { | |
8141 | ui_out_field_string (uiout, "reason", | |
8142 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8143 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8144 | } | |
8145 | ui_out_field_int (uiout, "bkptno", b->number); | |
8146 | ui_out_text (uiout, " (vforked process "); | |
8147 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8148 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8149 | return PRINT_SRC_AND_LOC; |
8150 | } | |
8151 | ||
4a64f543 MS |
8152 | /* Implement the "print_one" breakpoint_ops method for vfork |
8153 | catchpoints. */ | |
ce78b96d JB |
8154 | |
8155 | static void | |
a6d9a66e | 8156 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8157 | { |
e29a4733 | 8158 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8159 | struct value_print_options opts; |
79a45e25 | 8160 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8161 | |
8162 | get_user_print_options (&opts); | |
4a64f543 MS |
8163 | /* Field 4, the address, is omitted (which makes the columns not |
8164 | line up too nicely with the headers, but the effect is relatively | |
8165 | readable). */ | |
79a45b7d | 8166 | if (opts.addressprint) |
ce78b96d JB |
8167 | ui_out_field_skip (uiout, "addr"); |
8168 | annotate_field (5); | |
8169 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8170 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8171 | { |
8172 | ui_out_text (uiout, ", process "); | |
8173 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8174 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8175 | ui_out_spaces (uiout, 1); |
8176 | } | |
8ac3646f TT |
8177 | |
8178 | if (ui_out_is_mi_like_p (uiout)) | |
8179 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8180 | } |
8181 | ||
8182 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8183 | catchpoints. */ | |
8184 | ||
8185 | static void | |
8186 | print_mention_catch_vfork (struct breakpoint *b) | |
8187 | { | |
8188 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8189 | } | |
8190 | ||
6149aea9 PA |
8191 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8192 | catchpoints. */ | |
8193 | ||
8194 | static void | |
8195 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8196 | { | |
8197 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8198 | print_recreate_thread (b, fp); |
6149aea9 PA |
8199 | } |
8200 | ||
ce78b96d JB |
8201 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8202 | ||
2060206e | 8203 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8204 | |
edcc5120 TT |
8205 | /* An instance of this type is used to represent an solib catchpoint. |
8206 | It includes a "struct breakpoint" as a kind of base class; users | |
8207 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8208 | really of this type iff its ops pointer points to | |
8209 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8210 | ||
8211 | struct solib_catchpoint | |
8212 | { | |
8213 | /* The base class. */ | |
8214 | struct breakpoint base; | |
8215 | ||
8216 | /* True for "catch load", false for "catch unload". */ | |
8217 | unsigned char is_load; | |
8218 | ||
8219 | /* Regular expression to match, if any. COMPILED is only valid when | |
8220 | REGEX is non-NULL. */ | |
8221 | char *regex; | |
8222 | regex_t compiled; | |
8223 | }; | |
8224 | ||
8225 | static void | |
8226 | dtor_catch_solib (struct breakpoint *b) | |
8227 | { | |
8228 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8229 | ||
8230 | if (self->regex) | |
8231 | regfree (&self->compiled); | |
8232 | xfree (self->regex); | |
8233 | ||
8234 | base_breakpoint_ops.dtor (b); | |
8235 | } | |
8236 | ||
8237 | static int | |
8238 | insert_catch_solib (struct bp_location *ignore) | |
8239 | { | |
8240 | return 0; | |
8241 | } | |
8242 | ||
8243 | static int | |
8244 | remove_catch_solib (struct bp_location *ignore) | |
8245 | { | |
8246 | return 0; | |
8247 | } | |
8248 | ||
8249 | static int | |
8250 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8251 | struct address_space *aspace, | |
8252 | CORE_ADDR bp_addr, | |
8253 | const struct target_waitstatus *ws) | |
8254 | { | |
8255 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8256 | struct breakpoint *other; | |
8257 | ||
8258 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8259 | return 1; | |
8260 | ||
8261 | ALL_BREAKPOINTS (other) | |
8262 | { | |
8263 | struct bp_location *other_bl; | |
8264 | ||
8265 | if (other == bl->owner) | |
8266 | continue; | |
8267 | ||
8268 | if (other->type != bp_shlib_event) | |
8269 | continue; | |
8270 | ||
8271 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8272 | continue; | |
8273 | ||
8274 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8275 | { | |
8276 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8277 | return 1; | |
8278 | } | |
8279 | } | |
8280 | ||
8281 | return 0; | |
8282 | } | |
8283 | ||
8284 | static void | |
8285 | check_status_catch_solib (struct bpstats *bs) | |
8286 | { | |
8287 | struct solib_catchpoint *self | |
8288 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8289 | int ix; | |
8290 | ||
8291 | if (self->is_load) | |
8292 | { | |
8293 | struct so_list *iter; | |
8294 | ||
8295 | for (ix = 0; | |
8296 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8297 | ix, iter); | |
8298 | ++ix) | |
8299 | { | |
8300 | if (!self->regex | |
8301 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8302 | return; | |
8303 | } | |
8304 | } | |
8305 | else | |
8306 | { | |
8307 | char *iter; | |
8308 | ||
8309 | for (ix = 0; | |
8310 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8311 | ix, iter); | |
8312 | ++ix) | |
8313 | { | |
8314 | if (!self->regex | |
8315 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8316 | return; | |
8317 | } | |
8318 | } | |
8319 | ||
8320 | bs->stop = 0; | |
8321 | bs->print_it = print_it_noop; | |
8322 | } | |
8323 | ||
8324 | static enum print_stop_action | |
8325 | print_it_catch_solib (bpstat bs) | |
8326 | { | |
8327 | struct breakpoint *b = bs->breakpoint_at; | |
8328 | struct ui_out *uiout = current_uiout; | |
8329 | ||
8330 | annotate_catchpoint (b->number); | |
8331 | if (b->disposition == disp_del) | |
8332 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8333 | else | |
8334 | ui_out_text (uiout, "\nCatchpoint "); | |
8335 | ui_out_field_int (uiout, "bkptno", b->number); | |
8336 | ui_out_text (uiout, "\n"); | |
8337 | if (ui_out_is_mi_like_p (uiout)) | |
8338 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8339 | print_solib_event (1); | |
8340 | return PRINT_SRC_AND_LOC; | |
8341 | } | |
8342 | ||
8343 | static void | |
8344 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8345 | { | |
8346 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8347 | struct value_print_options opts; | |
8348 | struct ui_out *uiout = current_uiout; | |
8349 | char *msg; | |
8350 | ||
8351 | get_user_print_options (&opts); | |
8352 | /* Field 4, the address, is omitted (which makes the columns not | |
8353 | line up too nicely with the headers, but the effect is relatively | |
8354 | readable). */ | |
8355 | if (opts.addressprint) | |
8356 | { | |
8357 | annotate_field (4); | |
8358 | ui_out_field_skip (uiout, "addr"); | |
8359 | } | |
8360 | ||
8361 | annotate_field (5); | |
8362 | if (self->is_load) | |
8363 | { | |
8364 | if (self->regex) | |
8365 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8366 | else | |
8367 | msg = xstrdup (_("load of library")); | |
8368 | } | |
8369 | else | |
8370 | { | |
8371 | if (self->regex) | |
8372 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8373 | else | |
8374 | msg = xstrdup (_("unload of library")); | |
8375 | } | |
8376 | ui_out_field_string (uiout, "what", msg); | |
8377 | xfree (msg); | |
8ac3646f TT |
8378 | |
8379 | if (ui_out_is_mi_like_p (uiout)) | |
8380 | ui_out_field_string (uiout, "catch-type", | |
8381 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8382 | } |
8383 | ||
8384 | static void | |
8385 | print_mention_catch_solib (struct breakpoint *b) | |
8386 | { | |
8387 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8388 | ||
8389 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8390 | self->is_load ? "load" : "unload"); | |
8391 | } | |
8392 | ||
8393 | static void | |
8394 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8395 | { | |
8396 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8397 | ||
8398 | fprintf_unfiltered (fp, "%s %s", | |
8399 | b->disposition == disp_del ? "tcatch" : "catch", | |
8400 | self->is_load ? "load" : "unload"); | |
8401 | if (self->regex) | |
8402 | fprintf_unfiltered (fp, " %s", self->regex); | |
8403 | fprintf_unfiltered (fp, "\n"); | |
8404 | } | |
8405 | ||
8406 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8407 | ||
91985142 MG |
8408 | /* Shared helper function (MI and CLI) for creating and installing |
8409 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8410 | the events to be caught are load events, otherwise they are | |
8411 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8412 | temporary one. If ENABLED is non-zero the catchpoint is | |
8413 | created in an enabled state. */ | |
edcc5120 | 8414 | |
91985142 MG |
8415 | void |
8416 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8417 | { |
8418 | struct solib_catchpoint *c; | |
8419 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8420 | struct cleanup *cleanup; |
8421 | ||
edcc5120 TT |
8422 | if (!arg) |
8423 | arg = ""; | |
8424 | arg = skip_spaces (arg); | |
8425 | ||
8426 | c = XCNEW (struct solib_catchpoint); | |
8427 | cleanup = make_cleanup (xfree, c); | |
8428 | ||
8429 | if (*arg != '\0') | |
8430 | { | |
8431 | int errcode; | |
8432 | ||
8433 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8434 | if (errcode != 0) | |
8435 | { | |
8436 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8437 | ||
8438 | make_cleanup (xfree, err); | |
8439 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8440 | } | |
8441 | c->regex = xstrdup (arg); | |
8442 | } | |
8443 | ||
8444 | c->is_load = is_load; | |
91985142 | 8445 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8446 | &catch_solib_breakpoint_ops); |
8447 | ||
91985142 MG |
8448 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8449 | ||
edcc5120 TT |
8450 | discard_cleanups (cleanup); |
8451 | install_breakpoint (0, &c->base, 1); | |
8452 | } | |
8453 | ||
91985142 MG |
8454 | /* A helper function that does all the work for "catch load" and |
8455 | "catch unload". */ | |
8456 | ||
8457 | static void | |
8458 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8459 | struct cmd_list_element *command) | |
8460 | { | |
8461 | int tempflag; | |
8462 | const int enabled = 1; | |
8463 | ||
8464 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8465 | ||
8466 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8467 | } | |
8468 | ||
edcc5120 TT |
8469 | static void |
8470 | catch_load_command_1 (char *arg, int from_tty, | |
8471 | struct cmd_list_element *command) | |
8472 | { | |
8473 | catch_load_or_unload (arg, from_tty, 1, command); | |
8474 | } | |
8475 | ||
8476 | static void | |
8477 | catch_unload_command_1 (char *arg, int from_tty, | |
8478 | struct cmd_list_element *command) | |
8479 | { | |
8480 | catch_load_or_unload (arg, from_tty, 0, command); | |
8481 | } | |
8482 | ||
be5c67c1 PA |
8483 | /* An instance of this type is used to represent a syscall catchpoint. |
8484 | It includes a "struct breakpoint" as a kind of base class; users | |
8485 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8486 | really of this type iff its ops pointer points to | |
8487 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
8488 | ||
8489 | struct syscall_catchpoint | |
8490 | { | |
8491 | /* The base class. */ | |
8492 | struct breakpoint base; | |
8493 | ||
8494 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
8495 | syscall has been specified for filtering, its value is NULL. | |
8496 | Otherwise, it holds a list of all syscalls to be caught. The | |
8497 | list elements are allocated with xmalloc. */ | |
8498 | VEC(int) *syscalls_to_be_caught; | |
8499 | }; | |
8500 | ||
8501 | /* Implement the "dtor" breakpoint_ops method for syscall | |
8502 | catchpoints. */ | |
8503 | ||
8504 | static void | |
8505 | dtor_catch_syscall (struct breakpoint *b) | |
8506 | { | |
8507 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
8508 | ||
8509 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 8510 | |
2060206e | 8511 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
8512 | } |
8513 | ||
fa3064dd YQ |
8514 | static const struct inferior_data *catch_syscall_inferior_data = NULL; |
8515 | ||
8516 | struct catch_syscall_inferior_data | |
8517 | { | |
8518 | /* We keep a count of the number of times the user has requested a | |
8519 | particular syscall to be tracked, and pass this information to the | |
8520 | target. This lets capable targets implement filtering directly. */ | |
8521 | ||
8522 | /* Number of times that "any" syscall is requested. */ | |
8523 | int any_syscall_count; | |
8524 | ||
8525 | /* Count of each system call. */ | |
8526 | VEC(int) *syscalls_counts; | |
8527 | ||
8528 | /* This counts all syscall catch requests, so we can readily determine | |
8529 | if any catching is necessary. */ | |
8530 | int total_syscalls_count; | |
8531 | }; | |
8532 | ||
8533 | static struct catch_syscall_inferior_data* | |
8534 | get_catch_syscall_inferior_data (struct inferior *inf) | |
8535 | { | |
8536 | struct catch_syscall_inferior_data *inf_data; | |
8537 | ||
8538 | inf_data = inferior_data (inf, catch_syscall_inferior_data); | |
8539 | if (inf_data == NULL) | |
8540 | { | |
41bf6aca | 8541 | inf_data = XCNEW (struct catch_syscall_inferior_data); |
fa3064dd YQ |
8542 | set_inferior_data (inf, catch_syscall_inferior_data, inf_data); |
8543 | } | |
8544 | ||
8545 | return inf_data; | |
8546 | } | |
8547 | ||
8548 | static void | |
8549 | catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) | |
8550 | { | |
8551 | xfree (arg); | |
8552 | } | |
8553 | ||
8554 | ||
a96d9b2e SDJ |
8555 | /* Implement the "insert" breakpoint_ops method for syscall |
8556 | catchpoints. */ | |
8557 | ||
77b06cd7 TJB |
8558 | static int |
8559 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 8560 | { |
be5c67c1 | 8561 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8562 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8563 | struct catch_syscall_inferior_data *inf_data |
8564 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8565 | |
fa3064dd | 8566 | ++inf_data->total_syscalls_count; |
be5c67c1 | 8567 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8568 | ++inf_data->any_syscall_count; |
a96d9b2e SDJ |
8569 | else |
8570 | { | |
8571 | int i, iter; | |
cc59ec59 | 8572 | |
a96d9b2e | 8573 | for (i = 0; |
be5c67c1 | 8574 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8575 | i++) |
8576 | { | |
8577 | int elem; | |
cc59ec59 | 8578 | |
fa3064dd | 8579 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e | 8580 | { |
fa3064dd | 8581 | int old_size = VEC_length (int, inf_data->syscalls_counts); |
3e43a32a MS |
8582 | uintptr_t vec_addr_offset |
8583 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e | 8584 | uintptr_t vec_addr; |
fa3064dd YQ |
8585 | VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); |
8586 | vec_addr = ((uintptr_t) VEC_address (int, | |
8587 | inf_data->syscalls_counts) | |
8588 | + vec_addr_offset); | |
a96d9b2e SDJ |
8589 | memset ((void *) vec_addr, 0, |
8590 | (iter + 1 - old_size) * sizeof (int)); | |
8591 | } | |
fa3064dd YQ |
8592 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8593 | VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); | |
a96d9b2e SDJ |
8594 | } |
8595 | } | |
8596 | ||
dfd4cc63 | 8597 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8598 | inf_data->total_syscalls_count != 0, |
8599 | inf_data->any_syscall_count, | |
8600 | VEC_length (int, | |
8601 | inf_data->syscalls_counts), | |
8602 | VEC_address (int, | |
8603 | inf_data->syscalls_counts)); | |
a96d9b2e SDJ |
8604 | } |
8605 | ||
8606 | /* Implement the "remove" breakpoint_ops method for syscall | |
8607 | catchpoints. */ | |
8608 | ||
8609 | static int | |
77b06cd7 | 8610 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 8611 | { |
be5c67c1 | 8612 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8613 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8614 | struct catch_syscall_inferior_data *inf_data |
8615 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8616 | |
fa3064dd | 8617 | --inf_data->total_syscalls_count; |
be5c67c1 | 8618 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8619 | --inf_data->any_syscall_count; |
a96d9b2e SDJ |
8620 | else |
8621 | { | |
8622 | int i, iter; | |
cc59ec59 | 8623 | |
a96d9b2e | 8624 | for (i = 0; |
be5c67c1 | 8625 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8626 | i++) |
8627 | { | |
8628 | int elem; | |
fa3064dd | 8629 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e SDJ |
8630 | /* Shouldn't happen. */ |
8631 | continue; | |
fa3064dd YQ |
8632 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8633 | VEC_replace (int, inf_data->syscalls_counts, iter, --elem); | |
a96d9b2e SDJ |
8634 | } |
8635 | } | |
8636 | ||
dfd4cc63 | 8637 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8638 | inf_data->total_syscalls_count != 0, |
8639 | inf_data->any_syscall_count, | |
8640 | VEC_length (int, | |
8641 | inf_data->syscalls_counts), | |
3e43a32a | 8642 | VEC_address (int, |
fa3064dd | 8643 | inf_data->syscalls_counts)); |
a96d9b2e SDJ |
8644 | } |
8645 | ||
8646 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
8647 | catchpoints. */ | |
8648 | ||
8649 | static int | |
f1310107 | 8650 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
8651 | struct address_space *aspace, CORE_ADDR bp_addr, |
8652 | const struct target_waitstatus *ws) | |
a96d9b2e | 8653 | { |
4a64f543 MS |
8654 | /* We must check if we are catching specific syscalls in this |
8655 | breakpoint. If we are, then we must guarantee that the called | |
8656 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 8657 | int syscall_number = 0; |
be5c67c1 PA |
8658 | const struct syscall_catchpoint *c |
8659 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 8660 | |
f90263c1 TT |
8661 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
8662 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
8663 | return 0; |
8664 | ||
f90263c1 TT |
8665 | syscall_number = ws->value.syscall_number; |
8666 | ||
a96d9b2e | 8667 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 8668 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8669 | { |
8670 | int i, iter; | |
cc59ec59 | 8671 | |
a96d9b2e | 8672 | for (i = 0; |
be5c67c1 | 8673 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8674 | i++) |
8675 | if (syscall_number == iter) | |
4924df79 GKB |
8676 | return 1; |
8677 | ||
8678 | return 0; | |
a96d9b2e SDJ |
8679 | } |
8680 | ||
8681 | return 1; | |
8682 | } | |
8683 | ||
8684 | /* Implement the "print_it" breakpoint_ops method for syscall | |
8685 | catchpoints. */ | |
8686 | ||
8687 | static enum print_stop_action | |
348d480f | 8688 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 8689 | { |
36dfb11c | 8690 | struct ui_out *uiout = current_uiout; |
348d480f | 8691 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
8692 | /* These are needed because we want to know in which state a |
8693 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
8694 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
8695 | must print "called syscall" or "returned from syscall". */ | |
8696 | ptid_t ptid; | |
8697 | struct target_waitstatus last; | |
8698 | struct syscall s; | |
a96d9b2e SDJ |
8699 | |
8700 | get_last_target_status (&ptid, &last); | |
8701 | ||
8702 | get_syscall_by_number (last.value.syscall_number, &s); | |
8703 | ||
8704 | annotate_catchpoint (b->number); | |
8705 | ||
36dfb11c TT |
8706 | if (b->disposition == disp_del) |
8707 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 8708 | else |
36dfb11c TT |
8709 | ui_out_text (uiout, "\nCatchpoint "); |
8710 | if (ui_out_is_mi_like_p (uiout)) | |
8711 | { | |
8712 | ui_out_field_string (uiout, "reason", | |
8713 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
8714 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
8715 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
8716 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8717 | } | |
8718 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
8719 | |
8720 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
8721 | ui_out_text (uiout, " (call to syscall "); |
8722 | else | |
8723 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 8724 | |
36dfb11c TT |
8725 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
8726 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
8727 | if (s.name != NULL) | |
8728 | ui_out_field_string (uiout, "syscall-name", s.name); | |
8729 | ||
8730 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
8731 | |
8732 | return PRINT_SRC_AND_LOC; | |
8733 | } | |
8734 | ||
8735 | /* Implement the "print_one" breakpoint_ops method for syscall | |
8736 | catchpoints. */ | |
8737 | ||
8738 | static void | |
8739 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 8740 | struct bp_location **last_loc) |
a96d9b2e | 8741 | { |
be5c67c1 | 8742 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 8743 | struct value_print_options opts; |
79a45e25 | 8744 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
8745 | |
8746 | get_user_print_options (&opts); | |
4a64f543 MS |
8747 | /* Field 4, the address, is omitted (which makes the columns not |
8748 | line up too nicely with the headers, but the effect is relatively | |
8749 | readable). */ | |
a96d9b2e SDJ |
8750 | if (opts.addressprint) |
8751 | ui_out_field_skip (uiout, "addr"); | |
8752 | annotate_field (5); | |
8753 | ||
be5c67c1 PA |
8754 | if (c->syscalls_to_be_caught |
8755 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
8756 | ui_out_text (uiout, "syscalls \""); |
8757 | else | |
8758 | ui_out_text (uiout, "syscall \""); | |
8759 | ||
be5c67c1 | 8760 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8761 | { |
8762 | int i, iter; | |
8763 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 8764 | |
a96d9b2e | 8765 | for (i = 0; |
be5c67c1 | 8766 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8767 | i++) |
8768 | { | |
8769 | char *x = text; | |
8770 | struct syscall s; | |
8771 | get_syscall_by_number (iter, &s); | |
8772 | ||
8773 | if (s.name != NULL) | |
8774 | text = xstrprintf ("%s%s, ", text, s.name); | |
8775 | else | |
8776 | text = xstrprintf ("%s%d, ", text, iter); | |
8777 | ||
8778 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 8779 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
8780 | on every call. */ |
8781 | xfree (x); | |
8782 | } | |
8783 | /* Remove the last comma. */ | |
8784 | text[strlen (text) - 2] = '\0'; | |
8785 | ui_out_field_string (uiout, "what", text); | |
8786 | } | |
8787 | else | |
8788 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
8789 | ui_out_text (uiout, "\" "); | |
8ac3646f TT |
8790 | |
8791 | if (ui_out_is_mi_like_p (uiout)) | |
8792 | ui_out_field_string (uiout, "catch-type", "syscall"); | |
a96d9b2e SDJ |
8793 | } |
8794 | ||
8795 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
8796 | catchpoints. */ | |
8797 | ||
8798 | static void | |
8799 | print_mention_catch_syscall (struct breakpoint *b) | |
8800 | { | |
be5c67c1 PA |
8801 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8802 | ||
8803 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
8804 | { |
8805 | int i, iter; | |
8806 | ||
be5c67c1 | 8807 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
8808 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
8809 | else | |
8810 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
8811 | ||
8812 | for (i = 0; | |
be5c67c1 | 8813 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8814 | i++) |
8815 | { | |
8816 | struct syscall s; | |
8817 | get_syscall_by_number (iter, &s); | |
8818 | ||
8819 | if (s.name) | |
8820 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
8821 | else | |
8822 | printf_filtered (" %d", s.number); | |
8823 | } | |
8824 | printf_filtered (")"); | |
8825 | } | |
8826 | else | |
8827 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
8828 | b->number); | |
8829 | } | |
8830 | ||
6149aea9 PA |
8831 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
8832 | catchpoints. */ | |
8833 | ||
8834 | static void | |
8835 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
8836 | { | |
be5c67c1 PA |
8837 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
8838 | ||
6149aea9 PA |
8839 | fprintf_unfiltered (fp, "catch syscall"); |
8840 | ||
be5c67c1 | 8841 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
8842 | { |
8843 | int i, iter; | |
8844 | ||
8845 | for (i = 0; | |
be5c67c1 | 8846 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
8847 | i++) |
8848 | { | |
8849 | struct syscall s; | |
8850 | ||
8851 | get_syscall_by_number (iter, &s); | |
8852 | if (s.name) | |
8853 | fprintf_unfiltered (fp, " %s", s.name); | |
8854 | else | |
8855 | fprintf_unfiltered (fp, " %d", s.number); | |
8856 | } | |
8857 | } | |
d9b3f62e | 8858 | print_recreate_thread (b, fp); |
6149aea9 PA |
8859 | } |
8860 | ||
a96d9b2e SDJ |
8861 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
8862 | ||
2060206e | 8863 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
8864 | |
8865 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
8866 | ||
8867 | static int | |
8868 | syscall_catchpoint_p (struct breakpoint *b) | |
8869 | { | |
8870 | return (b->ops == &catch_syscall_breakpoint_ops); | |
8871 | } | |
8872 | ||
346774a9 PA |
8873 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8874 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8875 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8876 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8877 | |
ab04a2af | 8878 | void |
346774a9 PA |
8879 | init_catchpoint (struct breakpoint *b, |
8880 | struct gdbarch *gdbarch, int tempflag, | |
8881 | char *cond_string, | |
c0a91b2b | 8882 | const struct breakpoint_ops *ops) |
c906108c | 8883 | { |
c5aa993b | 8884 | struct symtab_and_line sal; |
346774a9 | 8885 | |
fe39c653 | 8886 | init_sal (&sal); |
6c95b8df | 8887 | sal.pspace = current_program_space; |
c5aa993b | 8888 | |
28010a5d | 8889 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8890 | |
1b36a34b | 8891 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8892 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8893 | } |
8894 | ||
28010a5d | 8895 | void |
3ea46bff | 8896 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8897 | { |
8898 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8899 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8900 | if (is_tracepoint (b)) |
8901 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8902 | if (!internal) |
8903 | mention (b); | |
c56053d2 | 8904 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8905 | |
8906 | if (update_gll) | |
44702360 | 8907 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8908 | } |
8909 | ||
9b70b993 | 8910 | static void |
a6d9a66e UW |
8911 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8912 | int tempflag, char *cond_string, | |
c0a91b2b | 8913 | const struct breakpoint_ops *ops) |
c906108c | 8914 | { |
e29a4733 | 8915 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8916 | |
e29a4733 PA |
8917 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8918 | ||
8919 | c->forked_inferior_pid = null_ptid; | |
8920 | ||
3ea46bff | 8921 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8922 | } |
8923 | ||
fe798b75 JB |
8924 | /* Exec catchpoints. */ |
8925 | ||
b4d90040 PA |
8926 | /* An instance of this type is used to represent an exec catchpoint. |
8927 | It includes a "struct breakpoint" as a kind of base class; users | |
8928 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8929 | really of this type iff its ops pointer points to | |
8930 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8931 | ||
8932 | struct exec_catchpoint | |
8933 | { | |
8934 | /* The base class. */ | |
8935 | struct breakpoint base; | |
8936 | ||
8937 | /* Filename of a program whose exec triggered this catchpoint. | |
8938 | This field is only valid immediately after this catchpoint has | |
8939 | triggered. */ | |
8940 | char *exec_pathname; | |
8941 | }; | |
8942 | ||
8943 | /* Implement the "dtor" breakpoint_ops method for exec | |
8944 | catchpoints. */ | |
8945 | ||
8946 | static void | |
8947 | dtor_catch_exec (struct breakpoint *b) | |
8948 | { | |
8949 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8950 | ||
8951 | xfree (c->exec_pathname); | |
348d480f | 8952 | |
2060206e | 8953 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8954 | } |
8955 | ||
77b06cd7 TJB |
8956 | static int |
8957 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8958 | { |
dfd4cc63 | 8959 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8960 | } |
c906108c | 8961 | |
fe798b75 | 8962 | static int |
77b06cd7 | 8963 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8964 | { |
dfd4cc63 | 8965 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8966 | } |
c906108c | 8967 | |
fe798b75 | 8968 | static int |
f1310107 | 8969 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8970 | struct address_space *aspace, CORE_ADDR bp_addr, |
8971 | const struct target_waitstatus *ws) | |
fe798b75 | 8972 | { |
b4d90040 PA |
8973 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8974 | ||
f90263c1 TT |
8975 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8976 | return 0; | |
8977 | ||
8978 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8979 | return 1; | |
fe798b75 | 8980 | } |
c906108c | 8981 | |
fe798b75 | 8982 | static enum print_stop_action |
348d480f | 8983 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8984 | { |
36dfb11c | 8985 | struct ui_out *uiout = current_uiout; |
348d480f | 8986 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8987 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8988 | ||
fe798b75 | 8989 | annotate_catchpoint (b->number); |
36dfb11c TT |
8990 | if (b->disposition == disp_del) |
8991 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8992 | else | |
8993 | ui_out_text (uiout, "\nCatchpoint "); | |
8994 | if (ui_out_is_mi_like_p (uiout)) | |
8995 | { | |
8996 | ui_out_field_string (uiout, "reason", | |
8997 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8998 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8999 | } | |
9000 | ui_out_field_int (uiout, "bkptno", b->number); | |
9001 | ui_out_text (uiout, " (exec'd "); | |
9002 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
9003 | ui_out_text (uiout, "), "); | |
9004 | ||
fe798b75 | 9005 | return PRINT_SRC_AND_LOC; |
c906108c SS |
9006 | } |
9007 | ||
fe798b75 | 9008 | static void |
a6d9a66e | 9009 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 9010 | { |
b4d90040 | 9011 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 9012 | struct value_print_options opts; |
79a45e25 | 9013 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
9014 | |
9015 | get_user_print_options (&opts); | |
9016 | ||
9017 | /* Field 4, the address, is omitted (which makes the columns | |
9018 | not line up too nicely with the headers, but the effect | |
9019 | is relatively readable). */ | |
9020 | if (opts.addressprint) | |
9021 | ui_out_field_skip (uiout, "addr"); | |
9022 | annotate_field (5); | |
9023 | ui_out_text (uiout, "exec"); | |
b4d90040 | 9024 | if (c->exec_pathname != NULL) |
fe798b75 JB |
9025 | { |
9026 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 9027 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
9028 | ui_out_text (uiout, "\" "); |
9029 | } | |
8ac3646f TT |
9030 | |
9031 | if (ui_out_is_mi_like_p (uiout)) | |
9032 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
9033 | } |
9034 | ||
9035 | static void | |
9036 | print_mention_catch_exec (struct breakpoint *b) | |
9037 | { | |
9038 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
9039 | } | |
9040 | ||
6149aea9 PA |
9041 | /* Implement the "print_recreate" breakpoint_ops method for exec |
9042 | catchpoints. */ | |
9043 | ||
9044 | static void | |
9045 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
9046 | { | |
9047 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 9048 | print_recreate_thread (b, fp); |
6149aea9 PA |
9049 | } |
9050 | ||
2060206e | 9051 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 9052 | |
a96d9b2e SDJ |
9053 | static void |
9054 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 9055 | const struct breakpoint_ops *ops) |
a96d9b2e | 9056 | { |
be5c67c1 | 9057 | struct syscall_catchpoint *c; |
a96d9b2e | 9058 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 9059 | |
be5c67c1 PA |
9060 | c = XNEW (struct syscall_catchpoint); |
9061 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
9062 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 9063 | |
3ea46bff | 9064 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
9065 | } |
9066 | ||
c906108c | 9067 | static int |
fba45db2 | 9068 | hw_breakpoint_used_count (void) |
c906108c | 9069 | { |
c906108c | 9070 | int i = 0; |
f1310107 TJB |
9071 | struct breakpoint *b; |
9072 | struct bp_location *bl; | |
c906108c SS |
9073 | |
9074 | ALL_BREAKPOINTS (b) | |
c5aa993b | 9075 | { |
d6b74ac4 | 9076 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
9077 | for (bl = b->loc; bl; bl = bl->next) |
9078 | { | |
9079 | /* Special types of hardware breakpoints may use more than | |
9080 | one register. */ | |
348d480f | 9081 | i += b->ops->resources_needed (bl); |
f1310107 | 9082 | } |
c5aa993b | 9083 | } |
c906108c SS |
9084 | |
9085 | return i; | |
9086 | } | |
9087 | ||
a1398e0c PA |
9088 | /* Returns the resources B would use if it were a hardware |
9089 | watchpoint. */ | |
9090 | ||
c906108c | 9091 | static int |
a1398e0c | 9092 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 9093 | { |
c906108c | 9094 | int i = 0; |
e09342b5 | 9095 | struct bp_location *bl; |
c906108c | 9096 | |
a1398e0c PA |
9097 | if (!breakpoint_enabled (b)) |
9098 | return 0; | |
9099 | ||
9100 | for (bl = b->loc; bl; bl = bl->next) | |
9101 | { | |
9102 | /* Special types of hardware watchpoints may use more than | |
9103 | one register. */ | |
9104 | i += b->ops->resources_needed (bl); | |
9105 | } | |
9106 | ||
9107 | return i; | |
9108 | } | |
9109 | ||
9110 | /* Returns the sum the used resources of all hardware watchpoints of | |
9111 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
9112 | the sum of the used resources of all hardware watchpoints of other | |
9113 | types _not_ TYPE. */ | |
9114 | ||
9115 | static int | |
9116 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
9117 | enum bptype type, int *other_type_used) | |
9118 | { | |
9119 | int i = 0; | |
9120 | struct breakpoint *b; | |
9121 | ||
c906108c SS |
9122 | *other_type_used = 0; |
9123 | ALL_BREAKPOINTS (b) | |
e09342b5 | 9124 | { |
a1398e0c PA |
9125 | if (b == except) |
9126 | continue; | |
e09342b5 TJB |
9127 | if (!breakpoint_enabled (b)) |
9128 | continue; | |
9129 | ||
a1398e0c PA |
9130 | if (b->type == type) |
9131 | i += hw_watchpoint_use_count (b); | |
9132 | else if (is_hardware_watchpoint (b)) | |
9133 | *other_type_used = 1; | |
e09342b5 TJB |
9134 | } |
9135 | ||
c906108c SS |
9136 | return i; |
9137 | } | |
9138 | ||
c906108c | 9139 | void |
fba45db2 | 9140 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 9141 | { |
c5aa993b | 9142 | struct breakpoint *b; |
c906108c SS |
9143 | |
9144 | ALL_BREAKPOINTS (b) | |
c5aa993b | 9145 | { |
cc60f2e3 | 9146 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 9147 | { |
b5de0fa7 | 9148 | b->enable_state = bp_call_disabled; |
44702360 | 9149 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
9150 | } |
9151 | } | |
c906108c SS |
9152 | } |
9153 | ||
9154 | void | |
fba45db2 | 9155 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 9156 | { |
c5aa993b | 9157 | struct breakpoint *b; |
c906108c SS |
9158 | |
9159 | ALL_BREAKPOINTS (b) | |
c5aa993b | 9160 | { |
cc60f2e3 | 9161 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 9162 | { |
b5de0fa7 | 9163 | b->enable_state = bp_enabled; |
44702360 | 9164 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
9165 | } |
9166 | } | |
c906108c SS |
9167 | } |
9168 | ||
8bea4e01 UW |
9169 | void |
9170 | disable_breakpoints_before_startup (void) | |
9171 | { | |
6c95b8df | 9172 | current_program_space->executing_startup = 1; |
44702360 | 9173 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
9174 | } |
9175 | ||
9176 | void | |
9177 | enable_breakpoints_after_startup (void) | |
9178 | { | |
6c95b8df | 9179 | current_program_space->executing_startup = 0; |
f8eba3c6 | 9180 | breakpoint_re_set (); |
8bea4e01 UW |
9181 | } |
9182 | ||
c906108c SS |
9183 | |
9184 | /* Set a breakpoint that will evaporate an end of command | |
9185 | at address specified by SAL. | |
9186 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
9187 | ||
9188 | struct breakpoint * | |
a6d9a66e UW |
9189 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
9190 | struct frame_id frame_id, enum bptype type) | |
c906108c | 9191 | { |
52f0bd74 | 9192 | struct breakpoint *b; |
edb3359d | 9193 | |
193facb3 JK |
9194 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
9195 | tail-called one. */ | |
9196 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 9197 | |
06edf0c0 | 9198 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
9199 | b->enable_state = bp_enabled; |
9200 | b->disposition = disp_donttouch; | |
818dd999 | 9201 | b->frame_id = frame_id; |
c906108c | 9202 | |
4a64f543 MS |
9203 | /* If we're debugging a multi-threaded program, then we want |
9204 | momentary breakpoints to be active in only a single thread of | |
9205 | control. */ | |
39f77062 KB |
9206 | if (in_thread_list (inferior_ptid)) |
9207 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 9208 | |
44702360 | 9209 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 9210 | |
c906108c SS |
9211 | return b; |
9212 | } | |
611c83ae | 9213 | |
06edf0c0 | 9214 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
9215 | The new breakpoint will have type TYPE, use OPS as its |
9216 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 9217 | |
06edf0c0 PA |
9218 | static struct breakpoint * |
9219 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
9220 | enum bptype type, | |
a1aa2221 LM |
9221 | const struct breakpoint_ops *ops, |
9222 | int loc_enabled) | |
e58b0e63 PA |
9223 | { |
9224 | struct breakpoint *copy; | |
9225 | ||
06edf0c0 | 9226 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 9227 | copy->loc = allocate_bp_location (copy); |
0e30163f | 9228 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 9229 | |
a6d9a66e | 9230 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
9231 | copy->loc->requested_address = orig->loc->requested_address; |
9232 | copy->loc->address = orig->loc->address; | |
9233 | copy->loc->section = orig->loc->section; | |
6c95b8df | 9234 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 9235 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 9236 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 9237 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 9238 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
9239 | copy->frame_id = orig->frame_id; |
9240 | copy->thread = orig->thread; | |
6c95b8df | 9241 | copy->pspace = orig->pspace; |
e58b0e63 PA |
9242 | |
9243 | copy->enable_state = bp_enabled; | |
9244 | copy->disposition = disp_donttouch; | |
9245 | copy->number = internal_breakpoint_number--; | |
9246 | ||
44702360 | 9247 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
9248 | return copy; |
9249 | } | |
9250 | ||
06edf0c0 PA |
9251 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
9252 | ORIG is NULL. */ | |
9253 | ||
9254 | struct breakpoint * | |
9255 | clone_momentary_breakpoint (struct breakpoint *orig) | |
9256 | { | |
9257 | /* If there's nothing to clone, then return nothing. */ | |
9258 | if (orig == NULL) | |
9259 | return NULL; | |
9260 | ||
a1aa2221 | 9261 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
9262 | } |
9263 | ||
611c83ae | 9264 | struct breakpoint * |
a6d9a66e UW |
9265 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
9266 | enum bptype type) | |
611c83ae PA |
9267 | { |
9268 | struct symtab_and_line sal; | |
9269 | ||
9270 | sal = find_pc_line (pc, 0); | |
9271 | sal.pc = pc; | |
9272 | sal.section = find_pc_overlay (pc); | |
9273 | sal.explicit_pc = 1; | |
9274 | ||
a6d9a66e | 9275 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 9276 | } |
c906108c | 9277 | \f |
c5aa993b | 9278 | |
c906108c SS |
9279 | /* Tell the user we have just set a breakpoint B. */ |
9280 | ||
9281 | static void | |
fba45db2 | 9282 | mention (struct breakpoint *b) |
c906108c | 9283 | { |
348d480f | 9284 | b->ops->print_mention (b); |
79a45e25 | 9285 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 9286 | return; |
c906108c SS |
9287 | printf_filtered ("\n"); |
9288 | } | |
c906108c | 9289 | \f |
c5aa993b | 9290 | |
0d381245 | 9291 | static struct bp_location * |
39d61571 | 9292 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
9293 | const struct symtab_and_line *sal) |
9294 | { | |
9295 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9296 | CORE_ADDR adjusted_address; |
9297 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9298 | ||
9299 | if (loc_gdbarch == NULL) | |
9300 | loc_gdbarch = b->gdbarch; | |
9301 | ||
9302 | /* Adjust the breakpoint's address prior to allocating a location. | |
9303 | Once we call allocate_bp_location(), that mostly uninitialized | |
9304 | location will be placed on the location chain. Adjustment of the | |
9305 | breakpoint may cause target_read_memory() to be called and we do | |
9306 | not want its scan of the location chain to find a breakpoint and | |
9307 | location that's only been partially initialized. */ | |
9308 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9309 | sal->pc, b->type); | |
0d381245 | 9310 | |
d30113d4 | 9311 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9312 | loc = allocate_bp_location (b); |
d30113d4 JK |
9313 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9314 | tmp = &((*tmp)->next)) | |
0d381245 | 9315 | ; |
d30113d4 | 9316 | loc->next = *tmp; |
0d381245 | 9317 | *tmp = loc; |
3742cc8b | 9318 | |
0d381245 | 9319 | loc->requested_address = sal->pc; |
3742cc8b | 9320 | loc->address = adjusted_address; |
6c95b8df | 9321 | loc->pspace = sal->pspace; |
729662a5 TT |
9322 | loc->probe.probe = sal->probe; |
9323 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9324 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9325 | loc->section = sal->section; |
3742cc8b | 9326 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9327 | loc->line_number = sal->line; |
2f202fde | 9328 | loc->symtab = sal->symtab; |
f8eba3c6 | 9329 | |
0e30163f JK |
9330 | set_breakpoint_location_function (loc, |
9331 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
9332 | return loc; |
9333 | } | |
514f746b AR |
9334 | \f |
9335 | ||
9336 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9337 | return 0 otherwise. */ | |
9338 | ||
9339 | static int | |
9340 | bp_loc_is_permanent (struct bp_location *loc) | |
9341 | { | |
9342 | int len; | |
9343 | CORE_ADDR addr; | |
1afeeb75 | 9344 | const gdb_byte *bpoint; |
514f746b | 9345 | gdb_byte *target_mem; |
939c61fa JK |
9346 | struct cleanup *cleanup; |
9347 | int retval = 0; | |
514f746b AR |
9348 | |
9349 | gdb_assert (loc != NULL); | |
9350 | ||
9351 | addr = loc->address; | |
1afeeb75 | 9352 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 9353 | |
939c61fa | 9354 | /* Software breakpoints unsupported? */ |
1afeeb75 | 9355 | if (bpoint == NULL) |
939c61fa JK |
9356 | return 0; |
9357 | ||
514f746b AR |
9358 | target_mem = alloca (len); |
9359 | ||
939c61fa JK |
9360 | /* Enable the automatic memory restoration from breakpoints while |
9361 | we read the memory. Otherwise we could say about our temporary | |
9362 | breakpoints they are permanent. */ | |
6c95b8df PA |
9363 | cleanup = save_current_space_and_thread (); |
9364 | ||
9365 | switch_to_program_space_and_thread (loc->pspace); | |
9366 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 9367 | |
514f746b | 9368 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 9369 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 9370 | retval = 1; |
514f746b | 9371 | |
939c61fa JK |
9372 | do_cleanups (cleanup); |
9373 | ||
9374 | return retval; | |
514f746b AR |
9375 | } |
9376 | ||
e7e0cddf SS |
9377 | /* Build a command list for the dprintf corresponding to the current |
9378 | settings of the dprintf style options. */ | |
9379 | ||
9380 | static void | |
9381 | update_dprintf_command_list (struct breakpoint *b) | |
9382 | { | |
9383 | char *dprintf_args = b->extra_string; | |
9384 | char *printf_line = NULL; | |
9385 | ||
9386 | if (!dprintf_args) | |
9387 | return; | |
9388 | ||
9389 | dprintf_args = skip_spaces (dprintf_args); | |
9390 | ||
9391 | /* Allow a comma, as it may have terminated a location, but don't | |
9392 | insist on it. */ | |
9393 | if (*dprintf_args == ',') | |
9394 | ++dprintf_args; | |
9395 | dprintf_args = skip_spaces (dprintf_args); | |
9396 | ||
9397 | if (*dprintf_args != '"') | |
9398 | error (_("Bad format string, missing '\"'.")); | |
9399 | ||
d3ce09f5 | 9400 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9401 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9402 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9403 | { |
9404 | if (!dprintf_function) | |
9405 | error (_("No function supplied for dprintf call")); | |
9406 | ||
9407 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9408 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9409 | dprintf_function, | |
9410 | dprintf_channel, | |
9411 | dprintf_args); | |
9412 | else | |
9413 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9414 | dprintf_function, | |
9415 | dprintf_args); | |
9416 | } | |
d3ce09f5 SS |
9417 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9418 | { | |
9419 | if (target_can_run_breakpoint_commands ()) | |
9420 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9421 | else | |
9422 | { | |
9423 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9424 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9425 | } | |
9426 | } | |
e7e0cddf SS |
9427 | else |
9428 | internal_error (__FILE__, __LINE__, | |
9429 | _("Invalid dprintf style.")); | |
9430 | ||
f28045c2 | 9431 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9432 | /* Manufacture a printf sequence. */ |
f28045c2 | 9433 | { |
9d6e6e84 HZ |
9434 | struct command_line *printf_cmd_line |
9435 | = xmalloc (sizeof (struct command_line)); | |
e7e0cddf | 9436 | |
f28045c2 YQ |
9437 | printf_cmd_line = xmalloc (sizeof (struct command_line)); |
9438 | printf_cmd_line->control_type = simple_control; | |
9439 | printf_cmd_line->body_count = 0; | |
9440 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9441 | printf_cmd_line->next = NULL; |
f28045c2 | 9442 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9443 | |
f28045c2 YQ |
9444 | breakpoint_set_commands (b, printf_cmd_line); |
9445 | } | |
e7e0cddf SS |
9446 | } |
9447 | ||
9448 | /* Update all dprintf commands, making their command lists reflect | |
9449 | current style settings. */ | |
9450 | ||
9451 | static void | |
9452 | update_dprintf_commands (char *args, int from_tty, | |
9453 | struct cmd_list_element *c) | |
9454 | { | |
9455 | struct breakpoint *b; | |
9456 | ||
9457 | ALL_BREAKPOINTS (b) | |
9458 | { | |
9459 | if (b->type == bp_dprintf) | |
9460 | update_dprintf_command_list (b); | |
9461 | } | |
9462 | } | |
c3f6f71d | 9463 | |
018d34a4 VP |
9464 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
9465 | as textual description of the location, and COND_STRING | |
db107f19 | 9466 | as condition expression. */ |
018d34a4 VP |
9467 | |
9468 | static void | |
d9b3f62e PA |
9469 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
9470 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9471 | char *filter, char *cond_string, |
e7e0cddf | 9472 | char *extra_string, |
d9b3f62e PA |
9473 | enum bptype type, enum bpdisp disposition, |
9474 | int thread, int task, int ignore_count, | |
c0a91b2b | 9475 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9476 | int enabled, int internal, unsigned flags, |
9477 | int display_canonical) | |
018d34a4 | 9478 | { |
0d381245 | 9479 | int i; |
018d34a4 VP |
9480 | |
9481 | if (type == bp_hardware_breakpoint) | |
9482 | { | |
fbbd034e AS |
9483 | int target_resources_ok; |
9484 | ||
9485 | i = hw_breakpoint_used_count (); | |
9486 | target_resources_ok = | |
9487 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9488 | i + 1, 0); |
9489 | if (target_resources_ok == 0) | |
9490 | error (_("No hardware breakpoint support in the target.")); | |
9491 | else if (target_resources_ok < 0) | |
9492 | error (_("Hardware breakpoints used exceeds limit.")); | |
9493 | } | |
9494 | ||
6c95b8df PA |
9495 | gdb_assert (sals.nelts > 0); |
9496 | ||
0d381245 VP |
9497 | for (i = 0; i < sals.nelts; ++i) |
9498 | { | |
9499 | struct symtab_and_line sal = sals.sals[i]; | |
9500 | struct bp_location *loc; | |
9501 | ||
9502 | if (from_tty) | |
5af949e3 UW |
9503 | { |
9504 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9505 | if (!loc_gdbarch) | |
9506 | loc_gdbarch = gdbarch; | |
9507 | ||
9508 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9509 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9510 | } |
0d381245 VP |
9511 | |
9512 | if (i == 0) | |
9513 | { | |
d9b3f62e | 9514 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9515 | b->thread = thread; |
4a306c9a | 9516 | b->task = task; |
855a6e68 | 9517 | |
0d381245 | 9518 | b->cond_string = cond_string; |
e7e0cddf | 9519 | b->extra_string = extra_string; |
0d381245 | 9520 | b->ignore_count = ignore_count; |
41447f92 | 9521 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9522 | b->disposition = disposition; |
6c95b8df | 9523 | |
44f238bb PA |
9524 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9525 | b->loc->inserted = 1; | |
9526 | ||
0fb4aa4b PA |
9527 | if (type == bp_static_tracepoint) |
9528 | { | |
d9b3f62e | 9529 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9530 | struct static_tracepoint_marker marker; |
9531 | ||
983af33b | 9532 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9533 | { |
9534 | /* We already know the marker exists, otherwise, we | |
9535 | wouldn't see a sal for it. */ | |
9536 | char *p = &addr_string[3]; | |
9537 | char *endp; | |
9538 | char *marker_str; | |
0fb4aa4b | 9539 | |
e9cafbcc | 9540 | p = skip_spaces (p); |
0fb4aa4b | 9541 | |
e9cafbcc | 9542 | endp = skip_to_space (p); |
0fb4aa4b PA |
9543 | |
9544 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9545 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9546 | |
3e43a32a MS |
9547 | printf_filtered (_("Probed static tracepoint " |
9548 | "marker \"%s\"\n"), | |
d9b3f62e | 9549 | t->static_trace_marker_id); |
0fb4aa4b PA |
9550 | } |
9551 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9552 | { | |
d9b3f62e | 9553 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9554 | release_static_tracepoint_marker (&marker); |
9555 | ||
3e43a32a MS |
9556 | printf_filtered (_("Probed static tracepoint " |
9557 | "marker \"%s\"\n"), | |
d9b3f62e | 9558 | t->static_trace_marker_id); |
0fb4aa4b PA |
9559 | } |
9560 | else | |
3e43a32a MS |
9561 | warning (_("Couldn't determine the static " |
9562 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9563 | } |
9564 | ||
0d381245 VP |
9565 | loc = b->loc; |
9566 | } | |
9567 | else | |
018d34a4 | 9568 | { |
39d61571 | 9569 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9570 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9571 | loc->inserted = 1; | |
0d381245 VP |
9572 | } |
9573 | ||
514f746b AR |
9574 | if (bp_loc_is_permanent (loc)) |
9575 | make_breakpoint_permanent (b); | |
9576 | ||
0d381245 VP |
9577 | if (b->cond_string) |
9578 | { | |
bbc13ae3 KS |
9579 | const char *arg = b->cond_string; |
9580 | ||
1bb9788d TT |
9581 | loc->cond = parse_exp_1 (&arg, loc->address, |
9582 | block_for_pc (loc->address), 0); | |
0d381245 | 9583 | if (*arg) |
588ae58c | 9584 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9585 | } |
e7e0cddf SS |
9586 | |
9587 | /* Dynamic printf requires and uses additional arguments on the | |
9588 | command line, otherwise it's an error. */ | |
9589 | if (type == bp_dprintf) | |
9590 | { | |
9591 | if (b->extra_string) | |
9592 | update_dprintf_command_list (b); | |
9593 | else | |
9594 | error (_("Format string required")); | |
9595 | } | |
9596 | else if (b->extra_string) | |
588ae58c | 9597 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9598 | } |
018d34a4 | 9599 | |
56435ebe | 9600 | b->display_canonical = display_canonical; |
018d34a4 VP |
9601 | if (addr_string) |
9602 | b->addr_string = addr_string; | |
9603 | else | |
9604 | /* addr_string has to be used or breakpoint_re_set will delete | |
9605 | me. */ | |
5af949e3 UW |
9606 | b->addr_string |
9607 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 9608 | b->filter = filter; |
d9b3f62e | 9609 | } |
018d34a4 | 9610 | |
d9b3f62e PA |
9611 | static void |
9612 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
9613 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9614 | char *filter, char *cond_string, |
e7e0cddf | 9615 | char *extra_string, |
d9b3f62e PA |
9616 | enum bptype type, enum bpdisp disposition, |
9617 | int thread, int task, int ignore_count, | |
c0a91b2b | 9618 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9619 | int enabled, int internal, unsigned flags, |
9620 | int display_canonical) | |
d9b3f62e PA |
9621 | { |
9622 | struct breakpoint *b; | |
9623 | struct cleanup *old_chain; | |
9624 | ||
9625 | if (is_tracepoint_type (type)) | |
9626 | { | |
9627 | struct tracepoint *t; | |
9628 | ||
9629 | t = XCNEW (struct tracepoint); | |
9630 | b = &t->base; | |
9631 | } | |
9632 | else | |
9633 | b = XNEW (struct breakpoint); | |
9634 | ||
9635 | old_chain = make_cleanup (xfree, b); | |
9636 | ||
9637 | init_breakpoint_sal (b, gdbarch, | |
9638 | sals, addr_string, | |
e7e0cddf | 9639 | filter, cond_string, extra_string, |
d9b3f62e PA |
9640 | type, disposition, |
9641 | thread, task, ignore_count, | |
9642 | ops, from_tty, | |
44f238bb PA |
9643 | enabled, internal, flags, |
9644 | display_canonical); | |
d9b3f62e PA |
9645 | discard_cleanups (old_chain); |
9646 | ||
3ea46bff | 9647 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9648 | } |
9649 | ||
9650 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9651 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9652 | value. COND_STRING, if not NULL, specified the condition to be | |
9653 | used for all breakpoints. Essentially the only case where | |
9654 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9655 | function. In that case, it's still not possible to specify | |
9656 | separate conditions for different overloaded functions, so | |
9657 | we take just a single condition string. | |
9658 | ||
c3f6f71d | 9659 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9660 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9661 | array contents). If the function fails (error() is called), the |
9662 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9663 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9664 | |
9665 | static void | |
8cdf0e15 | 9666 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9667 | struct linespec_result *canonical, |
e7e0cddf | 9668 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9669 | enum bptype type, enum bpdisp disposition, |
9670 | int thread, int task, int ignore_count, | |
c0a91b2b | 9671 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9672 | int enabled, int internal, unsigned flags) |
c906108c | 9673 | { |
018d34a4 | 9674 | int i; |
f8eba3c6 | 9675 | struct linespec_sals *lsal; |
cc59ec59 | 9676 | |
f8eba3c6 TT |
9677 | if (canonical->pre_expanded) |
9678 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9679 | ||
9680 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9681 | { |
f8eba3c6 TT |
9682 | /* Note that 'addr_string' can be NULL in the case of a plain |
9683 | 'break', without arguments. */ | |
9684 | char *addr_string = (canonical->addr_string | |
9685 | ? xstrdup (canonical->addr_string) | |
9686 | : NULL); | |
9687 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
9688 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 9689 | |
f8eba3c6 TT |
9690 | make_cleanup (xfree, filter_string); |
9691 | create_breakpoint_sal (gdbarch, lsal->sals, | |
9692 | addr_string, | |
9693 | filter_string, | |
e7e0cddf SS |
9694 | cond_string, extra_string, |
9695 | type, disposition, | |
84f4c1fe | 9696 | thread, task, ignore_count, ops, |
44f238bb | 9697 | from_tty, enabled, internal, flags, |
56435ebe | 9698 | canonical->special_display); |
f8eba3c6 | 9699 | discard_cleanups (inner); |
c3f6f71d | 9700 | } |
c3f6f71d | 9701 | } |
c906108c | 9702 | |
9998af43 | 9703 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 9704 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 9705 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
9706 | address strings. ADDRESS points to the end of the SAL. |
9707 | ||
9708 | The array and the line spec strings are allocated on the heap, it is | |
9709 | the caller's responsibility to free them. */ | |
c906108c | 9710 | |
b9362cc7 | 9711 | static void |
c3f6f71d | 9712 | parse_breakpoint_sals (char **address, |
58438ac1 | 9713 | struct linespec_result *canonical) |
c3f6f71d | 9714 | { |
c3f6f71d | 9715 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 9716 | breakpoint. */ |
c3f6f71d JM |
9717 | if ((*address) == NULL |
9718 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 9719 | { |
1bfeeb0f JL |
9720 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
9721 | address. */ | |
9722 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9723 | { |
f8eba3c6 | 9724 | struct linespec_sals lsal; |
c3f6f71d | 9725 | struct symtab_and_line sal; |
1c8cdcb1 | 9726 | CORE_ADDR pc; |
cc59ec59 | 9727 | |
4a64f543 | 9728 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 9729 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 9730 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
9731 | |
9732 | /* Set sal's pspace, pc, symtab, and line to the values | |
1c8cdcb1 JK |
9733 | corresponding to the last call to print_frame_info. |
9734 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9735 | as the breakpoint line number is inappropriate otherwise. | |
9736 | find_pc_line would adjust PC, re-set it back. */ | |
1bfeeb0f | 9737 | get_last_displayed_sal (&sal); |
1c8cdcb1 JK |
9738 | pc = sal.pc; |
9739 | sal = find_pc_line (pc, 0); | |
00903456 | 9740 | |
4a64f543 | 9741 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
9742 | where PC is the last displayed codepoint's address. So |
9743 | make sure to set sal.explicit_pc to prevent GDB from | |
9744 | trying to expand the list of sals to include all other | |
9745 | instances with the same symtab and line. */ | |
1c8cdcb1 | 9746 | sal.pc = pc; |
00903456 JK |
9747 | sal.explicit_pc = 1; |
9748 | ||
f8eba3c6 TT |
9749 | lsal.sals.sals[0] = sal; |
9750 | lsal.sals.nelts = 1; | |
9751 | lsal.canonical = NULL; | |
9752 | ||
9753 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
9754 | } |
9755 | else | |
8a3fe4f8 | 9756 | error (_("No default breakpoint address now.")); |
c906108c SS |
9757 | } |
9758 | else | |
9759 | { | |
cc80f267 JK |
9760 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
9761 | ||
c906108c | 9762 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
9763 | current_source_symtab (which is decode_line_1's default). |
9764 | This should produce the results we want almost all of the | |
cc80f267 JK |
9765 | time while leaving default_breakpoint_* alone. |
9766 | ||
9767 | ObjC: However, don't match an Objective-C method name which | |
9768 | may have a '+' or '-' succeeded by a '['. */ | |
9769 | if (last_displayed_sal_is_valid () | |
9770 | && (!cursal.symtab | |
9771 | || ((strchr ("+-", (*address)[0]) != NULL) | |
9772 | && ((*address)[1] != '[')))) | |
f8eba3c6 TT |
9773 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
9774 | get_last_displayed_symtab (), | |
9775 | get_last_displayed_line (), | |
9776 | canonical, NULL, NULL); | |
c906108c | 9777 | else |
f8eba3c6 | 9778 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
cc80f267 | 9779 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c906108c | 9780 | } |
c3f6f71d | 9781 | } |
c906108c | 9782 | |
c906108c | 9783 | |
c3f6f71d | 9784 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9785 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9786 | |
b9362cc7 | 9787 | static void |
23e7acfb | 9788 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9789 | { |
9790 | int i; | |
cc59ec59 | 9791 | |
c3f6f71d | 9792 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9793 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9794 | } |
9795 | ||
7a697b8d SS |
9796 | /* Fast tracepoints may have restrictions on valid locations. For |
9797 | instance, a fast tracepoint using a jump instead of a trap will | |
9798 | likely have to overwrite more bytes than a trap would, and so can | |
9799 | only be placed where the instruction is longer than the jump, or a | |
9800 | multi-instruction sequence does not have a jump into the middle of | |
9801 | it, etc. */ | |
9802 | ||
9803 | static void | |
9804 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9805 | struct symtabs_and_lines *sals) | |
9806 | { | |
9807 | int i, rslt; | |
9808 | struct symtab_and_line *sal; | |
9809 | char *msg; | |
9810 | struct cleanup *old_chain; | |
9811 | ||
9812 | for (i = 0; i < sals->nelts; i++) | |
9813 | { | |
f8eba3c6 TT |
9814 | struct gdbarch *sarch; |
9815 | ||
7a697b8d SS |
9816 | sal = &sals->sals[i]; |
9817 | ||
f8eba3c6 TT |
9818 | sarch = get_sal_arch (*sal); |
9819 | /* We fall back to GDBARCH if there is no architecture | |
9820 | associated with SAL. */ | |
9821 | if (sarch == NULL) | |
9822 | sarch = gdbarch; | |
9823 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
9824 | NULL, &msg); |
9825 | old_chain = make_cleanup (xfree, msg); | |
9826 | ||
9827 | if (!rslt) | |
9828 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9829 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9830 | |
9831 | do_cleanups (old_chain); | |
9832 | } | |
9833 | } | |
9834 | ||
af4908ba KS |
9835 | /* Issue an invalid thread ID error. */ |
9836 | ||
9837 | static void ATTRIBUTE_NORETURN | |
9838 | invalid_thread_id_error (int id) | |
9839 | { | |
9840 | error (_("Unknown thread %d."), id); | |
9841 | } | |
9842 | ||
018d34a4 VP |
9843 | /* Given TOK, a string specification of condition and thread, as |
9844 | accepted by the 'break' command, extract the condition | |
9845 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9846 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9847 | If no condition is found, *COND_STRING is set to NULL. |
9848 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9849 | |
9850 | static void | |
bbc13ae3 | 9851 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9852 | char **cond_string, int *thread, int *task, |
9853 | char **rest) | |
018d34a4 VP |
9854 | { |
9855 | *cond_string = NULL; | |
9856 | *thread = -1; | |
ed1d1739 KS |
9857 | *task = 0; |
9858 | *rest = NULL; | |
9859 | ||
018d34a4 VP |
9860 | while (tok && *tok) |
9861 | { | |
bbc13ae3 | 9862 | const char *end_tok; |
018d34a4 | 9863 | int toklen; |
bbc13ae3 KS |
9864 | const char *cond_start = NULL; |
9865 | const char *cond_end = NULL; | |
cc59ec59 | 9866 | |
bbc13ae3 | 9867 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9868 | |
9869 | if ((*tok == '"' || *tok == ',') && rest) | |
9870 | { | |
9871 | *rest = savestring (tok, strlen (tok)); | |
9872 | return; | |
9873 | } | |
9874 | ||
bbc13ae3 | 9875 | end_tok = skip_to_space_const (tok); |
d634f2de | 9876 | |
018d34a4 | 9877 | toklen = end_tok - tok; |
d634f2de | 9878 | |
018d34a4 VP |
9879 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9880 | { | |
f7545552 TT |
9881 | struct expression *expr; |
9882 | ||
018d34a4 | 9883 | tok = cond_start = end_tok + 1; |
1bb9788d | 9884 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9885 | xfree (expr); |
018d34a4 | 9886 | cond_end = tok; |
d634f2de | 9887 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9888 | } |
9889 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9890 | { | |
9891 | char *tmptok; | |
d634f2de | 9892 | |
018d34a4 | 9893 | tok = end_tok + 1; |
bbc13ae3 | 9894 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9895 | if (tok == tmptok) |
9896 | error (_("Junk after thread keyword.")); | |
9897 | if (!valid_thread_id (*thread)) | |
af4908ba | 9898 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9899 | tok = tmptok; |
018d34a4 | 9900 | } |
4a306c9a JB |
9901 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9902 | { | |
9903 | char *tmptok; | |
9904 | ||
9905 | tok = end_tok + 1; | |
bbc13ae3 | 9906 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9907 | if (tok == tmptok) |
9908 | error (_("Junk after task keyword.")); | |
9909 | if (!valid_task_id (*task)) | |
b6199126 | 9910 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9911 | tok = tmptok; |
4a306c9a | 9912 | } |
e7e0cddf SS |
9913 | else if (rest) |
9914 | { | |
9915 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9916 | return; |
e7e0cddf | 9917 | } |
018d34a4 VP |
9918 | else |
9919 | error (_("Junk at end of arguments.")); | |
9920 | } | |
9921 | } | |
9922 | ||
0fb4aa4b PA |
9923 | /* Decode a static tracepoint marker spec. */ |
9924 | ||
9925 | static struct symtabs_and_lines | |
9926 | decode_static_tracepoint_spec (char **arg_p) | |
9927 | { | |
9928 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9929 | struct symtabs_and_lines sals; | |
0fb4aa4b PA |
9930 | struct cleanup *old_chain; |
9931 | char *p = &(*arg_p)[3]; | |
9932 | char *endp; | |
9933 | char *marker_str; | |
9934 | int i; | |
9935 | ||
e9cafbcc | 9936 | p = skip_spaces (p); |
0fb4aa4b | 9937 | |
e9cafbcc | 9938 | endp = skip_to_space (p); |
0fb4aa4b PA |
9939 | |
9940 | marker_str = savestring (p, endp - p); | |
9941 | old_chain = make_cleanup (xfree, marker_str); | |
9942 | ||
9943 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9944 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9945 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9946 | ||
9947 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
9948 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
9949 | ||
9950 | for (i = 0; i < sals.nelts; i++) | |
9951 | { | |
9952 | struct static_tracepoint_marker *marker; | |
9953 | ||
9954 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9955 | ||
9956 | init_sal (&sals.sals[i]); | |
9957 | ||
9958 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9959 | sals.sals[i].pc = marker->address; | |
9960 | ||
9961 | release_static_tracepoint_marker (marker); | |
9962 | } | |
9963 | ||
9964 | do_cleanups (old_chain); | |
9965 | ||
9966 | *arg_p = endp; | |
9967 | return sals; | |
9968 | } | |
9969 | ||
fd9b8c24 PA |
9970 | /* Set a breakpoint. This function is shared between CLI and MI |
9971 | functions for setting a breakpoint. This function has two major | |
f6de8ec2 PA |
9972 | modes of operations, selected by the PARSE_ARG parameter. If |
9973 | non-zero, the function will parse ARG, extracting location, | |
9974 | condition, thread and extra string. Otherwise, ARG is just the | |
9975 | breakpoint's location, with condition, thread, and extra string | |
9976 | specified by the COND_STRING, THREAD and EXTRA_STRING parameters. | |
9977 | If INTERNAL is non-zero, the breakpoint number will be allocated | |
9978 | from the internal breakpoint count. Returns true if any breakpoint | |
9979 | was created; false otherwise. */ | |
0101ce28 | 9980 | |
8cdf0e15 VP |
9981 | int |
9982 | create_breakpoint (struct gdbarch *gdbarch, | |
e7e0cddf SS |
9983 | char *arg, char *cond_string, |
9984 | int thread, char *extra_string, | |
f6de8ec2 | 9985 | int parse_arg, |
0fb4aa4b | 9986 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9987 | int ignore_count, |
9988 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9989 | const struct breakpoint_ops *ops, |
44f238bb PA |
9990 | int from_tty, int enabled, int internal, |
9991 | unsigned flags) | |
c3f6f71d | 9992 | { |
b78a6381 | 9993 | volatile struct gdb_exception e; |
f8eba3c6 | 9994 | char *copy_arg = NULL; |
c3f6f71d | 9995 | char *addr_start = arg; |
7efd8fc2 | 9996 | struct linespec_result canonical; |
c3f6f71d | 9997 | struct cleanup *old_chain; |
80c99de1 | 9998 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9999 | int pending = 0; |
4a306c9a | 10000 | int task = 0; |
86b17b60 | 10001 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 10002 | |
348d480f PA |
10003 | gdb_assert (ops != NULL); |
10004 | ||
7efd8fc2 | 10005 | init_linespec_result (&canonical); |
c3f6f71d | 10006 | |
b78a6381 TT |
10007 | TRY_CATCH (e, RETURN_MASK_ALL) |
10008 | { | |
983af33b SDJ |
10009 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
10010 | addr_start, ©_arg); | |
b78a6381 | 10011 | } |
0101ce28 JJ |
10012 | |
10013 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 10014 | switch (e.reason) |
0101ce28 | 10015 | { |
983af33b SDJ |
10016 | case GDB_NO_ERROR: |
10017 | if (VEC_empty (linespec_sals, canonical.sals)) | |
10018 | return 0; | |
10019 | break; | |
05ff989b AC |
10020 | case RETURN_ERROR: |
10021 | switch (e.error) | |
0101ce28 | 10022 | { |
05ff989b | 10023 | case NOT_FOUND_ERROR: |
0101ce28 | 10024 | |
05ff989b AC |
10025 | /* If pending breakpoint support is turned off, throw |
10026 | error. */ | |
fa8d40ab JJ |
10027 | |
10028 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
10029 | throw_exception (e); |
10030 | ||
10031 | exception_print (gdb_stderr, e); | |
fa8d40ab | 10032 | |
05ff989b AC |
10033 | /* If pending breakpoint support is auto query and the user |
10034 | selects no, then simply return the error code. */ | |
059fb39f | 10035 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
10036 | && !nquery (_("Make %s pending on future shared library load? "), |
10037 | bptype_string (type_wanted))) | |
fd9b8c24 | 10038 | return 0; |
fa8d40ab | 10039 | |
05ff989b AC |
10040 | /* At this point, either the user was queried about setting |
10041 | a pending breakpoint and selected yes, or pending | |
10042 | breakpoint behavior is on and thus a pending breakpoint | |
10043 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
10044 | { |
10045 | struct linespec_sals lsal; | |
10046 | ||
10047 | copy_arg = xstrdup (addr_start); | |
10048 | lsal.canonical = xstrdup (copy_arg); | |
10049 | lsal.sals.nelts = 1; | |
10050 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
10051 | init_sal (&lsal.sals.sals[0]); | |
10052 | pending = 1; | |
10053 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
10054 | } | |
05ff989b AC |
10055 | break; |
10056 | default: | |
98deb0da | 10057 | throw_exception (e); |
0101ce28 | 10058 | } |
2abae994 | 10059 | break; |
05ff989b | 10060 | default: |
983af33b | 10061 | throw_exception (e); |
0101ce28 | 10062 | } |
c3f6f71d | 10063 | |
4a64f543 | 10064 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 10065 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 10066 | |
c3f6f71d JM |
10067 | /* ----------------------------- SNIP ----------------------------- |
10068 | Anything added to the cleanup chain beyond this point is assumed | |
10069 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
10070 | then the memory is not reclaimed. */ |
10071 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 10072 | |
c3f6f71d JM |
10073 | /* Resolve all line numbers to PC's and verify that the addresses |
10074 | are ok for the target. */ | |
0101ce28 | 10075 | if (!pending) |
f8eba3c6 TT |
10076 | { |
10077 | int ix; | |
10078 | struct linespec_sals *iter; | |
10079 | ||
10080 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
10081 | breakpoint_sals_to_pc (&iter->sals); | |
10082 | } | |
c3f6f71d | 10083 | |
7a697b8d | 10084 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 10085 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
10086 | { |
10087 | int ix; | |
10088 | struct linespec_sals *iter; | |
10089 | ||
10090 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
10091 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
10092 | } | |
7a697b8d | 10093 | |
c3f6f71d JM |
10094 | /* Verify that condition can be parsed, before setting any |
10095 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 10096 | breakpoint. */ |
0101ce28 | 10097 | if (!pending) |
c3f6f71d | 10098 | { |
f6de8ec2 | 10099 | if (parse_arg) |
72b2ff0e | 10100 | { |
0878d0fa | 10101 | char *rest; |
52d361e1 YQ |
10102 | struct linespec_sals *lsal; |
10103 | ||
10104 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
10105 | ||
0878d0fa YQ |
10106 | /* Here we only parse 'arg' to separate condition |
10107 | from thread number, so parsing in context of first | |
10108 | sal is OK. When setting the breakpoint we'll | |
10109 | re-parse it in context of each sal. */ | |
10110 | ||
10111 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, | |
10112 | &thread, &task, &rest); | |
10113 | if (cond_string) | |
10114 | make_cleanup (xfree, cond_string); | |
10115 | if (rest) | |
10116 | make_cleanup (xfree, rest); | |
10117 | if (rest) | |
10118 | extra_string = rest; | |
72b2ff0e | 10119 | } |
2f069f6f | 10120 | else |
72b2ff0e | 10121 | { |
0878d0fa YQ |
10122 | if (*arg != '\0') |
10123 | error (_("Garbage '%s' at end of location"), arg); | |
10124 | ||
10125 | /* Create a private copy of condition string. */ | |
10126 | if (cond_string) | |
10127 | { | |
10128 | cond_string = xstrdup (cond_string); | |
10129 | make_cleanup (xfree, cond_string); | |
10130 | } | |
10131 | /* Create a private copy of any extra string. */ | |
10132 | if (extra_string) | |
10133 | { | |
10134 | extra_string = xstrdup (extra_string); | |
10135 | make_cleanup (xfree, extra_string); | |
10136 | } | |
72b2ff0e | 10137 | } |
0fb4aa4b | 10138 | |
52d361e1 | 10139 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 10140 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
10141 | tempflag ? disp_del : disp_donttouch, |
10142 | thread, task, ignore_count, ops, | |
44f238bb | 10143 | from_tty, enabled, internal, flags); |
c906108c | 10144 | } |
0101ce28 JJ |
10145 | else |
10146 | { | |
0101ce28 JJ |
10147 | struct breakpoint *b; |
10148 | ||
0101ce28 JJ |
10149 | make_cleanup (xfree, copy_arg); |
10150 | ||
bfccc43c YQ |
10151 | if (is_tracepoint_type (type_wanted)) |
10152 | { | |
10153 | struct tracepoint *t; | |
10154 | ||
10155 | t = XCNEW (struct tracepoint); | |
10156 | b = &t->base; | |
10157 | } | |
10158 | else | |
10159 | b = XNEW (struct breakpoint); | |
10160 | ||
10161 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
10162 | ||
f8eba3c6 | 10163 | b->addr_string = copy_arg; |
f6de8ec2 | 10164 | if (parse_arg) |
e12c7713 MK |
10165 | b->cond_string = NULL; |
10166 | else | |
10167 | { | |
10168 | /* Create a private copy of condition string. */ | |
10169 | if (cond_string) | |
10170 | { | |
10171 | cond_string = xstrdup (cond_string); | |
10172 | make_cleanup (xfree, cond_string); | |
10173 | } | |
10174 | b->cond_string = cond_string; | |
10175 | } | |
e7e0cddf | 10176 | b->extra_string = NULL; |
0101ce28 | 10177 | b->ignore_count = ignore_count; |
0101ce28 | 10178 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 10179 | b->condition_not_parsed = 1; |
41447f92 | 10180 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
10181 | if ((type_wanted != bp_breakpoint |
10182 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 10183 | b->pspace = current_program_space; |
8bea4e01 | 10184 | |
bfccc43c | 10185 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
10186 | } |
10187 | ||
f8eba3c6 | 10188 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 10189 | { |
3e43a32a MS |
10190 | warning (_("Multiple breakpoints were set.\nUse the " |
10191 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 10192 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
10193 | } |
10194 | ||
80c99de1 PA |
10195 | /* That's it. Discard the cleanups for data inserted into the |
10196 | breakpoint. */ | |
10197 | discard_cleanups (bkpt_chain); | |
10198 | /* But cleanup everything else. */ | |
c3f6f71d | 10199 | do_cleanups (old_chain); |
217dc9e2 | 10200 | |
80c99de1 | 10201 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 10202 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
10203 | |
10204 | return 1; | |
c3f6f71d | 10205 | } |
c906108c | 10206 | |
348d480f | 10207 | /* Set a breakpoint. |
72b2ff0e VP |
10208 | ARG is a string describing breakpoint address, |
10209 | condition, and thread. | |
10210 | FLAG specifies if a breakpoint is hardware on, | |
10211 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
10212 | and BP_TEMPFLAG. */ | |
348d480f | 10213 | |
98deb0da | 10214 | static void |
72b2ff0e | 10215 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 10216 | { |
72b2ff0e | 10217 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
10218 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
10219 | ? bp_hardware_breakpoint | |
10220 | : bp_breakpoint); | |
55aa24fb SDJ |
10221 | struct breakpoint_ops *ops; |
10222 | const char *arg_cp = arg; | |
10223 | ||
10224 | /* Matching breakpoints on probes. */ | |
10225 | if (arg && probe_linespec_to_ops (&arg_cp) != NULL) | |
10226 | ops = &bkpt_probe_breakpoint_ops; | |
10227 | else | |
10228 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 10229 | |
8cdf0e15 VP |
10230 | create_breakpoint (get_current_arch (), |
10231 | arg, | |
e7e0cddf | 10232 | NULL, 0, NULL, 1 /* parse arg */, |
0fb4aa4b | 10233 | tempflag, type_wanted, |
8cdf0e15 VP |
10234 | 0 /* Ignore count */, |
10235 | pending_break_support, | |
55aa24fb | 10236 | ops, |
8cdf0e15 | 10237 | from_tty, |
84f4c1fe | 10238 | 1 /* enabled */, |
44f238bb PA |
10239 | 0 /* internal */, |
10240 | 0); | |
c906108c SS |
10241 | } |
10242 | ||
c906108c SS |
10243 | /* Helper function for break_command_1 and disassemble_command. */ |
10244 | ||
10245 | void | |
fba45db2 | 10246 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
10247 | { |
10248 | CORE_ADDR pc; | |
10249 | ||
10250 | if (sal->pc == 0 && sal->symtab != NULL) | |
10251 | { | |
10252 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 10253 | error (_("No line %d in file \"%s\"."), |
05cba821 | 10254 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 10255 | sal->pc = pc; |
6a048695 | 10256 | |
4a64f543 MS |
10257 | /* If this SAL corresponds to a breakpoint inserted using a line |
10258 | number, then skip the function prologue if necessary. */ | |
6a048695 | 10259 | if (sal->explicit_line) |
059acae7 | 10260 | skip_prologue_sal (sal); |
c906108c SS |
10261 | } |
10262 | ||
10263 | if (sal->section == 0 && sal->symtab != NULL) | |
10264 | { | |
346d1dfe | 10265 | const struct blockvector *bv; |
3977b71f | 10266 | const struct block *b; |
c5aa993b | 10267 | struct symbol *sym; |
c906108c | 10268 | |
801e3a5b | 10269 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
10270 | if (bv != NULL) |
10271 | { | |
7f0df278 | 10272 | sym = block_linkage_function (b); |
c906108c SS |
10273 | if (sym != NULL) |
10274 | { | |
10275 | fixup_symbol_section (sym, sal->symtab->objfile); | |
e27d198c | 10276 | sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym); |
c906108c SS |
10277 | } |
10278 | else | |
10279 | { | |
4a64f543 MS |
10280 | /* It really is worthwhile to have the section, so we'll |
10281 | just have to look harder. This case can be executed | |
10282 | if we have line numbers but no functions (as can | |
10283 | happen in assembly source). */ | |
c906108c | 10284 | |
7cbd4a93 | 10285 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10286 | struct cleanup *old_chain = save_current_space_and_thread (); |
10287 | ||
10288 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10289 | |
10290 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10291 | if (msym.minsym) |
efd66ac6 | 10292 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10293 | |
10294 | do_cleanups (old_chain); | |
c906108c SS |
10295 | } |
10296 | } | |
10297 | } | |
10298 | } | |
10299 | ||
10300 | void | |
fba45db2 | 10301 | break_command (char *arg, int from_tty) |
c906108c | 10302 | { |
db107f19 | 10303 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10304 | } |
10305 | ||
c906108c | 10306 | void |
fba45db2 | 10307 | tbreak_command (char *arg, int from_tty) |
c906108c | 10308 | { |
db107f19 | 10309 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10310 | } |
10311 | ||
c906108c | 10312 | static void |
fba45db2 | 10313 | hbreak_command (char *arg, int from_tty) |
c906108c | 10314 | { |
db107f19 | 10315 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10316 | } |
10317 | ||
10318 | static void | |
fba45db2 | 10319 | thbreak_command (char *arg, int from_tty) |
c906108c | 10320 | { |
db107f19 | 10321 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10322 | } |
10323 | ||
10324 | static void | |
fba45db2 | 10325 | stop_command (char *arg, int from_tty) |
c906108c | 10326 | { |
a3f17187 | 10327 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10328 | Usage: stop in <function | address>\n\ |
a3f17187 | 10329 | stop at <line>\n")); |
c906108c SS |
10330 | } |
10331 | ||
10332 | static void | |
fba45db2 | 10333 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10334 | { |
10335 | int badInput = 0; | |
10336 | ||
c5aa993b | 10337 | if (arg == (char *) NULL) |
c906108c SS |
10338 | badInput = 1; |
10339 | else if (*arg != '*') | |
10340 | { | |
10341 | char *argptr = arg; | |
10342 | int hasColon = 0; | |
10343 | ||
4a64f543 | 10344 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10345 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10346 | function/method name. */ |
c906108c | 10347 | while (*argptr && !hasColon) |
c5aa993b JM |
10348 | { |
10349 | hasColon = (*argptr == ':'); | |
10350 | argptr++; | |
10351 | } | |
c906108c SS |
10352 | |
10353 | if (hasColon) | |
c5aa993b | 10354 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10355 | else |
c5aa993b | 10356 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10357 | } |
10358 | ||
10359 | if (badInput) | |
a3f17187 | 10360 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10361 | else |
db107f19 | 10362 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10363 | } |
10364 | ||
10365 | static void | |
fba45db2 | 10366 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10367 | { |
10368 | int badInput = 0; | |
10369 | ||
c5aa993b | 10370 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10371 | badInput = 1; |
10372 | else | |
10373 | { | |
10374 | char *argptr = arg; | |
10375 | int hasColon = 0; | |
10376 | ||
4a64f543 MS |
10377 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10378 | it is probably a line number. */ | |
c906108c | 10379 | while (*argptr && !hasColon) |
c5aa993b JM |
10380 | { |
10381 | hasColon = (*argptr == ':'); | |
10382 | argptr++; | |
10383 | } | |
c906108c SS |
10384 | |
10385 | if (hasColon) | |
c5aa993b | 10386 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10387 | else |
c5aa993b | 10388 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10389 | } |
10390 | ||
10391 | if (badInput) | |
a3f17187 | 10392 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10393 | else |
db107f19 | 10394 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10395 | } |
10396 | ||
e7e0cddf SS |
10397 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10398 | with a prewired command list consisting of a single output command, | |
10399 | built from extra arguments supplied on the dprintf command | |
10400 | line. */ | |
10401 | ||
da821c7b | 10402 | static void |
e7e0cddf SS |
10403 | dprintf_command (char *arg, int from_tty) |
10404 | { | |
10405 | create_breakpoint (get_current_arch (), | |
10406 | arg, | |
10407 | NULL, 0, NULL, 1 /* parse arg */, | |
10408 | 0, bp_dprintf, | |
10409 | 0 /* Ignore count */, | |
10410 | pending_break_support, | |
10411 | &dprintf_breakpoint_ops, | |
10412 | from_tty, | |
10413 | 1 /* enabled */, | |
10414 | 0 /* internal */, | |
10415 | 0); | |
10416 | } | |
10417 | ||
d3ce09f5 SS |
10418 | static void |
10419 | agent_printf_command (char *arg, int from_tty) | |
10420 | { | |
10421 | error (_("May only run agent-printf on the target")); | |
10422 | } | |
10423 | ||
f1310107 TJB |
10424 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10425 | ranged breakpoints. */ | |
10426 | ||
10427 | static int | |
10428 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10429 | struct address_space *aspace, | |
09ac7c10 TT |
10430 | CORE_ADDR bp_addr, |
10431 | const struct target_waitstatus *ws) | |
f1310107 | 10432 | { |
09ac7c10 | 10433 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10434 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10435 | return 0; |
10436 | ||
f1310107 TJB |
10437 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10438 | bl->length, aspace, bp_addr); | |
10439 | } | |
10440 | ||
10441 | /* Implement the "resources_needed" breakpoint_ops method for | |
10442 | ranged breakpoints. */ | |
10443 | ||
10444 | static int | |
10445 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10446 | { | |
10447 | return target_ranged_break_num_registers (); | |
10448 | } | |
10449 | ||
10450 | /* Implement the "print_it" breakpoint_ops method for | |
10451 | ranged breakpoints. */ | |
10452 | ||
10453 | static enum print_stop_action | |
348d480f | 10454 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10455 | { |
348d480f | 10456 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10457 | struct bp_location *bl = b->loc; |
79a45e25 | 10458 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10459 | |
10460 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10461 | ||
10462 | /* Ranged breakpoints have only one location. */ | |
10463 | gdb_assert (bl && bl->next == NULL); | |
10464 | ||
10465 | annotate_breakpoint (b->number); | |
10466 | if (b->disposition == disp_del) | |
10467 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10468 | else | |
10469 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10470 | if (ui_out_is_mi_like_p (uiout)) | |
10471 | { | |
10472 | ui_out_field_string (uiout, "reason", | |
10473 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10474 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10475 | } | |
10476 | ui_out_field_int (uiout, "bkptno", b->number); | |
10477 | ui_out_text (uiout, ", "); | |
10478 | ||
10479 | return PRINT_SRC_AND_LOC; | |
10480 | } | |
10481 | ||
10482 | /* Implement the "print_one" breakpoint_ops method for | |
10483 | ranged breakpoints. */ | |
10484 | ||
10485 | static void | |
10486 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10487 | struct bp_location **last_loc) | |
10488 | { | |
10489 | struct bp_location *bl = b->loc; | |
10490 | struct value_print_options opts; | |
79a45e25 | 10491 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10492 | |
10493 | /* Ranged breakpoints have only one location. */ | |
10494 | gdb_assert (bl && bl->next == NULL); | |
10495 | ||
10496 | get_user_print_options (&opts); | |
10497 | ||
10498 | if (opts.addressprint) | |
10499 | /* We don't print the address range here, it will be printed later | |
10500 | by print_one_detail_ranged_breakpoint. */ | |
10501 | ui_out_field_skip (uiout, "addr"); | |
10502 | annotate_field (5); | |
10503 | print_breakpoint_location (b, bl); | |
10504 | *last_loc = bl; | |
10505 | } | |
10506 | ||
10507 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10508 | ranged breakpoints. */ | |
10509 | ||
10510 | static void | |
10511 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10512 | struct ui_out *uiout) | |
10513 | { | |
10514 | CORE_ADDR address_start, address_end; | |
10515 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10516 | struct ui_file *stb = mem_fileopen (); |
10517 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10518 | |
10519 | gdb_assert (bl); | |
10520 | ||
10521 | address_start = bl->address; | |
10522 | address_end = address_start + bl->length - 1; | |
10523 | ||
10524 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10525 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10526 | print_core_address (bl->gdbarch, address_start), |
10527 | print_core_address (bl->gdbarch, address_end)); | |
10528 | ui_out_field_stream (uiout, "addr", stb); | |
10529 | ui_out_text (uiout, "\n"); | |
10530 | ||
10531 | do_cleanups (cleanup); | |
10532 | } | |
10533 | ||
10534 | /* Implement the "print_mention" breakpoint_ops method for | |
10535 | ranged breakpoints. */ | |
10536 | ||
10537 | static void | |
10538 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10539 | { | |
10540 | struct bp_location *bl = b->loc; | |
79a45e25 | 10541 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10542 | |
10543 | gdb_assert (bl); | |
10544 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10545 | ||
10546 | if (ui_out_is_mi_like_p (uiout)) | |
10547 | return; | |
10548 | ||
10549 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10550 | b->number, paddress (bl->gdbarch, bl->address), | |
10551 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10552 | } | |
10553 | ||
10554 | /* Implement the "print_recreate" breakpoint_ops method for | |
10555 | ranged breakpoints. */ | |
10556 | ||
10557 | static void | |
10558 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10559 | { | |
10560 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
10561 | b->addr_string_range_end); | |
d9b3f62e | 10562 | print_recreate_thread (b, fp); |
f1310107 TJB |
10563 | } |
10564 | ||
10565 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10566 | ||
2060206e | 10567 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10568 | |
10569 | /* Find the address where the end of the breakpoint range should be | |
10570 | placed, given the SAL of the end of the range. This is so that if | |
10571 | the user provides a line number, the end of the range is set to the | |
10572 | last instruction of the given line. */ | |
10573 | ||
10574 | static CORE_ADDR | |
10575 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10576 | { | |
10577 | CORE_ADDR end; | |
10578 | ||
10579 | /* If the user provided a PC value, use it. Otherwise, | |
10580 | find the address of the end of the given location. */ | |
10581 | if (sal.explicit_pc) | |
10582 | end = sal.pc; | |
10583 | else | |
10584 | { | |
10585 | int ret; | |
10586 | CORE_ADDR start; | |
10587 | ||
10588 | ret = find_line_pc_range (sal, &start, &end); | |
10589 | if (!ret) | |
10590 | error (_("Could not find location of the end of the range.")); | |
10591 | ||
10592 | /* find_line_pc_range returns the start of the next line. */ | |
10593 | end--; | |
10594 | } | |
10595 | ||
10596 | return end; | |
10597 | } | |
10598 | ||
10599 | /* Implement the "break-range" CLI command. */ | |
10600 | ||
10601 | static void | |
10602 | break_range_command (char *arg, int from_tty) | |
10603 | { | |
10604 | char *arg_start, *addr_string_start, *addr_string_end; | |
10605 | struct linespec_result canonical_start, canonical_end; | |
10606 | int bp_count, can_use_bp, length; | |
10607 | CORE_ADDR end; | |
10608 | struct breakpoint *b; | |
10609 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10610 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10611 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10612 | |
10613 | /* We don't support software ranged breakpoints. */ | |
10614 | if (target_ranged_break_num_registers () < 0) | |
10615 | error (_("This target does not support hardware ranged breakpoints.")); | |
10616 | ||
10617 | bp_count = hw_breakpoint_used_count (); | |
10618 | bp_count += target_ranged_break_num_registers (); | |
10619 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10620 | bp_count, 0); | |
10621 | if (can_use_bp < 0) | |
10622 | error (_("Hardware breakpoints used exceeds limit.")); | |
10623 | ||
f8eba3c6 | 10624 | arg = skip_spaces (arg); |
f1310107 TJB |
10625 | if (arg == NULL || arg[0] == '\0') |
10626 | error(_("No address range specified.")); | |
10627 | ||
f1310107 TJB |
10628 | init_linespec_result (&canonical_start); |
10629 | ||
f8eba3c6 TT |
10630 | arg_start = arg; |
10631 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 10632 | |
f8eba3c6 | 10633 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
10634 | |
10635 | if (arg[0] != ',') | |
10636 | error (_("Too few arguments.")); | |
f8eba3c6 | 10637 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10638 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10639 | |
10640 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10641 | ||
10642 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10643 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10644 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10645 | ||
f8eba3c6 TT |
10646 | sal_start = lsal_start->sals.sals[0]; |
10647 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10648 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10649 | |
10650 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10651 | arg = skip_spaces (arg); |
f1310107 TJB |
10652 | |
10653 | /* Parse the end location. */ | |
10654 | ||
f1310107 TJB |
10655 | init_linespec_result (&canonical_end); |
10656 | arg_start = arg; | |
10657 | ||
f8eba3c6 | 10658 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10659 | parse_breakpoint_sals because we need to specify the start location's |
10660 | symtab and line as the default symtab and line for the end of the | |
10661 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10662 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
10663 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
10664 | sal_start.symtab, sal_start.line, | |
10665 | &canonical_end, NULL, NULL); | |
10666 | ||
10667 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10668 | |
f8eba3c6 | 10669 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10670 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10671 | |
10672 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10673 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10674 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10675 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10676 | ||
f8eba3c6 TT |
10677 | sal_end = lsal_end->sals.sals[0]; |
10678 | addr_string_end = savestring (arg_start, arg - arg_start); | |
10679 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
10680 | |
10681 | end = find_breakpoint_range_end (sal_end); | |
10682 | if (sal_start.pc > end) | |
177b42fe | 10683 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10684 | |
10685 | length = end - sal_start.pc + 1; | |
10686 | if (length < 0) | |
10687 | /* Length overflowed. */ | |
10688 | error (_("Address range too large.")); | |
10689 | else if (length == 1) | |
10690 | { | |
10691 | /* This range is simple enough to be handled by | |
10692 | the `hbreak' command. */ | |
10693 | hbreak_command (addr_string_start, 1); | |
10694 | ||
10695 | do_cleanups (cleanup_bkpt); | |
10696 | ||
10697 | return; | |
10698 | } | |
10699 | ||
10700 | /* Now set up the breakpoint. */ | |
10701 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10702 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10703 | set_breakpoint_count (breakpoint_count + 1); |
10704 | b->number = breakpoint_count; | |
10705 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
10706 | b->addr_string = xstrdup (addr_string_start); |
10707 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
10708 | b->loc->length = length; |
10709 | ||
f8eba3c6 | 10710 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10711 | |
10712 | mention (b); | |
8d3788bd | 10713 | observer_notify_breakpoint_created (b); |
44702360 | 10714 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10715 | } |
10716 | ||
4a64f543 MS |
10717 | /* Return non-zero if EXP is verified as constant. Returned zero |
10718 | means EXP is variable. Also the constant detection may fail for | |
10719 | some constant expressions and in such case still falsely return | |
10720 | zero. */ | |
2e6e3d9c | 10721 | |
65d79d4b SDJ |
10722 | static int |
10723 | watchpoint_exp_is_const (const struct expression *exp) | |
10724 | { | |
10725 | int i = exp->nelts; | |
10726 | ||
10727 | while (i > 0) | |
10728 | { | |
10729 | int oplenp, argsp; | |
10730 | ||
10731 | /* We are only interested in the descriptor of each element. */ | |
10732 | operator_length (exp, i, &oplenp, &argsp); | |
10733 | i -= oplenp; | |
10734 | ||
10735 | switch (exp->elts[i].opcode) | |
10736 | { | |
10737 | case BINOP_ADD: | |
10738 | case BINOP_SUB: | |
10739 | case BINOP_MUL: | |
10740 | case BINOP_DIV: | |
10741 | case BINOP_REM: | |
10742 | case BINOP_MOD: | |
10743 | case BINOP_LSH: | |
10744 | case BINOP_RSH: | |
10745 | case BINOP_LOGICAL_AND: | |
10746 | case BINOP_LOGICAL_OR: | |
10747 | case BINOP_BITWISE_AND: | |
10748 | case BINOP_BITWISE_IOR: | |
10749 | case BINOP_BITWISE_XOR: | |
10750 | case BINOP_EQUAL: | |
10751 | case BINOP_NOTEQUAL: | |
10752 | case BINOP_LESS: | |
10753 | case BINOP_GTR: | |
10754 | case BINOP_LEQ: | |
10755 | case BINOP_GEQ: | |
10756 | case BINOP_REPEAT: | |
10757 | case BINOP_COMMA: | |
10758 | case BINOP_EXP: | |
10759 | case BINOP_MIN: | |
10760 | case BINOP_MAX: | |
10761 | case BINOP_INTDIV: | |
10762 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10763 | case TERNOP_COND: |
10764 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10765 | |
10766 | case OP_LONG: | |
10767 | case OP_DOUBLE: | |
10768 | case OP_DECFLOAT: | |
10769 | case OP_LAST: | |
10770 | case OP_COMPLEX: | |
10771 | case OP_STRING: | |
65d79d4b SDJ |
10772 | case OP_ARRAY: |
10773 | case OP_TYPE: | |
608b4967 TT |
10774 | case OP_TYPEOF: |
10775 | case OP_DECLTYPE: | |
6e72ca20 | 10776 | case OP_TYPEID: |
65d79d4b SDJ |
10777 | case OP_NAME: |
10778 | case OP_OBJC_NSSTRING: | |
10779 | ||
10780 | case UNOP_NEG: | |
10781 | case UNOP_LOGICAL_NOT: | |
10782 | case UNOP_COMPLEMENT: | |
10783 | case UNOP_ADDR: | |
10784 | case UNOP_HIGH: | |
aeaa2474 | 10785 | case UNOP_CAST: |
9eaf6705 TT |
10786 | |
10787 | case UNOP_CAST_TYPE: | |
10788 | case UNOP_REINTERPRET_CAST: | |
10789 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10790 | /* Unary, binary and ternary operators: We have to check |
10791 | their operands. If they are constant, then so is the | |
10792 | result of that operation. For instance, if A and B are | |
10793 | determined to be constants, then so is "A + B". | |
10794 | ||
10795 | UNOP_IND is one exception to the rule above, because the | |
10796 | value of *ADDR is not necessarily a constant, even when | |
10797 | ADDR is. */ | |
65d79d4b SDJ |
10798 | break; |
10799 | ||
10800 | case OP_VAR_VALUE: | |
10801 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10802 | |
65d79d4b | 10803 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10804 | possible that a buggy compiler could mark a variable as |
10805 | constant even when it is not, and TYPE_CONST would return | |
10806 | true in this case, while SYMBOL_CLASS wouldn't. | |
10807 | ||
10808 | We also have to check for function symbols because they | |
10809 | are always constant. */ | |
65d79d4b SDJ |
10810 | { |
10811 | struct symbol *s = exp->elts[i + 2].symbol; | |
10812 | ||
10813 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10814 | && SYMBOL_CLASS (s) != LOC_CONST | |
10815 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10816 | return 0; | |
10817 | break; | |
10818 | } | |
10819 | ||
10820 | /* The default action is to return 0 because we are using | |
10821 | the optimistic approach here: If we don't know something, | |
10822 | then it is not a constant. */ | |
10823 | default: | |
10824 | return 0; | |
10825 | } | |
10826 | } | |
10827 | ||
10828 | return 1; | |
10829 | } | |
10830 | ||
3a5c3e22 PA |
10831 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10832 | ||
10833 | static void | |
10834 | dtor_watchpoint (struct breakpoint *self) | |
10835 | { | |
10836 | struct watchpoint *w = (struct watchpoint *) self; | |
10837 | ||
10838 | xfree (w->cond_exp); | |
10839 | xfree (w->exp); | |
10840 | xfree (w->exp_string); | |
10841 | xfree (w->exp_string_reparse); | |
10842 | value_free (w->val); | |
10843 | ||
10844 | base_breakpoint_ops.dtor (self); | |
10845 | } | |
10846 | ||
348d480f PA |
10847 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10848 | ||
10849 | static void | |
10850 | re_set_watchpoint (struct breakpoint *b) | |
10851 | { | |
3a5c3e22 PA |
10852 | struct watchpoint *w = (struct watchpoint *) b; |
10853 | ||
348d480f PA |
10854 | /* Watchpoint can be either on expression using entirely global |
10855 | variables, or it can be on local variables. | |
10856 | ||
10857 | Watchpoints of the first kind are never auto-deleted, and even | |
10858 | persist across program restarts. Since they can use variables | |
10859 | from shared libraries, we need to reparse expression as libraries | |
10860 | are loaded and unloaded. | |
10861 | ||
10862 | Watchpoints on local variables can also change meaning as result | |
10863 | of solib event. For example, if a watchpoint uses both a local | |
10864 | and a global variables in expression, it's a local watchpoint, | |
10865 | but unloading of a shared library will make the expression | |
10866 | invalid. This is not a very common use case, but we still | |
10867 | re-evaluate expression, to avoid surprises to the user. | |
10868 | ||
10869 | Note that for local watchpoints, we re-evaluate it only if | |
10870 | watchpoints frame id is still valid. If it's not, it means the | |
10871 | watchpoint is out of scope and will be deleted soon. In fact, | |
10872 | I'm not sure we'll ever be called in this case. | |
10873 | ||
10874 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10875 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10876 | |
3a5c3e22 PA |
10877 | Don't do anything about disabled watchpoints, since they will be |
10878 | reevaluated again when enabled. */ | |
10879 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10880 | } |
10881 | ||
77b06cd7 TJB |
10882 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10883 | ||
10884 | static int | |
10885 | insert_watchpoint (struct bp_location *bl) | |
10886 | { | |
3a5c3e22 PA |
10887 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10888 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10889 | |
10890 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10891 | w->cond_exp); |
77b06cd7 TJB |
10892 | } |
10893 | ||
10894 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10895 | ||
10896 | static int | |
10897 | remove_watchpoint (struct bp_location *bl) | |
10898 | { | |
3a5c3e22 PA |
10899 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10900 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10901 | |
10902 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10903 | w->cond_exp); |
e09342b5 TJB |
10904 | } |
10905 | ||
e09342b5 | 10906 | static int |
348d480f | 10907 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10908 | struct address_space *aspace, CORE_ADDR bp_addr, |
10909 | const struct target_waitstatus *ws) | |
e09342b5 | 10910 | { |
348d480f | 10911 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10912 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10913 | |
348d480f PA |
10914 | /* Continuable hardware watchpoints are treated as non-existent if the |
10915 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10916 | some data address). Otherwise gdb won't stop on a break instruction | |
10917 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10918 | been defined. Also skip watchpoints which we know did not trigger | |
10919 | (did not match the data address). */ | |
10920 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10921 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10922 | return 0; |
9c06b0b4 | 10923 | |
348d480f | 10924 | return 1; |
9c06b0b4 TJB |
10925 | } |
10926 | ||
348d480f PA |
10927 | static void |
10928 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10929 | { |
348d480f | 10930 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10931 | |
348d480f | 10932 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10933 | } |
10934 | ||
10935 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10936 | hardware watchpoints. */ |
9c06b0b4 TJB |
10937 | |
10938 | static int | |
348d480f | 10939 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10940 | { |
3a5c3e22 PA |
10941 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10942 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10943 | |
10944 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10945 | } |
10946 | ||
10947 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10948 | hardware watchpoints. */ |
9c06b0b4 TJB |
10949 | |
10950 | static int | |
348d480f | 10951 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10952 | { |
efa80663 PA |
10953 | /* Read and access watchpoints only work with hardware support. */ |
10954 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10955 | } |
10956 | ||
9c06b0b4 | 10957 | static enum print_stop_action |
348d480f | 10958 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10959 | { |
348d480f PA |
10960 | struct cleanup *old_chain; |
10961 | struct breakpoint *b; | |
f99d8bf4 | 10962 | struct ui_file *stb; |
348d480f | 10963 | enum print_stop_action result; |
3a5c3e22 | 10964 | struct watchpoint *w; |
79a45e25 | 10965 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10966 | |
10967 | gdb_assert (bs->bp_location_at != NULL); | |
10968 | ||
348d480f | 10969 | b = bs->breakpoint_at; |
3a5c3e22 | 10970 | w = (struct watchpoint *) b; |
348d480f | 10971 | |
f99d8bf4 PA |
10972 | stb = mem_fileopen (); |
10973 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10974 | |
10975 | switch (b->type) | |
10976 | { | |
348d480f | 10977 | case bp_watchpoint: |
9c06b0b4 TJB |
10978 | case bp_hardware_watchpoint: |
10979 | annotate_watchpoint (b->number); | |
10980 | if (ui_out_is_mi_like_p (uiout)) | |
10981 | ui_out_field_string | |
10982 | (uiout, "reason", | |
10983 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10984 | mention (b); |
10985 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10986 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10987 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10988 | ui_out_field_stream (uiout, "old", stb); |
10989 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10990 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10991 | ui_out_field_stream (uiout, "new", stb); |
10992 | ui_out_text (uiout, "\n"); | |
10993 | /* More than one watchpoint may have been triggered. */ | |
10994 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10995 | break; |
10996 | ||
10997 | case bp_read_watchpoint: | |
10998 | if (ui_out_is_mi_like_p (uiout)) | |
10999 | ui_out_field_string | |
11000 | (uiout, "reason", | |
11001 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
11002 | mention (b); |
11003 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
11004 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 11005 | watchpoint_value_print (w->val, stb); |
348d480f PA |
11006 | ui_out_field_stream (uiout, "value", stb); |
11007 | ui_out_text (uiout, "\n"); | |
11008 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
11009 | break; |
11010 | ||
11011 | case bp_access_watchpoint: | |
348d480f PA |
11012 | if (bs->old_val != NULL) |
11013 | { | |
11014 | annotate_watchpoint (b->number); | |
11015 | if (ui_out_is_mi_like_p (uiout)) | |
11016 | ui_out_field_string | |
11017 | (uiout, "reason", | |
11018 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11019 | mention (b); | |
11020 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
11021 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 11022 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
11023 | ui_out_field_stream (uiout, "old", stb); |
11024 | ui_out_text (uiout, "\nNew value = "); | |
11025 | } | |
11026 | else | |
11027 | { | |
11028 | mention (b); | |
11029 | if (ui_out_is_mi_like_p (uiout)) | |
11030 | ui_out_field_string | |
11031 | (uiout, "reason", | |
11032 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11033 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
11034 | ui_out_text (uiout, "\nValue = "); | |
11035 | } | |
f99d8bf4 | 11036 | watchpoint_value_print (w->val, stb); |
348d480f PA |
11037 | ui_out_field_stream (uiout, "new", stb); |
11038 | ui_out_text (uiout, "\n"); | |
11039 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
11040 | break; |
11041 | default: | |
348d480f | 11042 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
11043 | } |
11044 | ||
348d480f PA |
11045 | do_cleanups (old_chain); |
11046 | return result; | |
11047 | } | |
11048 | ||
11049 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
11050 | watchpoints. */ | |
11051 | ||
11052 | static void | |
11053 | print_mention_watchpoint (struct breakpoint *b) | |
11054 | { | |
11055 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 11056 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11057 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11058 | |
11059 | switch (b->type) | |
11060 | { | |
11061 | case bp_watchpoint: | |
11062 | ui_out_text (uiout, "Watchpoint "); | |
11063 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11064 | break; | |
11065 | case bp_hardware_watchpoint: | |
11066 | ui_out_text (uiout, "Hardware watchpoint "); | |
11067 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11068 | break; | |
11069 | case bp_read_watchpoint: | |
11070 | ui_out_text (uiout, "Hardware read watchpoint "); | |
11071 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11072 | break; | |
11073 | case bp_access_watchpoint: | |
11074 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
11075 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11076 | break; | |
11077 | default: | |
11078 | internal_error (__FILE__, __LINE__, | |
11079 | _("Invalid hardware watchpoint type.")); | |
11080 | } | |
11081 | ||
11082 | ui_out_field_int (uiout, "number", b->number); | |
11083 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11084 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
11085 | do_cleanups (ui_out_chain); |
11086 | } | |
11087 | ||
11088 | /* Implement the "print_recreate" breakpoint_ops method for | |
11089 | watchpoints. */ | |
11090 | ||
11091 | static void | |
11092 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11093 | { | |
3a5c3e22 PA |
11094 | struct watchpoint *w = (struct watchpoint *) b; |
11095 | ||
348d480f PA |
11096 | switch (b->type) |
11097 | { | |
11098 | case bp_watchpoint: | |
11099 | case bp_hardware_watchpoint: | |
11100 | fprintf_unfiltered (fp, "watch"); | |
11101 | break; | |
11102 | case bp_read_watchpoint: | |
11103 | fprintf_unfiltered (fp, "rwatch"); | |
11104 | break; | |
11105 | case bp_access_watchpoint: | |
11106 | fprintf_unfiltered (fp, "awatch"); | |
11107 | break; | |
11108 | default: | |
11109 | internal_error (__FILE__, __LINE__, | |
11110 | _("Invalid watchpoint type.")); | |
11111 | } | |
11112 | ||
3a5c3e22 | 11113 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 11114 | print_recreate_thread (b, fp); |
348d480f PA |
11115 | } |
11116 | ||
427cd150 TT |
11117 | /* Implement the "explains_signal" breakpoint_ops method for |
11118 | watchpoints. */ | |
11119 | ||
47591c29 | 11120 | static int |
427cd150 TT |
11121 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
11122 | { | |
11123 | /* A software watchpoint cannot cause a signal other than | |
11124 | GDB_SIGNAL_TRAP. */ | |
11125 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 11126 | return 0; |
427cd150 | 11127 | |
47591c29 | 11128 | return 1; |
427cd150 TT |
11129 | } |
11130 | ||
348d480f PA |
11131 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
11132 | ||
2060206e | 11133 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
11134 | |
11135 | /* Implement the "insert" breakpoint_ops method for | |
11136 | masked hardware watchpoints. */ | |
11137 | ||
11138 | static int | |
11139 | insert_masked_watchpoint (struct bp_location *bl) | |
11140 | { | |
3a5c3e22 PA |
11141 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
11142 | ||
11143 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
11144 | bl->watchpoint_type); |
11145 | } | |
11146 | ||
11147 | /* Implement the "remove" breakpoint_ops method for | |
11148 | masked hardware watchpoints. */ | |
11149 | ||
11150 | static int | |
11151 | remove_masked_watchpoint (struct bp_location *bl) | |
11152 | { | |
3a5c3e22 PA |
11153 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
11154 | ||
11155 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
11156 | bl->watchpoint_type); |
11157 | } | |
11158 | ||
11159 | /* Implement the "resources_needed" breakpoint_ops method for | |
11160 | masked hardware watchpoints. */ | |
11161 | ||
11162 | static int | |
11163 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
11164 | { | |
3a5c3e22 PA |
11165 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
11166 | ||
11167 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
11168 | } |
11169 | ||
11170 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
11171 | masked hardware watchpoints. */ | |
11172 | ||
11173 | static int | |
11174 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
11175 | { | |
11176 | return 0; | |
11177 | } | |
11178 | ||
11179 | /* Implement the "print_it" breakpoint_ops method for | |
11180 | masked hardware watchpoints. */ | |
11181 | ||
11182 | static enum print_stop_action | |
11183 | print_it_masked_watchpoint (bpstat bs) | |
11184 | { | |
11185 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 11186 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11187 | |
11188 | /* Masked watchpoints have only one location. */ | |
11189 | gdb_assert (b->loc && b->loc->next == NULL); | |
11190 | ||
11191 | switch (b->type) | |
11192 | { | |
11193 | case bp_hardware_watchpoint: | |
11194 | annotate_watchpoint (b->number); | |
11195 | if (ui_out_is_mi_like_p (uiout)) | |
11196 | ui_out_field_string | |
11197 | (uiout, "reason", | |
11198 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
11199 | break; | |
11200 | ||
11201 | case bp_read_watchpoint: | |
11202 | if (ui_out_is_mi_like_p (uiout)) | |
11203 | ui_out_field_string | |
11204 | (uiout, "reason", | |
11205 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
11206 | break; | |
11207 | ||
11208 | case bp_access_watchpoint: | |
11209 | if (ui_out_is_mi_like_p (uiout)) | |
11210 | ui_out_field_string | |
11211 | (uiout, "reason", | |
11212 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11213 | break; | |
11214 | default: | |
11215 | internal_error (__FILE__, __LINE__, | |
11216 | _("Invalid hardware watchpoint type.")); | |
11217 | } | |
11218 | ||
11219 | mention (b); | |
9c06b0b4 TJB |
11220 | ui_out_text (uiout, _("\n\ |
11221 | Check the underlying instruction at PC for the memory\n\ | |
11222 | address and value which triggered this watchpoint.\n")); | |
11223 | ui_out_text (uiout, "\n"); | |
11224 | ||
11225 | /* More than one watchpoint may have been triggered. */ | |
11226 | return PRINT_UNKNOWN; | |
11227 | } | |
11228 | ||
11229 | /* Implement the "print_one_detail" breakpoint_ops method for | |
11230 | masked hardware watchpoints. */ | |
11231 | ||
11232 | static void | |
11233 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
11234 | struct ui_out *uiout) | |
11235 | { | |
3a5c3e22 PA |
11236 | struct watchpoint *w = (struct watchpoint *) b; |
11237 | ||
9c06b0b4 TJB |
11238 | /* Masked watchpoints have only one location. */ |
11239 | gdb_assert (b->loc && b->loc->next == NULL); | |
11240 | ||
11241 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 11242 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
11243 | ui_out_text (uiout, "\n"); |
11244 | } | |
11245 | ||
11246 | /* Implement the "print_mention" breakpoint_ops method for | |
11247 | masked hardware watchpoints. */ | |
11248 | ||
11249 | static void | |
11250 | print_mention_masked_watchpoint (struct breakpoint *b) | |
11251 | { | |
3a5c3e22 | 11252 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11253 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
11254 | struct cleanup *ui_out_chain; |
11255 | ||
11256 | switch (b->type) | |
11257 | { | |
11258 | case bp_hardware_watchpoint: | |
11259 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
11260 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11261 | break; | |
11262 | case bp_read_watchpoint: | |
11263 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
11264 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11265 | break; | |
11266 | case bp_access_watchpoint: | |
11267 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
11268 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11269 | break; | |
11270 | default: | |
11271 | internal_error (__FILE__, __LINE__, | |
11272 | _("Invalid hardware watchpoint type.")); | |
11273 | } | |
11274 | ||
11275 | ui_out_field_int (uiout, "number", b->number); | |
11276 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11277 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
11278 | do_cleanups (ui_out_chain); |
11279 | } | |
11280 | ||
11281 | /* Implement the "print_recreate" breakpoint_ops method for | |
11282 | masked hardware watchpoints. */ | |
11283 | ||
11284 | static void | |
11285 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11286 | { | |
3a5c3e22 | 11287 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11288 | char tmp[40]; |
11289 | ||
11290 | switch (b->type) | |
11291 | { | |
11292 | case bp_hardware_watchpoint: | |
11293 | fprintf_unfiltered (fp, "watch"); | |
11294 | break; | |
11295 | case bp_read_watchpoint: | |
11296 | fprintf_unfiltered (fp, "rwatch"); | |
11297 | break; | |
11298 | case bp_access_watchpoint: | |
11299 | fprintf_unfiltered (fp, "awatch"); | |
11300 | break; | |
11301 | default: | |
11302 | internal_error (__FILE__, __LINE__, | |
11303 | _("Invalid hardware watchpoint type.")); | |
11304 | } | |
11305 | ||
3a5c3e22 PA |
11306 | sprintf_vma (tmp, w->hw_wp_mask); |
11307 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11308 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11309 | } |
11310 | ||
11311 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11312 | ||
2060206e | 11313 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11314 | |
11315 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11316 | ||
11317 | static int | |
11318 | is_masked_watchpoint (const struct breakpoint *b) | |
11319 | { | |
11320 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11321 | } | |
11322 | ||
53a5351d JM |
11323 | /* accessflag: hw_write: watch write, |
11324 | hw_read: watch read, | |
11325 | hw_access: watch access (read or write) */ | |
c906108c | 11326 | static void |
bbc13ae3 | 11327 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11328 | int just_location, int internal) |
c906108c | 11329 | { |
a9634178 | 11330 | volatile struct gdb_exception e; |
d983da9c | 11331 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11332 | struct expression *exp; |
270140bd | 11333 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11334 | struct value *val, *mark, *result; |
bb9d5f81 | 11335 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 11336 | struct frame_info *frame; |
bbc13ae3 KS |
11337 | const char *exp_start = NULL; |
11338 | const char *exp_end = NULL; | |
11339 | const char *tok, *end_tok; | |
9c06b0b4 | 11340 | int toklen = -1; |
bbc13ae3 KS |
11341 | const char *cond_start = NULL; |
11342 | const char *cond_end = NULL; | |
c906108c | 11343 | enum bptype bp_type; |
37e4754d | 11344 | int thread = -1; |
0cf6dd15 | 11345 | int pc = 0; |
9c06b0b4 TJB |
11346 | /* Flag to indicate whether we are going to use masks for |
11347 | the hardware watchpoint. */ | |
11348 | int use_mask = 0; | |
11349 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11350 | struct watchpoint *w; |
bbc13ae3 KS |
11351 | char *expression; |
11352 | struct cleanup *back_to; | |
c906108c | 11353 | |
37e4754d LM |
11354 | /* Make sure that we actually have parameters to parse. */ |
11355 | if (arg != NULL && arg[0] != '\0') | |
11356 | { | |
bbc13ae3 KS |
11357 | const char *value_start; |
11358 | ||
11359 | exp_end = arg + strlen (arg); | |
37e4754d | 11360 | |
9c06b0b4 TJB |
11361 | /* Look for "parameter value" pairs at the end |
11362 | of the arguments string. */ | |
bbc13ae3 | 11363 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11364 | { |
11365 | /* Skip whitespace at the end of the argument list. */ | |
11366 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11367 | tok--; | |
11368 | ||
11369 | /* Find the beginning of the last token. | |
11370 | This is the value of the parameter. */ | |
11371 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11372 | tok--; | |
11373 | value_start = tok + 1; | |
11374 | ||
11375 | /* Skip whitespace. */ | |
11376 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11377 | tok--; | |
11378 | ||
11379 | end_tok = tok; | |
11380 | ||
11381 | /* Find the beginning of the second to last token. | |
11382 | This is the parameter itself. */ | |
11383 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11384 | tok--; | |
11385 | tok++; | |
11386 | toklen = end_tok - tok + 1; | |
11387 | ||
11388 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
11389 | { | |
11390 | /* At this point we've found a "thread" token, which means | |
11391 | the user is trying to set a watchpoint that triggers | |
11392 | only in a specific thread. */ | |
11393 | char *endp; | |
37e4754d | 11394 | |
9c06b0b4 TJB |
11395 | if (thread != -1) |
11396 | error(_("You can specify only one thread.")); | |
37e4754d | 11397 | |
9c06b0b4 TJB |
11398 | /* Extract the thread ID from the next token. */ |
11399 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 11400 | |
9c06b0b4 TJB |
11401 | /* Check if the user provided a valid numeric value for the |
11402 | thread ID. */ | |
11403 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
11404 | error (_("Invalid thread ID specification %s."), value_start); | |
11405 | ||
11406 | /* Check if the thread actually exists. */ | |
11407 | if (!valid_thread_id (thread)) | |
af4908ba | 11408 | invalid_thread_id_error (thread); |
9c06b0b4 TJB |
11409 | } |
11410 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
11411 | { | |
11412 | /* We've found a "mask" token, which means the user wants to | |
11413 | create a hardware watchpoint that is going to have the mask | |
11414 | facility. */ | |
11415 | struct value *mask_value, *mark; | |
37e4754d | 11416 | |
9c06b0b4 TJB |
11417 | if (use_mask) |
11418 | error(_("You can specify only one mask.")); | |
37e4754d | 11419 | |
9c06b0b4 | 11420 | use_mask = just_location = 1; |
37e4754d | 11421 | |
9c06b0b4 TJB |
11422 | mark = value_mark (); |
11423 | mask_value = parse_to_comma_and_eval (&value_start); | |
11424 | mask = value_as_address (mask_value); | |
11425 | value_free_to_mark (mark); | |
11426 | } | |
11427 | else | |
11428 | /* We didn't recognize what we found. We should stop here. */ | |
11429 | break; | |
37e4754d | 11430 | |
9c06b0b4 TJB |
11431 | /* Truncate the string and get rid of the "parameter value" pair before |
11432 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11433 | exp_end = tok; |
9c06b0b4 | 11434 | } |
37e4754d | 11435 | } |
bbc13ae3 KS |
11436 | else |
11437 | exp_end = arg; | |
37e4754d | 11438 | |
bbc13ae3 KS |
11439 | /* Parse the rest of the arguments. From here on out, everything |
11440 | is in terms of a newly allocated string instead of the original | |
11441 | ARG. */ | |
c906108c | 11442 | innermost_block = NULL; |
bbc13ae3 KS |
11443 | expression = savestring (arg, exp_end - arg); |
11444 | back_to = make_cleanup (xfree, expression); | |
11445 | exp_start = arg = expression; | |
1bb9788d | 11446 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11447 | exp_end = arg; |
fa8a61dc TT |
11448 | /* Remove trailing whitespace from the expression before saving it. |
11449 | This makes the eventual display of the expression string a bit | |
11450 | prettier. */ | |
11451 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11452 | --exp_end; | |
11453 | ||
65d79d4b SDJ |
11454 | /* Checking if the expression is not constant. */ |
11455 | if (watchpoint_exp_is_const (exp)) | |
11456 | { | |
11457 | int len; | |
11458 | ||
11459 | len = exp_end - exp_start; | |
11460 | while (len > 0 && isspace (exp_start[len - 1])) | |
11461 | len--; | |
11462 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11463 | } | |
11464 | ||
c906108c SS |
11465 | exp_valid_block = innermost_block; |
11466 | mark = value_mark (); | |
3a1115a0 | 11467 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b | 11468 | |
bb9d5f81 PP |
11469 | if (val != NULL && just_location) |
11470 | { | |
11471 | saved_bitpos = value_bitpos (val); | |
11472 | saved_bitsize = value_bitsize (val); | |
11473 | } | |
11474 | ||
06a64a0b TT |
11475 | if (just_location) |
11476 | { | |
9c06b0b4 TJB |
11477 | int ret; |
11478 | ||
06a64a0b | 11479 | exp_valid_block = NULL; |
a1442452 | 11480 | val = value_addr (result); |
06a64a0b TT |
11481 | release_value (val); |
11482 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11483 | |
11484 | if (use_mask) | |
11485 | { | |
11486 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11487 | mask); | |
11488 | if (ret == -1) | |
11489 | error (_("This target does not support masked watchpoints.")); | |
11490 | else if (ret == -2) | |
11491 | error (_("Invalid mask or memory region.")); | |
11492 | } | |
06a64a0b TT |
11493 | } |
11494 | else if (val != NULL) | |
fa4727a6 | 11495 | release_value (val); |
c906108c | 11496 | |
bbc13ae3 KS |
11497 | tok = skip_spaces_const (arg); |
11498 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11499 | |
11500 | toklen = end_tok - tok; | |
11501 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11502 | { | |
2d134ed3 PA |
11503 | struct expression *cond; |
11504 | ||
60e1c644 | 11505 | innermost_block = NULL; |
c906108c | 11506 | tok = cond_start = end_tok + 1; |
1bb9788d | 11507 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11508 | |
11509 | /* The watchpoint expression may not be local, but the condition | |
11510 | may still be. E.g.: `watch global if local > 0'. */ | |
11511 | cond_exp_valid_block = innermost_block; | |
11512 | ||
2d134ed3 | 11513 | xfree (cond); |
c906108c SS |
11514 | cond_end = tok; |
11515 | } | |
11516 | if (*tok) | |
8a3fe4f8 | 11517 | error (_("Junk at end of command.")); |
c906108c | 11518 | |
d983da9c | 11519 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11520 | |
11521 | /* If the expression is "local", then set up a "watchpoint scope" | |
11522 | breakpoint at the point where we've left the scope of the watchpoint | |
11523 | expression. Create the scope breakpoint before the watchpoint, so | |
11524 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11525 | if (exp_valid_block && frame) |
d983da9c | 11526 | { |
edb3359d DJ |
11527 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11528 | { | |
11529 | scope_breakpoint | |
a6d9a66e UW |
11530 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11531 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11532 | bp_watchpoint_scope, |
11533 | &momentary_breakpoint_ops); | |
d983da9c | 11534 | |
edb3359d | 11535 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11536 | |
edb3359d DJ |
11537 | /* Automatically delete the breakpoint when it hits. */ |
11538 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11539 | |
edb3359d DJ |
11540 | /* Only break in the proper frame (help with recursion). */ |
11541 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11542 | |
edb3359d | 11543 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11544 | scope_breakpoint->loc->gdbarch |
11545 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11546 | scope_breakpoint->loc->requested_address |
11547 | = frame_unwind_caller_pc (frame); | |
11548 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11549 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11550 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11551 | scope_breakpoint->type); |
11552 | } | |
d983da9c DJ |
11553 | } |
11554 | ||
e8369a73 AB |
11555 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11556 | watchpoints here even if hardware watchpoints are turned off, a call | |
11557 | to update_watchpoint later in this function will cause the type to | |
11558 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11559 | ||
11560 | if (accessflag == hw_read) | |
11561 | bp_type = bp_read_watchpoint; | |
11562 | else if (accessflag == hw_access) | |
11563 | bp_type = bp_access_watchpoint; | |
11564 | else | |
11565 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11566 | |
11567 | w = XCNEW (struct watchpoint); | |
11568 | b = &w->base; | |
348d480f | 11569 | if (use_mask) |
3a5c3e22 PA |
11570 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11571 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11572 | else |
3a5c3e22 PA |
11573 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11574 | &watchpoint_breakpoint_ops); | |
37e4754d | 11575 | b->thread = thread; |
b5de0fa7 | 11576 | b->disposition = disp_donttouch; |
348d480f | 11577 | b->pspace = current_program_space; |
3a5c3e22 PA |
11578 | w->exp = exp; |
11579 | w->exp_valid_block = exp_valid_block; | |
11580 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11581 | if (just_location) |
11582 | { | |
11583 | struct type *t = value_type (val); | |
11584 | CORE_ADDR addr = value_as_address (val); | |
11585 | char *name; | |
11586 | ||
11587 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11588 | name = type_to_string (t); | |
11589 | ||
3a5c3e22 | 11590 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11591 | core_addr_to_string (addr)); |
06a64a0b TT |
11592 | xfree (name); |
11593 | ||
3a5c3e22 | 11594 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11595 | (int) (exp_end - exp_start), exp_start); |
11596 | ||
06a64a0b TT |
11597 | /* The above expression is in C. */ |
11598 | b->language = language_c; | |
11599 | } | |
11600 | else | |
3a5c3e22 | 11601 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11602 | |
11603 | if (use_mask) | |
11604 | { | |
3a5c3e22 | 11605 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11606 | } |
11607 | else | |
11608 | { | |
3a5c3e22 | 11609 | w->val = val; |
bb9d5f81 PP |
11610 | w->val_bitpos = saved_bitpos; |
11611 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11612 | w->val_valid = 1; |
9c06b0b4 | 11613 | } |
77b06cd7 | 11614 | |
c906108c SS |
11615 | if (cond_start) |
11616 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11617 | else | |
11618 | b->cond_string = 0; | |
c5aa993b | 11619 | |
c906108c | 11620 | if (frame) |
f6bc2008 | 11621 | { |
3a5c3e22 PA |
11622 | w->watchpoint_frame = get_frame_id (frame); |
11623 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11624 | } |
c906108c | 11625 | else |
f6bc2008 | 11626 | { |
3a5c3e22 PA |
11627 | w->watchpoint_frame = null_frame_id; |
11628 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11629 | } |
c906108c | 11630 | |
d983da9c | 11631 | if (scope_breakpoint != NULL) |
c906108c | 11632 | { |
d983da9c DJ |
11633 | /* The scope breakpoint is related to the watchpoint. We will |
11634 | need to act on them together. */ | |
11635 | b->related_breakpoint = scope_breakpoint; | |
11636 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11637 | } |
d983da9c | 11638 | |
06a64a0b TT |
11639 | if (!just_location) |
11640 | value_free_to_mark (mark); | |
2d134ed3 | 11641 | |
a9634178 TJB |
11642 | TRY_CATCH (e, RETURN_MASK_ALL) |
11643 | { | |
11644 | /* Finally update the new watchpoint. This creates the locations | |
11645 | that should be inserted. */ | |
3a5c3e22 | 11646 | update_watchpoint (w, 1); |
a9634178 TJB |
11647 | } |
11648 | if (e.reason < 0) | |
11649 | { | |
11650 | delete_breakpoint (b); | |
11651 | throw_exception (e); | |
11652 | } | |
11653 | ||
3ea46bff | 11654 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11655 | do_cleanups (back_to); |
c906108c SS |
11656 | } |
11657 | ||
e09342b5 | 11658 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11659 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11660 | |
c906108c | 11661 | static int |
a9634178 | 11662 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11663 | { |
11664 | int found_memory_cnt = 0; | |
2e70b7b9 | 11665 | struct value *head = v; |
c906108c SS |
11666 | |
11667 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11668 | if (!can_use_hw_watchpoints) |
c906108c | 11669 | return 0; |
c5aa993b | 11670 | |
5c44784c JM |
11671 | /* Make sure that the value of the expression depends only upon |
11672 | memory contents, and values computed from them within GDB. If we | |
11673 | find any register references or function calls, we can't use a | |
11674 | hardware watchpoint. | |
11675 | ||
11676 | The idea here is that evaluating an expression generates a series | |
11677 | of values, one holding the value of every subexpression. (The | |
11678 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11679 | a*b+c.) GDB's values hold almost enough information to establish | |
11680 | the criteria given above --- they identify memory lvalues, | |
11681 | register lvalues, computed values, etcetera. So we can evaluate | |
11682 | the expression, and then scan the chain of values that leaves | |
11683 | behind to decide whether we can detect any possible change to the | |
11684 | expression's final value using only hardware watchpoints. | |
11685 | ||
11686 | However, I don't think that the values returned by inferior | |
11687 | function calls are special in any way. So this function may not | |
11688 | notice that an expression involving an inferior function call | |
11689 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11690 | for (; v; v = value_next (v)) |
c906108c | 11691 | { |
5c44784c | 11692 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11693 | { |
8464be76 DJ |
11694 | if (v != head && value_lazy (v)) |
11695 | /* A lazy memory lvalue in the chain is one that GDB never | |
11696 | needed to fetch; we either just used its address (e.g., | |
11697 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11698 | in `a,b'). This doesn't apply to HEAD; if that is | |
11699 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11700 | ; |
53a5351d | 11701 | else |
5c44784c JM |
11702 | { |
11703 | /* Ahh, memory we actually used! Check if we can cover | |
11704 | it with hardware watchpoints. */ | |
df407dfe | 11705 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11706 | |
11707 | /* We only watch structs and arrays if user asked for it | |
11708 | explicitly, never if they just happen to appear in a | |
11709 | middle of some value chain. */ | |
11710 | if (v == head | |
11711 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11712 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11713 | { | |
42ae5230 | 11714 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11715 | int len; |
11716 | int num_regs; | |
11717 | ||
a9634178 | 11718 | len = (target_exact_watchpoints |
e09342b5 TJB |
11719 | && is_scalar_type_recursive (vtype))? |
11720 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11721 | |
e09342b5 TJB |
11722 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11723 | if (!num_regs) | |
2e70b7b9 MS |
11724 | return 0; |
11725 | else | |
e09342b5 | 11726 | found_memory_cnt += num_regs; |
2e70b7b9 | 11727 | } |
5c44784c | 11728 | } |
c5aa993b | 11729 | } |
5086187c AC |
11730 | else if (VALUE_LVAL (v) != not_lval |
11731 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11732 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11733 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11734 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11735 | } |
11736 | ||
11737 | /* The expression itself looks suitable for using a hardware | |
11738 | watchpoint, but give the target machine a chance to reject it. */ | |
11739 | return found_memory_cnt; | |
11740 | } | |
11741 | ||
8b93c638 | 11742 | void |
84f4c1fe | 11743 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11744 | { |
84f4c1fe | 11745 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11746 | } |
11747 | ||
06a64a0b TT |
11748 | /* A helper function that looks for the "-location" argument and then |
11749 | calls watch_command_1. */ | |
11750 | ||
11751 | static void | |
11752 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11753 | { | |
11754 | int just_location = 0; | |
11755 | ||
11756 | if (arg | |
11757 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11758 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11759 | { | |
e9cafbcc | 11760 | arg = skip_spaces (arg); |
06a64a0b TT |
11761 | just_location = 1; |
11762 | } | |
11763 | ||
84f4c1fe | 11764 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11765 | } |
8926118c | 11766 | |
c5aa993b | 11767 | static void |
fba45db2 | 11768 | watch_command (char *arg, int from_tty) |
c906108c | 11769 | { |
06a64a0b | 11770 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11771 | } |
11772 | ||
8b93c638 | 11773 | void |
84f4c1fe | 11774 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11775 | { |
84f4c1fe | 11776 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11777 | } |
8926118c | 11778 | |
c5aa993b | 11779 | static void |
fba45db2 | 11780 | rwatch_command (char *arg, int from_tty) |
c906108c | 11781 | { |
06a64a0b | 11782 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11783 | } |
11784 | ||
8b93c638 | 11785 | void |
84f4c1fe | 11786 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11787 | { |
84f4c1fe | 11788 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11789 | } |
8926118c | 11790 | |
c5aa993b | 11791 | static void |
fba45db2 | 11792 | awatch_command (char *arg, int from_tty) |
c906108c | 11793 | { |
06a64a0b | 11794 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11795 | } |
c906108c | 11796 | \f |
c5aa993b | 11797 | |
43ff13b4 | 11798 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
11799 | because it uses the mechanisms of breakpoints. */ |
11800 | ||
bfec99b2 PA |
11801 | struct until_break_command_continuation_args |
11802 | { | |
11803 | struct breakpoint *breakpoint; | |
11804 | struct breakpoint *breakpoint2; | |
186c406b | 11805 | int thread_num; |
bfec99b2 PA |
11806 | }; |
11807 | ||
43ff13b4 | 11808 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 11809 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 11810 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 11811 | command. */ |
c2c6d25f | 11812 | static void |
fa4cd53f | 11813 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 11814 | { |
bfec99b2 PA |
11815 | struct until_break_command_continuation_args *a = arg; |
11816 | ||
11817 | delete_breakpoint (a->breakpoint); | |
11818 | if (a->breakpoint2) | |
11819 | delete_breakpoint (a->breakpoint2); | |
186c406b | 11820 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
11821 | } |
11822 | ||
c906108c | 11823 | void |
ae66c1fc | 11824 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11825 | { |
11826 | struct symtabs_and_lines sals; | |
11827 | struct symtab_and_line sal; | |
8556afb4 PA |
11828 | struct frame_info *frame; |
11829 | struct gdbarch *frame_gdbarch; | |
11830 | struct frame_id stack_frame_id; | |
11831 | struct frame_id caller_frame_id; | |
c906108c | 11832 | struct breakpoint *breakpoint; |
f107f563 | 11833 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 11834 | struct cleanup *old_chain; |
186c406b TT |
11835 | int thread; |
11836 | struct thread_info *tp; | |
c906108c | 11837 | |
70509625 | 11838 | clear_proceed_status (0); |
c906108c SS |
11839 | |
11840 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11841 | this function. */ |
c5aa993b | 11842 | |
1bfeeb0f | 11843 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 11844 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11845 | get_last_displayed_symtab (), |
f8eba3c6 | 11846 | get_last_displayed_line ()); |
c906108c | 11847 | else |
f8eba3c6 TT |
11848 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
11849 | (struct symtab *) NULL, 0); | |
c5aa993b | 11850 | |
c906108c | 11851 | if (sals.nelts != 1) |
8a3fe4f8 | 11852 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11853 | |
c906108c | 11854 | sal = sals.sals[0]; |
4a64f543 | 11855 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11856 | |
c906108c | 11857 | if (*arg) |
8a3fe4f8 | 11858 | error (_("Junk at end of arguments.")); |
c5aa993b | 11859 | |
c906108c | 11860 | resolve_sal_pc (&sal); |
c5aa993b | 11861 | |
186c406b TT |
11862 | tp = inferior_thread (); |
11863 | thread = tp->num; | |
11864 | ||
883bc8d1 PA |
11865 | old_chain = make_cleanup (null_cleanup, NULL); |
11866 | ||
8556afb4 PA |
11867 | /* Note linespec handling above invalidates the frame chain. |
11868 | Installing a breakpoint also invalidates the frame chain (as it | |
11869 | may need to switch threads), so do any frame handling before | |
11870 | that. */ | |
11871 | ||
11872 | frame = get_selected_frame (NULL); | |
11873 | frame_gdbarch = get_frame_arch (frame); | |
11874 | stack_frame_id = get_stack_frame_id (frame); | |
11875 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11876 | |
ae66c1fc EZ |
11877 | /* Keep within the current frame, or in frames called by the current |
11878 | one. */ | |
edb3359d | 11879 | |
883bc8d1 | 11880 | if (frame_id_p (caller_frame_id)) |
c906108c | 11881 | { |
883bc8d1 PA |
11882 | struct symtab_and_line sal2; |
11883 | ||
11884 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11885 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 11886 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
11887 | sal2, |
11888 | caller_frame_id, | |
f107f563 VP |
11889 | bp_until); |
11890 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 11891 | |
883bc8d1 | 11892 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11893 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11894 | } |
c5aa993b | 11895 | |
c70a6932 JK |
11896 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11897 | frame = NULL; | |
11898 | ||
883bc8d1 PA |
11899 | if (anywhere) |
11900 | /* If the user told us to continue until a specified location, | |
11901 | we don't specify a frame at which we need to stop. */ | |
11902 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11903 | null_frame_id, bp_until); | |
11904 | else | |
11905 | /* Otherwise, specify the selected frame, because we want to stop | |
11906 | only at the very same frame. */ | |
11907 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11908 | stack_frame_id, bp_until); | |
11909 | make_cleanup_delete_breakpoint (breakpoint); | |
11910 | ||
a493e3e2 | 11911 | proceed (-1, GDB_SIGNAL_DEFAULT, 0); |
f107f563 | 11912 | |
4a64f543 MS |
11913 | /* If we are running asynchronously, and proceed call above has |
11914 | actually managed to start the target, arrange for breakpoints to | |
11915 | be deleted when the target stops. Otherwise, we're already | |
11916 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 11917 | |
8ea051c5 | 11918 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 11919 | { |
bfec99b2 PA |
11920 | struct until_break_command_continuation_args *args; |
11921 | args = xmalloc (sizeof (*args)); | |
f107f563 | 11922 | |
bfec99b2 PA |
11923 | args->breakpoint = breakpoint; |
11924 | args->breakpoint2 = breakpoint2; | |
186c406b | 11925 | args->thread_num = thread; |
f107f563 VP |
11926 | |
11927 | discard_cleanups (old_chain); | |
95e54da7 PA |
11928 | add_continuation (inferior_thread (), |
11929 | until_break_command_continuation, args, | |
604ead4a | 11930 | xfree); |
f107f563 VP |
11931 | } |
11932 | else | |
c5aa993b | 11933 | do_cleanups (old_chain); |
c906108c | 11934 | } |
ae66c1fc | 11935 | |
c906108c SS |
11936 | /* This function attempts to parse an optional "if <cond>" clause |
11937 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11938 | |
c906108c SS |
11939 | Else, it returns a pointer to the condition string. (It does not |
11940 | attempt to evaluate the string against a particular block.) And, | |
11941 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11942 | if clause in the arg string. */ |
53a5351d | 11943 | |
916703c0 | 11944 | char * |
fba45db2 | 11945 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11946 | { |
c5aa993b JM |
11947 | char *cond_string; |
11948 | ||
11949 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11950 | return NULL; |
c5aa993b | 11951 | |
4a64f543 | 11952 | /* Skip the "if" keyword. */ |
c906108c | 11953 | (*arg) += 2; |
c5aa993b | 11954 | |
c906108c | 11955 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11956 | condition string. */ |
e9cafbcc | 11957 | *arg = skip_spaces (*arg); |
c906108c | 11958 | cond_string = *arg; |
c5aa993b | 11959 | |
4a64f543 MS |
11960 | /* Assume that the condition occupies the remainder of the arg |
11961 | string. */ | |
c906108c | 11962 | (*arg) += strlen (cond_string); |
c5aa993b | 11963 | |
c906108c SS |
11964 | return cond_string; |
11965 | } | |
c5aa993b | 11966 | |
c906108c SS |
11967 | /* Commands to deal with catching events, such as signals, exceptions, |
11968 | process start/exit, etc. */ | |
c5aa993b JM |
11969 | |
11970 | typedef enum | |
11971 | { | |
44feb3ce TT |
11972 | catch_fork_temporary, catch_vfork_temporary, |
11973 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11974 | } |
11975 | catch_fork_kind; | |
11976 | ||
c906108c | 11977 | static void |
cc59ec59 MS |
11978 | catch_fork_command_1 (char *arg, int from_tty, |
11979 | struct cmd_list_element *command) | |
c906108c | 11980 | { |
a6d9a66e | 11981 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11982 | char *cond_string = NULL; |
44feb3ce TT |
11983 | catch_fork_kind fork_kind; |
11984 | int tempflag; | |
11985 | ||
11986 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11987 | tempflag = (fork_kind == catch_fork_temporary | |
11988 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11989 | |
44feb3ce TT |
11990 | if (!arg) |
11991 | arg = ""; | |
e9cafbcc | 11992 | arg = skip_spaces (arg); |
c5aa993b | 11993 | |
c906108c | 11994 | /* The allowed syntax is: |
c5aa993b JM |
11995 | catch [v]fork |
11996 | catch [v]fork if <cond> | |
11997 | ||
4a64f543 | 11998 | First, check if there's an if clause. */ |
c906108c | 11999 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 12000 | |
c906108c | 12001 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 12002 | error (_("Junk at end of arguments.")); |
c5aa993b | 12003 | |
c906108c | 12004 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 12005 | and enable reporting of such events. */ |
c5aa993b JM |
12006 | switch (fork_kind) |
12007 | { | |
44feb3ce TT |
12008 | case catch_fork_temporary: |
12009 | case catch_fork_permanent: | |
a6d9a66e | 12010 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 12011 | &catch_fork_breakpoint_ops); |
c906108c | 12012 | break; |
44feb3ce TT |
12013 | case catch_vfork_temporary: |
12014 | case catch_vfork_permanent: | |
a6d9a66e | 12015 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 12016 | &catch_vfork_breakpoint_ops); |
c906108c | 12017 | break; |
c5aa993b | 12018 | default: |
8a3fe4f8 | 12019 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 12020 | break; |
c5aa993b | 12021 | } |
c906108c SS |
12022 | } |
12023 | ||
12024 | static void | |
cc59ec59 MS |
12025 | catch_exec_command_1 (char *arg, int from_tty, |
12026 | struct cmd_list_element *command) | |
c906108c | 12027 | { |
b4d90040 | 12028 | struct exec_catchpoint *c; |
a6d9a66e | 12029 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 12030 | int tempflag; |
c5aa993b | 12031 | char *cond_string = NULL; |
c906108c | 12032 | |
44feb3ce TT |
12033 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
12034 | ||
12035 | if (!arg) | |
12036 | arg = ""; | |
e9cafbcc | 12037 | arg = skip_spaces (arg); |
c906108c SS |
12038 | |
12039 | /* The allowed syntax is: | |
c5aa993b JM |
12040 | catch exec |
12041 | catch exec if <cond> | |
c906108c | 12042 | |
4a64f543 | 12043 | First, check if there's an if clause. */ |
c906108c SS |
12044 | cond_string = ep_parse_optional_if_clause (&arg); |
12045 | ||
12046 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 12047 | error (_("Junk at end of arguments.")); |
c906108c | 12048 | |
b4d90040 PA |
12049 | c = XNEW (struct exec_catchpoint); |
12050 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
12051 | &catch_exec_breakpoint_ops); | |
12052 | c->exec_pathname = NULL; | |
12053 | ||
3ea46bff | 12054 | install_breakpoint (0, &c->base, 1); |
c906108c | 12055 | } |
c5aa993b | 12056 | |
9ac4176b | 12057 | void |
28010a5d PA |
12058 | init_ada_exception_breakpoint (struct breakpoint *b, |
12059 | struct gdbarch *gdbarch, | |
12060 | struct symtab_and_line sal, | |
12061 | char *addr_string, | |
c0a91b2b | 12062 | const struct breakpoint_ops *ops, |
28010a5d | 12063 | int tempflag, |
349774ef | 12064 | int enabled, |
28010a5d | 12065 | int from_tty) |
f7f9143b | 12066 | { |
f7f9143b JB |
12067 | if (from_tty) |
12068 | { | |
5af949e3 UW |
12069 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
12070 | if (!loc_gdbarch) | |
12071 | loc_gdbarch = gdbarch; | |
12072 | ||
6c95b8df PA |
12073 | describe_other_breakpoints (loc_gdbarch, |
12074 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
12075 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
12076 | version for exception catchpoints, because two catchpoints | |
12077 | used for different exception names will use the same address. | |
12078 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 12079 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 12080 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
12081 | the user what type of catchpoint it is. The above is good |
12082 | enough for now, though. */ | |
12083 | } | |
12084 | ||
28010a5d | 12085 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 12086 | |
349774ef | 12087 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 12088 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f7f9143b JB |
12089 | b->addr_string = addr_string; |
12090 | b->language = language_ada; | |
f7f9143b JB |
12091 | } |
12092 | ||
a96d9b2e SDJ |
12093 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
12094 | filter list, or NULL if no filtering is required. */ | |
12095 | static VEC(int) * | |
12096 | catch_syscall_split_args (char *arg) | |
12097 | { | |
12098 | VEC(int) *result = NULL; | |
29d0bb3d | 12099 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
12100 | |
12101 | while (*arg != '\0') | |
12102 | { | |
12103 | int i, syscall_number; | |
12104 | char *endptr; | |
12105 | char cur_name[128]; | |
12106 | struct syscall s; | |
12107 | ||
12108 | /* Skip whitespace. */ | |
529480d0 | 12109 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
12110 | |
12111 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
12112 | cur_name[i] = arg[i]; | |
12113 | cur_name[i] = '\0'; | |
12114 | arg += i; | |
12115 | ||
12116 | /* Check if the user provided a syscall name or a number. */ | |
12117 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
12118 | if (*endptr == '\0') | |
bccd0dd2 | 12119 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
12120 | else |
12121 | { | |
12122 | /* We have a name. Let's check if it's valid and convert it | |
12123 | to a number. */ | |
12124 | get_syscall_by_name (cur_name, &s); | |
12125 | ||
12126 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
12127 | /* Here we have to issue an error instead of a warning, |
12128 | because GDB cannot do anything useful if there's no | |
12129 | syscall number to be caught. */ | |
a96d9b2e SDJ |
12130 | error (_("Unknown syscall name '%s'."), cur_name); |
12131 | } | |
12132 | ||
12133 | /* Ok, it's valid. */ | |
12134 | VEC_safe_push (int, result, s.number); | |
12135 | } | |
12136 | ||
12137 | discard_cleanups (cleanup); | |
12138 | return result; | |
12139 | } | |
12140 | ||
12141 | /* Implement the "catch syscall" command. */ | |
12142 | ||
12143 | static void | |
cc59ec59 MS |
12144 | catch_syscall_command_1 (char *arg, int from_tty, |
12145 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
12146 | { |
12147 | int tempflag; | |
12148 | VEC(int) *filter; | |
12149 | struct syscall s; | |
12150 | struct gdbarch *gdbarch = get_current_arch (); | |
12151 | ||
12152 | /* Checking if the feature if supported. */ | |
12153 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
12154 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 12155 | this architecture yet.")); |
a96d9b2e SDJ |
12156 | |
12157 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
12158 | ||
e9cafbcc | 12159 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
12160 | |
12161 | /* We need to do this first "dummy" translation in order | |
12162 | to get the syscall XML file loaded or, most important, | |
12163 | to display a warning to the user if there's no XML file | |
12164 | for his/her architecture. */ | |
12165 | get_syscall_by_number (0, &s); | |
12166 | ||
12167 | /* The allowed syntax is: | |
12168 | catch syscall | |
12169 | catch syscall <name | number> [<name | number> ... <name | number>] | |
12170 | ||
12171 | Let's check if there's a syscall name. */ | |
12172 | ||
12173 | if (arg != NULL) | |
12174 | filter = catch_syscall_split_args (arg); | |
12175 | else | |
12176 | filter = NULL; | |
12177 | ||
12178 | create_syscall_event_catchpoint (tempflag, filter, | |
12179 | &catch_syscall_breakpoint_ops); | |
12180 | } | |
12181 | ||
c906108c | 12182 | static void |
fba45db2 | 12183 | catch_command (char *arg, int from_tty) |
c906108c | 12184 | { |
44feb3ce | 12185 | error (_("Catch requires an event name.")); |
c906108c SS |
12186 | } |
12187 | \f | |
12188 | ||
12189 | static void | |
fba45db2 | 12190 | tcatch_command (char *arg, int from_tty) |
c906108c | 12191 | { |
44feb3ce | 12192 | error (_("Catch requires an event name.")); |
c906108c SS |
12193 | } |
12194 | ||
8a2c437b TT |
12195 | /* A qsort comparison function that sorts breakpoints in order. */ |
12196 | ||
12197 | static int | |
12198 | compare_breakpoints (const void *a, const void *b) | |
12199 | { | |
12200 | const breakpoint_p *ba = a; | |
12201 | uintptr_t ua = (uintptr_t) *ba; | |
12202 | const breakpoint_p *bb = b; | |
12203 | uintptr_t ub = (uintptr_t) *bb; | |
12204 | ||
12205 | if ((*ba)->number < (*bb)->number) | |
12206 | return -1; | |
12207 | else if ((*ba)->number > (*bb)->number) | |
12208 | return 1; | |
12209 | ||
12210 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
12211 | the number 0. */ | |
12212 | if (ua < ub) | |
12213 | return -1; | |
94b0e70d | 12214 | return ua > ub ? 1 : 0; |
8a2c437b TT |
12215 | } |
12216 | ||
80f8a6eb | 12217 | /* Delete breakpoints by address or line. */ |
c906108c SS |
12218 | |
12219 | static void | |
fba45db2 | 12220 | clear_command (char *arg, int from_tty) |
c906108c | 12221 | { |
8a2c437b | 12222 | struct breakpoint *b, *prev; |
d6e956e5 VP |
12223 | VEC(breakpoint_p) *found = 0; |
12224 | int ix; | |
c906108c SS |
12225 | int default_match; |
12226 | struct symtabs_and_lines sals; | |
12227 | struct symtab_and_line sal; | |
c906108c | 12228 | int i; |
8a2c437b | 12229 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
12230 | |
12231 | if (arg) | |
12232 | { | |
39cf75f7 DE |
12233 | sals = decode_line_with_current_source (arg, |
12234 | (DECODE_LINE_FUNFIRSTLINE | |
12235 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 12236 | make_cleanup (xfree, sals.sals); |
c906108c SS |
12237 | default_match = 0; |
12238 | } | |
12239 | else | |
12240 | { | |
c5aa993b | 12241 | sals.sals = (struct symtab_and_line *) |
c906108c | 12242 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 12243 | make_cleanup (xfree, sals.sals); |
4a64f543 | 12244 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
12245 | |
12246 | /* Set sal's line, symtab, pc, and pspace to the values | |
12247 | corresponding to the last call to print_frame_info. If the | |
12248 | codepoint is not valid, this will set all the fields to 0. */ | |
12249 | get_last_displayed_sal (&sal); | |
c906108c | 12250 | if (sal.symtab == 0) |
8a3fe4f8 | 12251 | error (_("No source file specified.")); |
c906108c SS |
12252 | |
12253 | sals.sals[0] = sal; | |
12254 | sals.nelts = 1; | |
12255 | ||
12256 | default_match = 1; | |
12257 | } | |
12258 | ||
4a64f543 MS |
12259 | /* We don't call resolve_sal_pc here. That's not as bad as it |
12260 | seems, because all existing breakpoints typically have both | |
12261 | file/line and pc set. So, if clear is given file/line, we can | |
12262 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
12263 | |
12264 | We only support clearing given the address explicitly | |
12265 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 12266 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 12267 | due to optimization, all in one block. |
4a64f543 MS |
12268 | |
12269 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
12270 | PC corresponding to the same file:line, the breakpoint won't |
12271 | be cleared. We probably can still clear the breakpoint, but | |
12272 | since the other PC value is never presented to user, user | |
12273 | can only find it by guessing, and it does not seem important | |
12274 | to support that. */ | |
12275 | ||
4a64f543 MS |
12276 | /* For each line spec given, delete bps which correspond to it. Do |
12277 | it in two passes, solely to preserve the current behavior that | |
12278 | from_tty is forced true if we delete more than one | |
12279 | breakpoint. */ | |
c906108c | 12280 | |
80f8a6eb | 12281 | found = NULL; |
8a2c437b | 12282 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12283 | for (i = 0; i < sals.nelts; i++) |
12284 | { | |
05cba821 JK |
12285 | const char *sal_fullname; |
12286 | ||
c906108c | 12287 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12288 | If line given (pc == 0), clear all bpts on specified line. |
12289 | If defaulting, clear all bpts on default line | |
c906108c | 12290 | or at default pc. |
c5aa993b JM |
12291 | |
12292 | defaulting sal.pc != 0 tests to do | |
12293 | ||
12294 | 0 1 pc | |
12295 | 1 1 pc _and_ line | |
12296 | 0 0 line | |
12297 | 1 0 <can't happen> */ | |
c906108c SS |
12298 | |
12299 | sal = sals.sals[i]; | |
05cba821 JK |
12300 | sal_fullname = (sal.symtab == NULL |
12301 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12302 | |
4a64f543 | 12303 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12304 | ALL_BREAKPOINTS (b) |
c5aa993b | 12305 | { |
0d381245 | 12306 | int match = 0; |
4a64f543 | 12307 | /* Are we going to delete b? */ |
cc60f2e3 | 12308 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12309 | { |
12310 | struct bp_location *loc = b->loc; | |
12311 | for (; loc; loc = loc->next) | |
12312 | { | |
f8eba3c6 TT |
12313 | /* If the user specified file:line, don't allow a PC |
12314 | match. This matches historical gdb behavior. */ | |
12315 | int pc_match = (!sal.explicit_line | |
12316 | && sal.pc | |
12317 | && (loc->pspace == sal.pspace) | |
12318 | && (loc->address == sal.pc) | |
12319 | && (!section_is_overlay (loc->section) | |
12320 | || loc->section == sal.section)); | |
4aac40c8 TT |
12321 | int line_match = 0; |
12322 | ||
12323 | if ((default_match || sal.explicit_line) | |
2f202fde | 12324 | && loc->symtab != NULL |
05cba821 | 12325 | && sal_fullname != NULL |
4aac40c8 | 12326 | && sal.pspace == loc->pspace |
05cba821 JK |
12327 | && loc->line_number == sal.line |
12328 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12329 | sal_fullname) == 0) | |
12330 | line_match = 1; | |
4aac40c8 | 12331 | |
0d381245 VP |
12332 | if (pc_match || line_match) |
12333 | { | |
12334 | match = 1; | |
12335 | break; | |
12336 | } | |
12337 | } | |
12338 | } | |
12339 | ||
12340 | if (match) | |
d6e956e5 | 12341 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12342 | } |
80f8a6eb | 12343 | } |
8a2c437b | 12344 | |
80f8a6eb | 12345 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12346 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12347 | { |
12348 | if (arg) | |
8a3fe4f8 | 12349 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12350 | else |
8a3fe4f8 | 12351 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12352 | } |
c906108c | 12353 | |
8a2c437b TT |
12354 | /* Remove duplicates from the vec. */ |
12355 | qsort (VEC_address (breakpoint_p, found), | |
12356 | VEC_length (breakpoint_p, found), | |
12357 | sizeof (breakpoint_p), | |
12358 | compare_breakpoints); | |
12359 | prev = VEC_index (breakpoint_p, found, 0); | |
12360 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12361 | { | |
12362 | if (b == prev) | |
12363 | { | |
12364 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12365 | --ix; | |
12366 | } | |
12367 | } | |
12368 | ||
d6e956e5 | 12369 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12370 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12371 | if (from_tty) |
a3f17187 | 12372 | { |
d6e956e5 | 12373 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12374 | printf_unfiltered (_("Deleted breakpoint ")); |
12375 | else | |
12376 | printf_unfiltered (_("Deleted breakpoints ")); | |
12377 | } | |
d6e956e5 VP |
12378 | |
12379 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12380 | { |
c5aa993b | 12381 | if (from_tty) |
d6e956e5 VP |
12382 | printf_unfiltered ("%d ", b->number); |
12383 | delete_breakpoint (b); | |
c906108c | 12384 | } |
80f8a6eb MS |
12385 | if (from_tty) |
12386 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12387 | |
12388 | do_cleanups (cleanups); | |
c906108c SS |
12389 | } |
12390 | \f | |
12391 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12392 | all breakpoints that are marked for deletion, whether hit or not. | |
12393 | This is called after any breakpoint is hit, or after errors. */ | |
12394 | ||
12395 | void | |
fba45db2 | 12396 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12397 | { |
35df4500 | 12398 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12399 | |
12400 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12401 | if (bs->breakpoint_at |
12402 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12403 | && bs->stop) |
f431efe5 | 12404 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12405 | |
35df4500 | 12406 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12407 | { |
b5de0fa7 | 12408 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12409 | delete_breakpoint (b); |
12410 | } | |
c906108c SS |
12411 | } |
12412 | ||
4a64f543 MS |
12413 | /* A comparison function for bp_location AP and BP being interfaced to |
12414 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12415 | does breakpoint_address_is_meaningful say for its OWNER), | |
12416 | secondarily by ordering first bp_permanent OWNERed elements and | |
12417 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 12418 | qsort being an unstable algorithm. */ |
876fa593 JK |
12419 | |
12420 | static int | |
494cfb0f | 12421 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12422 | { |
494cfb0f JK |
12423 | struct bp_location *a = *(void **) ap; |
12424 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 12425 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
12426 | int a_perm = a->owner->enable_state == bp_permanent; |
12427 | int b_perm = b->owner->enable_state == bp_permanent; | |
12428 | ||
12429 | if (a->address != b->address) | |
12430 | return (a->address > b->address) - (a->address < b->address); | |
12431 | ||
dea2aa5f LM |
12432 | /* Sort locations at the same address by their pspace number, keeping |
12433 | locations of the same inferior (in a multi-inferior environment) | |
12434 | grouped. */ | |
12435 | ||
12436 | if (a->pspace->num != b->pspace->num) | |
12437 | return ((a->pspace->num > b->pspace->num) | |
12438 | - (a->pspace->num < b->pspace->num)); | |
12439 | ||
876fa593 JK |
12440 | /* Sort permanent breakpoints first. */ |
12441 | if (a_perm != b_perm) | |
12442 | return (a_perm < b_perm) - (a_perm > b_perm); | |
12443 | ||
c56a97f9 JK |
12444 | /* Make the internal GDB representation stable across GDB runs |
12445 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12446 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12447 | |
12448 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12449 | return ((a->owner->number > b->owner->number) |
12450 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12451 | |
12452 | return (a > b) - (a < b); | |
12453 | } | |
12454 | ||
876fa593 | 12455 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12456 | bp_location_shadow_len_after_address_max according to the current |
12457 | content of the bp_location array. */ | |
f7545552 TT |
12458 | |
12459 | static void | |
876fa593 | 12460 | bp_location_target_extensions_update (void) |
f7545552 | 12461 | { |
876fa593 JK |
12462 | struct bp_location *bl, **blp_tmp; |
12463 | ||
12464 | bp_location_placed_address_before_address_max = 0; | |
12465 | bp_location_shadow_len_after_address_max = 0; | |
12466 | ||
12467 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12468 | { | |
12469 | CORE_ADDR start, end, addr; | |
12470 | ||
12471 | if (!bp_location_has_shadow (bl)) | |
12472 | continue; | |
12473 | ||
12474 | start = bl->target_info.placed_address; | |
12475 | end = start + bl->target_info.shadow_len; | |
12476 | ||
12477 | gdb_assert (bl->address >= start); | |
12478 | addr = bl->address - start; | |
12479 | if (addr > bp_location_placed_address_before_address_max) | |
12480 | bp_location_placed_address_before_address_max = addr; | |
12481 | ||
12482 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12483 | ||
12484 | gdb_assert (bl->address < end); | |
12485 | addr = end - bl->address; | |
12486 | if (addr > bp_location_shadow_len_after_address_max) | |
12487 | bp_location_shadow_len_after_address_max = addr; | |
12488 | } | |
f7545552 TT |
12489 | } |
12490 | ||
1e4d1764 YQ |
12491 | /* Download tracepoint locations if they haven't been. */ |
12492 | ||
12493 | static void | |
12494 | download_tracepoint_locations (void) | |
12495 | { | |
7ed2c994 | 12496 | struct breakpoint *b; |
1e4d1764 YQ |
12497 | struct cleanup *old_chain; |
12498 | ||
12499 | if (!target_can_download_tracepoint ()) | |
12500 | return; | |
12501 | ||
12502 | old_chain = save_current_space_and_thread (); | |
12503 | ||
7ed2c994 | 12504 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12505 | { |
7ed2c994 | 12506 | struct bp_location *bl; |
1e4d1764 | 12507 | struct tracepoint *t; |
f2a8bc8a | 12508 | int bp_location_downloaded = 0; |
1e4d1764 | 12509 | |
7ed2c994 | 12510 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12511 | ? !may_insert_fast_tracepoints |
12512 | : !may_insert_tracepoints)) | |
12513 | continue; | |
12514 | ||
7ed2c994 YQ |
12515 | for (bl = b->loc; bl; bl = bl->next) |
12516 | { | |
12517 | /* In tracepoint, locations are _never_ duplicated, so | |
12518 | should_be_inserted is equivalent to | |
12519 | unduplicated_should_be_inserted. */ | |
12520 | if (!should_be_inserted (bl) || bl->inserted) | |
12521 | continue; | |
1e4d1764 | 12522 | |
7ed2c994 | 12523 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12524 | |
7ed2c994 | 12525 | target_download_tracepoint (bl); |
1e4d1764 | 12526 | |
7ed2c994 | 12527 | bl->inserted = 1; |
f2a8bc8a | 12528 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12529 | } |
12530 | t = (struct tracepoint *) b; | |
12531 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12532 | if (bp_location_downloaded) |
12533 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12534 | } |
12535 | ||
12536 | do_cleanups (old_chain); | |
12537 | } | |
12538 | ||
934709f0 PW |
12539 | /* Swap the insertion/duplication state between two locations. */ |
12540 | ||
12541 | static void | |
12542 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12543 | { | |
12544 | const int left_inserted = left->inserted; | |
12545 | const int left_duplicate = left->duplicate; | |
b775012e | 12546 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12547 | const struct bp_target_info left_target_info = left->target_info; |
12548 | ||
1e4d1764 YQ |
12549 | /* Locations of tracepoints can never be duplicated. */ |
12550 | if (is_tracepoint (left->owner)) | |
12551 | gdb_assert (!left->duplicate); | |
12552 | if (is_tracepoint (right->owner)) | |
12553 | gdb_assert (!right->duplicate); | |
12554 | ||
934709f0 PW |
12555 | left->inserted = right->inserted; |
12556 | left->duplicate = right->duplicate; | |
b775012e | 12557 | left->needs_update = right->needs_update; |
934709f0 PW |
12558 | left->target_info = right->target_info; |
12559 | right->inserted = left_inserted; | |
12560 | right->duplicate = left_duplicate; | |
b775012e | 12561 | right->needs_update = left_needs_update; |
934709f0 PW |
12562 | right->target_info = left_target_info; |
12563 | } | |
12564 | ||
b775012e LM |
12565 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12566 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12567 | conditions on the target's side. Such conditions need to be updated on | |
12568 | the target. */ | |
12569 | ||
12570 | static void | |
12571 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12572 | { | |
12573 | struct bp_location **locp = NULL, **loc2p; | |
12574 | struct bp_location *loc; | |
12575 | CORE_ADDR address = 0; | |
12576 | int pspace_num; | |
12577 | ||
12578 | address = bl->address; | |
12579 | pspace_num = bl->pspace->num; | |
12580 | ||
12581 | /* This is only meaningful if the target is | |
12582 | evaluating conditions and if the user has | |
12583 | opted for condition evaluation on the target's | |
12584 | side. */ | |
12585 | if (gdb_evaluates_breakpoint_condition_p () | |
12586 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12587 | return; | |
12588 | ||
12589 | /* Flag all breakpoint locations with this address and | |
12590 | the same program space as the location | |
12591 | as "its condition has changed". We need to | |
12592 | update the conditions on the target's side. */ | |
12593 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12594 | { | |
12595 | loc = *loc2p; | |
12596 | ||
12597 | if (!is_breakpoint (loc->owner) | |
12598 | || pspace_num != loc->pspace->num) | |
12599 | continue; | |
12600 | ||
12601 | /* Flag the location appropriately. We use a different state to | |
12602 | let everyone know that we already updated the set of locations | |
12603 | with addr bl->address and program space bl->pspace. This is so | |
12604 | we don't have to keep calling these functions just to mark locations | |
12605 | that have already been marked. */ | |
12606 | loc->condition_changed = condition_updated; | |
12607 | ||
12608 | /* Free the agent expression bytecode as well. We will compute | |
12609 | it later on. */ | |
12610 | if (loc->cond_bytecode) | |
12611 | { | |
12612 | free_agent_expr (loc->cond_bytecode); | |
12613 | loc->cond_bytecode = NULL; | |
12614 | } | |
12615 | } | |
12616 | } | |
44702360 PA |
12617 | /* Called whether new breakpoints are created, or existing breakpoints |
12618 | deleted, to update the global location list and recompute which | |
12619 | locations are duplicate of which. | |
b775012e | 12620 | |
04086b45 PA |
12621 | The INSERT_MODE flag determines whether locations may not, may, or |
12622 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12623 | info. */ | |
b60e7edf | 12624 | |
0d381245 | 12625 | static void |
44702360 | 12626 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12627 | { |
74960c60 | 12628 | struct breakpoint *b; |
876fa593 | 12629 | struct bp_location **locp, *loc; |
f7545552 | 12630 | struct cleanup *cleanups; |
b775012e LM |
12631 | /* Last breakpoint location address that was marked for update. */ |
12632 | CORE_ADDR last_addr = 0; | |
12633 | /* Last breakpoint location program space that was marked for update. */ | |
12634 | int last_pspace_num = -1; | |
f7545552 | 12635 | |
2d134ed3 PA |
12636 | /* Used in the duplicates detection below. When iterating over all |
12637 | bp_locations, points to the first bp_location of a given address. | |
12638 | Breakpoints and watchpoints of different types are never | |
12639 | duplicates of each other. Keep one pointer for each type of | |
12640 | breakpoint/watchpoint, so we only need to loop over all locations | |
12641 | once. */ | |
12642 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12643 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12644 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12645 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12646 | |
4a64f543 MS |
12647 | /* Saved former bp_location array which we compare against the newly |
12648 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12649 | struct bp_location **old_location, **old_locp; |
12650 | unsigned old_location_count; | |
12651 | ||
12652 | old_location = bp_location; | |
12653 | old_location_count = bp_location_count; | |
12654 | bp_location = NULL; | |
12655 | bp_location_count = 0; | |
12656 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12657 | |
74960c60 | 12658 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12659 | for (loc = b->loc; loc; loc = loc->next) |
12660 | bp_location_count++; | |
12661 | ||
12662 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
12663 | locp = bp_location; | |
12664 | ALL_BREAKPOINTS (b) | |
12665 | for (loc = b->loc; loc; loc = loc->next) | |
12666 | *locp++ = loc; | |
12667 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12668 | bp_location_compare); |
876fa593 JK |
12669 | |
12670 | bp_location_target_extensions_update (); | |
74960c60 | 12671 | |
4a64f543 MS |
12672 | /* Identify bp_location instances that are no longer present in the |
12673 | new list, and therefore should be freed. Note that it's not | |
12674 | necessary that those locations should be removed from inferior -- | |
12675 | if there's another location at the same address (previously | |
12676 | marked as duplicate), we don't need to remove/insert the | |
12677 | location. | |
876fa593 | 12678 | |
4a64f543 MS |
12679 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12680 | and former bp_location array state respectively. */ | |
876fa593 JK |
12681 | |
12682 | locp = bp_location; | |
12683 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12684 | old_locp++) | |
74960c60 | 12685 | { |
876fa593 | 12686 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12687 | struct bp_location **loc2p; |
876fa593 | 12688 | |
e5dd4106 | 12689 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12690 | not, we have to free it. */ |
c7d46a38 | 12691 | int found_object = 0; |
20874c92 VP |
12692 | /* Tells if the location should remain inserted in the target. */ |
12693 | int keep_in_target = 0; | |
12694 | int removed = 0; | |
876fa593 | 12695 | |
4a64f543 MS |
12696 | /* Skip LOCP entries which will definitely never be needed. |
12697 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12698 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12699 | && (*locp)->address < old_loc->address) |
876fa593 | 12700 | locp++; |
c7d46a38 PA |
12701 | |
12702 | for (loc2p = locp; | |
12703 | (loc2p < bp_location + bp_location_count | |
12704 | && (*loc2p)->address == old_loc->address); | |
12705 | loc2p++) | |
12706 | { | |
b775012e LM |
12707 | /* Check if this is a new/duplicated location or a duplicated |
12708 | location that had its condition modified. If so, we want to send | |
12709 | its condition to the target if evaluation of conditions is taking | |
12710 | place there. */ | |
12711 | if ((*loc2p)->condition_changed == condition_modified | |
12712 | && (last_addr != old_loc->address | |
12713 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12714 | { |
b775012e LM |
12715 | force_breakpoint_reinsertion (*loc2p); |
12716 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12717 | } |
b775012e LM |
12718 | |
12719 | if (*loc2p == old_loc) | |
12720 | found_object = 1; | |
c7d46a38 | 12721 | } |
74960c60 | 12722 | |
b775012e LM |
12723 | /* We have already handled this address, update it so that we don't |
12724 | have to go through updates again. */ | |
12725 | last_addr = old_loc->address; | |
12726 | ||
12727 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12728 | if (!found_object) | |
12729 | force_breakpoint_reinsertion (old_loc); | |
12730 | ||
4a64f543 MS |
12731 | /* If this location is no longer present, and inserted, look if |
12732 | there's maybe a new location at the same address. If so, | |
12733 | mark that one inserted, and don't remove this one. This is | |
12734 | needed so that we don't have a time window where a breakpoint | |
12735 | at certain location is not inserted. */ | |
74960c60 | 12736 | |
876fa593 | 12737 | if (old_loc->inserted) |
0d381245 | 12738 | { |
4a64f543 MS |
12739 | /* If the location is inserted now, we might have to remove |
12740 | it. */ | |
74960c60 | 12741 | |
876fa593 | 12742 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12743 | { |
4a64f543 MS |
12744 | /* The location is still present in the location list, |
12745 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12746 | keep_in_target = 1; |
74960c60 VP |
12747 | } |
12748 | else | |
12749 | { | |
b775012e LM |
12750 | /* This location still exists, but it won't be kept in the |
12751 | target since it may have been disabled. We proceed to | |
12752 | remove its target-side condition. */ | |
12753 | ||
4a64f543 MS |
12754 | /* The location is either no longer present, or got |
12755 | disabled. See if there's another location at the | |
12756 | same address, in which case we don't need to remove | |
12757 | this one from the target. */ | |
876fa593 | 12758 | |
2bdf28a0 | 12759 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12760 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12761 | { | |
876fa593 | 12762 | for (loc2p = locp; |
c7d46a38 PA |
12763 | (loc2p < bp_location + bp_location_count |
12764 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12765 | loc2p++) |
12766 | { | |
12767 | struct bp_location *loc2 = *loc2p; | |
12768 | ||
2d134ed3 | 12769 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12770 | { |
85d721b8 PA |
12771 | /* Read watchpoint locations are switched to |
12772 | access watchpoints, if the former are not | |
12773 | supported, but the latter are. */ | |
12774 | if (is_hardware_watchpoint (old_loc->owner)) | |
12775 | { | |
12776 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12777 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12778 | } | |
12779 | ||
934709f0 PW |
12780 | /* loc2 is a duplicated location. We need to check |
12781 | if it should be inserted in case it will be | |
12782 | unduplicated. */ | |
12783 | if (loc2 != old_loc | |
12784 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12785 | { |
934709f0 | 12786 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12787 | keep_in_target = 1; |
12788 | break; | |
12789 | } | |
876fa593 JK |
12790 | } |
12791 | } | |
12792 | } | |
74960c60 VP |
12793 | } |
12794 | ||
20874c92 VP |
12795 | if (!keep_in_target) |
12796 | { | |
876fa593 | 12797 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12798 | { |
4a64f543 MS |
12799 | /* This is just about all we can do. We could keep |
12800 | this location on the global list, and try to | |
12801 | remove it next time, but there's no particular | |
12802 | reason why we will succeed next time. | |
20874c92 | 12803 | |
4a64f543 MS |
12804 | Note that at this point, old_loc->owner is still |
12805 | valid, as delete_breakpoint frees the breakpoint | |
12806 | only after calling us. */ | |
3e43a32a MS |
12807 | printf_filtered (_("warning: Error removing " |
12808 | "breakpoint %d\n"), | |
876fa593 | 12809 | old_loc->owner->number); |
20874c92 VP |
12810 | } |
12811 | removed = 1; | |
12812 | } | |
0d381245 | 12813 | } |
74960c60 VP |
12814 | |
12815 | if (!found_object) | |
1c5cfe86 | 12816 | { |
db82e815 PA |
12817 | if (removed && non_stop |
12818 | && breakpoint_address_is_meaningful (old_loc->owner) | |
12819 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 12820 | { |
db82e815 PA |
12821 | /* This location was removed from the target. In |
12822 | non-stop mode, a race condition is possible where | |
12823 | we've removed a breakpoint, but stop events for that | |
12824 | breakpoint are already queued and will arrive later. | |
12825 | We apply an heuristic to be able to distinguish such | |
12826 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12827 | breakpoint location for a bit, and will retire it | |
12828 | after we see some number of events. The theory here | |
12829 | is that reporting of events should, "on the average", | |
12830 | be fair, so after a while we'll see events from all | |
12831 | threads that have anything of interest, and no longer | |
12832 | need to keep this breakpoint location around. We | |
12833 | don't hold locations forever so to reduce chances of | |
12834 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12835 | SIGTRAP. | |
12836 | ||
12837 | The heuristic failing can be disastrous on | |
12838 | decr_pc_after_break targets. | |
12839 | ||
12840 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12841 | if we fail to recognize a late breakpoint SIGTRAP, | |
12842 | because events_till_retirement has reached 0 too | |
12843 | soon, we'll fail to do the PC adjustment, and report | |
12844 | a random SIGTRAP to the user. When the user resumes | |
12845 | the inferior, it will most likely immediately crash | |
2dec564e | 12846 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12847 | corrupted, because of being resumed e.g., in the |
12848 | middle of a multi-byte instruction, or skipped a | |
12849 | one-byte instruction. This was actually seen happen | |
12850 | on native x86-linux, and should be less rare on | |
12851 | targets that do not support new thread events, like | |
12852 | remote, due to the heuristic depending on | |
12853 | thread_count. | |
12854 | ||
12855 | Mistaking a random SIGTRAP for a breakpoint trap | |
12856 | causes similar symptoms (PC adjustment applied when | |
12857 | it shouldn't), but then again, playing with SIGTRAPs | |
12858 | behind the debugger's back is asking for trouble. | |
12859 | ||
12860 | Since hardware watchpoint traps are always | |
12861 | distinguishable from other traps, so we don't need to | |
12862 | apply keep hardware watchpoint moribund locations | |
12863 | around. We simply always ignore hardware watchpoint | |
12864 | traps we can no longer explain. */ | |
12865 | ||
876fa593 JK |
12866 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12867 | old_loc->owner = NULL; | |
20874c92 | 12868 | |
876fa593 | 12869 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12870 | } |
12871 | else | |
f431efe5 PA |
12872 | { |
12873 | old_loc->owner = NULL; | |
12874 | decref_bp_location (&old_loc); | |
12875 | } | |
20874c92 | 12876 | } |
74960c60 | 12877 | } |
1c5cfe86 | 12878 | |
348d480f PA |
12879 | /* Rescan breakpoints at the same address and section, marking the |
12880 | first one as "first" and any others as "duplicates". This is so | |
12881 | that the bpt instruction is only inserted once. If we have a | |
12882 | permanent breakpoint at the same place as BPT, make that one the | |
12883 | official one, and the rest as duplicates. Permanent breakpoints | |
12884 | are sorted first for the same address. | |
12885 | ||
12886 | Do the same for hardware watchpoints, but also considering the | |
12887 | watchpoint's type (regular/access/read) and length. */ | |
12888 | ||
12889 | bp_loc_first = NULL; | |
12890 | wp_loc_first = NULL; | |
12891 | awp_loc_first = NULL; | |
12892 | rwp_loc_first = NULL; | |
12893 | ALL_BP_LOCATIONS (loc, locp) | |
12894 | { | |
12895 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12896 | non-NULL. */ | |
348d480f | 12897 | struct bp_location **loc_first_p; |
d3fbdd86 | 12898 | b = loc->owner; |
348d480f | 12899 | |
6f380991 | 12900 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12901 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12902 | /* Don't detect duplicate for tracepoint locations because they are |
12903 | never duplicated. See the comments in field `duplicate' of | |
12904 | `struct bp_location'. */ | |
348d480f | 12905 | || is_tracepoint (b)) |
b775012e LM |
12906 | { |
12907 | /* Clear the condition modification flag. */ | |
12908 | loc->condition_changed = condition_unchanged; | |
12909 | continue; | |
12910 | } | |
348d480f PA |
12911 | |
12912 | /* Permanent breakpoint should always be inserted. */ | |
12913 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
12914 | internal_error (__FILE__, __LINE__, | |
12915 | _("allegedly permanent breakpoint is not " | |
12916 | "actually inserted")); | |
12917 | ||
12918 | if (b->type == bp_hardware_watchpoint) | |
12919 | loc_first_p = &wp_loc_first; | |
12920 | else if (b->type == bp_read_watchpoint) | |
12921 | loc_first_p = &rwp_loc_first; | |
12922 | else if (b->type == bp_access_watchpoint) | |
12923 | loc_first_p = &awp_loc_first; | |
12924 | else | |
12925 | loc_first_p = &bp_loc_first; | |
12926 | ||
12927 | if (*loc_first_p == NULL | |
12928 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12929 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12930 | { | |
12931 | *loc_first_p = loc; | |
12932 | loc->duplicate = 0; | |
b775012e LM |
12933 | |
12934 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12935 | { | |
12936 | loc->needs_update = 1; | |
12937 | /* Clear the condition modification flag. */ | |
12938 | loc->condition_changed = condition_unchanged; | |
12939 | } | |
348d480f PA |
12940 | continue; |
12941 | } | |
12942 | ||
934709f0 PW |
12943 | |
12944 | /* This and the above ensure the invariant that the first location | |
12945 | is not duplicated, and is the inserted one. | |
12946 | All following are marked as duplicated, and are not inserted. */ | |
12947 | if (loc->inserted) | |
12948 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12949 | loc->duplicate = 1; |
12950 | ||
b775012e LM |
12951 | /* Clear the condition modification flag. */ |
12952 | loc->condition_changed = condition_unchanged; | |
12953 | ||
348d480f PA |
12954 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
12955 | && b->enable_state != bp_permanent) | |
12956 | internal_error (__FILE__, __LINE__, | |
12957 | _("another breakpoint was inserted on top of " | |
12958 | "a permanent breakpoint")); | |
12959 | } | |
12960 | ||
a25a5a45 | 12961 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12962 | { |
04086b45 | 12963 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12964 | insert_breakpoint_locations (); |
12965 | else | |
12966 | { | |
44702360 PA |
12967 | /* Even though the caller told us to not insert new |
12968 | locations, we may still need to update conditions on the | |
12969 | target's side of breakpoints that were already inserted | |
12970 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12971 | only update conditions for locations that are marked |
12972 | "needs_update". */ | |
12973 | update_inserted_breakpoint_locations (); | |
12974 | } | |
12975 | } | |
348d480f | 12976 | |
04086b45 | 12977 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12978 | download_tracepoint_locations (); |
12979 | ||
348d480f PA |
12980 | do_cleanups (cleanups); |
12981 | } | |
12982 | ||
12983 | void | |
12984 | breakpoint_retire_moribund (void) | |
12985 | { | |
12986 | struct bp_location *loc; | |
12987 | int ix; | |
12988 | ||
12989 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12990 | if (--(loc->events_till_retirement) == 0) | |
12991 | { | |
12992 | decref_bp_location (&loc); | |
12993 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12994 | --ix; | |
12995 | } | |
12996 | } | |
12997 | ||
12998 | static void | |
44702360 | 12999 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 13000 | { |
bfd189b1 | 13001 | volatile struct gdb_exception e; |
348d480f PA |
13002 | |
13003 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
44702360 | 13004 | update_global_location_list (insert_mode); |
348d480f PA |
13005 | } |
13006 | ||
13007 | /* Clear BKP from a BPS. */ | |
13008 | ||
13009 | static void | |
13010 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
13011 | { | |
13012 | bpstat bs; | |
13013 | ||
13014 | for (bs = bps; bs; bs = bs->next) | |
13015 | if (bs->breakpoint_at == bpt) | |
13016 | { | |
13017 | bs->breakpoint_at = NULL; | |
13018 | bs->old_val = NULL; | |
13019 | /* bs->commands will be freed later. */ | |
13020 | } | |
13021 | } | |
13022 | ||
13023 | /* Callback for iterate_over_threads. */ | |
13024 | static int | |
13025 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
13026 | { | |
13027 | struct breakpoint *bpt = data; | |
13028 | ||
13029 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
13030 | return 0; | |
13031 | } | |
13032 | ||
13033 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
13034 | callbacks. */ | |
13035 | ||
13036 | static void | |
13037 | say_where (struct breakpoint *b) | |
13038 | { | |
13039 | struct value_print_options opts; | |
13040 | ||
13041 | get_user_print_options (&opts); | |
13042 | ||
13043 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
13044 | single string. */ | |
13045 | if (b->loc == NULL) | |
13046 | { | |
13047 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
13048 | } | |
13049 | else | |
13050 | { | |
2f202fde | 13051 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
13052 | { |
13053 | printf_filtered (" at "); | |
13054 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
13055 | gdb_stdout); | |
13056 | } | |
2f202fde | 13057 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
13058 | { |
13059 | /* If there is a single location, we can print the location | |
13060 | more nicely. */ | |
13061 | if (b->loc->next == NULL) | |
13062 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
13063 | symtab_to_filename_for_display (b->loc->symtab), |
13064 | b->loc->line_number); | |
f8eba3c6 TT |
13065 | else |
13066 | /* This is not ideal, but each location may have a | |
13067 | different file name, and this at least reflects the | |
13068 | real situation somewhat. */ | |
13069 | printf_filtered (": %s.", b->addr_string); | |
13070 | } | |
348d480f PA |
13071 | |
13072 | if (b->loc->next) | |
13073 | { | |
13074 | struct bp_location *loc = b->loc; | |
13075 | int n = 0; | |
13076 | for (; loc; loc = loc->next) | |
13077 | ++n; | |
13078 | printf_filtered (" (%d locations)", n); | |
13079 | } | |
13080 | } | |
13081 | } | |
13082 | ||
348d480f PA |
13083 | /* Default bp_location_ops methods. */ |
13084 | ||
13085 | static void | |
13086 | bp_location_dtor (struct bp_location *self) | |
13087 | { | |
13088 | xfree (self->cond); | |
b775012e LM |
13089 | if (self->cond_bytecode) |
13090 | free_agent_expr (self->cond_bytecode); | |
348d480f | 13091 | xfree (self->function_name); |
8b4f3082 PA |
13092 | |
13093 | VEC_free (agent_expr_p, self->target_info.conditions); | |
13094 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
13095 | } |
13096 | ||
13097 | static const struct bp_location_ops bp_location_ops = | |
13098 | { | |
13099 | bp_location_dtor | |
13100 | }; | |
13101 | ||
2060206e PA |
13102 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
13103 | inherit from. */ | |
348d480f | 13104 | |
2060206e PA |
13105 | static void |
13106 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
13107 | { |
13108 | decref_counted_command_line (&self->commands); | |
13109 | xfree (self->cond_string); | |
fb81d016 | 13110 | xfree (self->extra_string); |
348d480f | 13111 | xfree (self->addr_string); |
f8eba3c6 | 13112 | xfree (self->filter); |
348d480f | 13113 | xfree (self->addr_string_range_end); |
348d480f PA |
13114 | } |
13115 | ||
2060206e PA |
13116 | static struct bp_location * |
13117 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
13118 | { |
13119 | struct bp_location *loc; | |
13120 | ||
13121 | loc = XNEW (struct bp_location); | |
13122 | init_bp_location (loc, &bp_location_ops, self); | |
13123 | return loc; | |
13124 | } | |
13125 | ||
2060206e PA |
13126 | static void |
13127 | base_breakpoint_re_set (struct breakpoint *b) | |
13128 | { | |
13129 | /* Nothing to re-set. */ | |
13130 | } | |
13131 | ||
13132 | #define internal_error_pure_virtual_called() \ | |
13133 | gdb_assert_not_reached ("pure virtual function called") | |
13134 | ||
13135 | static int | |
13136 | base_breakpoint_insert_location (struct bp_location *bl) | |
13137 | { | |
13138 | internal_error_pure_virtual_called (); | |
13139 | } | |
13140 | ||
13141 | static int | |
13142 | base_breakpoint_remove_location (struct bp_location *bl) | |
13143 | { | |
13144 | internal_error_pure_virtual_called (); | |
13145 | } | |
13146 | ||
13147 | static int | |
13148 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
13149 | struct address_space *aspace, | |
09ac7c10 TT |
13150 | CORE_ADDR bp_addr, |
13151 | const struct target_waitstatus *ws) | |
2060206e PA |
13152 | { |
13153 | internal_error_pure_virtual_called (); | |
13154 | } | |
13155 | ||
13156 | static void | |
13157 | base_breakpoint_check_status (bpstat bs) | |
13158 | { | |
13159 | /* Always stop. */ | |
13160 | } | |
13161 | ||
13162 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
13163 | errors. */ | |
13164 | ||
13165 | static int | |
13166 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
13167 | { | |
13168 | internal_error_pure_virtual_called (); | |
13169 | } | |
13170 | ||
13171 | /* A "resources_needed" breakpoint_ops method that just internal | |
13172 | errors. */ | |
13173 | ||
13174 | static int | |
13175 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
13176 | { | |
13177 | internal_error_pure_virtual_called (); | |
13178 | } | |
13179 | ||
13180 | static enum print_stop_action | |
13181 | base_breakpoint_print_it (bpstat bs) | |
13182 | { | |
13183 | internal_error_pure_virtual_called (); | |
13184 | } | |
13185 | ||
13186 | static void | |
13187 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
13188 | struct ui_out *uiout) | |
13189 | { | |
13190 | /* nothing */ | |
13191 | } | |
13192 | ||
13193 | static void | |
13194 | base_breakpoint_print_mention (struct breakpoint *b) | |
13195 | { | |
13196 | internal_error_pure_virtual_called (); | |
13197 | } | |
13198 | ||
13199 | static void | |
13200 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
13201 | { | |
13202 | internal_error_pure_virtual_called (); | |
13203 | } | |
13204 | ||
983af33b SDJ |
13205 | static void |
13206 | base_breakpoint_create_sals_from_address (char **arg, | |
13207 | struct linespec_result *canonical, | |
13208 | enum bptype type_wanted, | |
13209 | char *addr_start, | |
13210 | char **copy_arg) | |
13211 | { | |
13212 | internal_error_pure_virtual_called (); | |
13213 | } | |
13214 | ||
13215 | static void | |
13216 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13217 | struct linespec_result *c, | |
983af33b | 13218 | char *cond_string, |
e7e0cddf | 13219 | char *extra_string, |
983af33b SDJ |
13220 | enum bptype type_wanted, |
13221 | enum bpdisp disposition, | |
13222 | int thread, | |
13223 | int task, int ignore_count, | |
13224 | const struct breakpoint_ops *o, | |
13225 | int from_tty, int enabled, | |
44f238bb | 13226 | int internal, unsigned flags) |
983af33b SDJ |
13227 | { |
13228 | internal_error_pure_virtual_called (); | |
13229 | } | |
13230 | ||
13231 | static void | |
13232 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
13233 | struct symtabs_and_lines *sals) | |
13234 | { | |
13235 | internal_error_pure_virtual_called (); | |
13236 | } | |
13237 | ||
ab04a2af TT |
13238 | /* The default 'explains_signal' method. */ |
13239 | ||
47591c29 | 13240 | static int |
427cd150 | 13241 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 13242 | { |
47591c29 | 13243 | return 1; |
ab04a2af TT |
13244 | } |
13245 | ||
9d6e6e84 HZ |
13246 | /* The default "after_condition_true" method. */ |
13247 | ||
13248 | static void | |
13249 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
13250 | { | |
13251 | /* Nothing to do. */ | |
13252 | } | |
13253 | ||
ab04a2af | 13254 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
13255 | { |
13256 | base_breakpoint_dtor, | |
13257 | base_breakpoint_allocate_location, | |
13258 | base_breakpoint_re_set, | |
13259 | base_breakpoint_insert_location, | |
13260 | base_breakpoint_remove_location, | |
13261 | base_breakpoint_breakpoint_hit, | |
13262 | base_breakpoint_check_status, | |
13263 | base_breakpoint_resources_needed, | |
13264 | base_breakpoint_works_in_software_mode, | |
13265 | base_breakpoint_print_it, | |
13266 | NULL, | |
13267 | base_breakpoint_print_one_detail, | |
13268 | base_breakpoint_print_mention, | |
983af33b SDJ |
13269 | base_breakpoint_print_recreate, |
13270 | base_breakpoint_create_sals_from_address, | |
13271 | base_breakpoint_create_breakpoints_sal, | |
13272 | base_breakpoint_decode_linespec, | |
9d6e6e84 HZ |
13273 | base_breakpoint_explains_signal, |
13274 | base_breakpoint_after_condition_true, | |
2060206e PA |
13275 | }; |
13276 | ||
13277 | /* Default breakpoint_ops methods. */ | |
13278 | ||
13279 | static void | |
348d480f PA |
13280 | bkpt_re_set (struct breakpoint *b) |
13281 | { | |
06edf0c0 PA |
13282 | /* FIXME: is this still reachable? */ |
13283 | if (b->addr_string == NULL) | |
13284 | { | |
13285 | /* Anything without a string can't be re-set. */ | |
348d480f | 13286 | delete_breakpoint (b); |
06edf0c0 | 13287 | return; |
348d480f | 13288 | } |
06edf0c0 PA |
13289 | |
13290 | breakpoint_re_set_default (b); | |
348d480f PA |
13291 | } |
13292 | ||
ef370185 JB |
13293 | /* Copy SRC's shadow buffer and whatever else we'd set if we actually |
13294 | inserted DEST, so we can remove it later, in case SRC is removed | |
13295 | first. */ | |
13296 | ||
13297 | static void | |
13298 | bp_target_info_copy_insertion_state (struct bp_target_info *dest, | |
13299 | const struct bp_target_info *src) | |
13300 | { | |
13301 | dest->shadow_len = src->shadow_len; | |
13302 | memcpy (dest->shadow_contents, src->shadow_contents, src->shadow_len); | |
0d5ed153 | 13303 | dest->placed_address = src->placed_address; |
ef370185 JB |
13304 | dest->placed_size = src->placed_size; |
13305 | } | |
13306 | ||
2060206e | 13307 | static int |
348d480f PA |
13308 | bkpt_insert_location (struct bp_location *bl) |
13309 | { | |
13310 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13311 | return target_insert_hw_breakpoint (bl->gdbarch, | |
13312 | &bl->target_info); | |
13313 | else | |
ef370185 JB |
13314 | { |
13315 | struct bp_target_info *bp_tgt = &bl->target_info; | |
13316 | int ret; | |
13317 | int sss_slot; | |
13318 | ||
13319 | /* There is no need to insert a breakpoint if an unconditional | |
13320 | raw/sss breakpoint is already inserted at that location. */ | |
13321 | sss_slot = find_single_step_breakpoint (bp_tgt->placed_address_space, | |
0d5ed153 | 13322 | bp_tgt->reqstd_address); |
ef370185 JB |
13323 | if (sss_slot >= 0) |
13324 | { | |
13325 | struct bp_target_info *sss_bp_tgt = single_step_breakpoints[sss_slot]; | |
13326 | ||
13327 | bp_target_info_copy_insertion_state (bp_tgt, sss_bp_tgt); | |
13328 | return 0; | |
13329 | } | |
13330 | ||
13331 | return target_insert_breakpoint (bl->gdbarch, bp_tgt); | |
13332 | } | |
348d480f PA |
13333 | } |
13334 | ||
2060206e | 13335 | static int |
348d480f PA |
13336 | bkpt_remove_location (struct bp_location *bl) |
13337 | { | |
13338 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13339 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13340 | else | |
ef370185 JB |
13341 | { |
13342 | struct bp_target_info *bp_tgt = &bl->target_info; | |
13343 | struct address_space *aspace = bp_tgt->placed_address_space; | |
0d5ed153 | 13344 | CORE_ADDR address = bp_tgt->reqstd_address; |
ef370185 JB |
13345 | |
13346 | /* Only remove the breakpoint if there is no raw/sss breakpoint | |
13347 | still inserted at this location. Otherwise, we would be | |
13348 | effectively disabling the raw/sss breakpoint. */ | |
13349 | if (single_step_breakpoint_inserted_here_p (aspace, address)) | |
13350 | return 0; | |
13351 | ||
13352 | return target_remove_breakpoint (bl->gdbarch, bp_tgt); | |
13353 | } | |
348d480f PA |
13354 | } |
13355 | ||
2060206e | 13356 | static int |
348d480f | 13357 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13358 | struct address_space *aspace, CORE_ADDR bp_addr, |
13359 | const struct target_waitstatus *ws) | |
348d480f | 13360 | { |
09ac7c10 | 13361 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13362 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13363 | return 0; |
13364 | ||
348d480f PA |
13365 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13366 | aspace, bp_addr)) | |
13367 | return 0; | |
13368 | ||
13369 | if (overlay_debugging /* unmapped overlay section */ | |
13370 | && section_is_overlay (bl->section) | |
13371 | && !section_is_mapped (bl->section)) | |
13372 | return 0; | |
13373 | ||
13374 | return 1; | |
13375 | } | |
13376 | ||
cd1608cc PA |
13377 | static int |
13378 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
13379 | struct address_space *aspace, CORE_ADDR bp_addr, | |
13380 | const struct target_waitstatus *ws) | |
13381 | { | |
13382 | if (dprintf_style == dprintf_style_agent | |
13383 | && target_can_run_breakpoint_commands ()) | |
13384 | { | |
13385 | /* An agent-style dprintf never causes a stop. If we see a trap | |
13386 | for this address it must be for a breakpoint that happens to | |
13387 | be set at the same address. */ | |
13388 | return 0; | |
13389 | } | |
13390 | ||
13391 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
13392 | } | |
13393 | ||
2060206e | 13394 | static int |
348d480f PA |
13395 | bkpt_resources_needed (const struct bp_location *bl) |
13396 | { | |
13397 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13398 | ||
13399 | return 1; | |
13400 | } | |
13401 | ||
2060206e | 13402 | static enum print_stop_action |
348d480f PA |
13403 | bkpt_print_it (bpstat bs) |
13404 | { | |
348d480f PA |
13405 | struct breakpoint *b; |
13406 | const struct bp_location *bl; | |
001c8c33 | 13407 | int bp_temp; |
79a45e25 | 13408 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13409 | |
13410 | gdb_assert (bs->bp_location_at != NULL); | |
13411 | ||
13412 | bl = bs->bp_location_at; | |
13413 | b = bs->breakpoint_at; | |
13414 | ||
001c8c33 PA |
13415 | bp_temp = b->disposition == disp_del; |
13416 | if (bl->address != bl->requested_address) | |
13417 | breakpoint_adjustment_warning (bl->requested_address, | |
13418 | bl->address, | |
13419 | b->number, 1); | |
13420 | annotate_breakpoint (b->number); | |
13421 | if (bp_temp) | |
13422 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
13423 | else | |
13424 | ui_out_text (uiout, "\nBreakpoint "); | |
13425 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 13426 | { |
001c8c33 PA |
13427 | ui_out_field_string (uiout, "reason", |
13428 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13429 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13430 | } |
001c8c33 PA |
13431 | ui_out_field_int (uiout, "bkptno", b->number); |
13432 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13433 | |
001c8c33 | 13434 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13435 | } |
13436 | ||
2060206e | 13437 | static void |
06edf0c0 PA |
13438 | bkpt_print_mention (struct breakpoint *b) |
13439 | { | |
79a45e25 | 13440 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13441 | return; |
13442 | ||
13443 | switch (b->type) | |
13444 | { | |
13445 | case bp_breakpoint: | |
13446 | case bp_gnu_ifunc_resolver: | |
13447 | if (b->disposition == disp_del) | |
13448 | printf_filtered (_("Temporary breakpoint")); | |
13449 | else | |
13450 | printf_filtered (_("Breakpoint")); | |
13451 | printf_filtered (_(" %d"), b->number); | |
13452 | if (b->type == bp_gnu_ifunc_resolver) | |
13453 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13454 | break; | |
13455 | case bp_hardware_breakpoint: | |
13456 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13457 | break; | |
e7e0cddf SS |
13458 | case bp_dprintf: |
13459 | printf_filtered (_("Dprintf %d"), b->number); | |
13460 | break; | |
06edf0c0 PA |
13461 | } |
13462 | ||
13463 | say_where (b); | |
13464 | } | |
13465 | ||
2060206e | 13466 | static void |
06edf0c0 PA |
13467 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13468 | { | |
13469 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13470 | fprintf_unfiltered (fp, "tbreak"); | |
13471 | else if (tp->type == bp_breakpoint) | |
13472 | fprintf_unfiltered (fp, "break"); | |
13473 | else if (tp->type == bp_hardware_breakpoint | |
13474 | && tp->disposition == disp_del) | |
13475 | fprintf_unfiltered (fp, "thbreak"); | |
13476 | else if (tp->type == bp_hardware_breakpoint) | |
13477 | fprintf_unfiltered (fp, "hbreak"); | |
13478 | else | |
13479 | internal_error (__FILE__, __LINE__, | |
13480 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13481 | ||
2060206e | 13482 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 13483 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13484 | } |
13485 | ||
983af33b SDJ |
13486 | static void |
13487 | bkpt_create_sals_from_address (char **arg, | |
13488 | struct linespec_result *canonical, | |
13489 | enum bptype type_wanted, | |
13490 | char *addr_start, char **copy_arg) | |
13491 | { | |
13492 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13493 | addr_start, copy_arg); | |
13494 | } | |
13495 | ||
13496 | static void | |
13497 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13498 | struct linespec_result *canonical, | |
983af33b | 13499 | char *cond_string, |
e7e0cddf | 13500 | char *extra_string, |
983af33b SDJ |
13501 | enum bptype type_wanted, |
13502 | enum bpdisp disposition, | |
13503 | int thread, | |
13504 | int task, int ignore_count, | |
13505 | const struct breakpoint_ops *ops, | |
13506 | int from_tty, int enabled, | |
44f238bb | 13507 | int internal, unsigned flags) |
983af33b | 13508 | { |
023fa29b | 13509 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13510 | cond_string, extra_string, |
13511 | type_wanted, | |
983af33b SDJ |
13512 | disposition, thread, task, |
13513 | ignore_count, ops, from_tty, | |
44f238bb | 13514 | enabled, internal, flags); |
983af33b SDJ |
13515 | } |
13516 | ||
13517 | static void | |
13518 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
13519 | struct symtabs_and_lines *sals) | |
13520 | { | |
13521 | decode_linespec_default (b, s, sals); | |
13522 | } | |
13523 | ||
06edf0c0 PA |
13524 | /* Virtual table for internal breakpoints. */ |
13525 | ||
13526 | static void | |
13527 | internal_bkpt_re_set (struct breakpoint *b) | |
13528 | { | |
13529 | switch (b->type) | |
13530 | { | |
13531 | /* Delete overlay event and longjmp master breakpoints; they | |
13532 | will be reset later by breakpoint_re_set. */ | |
13533 | case bp_overlay_event: | |
13534 | case bp_longjmp_master: | |
13535 | case bp_std_terminate_master: | |
13536 | case bp_exception_master: | |
13537 | delete_breakpoint (b); | |
13538 | break; | |
13539 | ||
13540 | /* This breakpoint is special, it's set up when the inferior | |
13541 | starts and we really don't want to touch it. */ | |
13542 | case bp_shlib_event: | |
13543 | ||
13544 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13545 | it is set up, we do not want to touch it. */ | |
13546 | case bp_thread_event: | |
13547 | break; | |
13548 | } | |
13549 | } | |
13550 | ||
13551 | static void | |
13552 | internal_bkpt_check_status (bpstat bs) | |
13553 | { | |
a9b3a50f PA |
13554 | if (bs->breakpoint_at->type == bp_shlib_event) |
13555 | { | |
13556 | /* If requested, stop when the dynamic linker notifies GDB of | |
13557 | events. This allows the user to get control and place | |
13558 | breakpoints in initializer routines for dynamically loaded | |
13559 | objects (among other things). */ | |
13560 | bs->stop = stop_on_solib_events; | |
13561 | bs->print = stop_on_solib_events; | |
13562 | } | |
13563 | else | |
13564 | bs->stop = 0; | |
06edf0c0 PA |
13565 | } |
13566 | ||
13567 | static enum print_stop_action | |
13568 | internal_bkpt_print_it (bpstat bs) | |
13569 | { | |
06edf0c0 | 13570 | struct breakpoint *b; |
06edf0c0 | 13571 | |
06edf0c0 PA |
13572 | b = bs->breakpoint_at; |
13573 | ||
06edf0c0 PA |
13574 | switch (b->type) |
13575 | { | |
348d480f PA |
13576 | case bp_shlib_event: |
13577 | /* Did we stop because the user set the stop_on_solib_events | |
13578 | variable? (If so, we report this as a generic, "Stopped due | |
13579 | to shlib event" message.) */ | |
edcc5120 | 13580 | print_solib_event (0); |
348d480f PA |
13581 | break; |
13582 | ||
13583 | case bp_thread_event: | |
13584 | /* Not sure how we will get here. | |
13585 | GDB should not stop for these breakpoints. */ | |
13586 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13587 | break; |
13588 | ||
13589 | case bp_overlay_event: | |
13590 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13591 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13592 | break; |
13593 | ||
13594 | case bp_longjmp_master: | |
13595 | /* These should never be enabled. */ | |
13596 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13597 | break; |
13598 | ||
13599 | case bp_std_terminate_master: | |
13600 | /* These should never be enabled. */ | |
13601 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13602 | "gdb should not stop!\n")); | |
348d480f PA |
13603 | break; |
13604 | ||
13605 | case bp_exception_master: | |
13606 | /* These should never be enabled. */ | |
13607 | printf_filtered (_("Exception Master Breakpoint: " | |
13608 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13609 | break; |
13610 | } | |
13611 | ||
001c8c33 | 13612 | return PRINT_NOTHING; |
06edf0c0 PA |
13613 | } |
13614 | ||
13615 | static void | |
13616 | internal_bkpt_print_mention (struct breakpoint *b) | |
13617 | { | |
13618 | /* Nothing to mention. These breakpoints are internal. */ | |
13619 | } | |
13620 | ||
06edf0c0 PA |
13621 | /* Virtual table for momentary breakpoints */ |
13622 | ||
13623 | static void | |
13624 | momentary_bkpt_re_set (struct breakpoint *b) | |
13625 | { | |
13626 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13627 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13628 | Otherwise these should have been blown away via the cleanup chain |
13629 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13630 | } | |
13631 | ||
13632 | static void | |
13633 | momentary_bkpt_check_status (bpstat bs) | |
13634 | { | |
13635 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13636 | } | |
13637 | ||
13638 | static enum print_stop_action | |
13639 | momentary_bkpt_print_it (bpstat bs) | |
13640 | { | |
79a45e25 PA |
13641 | struct ui_out *uiout = current_uiout; |
13642 | ||
001c8c33 | 13643 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 13644 | { |
001c8c33 | 13645 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 13646 | |
001c8c33 PA |
13647 | switch (b->type) |
13648 | { | |
13649 | case bp_finish: | |
13650 | ui_out_field_string | |
13651 | (uiout, "reason", | |
13652 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
13653 | break; | |
348d480f | 13654 | |
001c8c33 PA |
13655 | case bp_until: |
13656 | ui_out_field_string | |
13657 | (uiout, "reason", | |
13658 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
13659 | break; | |
13660 | } | |
348d480f PA |
13661 | } |
13662 | ||
001c8c33 | 13663 | return PRINT_UNKNOWN; |
348d480f PA |
13664 | } |
13665 | ||
06edf0c0 PA |
13666 | static void |
13667 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13668 | { |
06edf0c0 | 13669 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13670 | } |
13671 | ||
e2e4d78b JK |
13672 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13673 | ||
13674 | It gets cleared already on the removal of the first one of such placed | |
13675 | breakpoints. This is OK as they get all removed altogether. */ | |
13676 | ||
13677 | static void | |
13678 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13679 | { | |
13680 | struct thread_info *tp = find_thread_id (self->thread); | |
13681 | ||
13682 | if (tp) | |
13683 | tp->initiating_frame = null_frame_id; | |
13684 | ||
13685 | momentary_breakpoint_ops.dtor (self); | |
13686 | } | |
13687 | ||
55aa24fb SDJ |
13688 | /* Specific methods for probe breakpoints. */ |
13689 | ||
13690 | static int | |
13691 | bkpt_probe_insert_location (struct bp_location *bl) | |
13692 | { | |
13693 | int v = bkpt_insert_location (bl); | |
13694 | ||
13695 | if (v == 0) | |
13696 | { | |
13697 | /* The insertion was successful, now let's set the probe's semaphore | |
13698 | if needed. */ | |
0ea5cda8 SDJ |
13699 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13700 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13701 | bl->probe.objfile, | |
13702 | bl->gdbarch); | |
55aa24fb SDJ |
13703 | } |
13704 | ||
13705 | return v; | |
13706 | } | |
13707 | ||
13708 | static int | |
13709 | bkpt_probe_remove_location (struct bp_location *bl) | |
13710 | { | |
13711 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13712 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13713 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13714 | bl->probe.objfile, | |
13715 | bl->gdbarch); | |
55aa24fb SDJ |
13716 | |
13717 | return bkpt_remove_location (bl); | |
13718 | } | |
13719 | ||
13720 | static void | |
13721 | bkpt_probe_create_sals_from_address (char **arg, | |
13722 | struct linespec_result *canonical, | |
13723 | enum bptype type_wanted, | |
13724 | char *addr_start, char **copy_arg) | |
13725 | { | |
13726 | struct linespec_sals lsal; | |
13727 | ||
13728 | lsal.sals = parse_probes (arg, canonical); | |
13729 | ||
13730 | *copy_arg = xstrdup (canonical->addr_string); | |
13731 | lsal.canonical = xstrdup (*copy_arg); | |
13732 | ||
13733 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13734 | } | |
13735 | ||
13736 | static void | |
13737 | bkpt_probe_decode_linespec (struct breakpoint *b, char **s, | |
13738 | struct symtabs_and_lines *sals) | |
13739 | { | |
13740 | *sals = parse_probes (s, NULL); | |
13741 | if (!sals->sals) | |
13742 | error (_("probe not found")); | |
13743 | } | |
13744 | ||
348d480f | 13745 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13746 | |
348d480f PA |
13747 | static void |
13748 | tracepoint_re_set (struct breakpoint *b) | |
13749 | { | |
13750 | breakpoint_re_set_default (b); | |
13751 | } | |
876fa593 | 13752 | |
348d480f PA |
13753 | static int |
13754 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13755 | struct address_space *aspace, CORE_ADDR bp_addr, |
13756 | const struct target_waitstatus *ws) | |
348d480f PA |
13757 | { |
13758 | /* By definition, the inferior does not report stops at | |
13759 | tracepoints. */ | |
13760 | return 0; | |
74960c60 VP |
13761 | } |
13762 | ||
13763 | static void | |
348d480f PA |
13764 | tracepoint_print_one_detail (const struct breakpoint *self, |
13765 | struct ui_out *uiout) | |
74960c60 | 13766 | { |
d9b3f62e PA |
13767 | struct tracepoint *tp = (struct tracepoint *) self; |
13768 | if (tp->static_trace_marker_id) | |
348d480f PA |
13769 | { |
13770 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13771 | |
348d480f PA |
13772 | ui_out_text (uiout, "\tmarker id is "); |
13773 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13774 | tp->static_trace_marker_id); |
348d480f PA |
13775 | ui_out_text (uiout, "\n"); |
13776 | } | |
0d381245 VP |
13777 | } |
13778 | ||
a474d7c2 | 13779 | static void |
348d480f | 13780 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13781 | { |
79a45e25 | 13782 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13783 | return; |
cc59ec59 | 13784 | |
348d480f PA |
13785 | switch (b->type) |
13786 | { | |
13787 | case bp_tracepoint: | |
13788 | printf_filtered (_("Tracepoint")); | |
13789 | printf_filtered (_(" %d"), b->number); | |
13790 | break; | |
13791 | case bp_fast_tracepoint: | |
13792 | printf_filtered (_("Fast tracepoint")); | |
13793 | printf_filtered (_(" %d"), b->number); | |
13794 | break; | |
13795 | case bp_static_tracepoint: | |
13796 | printf_filtered (_("Static tracepoint")); | |
13797 | printf_filtered (_(" %d"), b->number); | |
13798 | break; | |
13799 | default: | |
13800 | internal_error (__FILE__, __LINE__, | |
13801 | _("unhandled tracepoint type %d"), (int) b->type); | |
13802 | } | |
13803 | ||
13804 | say_where (b); | |
a474d7c2 PA |
13805 | } |
13806 | ||
348d480f | 13807 | static void |
d9b3f62e | 13808 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13809 | { |
d9b3f62e PA |
13810 | struct tracepoint *tp = (struct tracepoint *) self; |
13811 | ||
13812 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13813 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13814 | if (self->type == bp_static_tracepoint) |
348d480f | 13815 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13816 | else if (self->type == bp_tracepoint) |
348d480f PA |
13817 | fprintf_unfiltered (fp, "trace"); |
13818 | else | |
13819 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13820 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13821 | |
d9b3f62e PA |
13822 | fprintf_unfiltered (fp, " %s", self->addr_string); |
13823 | print_recreate_thread (self, fp); | |
13824 | ||
13825 | if (tp->pass_count) | |
13826 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13827 | } |
13828 | ||
983af33b SDJ |
13829 | static void |
13830 | tracepoint_create_sals_from_address (char **arg, | |
13831 | struct linespec_result *canonical, | |
13832 | enum bptype type_wanted, | |
13833 | char *addr_start, char **copy_arg) | |
13834 | { | |
13835 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13836 | addr_start, copy_arg); | |
13837 | } | |
13838 | ||
13839 | static void | |
13840 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13841 | struct linespec_result *canonical, | |
983af33b | 13842 | char *cond_string, |
e7e0cddf | 13843 | char *extra_string, |
983af33b SDJ |
13844 | enum bptype type_wanted, |
13845 | enum bpdisp disposition, | |
13846 | int thread, | |
13847 | int task, int ignore_count, | |
13848 | const struct breakpoint_ops *ops, | |
13849 | int from_tty, int enabled, | |
44f238bb | 13850 | int internal, unsigned flags) |
983af33b | 13851 | { |
023fa29b | 13852 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13853 | cond_string, extra_string, |
13854 | type_wanted, | |
983af33b SDJ |
13855 | disposition, thread, task, |
13856 | ignore_count, ops, from_tty, | |
44f238bb | 13857 | enabled, internal, flags); |
983af33b SDJ |
13858 | } |
13859 | ||
13860 | static void | |
13861 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
13862 | struct symtabs_and_lines *sals) | |
13863 | { | |
13864 | decode_linespec_default (b, s, sals); | |
13865 | } | |
13866 | ||
2060206e | 13867 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13868 | |
55aa24fb SDJ |
13869 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13870 | static probe. */ | |
13871 | ||
13872 | static void | |
13873 | tracepoint_probe_create_sals_from_address (char **arg, | |
13874 | struct linespec_result *canonical, | |
13875 | enum bptype type_wanted, | |
13876 | char *addr_start, char **copy_arg) | |
13877 | { | |
13878 | /* We use the same method for breakpoint on probes. */ | |
13879 | bkpt_probe_create_sals_from_address (arg, canonical, type_wanted, | |
13880 | addr_start, copy_arg); | |
13881 | } | |
13882 | ||
13883 | static void | |
13884 | tracepoint_probe_decode_linespec (struct breakpoint *b, char **s, | |
13885 | struct symtabs_and_lines *sals) | |
13886 | { | |
13887 | /* We use the same method for breakpoint on probes. */ | |
13888 | bkpt_probe_decode_linespec (b, s, sals); | |
13889 | } | |
13890 | ||
13891 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13892 | ||
5c2b4418 HZ |
13893 | /* Dprintf breakpoint_ops methods. */ |
13894 | ||
13895 | static void | |
13896 | dprintf_re_set (struct breakpoint *b) | |
13897 | { | |
13898 | breakpoint_re_set_default (b); | |
13899 | ||
13900 | /* This breakpoint could have been pending, and be resolved now, and | |
13901 | if so, we should now have the extra string. If we don't, the | |
13902 | dprintf was malformed when created, but we couldn't tell because | |
13903 | we can't extract the extra string until the location is | |
13904 | resolved. */ | |
13905 | if (b->loc != NULL && b->extra_string == NULL) | |
13906 | error (_("Format string required")); | |
13907 | ||
13908 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13909 | 2 - create a dprintf, which resolves fine. | |
13910 | 3 - disconnect from target 1 | |
13911 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13912 | ||
13913 | After steps #3/#4, you'll want the dprintf command list to | |
13914 | be updated, because target 1 and 2 may well return different | |
13915 | answers for target_can_run_breakpoint_commands(). | |
13916 | Given absence of finer grained resetting, we get to do | |
13917 | it all the time. */ | |
13918 | if (b->extra_string != NULL) | |
13919 | update_dprintf_command_list (b); | |
13920 | } | |
13921 | ||
2d9442cc HZ |
13922 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13923 | ||
13924 | static void | |
13925 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13926 | { | |
13927 | fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string, | |
13928 | tp->extra_string); | |
13929 | print_recreate_thread (tp, fp); | |
13930 | } | |
13931 | ||
9d6e6e84 HZ |
13932 | /* Implement the "after_condition_true" breakpoint_ops method for |
13933 | dprintf. | |
13934 | ||
13935 | dprintf's are implemented with regular commands in their command | |
13936 | list, but we run the commands here instead of before presenting the | |
13937 | stop to the user, as dprintf's don't actually cause a stop. This | |
13938 | also makes it so that the commands of multiple dprintfs at the same | |
13939 | address are all handled. */ | |
13940 | ||
13941 | static void | |
13942 | dprintf_after_condition_true (struct bpstats *bs) | |
13943 | { | |
13944 | struct cleanup *old_chain; | |
13945 | struct bpstats tmp_bs = { NULL }; | |
13946 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13947 | ||
13948 | /* dprintf's never cause a stop. This wasn't set in the | |
13949 | check_status hook instead because that would make the dprintf's | |
13950 | condition not be evaluated. */ | |
13951 | bs->stop = 0; | |
13952 | ||
13953 | /* Run the command list here. Take ownership of it instead of | |
13954 | copying. We never want these commands to run later in | |
13955 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13956 | be set at same address as this dprintf, or even if running the | |
13957 | commands here throws. */ | |
13958 | tmp_bs.commands = bs->commands; | |
13959 | bs->commands = NULL; | |
13960 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13961 | ||
13962 | bpstat_do_actions_1 (&tmp_bs_p); | |
13963 | ||
13964 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13965 | bpstat_do_actions_1 may return early without processing the whole | |
13966 | list. */ | |
13967 | do_cleanups (old_chain); | |
13968 | } | |
13969 | ||
983af33b SDJ |
13970 | /* The breakpoint_ops structure to be used on static tracepoints with |
13971 | markers (`-m'). */ | |
13972 | ||
13973 | static void | |
13974 | strace_marker_create_sals_from_address (char **arg, | |
13975 | struct linespec_result *canonical, | |
13976 | enum bptype type_wanted, | |
13977 | char *addr_start, char **copy_arg) | |
13978 | { | |
13979 | struct linespec_sals lsal; | |
13980 | ||
13981 | lsal.sals = decode_static_tracepoint_spec (arg); | |
13982 | ||
13983 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
13984 | ||
13985 | canonical->addr_string = xstrdup (*copy_arg); | |
13986 | lsal.canonical = xstrdup (*copy_arg); | |
13987 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13988 | } | |
13989 | ||
13990 | static void | |
13991 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13992 | struct linespec_result *canonical, | |
983af33b | 13993 | char *cond_string, |
e7e0cddf | 13994 | char *extra_string, |
983af33b SDJ |
13995 | enum bptype type_wanted, |
13996 | enum bpdisp disposition, | |
13997 | int thread, | |
13998 | int task, int ignore_count, | |
13999 | const struct breakpoint_ops *ops, | |
14000 | int from_tty, int enabled, | |
44f238bb | 14001 | int internal, unsigned flags) |
983af33b SDJ |
14002 | { |
14003 | int i; | |
52d361e1 YQ |
14004 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
14005 | canonical->sals, 0); | |
983af33b SDJ |
14006 | |
14007 | /* If the user is creating a static tracepoint by marker id | |
14008 | (strace -m MARKER_ID), then store the sals index, so that | |
14009 | breakpoint_re_set can try to match up which of the newly | |
14010 | found markers corresponds to this one, and, don't try to | |
14011 | expand multiple locations for each sal, given than SALS | |
14012 | already should contain all sals for MARKER_ID. */ | |
14013 | ||
14014 | for (i = 0; i < lsal->sals.nelts; ++i) | |
14015 | { | |
14016 | struct symtabs_and_lines expanded; | |
14017 | struct tracepoint *tp; | |
14018 | struct cleanup *old_chain; | |
14019 | char *addr_string; | |
14020 | ||
14021 | expanded.nelts = 1; | |
14022 | expanded.sals = &lsal->sals.sals[i]; | |
14023 | ||
14024 | addr_string = xstrdup (canonical->addr_string); | |
14025 | old_chain = make_cleanup (xfree, addr_string); | |
14026 | ||
14027 | tp = XCNEW (struct tracepoint); | |
14028 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
14029 | addr_string, NULL, | |
e7e0cddf SS |
14030 | cond_string, extra_string, |
14031 | type_wanted, disposition, | |
983af33b | 14032 | thread, task, ignore_count, ops, |
44f238bb | 14033 | from_tty, enabled, internal, flags, |
983af33b SDJ |
14034 | canonical->special_display); |
14035 | /* Given that its possible to have multiple markers with | |
14036 | the same string id, if the user is creating a static | |
14037 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
14038 | store the sals index, so that breakpoint_re_set can | |
14039 | try to match up which of the newly found markers | |
14040 | corresponds to this one */ | |
14041 | tp->static_trace_marker_id_idx = i; | |
14042 | ||
14043 | install_breakpoint (internal, &tp->base, 0); | |
14044 | ||
14045 | discard_cleanups (old_chain); | |
14046 | } | |
14047 | } | |
14048 | ||
14049 | static void | |
14050 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
14051 | struct symtabs_and_lines *sals) | |
14052 | { | |
14053 | struct tracepoint *tp = (struct tracepoint *) b; | |
14054 | ||
14055 | *sals = decode_static_tracepoint_spec (s); | |
14056 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
14057 | { | |
14058 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
14059 | sals->nelts = 1; | |
14060 | } | |
14061 | else | |
14062 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
14063 | } | |
14064 | ||
14065 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
14066 | ||
14067 | static int | |
14068 | strace_marker_p (struct breakpoint *b) | |
14069 | { | |
14070 | return b->ops == &strace_marker_breakpoint_ops; | |
14071 | } | |
14072 | ||
53a5351d | 14073 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 14074 | structures. */ |
c906108c SS |
14075 | |
14076 | void | |
fba45db2 | 14077 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 14078 | { |
52f0bd74 | 14079 | struct breakpoint *b; |
c906108c | 14080 | |
8a3fe4f8 | 14081 | gdb_assert (bpt != NULL); |
c906108c | 14082 | |
4a64f543 MS |
14083 | /* Has this bp already been deleted? This can happen because |
14084 | multiple lists can hold pointers to bp's. bpstat lists are | |
14085 | especial culprits. | |
14086 | ||
14087 | One example of this happening is a watchpoint's scope bp. When | |
14088 | the scope bp triggers, we notice that the watchpoint is out of | |
14089 | scope, and delete it. We also delete its scope bp. But the | |
14090 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
14091 | That bpstat is then checked for auto-deleting bp's, which are | |
14092 | deleted. | |
14093 | ||
14094 | A real solution to this problem might involve reference counts in | |
14095 | bp's, and/or giving them pointers back to their referencing | |
14096 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
14097 | storage when no more references were extent. A cheaper bandaid | |
14098 | was chosen. */ | |
c906108c SS |
14099 | if (bpt->type == bp_none) |
14100 | return; | |
14101 | ||
4a64f543 MS |
14102 | /* At least avoid this stale reference until the reference counting |
14103 | of breakpoints gets resolved. */ | |
d0fb5eae | 14104 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 14105 | { |
d0fb5eae | 14106 | struct breakpoint *related; |
3a5c3e22 | 14107 | struct watchpoint *w; |
d0fb5eae JK |
14108 | |
14109 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 14110 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 14111 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
14112 | w = (struct watchpoint *) bpt; |
14113 | else | |
14114 | w = NULL; | |
14115 | if (w != NULL) | |
14116 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
14117 | |
14118 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
14119 | for (related = bpt; related->related_breakpoint != bpt; | |
14120 | related = related->related_breakpoint); | |
14121 | related->related_breakpoint = bpt->related_breakpoint; | |
14122 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
14123 | } |
14124 | ||
a9634178 TJB |
14125 | /* watch_command_1 creates a watchpoint but only sets its number if |
14126 | update_watchpoint succeeds in creating its bp_locations. If there's | |
14127 | a problem in that process, we'll be asked to delete the half-created | |
14128 | watchpoint. In that case, don't announce the deletion. */ | |
14129 | if (bpt->number) | |
14130 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 14131 | |
c906108c SS |
14132 | if (breakpoint_chain == bpt) |
14133 | breakpoint_chain = bpt->next; | |
14134 | ||
c906108c SS |
14135 | ALL_BREAKPOINTS (b) |
14136 | if (b->next == bpt) | |
c5aa993b JM |
14137 | { |
14138 | b->next = bpt->next; | |
14139 | break; | |
14140 | } | |
c906108c | 14141 | |
f431efe5 PA |
14142 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
14143 | been freed. */ | |
14144 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 14145 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
14146 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
14147 | commands are associated with the bpstat; if we remove it here, | |
14148 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
14149 | event-top.c won't do anything, and temporary breakpoints with | |
14150 | commands won't work. */ | |
14151 | ||
14152 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
14153 | ||
4a64f543 MS |
14154 | /* Now that breakpoint is removed from breakpoint list, update the |
14155 | global location list. This will remove locations that used to | |
14156 | belong to this breakpoint. Do this before freeing the breakpoint | |
14157 | itself, since remove_breakpoint looks at location's owner. It | |
14158 | might be better design to have location completely | |
14159 | self-contained, but it's not the case now. */ | |
44702360 | 14160 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 14161 | |
348d480f | 14162 | bpt->ops->dtor (bpt); |
4a64f543 MS |
14163 | /* On the chance that someone will soon try again to delete this |
14164 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 14165 | bpt->type = bp_none; |
b8c9b27d | 14166 | xfree (bpt); |
c906108c SS |
14167 | } |
14168 | ||
4d6140d9 AC |
14169 | static void |
14170 | do_delete_breakpoint_cleanup (void *b) | |
14171 | { | |
14172 | delete_breakpoint (b); | |
14173 | } | |
14174 | ||
14175 | struct cleanup * | |
14176 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
14177 | { | |
14178 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
14179 | } | |
14180 | ||
51be5b68 PA |
14181 | /* Iterator function to call a user-provided callback function once |
14182 | for each of B and its related breakpoints. */ | |
14183 | ||
14184 | static void | |
14185 | iterate_over_related_breakpoints (struct breakpoint *b, | |
14186 | void (*function) (struct breakpoint *, | |
14187 | void *), | |
14188 | void *data) | |
14189 | { | |
14190 | struct breakpoint *related; | |
14191 | ||
14192 | related = b; | |
14193 | do | |
14194 | { | |
14195 | struct breakpoint *next; | |
14196 | ||
14197 | /* FUNCTION may delete RELATED. */ | |
14198 | next = related->related_breakpoint; | |
14199 | ||
14200 | if (next == related) | |
14201 | { | |
14202 | /* RELATED is the last ring entry. */ | |
14203 | function (related, data); | |
14204 | ||
14205 | /* FUNCTION may have deleted it, so we'd never reach back to | |
14206 | B. There's nothing left to do anyway, so just break | |
14207 | out. */ | |
14208 | break; | |
14209 | } | |
14210 | else | |
14211 | function (related, data); | |
14212 | ||
14213 | related = next; | |
14214 | } | |
14215 | while (related != b); | |
14216 | } | |
95a42b64 TT |
14217 | |
14218 | static void | |
14219 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
14220 | { | |
14221 | delete_breakpoint (b); | |
14222 | } | |
14223 | ||
51be5b68 PA |
14224 | /* A callback for map_breakpoint_numbers that calls |
14225 | delete_breakpoint. */ | |
14226 | ||
14227 | static void | |
14228 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
14229 | { | |
14230 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
14231 | } | |
14232 | ||
c906108c | 14233 | void |
fba45db2 | 14234 | delete_command (char *arg, int from_tty) |
c906108c | 14235 | { |
35df4500 | 14236 | struct breakpoint *b, *b_tmp; |
c906108c | 14237 | |
ea9365bb TT |
14238 | dont_repeat (); |
14239 | ||
c906108c SS |
14240 | if (arg == 0) |
14241 | { | |
14242 | int breaks_to_delete = 0; | |
14243 | ||
46c6471b PA |
14244 | /* Delete all breakpoints if no argument. Do not delete |
14245 | internal breakpoints, these have to be deleted with an | |
14246 | explicit breakpoint number argument. */ | |
c5aa993b | 14247 | ALL_BREAKPOINTS (b) |
46c6471b | 14248 | if (user_breakpoint_p (b)) |
973d738b DJ |
14249 | { |
14250 | breaks_to_delete = 1; | |
14251 | break; | |
14252 | } | |
c906108c SS |
14253 | |
14254 | /* Ask user only if there are some breakpoints to delete. */ | |
14255 | if (!from_tty | |
e2e0b3e5 | 14256 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 14257 | { |
35df4500 | 14258 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14259 | if (user_breakpoint_p (b)) |
c5aa993b | 14260 | delete_breakpoint (b); |
c906108c SS |
14261 | } |
14262 | } | |
14263 | else | |
51be5b68 | 14264 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
14265 | } |
14266 | ||
0d381245 VP |
14267 | static int |
14268 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 14269 | { |
0d381245 | 14270 | for (; loc; loc = loc->next) |
8645ff69 UW |
14271 | if (!loc->shlib_disabled |
14272 | && !loc->pspace->executing_startup) | |
0d381245 VP |
14273 | return 0; |
14274 | return 1; | |
fe3f5fa8 VP |
14275 | } |
14276 | ||
776592bf DE |
14277 | /* Subroutine of update_breakpoint_locations to simplify it. |
14278 | Return non-zero if multiple fns in list LOC have the same name. | |
14279 | Null names are ignored. */ | |
14280 | ||
14281 | static int | |
14282 | ambiguous_names_p (struct bp_location *loc) | |
14283 | { | |
14284 | struct bp_location *l; | |
14285 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
14286 | (int (*) (const void *, |
14287 | const void *)) streq, | |
776592bf DE |
14288 | NULL, xcalloc, xfree); |
14289 | ||
14290 | for (l = loc; l != NULL; l = l->next) | |
14291 | { | |
14292 | const char **slot; | |
14293 | const char *name = l->function_name; | |
14294 | ||
14295 | /* Allow for some names to be NULL, ignore them. */ | |
14296 | if (name == NULL) | |
14297 | continue; | |
14298 | ||
14299 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
14300 | INSERT); | |
4a64f543 MS |
14301 | /* NOTE: We can assume slot != NULL here because xcalloc never |
14302 | returns NULL. */ | |
776592bf DE |
14303 | if (*slot != NULL) |
14304 | { | |
14305 | htab_delete (htab); | |
14306 | return 1; | |
14307 | } | |
14308 | *slot = name; | |
14309 | } | |
14310 | ||
14311 | htab_delete (htab); | |
14312 | return 0; | |
14313 | } | |
14314 | ||
0fb4aa4b PA |
14315 | /* When symbols change, it probably means the sources changed as well, |
14316 | and it might mean the static tracepoint markers are no longer at | |
14317 | the same address or line numbers they used to be at last we | |
14318 | checked. Losing your static tracepoints whenever you rebuild is | |
14319 | undesirable. This function tries to resync/rematch gdb static | |
14320 | tracepoints with the markers on the target, for static tracepoints | |
14321 | that have not been set by marker id. Static tracepoint that have | |
14322 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14323 | The heuristic is: | |
14324 | ||
14325 | 1) For a tracepoint set at a specific address, look for a marker at | |
14326 | the old PC. If one is found there, assume to be the same marker. | |
14327 | If the name / string id of the marker found is different from the | |
14328 | previous known name, assume that means the user renamed the marker | |
14329 | in the sources, and output a warning. | |
14330 | ||
14331 | 2) For a tracepoint set at a given line number, look for a marker | |
14332 | at the new address of the old line number. If one is found there, | |
14333 | assume to be the same marker. If the name / string id of the | |
14334 | marker found is different from the previous known name, assume that | |
14335 | means the user renamed the marker in the sources, and output a | |
14336 | warning. | |
14337 | ||
14338 | 3) If a marker is no longer found at the same address or line, it | |
14339 | may mean the marker no longer exists. But it may also just mean | |
14340 | the code changed a bit. Maybe the user added a few lines of code | |
14341 | that made the marker move up or down (in line number terms). Ask | |
14342 | the target for info about the marker with the string id as we knew | |
14343 | it. If found, update line number and address in the matching | |
14344 | static tracepoint. This will get confused if there's more than one | |
14345 | marker with the same ID (possible in UST, although unadvised | |
14346 | precisely because it confuses tools). */ | |
14347 | ||
14348 | static struct symtab_and_line | |
14349 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14350 | { | |
d9b3f62e | 14351 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14352 | struct static_tracepoint_marker marker; |
14353 | CORE_ADDR pc; | |
0fb4aa4b PA |
14354 | |
14355 | pc = sal.pc; | |
14356 | if (sal.line) | |
14357 | find_line_pc (sal.symtab, sal.line, &pc); | |
14358 | ||
14359 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14360 | { | |
d9b3f62e | 14361 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14362 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14363 | b->number, | |
d9b3f62e | 14364 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14365 | |
d9b3f62e PA |
14366 | xfree (tp->static_trace_marker_id); |
14367 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14368 | release_static_tracepoint_marker (&marker); |
14369 | ||
14370 | return sal; | |
14371 | } | |
14372 | ||
14373 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14374 | by string ID. */ | |
14375 | if (!sal.explicit_pc | |
14376 | && sal.line != 0 | |
14377 | && sal.symtab != NULL | |
d9b3f62e | 14378 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14379 | { |
14380 | VEC(static_tracepoint_marker_p) *markers; | |
14381 | ||
14382 | markers | |
d9b3f62e | 14383 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14384 | |
14385 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14386 | { | |
80e1d417 | 14387 | struct symtab_and_line sal2; |
0fb4aa4b | 14388 | struct symbol *sym; |
80e1d417 | 14389 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14390 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 14391 | |
80e1d417 | 14392 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14393 | |
d9b3f62e | 14394 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14395 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14396 | |
14397 | warning (_("marker for static tracepoint %d (%s) not " | |
14398 | "found at previous line number"), | |
d9b3f62e | 14399 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14400 | |
80e1d417 | 14401 | init_sal (&sal2); |
0fb4aa4b | 14402 | |
80e1d417 | 14403 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14404 | |
80e1d417 AS |
14405 | sal2 = find_pc_line (tpmarker->address, 0); |
14406 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14407 | ui_out_text (uiout, "Now in "); |
14408 | if (sym) | |
14409 | { | |
14410 | ui_out_field_string (uiout, "func", | |
14411 | SYMBOL_PRINT_NAME (sym)); | |
14412 | ui_out_text (uiout, " at "); | |
14413 | } | |
05cba821 JK |
14414 | ui_out_field_string (uiout, "file", |
14415 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14416 | ui_out_text (uiout, ":"); |
14417 | ||
14418 | if (ui_out_is_mi_like_p (uiout)) | |
14419 | { | |
0b0865da | 14420 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14421 | |
f35a17b5 | 14422 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14423 | } |
14424 | ||
80e1d417 | 14425 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14426 | ui_out_text (uiout, "\n"); |
14427 | ||
80e1d417 | 14428 | b->loc->line_number = sal2.line; |
2f202fde | 14429 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b PA |
14430 | |
14431 | xfree (b->addr_string); | |
14432 | b->addr_string = xstrprintf ("%s:%d", | |
05cba821 | 14433 | symtab_to_filename_for_display (sal2.symtab), |
f8eba3c6 | 14434 | b->loc->line_number); |
0fb4aa4b PA |
14435 | |
14436 | /* Might be nice to check if function changed, and warn if | |
14437 | so. */ | |
14438 | ||
80e1d417 | 14439 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14440 | } |
14441 | } | |
14442 | return sal; | |
14443 | } | |
14444 | ||
8d3788bd VP |
14445 | /* Returns 1 iff locations A and B are sufficiently same that |
14446 | we don't need to report breakpoint as changed. */ | |
14447 | ||
14448 | static int | |
14449 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14450 | { | |
14451 | while (a && b) | |
14452 | { | |
14453 | if (a->address != b->address) | |
14454 | return 0; | |
14455 | ||
14456 | if (a->shlib_disabled != b->shlib_disabled) | |
14457 | return 0; | |
14458 | ||
14459 | if (a->enabled != b->enabled) | |
14460 | return 0; | |
14461 | ||
14462 | a = a->next; | |
14463 | b = b->next; | |
14464 | } | |
14465 | ||
14466 | if ((a == NULL) != (b == NULL)) | |
14467 | return 0; | |
14468 | ||
14469 | return 1; | |
14470 | } | |
14471 | ||
f1310107 TJB |
14472 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
14473 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
14474 | a ranged breakpoint. */ | |
14475 | ||
0e30163f | 14476 | void |
0d381245 | 14477 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
14478 | struct symtabs_and_lines sals, |
14479 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14480 | { |
14481 | int i; | |
0d381245 VP |
14482 | struct bp_location *existing_locations = b->loc; |
14483 | ||
f8eba3c6 TT |
14484 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14485 | { | |
14486 | /* Ranged breakpoints have only one start location and one end | |
14487 | location. */ | |
14488 | b->enable_state = bp_disabled; | |
44702360 | 14489 | update_global_location_list (UGLL_MAY_INSERT); |
f8eba3c6 TT |
14490 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14491 | "multiple locations found\n"), | |
14492 | b->number); | |
14493 | return; | |
14494 | } | |
f1310107 | 14495 | |
4a64f543 MS |
14496 | /* If there's no new locations, and all existing locations are |
14497 | pending, don't do anything. This optimizes the common case where | |
14498 | all locations are in the same shared library, that was unloaded. | |
14499 | We'd like to retain the location, so that when the library is | |
14500 | loaded again, we don't loose the enabled/disabled status of the | |
14501 | individual locations. */ | |
0d381245 | 14502 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
14503 | return; |
14504 | ||
fe3f5fa8 VP |
14505 | b->loc = NULL; |
14506 | ||
0d381245 | 14507 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14508 | { |
f8eba3c6 TT |
14509 | struct bp_location *new_loc; |
14510 | ||
14511 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14512 | ||
14513 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14514 | |
0d381245 VP |
14515 | /* Reparse conditions, they might contain references to the |
14516 | old symtab. */ | |
14517 | if (b->cond_string != NULL) | |
14518 | { | |
bbc13ae3 | 14519 | const char *s; |
bfd189b1 | 14520 | volatile struct gdb_exception e; |
fe3f5fa8 | 14521 | |
0d381245 VP |
14522 | s = b->cond_string; |
14523 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14524 | { | |
1bb9788d TT |
14525 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14526 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14527 | 0); |
14528 | } | |
14529 | if (e.reason < 0) | |
14530 | { | |
3e43a32a MS |
14531 | warning (_("failed to reevaluate condition " |
14532 | "for breakpoint %d: %s"), | |
0d381245 VP |
14533 | b->number, e.message); |
14534 | new_loc->enabled = 0; | |
14535 | } | |
14536 | } | |
fe3f5fa8 | 14537 | |
f1310107 TJB |
14538 | if (sals_end.nelts) |
14539 | { | |
14540 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14541 | ||
14542 | new_loc->length = end - sals.sals[0].pc + 1; | |
14543 | } | |
0d381245 | 14544 | } |
fe3f5fa8 | 14545 | |
514f746b AR |
14546 | /* Update locations of permanent breakpoints. */ |
14547 | if (b->enable_state == bp_permanent) | |
14548 | make_breakpoint_permanent (b); | |
14549 | ||
4a64f543 MS |
14550 | /* If possible, carry over 'disable' status from existing |
14551 | breakpoints. */ | |
0d381245 VP |
14552 | { |
14553 | struct bp_location *e = existing_locations; | |
776592bf DE |
14554 | /* If there are multiple breakpoints with the same function name, |
14555 | e.g. for inline functions, comparing function names won't work. | |
14556 | Instead compare pc addresses; this is just a heuristic as things | |
14557 | may have moved, but in practice it gives the correct answer | |
14558 | often enough until a better solution is found. */ | |
14559 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14560 | ||
0d381245 VP |
14561 | for (; e; e = e->next) |
14562 | { | |
14563 | if (!e->enabled && e->function_name) | |
14564 | { | |
14565 | struct bp_location *l = b->loc; | |
776592bf DE |
14566 | if (have_ambiguous_names) |
14567 | { | |
14568 | for (; l; l = l->next) | |
f1310107 | 14569 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14570 | { |
14571 | l->enabled = 0; | |
14572 | break; | |
14573 | } | |
14574 | } | |
14575 | else | |
14576 | { | |
14577 | for (; l; l = l->next) | |
14578 | if (l->function_name | |
14579 | && strcmp (e->function_name, l->function_name) == 0) | |
14580 | { | |
14581 | l->enabled = 0; | |
14582 | break; | |
14583 | } | |
14584 | } | |
0d381245 VP |
14585 | } |
14586 | } | |
14587 | } | |
fe3f5fa8 | 14588 | |
8d3788bd VP |
14589 | if (!locations_are_equal (existing_locations, b->loc)) |
14590 | observer_notify_breakpoint_modified (b); | |
14591 | ||
44702360 | 14592 | update_global_location_list (UGLL_MAY_INSERT); |
fe3f5fa8 VP |
14593 | } |
14594 | ||
ef23e705 TJB |
14595 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
14596 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
14597 | ||
14598 | static struct symtabs_and_lines | |
14599 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
14600 | { | |
14601 | char *s; | |
02d20e4a | 14602 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 14603 | volatile struct gdb_exception e; |
ef23e705 | 14604 | |
983af33b | 14605 | gdb_assert (b->ops != NULL); |
ef23e705 | 14606 | s = addr_string; |
ef23e705 TJB |
14607 | |
14608 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14609 | { | |
983af33b | 14610 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
14611 | } |
14612 | if (e.reason < 0) | |
14613 | { | |
14614 | int not_found_and_ok = 0; | |
14615 | /* For pending breakpoints, it's expected that parsing will | |
14616 | fail until the right shared library is loaded. User has | |
14617 | already told to create pending breakpoints and don't need | |
14618 | extra messages. If breakpoint is in bp_shlib_disabled | |
14619 | state, then user already saw the message about that | |
14620 | breakpoint being disabled, and don't want to see more | |
14621 | errors. */ | |
58438ac1 | 14622 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14623 | && (b->condition_not_parsed |
14624 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14625 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14626 | || b->enable_state == bp_disabled)) |
14627 | not_found_and_ok = 1; | |
14628 | ||
14629 | if (!not_found_and_ok) | |
14630 | { | |
14631 | /* We surely don't want to warn about the same breakpoint | |
14632 | 10 times. One solution, implemented here, is disable | |
14633 | the breakpoint on error. Another solution would be to | |
14634 | have separate 'warning emitted' flag. Since this | |
14635 | happens only when a binary has changed, I don't know | |
14636 | which approach is better. */ | |
14637 | b->enable_state = bp_disabled; | |
14638 | throw_exception (e); | |
14639 | } | |
14640 | } | |
14641 | ||
58438ac1 | 14642 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 14643 | { |
f8eba3c6 | 14644 | int i; |
ef23e705 | 14645 | |
f8eba3c6 TT |
14646 | for (i = 0; i < sals.nelts; ++i) |
14647 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
14648 | if (b->condition_not_parsed && s && s[0]) |
14649 | { | |
ed1d1739 KS |
14650 | char *cond_string, *extra_string; |
14651 | int thread, task; | |
ef23e705 TJB |
14652 | |
14653 | find_condition_and_thread (s, sals.sals[0].pc, | |
e7e0cddf SS |
14654 | &cond_string, &thread, &task, |
14655 | &extra_string); | |
ef23e705 TJB |
14656 | if (cond_string) |
14657 | b->cond_string = cond_string; | |
14658 | b->thread = thread; | |
14659 | b->task = task; | |
e7e0cddf SS |
14660 | if (extra_string) |
14661 | b->extra_string = extra_string; | |
ef23e705 TJB |
14662 | b->condition_not_parsed = 0; |
14663 | } | |
14664 | ||
983af33b | 14665 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14666 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14667 | |
58438ac1 TT |
14668 | *found = 1; |
14669 | } | |
14670 | else | |
14671 | *found = 0; | |
ef23e705 TJB |
14672 | |
14673 | return sals; | |
14674 | } | |
14675 | ||
348d480f PA |
14676 | /* The default re_set method, for typical hardware or software |
14677 | breakpoints. Reevaluate the breakpoint and recreate its | |
14678 | locations. */ | |
14679 | ||
14680 | static void | |
28010a5d | 14681 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14682 | { |
14683 | int found; | |
f1310107 | 14684 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14685 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14686 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
14687 | |
14688 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
14689 | if (found) | |
14690 | { | |
14691 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14692 | expanded = sals; |
ef23e705 TJB |
14693 | } |
14694 | ||
f1310107 TJB |
14695 | if (b->addr_string_range_end) |
14696 | { | |
14697 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
14698 | if (found) | |
14699 | { | |
14700 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14701 | expanded_end = sals_end; |
f1310107 TJB |
14702 | } |
14703 | } | |
14704 | ||
14705 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14706 | } |
14707 | ||
983af33b SDJ |
14708 | /* Default method for creating SALs from an address string. It basically |
14709 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14710 | ||
14711 | static void | |
14712 | create_sals_from_address_default (char **arg, | |
14713 | struct linespec_result *canonical, | |
14714 | enum bptype type_wanted, | |
14715 | char *addr_start, char **copy_arg) | |
14716 | { | |
14717 | parse_breakpoint_sals (arg, canonical); | |
14718 | } | |
14719 | ||
14720 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14721 | function for the `create_breakpoints_sal' method of | |
14722 | breakpoint_ops. */ | |
14723 | ||
14724 | static void | |
14725 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14726 | struct linespec_result *canonical, | |
983af33b | 14727 | char *cond_string, |
e7e0cddf | 14728 | char *extra_string, |
983af33b SDJ |
14729 | enum bptype type_wanted, |
14730 | enum bpdisp disposition, | |
14731 | int thread, | |
14732 | int task, int ignore_count, | |
14733 | const struct breakpoint_ops *ops, | |
14734 | int from_tty, int enabled, | |
44f238bb | 14735 | int internal, unsigned flags) |
983af33b SDJ |
14736 | { |
14737 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14738 | extra_string, |
983af33b SDJ |
14739 | type_wanted, disposition, |
14740 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14741 | enabled, internal, flags); |
983af33b SDJ |
14742 | } |
14743 | ||
14744 | /* Decode the line represented by S by calling decode_line_full. This is the | |
14745 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
14746 | ||
14747 | static void | |
14748 | decode_linespec_default (struct breakpoint *b, char **s, | |
14749 | struct symtabs_and_lines *sals) | |
14750 | { | |
14751 | struct linespec_result canonical; | |
14752 | ||
14753 | init_linespec_result (&canonical); | |
14754 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
14755 | (struct symtab *) NULL, 0, | |
14756 | &canonical, multiple_symbols_all, | |
14757 | b->filter); | |
14758 | ||
14759 | /* We should get 0 or 1 resulting SALs. */ | |
14760 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14761 | ||
14762 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14763 | { | |
14764 | struct linespec_sals *lsal; | |
14765 | ||
14766 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14767 | *sals = lsal->sals; | |
14768 | /* Arrange it so the destructor does not free the | |
14769 | contents. */ | |
14770 | lsal->sals.sals = NULL; | |
14771 | } | |
14772 | ||
14773 | destroy_linespec_result (&canonical); | |
14774 | } | |
14775 | ||
28010a5d PA |
14776 | /* Prepare the global context for a re-set of breakpoint B. */ |
14777 | ||
14778 | static struct cleanup * | |
14779 | prepare_re_set_context (struct breakpoint *b) | |
14780 | { | |
14781 | struct cleanup *cleanups; | |
14782 | ||
14783 | input_radix = b->input_radix; | |
14784 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14785 | if (b->pspace != NULL) |
14786 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14787 | set_language (b->language); |
14788 | ||
14789 | return cleanups; | |
ef23e705 TJB |
14790 | } |
14791 | ||
c906108c SS |
14792 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14793 | The value we return ends up being the return value from catch_errors. | |
14794 | Unused in this case. */ | |
14795 | ||
14796 | static int | |
4efb68b1 | 14797 | breakpoint_re_set_one (void *bint) |
c906108c | 14798 | { |
4a64f543 | 14799 | /* Get past catch_errs. */ |
53a5351d | 14800 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14801 | struct cleanup *cleanups; |
c906108c | 14802 | |
348d480f PA |
14803 | cleanups = prepare_re_set_context (b); |
14804 | b->ops->re_set (b); | |
14805 | do_cleanups (cleanups); | |
c906108c SS |
14806 | return 0; |
14807 | } | |
14808 | ||
69de3c6a | 14809 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14810 | void |
69de3c6a | 14811 | breakpoint_re_set (void) |
c906108c | 14812 | { |
35df4500 | 14813 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14814 | enum language save_language; |
14815 | int save_input_radix; | |
6c95b8df | 14816 | struct cleanup *old_chain; |
c5aa993b | 14817 | |
c906108c SS |
14818 | save_language = current_language->la_language; |
14819 | save_input_radix = input_radix; | |
6c95b8df PA |
14820 | old_chain = save_current_program_space (); |
14821 | ||
35df4500 | 14822 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14823 | { |
4a64f543 | 14824 | /* Format possible error msg. */ |
fe3f5fa8 | 14825 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14826 | b->number); |
14827 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14828 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14829 | do_cleanups (cleanups); |
c5aa993b | 14830 | } |
c906108c SS |
14831 | set_language (save_language); |
14832 | input_radix = save_input_radix; | |
e62c965a | 14833 | |
0756c555 | 14834 | jit_breakpoint_re_set (); |
4efc6507 | 14835 | |
6c95b8df PA |
14836 | do_cleanups (old_chain); |
14837 | ||
af02033e PP |
14838 | create_overlay_event_breakpoint (); |
14839 | create_longjmp_master_breakpoint (); | |
14840 | create_std_terminate_master_breakpoint (); | |
186c406b | 14841 | create_exception_master_breakpoint (); |
c906108c SS |
14842 | } |
14843 | \f | |
c906108c SS |
14844 | /* Reset the thread number of this breakpoint: |
14845 | ||
14846 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14847 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14848 | void |
fba45db2 | 14849 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14850 | { |
14851 | if (b->thread != -1) | |
14852 | { | |
39f77062 KB |
14853 | if (in_thread_list (inferior_ptid)) |
14854 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14855 | |
14856 | /* We're being called after following a fork. The new fork is | |
14857 | selected as current, and unless this was a vfork will have a | |
14858 | different program space from the original thread. Reset that | |
14859 | as well. */ | |
14860 | b->loc->pspace = current_program_space; | |
c906108c SS |
14861 | } |
14862 | } | |
14863 | ||
03ac34d5 MS |
14864 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14865 | If from_tty is nonzero, it prints a message to that effect, | |
14866 | which ends with a period (no newline). */ | |
14867 | ||
c906108c | 14868 | void |
fba45db2 | 14869 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14870 | { |
52f0bd74 | 14871 | struct breakpoint *b; |
c906108c SS |
14872 | |
14873 | if (count < 0) | |
14874 | count = 0; | |
14875 | ||
14876 | ALL_BREAKPOINTS (b) | |
14877 | if (b->number == bptnum) | |
c5aa993b | 14878 | { |
d77f58be SS |
14879 | if (is_tracepoint (b)) |
14880 | { | |
14881 | if (from_tty && count != 0) | |
14882 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14883 | bptnum); | |
14884 | return; | |
14885 | } | |
14886 | ||
c5aa993b | 14887 | b->ignore_count = count; |
221ea385 KS |
14888 | if (from_tty) |
14889 | { | |
14890 | if (count == 0) | |
3e43a32a MS |
14891 | printf_filtered (_("Will stop next time " |
14892 | "breakpoint %d is reached."), | |
221ea385 KS |
14893 | bptnum); |
14894 | else if (count == 1) | |
a3f17187 | 14895 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14896 | bptnum); |
14897 | else | |
3e43a32a MS |
14898 | printf_filtered (_("Will ignore next %d " |
14899 | "crossings of breakpoint %d."), | |
221ea385 KS |
14900 | count, bptnum); |
14901 | } | |
8d3788bd | 14902 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14903 | return; |
14904 | } | |
c906108c | 14905 | |
8a3fe4f8 | 14906 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14907 | } |
14908 | ||
c906108c SS |
14909 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14910 | ||
14911 | static void | |
fba45db2 | 14912 | ignore_command (char *args, int from_tty) |
c906108c SS |
14913 | { |
14914 | char *p = args; | |
52f0bd74 | 14915 | int num; |
c906108c SS |
14916 | |
14917 | if (p == 0) | |
e2e0b3e5 | 14918 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14919 | |
c906108c | 14920 | num = get_number (&p); |
5c44784c | 14921 | if (num == 0) |
8a3fe4f8 | 14922 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14923 | if (*p == 0) |
8a3fe4f8 | 14924 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14925 | |
14926 | set_ignore_count (num, | |
14927 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14928 | from_tty); | |
221ea385 KS |
14929 | if (from_tty) |
14930 | printf_filtered ("\n"); | |
c906108c SS |
14931 | } |
14932 | \f | |
14933 | /* Call FUNCTION on each of the breakpoints | |
14934 | whose numbers are given in ARGS. */ | |
14935 | ||
14936 | static void | |
95a42b64 TT |
14937 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14938 | void *), | |
14939 | void *data) | |
c906108c | 14940 | { |
52f0bd74 AC |
14941 | int num; |
14942 | struct breakpoint *b, *tmp; | |
11cf8741 | 14943 | int match; |
197f0a60 | 14944 | struct get_number_or_range_state state; |
c906108c | 14945 | |
197f0a60 | 14946 | if (args == 0) |
e2e0b3e5 | 14947 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14948 | |
197f0a60 TT |
14949 | init_number_or_range (&state, args); |
14950 | ||
14951 | while (!state.finished) | |
c906108c | 14952 | { |
e799154c | 14953 | const char *p = state.string; |
197f0a60 | 14954 | |
11cf8741 | 14955 | match = 0; |
c5aa993b | 14956 | |
197f0a60 | 14957 | num = get_number_or_range (&state); |
5c44784c | 14958 | if (num == 0) |
c5aa993b | 14959 | { |
8a3fe4f8 | 14960 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14961 | } |
14962 | else | |
14963 | { | |
14964 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14965 | if (b->number == num) | |
14966 | { | |
11cf8741 | 14967 | match = 1; |
cdac0397 | 14968 | function (b, data); |
11cf8741 | 14969 | break; |
5c44784c | 14970 | } |
11cf8741 | 14971 | if (match == 0) |
a3f17187 | 14972 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14973 | } |
c906108c SS |
14974 | } |
14975 | } | |
14976 | ||
0d381245 VP |
14977 | static struct bp_location * |
14978 | find_location_by_number (char *number) | |
14979 | { | |
14980 | char *dot = strchr (number, '.'); | |
14981 | char *p1; | |
14982 | int bp_num; | |
14983 | int loc_num; | |
14984 | struct breakpoint *b; | |
14985 | struct bp_location *loc; | |
14986 | ||
14987 | *dot = '\0'; | |
14988 | ||
14989 | p1 = number; | |
197f0a60 | 14990 | bp_num = get_number (&p1); |
0d381245 VP |
14991 | if (bp_num == 0) |
14992 | error (_("Bad breakpoint number '%s'"), number); | |
14993 | ||
14994 | ALL_BREAKPOINTS (b) | |
14995 | if (b->number == bp_num) | |
14996 | { | |
14997 | break; | |
14998 | } | |
14999 | ||
15000 | if (!b || b->number != bp_num) | |
15001 | error (_("Bad breakpoint number '%s'"), number); | |
15002 | ||
15003 | p1 = dot+1; | |
197f0a60 | 15004 | loc_num = get_number (&p1); |
0d381245 VP |
15005 | if (loc_num == 0) |
15006 | error (_("Bad breakpoint location number '%s'"), number); | |
15007 | ||
15008 | --loc_num; | |
15009 | loc = b->loc; | |
15010 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
15011 | ; | |
15012 | if (!loc) | |
15013 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
15014 | ||
15015 | return loc; | |
15016 | } | |
15017 | ||
15018 | ||
1900040c MS |
15019 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
15020 | If from_tty is nonzero, it prints a message to that effect, | |
15021 | which ends with a period (no newline). */ | |
15022 | ||
c906108c | 15023 | void |
fba45db2 | 15024 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
15025 | { |
15026 | /* Never disable a watchpoint scope breakpoint; we want to | |
15027 | hit them when we leave scope so we can delete both the | |
15028 | watchpoint and its scope breakpoint at that time. */ | |
15029 | if (bpt->type == bp_watchpoint_scope) | |
15030 | return; | |
15031 | ||
c2c6d25f | 15032 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 15033 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
15034 | return; |
15035 | ||
b5de0fa7 | 15036 | bpt->enable_state = bp_disabled; |
c906108c | 15037 | |
b775012e LM |
15038 | /* Mark breakpoint locations modified. */ |
15039 | mark_breakpoint_modified (bpt); | |
15040 | ||
d248b706 KY |
15041 | if (target_supports_enable_disable_tracepoint () |
15042 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
15043 | { | |
15044 | struct bp_location *location; | |
15045 | ||
15046 | for (location = bpt->loc; location; location = location->next) | |
15047 | target_disable_tracepoint (location); | |
15048 | } | |
15049 | ||
44702360 | 15050 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 15051 | |
8d3788bd | 15052 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
15053 | } |
15054 | ||
51be5b68 PA |
15055 | /* A callback for iterate_over_related_breakpoints. */ |
15056 | ||
15057 | static void | |
15058 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
15059 | { | |
15060 | disable_breakpoint (b); | |
15061 | } | |
15062 | ||
95a42b64 TT |
15063 | /* A callback for map_breakpoint_numbers that calls |
15064 | disable_breakpoint. */ | |
15065 | ||
15066 | static void | |
15067 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
15068 | { | |
51be5b68 | 15069 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
15070 | } |
15071 | ||
c906108c | 15072 | static void |
fba45db2 | 15073 | disable_command (char *args, int from_tty) |
c906108c | 15074 | { |
c906108c | 15075 | if (args == 0) |
46c6471b PA |
15076 | { |
15077 | struct breakpoint *bpt; | |
15078 | ||
15079 | ALL_BREAKPOINTS (bpt) | |
15080 | if (user_breakpoint_p (bpt)) | |
15081 | disable_breakpoint (bpt); | |
15082 | } | |
9eaabc75 | 15083 | else |
0d381245 | 15084 | { |
9eaabc75 MW |
15085 | char *num = extract_arg (&args); |
15086 | ||
15087 | while (num) | |
d248b706 | 15088 | { |
9eaabc75 | 15089 | if (strchr (num, '.')) |
b775012e | 15090 | { |
9eaabc75 MW |
15091 | struct bp_location *loc = find_location_by_number (num); |
15092 | ||
15093 | if (loc) | |
15094 | { | |
15095 | if (loc->enabled) | |
15096 | { | |
15097 | loc->enabled = 0; | |
15098 | mark_breakpoint_location_modified (loc); | |
15099 | } | |
15100 | if (target_supports_enable_disable_tracepoint () | |
15101 | && current_trace_status ()->running && loc->owner | |
15102 | && is_tracepoint (loc->owner)) | |
15103 | target_disable_tracepoint (loc); | |
15104 | } | |
44702360 | 15105 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 15106 | } |
9eaabc75 MW |
15107 | else |
15108 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
15109 | num = extract_arg (&args); | |
d248b706 | 15110 | } |
0d381245 | 15111 | } |
c906108c SS |
15112 | } |
15113 | ||
15114 | static void | |
816338b5 SS |
15115 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
15116 | int count) | |
c906108c | 15117 | { |
afe38095 | 15118 | int target_resources_ok; |
c906108c SS |
15119 | |
15120 | if (bpt->type == bp_hardware_breakpoint) | |
15121 | { | |
15122 | int i; | |
c5aa993b | 15123 | i = hw_breakpoint_used_count (); |
53a5351d | 15124 | target_resources_ok = |
d92524f1 | 15125 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 15126 | i + 1, 0); |
c906108c | 15127 | if (target_resources_ok == 0) |
8a3fe4f8 | 15128 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 15129 | else if (target_resources_ok < 0) |
8a3fe4f8 | 15130 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
15131 | } |
15132 | ||
cc60f2e3 | 15133 | if (is_watchpoint (bpt)) |
c906108c | 15134 | { |
d07205c2 JK |
15135 | /* Initialize it just to avoid a GCC false warning. */ |
15136 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 15137 | volatile struct gdb_exception e; |
dde02812 ES |
15138 | |
15139 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 15140 | { |
3a5c3e22 PA |
15141 | struct watchpoint *w = (struct watchpoint *) bpt; |
15142 | ||
1e718ff1 TJB |
15143 | orig_enable_state = bpt->enable_state; |
15144 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 15145 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 15146 | } |
dde02812 | 15147 | if (e.reason < 0) |
c5aa993b | 15148 | { |
1e718ff1 | 15149 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
15150 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
15151 | bpt->number); | |
15152 | return; | |
c5aa993b | 15153 | } |
c906108c | 15154 | } |
0101ce28 | 15155 | |
b4c291bb KH |
15156 | if (bpt->enable_state != bp_permanent) |
15157 | bpt->enable_state = bp_enabled; | |
d248b706 | 15158 | |
b775012e LM |
15159 | bpt->enable_state = bp_enabled; |
15160 | ||
15161 | /* Mark breakpoint locations modified. */ | |
15162 | mark_breakpoint_modified (bpt); | |
15163 | ||
d248b706 KY |
15164 | if (target_supports_enable_disable_tracepoint () |
15165 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
15166 | { | |
15167 | struct bp_location *location; | |
15168 | ||
15169 | for (location = bpt->loc; location; location = location->next) | |
15170 | target_enable_tracepoint (location); | |
15171 | } | |
15172 | ||
b4c291bb | 15173 | bpt->disposition = disposition; |
816338b5 | 15174 | bpt->enable_count = count; |
44702360 | 15175 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 15176 | |
8d3788bd | 15177 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
15178 | } |
15179 | ||
fe3f5fa8 | 15180 | |
c906108c | 15181 | void |
fba45db2 | 15182 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 15183 | { |
816338b5 | 15184 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
15185 | } |
15186 | ||
15187 | static void | |
15188 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
15189 | { | |
15190 | enable_breakpoint (bpt); | |
c906108c SS |
15191 | } |
15192 | ||
95a42b64 TT |
15193 | /* A callback for map_breakpoint_numbers that calls |
15194 | enable_breakpoint. */ | |
15195 | ||
15196 | static void | |
15197 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
15198 | { | |
51be5b68 | 15199 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
15200 | } |
15201 | ||
c906108c SS |
15202 | /* The enable command enables the specified breakpoints (or all defined |
15203 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 15204 | in stopping the inferior. */ |
c906108c | 15205 | |
c906108c | 15206 | static void |
fba45db2 | 15207 | enable_command (char *args, int from_tty) |
c906108c | 15208 | { |
c906108c | 15209 | if (args == 0) |
46c6471b PA |
15210 | { |
15211 | struct breakpoint *bpt; | |
15212 | ||
15213 | ALL_BREAKPOINTS (bpt) | |
15214 | if (user_breakpoint_p (bpt)) | |
15215 | enable_breakpoint (bpt); | |
15216 | } | |
9eaabc75 | 15217 | else |
0d381245 | 15218 | { |
9eaabc75 MW |
15219 | char *num = extract_arg (&args); |
15220 | ||
15221 | while (num) | |
d248b706 | 15222 | { |
9eaabc75 | 15223 | if (strchr (num, '.')) |
b775012e | 15224 | { |
9eaabc75 MW |
15225 | struct bp_location *loc = find_location_by_number (num); |
15226 | ||
15227 | if (loc) | |
15228 | { | |
15229 | if (!loc->enabled) | |
15230 | { | |
15231 | loc->enabled = 1; | |
15232 | mark_breakpoint_location_modified (loc); | |
15233 | } | |
15234 | if (target_supports_enable_disable_tracepoint () | |
15235 | && current_trace_status ()->running && loc->owner | |
15236 | && is_tracepoint (loc->owner)) | |
15237 | target_enable_tracepoint (loc); | |
15238 | } | |
44702360 | 15239 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 15240 | } |
9eaabc75 MW |
15241 | else |
15242 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
15243 | num = extract_arg (&args); | |
d248b706 | 15244 | } |
0d381245 | 15245 | } |
c906108c SS |
15246 | } |
15247 | ||
816338b5 SS |
15248 | /* This struct packages up disposition data for application to multiple |
15249 | breakpoints. */ | |
15250 | ||
15251 | struct disp_data | |
15252 | { | |
15253 | enum bpdisp disp; | |
15254 | int count; | |
15255 | }; | |
15256 | ||
c906108c | 15257 | static void |
51be5b68 PA |
15258 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
15259 | { | |
816338b5 | 15260 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 15261 | |
816338b5 | 15262 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
15263 | } |
15264 | ||
15265 | static void | |
15266 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 15267 | { |
816338b5 | 15268 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
15269 | |
15270 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15271 | } |
15272 | ||
c906108c | 15273 | static void |
fba45db2 | 15274 | enable_once_command (char *args, int from_tty) |
c906108c | 15275 | { |
51be5b68 | 15276 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
15277 | } |
15278 | ||
816338b5 SS |
15279 | static void |
15280 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
15281 | { | |
15282 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
15283 | ||
15284 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
15285 | } | |
15286 | ||
15287 | static void | |
15288 | enable_count_command (char *args, int from_tty) | |
15289 | { | |
15290 | int count = get_number (&args); | |
15291 | ||
15292 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
15293 | } | |
15294 | ||
c906108c | 15295 | static void |
51be5b68 | 15296 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 15297 | { |
816338b5 | 15298 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
15299 | |
15300 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15301 | } |
15302 | ||
c906108c | 15303 | static void |
fba45db2 | 15304 | enable_delete_command (char *args, int from_tty) |
c906108c | 15305 | { |
51be5b68 | 15306 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15307 | } |
15308 | \f | |
fa8d40ab JJ |
15309 | static void |
15310 | set_breakpoint_cmd (char *args, int from_tty) | |
15311 | { | |
15312 | } | |
15313 | ||
15314 | static void | |
15315 | show_breakpoint_cmd (char *args, int from_tty) | |
15316 | { | |
15317 | } | |
15318 | ||
1f3b5d1b PP |
15319 | /* Invalidate last known value of any hardware watchpoint if |
15320 | the memory which that value represents has been written to by | |
15321 | GDB itself. */ | |
15322 | ||
15323 | static void | |
8de0566d YQ |
15324 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15325 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15326 | const bfd_byte *data) |
15327 | { | |
15328 | struct breakpoint *bp; | |
15329 | ||
15330 | ALL_BREAKPOINTS (bp) | |
15331 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15332 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15333 | { |
3a5c3e22 | 15334 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15335 | |
3a5c3e22 PA |
15336 | if (wp->val_valid && wp->val) |
15337 | { | |
15338 | struct bp_location *loc; | |
15339 | ||
15340 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15341 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15342 | && loc->address + loc->length > addr | |
15343 | && addr + len > loc->address) | |
15344 | { | |
15345 | value_free (wp->val); | |
15346 | wp->val = NULL; | |
15347 | wp->val_valid = 0; | |
15348 | } | |
15349 | } | |
1f3b5d1b PP |
15350 | } |
15351 | } | |
15352 | ||
8181d85f DJ |
15353 | /* Create and insert a raw software breakpoint at PC. Return an |
15354 | identifier, which should be used to remove the breakpoint later. | |
15355 | In general, places which call this should be using something on the | |
15356 | breakpoint chain instead; this function should be eliminated | |
15357 | someday. */ | |
15358 | ||
15359 | void * | |
6c95b8df PA |
15360 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
15361 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
15362 | { |
15363 | struct bp_target_info *bp_tgt; | |
ef370185 | 15364 | struct bp_location *bl; |
8181d85f | 15365 | |
41bf6aca | 15366 | bp_tgt = XCNEW (struct bp_target_info); |
8181d85f | 15367 | |
6c95b8df | 15368 | bp_tgt->placed_address_space = aspace; |
0d5ed153 | 15369 | bp_tgt->reqstd_address = pc; |
6c95b8df | 15370 | |
ef370185 JB |
15371 | /* If an unconditional non-raw breakpoint is already inserted at |
15372 | that location, there's no need to insert another. However, with | |
15373 | target-side evaluation of breakpoint conditions, if the | |
15374 | breakpoint that is currently inserted on the target is | |
15375 | conditional, we need to make it unconditional. Note that a | |
15376 | breakpoint with target-side commands is not reported even if | |
15377 | unconditional, so we need to remove the commands from the target | |
15378 | as well. */ | |
15379 | bl = find_non_raw_software_breakpoint_inserted_here (aspace, pc); | |
15380 | if (bl != NULL | |
15381 | && VEC_empty (agent_expr_p, bl->target_info.conditions) | |
15382 | && VEC_empty (agent_expr_p, bl->target_info.tcommands)) | |
15383 | { | |
15384 | bp_target_info_copy_insertion_state (bp_tgt, &bl->target_info); | |
15385 | return bp_tgt; | |
15386 | } | |
15387 | ||
a6d9a66e | 15388 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
15389 | { |
15390 | /* Could not insert the breakpoint. */ | |
15391 | xfree (bp_tgt); | |
15392 | return NULL; | |
15393 | } | |
15394 | ||
15395 | return bp_tgt; | |
15396 | } | |
15397 | ||
4a64f543 MS |
15398 | /* Remove a breakpoint BP inserted by |
15399 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
15400 | |
15401 | int | |
a6d9a66e | 15402 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
15403 | { |
15404 | struct bp_target_info *bp_tgt = bp; | |
ef370185 | 15405 | struct address_space *aspace = bp_tgt->placed_address_space; |
0d5ed153 | 15406 | CORE_ADDR address = bp_tgt->reqstd_address; |
ef370185 | 15407 | struct bp_location *bl; |
8181d85f DJ |
15408 | int ret; |
15409 | ||
ef370185 JB |
15410 | bl = find_non_raw_software_breakpoint_inserted_here (aspace, address); |
15411 | ||
15412 | /* Only remove the raw breakpoint if there are no other non-raw | |
15413 | breakpoints still inserted at this location. Otherwise, we would | |
15414 | be effectively disabling those breakpoints. */ | |
15415 | if (bl == NULL) | |
15416 | ret = target_remove_breakpoint (gdbarch, bp_tgt); | |
15417 | else if (!VEC_empty (agent_expr_p, bl->target_info.conditions) | |
15418 | || !VEC_empty (agent_expr_p, bl->target_info.tcommands)) | |
15419 | { | |
15420 | /* The target is evaluating conditions, and when we inserted the | |
15421 | software single-step breakpoint, we had made the breakpoint | |
15422 | unconditional and command-less on the target side. Reinsert | |
15423 | to restore the conditions/commands. */ | |
15424 | ret = target_insert_breakpoint (bl->gdbarch, &bl->target_info); | |
15425 | } | |
15426 | else | |
15427 | ret = 0; | |
15428 | ||
8181d85f DJ |
15429 | xfree (bp_tgt); |
15430 | ||
15431 | return ret; | |
15432 | } | |
15433 | ||
8181d85f DJ |
15434 | /* Create and insert a breakpoint for software single step. */ |
15435 | ||
15436 | void | |
6c95b8df | 15437 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15438 | struct address_space *aspace, |
15439 | CORE_ADDR next_pc) | |
8181d85f DJ |
15440 | { |
15441 | void **bpt_p; | |
15442 | ||
15443 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
15444 | { |
15445 | bpt_p = &single_step_breakpoints[0]; | |
15446 | single_step_gdbarch[0] = gdbarch; | |
15447 | } | |
8181d85f DJ |
15448 | else |
15449 | { | |
15450 | gdb_assert (single_step_breakpoints[1] == NULL); | |
15451 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 15452 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
15453 | } |
15454 | ||
4a64f543 MS |
15455 | /* NOTE drow/2006-04-11: A future improvement to this function would |
15456 | be to only create the breakpoints once, and actually put them on | |
15457 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
15458 | We could adjust the addresses each time they were needed. Doing | |
15459 | this requires corresponding changes elsewhere where single step | |
15460 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 15461 | |
6c95b8df | 15462 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 15463 | if (*bpt_p == NULL) |
5af949e3 UW |
15464 | error (_("Could not insert single-step breakpoint at %s"), |
15465 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
15466 | } |
15467 | ||
f02253f1 HZ |
15468 | /* Check if the breakpoints used for software single stepping |
15469 | were inserted or not. */ | |
15470 | ||
15471 | int | |
15472 | single_step_breakpoints_inserted (void) | |
15473 | { | |
15474 | return (single_step_breakpoints[0] != NULL | |
15475 | || single_step_breakpoints[1] != NULL); | |
15476 | } | |
15477 | ||
8181d85f DJ |
15478 | /* Remove and delete any breakpoints used for software single step. */ |
15479 | ||
15480 | void | |
15481 | remove_single_step_breakpoints (void) | |
15482 | { | |
15483 | gdb_assert (single_step_breakpoints[0] != NULL); | |
15484 | ||
15485 | /* See insert_single_step_breakpoint for more about this deprecated | |
15486 | call. */ | |
a6d9a66e UW |
15487 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
15488 | single_step_breakpoints[0]); | |
15489 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
15490 | single_step_breakpoints[0] = NULL; |
15491 | ||
15492 | if (single_step_breakpoints[1] != NULL) | |
15493 | { | |
a6d9a66e UW |
15494 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
15495 | single_step_breakpoints[1]); | |
15496 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
15497 | single_step_breakpoints[1] = NULL; |
15498 | } | |
15499 | } | |
15500 | ||
d03285ec UW |
15501 | /* Delete software single step breakpoints without removing them from |
15502 | the inferior. This is intended to be used if the inferior's address | |
15503 | space where they were inserted is already gone, e.g. after exit or | |
15504 | exec. */ | |
15505 | ||
15506 | void | |
15507 | cancel_single_step_breakpoints (void) | |
15508 | { | |
15509 | int i; | |
15510 | ||
15511 | for (i = 0; i < 2; i++) | |
15512 | if (single_step_breakpoints[i]) | |
15513 | { | |
15514 | xfree (single_step_breakpoints[i]); | |
15515 | single_step_breakpoints[i] = NULL; | |
15516 | single_step_gdbarch[i] = NULL; | |
15517 | } | |
15518 | } | |
15519 | ||
15520 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
15521 | removing them. */ | |
15522 | ||
15523 | static void | |
15524 | detach_single_step_breakpoints (void) | |
15525 | { | |
15526 | int i; | |
15527 | ||
15528 | for (i = 0; i < 2; i++) | |
15529 | if (single_step_breakpoints[i]) | |
15530 | target_remove_breakpoint (single_step_gdbarch[i], | |
15531 | single_step_breakpoints[i]); | |
15532 | } | |
15533 | ||
ef370185 JB |
15534 | /* Find the software single-step breakpoint that inserted at PC. |
15535 | Returns its slot if found, and -1 if not found. */ | |
1aafd4da | 15536 | |
ef370185 JB |
15537 | static int |
15538 | find_single_step_breakpoint (struct address_space *aspace, | |
15539 | CORE_ADDR pc) | |
1aafd4da UW |
15540 | { |
15541 | int i; | |
15542 | ||
15543 | for (i = 0; i < 2; i++) | |
15544 | { | |
15545 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
15546 | if (bp_tgt |
15547 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
0d5ed153 | 15548 | bp_tgt->reqstd_address, |
6c95b8df | 15549 | aspace, pc)) |
ef370185 | 15550 | return i; |
1aafd4da UW |
15551 | } |
15552 | ||
ef370185 JB |
15553 | return -1; |
15554 | } | |
15555 | ||
15556 | /* Check whether a software single-step breakpoint is inserted at | |
15557 | PC. */ | |
15558 | ||
15559 | int | |
15560 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15561 | CORE_ADDR pc) | |
15562 | { | |
15563 | return find_single_step_breakpoint (aspace, pc) >= 0; | |
1aafd4da UW |
15564 | } |
15565 | ||
a96d9b2e SDJ |
15566 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
15567 | non-zero otherwise. */ | |
15568 | static int | |
15569 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
15570 | { | |
15571 | if (syscall_catchpoint_p (bp) | |
15572 | && bp->enable_state != bp_disabled | |
15573 | && bp->enable_state != bp_call_disabled) | |
15574 | return 1; | |
15575 | else | |
15576 | return 0; | |
15577 | } | |
15578 | ||
15579 | int | |
15580 | catch_syscall_enabled (void) | |
15581 | { | |
fa3064dd YQ |
15582 | struct catch_syscall_inferior_data *inf_data |
15583 | = get_catch_syscall_inferior_data (current_inferior ()); | |
a96d9b2e | 15584 | |
fa3064dd | 15585 | return inf_data->total_syscalls_count != 0; |
a96d9b2e SDJ |
15586 | } |
15587 | ||
15588 | int | |
15589 | catching_syscall_number (int syscall_number) | |
15590 | { | |
15591 | struct breakpoint *bp; | |
15592 | ||
15593 | ALL_BREAKPOINTS (bp) | |
15594 | if (is_syscall_catchpoint_enabled (bp)) | |
15595 | { | |
be5c67c1 PA |
15596 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
15597 | ||
15598 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
15599 | { |
15600 | int i, iter; | |
15601 | for (i = 0; | |
be5c67c1 | 15602 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
15603 | i++) |
15604 | if (syscall_number == iter) | |
15605 | return 1; | |
15606 | } | |
15607 | else | |
15608 | return 1; | |
15609 | } | |
15610 | ||
15611 | return 0; | |
15612 | } | |
15613 | ||
15614 | /* Complete syscall names. Used by "catch syscall". */ | |
49c4e619 | 15615 | static VEC (char_ptr) * |
a96d9b2e | 15616 | catch_syscall_completer (struct cmd_list_element *cmd, |
6f937416 | 15617 | const char *text, const char *word) |
a96d9b2e SDJ |
15618 | { |
15619 | const char **list = get_syscall_names (); | |
49c4e619 | 15620 | VEC (char_ptr) *retlist |
b45627a0 | 15621 | = (list == NULL) ? NULL : complete_on_enum (list, word, word); |
cc59ec59 | 15622 | |
c38eea1a MS |
15623 | xfree (list); |
15624 | return retlist; | |
a96d9b2e SDJ |
15625 | } |
15626 | ||
1042e4c0 SS |
15627 | /* Tracepoint-specific operations. */ |
15628 | ||
15629 | /* Set tracepoint count to NUM. */ | |
15630 | static void | |
15631 | set_tracepoint_count (int num) | |
15632 | { | |
15633 | tracepoint_count = num; | |
4fa62494 | 15634 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15635 | } |
15636 | ||
70221824 | 15637 | static void |
1042e4c0 SS |
15638 | trace_command (char *arg, int from_tty) |
15639 | { | |
55aa24fb SDJ |
15640 | struct breakpoint_ops *ops; |
15641 | const char *arg_cp = arg; | |
15642 | ||
15643 | if (arg && probe_linespec_to_ops (&arg_cp)) | |
15644 | ops = &tracepoint_probe_breakpoint_ops; | |
15645 | else | |
15646 | ops = &tracepoint_breakpoint_ops; | |
15647 | ||
558a9d82 YQ |
15648 | create_breakpoint (get_current_arch (), |
15649 | arg, | |
15650 | NULL, 0, NULL, 1 /* parse arg */, | |
15651 | 0 /* tempflag */, | |
15652 | bp_tracepoint /* type_wanted */, | |
15653 | 0 /* Ignore count */, | |
15654 | pending_break_support, | |
15655 | ops, | |
15656 | from_tty, | |
15657 | 1 /* enabled */, | |
15658 | 0 /* internal */, 0); | |
1042e4c0 SS |
15659 | } |
15660 | ||
70221824 | 15661 | static void |
7a697b8d SS |
15662 | ftrace_command (char *arg, int from_tty) |
15663 | { | |
558a9d82 YQ |
15664 | create_breakpoint (get_current_arch (), |
15665 | arg, | |
15666 | NULL, 0, NULL, 1 /* parse arg */, | |
15667 | 0 /* tempflag */, | |
15668 | bp_fast_tracepoint /* type_wanted */, | |
15669 | 0 /* Ignore count */, | |
15670 | pending_break_support, | |
15671 | &tracepoint_breakpoint_ops, | |
15672 | from_tty, | |
15673 | 1 /* enabled */, | |
15674 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15675 | } |
15676 | ||
15677 | /* strace command implementation. Creates a static tracepoint. */ | |
15678 | ||
70221824 | 15679 | static void |
0fb4aa4b PA |
15680 | strace_command (char *arg, int from_tty) |
15681 | { | |
983af33b SDJ |
15682 | struct breakpoint_ops *ops; |
15683 | ||
15684 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15685 | or with a normal static tracepoint. */ | |
15686 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
15687 | ops = &strace_marker_breakpoint_ops; | |
15688 | else | |
15689 | ops = &tracepoint_breakpoint_ops; | |
15690 | ||
558a9d82 YQ |
15691 | create_breakpoint (get_current_arch (), |
15692 | arg, | |
15693 | NULL, 0, NULL, 1 /* parse arg */, | |
15694 | 0 /* tempflag */, | |
15695 | bp_static_tracepoint /* type_wanted */, | |
15696 | 0 /* Ignore count */, | |
15697 | pending_break_support, | |
15698 | ops, | |
15699 | from_tty, | |
15700 | 1 /* enabled */, | |
15701 | 0 /* internal */, 0); | |
7a697b8d SS |
15702 | } |
15703 | ||
409873ef SS |
15704 | /* Set up a fake reader function that gets command lines from a linked |
15705 | list that was acquired during tracepoint uploading. */ | |
15706 | ||
15707 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15708 | static int next_cmd; |
409873ef SS |
15709 | |
15710 | static char * | |
15711 | read_uploaded_action (void) | |
15712 | { | |
15713 | char *rslt; | |
15714 | ||
3149d8c1 | 15715 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15716 | |
3149d8c1 | 15717 | next_cmd++; |
409873ef SS |
15718 | |
15719 | return rslt; | |
15720 | } | |
15721 | ||
00bf0b85 SS |
15722 | /* Given information about a tracepoint as recorded on a target (which |
15723 | can be either a live system or a trace file), attempt to create an | |
15724 | equivalent GDB tracepoint. This is not a reliable process, since | |
15725 | the target does not necessarily have all the information used when | |
15726 | the tracepoint was originally defined. */ | |
15727 | ||
d9b3f62e | 15728 | struct tracepoint * |
00bf0b85 | 15729 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15730 | { |
409873ef | 15731 | char *addr_str, small_buf[100]; |
d9b3f62e | 15732 | struct tracepoint *tp; |
fd9b8c24 | 15733 | |
409873ef SS |
15734 | if (utp->at_string) |
15735 | addr_str = utp->at_string; | |
15736 | else | |
15737 | { | |
15738 | /* In the absence of a source location, fall back to raw | |
15739 | address. Since there is no way to confirm that the address | |
15740 | means the same thing as when the trace was started, warn the | |
15741 | user. */ | |
3e43a32a MS |
15742 | warning (_("Uploaded tracepoint %d has no " |
15743 | "source location, using raw address"), | |
409873ef | 15744 | utp->number); |
8c042590 | 15745 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15746 | addr_str = small_buf; |
15747 | } | |
15748 | ||
15749 | /* There's not much we can do with a sequence of bytecodes. */ | |
15750 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15751 | warning (_("Uploaded tracepoint %d condition " |
15752 | "has no source form, ignoring it"), | |
409873ef | 15753 | utp->number); |
d5551862 | 15754 | |
8cdf0e15 | 15755 | if (!create_breakpoint (get_current_arch (), |
409873ef | 15756 | addr_str, |
e7e0cddf SS |
15757 | utp->cond_string, -1, NULL, |
15758 | 0 /* parse cond/thread */, | |
8cdf0e15 | 15759 | 0 /* tempflag */, |
0fb4aa4b | 15760 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15761 | 0 /* Ignore count */, |
15762 | pending_break_support, | |
348d480f | 15763 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15764 | 0 /* from_tty */, |
84f4c1fe | 15765 | utp->enabled /* enabled */, |
44f238bb PA |
15766 | 0 /* internal */, |
15767 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
15768 | return NULL; |
15769 | ||
409873ef | 15770 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15771 | tp = get_tracepoint (tracepoint_count); |
15772 | gdb_assert (tp != NULL); | |
d5551862 | 15773 | |
00bf0b85 SS |
15774 | if (utp->pass > 0) |
15775 | { | |
8c042590 PM |
15776 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15777 | tp->base.number); | |
00bf0b85 | 15778 | |
409873ef | 15779 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15780 | } |
15781 | ||
409873ef SS |
15782 | /* If we have uploaded versions of the original commands, set up a |
15783 | special-purpose "reader" function and call the usual command line | |
15784 | reader, then pass the result to the breakpoint command-setting | |
15785 | function. */ | |
3149d8c1 | 15786 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15787 | { |
409873ef | 15788 | struct command_line *cmd_list; |
00bf0b85 | 15789 | |
409873ef | 15790 | this_utp = utp; |
3149d8c1 | 15791 | next_cmd = 0; |
d5551862 | 15792 | |
409873ef SS |
15793 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15794 | ||
d9b3f62e | 15795 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15796 | } |
3149d8c1 SS |
15797 | else if (!VEC_empty (char_ptr, utp->actions) |
15798 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15799 | warning (_("Uploaded tracepoint %d actions " |
15800 | "have no source form, ignoring them"), | |
409873ef | 15801 | utp->number); |
00bf0b85 | 15802 | |
f196051f SS |
15803 | /* Copy any status information that might be available. */ |
15804 | tp->base.hit_count = utp->hit_count; | |
15805 | tp->traceframe_usage = utp->traceframe_usage; | |
15806 | ||
00bf0b85 | 15807 | return tp; |
d9b3f62e | 15808 | } |
00bf0b85 | 15809 | |
1042e4c0 SS |
15810 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15811 | omitted. */ | |
15812 | ||
15813 | static void | |
e5a67952 | 15814 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15815 | { |
79a45e25 | 15816 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15817 | int num_printed; |
1042e4c0 | 15818 | |
e5a67952 | 15819 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15820 | |
15821 | if (num_printed == 0) | |
1042e4c0 | 15822 | { |
e5a67952 | 15823 | if (args == NULL || *args == '\0') |
d77f58be SS |
15824 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15825 | else | |
e5a67952 | 15826 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15827 | } |
ad443146 SS |
15828 | |
15829 | default_collect_info (); | |
1042e4c0 SS |
15830 | } |
15831 | ||
4a64f543 | 15832 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15833 | Not supported by all targets. */ |
15834 | static void | |
15835 | enable_trace_command (char *args, int from_tty) | |
15836 | { | |
15837 | enable_command (args, from_tty); | |
15838 | } | |
15839 | ||
4a64f543 | 15840 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15841 | Not supported by all targets. */ |
15842 | static void | |
15843 | disable_trace_command (char *args, int from_tty) | |
15844 | { | |
15845 | disable_command (args, from_tty); | |
15846 | } | |
15847 | ||
4a64f543 | 15848 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15849 | static void |
15850 | delete_trace_command (char *arg, int from_tty) | |
15851 | { | |
35df4500 | 15852 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15853 | |
15854 | dont_repeat (); | |
15855 | ||
15856 | if (arg == 0) | |
15857 | { | |
15858 | int breaks_to_delete = 0; | |
15859 | ||
15860 | /* Delete all breakpoints if no argument. | |
15861 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15862 | have to be deleted with an explicit breakpoint number |
15863 | argument. */ | |
1042e4c0 | 15864 | ALL_TRACEPOINTS (b) |
46c6471b | 15865 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15866 | { |
15867 | breaks_to_delete = 1; | |
15868 | break; | |
15869 | } | |
1042e4c0 SS |
15870 | |
15871 | /* Ask user only if there are some breakpoints to delete. */ | |
15872 | if (!from_tty | |
15873 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15874 | { | |
35df4500 | 15875 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15876 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15877 | delete_breakpoint (b); |
1042e4c0 SS |
15878 | } |
15879 | } | |
15880 | else | |
51be5b68 | 15881 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15882 | } |
15883 | ||
197f0a60 TT |
15884 | /* Helper function for trace_pass_command. */ |
15885 | ||
15886 | static void | |
d9b3f62e | 15887 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15888 | { |
d9b3f62e | 15889 | tp->pass_count = count; |
6f6484cd | 15890 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15891 | if (from_tty) |
15892 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15893 | tp->base.number, count); |
197f0a60 TT |
15894 | } |
15895 | ||
1042e4c0 SS |
15896 | /* Set passcount for tracepoint. |
15897 | ||
15898 | First command argument is passcount, second is tracepoint number. | |
15899 | If tracepoint number omitted, apply to most recently defined. | |
15900 | Also accepts special argument "all". */ | |
15901 | ||
15902 | static void | |
15903 | trace_pass_command (char *args, int from_tty) | |
15904 | { | |
d9b3f62e | 15905 | struct tracepoint *t1; |
1042e4c0 | 15906 | unsigned int count; |
1042e4c0 SS |
15907 | |
15908 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15909 | error (_("passcount command requires an " |
15910 | "argument (count + optional TP num)")); | |
1042e4c0 | 15911 | |
4a64f543 | 15912 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15913 | |
529480d0 | 15914 | args = skip_spaces (args); |
1042e4c0 SS |
15915 | if (*args && strncasecmp (args, "all", 3) == 0) |
15916 | { | |
d9b3f62e PA |
15917 | struct breakpoint *b; |
15918 | ||
1042e4c0 | 15919 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15920 | if (*args) |
15921 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15922 | |
d9b3f62e | 15923 | ALL_TRACEPOINTS (b) |
197f0a60 | 15924 | { |
d9b3f62e | 15925 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15926 | trace_pass_set_count (t1, count, from_tty); |
15927 | } | |
15928 | } | |
15929 | else if (*args == '\0') | |
1042e4c0 | 15930 | { |
5fa1d40e | 15931 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15932 | if (t1) |
197f0a60 TT |
15933 | trace_pass_set_count (t1, count, from_tty); |
15934 | } | |
15935 | else | |
15936 | { | |
15937 | struct get_number_or_range_state state; | |
15938 | ||
15939 | init_number_or_range (&state, args); | |
15940 | while (!state.finished) | |
1042e4c0 | 15941 | { |
5fa1d40e | 15942 | t1 = get_tracepoint_by_number (&args, &state); |
197f0a60 TT |
15943 | if (t1) |
15944 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15945 | } |
15946 | } | |
1042e4c0 SS |
15947 | } |
15948 | ||
d9b3f62e | 15949 | struct tracepoint * |
1042e4c0 SS |
15950 | get_tracepoint (int num) |
15951 | { | |
15952 | struct breakpoint *t; | |
15953 | ||
15954 | ALL_TRACEPOINTS (t) | |
15955 | if (t->number == num) | |
d9b3f62e | 15956 | return (struct tracepoint *) t; |
1042e4c0 SS |
15957 | |
15958 | return NULL; | |
15959 | } | |
15960 | ||
d5551862 SS |
15961 | /* Find the tracepoint with the given target-side number (which may be |
15962 | different from the tracepoint number after disconnecting and | |
15963 | reconnecting). */ | |
15964 | ||
d9b3f62e | 15965 | struct tracepoint * |
d5551862 SS |
15966 | get_tracepoint_by_number_on_target (int num) |
15967 | { | |
d9b3f62e | 15968 | struct breakpoint *b; |
d5551862 | 15969 | |
d9b3f62e PA |
15970 | ALL_TRACEPOINTS (b) |
15971 | { | |
15972 | struct tracepoint *t = (struct tracepoint *) b; | |
15973 | ||
15974 | if (t->number_on_target == num) | |
15975 | return t; | |
15976 | } | |
d5551862 SS |
15977 | |
15978 | return NULL; | |
15979 | } | |
15980 | ||
1042e4c0 | 15981 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15982 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15983 | If the argument is missing, the most recent tracepoint |
15984 | (tracepoint_count) is returned. */ | |
15985 | ||
d9b3f62e | 15986 | struct tracepoint * |
197f0a60 | 15987 | get_tracepoint_by_number (char **arg, |
5fa1d40e | 15988 | struct get_number_or_range_state *state) |
1042e4c0 | 15989 | { |
1042e4c0 SS |
15990 | struct breakpoint *t; |
15991 | int tpnum; | |
15992 | char *instring = arg == NULL ? NULL : *arg; | |
15993 | ||
197f0a60 TT |
15994 | if (state) |
15995 | { | |
15996 | gdb_assert (!state->finished); | |
15997 | tpnum = get_number_or_range (state); | |
15998 | } | |
15999 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 16000 | tpnum = tracepoint_count; |
1042e4c0 | 16001 | else |
197f0a60 | 16002 | tpnum = get_number (arg); |
1042e4c0 SS |
16003 | |
16004 | if (tpnum <= 0) | |
16005 | { | |
16006 | if (instring && *instring) | |
16007 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
16008 | instring); | |
16009 | else | |
5fa1d40e | 16010 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
16011 | return NULL; |
16012 | } | |
16013 | ||
16014 | ALL_TRACEPOINTS (t) | |
16015 | if (t->number == tpnum) | |
16016 | { | |
d9b3f62e | 16017 | return (struct tracepoint *) t; |
1042e4c0 SS |
16018 | } |
16019 | ||
1042e4c0 SS |
16020 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
16021 | return NULL; | |
16022 | } | |
16023 | ||
d9b3f62e PA |
16024 | void |
16025 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
16026 | { | |
16027 | if (b->thread != -1) | |
16028 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
16029 | ||
16030 | if (b->task != 0) | |
16031 | fprintf_unfiltered (fp, " task %d", b->task); | |
16032 | ||
16033 | fprintf_unfiltered (fp, "\n"); | |
16034 | } | |
16035 | ||
6149aea9 PA |
16036 | /* Save information on user settable breakpoints (watchpoints, etc) to |
16037 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
16038 | on each breakpoint and only include the ones for which it returns | |
16039 | non-zero. */ | |
16040 | ||
1042e4c0 | 16041 | static void |
6149aea9 PA |
16042 | save_breakpoints (char *filename, int from_tty, |
16043 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
16044 | { |
16045 | struct breakpoint *tp; | |
6149aea9 | 16046 | int any = 0; |
1042e4c0 | 16047 | struct cleanup *cleanup; |
a7bdde9e | 16048 | struct ui_file *fp; |
6149aea9 | 16049 | int extra_trace_bits = 0; |
1042e4c0 | 16050 | |
6149aea9 PA |
16051 | if (filename == 0 || *filename == 0) |
16052 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
16053 | |
16054 | /* See if we have anything to save. */ | |
6149aea9 | 16055 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 16056 | { |
6149aea9 | 16057 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 16058 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
16059 | continue; |
16060 | ||
16061 | /* If we have a filter, only save the breakpoints it accepts. */ | |
16062 | if (filter && !filter (tp)) | |
16063 | continue; | |
16064 | ||
16065 | any = 1; | |
16066 | ||
16067 | if (is_tracepoint (tp)) | |
16068 | { | |
16069 | extra_trace_bits = 1; | |
16070 | ||
16071 | /* We can stop searching. */ | |
16072 | break; | |
16073 | } | |
1042e4c0 | 16074 | } |
6149aea9 PA |
16075 | |
16076 | if (!any) | |
1042e4c0 | 16077 | { |
6149aea9 | 16078 | warning (_("Nothing to save.")); |
1042e4c0 SS |
16079 | return; |
16080 | } | |
16081 | ||
c718be47 PA |
16082 | filename = tilde_expand (filename); |
16083 | cleanup = make_cleanup (xfree, filename); | |
16084 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 16085 | if (!fp) |
6149aea9 PA |
16086 | error (_("Unable to open file '%s' for saving (%s)"), |
16087 | filename, safe_strerror (errno)); | |
a7bdde9e | 16088 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 16089 | |
6149aea9 PA |
16090 | if (extra_trace_bits) |
16091 | save_trace_state_variables (fp); | |
8bf6485c | 16092 | |
6149aea9 | 16093 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 16094 | { |
6149aea9 | 16095 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 16096 | if (!user_breakpoint_p (tp)) |
6149aea9 | 16097 | continue; |
8bf6485c | 16098 | |
6149aea9 PA |
16099 | /* If we have a filter, only save the breakpoints it accepts. */ |
16100 | if (filter && !filter (tp)) | |
16101 | continue; | |
16102 | ||
348d480f | 16103 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 16104 | |
6149aea9 PA |
16105 | /* Note, we can't rely on tp->number for anything, as we can't |
16106 | assume the recreated breakpoint numbers will match. Use $bpnum | |
16107 | instead. */ | |
16108 | ||
16109 | if (tp->cond_string) | |
16110 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
16111 | ||
16112 | if (tp->ignore_count) | |
16113 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
16114 | ||
2d9442cc | 16115 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 16116 | { |
a7bdde9e VP |
16117 | volatile struct gdb_exception ex; |
16118 | ||
6149aea9 | 16119 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 16120 | |
79a45e25 | 16121 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 16122 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 16123 | { |
79a45e25 | 16124 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 16125 | } |
79a45e25 | 16126 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 16127 | |
a7bdde9e VP |
16128 | if (ex.reason < 0) |
16129 | throw_exception (ex); | |
1042e4c0 | 16130 | |
a7bdde9e | 16131 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 16132 | } |
6149aea9 PA |
16133 | |
16134 | if (tp->enable_state == bp_disabled) | |
99894e11 | 16135 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
6149aea9 PA |
16136 | |
16137 | /* If this is a multi-location breakpoint, check if the locations | |
16138 | should be individually disabled. Watchpoint locations are | |
16139 | special, and not user visible. */ | |
16140 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
16141 | { | |
16142 | struct bp_location *loc; | |
16143 | int n = 1; | |
16144 | ||
16145 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
16146 | if (!loc->enabled) | |
16147 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
16148 | } | |
1042e4c0 | 16149 | } |
8bf6485c | 16150 | |
6149aea9 | 16151 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
16152 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
16153 | ||
1042e4c0 | 16154 | if (from_tty) |
6149aea9 | 16155 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 16156 | do_cleanups (cleanup); |
6149aea9 PA |
16157 | } |
16158 | ||
16159 | /* The `save breakpoints' command. */ | |
16160 | ||
16161 | static void | |
16162 | save_breakpoints_command (char *args, int from_tty) | |
16163 | { | |
16164 | save_breakpoints (args, from_tty, NULL); | |
16165 | } | |
16166 | ||
16167 | /* The `save tracepoints' command. */ | |
16168 | ||
16169 | static void | |
16170 | save_tracepoints_command (char *args, int from_tty) | |
16171 | { | |
16172 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
16173 | } |
16174 | ||
16175 | /* Create a vector of all tracepoints. */ | |
16176 | ||
16177 | VEC(breakpoint_p) * | |
eeae04df | 16178 | all_tracepoints (void) |
1042e4c0 SS |
16179 | { |
16180 | VEC(breakpoint_p) *tp_vec = 0; | |
16181 | struct breakpoint *tp; | |
16182 | ||
16183 | ALL_TRACEPOINTS (tp) | |
16184 | { | |
16185 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
16186 | } | |
16187 | ||
16188 | return tp_vec; | |
16189 | } | |
16190 | ||
c906108c | 16191 | \f |
4a64f543 MS |
16192 | /* This help string is used for the break, hbreak, tbreak and thbreak |
16193 | commands. It is defined as a macro to prevent duplication. | |
16194 | COMMAND should be a string constant containing the name of the | |
16195 | command. */ | |
31e2b00f | 16196 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
16197 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
16198 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
16199 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
16200 | guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\ | |
31e2b00f AS |
16201 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
16202 | If a line number is specified, break at start of code for that line.\n\ | |
16203 | If a function is specified, break at start of code for that function.\n\ | |
16204 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
16205 | With no LOCATION, uses current execution address of the selected\n\ |
16206 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
16207 | \n\ |
16208 | THREADNUM is the number from \"info threads\".\n\ | |
16209 | CONDITION is a boolean expression.\n\ | |
16210 | \n\ | |
d41c0fc8 PA |
16211 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
16212 | conditions are different.\n\ | |
31e2b00f AS |
16213 | \n\ |
16214 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
16215 | ||
44feb3ce TT |
16216 | /* List of subcommands for "catch". */ |
16217 | static struct cmd_list_element *catch_cmdlist; | |
16218 | ||
16219 | /* List of subcommands for "tcatch". */ | |
16220 | static struct cmd_list_element *tcatch_cmdlist; | |
16221 | ||
9ac4176b | 16222 | void |
44feb3ce | 16223 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 16224 | cmd_sfunc_ftype *sfunc, |
625e8578 | 16225 | completer_ftype *completer, |
44feb3ce TT |
16226 | void *user_data_catch, |
16227 | void *user_data_tcatch) | |
16228 | { | |
16229 | struct cmd_list_element *command; | |
16230 | ||
16231 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
16232 | &catch_cmdlist); | |
16233 | set_cmd_sfunc (command, sfunc); | |
16234 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 16235 | set_cmd_completer (command, completer); |
44feb3ce TT |
16236 | |
16237 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
16238 | &tcatch_cmdlist); | |
16239 | set_cmd_sfunc (command, sfunc); | |
16240 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 16241 | set_cmd_completer (command, completer); |
44feb3ce TT |
16242 | } |
16243 | ||
6c95b8df | 16244 | static void |
a79b8f6e | 16245 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 16246 | { |
fa3064dd YQ |
16247 | struct catch_syscall_inferior_data *inf_data |
16248 | = get_catch_syscall_inferior_data (inf); | |
16249 | ||
16250 | inf_data->total_syscalls_count = 0; | |
16251 | inf_data->any_syscall_count = 0; | |
16252 | VEC_free (int, inf_data->syscalls_counts); | |
6c95b8df PA |
16253 | } |
16254 | ||
6149aea9 PA |
16255 | static void |
16256 | save_command (char *arg, int from_tty) | |
16257 | { | |
3e43a32a MS |
16258 | printf_unfiltered (_("\"save\" must be followed by " |
16259 | "the name of a save subcommand.\n")); | |
635c7e8a | 16260 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
16261 | } |
16262 | ||
84f4c1fe PM |
16263 | struct breakpoint * |
16264 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
16265 | void *data) | |
16266 | { | |
35df4500 | 16267 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 16268 | |
35df4500 | 16269 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
16270 | { |
16271 | if ((*callback) (b, data)) | |
16272 | return b; | |
16273 | } | |
16274 | ||
16275 | return NULL; | |
16276 | } | |
16277 | ||
0574c78f GB |
16278 | /* Zero if any of the breakpoint's locations could be a location where |
16279 | functions have been inlined, nonzero otherwise. */ | |
16280 | ||
16281 | static int | |
16282 | is_non_inline_function (struct breakpoint *b) | |
16283 | { | |
16284 | /* The shared library event breakpoint is set on the address of a | |
16285 | non-inline function. */ | |
16286 | if (b->type == bp_shlib_event) | |
16287 | return 1; | |
16288 | ||
16289 | return 0; | |
16290 | } | |
16291 | ||
16292 | /* Nonzero if the specified PC cannot be a location where functions | |
16293 | have been inlined. */ | |
16294 | ||
16295 | int | |
09ac7c10 TT |
16296 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
16297 | const struct target_waitstatus *ws) | |
0574c78f GB |
16298 | { |
16299 | struct breakpoint *b; | |
16300 | struct bp_location *bl; | |
16301 | ||
16302 | ALL_BREAKPOINTS (b) | |
16303 | { | |
16304 | if (!is_non_inline_function (b)) | |
16305 | continue; | |
16306 | ||
16307 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
16308 | { | |
16309 | if (!bl->shlib_disabled | |
09ac7c10 | 16310 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
16311 | return 1; |
16312 | } | |
16313 | } | |
16314 | ||
16315 | return 0; | |
16316 | } | |
16317 | ||
2f202fde JK |
16318 | /* Remove any references to OBJFILE which is going to be freed. */ |
16319 | ||
16320 | void | |
16321 | breakpoint_free_objfile (struct objfile *objfile) | |
16322 | { | |
16323 | struct bp_location **locp, *loc; | |
16324 | ||
16325 | ALL_BP_LOCATIONS (loc, locp) | |
16326 | if (loc->symtab != NULL && loc->symtab->objfile == objfile) | |
16327 | loc->symtab = NULL; | |
16328 | } | |
16329 | ||
2060206e PA |
16330 | void |
16331 | initialize_breakpoint_ops (void) | |
16332 | { | |
16333 | static int initialized = 0; | |
16334 | ||
16335 | struct breakpoint_ops *ops; | |
16336 | ||
16337 | if (initialized) | |
16338 | return; | |
16339 | initialized = 1; | |
16340 | ||
16341 | /* The breakpoint_ops structure to be inherit by all kinds of | |
16342 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
16343 | internal and momentary breakpoints, etc.). */ | |
16344 | ops = &bkpt_base_breakpoint_ops; | |
16345 | *ops = base_breakpoint_ops; | |
16346 | ops->re_set = bkpt_re_set; | |
16347 | ops->insert_location = bkpt_insert_location; | |
16348 | ops->remove_location = bkpt_remove_location; | |
16349 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
16350 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
16351 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
16352 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
16353 | |
16354 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
16355 | ops = &bkpt_breakpoint_ops; | |
16356 | *ops = bkpt_base_breakpoint_ops; | |
16357 | ops->re_set = bkpt_re_set; | |
16358 | ops->resources_needed = bkpt_resources_needed; | |
16359 | ops->print_it = bkpt_print_it; | |
16360 | ops->print_mention = bkpt_print_mention; | |
16361 | ops->print_recreate = bkpt_print_recreate; | |
16362 | ||
16363 | /* Ranged breakpoints. */ | |
16364 | ops = &ranged_breakpoint_ops; | |
16365 | *ops = bkpt_breakpoint_ops; | |
16366 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
16367 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
16368 | ops->print_it = print_it_ranged_breakpoint; | |
16369 | ops->print_one = print_one_ranged_breakpoint; | |
16370 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
16371 | ops->print_mention = print_mention_ranged_breakpoint; | |
16372 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
16373 | ||
16374 | /* Internal breakpoints. */ | |
16375 | ops = &internal_breakpoint_ops; | |
16376 | *ops = bkpt_base_breakpoint_ops; | |
16377 | ops->re_set = internal_bkpt_re_set; | |
16378 | ops->check_status = internal_bkpt_check_status; | |
16379 | ops->print_it = internal_bkpt_print_it; | |
16380 | ops->print_mention = internal_bkpt_print_mention; | |
16381 | ||
16382 | /* Momentary breakpoints. */ | |
16383 | ops = &momentary_breakpoint_ops; | |
16384 | *ops = bkpt_base_breakpoint_ops; | |
16385 | ops->re_set = momentary_bkpt_re_set; | |
16386 | ops->check_status = momentary_bkpt_check_status; | |
16387 | ops->print_it = momentary_bkpt_print_it; | |
16388 | ops->print_mention = momentary_bkpt_print_mention; | |
16389 | ||
e2e4d78b JK |
16390 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
16391 | ops = &longjmp_breakpoint_ops; | |
16392 | *ops = momentary_breakpoint_ops; | |
16393 | ops->dtor = longjmp_bkpt_dtor; | |
16394 | ||
55aa24fb SDJ |
16395 | /* Probe breakpoints. */ |
16396 | ops = &bkpt_probe_breakpoint_ops; | |
16397 | *ops = bkpt_breakpoint_ops; | |
16398 | ops->insert_location = bkpt_probe_insert_location; | |
16399 | ops->remove_location = bkpt_probe_remove_location; | |
16400 | ops->create_sals_from_address = bkpt_probe_create_sals_from_address; | |
16401 | ops->decode_linespec = bkpt_probe_decode_linespec; | |
16402 | ||
2060206e PA |
16403 | /* Watchpoints. */ |
16404 | ops = &watchpoint_breakpoint_ops; | |
16405 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 16406 | ops->dtor = dtor_watchpoint; |
2060206e PA |
16407 | ops->re_set = re_set_watchpoint; |
16408 | ops->insert_location = insert_watchpoint; | |
16409 | ops->remove_location = remove_watchpoint; | |
16410 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
16411 | ops->check_status = check_status_watchpoint; | |
16412 | ops->resources_needed = resources_needed_watchpoint; | |
16413 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
16414 | ops->print_it = print_it_watchpoint; | |
16415 | ops->print_mention = print_mention_watchpoint; | |
16416 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 16417 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
16418 | |
16419 | /* Masked watchpoints. */ | |
16420 | ops = &masked_watchpoint_breakpoint_ops; | |
16421 | *ops = watchpoint_breakpoint_ops; | |
16422 | ops->insert_location = insert_masked_watchpoint; | |
16423 | ops->remove_location = remove_masked_watchpoint; | |
16424 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16425 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16426 | ops->print_it = print_it_masked_watchpoint; | |
16427 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16428 | ops->print_mention = print_mention_masked_watchpoint; | |
16429 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16430 | ||
16431 | /* Tracepoints. */ | |
16432 | ops = &tracepoint_breakpoint_ops; | |
16433 | *ops = base_breakpoint_ops; | |
16434 | ops->re_set = tracepoint_re_set; | |
16435 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16436 | ops->print_one_detail = tracepoint_print_one_detail; | |
16437 | ops->print_mention = tracepoint_print_mention; | |
16438 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
16439 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
16440 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
16441 | ops->decode_linespec = tracepoint_decode_linespec; | |
16442 | ||
55aa24fb SDJ |
16443 | /* Probe tracepoints. */ |
16444 | ops = &tracepoint_probe_breakpoint_ops; | |
16445 | *ops = tracepoint_breakpoint_ops; | |
16446 | ops->create_sals_from_address = tracepoint_probe_create_sals_from_address; | |
16447 | ops->decode_linespec = tracepoint_probe_decode_linespec; | |
16448 | ||
983af33b SDJ |
16449 | /* Static tracepoints with marker (`-m'). */ |
16450 | ops = &strace_marker_breakpoint_ops; | |
16451 | *ops = tracepoint_breakpoint_ops; | |
16452 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
16453 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
16454 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
16455 | |
16456 | /* Fork catchpoints. */ | |
16457 | ops = &catch_fork_breakpoint_ops; | |
16458 | *ops = base_breakpoint_ops; | |
16459 | ops->insert_location = insert_catch_fork; | |
16460 | ops->remove_location = remove_catch_fork; | |
16461 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16462 | ops->print_it = print_it_catch_fork; | |
16463 | ops->print_one = print_one_catch_fork; | |
16464 | ops->print_mention = print_mention_catch_fork; | |
16465 | ops->print_recreate = print_recreate_catch_fork; | |
16466 | ||
16467 | /* Vfork catchpoints. */ | |
16468 | ops = &catch_vfork_breakpoint_ops; | |
16469 | *ops = base_breakpoint_ops; | |
16470 | ops->insert_location = insert_catch_vfork; | |
16471 | ops->remove_location = remove_catch_vfork; | |
16472 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16473 | ops->print_it = print_it_catch_vfork; | |
16474 | ops->print_one = print_one_catch_vfork; | |
16475 | ops->print_mention = print_mention_catch_vfork; | |
16476 | ops->print_recreate = print_recreate_catch_vfork; | |
16477 | ||
16478 | /* Exec catchpoints. */ | |
16479 | ops = &catch_exec_breakpoint_ops; | |
16480 | *ops = base_breakpoint_ops; | |
16481 | ops->dtor = dtor_catch_exec; | |
16482 | ops->insert_location = insert_catch_exec; | |
16483 | ops->remove_location = remove_catch_exec; | |
16484 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16485 | ops->print_it = print_it_catch_exec; | |
16486 | ops->print_one = print_one_catch_exec; | |
16487 | ops->print_mention = print_mention_catch_exec; | |
16488 | ops->print_recreate = print_recreate_catch_exec; | |
16489 | ||
16490 | /* Syscall catchpoints. */ | |
16491 | ops = &catch_syscall_breakpoint_ops; | |
16492 | *ops = base_breakpoint_ops; | |
16493 | ops->dtor = dtor_catch_syscall; | |
16494 | ops->insert_location = insert_catch_syscall; | |
16495 | ops->remove_location = remove_catch_syscall; | |
16496 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
16497 | ops->print_it = print_it_catch_syscall; | |
16498 | ops->print_one = print_one_catch_syscall; | |
16499 | ops->print_mention = print_mention_catch_syscall; | |
16500 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
16501 | |
16502 | /* Solib-related catchpoints. */ | |
16503 | ops = &catch_solib_breakpoint_ops; | |
16504 | *ops = base_breakpoint_ops; | |
16505 | ops->dtor = dtor_catch_solib; | |
16506 | ops->insert_location = insert_catch_solib; | |
16507 | ops->remove_location = remove_catch_solib; | |
16508 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16509 | ops->check_status = check_status_catch_solib; | |
16510 | ops->print_it = print_it_catch_solib; | |
16511 | ops->print_one = print_one_catch_solib; | |
16512 | ops->print_mention = print_mention_catch_solib; | |
16513 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16514 | |
16515 | ops = &dprintf_breakpoint_ops; | |
16516 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16517 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16518 | ops->resources_needed = bkpt_resources_needed; |
16519 | ops->print_it = bkpt_print_it; | |
16520 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16521 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16522 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 16523 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
16524 | } |
16525 | ||
8bfd80db YQ |
16526 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16527 | ||
16528 | static struct cmd_list_element *enablebreaklist = NULL; | |
16529 | ||
c906108c | 16530 | void |
fba45db2 | 16531 | _initialize_breakpoint (void) |
c906108c SS |
16532 | { |
16533 | struct cmd_list_element *c; | |
16534 | ||
2060206e PA |
16535 | initialize_breakpoint_ops (); |
16536 | ||
84acb35a | 16537 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16538 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
6c95b8df | 16539 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 16540 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16541 | |
55aa24fb SDJ |
16542 | breakpoint_objfile_key |
16543 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16544 | |
fa3064dd | 16545 | catch_syscall_inferior_data |
8e260fc0 TT |
16546 | = register_inferior_data_with_cleanup (NULL, |
16547 | catch_syscall_inferior_data_cleanup); | |
fa3064dd | 16548 | |
c906108c SS |
16549 | breakpoint_chain = 0; |
16550 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16551 | before a breakpoint is set. */ | |
16552 | breakpoint_count = 0; | |
16553 | ||
1042e4c0 SS |
16554 | tracepoint_count = 0; |
16555 | ||
1bedd215 AC |
16556 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16557 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16558 | Usage is `ignore N COUNT'.")); | |
c906108c | 16559 | if (xdb_commands) |
c5aa993b | 16560 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 16561 | |
1bedd215 AC |
16562 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16563 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16564 | Give breakpoint number as argument after \"commands\".\n\ |
16565 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16566 | The commands themselves follow starting on the next line.\n\ | |
16567 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16568 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16569 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16570 | |
d55637df | 16571 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16572 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16573 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16574 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16575 | set_cmd_completer (c, condition_completer); |
c906108c | 16576 | |
1bedd215 | 16577 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16578 | Set a temporary breakpoint.\n\ |
c906108c SS |
16579 | Like \"break\" except the breakpoint is only temporary,\n\ |
16580 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16581 | by using \"enable delete\" on the breakpoint number.\n\ |
16582 | \n" | |
16583 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16584 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16585 | |
1bedd215 | 16586 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16587 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16588 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16589 | some target hardware may not have this support.\n\ |
16590 | \n" | |
16591 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16592 | set_cmd_completer (c, location_completer); |
c906108c | 16593 | |
1bedd215 | 16594 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16595 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16596 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16597 | so it will be deleted when hit.\n\ |
16598 | \n" | |
16599 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16600 | set_cmd_completer (c, location_completer); |
c906108c | 16601 | |
1bedd215 AC |
16602 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16603 | Enable some breakpoints.\n\ | |
c906108c SS |
16604 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16605 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16606 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16607 | With a subcommand you can enable temporarily."), |
c906108c SS |
16608 | &enablelist, "enable ", 1, &cmdlist); |
16609 | if (xdb_commands) | |
1bedd215 AC |
16610 | add_com ("ab", class_breakpoint, enable_command, _("\ |
16611 | Enable some breakpoints.\n\ | |
c906108c SS |
16612 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16613 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16614 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16615 | With a subcommand you can enable temporarily.")); |
c906108c SS |
16616 | |
16617 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16618 | ||
84951ab5 | 16619 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16620 | Enable some breakpoints.\n\ |
c906108c SS |
16621 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16622 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16623 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16624 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16625 | |
1a966eab AC |
16626 | add_cmd ("once", no_class, enable_once_command, _("\ |
16627 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16628 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16629 | &enablebreaklist); |
16630 | ||
1a966eab AC |
16631 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16632 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16633 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16634 | &enablebreaklist); |
16635 | ||
816338b5 SS |
16636 | add_cmd ("count", no_class, enable_count_command, _("\ |
16637 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16638 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16639 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16640 | &enablebreaklist); | |
16641 | ||
1a966eab AC |
16642 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16643 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16644 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16645 | &enablelist); |
16646 | ||
1a966eab AC |
16647 | add_cmd ("once", no_class, enable_once_command, _("\ |
16648 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16649 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16650 | &enablelist); |
16651 | ||
16652 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16653 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16654 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16655 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16656 | &enablelist); |
16657 | ||
1bedd215 AC |
16658 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16659 | Disable some breakpoints.\n\ | |
c906108c SS |
16660 | Arguments are breakpoint numbers with spaces in between.\n\ |
16661 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16662 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16663 | &disablelist, "disable ", 1, &cmdlist); |
16664 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16665 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
16666 | if (xdb_commands) | |
1bedd215 AC |
16667 | add_com ("sb", class_breakpoint, disable_command, _("\ |
16668 | Disable some breakpoints.\n\ | |
c906108c SS |
16669 | Arguments are breakpoint numbers with spaces in between.\n\ |
16670 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16671 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 16672 | |
1a966eab AC |
16673 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16674 | Disable some breakpoints.\n\ | |
c906108c SS |
16675 | Arguments are breakpoint numbers with spaces in between.\n\ |
16676 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16677 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16678 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16679 | &disablelist); |
16680 | ||
1bedd215 AC |
16681 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16682 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16683 | Arguments are breakpoint numbers with spaces in between.\n\ |
16684 | To delete all breakpoints, give no argument.\n\ | |
16685 | \n\ | |
16686 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16687 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16688 | &deletelist, "delete ", 1, &cmdlist); |
16689 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16690 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16691 | if (xdb_commands) |
1bedd215 AC |
16692 | add_com ("db", class_breakpoint, delete_command, _("\ |
16693 | Delete some breakpoints.\n\ | |
c906108c | 16694 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 16695 | To delete all breakpoints, give no argument.\n")); |
c906108c | 16696 | |
1a966eab AC |
16697 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16698 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16699 | Arguments are breakpoint numbers with spaces in between.\n\ |
16700 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16701 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16702 | &deletelist); |
16703 | ||
1bedd215 AC |
16704 | add_com ("clear", class_breakpoint, clear_command, _("\ |
16705 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
16706 | Argument may be line number, function name, or \"*\" and an address.\n\ |
16707 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
16708 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
16709 | If an address is specified, breakpoints at that address are cleared.\n\ |
16710 | \n\ | |
16711 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
16712 | is executing in.\n\ |
16713 | \n\ | |
1bedd215 | 16714 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16715 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16716 | |
1bedd215 | 16717 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
16718 | Set breakpoint at specified line or function.\n" |
16719 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 16720 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16721 | |
c906108c SS |
16722 | add_com_alias ("b", "break", class_run, 1); |
16723 | add_com_alias ("br", "break", class_run, 1); | |
16724 | add_com_alias ("bre", "break", class_run, 1); | |
16725 | add_com_alias ("brea", "break", class_run, 1); | |
16726 | ||
7681d515 PM |
16727 | if (xdb_commands) |
16728 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
16729 | |
16730 | if (dbx_commands) | |
16731 | { | |
1bedd215 AC |
16732 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16733 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16734 | &stoplist, "stop ", 1, &cmdlist); |
16735 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16736 | _("Break in function or address."), &stoplist); |
c5aa993b | 16737 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16738 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16739 | add_com ("status", class_info, breakpoints_info, _("\ |
16740 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16741 | The \"Type\" column indicates one of:\n\ |
16742 | \tbreakpoint - normal breakpoint\n\ | |
16743 | \twatchpoint - watchpoint\n\ | |
16744 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16745 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16746 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16747 | address and file/line number respectively.\n\ |
16748 | \n\ | |
16749 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16750 | are set to the address of the last breakpoint listed unless the command\n\ |
16751 | is prefixed with \"server \".\n\n\ | |
c906108c | 16752 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16753 | breakpoint set.")); |
c906108c SS |
16754 | } |
16755 | ||
1bedd215 | 16756 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16757 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16758 | The \"Type\" column indicates one of:\n\ |
16759 | \tbreakpoint - normal breakpoint\n\ | |
16760 | \twatchpoint - watchpoint\n\ | |
16761 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16762 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16763 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16764 | address and file/line number respectively.\n\ |
16765 | \n\ | |
16766 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16767 | are set to the address of the last breakpoint listed unless the command\n\ |
16768 | is prefixed with \"server \".\n\n\ | |
c906108c | 16769 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16770 | breakpoint set.")); |
c906108c | 16771 | |
6b04bdb7 MS |
16772 | add_info_alias ("b", "breakpoints", 1); |
16773 | ||
c906108c | 16774 | if (xdb_commands) |
1bedd215 AC |
16775 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
16776 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16777 | The \"Type\" column indicates one of:\n\ |
16778 | \tbreakpoint - normal breakpoint\n\ | |
16779 | \twatchpoint - watchpoint\n\ | |
16780 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16781 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16782 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16783 | address and file/line number respectively.\n\ |
16784 | \n\ | |
16785 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16786 | are set to the address of the last breakpoint listed unless the command\n\ |
16787 | is prefixed with \"server \".\n\n\ | |
c906108c | 16788 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16789 | breakpoint set.")); |
c906108c | 16790 | |
1a966eab AC |
16791 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16792 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16793 | The \"Type\" column indicates one of:\n\ |
16794 | \tbreakpoint - normal breakpoint\n\ | |
16795 | \twatchpoint - watchpoint\n\ | |
16796 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16797 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16798 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16799 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16800 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16801 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16802 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16803 | address and file/line number respectively.\n\ |
16804 | \n\ | |
16805 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16806 | are set to the address of the last breakpoint listed unless the command\n\ |
16807 | is prefixed with \"server \".\n\n\ | |
c906108c | 16808 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16809 | breakpoint set."), |
c906108c SS |
16810 | &maintenanceinfolist); |
16811 | ||
44feb3ce TT |
16812 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16813 | Set catchpoints to catch events."), | |
16814 | &catch_cmdlist, "catch ", | |
16815 | 0/*allow-unknown*/, &cmdlist); | |
16816 | ||
16817 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16818 | Set temporary catchpoints to catch events."), | |
16819 | &tcatch_cmdlist, "tcatch ", | |
16820 | 0/*allow-unknown*/, &cmdlist); | |
16821 | ||
44feb3ce TT |
16822 | add_catch_command ("fork", _("Catch calls to fork."), |
16823 | catch_fork_command_1, | |
a96d9b2e | 16824 | NULL, |
44feb3ce TT |
16825 | (void *) (uintptr_t) catch_fork_permanent, |
16826 | (void *) (uintptr_t) catch_fork_temporary); | |
16827 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16828 | catch_fork_command_1, | |
a96d9b2e | 16829 | NULL, |
44feb3ce TT |
16830 | (void *) (uintptr_t) catch_vfork_permanent, |
16831 | (void *) (uintptr_t) catch_vfork_temporary); | |
16832 | add_catch_command ("exec", _("Catch calls to exec."), | |
16833 | catch_exec_command_1, | |
a96d9b2e SDJ |
16834 | NULL, |
16835 | CATCH_PERMANENT, | |
16836 | CATCH_TEMPORARY); | |
edcc5120 TT |
16837 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16838 | Usage: catch load [REGEX]\n\ | |
16839 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16840 | catch_load_command_1, | |
16841 | NULL, | |
16842 | CATCH_PERMANENT, | |
16843 | CATCH_TEMPORARY); | |
16844 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16845 | Usage: catch unload [REGEX]\n\ | |
16846 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16847 | catch_unload_command_1, | |
16848 | NULL, | |
16849 | CATCH_PERMANENT, | |
16850 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
16851 | add_catch_command ("syscall", _("\ |
16852 | Catch system calls by their names and/or numbers.\n\ | |
16853 | Arguments say which system calls to catch. If no arguments\n\ | |
16854 | are given, every system call will be caught.\n\ | |
16855 | Arguments, if given, should be one or more system call names\n\ | |
16856 | (if your system supports that), or system call numbers."), | |
16857 | catch_syscall_command_1, | |
16858 | catch_syscall_completer, | |
44feb3ce TT |
16859 | CATCH_PERMANENT, |
16860 | CATCH_TEMPORARY); | |
c5aa993b | 16861 | |
1bedd215 AC |
16862 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16863 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16864 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16865 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16866 | an expression changes.\n\ |
16867 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16868 | the memory to which it refers.")); | |
65d12d83 | 16869 | set_cmd_completer (c, expression_completer); |
c906108c | 16870 | |
1bedd215 AC |
16871 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16872 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16873 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16874 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16875 | an expression is read.\n\ |
16876 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16877 | the memory to which it refers.")); | |
65d12d83 | 16878 | set_cmd_completer (c, expression_completer); |
c906108c | 16879 | |
1bedd215 AC |
16880 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16881 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16882 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16883 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16884 | an expression is either read or written.\n\ |
16885 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16886 | the memory to which it refers.")); | |
65d12d83 | 16887 | set_cmd_completer (c, expression_completer); |
c906108c | 16888 | |
d77f58be | 16889 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16890 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16891 | |
920d2a44 AC |
16892 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16893 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16894 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16895 | &can_use_hw_watchpoints, _("\ | |
16896 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16897 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16898 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16899 | such is available. (However, any hardware watchpoints that were\n\ | |
16900 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16901 | hardware.)"), |
16902 | NULL, | |
920d2a44 | 16903 | show_can_use_hw_watchpoints, |
85c07804 | 16904 | &setlist, &showlist); |
c906108c SS |
16905 | |
16906 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16907 | |
1042e4c0 SS |
16908 | /* Tracepoint manipulation commands. */ |
16909 | ||
16910 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
16911 | Set a tracepoint at specified line or function.\n\ | |
16912 | \n" | |
16913 | BREAK_ARGS_HELP ("trace") "\n\ | |
16914 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16915 | set_cmd_completer (c, location_completer); | |
16916 | ||
16917 | add_com_alias ("tp", "trace", class_alias, 0); | |
16918 | add_com_alias ("tr", "trace", class_alias, 1); | |
16919 | add_com_alias ("tra", "trace", class_alias, 1); | |
16920 | add_com_alias ("trac", "trace", class_alias, 1); | |
16921 | ||
7a697b8d SS |
16922 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
16923 | Set a fast tracepoint at specified line or function.\n\ | |
16924 | \n" | |
16925 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16926 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16927 | set_cmd_completer (c, location_completer); | |
16928 | ||
0fb4aa4b PA |
16929 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
16930 | Set a static tracepoint at specified line, function or marker.\n\ | |
16931 | \n\ | |
16932 | strace [LOCATION] [if CONDITION]\n\ | |
16933 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
16934 | or -m MARKER_ID.\n\ | |
16935 | If a line number is specified, probe the marker at start of code\n\ | |
16936 | for that line. If a function is specified, probe the marker at start\n\ | |
16937 | of code for that function. If an address is specified, probe the marker\n\ | |
16938 | at that exact address. If a marker id is specified, probe the marker\n\ | |
16939 | with that name. With no LOCATION, uses current execution address of\n\ | |
16940 | the selected stack frame.\n\ | |
16941 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
16942 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16943 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16944 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16945 | \n\ | |
16946 | CONDITION is a boolean expression.\n\ | |
16947 | \n\ | |
d41c0fc8 PA |
16948 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16949 | conditions are different.\n\ | |
0fb4aa4b PA |
16950 | \n\ |
16951 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16952 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16953 | set_cmd_completer (c, location_completer); | |
16954 | ||
1042e4c0 | 16955 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16956 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16957 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16958 | last tracepoint set.")); | |
16959 | ||
16960 | add_info_alias ("tp", "tracepoints", 1); | |
16961 | ||
16962 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16963 | Delete specified tracepoints.\n\ | |
16964 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16965 | No argument means delete all tracepoints."), | |
16966 | &deletelist); | |
7e20dfcd | 16967 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16968 | |
16969 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16970 | Disable specified tracepoints.\n\ | |
16971 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16972 | No argument means disable all tracepoints."), | |
16973 | &disablelist); | |
16974 | deprecate_cmd (c, "disable"); | |
16975 | ||
16976 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16977 | Enable specified tracepoints.\n\ | |
16978 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16979 | No argument means enable all tracepoints."), | |
16980 | &enablelist); | |
16981 | deprecate_cmd (c, "enable"); | |
16982 | ||
16983 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16984 | Set the passcount for a tracepoint.\n\ | |
16985 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16986 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16987 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16988 | ||
6149aea9 PA |
16989 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16990 | _("Save breakpoint definitions as a script."), | |
16991 | &save_cmdlist, "save ", | |
16992 | 0/*allow-unknown*/, &cmdlist); | |
16993 | ||
16994 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16995 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16996 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16997 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16998 | session to restore them."), | |
16999 | &save_cmdlist); | |
17000 | set_cmd_completer (c, filename_completer); | |
17001 | ||
17002 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 17003 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
17004 | Use the 'source' command in another debug session to restore them."), |
17005 | &save_cmdlist); | |
1042e4c0 SS |
17006 | set_cmd_completer (c, filename_completer); |
17007 | ||
6149aea9 PA |
17008 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
17009 | deprecate_cmd (c, "save tracepoints"); | |
17010 | ||
1bedd215 | 17011 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
17012 | Breakpoint specific settings\n\ |
17013 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 17014 | pending breakpoint behavior"), |
fa8d40ab JJ |
17015 | &breakpoint_set_cmdlist, "set breakpoint ", |
17016 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 17017 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
17018 | Breakpoint specific settings\n\ |
17019 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 17020 | pending breakpoint behavior"), |
fa8d40ab JJ |
17021 | &breakpoint_show_cmdlist, "show breakpoint ", |
17022 | 0/*allow-unknown*/, &showlist); | |
17023 | ||
7915a72c AC |
17024 | add_setshow_auto_boolean_cmd ("pending", no_class, |
17025 | &pending_break_support, _("\ | |
17026 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
17027 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
17028 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
17029 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
17030 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 17031 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 17032 | NULL, |
920d2a44 | 17033 | show_pending_break_support, |
6e1d7d6c AC |
17034 | &breakpoint_set_cmdlist, |
17035 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
17036 | |
17037 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
17038 | |
17039 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
17040 | &automatic_hardware_breakpoints, _("\ | |
17041 | Set automatic usage of hardware breakpoints."), _("\ | |
17042 | Show automatic usage of hardware breakpoints."), _("\ | |
17043 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
17044 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
17045 | a warning will be emitted for such breakpoints."), | |
17046 | NULL, | |
17047 | show_automatic_hardware_breakpoints, | |
17048 | &breakpoint_set_cmdlist, | |
17049 | &breakpoint_show_cmdlist); | |
74960c60 | 17050 | |
a25a5a45 PA |
17051 | add_setshow_boolean_cmd ("always-inserted", class_support, |
17052 | &always_inserted_mode, _("\ | |
74960c60 VP |
17053 | Set mode for inserting breakpoints."), _("\ |
17054 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
17055 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
17056 | they're created, kept inserted even when execution stops, and removed\n\ | |
17057 | only when the user deletes them. When this mode is off (the default),\n\ | |
17058 | breakpoints are inserted only when execution continues, and removed\n\ | |
17059 | when execution stops."), | |
72d0e2c5 YQ |
17060 | NULL, |
17061 | &show_always_inserted_mode, | |
17062 | &breakpoint_set_cmdlist, | |
17063 | &breakpoint_show_cmdlist); | |
f1310107 | 17064 | |
b775012e LM |
17065 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
17066 | condition_evaluation_enums, | |
17067 | &condition_evaluation_mode_1, _("\ | |
17068 | Set mode of breakpoint condition evaluation."), _("\ | |
17069 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 17070 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
17071 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
17072 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
17073 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
17074 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
17075 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
17076 | be set to \"gdb\""), | |
17077 | &set_condition_evaluation_mode, | |
17078 | &show_condition_evaluation_mode, | |
17079 | &breakpoint_set_cmdlist, | |
17080 | &breakpoint_show_cmdlist); | |
17081 | ||
f1310107 TJB |
17082 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
17083 | Set a breakpoint for an address range.\n\ | |
17084 | break-range START-LOCATION, END-LOCATION\n\ | |
17085 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
17086 | LINENUM, for that line in the current file,\n\ | |
17087 | FILE:LINENUM, for that line in that file,\n\ | |
17088 | +OFFSET, for that number of lines after the current line\n\ | |
17089 | or the start of the range\n\ | |
17090 | FUNCTION, for the first line in that function,\n\ | |
17091 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
17092 | *ADDRESS, for the instruction at that address.\n\ | |
17093 | \n\ | |
17094 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
17095 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
17096 | range (including START-LOCATION and END-LOCATION).")); | |
17097 | ||
e7e0cddf SS |
17098 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
17099 | Set a dynamic printf at specified line or function.\n\ | |
17100 | dprintf location,format string,arg1,arg2,...\n\ | |
17101 | location may be a line number, function name, or \"*\" and an address.\n\ | |
17102 | If a line number is specified, break at start of code for that line.\n\ | |
0e4777df | 17103 | If a function is specified, break at start of code for that function.")); |
e7e0cddf SS |
17104 | set_cmd_completer (c, location_completer); |
17105 | ||
17106 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
17107 | dprintf_style_enums, &dprintf_style, _("\ | |
17108 | Set the style of usage for dynamic printf."), _("\ | |
17109 | Show the style of usage for dynamic printf."), _("\ | |
17110 | This setting chooses how GDB will do a dynamic printf.\n\ | |
17111 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
17112 | console, as with the \"printf\" command.\n\ | |
17113 | If the value is \"call\", the print is done by calling a function in your\n\ | |
17114 | program; by default printf(), but you can choose a different function or\n\ | |
17115 | output stream by setting dprintf-function and dprintf-channel."), | |
17116 | update_dprintf_commands, NULL, | |
17117 | &setlist, &showlist); | |
17118 | ||
17119 | dprintf_function = xstrdup ("printf"); | |
17120 | add_setshow_string_cmd ("dprintf-function", class_support, | |
17121 | &dprintf_function, _("\ | |
17122 | Set the function to use for dynamic printf"), _("\ | |
17123 | Show the function to use for dynamic printf"), NULL, | |
17124 | update_dprintf_commands, NULL, | |
17125 | &setlist, &showlist); | |
17126 | ||
17127 | dprintf_channel = xstrdup (""); | |
17128 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
17129 | &dprintf_channel, _("\ | |
17130 | Set the channel to use for dynamic printf"), _("\ | |
17131 | Show the channel to use for dynamic printf"), NULL, | |
17132 | update_dprintf_commands, NULL, | |
17133 | &setlist, &showlist); | |
17134 | ||
d3ce09f5 SS |
17135 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
17136 | &disconnected_dprintf, _("\ | |
17137 | Set whether dprintf continues after GDB disconnects."), _("\ | |
17138 | Show whether dprintf continues after GDB disconnects."), _("\ | |
17139 | Use this to let dprintf commands continue to hit and produce output\n\ | |
17140 | even if GDB disconnects or detaches from the target."), | |
17141 | NULL, | |
17142 | NULL, | |
17143 | &setlist, &showlist); | |
17144 | ||
17145 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
17146 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
17147 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
17148 | ||
765dc015 | 17149 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
17150 | |
17151 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 17152 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 17153 | } |