Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
32d0add0 | 3 | Copyright (C) 1986-2015 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
45741a9c | 35 | #include "infrun.h" |
c906108c SS |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
38 | #include "language.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
fe898f56 | 50 | #include "block.h" |
a77053c2 | 51 | #include "solib.h" |
84acb35a JJ |
52 | #include "solist.h" |
53 | #include "observer.h" | |
765dc015 | 54 | #include "memattr.h" |
f7f9143b | 55 | #include "ada-lang.h" |
d1aa2f50 | 56 | #include "top.h" |
79a45b7d | 57 | #include "valprint.h" |
4efc6507 | 58 | #include "jit.h" |
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 | |
fe3f5fa8 | 228 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
229 | static void incref_bp_location (struct bp_location *loc); |
230 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 231 | |
39d61571 | 232 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 233 | |
44702360 PA |
234 | /* update_global_location_list's modes of operation wrt to whether to |
235 | insert locations now. */ | |
236 | enum ugll_insert_mode | |
237 | { | |
238 | /* Don't insert any breakpoint locations into the inferior, only | |
239 | remove already-inserted locations that no longer should be | |
240 | inserted. Functions that delete a breakpoint or breakpoints | |
241 | should specify this mode, so that deleting a breakpoint doesn't | |
242 | have the side effect of inserting the locations of other | |
243 | breakpoints that are marked not-inserted, but should_be_inserted | |
244 | returns true on them. | |
245 | ||
246 | This behavior is useful is situations close to tear-down -- e.g., | |
247 | after an exec, while the target still has execution, but | |
248 | breakpoint shadows of the previous executable image should *NOT* | |
249 | be restored to the new image; or before detaching, where the | |
250 | target still has execution and wants to delete breakpoints from | |
251 | GDB's lists, and all breakpoints had already been removed from | |
252 | the inferior. */ | |
253 | UGLL_DONT_INSERT, | |
254 | ||
a25a5a45 PA |
255 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
256 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
257 | UGLL_MAY_INSERT, |
258 | ||
a25a5a45 PA |
259 | /* Insert locations now, irrespective of |
260 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
261 | stopped right now, and the user did "continue". We need to | |
262 | insert breakpoints _before_ resuming the target, but | |
263 | UGLL_MAY_INSERT wouldn't insert them, because | |
264 | breakpoints_should_be_inserted_now returns false at that point, | |
265 | as no thread is running yet. */ | |
04086b45 | 266 | UGLL_INSERT |
44702360 PA |
267 | }; |
268 | ||
269 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 270 | |
44702360 | 271 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 272 | |
d77f58be | 273 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
274 | |
275 | static void insert_breakpoint_locations (void); | |
a5606eee | 276 | |
a96d9b2e SDJ |
277 | static int syscall_catchpoint_p (struct breakpoint *b); |
278 | ||
1042e4c0 SS |
279 | static void tracepoints_info (char *, int); |
280 | ||
281 | static void delete_trace_command (char *, int); | |
282 | ||
283 | static void enable_trace_command (char *, int); | |
284 | ||
285 | static void disable_trace_command (char *, int); | |
286 | ||
287 | static void trace_pass_command (char *, int); | |
288 | ||
558a9d82 YQ |
289 | static void set_tracepoint_count (int num); |
290 | ||
9c06b0b4 TJB |
291 | static int is_masked_watchpoint (const struct breakpoint *b); |
292 | ||
b775012e LM |
293 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
294 | ||
983af33b SDJ |
295 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
296 | otherwise. */ | |
297 | ||
298 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 299 | |
2060206e PA |
300 | /* The abstract base class all breakpoint_ops structures inherit |
301 | from. */ | |
ab04a2af | 302 | struct breakpoint_ops base_breakpoint_ops; |
2060206e PA |
303 | |
304 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
305 | that are implemented on top of software or hardware breakpoints | |
306 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
307 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
308 | ||
309 | /* Internal breakpoints class type. */ | |
06edf0c0 | 310 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
311 | |
312 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
313 | static struct breakpoint_ops momentary_breakpoint_ops; |
314 | ||
e2e4d78b JK |
315 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
316 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
317 | ||
2060206e PA |
318 | /* The breakpoint_ops structure to be used in regular user created |
319 | breakpoints. */ | |
320 | struct breakpoint_ops bkpt_breakpoint_ops; | |
321 | ||
55aa24fb SDJ |
322 | /* Breakpoints set on probes. */ |
323 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
324 | ||
e7e0cddf | 325 | /* Dynamic printf class type. */ |
c5867ab6 | 326 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 327 | |
d3ce09f5 SS |
328 | /* The style in which to perform a dynamic printf. This is a user |
329 | option because different output options have different tradeoffs; | |
330 | if GDB does the printing, there is better error handling if there | |
331 | is a problem with any of the arguments, but using an inferior | |
332 | function lets you have special-purpose printers and sending of | |
333 | output to the same place as compiled-in print functions. */ | |
334 | ||
335 | static const char dprintf_style_gdb[] = "gdb"; | |
336 | static const char dprintf_style_call[] = "call"; | |
337 | static const char dprintf_style_agent[] = "agent"; | |
338 | static const char *const dprintf_style_enums[] = { | |
339 | dprintf_style_gdb, | |
340 | dprintf_style_call, | |
341 | dprintf_style_agent, | |
342 | NULL | |
343 | }; | |
344 | static const char *dprintf_style = dprintf_style_gdb; | |
345 | ||
346 | /* The function to use for dynamic printf if the preferred style is to | |
347 | call into the inferior. The value is simply a string that is | |
348 | copied into the command, so it can be anything that GDB can | |
349 | evaluate to a callable address, not necessarily a function name. */ | |
350 | ||
351 | static char *dprintf_function = ""; | |
352 | ||
353 | /* The channel to use for dynamic printf if the preferred style is to | |
354 | call into the inferior; if a nonempty string, it will be passed to | |
355 | the call as the first argument, with the format string as the | |
356 | second. As with the dprintf function, this can be anything that | |
357 | GDB knows how to evaluate, so in addition to common choices like | |
358 | "stderr", this could be an app-specific expression like | |
359 | "mystreams[curlogger]". */ | |
360 | ||
361 | static char *dprintf_channel = ""; | |
362 | ||
363 | /* True if dprintf commands should continue to operate even if GDB | |
364 | has disconnected. */ | |
365 | static int disconnected_dprintf = 1; | |
366 | ||
5cea2a26 PA |
367 | /* A reference-counted struct command_line. This lets multiple |
368 | breakpoints share a single command list. */ | |
369 | struct counted_command_line | |
370 | { | |
371 | /* The reference count. */ | |
372 | int refc; | |
373 | ||
374 | /* The command list. */ | |
375 | struct command_line *commands; | |
376 | }; | |
377 | ||
378 | struct command_line * | |
379 | breakpoint_commands (struct breakpoint *b) | |
380 | { | |
381 | return b->commands ? b->commands->commands : NULL; | |
382 | } | |
3daf8fe5 | 383 | |
f3b1572e PA |
384 | /* Flag indicating that a command has proceeded the inferior past the |
385 | current breakpoint. */ | |
386 | ||
387 | static int breakpoint_proceeded; | |
388 | ||
956a9fb9 | 389 | const char * |
2cec12e5 AR |
390 | bpdisp_text (enum bpdisp disp) |
391 | { | |
4a64f543 MS |
392 | /* NOTE: the following values are a part of MI protocol and |
393 | represent values of 'disp' field returned when inferior stops at | |
394 | a breakpoint. */ | |
bc043ef3 | 395 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 396 | |
2cec12e5 AR |
397 | return bpdisps[(int) disp]; |
398 | } | |
c906108c | 399 | |
4a64f543 | 400 | /* Prototypes for exported functions. */ |
c906108c | 401 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 402 | if such is available. */ |
c906108c SS |
403 | static int can_use_hw_watchpoints; |
404 | ||
920d2a44 AC |
405 | static void |
406 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
407 | struct cmd_list_element *c, | |
408 | const char *value) | |
409 | { | |
3e43a32a MS |
410 | fprintf_filtered (file, |
411 | _("Debugger's willingness to use " | |
412 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
413 | value); |
414 | } | |
415 | ||
fa8d40ab JJ |
416 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
417 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 418 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
419 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
420 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
421 | static void |
422 | show_pending_break_support (struct ui_file *file, int from_tty, | |
423 | struct cmd_list_element *c, | |
424 | const char *value) | |
425 | { | |
3e43a32a MS |
426 | fprintf_filtered (file, |
427 | _("Debugger's behavior regarding " | |
428 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
429 | value); |
430 | } | |
fa8d40ab | 431 | |
765dc015 | 432 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 433 | set with "break" but falling in read-only memory. |
765dc015 VP |
434 | If 0, gdb will warn about such breakpoints, but won't automatically |
435 | use hardware breakpoints. */ | |
436 | static int automatic_hardware_breakpoints; | |
437 | static void | |
438 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
439 | struct cmd_list_element *c, | |
440 | const char *value) | |
441 | { | |
3e43a32a MS |
442 | fprintf_filtered (file, |
443 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
444 | value); |
445 | } | |
446 | ||
a25a5a45 PA |
447 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
448 | stopped, and immediately inserts any new breakpoints as soon as | |
449 | they're created. If off (default), GDB keeps breakpoints off of | |
450 | the target as long as possible. That is, it delays inserting | |
451 | breakpoints until the next resume, and removes them again when the | |
452 | target fully stops. This is a bit safer in case GDB crashes while | |
453 | processing user input. */ | |
454 | static int always_inserted_mode = 0; | |
72d0e2c5 | 455 | |
33e5cbd6 | 456 | static void |
74960c60 | 457 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 458 | struct cmd_list_element *c, const char *value) |
74960c60 | 459 | { |
a25a5a45 PA |
460 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
461 | value); | |
74960c60 VP |
462 | } |
463 | ||
b57bacec PA |
464 | /* See breakpoint.h. */ |
465 | ||
33e5cbd6 | 466 | int |
a25a5a45 | 467 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 468 | { |
a25a5a45 PA |
469 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
470 | { | |
471 | /* If breakpoints are global, they should be inserted even if no | |
472 | thread under gdb's control is running, or even if there are | |
473 | no threads under GDB's control yet. */ | |
474 | return 1; | |
475 | } | |
476 | else if (target_has_execution) | |
477 | { | |
a25a5a45 PA |
478 | if (always_inserted_mode) |
479 | { | |
480 | /* The user wants breakpoints inserted even if all threads | |
481 | are stopped. */ | |
482 | return 1; | |
483 | } | |
484 | ||
b57bacec PA |
485 | if (threads_are_executing ()) |
486 | return 1; | |
a25a5a45 PA |
487 | } |
488 | return 0; | |
33e5cbd6 | 489 | } |
765dc015 | 490 | |
b775012e LM |
491 | static const char condition_evaluation_both[] = "host or target"; |
492 | ||
493 | /* Modes for breakpoint condition evaluation. */ | |
494 | static const char condition_evaluation_auto[] = "auto"; | |
495 | static const char condition_evaluation_host[] = "host"; | |
496 | static const char condition_evaluation_target[] = "target"; | |
497 | static const char *const condition_evaluation_enums[] = { | |
498 | condition_evaluation_auto, | |
499 | condition_evaluation_host, | |
500 | condition_evaluation_target, | |
501 | NULL | |
502 | }; | |
503 | ||
504 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
505 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
506 | ||
507 | /* Global that we use to display information to the user (gets its value from | |
508 | condition_evaluation_mode_1. */ | |
509 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
510 | ||
511 | /* Translate a condition evaluation mode MODE into either "host" | |
512 | or "target". This is used mostly to translate from "auto" to the | |
513 | real setting that is being used. It returns the translated | |
514 | evaluation mode. */ | |
515 | ||
516 | static const char * | |
517 | translate_condition_evaluation_mode (const char *mode) | |
518 | { | |
519 | if (mode == condition_evaluation_auto) | |
520 | { | |
521 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
522 | return condition_evaluation_target; | |
523 | else | |
524 | return condition_evaluation_host; | |
525 | } | |
526 | else | |
527 | return mode; | |
528 | } | |
529 | ||
530 | /* Discovers what condition_evaluation_auto translates to. */ | |
531 | ||
532 | static const char * | |
533 | breakpoint_condition_evaluation_mode (void) | |
534 | { | |
535 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
536 | } | |
537 | ||
538 | /* Return true if GDB should evaluate breakpoint conditions or false | |
539 | otherwise. */ | |
540 | ||
541 | static int | |
542 | gdb_evaluates_breakpoint_condition_p (void) | |
543 | { | |
544 | const char *mode = breakpoint_condition_evaluation_mode (); | |
545 | ||
546 | return (mode == condition_evaluation_host); | |
547 | } | |
548 | ||
a14ed312 | 549 | void _initialize_breakpoint (void); |
c906108c | 550 | |
c906108c SS |
551 | /* Are we executing breakpoint commands? */ |
552 | static int executing_breakpoint_commands; | |
553 | ||
c02f5703 MS |
554 | /* Are overlay event breakpoints enabled? */ |
555 | static int overlay_events_enabled; | |
556 | ||
e09342b5 TJB |
557 | /* See description in breakpoint.h. */ |
558 | int target_exact_watchpoints = 0; | |
559 | ||
c906108c | 560 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 561 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 562 | current breakpoint. */ |
c906108c | 563 | |
5c44784c | 564 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 565 | |
5c44784c JM |
566 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
567 | for (B = breakpoint_chain; \ | |
568 | B ? (TMP=B->next, 1): 0; \ | |
569 | B = TMP) | |
c906108c | 570 | |
4a64f543 MS |
571 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
572 | not provided so update_global_location_list must not be called | |
573 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 574 | |
876fa593 JK |
575 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
576 | for (BP_TMP = bp_location; \ | |
577 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
578 | BP_TMP++) | |
7cc221ef | 579 | |
b775012e LM |
580 | /* Iterates through locations with address ADDRESS for the currently selected |
581 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
582 | to where the loop should start from. | |
583 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
584 | appropriate location to start with. */ | |
585 | ||
586 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
587 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
588 | BP_LOCP_TMP = BP_LOCP_START; \ | |
589 | BP_LOCP_START \ | |
590 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
591 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
592 | BP_LOCP_TMP++) | |
593 | ||
1042e4c0 SS |
594 | /* Iterator for tracepoints only. */ |
595 | ||
596 | #define ALL_TRACEPOINTS(B) \ | |
597 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 598 | if (is_tracepoint (B)) |
1042e4c0 | 599 | |
7cc221ef | 600 | /* Chains of all breakpoints defined. */ |
c906108c SS |
601 | |
602 | struct breakpoint *breakpoint_chain; | |
603 | ||
876fa593 JK |
604 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
605 | ||
606 | static struct bp_location **bp_location; | |
607 | ||
608 | /* Number of elements of BP_LOCATION. */ | |
609 | ||
610 | static unsigned bp_location_count; | |
611 | ||
4a64f543 MS |
612 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
613 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
614 | result from bp_location_has_shadow. You can use it for roughly | |
615 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
616 | an address you need to read. */ | |
876fa593 JK |
617 | |
618 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
619 | ||
4a64f543 MS |
620 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
621 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
622 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
623 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
624 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
625 | |
626 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 627 | |
4a64f543 MS |
628 | /* The locations that no longer correspond to any breakpoint, unlinked |
629 | from bp_location array, but for which a hit may still be reported | |
630 | by a target. */ | |
20874c92 VP |
631 | VEC(bp_location_p) *moribund_locations = NULL; |
632 | ||
c906108c SS |
633 | /* Number of last breakpoint made. */ |
634 | ||
95a42b64 TT |
635 | static int breakpoint_count; |
636 | ||
86b17b60 PA |
637 | /* The value of `breakpoint_count' before the last command that |
638 | created breakpoints. If the last (break-like) command created more | |
639 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
640 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
641 | static int prev_breakpoint_count; | |
c906108c | 642 | |
1042e4c0 SS |
643 | /* Number of last tracepoint made. */ |
644 | ||
95a42b64 | 645 | static int tracepoint_count; |
1042e4c0 | 646 | |
6149aea9 PA |
647 | static struct cmd_list_element *breakpoint_set_cmdlist; |
648 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 649 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 650 | |
468d015d JJ |
651 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
652 | static int | |
653 | breakpoint_enabled (struct breakpoint *b) | |
654 | { | |
0d381245 | 655 | return (b->enable_state == bp_enabled); |
468d015d JJ |
656 | } |
657 | ||
c906108c SS |
658 | /* Set breakpoint count to NUM. */ |
659 | ||
95a42b64 | 660 | static void |
fba45db2 | 661 | set_breakpoint_count (int num) |
c906108c | 662 | { |
86b17b60 | 663 | prev_breakpoint_count = breakpoint_count; |
c906108c | 664 | breakpoint_count = num; |
4fa62494 | 665 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
666 | } |
667 | ||
86b17b60 PA |
668 | /* Used by `start_rbreak_breakpoints' below, to record the current |
669 | breakpoint count before "rbreak" creates any breakpoint. */ | |
670 | static int rbreak_start_breakpoint_count; | |
671 | ||
95a42b64 TT |
672 | /* Called at the start an "rbreak" command to record the first |
673 | breakpoint made. */ | |
86b17b60 | 674 | |
95a42b64 TT |
675 | void |
676 | start_rbreak_breakpoints (void) | |
677 | { | |
86b17b60 | 678 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
679 | } |
680 | ||
681 | /* Called at the end of an "rbreak" command to record the last | |
682 | breakpoint made. */ | |
86b17b60 | 683 | |
95a42b64 TT |
684 | void |
685 | end_rbreak_breakpoints (void) | |
686 | { | |
86b17b60 | 687 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
688 | } |
689 | ||
4a64f543 | 690 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
691 | |
692 | void | |
fba45db2 | 693 | clear_breakpoint_hit_counts (void) |
c906108c SS |
694 | { |
695 | struct breakpoint *b; | |
696 | ||
697 | ALL_BREAKPOINTS (b) | |
698 | b->hit_count = 0; | |
699 | } | |
700 | ||
9add0f1b TT |
701 | /* Allocate a new counted_command_line with reference count of 1. |
702 | The new structure owns COMMANDS. */ | |
703 | ||
704 | static struct counted_command_line * | |
705 | alloc_counted_command_line (struct command_line *commands) | |
706 | { | |
707 | struct counted_command_line *result | |
708 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 709 | |
9add0f1b TT |
710 | result->refc = 1; |
711 | result->commands = commands; | |
712 | return result; | |
713 | } | |
714 | ||
715 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
716 | ||
717 | static void | |
718 | incref_counted_command_line (struct counted_command_line *cmd) | |
719 | { | |
720 | if (cmd) | |
721 | ++cmd->refc; | |
722 | } | |
723 | ||
724 | /* Decrement reference count. If the reference count reaches 0, | |
725 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
726 | nothing if *CMDP is NULL. */ | |
727 | ||
728 | static void | |
729 | decref_counted_command_line (struct counted_command_line **cmdp) | |
730 | { | |
731 | if (*cmdp) | |
732 | { | |
733 | if (--(*cmdp)->refc == 0) | |
734 | { | |
735 | free_command_lines (&(*cmdp)->commands); | |
736 | xfree (*cmdp); | |
737 | } | |
738 | *cmdp = NULL; | |
739 | } | |
740 | } | |
741 | ||
742 | /* A cleanup function that calls decref_counted_command_line. */ | |
743 | ||
744 | static void | |
745 | do_cleanup_counted_command_line (void *arg) | |
746 | { | |
747 | decref_counted_command_line (arg); | |
748 | } | |
749 | ||
750 | /* Create a cleanup that calls decref_counted_command_line on the | |
751 | argument. */ | |
752 | ||
753 | static struct cleanup * | |
754 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
755 | { | |
756 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
757 | } | |
758 | ||
c906108c | 759 | \f |
48cb2d85 VP |
760 | /* Return the breakpoint with the specified number, or NULL |
761 | if the number does not refer to an existing breakpoint. */ | |
762 | ||
763 | struct breakpoint * | |
764 | get_breakpoint (int num) | |
765 | { | |
766 | struct breakpoint *b; | |
767 | ||
768 | ALL_BREAKPOINTS (b) | |
769 | if (b->number == num) | |
770 | return b; | |
771 | ||
772 | return NULL; | |
773 | } | |
5c44784c | 774 | |
c906108c | 775 | \f |
adc36818 | 776 | |
b775012e LM |
777 | /* Mark locations as "conditions have changed" in case the target supports |
778 | evaluating conditions on its side. */ | |
779 | ||
780 | static void | |
781 | mark_breakpoint_modified (struct breakpoint *b) | |
782 | { | |
783 | struct bp_location *loc; | |
784 | ||
785 | /* This is only meaningful if the target is | |
786 | evaluating conditions and if the user has | |
787 | opted for condition evaluation on the target's | |
788 | side. */ | |
789 | if (gdb_evaluates_breakpoint_condition_p () | |
790 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
791 | return; | |
792 | ||
793 | if (!is_breakpoint (b)) | |
794 | return; | |
795 | ||
796 | for (loc = b->loc; loc; loc = loc->next) | |
797 | loc->condition_changed = condition_modified; | |
798 | } | |
799 | ||
800 | /* Mark location as "conditions have changed" in case the target supports | |
801 | evaluating conditions on its side. */ | |
802 | ||
803 | static void | |
804 | mark_breakpoint_location_modified (struct bp_location *loc) | |
805 | { | |
806 | /* This is only meaningful if the target is | |
807 | evaluating conditions and if the user has | |
808 | opted for condition evaluation on the target's | |
809 | side. */ | |
810 | if (gdb_evaluates_breakpoint_condition_p () | |
811 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
812 | ||
813 | return; | |
814 | ||
815 | if (!is_breakpoint (loc->owner)) | |
816 | return; | |
817 | ||
818 | loc->condition_changed = condition_modified; | |
819 | } | |
820 | ||
821 | /* Sets the condition-evaluation mode using the static global | |
822 | condition_evaluation_mode. */ | |
823 | ||
824 | static void | |
825 | set_condition_evaluation_mode (char *args, int from_tty, | |
826 | struct cmd_list_element *c) | |
827 | { | |
b775012e LM |
828 | const char *old_mode, *new_mode; |
829 | ||
830 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
831 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
832 | { | |
833 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
834 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
835 | "Using host evaluation mode instead.")); | |
836 | return; | |
837 | } | |
838 | ||
839 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
840 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
841 | ||
abf1152a JK |
842 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
843 | settings was "auto". */ | |
844 | condition_evaluation_mode = condition_evaluation_mode_1; | |
845 | ||
b775012e LM |
846 | /* Only update the mode if the user picked a different one. */ |
847 | if (new_mode != old_mode) | |
848 | { | |
849 | struct bp_location *loc, **loc_tmp; | |
850 | /* If the user switched to a different evaluation mode, we | |
851 | need to synch the changes with the target as follows: | |
852 | ||
853 | "host" -> "target": Send all (valid) conditions to the target. | |
854 | "target" -> "host": Remove all the conditions from the target. | |
855 | */ | |
856 | ||
b775012e LM |
857 | if (new_mode == condition_evaluation_target) |
858 | { | |
859 | /* Mark everything modified and synch conditions with the | |
860 | target. */ | |
861 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
862 | mark_breakpoint_location_modified (loc); | |
863 | } | |
864 | else | |
865 | { | |
866 | /* Manually mark non-duplicate locations to synch conditions | |
867 | with the target. We do this to remove all the conditions the | |
868 | target knows about. */ | |
869 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
870 | if (is_breakpoint (loc->owner) && loc->inserted) | |
871 | loc->needs_update = 1; | |
872 | } | |
873 | ||
874 | /* Do the update. */ | |
44702360 | 875 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
876 | } |
877 | ||
878 | return; | |
879 | } | |
880 | ||
881 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
882 | what "auto" is translating to. */ | |
883 | ||
884 | static void | |
885 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
886 | struct cmd_list_element *c, const char *value) | |
887 | { | |
888 | if (condition_evaluation_mode == condition_evaluation_auto) | |
889 | fprintf_filtered (file, | |
890 | _("Breakpoint condition evaluation " | |
891 | "mode is %s (currently %s).\n"), | |
892 | value, | |
893 | breakpoint_condition_evaluation_mode ()); | |
894 | else | |
895 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
896 | value); | |
897 | } | |
898 | ||
899 | /* A comparison function for bp_location AP and BP that is used by | |
900 | bsearch. This comparison function only cares about addresses, unlike | |
901 | the more general bp_location_compare function. */ | |
902 | ||
903 | static int | |
904 | bp_location_compare_addrs (const void *ap, const void *bp) | |
905 | { | |
906 | struct bp_location *a = *(void **) ap; | |
907 | struct bp_location *b = *(void **) bp; | |
908 | ||
909 | if (a->address == b->address) | |
910 | return 0; | |
911 | else | |
912 | return ((a->address > b->address) - (a->address < b->address)); | |
913 | } | |
914 | ||
915 | /* Helper function to skip all bp_locations with addresses | |
916 | less than ADDRESS. It returns the first bp_location that | |
917 | is greater than or equal to ADDRESS. If none is found, just | |
918 | return NULL. */ | |
919 | ||
920 | static struct bp_location ** | |
921 | get_first_locp_gte_addr (CORE_ADDR address) | |
922 | { | |
923 | struct bp_location dummy_loc; | |
924 | struct bp_location *dummy_locp = &dummy_loc; | |
925 | struct bp_location **locp_found = NULL; | |
926 | ||
927 | /* Initialize the dummy location's address field. */ | |
928 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
929 | dummy_loc.address = address; | |
930 | ||
931 | /* Find a close match to the first location at ADDRESS. */ | |
932 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, | |
933 | sizeof (struct bp_location **), | |
934 | bp_location_compare_addrs); | |
935 | ||
936 | /* Nothing was found, nothing left to do. */ | |
937 | if (locp_found == NULL) | |
938 | return NULL; | |
939 | ||
940 | /* We may have found a location that is at ADDRESS but is not the first in the | |
941 | location's list. Go backwards (if possible) and locate the first one. */ | |
942 | while ((locp_found - 1) >= bp_location | |
943 | && (*(locp_found - 1))->address == address) | |
944 | locp_found--; | |
945 | ||
946 | return locp_found; | |
947 | } | |
948 | ||
adc36818 PM |
949 | void |
950 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
951 | int from_tty) | |
952 | { | |
3a5c3e22 PA |
953 | xfree (b->cond_string); |
954 | b->cond_string = NULL; | |
adc36818 | 955 | |
3a5c3e22 | 956 | if (is_watchpoint (b)) |
adc36818 | 957 | { |
3a5c3e22 PA |
958 | struct watchpoint *w = (struct watchpoint *) b; |
959 | ||
960 | xfree (w->cond_exp); | |
961 | w->cond_exp = NULL; | |
962 | } | |
963 | else | |
964 | { | |
965 | struct bp_location *loc; | |
966 | ||
967 | for (loc = b->loc; loc; loc = loc->next) | |
968 | { | |
969 | xfree (loc->cond); | |
970 | loc->cond = NULL; | |
b775012e LM |
971 | |
972 | /* No need to free the condition agent expression | |
973 | bytecode (if we have one). We will handle this | |
974 | when we go through update_global_location_list. */ | |
3a5c3e22 | 975 | } |
adc36818 | 976 | } |
adc36818 PM |
977 | |
978 | if (*exp == 0) | |
979 | { | |
980 | if (from_tty) | |
981 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
982 | } | |
983 | else | |
984 | { | |
bbc13ae3 | 985 | const char *arg = exp; |
cc59ec59 | 986 | |
adc36818 PM |
987 | /* I don't know if it matters whether this is the string the user |
988 | typed in or the decompiled expression. */ | |
989 | b->cond_string = xstrdup (arg); | |
990 | b->condition_not_parsed = 0; | |
991 | ||
992 | if (is_watchpoint (b)) | |
993 | { | |
3a5c3e22 PA |
994 | struct watchpoint *w = (struct watchpoint *) b; |
995 | ||
adc36818 PM |
996 | innermost_block = NULL; |
997 | arg = exp; | |
1bb9788d | 998 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
999 | if (*arg) |
1000 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1001 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1002 | } |
1003 | else | |
1004 | { | |
3a5c3e22 PA |
1005 | struct bp_location *loc; |
1006 | ||
adc36818 PM |
1007 | for (loc = b->loc; loc; loc = loc->next) |
1008 | { | |
1009 | arg = exp; | |
1010 | loc->cond = | |
1bb9788d TT |
1011 | parse_exp_1 (&arg, loc->address, |
1012 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1013 | if (*arg) |
1014 | error (_("Junk at end of expression")); | |
1015 | } | |
1016 | } | |
1017 | } | |
b775012e LM |
1018 | mark_breakpoint_modified (b); |
1019 | ||
8d3788bd | 1020 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1021 | } |
1022 | ||
d55637df TT |
1023 | /* Completion for the "condition" command. */ |
1024 | ||
1025 | static VEC (char_ptr) * | |
6f937416 PA |
1026 | condition_completer (struct cmd_list_element *cmd, |
1027 | const char *text, const char *word) | |
d55637df | 1028 | { |
6f937416 | 1029 | const char *space; |
d55637df | 1030 | |
6f937416 PA |
1031 | text = skip_spaces_const (text); |
1032 | space = skip_to_space_const (text); | |
d55637df TT |
1033 | if (*space == '\0') |
1034 | { | |
1035 | int len; | |
1036 | struct breakpoint *b; | |
1037 | VEC (char_ptr) *result = NULL; | |
1038 | ||
1039 | if (text[0] == '$') | |
1040 | { | |
1041 | /* We don't support completion of history indices. */ | |
1042 | if (isdigit (text[1])) | |
1043 | return NULL; | |
1044 | return complete_internalvar (&text[1]); | |
1045 | } | |
1046 | ||
1047 | /* We're completing the breakpoint number. */ | |
1048 | len = strlen (text); | |
1049 | ||
1050 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1051 | { |
1052 | char number[50]; | |
1053 | ||
1054 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1055 | ||
1056 | if (strncmp (number, text, len) == 0) | |
1057 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1058 | } | |
d55637df TT |
1059 | |
1060 | return result; | |
1061 | } | |
1062 | ||
1063 | /* We're completing the expression part. */ | |
6f937416 | 1064 | text = skip_spaces_const (space); |
d55637df TT |
1065 | return expression_completer (cmd, text, word); |
1066 | } | |
1067 | ||
c906108c SS |
1068 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1069 | ||
1070 | static void | |
fba45db2 | 1071 | condition_command (char *arg, int from_tty) |
c906108c | 1072 | { |
52f0bd74 | 1073 | struct breakpoint *b; |
c906108c | 1074 | char *p; |
52f0bd74 | 1075 | int bnum; |
c906108c SS |
1076 | |
1077 | if (arg == 0) | |
e2e0b3e5 | 1078 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1079 | |
1080 | p = arg; | |
1081 | bnum = get_number (&p); | |
5c44784c | 1082 | if (bnum == 0) |
8a3fe4f8 | 1083 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1084 | |
1085 | ALL_BREAKPOINTS (b) | |
1086 | if (b->number == bnum) | |
2f069f6f | 1087 | { |
6dddc817 DE |
1088 | /* Check if this breakpoint has a "stop" method implemented in an |
1089 | extension language. This method and conditions entered into GDB | |
1090 | from the CLI are mutually exclusive. */ | |
1091 | const struct extension_language_defn *extlang | |
1092 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1093 | ||
1094 | if (extlang != NULL) | |
1095 | { | |
1096 | error (_("Only one stop condition allowed. There is currently" | |
1097 | " a %s stop condition defined for this breakpoint."), | |
1098 | ext_lang_capitalized_name (extlang)); | |
1099 | } | |
2566ad2d | 1100 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1101 | |
1102 | if (is_breakpoint (b)) | |
44702360 | 1103 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1104 | |
2f069f6f JB |
1105 | return; |
1106 | } | |
c906108c | 1107 | |
8a3fe4f8 | 1108 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1109 | } |
1110 | ||
a7bdde9e VP |
1111 | /* Check that COMMAND do not contain commands that are suitable |
1112 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1113 | Throw if any such commands is found. */ |
1114 | ||
a7bdde9e VP |
1115 | static void |
1116 | check_no_tracepoint_commands (struct command_line *commands) | |
1117 | { | |
1118 | struct command_line *c; | |
cc59ec59 | 1119 | |
a7bdde9e VP |
1120 | for (c = commands; c; c = c->next) |
1121 | { | |
1122 | int i; | |
1123 | ||
1124 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1125 | error (_("The 'while-stepping' command can " |
1126 | "only be used for tracepoints")); | |
a7bdde9e VP |
1127 | |
1128 | for (i = 0; i < c->body_count; ++i) | |
1129 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1130 | ||
1131 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1132 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1133 | command directly. */ |
1134 | if (strstr (c->line, "collect ") == c->line) | |
1135 | error (_("The 'collect' command can only be used for tracepoints")); | |
1136 | ||
51661e93 VP |
1137 | if (strstr (c->line, "teval ") == c->line) |
1138 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1139 | } |
1140 | } | |
1141 | ||
d77f58be SS |
1142 | /* Encapsulate tests for different types of tracepoints. */ |
1143 | ||
d9b3f62e PA |
1144 | static int |
1145 | is_tracepoint_type (enum bptype type) | |
1146 | { | |
1147 | return (type == bp_tracepoint | |
1148 | || type == bp_fast_tracepoint | |
1149 | || type == bp_static_tracepoint); | |
1150 | } | |
1151 | ||
a7bdde9e | 1152 | int |
d77f58be | 1153 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1154 | { |
d9b3f62e | 1155 | return is_tracepoint_type (b->type); |
a7bdde9e | 1156 | } |
d9b3f62e | 1157 | |
e5dd4106 | 1158 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1159 | breakpoint. This function will throw an exception if a problem is |
1160 | found. */ | |
48cb2d85 | 1161 | |
95a42b64 TT |
1162 | static void |
1163 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1164 | struct command_line *commands) | |
48cb2d85 | 1165 | { |
d77f58be | 1166 | if (is_tracepoint (b)) |
a7bdde9e | 1167 | { |
c9a6ce02 | 1168 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1169 | struct command_line *c; |
1170 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1171 | |
1172 | /* Reset the while-stepping step count. The previous commands | |
1173 | might have included a while-stepping action, while the new | |
1174 | ones might not. */ | |
1175 | t->step_count = 0; | |
1176 | ||
1177 | /* We need to verify that each top-level element of commands is | |
1178 | valid for tracepoints, that there's at most one | |
1179 | while-stepping element, and that the while-stepping's body | |
1180 | has valid tracing commands excluding nested while-stepping. | |
1181 | We also need to validate the tracepoint action line in the | |
1182 | context of the tracepoint --- validate_actionline actually | |
1183 | has side effects, like setting the tracepoint's | |
1184 | while-stepping STEP_COUNT, in addition to checking if the | |
1185 | collect/teval actions parse and make sense in the | |
1186 | tracepoint's context. */ | |
a7bdde9e VP |
1187 | for (c = commands; c; c = c->next) |
1188 | { | |
a7bdde9e VP |
1189 | if (c->control_type == while_stepping_control) |
1190 | { | |
1191 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1192 | error (_("The 'while-stepping' command " |
1193 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1194 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1195 | error (_("The 'while-stepping' command " |
1196 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1197 | |
1198 | if (while_stepping) | |
3e43a32a MS |
1199 | error (_("The 'while-stepping' command " |
1200 | "can be used only once")); | |
a7bdde9e VP |
1201 | else |
1202 | while_stepping = c; | |
1203 | } | |
c9a6ce02 PA |
1204 | |
1205 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1206 | } |
1207 | if (while_stepping) | |
1208 | { | |
1209 | struct command_line *c2; | |
1210 | ||
1211 | gdb_assert (while_stepping->body_count == 1); | |
1212 | c2 = while_stepping->body_list[0]; | |
1213 | for (; c2; c2 = c2->next) | |
1214 | { | |
a7bdde9e VP |
1215 | if (c2->control_type == while_stepping_control) |
1216 | error (_("The 'while-stepping' command cannot be nested")); | |
1217 | } | |
1218 | } | |
1219 | } | |
1220 | else | |
1221 | { | |
1222 | check_no_tracepoint_commands (commands); | |
1223 | } | |
95a42b64 TT |
1224 | } |
1225 | ||
0fb4aa4b PA |
1226 | /* Return a vector of all the static tracepoints set at ADDR. The |
1227 | caller is responsible for releasing the vector. */ | |
1228 | ||
1229 | VEC(breakpoint_p) * | |
1230 | static_tracepoints_here (CORE_ADDR addr) | |
1231 | { | |
1232 | struct breakpoint *b; | |
1233 | VEC(breakpoint_p) *found = 0; | |
1234 | struct bp_location *loc; | |
1235 | ||
1236 | ALL_BREAKPOINTS (b) | |
1237 | if (b->type == bp_static_tracepoint) | |
1238 | { | |
1239 | for (loc = b->loc; loc; loc = loc->next) | |
1240 | if (loc->address == addr) | |
1241 | VEC_safe_push(breakpoint_p, found, b); | |
1242 | } | |
1243 | ||
1244 | return found; | |
1245 | } | |
1246 | ||
95a42b64 | 1247 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1248 | validate that only allowed commands are included. */ |
95a42b64 TT |
1249 | |
1250 | void | |
4a64f543 MS |
1251 | breakpoint_set_commands (struct breakpoint *b, |
1252 | struct command_line *commands) | |
95a42b64 TT |
1253 | { |
1254 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1255 | |
9add0f1b TT |
1256 | decref_counted_command_line (&b->commands); |
1257 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1258 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1259 | } |
1260 | ||
45a43567 TT |
1261 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1262 | is not the same as the "silent" that may appear in the breakpoint's | |
1263 | commands. */ | |
1264 | ||
1265 | void | |
1266 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1267 | { | |
1268 | int old_silent = b->silent; | |
1269 | ||
1270 | b->silent = silent; | |
1271 | if (old_silent != silent) | |
8d3788bd | 1272 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1273 | } |
1274 | ||
1275 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1276 | breakpoint work for any thread. */ | |
1277 | ||
1278 | void | |
1279 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1280 | { | |
1281 | int old_thread = b->thread; | |
1282 | ||
1283 | b->thread = thread; | |
1284 | if (old_thread != thread) | |
8d3788bd | 1285 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1286 | } |
1287 | ||
1288 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1289 | breakpoint work for any task. */ | |
1290 | ||
1291 | void | |
1292 | breakpoint_set_task (struct breakpoint *b, int task) | |
1293 | { | |
1294 | int old_task = b->task; | |
1295 | ||
1296 | b->task = task; | |
1297 | if (old_task != task) | |
8d3788bd | 1298 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1299 | } |
1300 | ||
95a42b64 TT |
1301 | void |
1302 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
1303 | { |
1304 | struct breakpoint *b = closure; | |
cc59ec59 | 1305 | |
6f937416 | 1306 | validate_actionline (line, b); |
a7bdde9e VP |
1307 | } |
1308 | ||
95a42b64 TT |
1309 | /* A structure used to pass information through |
1310 | map_breakpoint_numbers. */ | |
1311 | ||
1312 | struct commands_info | |
1313 | { | |
1314 | /* True if the command was typed at a tty. */ | |
1315 | int from_tty; | |
86b17b60 PA |
1316 | |
1317 | /* The breakpoint range spec. */ | |
1318 | char *arg; | |
1319 | ||
95a42b64 TT |
1320 | /* Non-NULL if the body of the commands are being read from this |
1321 | already-parsed command. */ | |
1322 | struct command_line *control; | |
86b17b60 | 1323 | |
95a42b64 TT |
1324 | /* The command lines read from the user, or NULL if they have not |
1325 | yet been read. */ | |
1326 | struct counted_command_line *cmd; | |
1327 | }; | |
1328 | ||
1329 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1330 | commands_command. */ | |
1331 | ||
c906108c | 1332 | static void |
95a42b64 | 1333 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1334 | { |
95a42b64 | 1335 | struct commands_info *info = data; |
c906108c | 1336 | |
95a42b64 TT |
1337 | if (info->cmd == NULL) |
1338 | { | |
1339 | struct command_line *l; | |
5c44784c | 1340 | |
95a42b64 TT |
1341 | if (info->control != NULL) |
1342 | l = copy_command_lines (info->control->body_list[0]); | |
1343 | else | |
86b17b60 PA |
1344 | { |
1345 | struct cleanup *old_chain; | |
1346 | char *str; | |
c5aa993b | 1347 | |
3e43a32a MS |
1348 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1349 | "%s, one per line."), | |
86b17b60 PA |
1350 | info->arg); |
1351 | ||
1352 | old_chain = make_cleanup (xfree, str); | |
1353 | ||
1354 | l = read_command_lines (str, | |
1355 | info->from_tty, 1, | |
d77f58be | 1356 | (is_tracepoint (b) |
86b17b60 PA |
1357 | ? check_tracepoint_command : 0), |
1358 | b); | |
1359 | ||
1360 | do_cleanups (old_chain); | |
1361 | } | |
a7bdde9e | 1362 | |
95a42b64 TT |
1363 | info->cmd = alloc_counted_command_line (l); |
1364 | } | |
1365 | ||
1366 | /* If a breakpoint was on the list more than once, we don't need to | |
1367 | do anything. */ | |
1368 | if (b->commands != info->cmd) | |
1369 | { | |
1370 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1371 | incref_counted_command_line (info->cmd); | |
1372 | decref_counted_command_line (&b->commands); | |
1373 | b->commands = info->cmd; | |
8d3788bd | 1374 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1375 | } |
95a42b64 TT |
1376 | } |
1377 | ||
1378 | static void | |
4a64f543 MS |
1379 | commands_command_1 (char *arg, int from_tty, |
1380 | struct command_line *control) | |
95a42b64 TT |
1381 | { |
1382 | struct cleanup *cleanups; | |
1383 | struct commands_info info; | |
1384 | ||
1385 | info.from_tty = from_tty; | |
1386 | info.control = control; | |
1387 | info.cmd = NULL; | |
1388 | /* If we read command lines from the user, then `info' will hold an | |
1389 | extra reference to the commands that we must clean up. */ | |
1390 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1391 | ||
1392 | if (arg == NULL || !*arg) | |
1393 | { | |
86b17b60 | 1394 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1395 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1396 | breakpoint_count); | |
95a42b64 TT |
1397 | else if (breakpoint_count > 0) |
1398 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1399 | else |
1400 | { | |
1401 | /* So that we don't try to free the incoming non-NULL | |
1402 | argument in the cleanup below. Mapping breakpoint | |
1403 | numbers will fail in this case. */ | |
1404 | arg = NULL; | |
1405 | } | |
95a42b64 | 1406 | } |
9766ced4 SS |
1407 | else |
1408 | /* The command loop has some static state, so we need to preserve | |
1409 | our argument. */ | |
1410 | arg = xstrdup (arg); | |
86b17b60 PA |
1411 | |
1412 | if (arg != NULL) | |
1413 | make_cleanup (xfree, arg); | |
1414 | ||
1415 | info.arg = arg; | |
95a42b64 TT |
1416 | |
1417 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1418 | ||
1419 | if (info.cmd == NULL) | |
1420 | error (_("No breakpoints specified.")); | |
1421 | ||
1422 | do_cleanups (cleanups); | |
1423 | } | |
1424 | ||
1425 | static void | |
1426 | commands_command (char *arg, int from_tty) | |
1427 | { | |
1428 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1429 | } |
40c03ae8 EZ |
1430 | |
1431 | /* Like commands_command, but instead of reading the commands from | |
1432 | input stream, takes them from an already parsed command structure. | |
1433 | ||
1434 | This is used by cli-script.c to DTRT with breakpoint commands | |
1435 | that are part of if and while bodies. */ | |
1436 | enum command_control_type | |
1437 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1438 | { | |
95a42b64 TT |
1439 | commands_command_1 (arg, 0, cmd); |
1440 | return simple_control; | |
40c03ae8 | 1441 | } |
876fa593 JK |
1442 | |
1443 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1444 | ||
1445 | static int | |
1446 | bp_location_has_shadow (struct bp_location *bl) | |
1447 | { | |
1448 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1449 | return 0; | |
1450 | if (!bl->inserted) | |
1451 | return 0; | |
1452 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1453 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1454 | return 0; |
1455 | return 1; | |
1456 | } | |
1457 | ||
9d497a19 PA |
1458 | /* Update BUF, which is LEN bytes read from the target address |
1459 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1460 | contents. | |
1461 | ||
1462 | If READBUF is not NULL, this buffer must not overlap with the of | |
1463 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1464 | failed assertion internal error will be raised. */ | |
1465 | ||
1466 | static void | |
1467 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1468 | const gdb_byte *writebuf_org, | |
1469 | ULONGEST memaddr, LONGEST len, | |
1470 | struct bp_target_info *target_info, | |
1471 | struct gdbarch *gdbarch) | |
1472 | { | |
1473 | /* Now do full processing of the found relevant range of elements. */ | |
1474 | CORE_ADDR bp_addr = 0; | |
1475 | int bp_size = 0; | |
1476 | int bptoffset = 0; | |
1477 | ||
1478 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1479 | current_program_space->aspace, 0)) | |
1480 | { | |
1481 | /* The breakpoint is inserted in a different address space. */ | |
1482 | return; | |
1483 | } | |
1484 | ||
1485 | /* Addresses and length of the part of the breakpoint that | |
1486 | we need to copy. */ | |
1487 | bp_addr = target_info->placed_address; | |
1488 | bp_size = target_info->shadow_len; | |
1489 | ||
1490 | if (bp_addr + bp_size <= memaddr) | |
1491 | { | |
1492 | /* The breakpoint is entirely before the chunk of memory we are | |
1493 | reading. */ | |
1494 | return; | |
1495 | } | |
1496 | ||
1497 | if (bp_addr >= memaddr + len) | |
1498 | { | |
1499 | /* The breakpoint is entirely after the chunk of memory we are | |
1500 | reading. */ | |
1501 | return; | |
1502 | } | |
1503 | ||
1504 | /* Offset within shadow_contents. */ | |
1505 | if (bp_addr < memaddr) | |
1506 | { | |
1507 | /* Only copy the second part of the breakpoint. */ | |
1508 | bp_size -= memaddr - bp_addr; | |
1509 | bptoffset = memaddr - bp_addr; | |
1510 | bp_addr = memaddr; | |
1511 | } | |
1512 | ||
1513 | if (bp_addr + bp_size > memaddr + len) | |
1514 | { | |
1515 | /* Only copy the first part of the breakpoint. */ | |
1516 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1517 | } | |
1518 | ||
1519 | if (readbuf != NULL) | |
1520 | { | |
1521 | /* Verify that the readbuf buffer does not overlap with the | |
1522 | shadow_contents buffer. */ | |
1523 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1524 | || readbuf >= (target_info->shadow_contents | |
1525 | + target_info->shadow_len)); | |
1526 | ||
1527 | /* Update the read buffer with this inserted breakpoint's | |
1528 | shadow. */ | |
1529 | memcpy (readbuf + bp_addr - memaddr, | |
1530 | target_info->shadow_contents + bptoffset, bp_size); | |
1531 | } | |
1532 | else | |
1533 | { | |
1534 | const unsigned char *bp; | |
0d5ed153 MR |
1535 | CORE_ADDR addr = target_info->reqstd_address; |
1536 | int placed_size; | |
9d497a19 PA |
1537 | |
1538 | /* Update the shadow with what we want to write to memory. */ | |
1539 | memcpy (target_info->shadow_contents + bptoffset, | |
1540 | writebuf_org + bp_addr - memaddr, bp_size); | |
1541 | ||
1542 | /* Determine appropriate breakpoint contents and size for this | |
1543 | address. */ | |
0d5ed153 | 1544 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1545 | |
1546 | /* Update the final write buffer with this inserted | |
1547 | breakpoint's INSN. */ | |
1548 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1549 | } | |
1550 | } | |
1551 | ||
8defab1a | 1552 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1553 | by replacing any memory breakpoints with their shadowed contents. |
1554 | ||
35c63cd8 JB |
1555 | If READBUF is not NULL, this buffer must not overlap with any of |
1556 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1557 | a failed assertion internal error will be raised. | |
1558 | ||
876fa593 | 1559 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1560 | bl->address - bp_location_placed_address_before_address_max |
1561 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1562 | The range we were requested to resolve shadows for is: |
1563 | memaddr ... memaddr + len | |
1564 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1565 | memaddr + len <= (bl->address |
1566 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1567 | and: |
35df4500 | 1568 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1569 | |
8defab1a | 1570 | void |
f0ba3972 PA |
1571 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1572 | const gdb_byte *writebuf_org, | |
1573 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1574 | { |
4a64f543 MS |
1575 | /* Left boundary, right boundary and median element of our binary |
1576 | search. */ | |
876fa593 | 1577 | unsigned bc_l, bc_r, bc; |
9d497a19 | 1578 | size_t i; |
876fa593 | 1579 | |
4a64f543 MS |
1580 | /* Find BC_L which is a leftmost element which may affect BUF |
1581 | content. It is safe to report lower value but a failure to | |
1582 | report higher one. */ | |
876fa593 JK |
1583 | |
1584 | bc_l = 0; | |
1585 | bc_r = bp_location_count; | |
1586 | while (bc_l + 1 < bc_r) | |
1587 | { | |
35df4500 | 1588 | struct bp_location *bl; |
876fa593 JK |
1589 | |
1590 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1591 | bl = bp_location[bc]; |
876fa593 | 1592 | |
4a64f543 MS |
1593 | /* Check first BL->ADDRESS will not overflow due to the added |
1594 | constant. Then advance the left boundary only if we are sure | |
1595 | the BC element can in no way affect the BUF content (MEMADDR | |
1596 | to MEMADDR + LEN range). | |
876fa593 | 1597 | |
4a64f543 MS |
1598 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1599 | offset so that we cannot miss a breakpoint with its shadow | |
1600 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1601 | |
35df4500 TJB |
1602 | if ((bl->address + bp_location_shadow_len_after_address_max |
1603 | >= bl->address) | |
1604 | && (bl->address + bp_location_shadow_len_after_address_max | |
1605 | <= memaddr)) | |
876fa593 JK |
1606 | bc_l = bc; |
1607 | else | |
1608 | bc_r = bc; | |
1609 | } | |
1610 | ||
128070bb PA |
1611 | /* Due to the binary search above, we need to make sure we pick the |
1612 | first location that's at BC_L's address. E.g., if there are | |
1613 | multiple locations at the same address, BC_L may end up pointing | |
1614 | at a duplicate location, and miss the "master"/"inserted" | |
1615 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1616 | B: | |
1617 | ||
1618 | L1@A, L2@A, L3@B, ... | |
1619 | ||
1620 | BC_L could end up pointing at location L2, while the "master" | |
1621 | location could be L1. Since the `loc->inserted' flag is only set | |
1622 | on "master" locations, we'd forget to restore the shadow of L1 | |
1623 | and L2. */ | |
1624 | while (bc_l > 0 | |
1625 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1626 | bc_l--; | |
1627 | ||
876fa593 JK |
1628 | /* Now do full processing of the found relevant range of elements. */ |
1629 | ||
1630 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1631 | { |
35df4500 | 1632 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1633 | CORE_ADDR bp_addr = 0; |
1634 | int bp_size = 0; | |
1635 | int bptoffset = 0; | |
1636 | ||
35df4500 TJB |
1637 | /* bp_location array has BL->OWNER always non-NULL. */ |
1638 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1639 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1640 | bl->owner->number); |
ffce0d52 | 1641 | |
e5dd4106 | 1642 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1643 | content. */ |
1644 | ||
35df4500 TJB |
1645 | if (bl->address >= bp_location_placed_address_before_address_max |
1646 | && memaddr + len <= (bl->address | |
1647 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1648 | break; |
1649 | ||
35df4500 | 1650 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1651 | continue; |
6c95b8df | 1652 | |
9d497a19 PA |
1653 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1654 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1655 | } | |
c906108c | 1656 | } |
9d497a19 | 1657 | |
c906108c | 1658 | \f |
c5aa993b | 1659 | |
b775012e LM |
1660 | /* Return true if BPT is either a software breakpoint or a hardware |
1661 | breakpoint. */ | |
1662 | ||
1663 | int | |
1664 | is_breakpoint (const struct breakpoint *bpt) | |
1665 | { | |
1666 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1667 | || bpt->type == bp_hardware_breakpoint |
1668 | || bpt->type == bp_dprintf); | |
b775012e LM |
1669 | } |
1670 | ||
60e1c644 PA |
1671 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1672 | ||
a5606eee | 1673 | static int |
d77f58be | 1674 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1675 | { |
1676 | return (bpt->type == bp_hardware_watchpoint | |
1677 | || bpt->type == bp_read_watchpoint | |
1678 | || bpt->type == bp_access_watchpoint); | |
1679 | } | |
7270d8f2 | 1680 | |
60e1c644 PA |
1681 | /* Return true if BPT is of any watchpoint kind, hardware or |
1682 | software. */ | |
1683 | ||
3a5c3e22 | 1684 | int |
d77f58be | 1685 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1686 | { |
1687 | return (is_hardware_watchpoint (bpt) | |
1688 | || bpt->type == bp_watchpoint); | |
1689 | } | |
1690 | ||
3a5c3e22 PA |
1691 | /* Returns true if the current thread and its running state are safe |
1692 | to evaluate or update watchpoint B. Watchpoints on local | |
1693 | expressions need to be evaluated in the context of the thread that | |
1694 | was current when the watchpoint was created, and, that thread needs | |
1695 | to be stopped to be able to select the correct frame context. | |
1696 | Watchpoints on global expressions can be evaluated on any thread, | |
1697 | and in any state. It is presently left to the target allowing | |
1698 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1699 | |
1700 | static int | |
3a5c3e22 | 1701 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1702 | { |
d0d8b0c6 JK |
1703 | return (b->base.pspace == current_program_space |
1704 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1705 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1706 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1707 | } |
1708 | ||
d0fb5eae JK |
1709 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1710 | associated bp_watchpoint_scope breakpoint. */ | |
1711 | ||
1712 | static void | |
3a5c3e22 | 1713 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1714 | { |
3a5c3e22 | 1715 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1716 | |
1717 | if (b->related_breakpoint != b) | |
1718 | { | |
1719 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1720 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1721 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1722 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1723 | b->related_breakpoint = b; | |
1724 | } | |
1725 | b->disposition = disp_del_at_next_stop; | |
1726 | } | |
1727 | ||
bb9d5f81 PP |
1728 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1729 | watchpoint W. */ | |
1730 | ||
1731 | static struct value * | |
1732 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1733 | { | |
1734 | struct value *bit_val; | |
1735 | ||
1736 | if (val == NULL) | |
1737 | return NULL; | |
1738 | ||
1739 | bit_val = allocate_value (value_type (val)); | |
1740 | ||
1741 | unpack_value_bitfield (bit_val, | |
1742 | w->val_bitpos, | |
1743 | w->val_bitsize, | |
1744 | value_contents_for_printing (val), | |
1745 | value_offset (val), | |
1746 | val); | |
1747 | ||
1748 | return bit_val; | |
1749 | } | |
1750 | ||
567e1b4e JB |
1751 | /* Assuming that B is a watchpoint: |
1752 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1753 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1754 | - Evaluate the condition if there is one, and store the result |
1755 | in b->loc->cond. | |
a5606eee VP |
1756 | - Update the list of values that must be watched in B->loc. |
1757 | ||
4a64f543 MS |
1758 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1759 | nothing. If this is local watchpoint that is out of scope, delete | |
1760 | it. | |
1761 | ||
1762 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1763 | removed + inserted on each stop here. Normal breakpoints must | |
1764 | never be removed because they might be missed by a running thread | |
1765 | when debugging in non-stop mode. On the other hand, hardware | |
1766 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1767 | to each LWP since they are stored in each LWP's hardware debug | |
1768 | registers. Therefore, such LWP must be stopped first in order to | |
1769 | be able to modify its hardware watchpoints. | |
1770 | ||
1771 | Hardware watchpoints must be reset exactly once after being | |
1772 | presented to the user. It cannot be done sooner, because it would | |
1773 | reset the data used to present the watchpoint hit to the user. And | |
1774 | it must not be done later because it could display the same single | |
1775 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1776 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1777 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1778 | not user-visible - its hit is suppressed if the memory content has | |
1779 | not changed. | |
1780 | ||
1781 | The following constraints influence the location where we can reset | |
1782 | hardware watchpoints: | |
1783 | ||
1784 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1785 | called several times when GDB stops. | |
1786 | ||
1787 | [linux] | |
1788 | * Multiple hardware watchpoints can be hit at the same time, | |
1789 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1790 | hit at a time as the reason for stopping, and all the other hits | |
1791 | are presented later, one after the other, each time the user | |
1792 | requests the execution to be resumed. Execution is not resumed | |
1793 | for the threads still having pending hit event stored in | |
1794 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1795 | the inferior on the first stop the thread hit event is kept being | |
1796 | reported from its cached value by linux_nat_stopped_data_address | |
1797 | until the real thread resume happens after the watchpoint gets | |
1798 | presented and thus its LWP_INFO->STATUS gets reset. | |
1799 | ||
1800 | Therefore the hardware watchpoint hit can get safely reset on the | |
1801 | watchpoint removal from inferior. */ | |
a79d3c27 | 1802 | |
b40ce68a | 1803 | static void |
3a5c3e22 | 1804 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1805 | { |
a5606eee | 1806 | int within_current_scope; |
a5606eee | 1807 | struct frame_id saved_frame_id; |
66076460 | 1808 | int frame_saved; |
a5606eee | 1809 | |
f6bc2008 PA |
1810 | /* If this is a local watchpoint, we only want to check if the |
1811 | watchpoint frame is in scope if the current thread is the thread | |
1812 | that was used to create the watchpoint. */ | |
1813 | if (!watchpoint_in_thread_scope (b)) | |
1814 | return; | |
1815 | ||
3a5c3e22 | 1816 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1817 | return; |
1818 | ||
66076460 | 1819 | frame_saved = 0; |
a5606eee VP |
1820 | |
1821 | /* Determine if the watchpoint is within scope. */ | |
1822 | if (b->exp_valid_block == NULL) | |
1823 | within_current_scope = 1; | |
1824 | else | |
1825 | { | |
b5db5dfc UW |
1826 | struct frame_info *fi = get_current_frame (); |
1827 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1828 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1829 | ||
1830 | /* If we're in a function epilogue, unwinding may not work | |
1831 | properly, so do not attempt to recreate locations at this | |
1832 | point. See similar comments in watchpoint_check. */ | |
1833 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1834 | return; | |
66076460 DJ |
1835 | |
1836 | /* Save the current frame's ID so we can restore it after | |
1837 | evaluating the watchpoint expression on its own frame. */ | |
1838 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1839 | took a frame parameter, so that we didn't have to change the | |
1840 | selected frame. */ | |
1841 | frame_saved = 1; | |
1842 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1843 | ||
a5606eee VP |
1844 | fi = frame_find_by_id (b->watchpoint_frame); |
1845 | within_current_scope = (fi != NULL); | |
1846 | if (within_current_scope) | |
1847 | select_frame (fi); | |
1848 | } | |
1849 | ||
b5db5dfc UW |
1850 | /* We don't free locations. They are stored in the bp_location array |
1851 | and update_global_location_list will eventually delete them and | |
1852 | remove breakpoints if needed. */ | |
3a5c3e22 | 1853 | b->base.loc = NULL; |
b5db5dfc | 1854 | |
a5606eee VP |
1855 | if (within_current_scope && reparse) |
1856 | { | |
bbc13ae3 | 1857 | const char *s; |
d63d0675 | 1858 | |
a5606eee VP |
1859 | if (b->exp) |
1860 | { | |
1861 | xfree (b->exp); | |
1862 | b->exp = NULL; | |
1863 | } | |
d63d0675 | 1864 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1865 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1866 | /* If the meaning of expression itself changed, the old value is |
1867 | no longer relevant. We don't want to report a watchpoint hit | |
1868 | to the user when the old value and the new value may actually | |
1869 | be completely different objects. */ | |
1870 | value_free (b->val); | |
fa4727a6 DJ |
1871 | b->val = NULL; |
1872 | b->val_valid = 0; | |
60e1c644 PA |
1873 | |
1874 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1875 | expression is stored in the breakpoint object, not in the | |
1876 | locations (re)created below. */ | |
3a5c3e22 | 1877 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1878 | { |
1879 | if (b->cond_exp != NULL) | |
1880 | { | |
1881 | xfree (b->cond_exp); | |
1882 | b->cond_exp = NULL; | |
1883 | } | |
1884 | ||
3a5c3e22 | 1885 | s = b->base.cond_string; |
1bb9788d | 1886 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1887 | } |
a5606eee | 1888 | } |
a5606eee VP |
1889 | |
1890 | /* If we failed to parse the expression, for example because | |
1891 | it refers to a global variable in a not-yet-loaded shared library, | |
1892 | don't try to insert watchpoint. We don't automatically delete | |
1893 | such watchpoint, though, since failure to parse expression | |
1894 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1895 | if (!target_has_execution) |
2d134ed3 PA |
1896 | { |
1897 | /* Without execution, memory can't change. No use to try and | |
1898 | set watchpoint locations. The watchpoint will be reset when | |
1899 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1900 | if (!can_use_hw_watchpoints) |
1901 | { | |
1902 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1903 | b->base.type = bp_watchpoint; | |
1904 | else | |
638aa5a1 AB |
1905 | error (_("Can't set read/access watchpoint when " |
1906 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1907 | } |
2d134ed3 PA |
1908 | } |
1909 | else if (within_current_scope && b->exp) | |
a5606eee | 1910 | { |
0cf6dd15 | 1911 | int pc = 0; |
fa4727a6 | 1912 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1913 | struct program_space *frame_pspace; |
a5606eee | 1914 | |
3a1115a0 | 1915 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1916 | |
a5606eee VP |
1917 | /* Avoid setting b->val if it's already set. The meaning of |
1918 | b->val is 'the last value' user saw, and we should update | |
1919 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1920 | happens, the code that reports it updates b->val directly. |
1921 | We don't keep track of the memory value for masked | |
1922 | watchpoints. */ | |
3a5c3e22 | 1923 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 | 1924 | { |
bb9d5f81 PP |
1925 | if (b->val_bitsize != 0) |
1926 | { | |
1927 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1928 | if (v != NULL) | |
1929 | release_value (v); | |
1930 | } | |
fa4727a6 DJ |
1931 | b->val = v; |
1932 | b->val_valid = 1; | |
1933 | } | |
a5606eee | 1934 | |
2d134ed3 PA |
1935 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1936 | ||
a5606eee | 1937 | /* Look at each value on the value chain. */ |
9fa40276 | 1938 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1939 | { |
1940 | /* If it's a memory location, and GDB actually needed | |
1941 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1942 | must watch it. If the first value returned is |
1943 | still lazy, that means an error occurred reading it; | |
1944 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1945 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1946 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1947 | { |
1948 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1949 | |
a5606eee VP |
1950 | /* We only watch structs and arrays if user asked |
1951 | for it explicitly, never if they just happen to | |
1952 | appear in the middle of some value chain. */ | |
fa4727a6 | 1953 | if (v == result |
a5606eee VP |
1954 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1955 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1956 | { | |
1957 | CORE_ADDR addr; | |
744a8059 | 1958 | int type; |
a5606eee | 1959 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1960 | int bitpos = 0, bitsize = 0; |
1961 | ||
1962 | if (value_bitsize (v) != 0) | |
1963 | { | |
1964 | /* Extract the bit parameters out from the bitfield | |
1965 | sub-expression. */ | |
1966 | bitpos = value_bitpos (v); | |
1967 | bitsize = value_bitsize (v); | |
1968 | } | |
1969 | else if (v == result && b->val_bitsize != 0) | |
1970 | { | |
1971 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1972 | lvalue whose bit parameters are saved in the fields | |
1973 | VAL_BITPOS and VAL_BITSIZE. */ | |
1974 | bitpos = b->val_bitpos; | |
1975 | bitsize = b->val_bitsize; | |
1976 | } | |
a5606eee | 1977 | |
42ae5230 | 1978 | addr = value_address (v); |
bb9d5f81 PP |
1979 | if (bitsize != 0) |
1980 | { | |
1981 | /* Skip the bytes that don't contain the bitfield. */ | |
1982 | addr += bitpos / 8; | |
1983 | } | |
1984 | ||
a5606eee | 1985 | type = hw_write; |
3a5c3e22 | 1986 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1987 | type = hw_read; |
3a5c3e22 | 1988 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1989 | type = hw_access; |
3a5c3e22 PA |
1990 | |
1991 | loc = allocate_bp_location (&b->base); | |
1992 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1993 | ; |
1994 | *tmp = loc; | |
a6d9a66e | 1995 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1996 | |
1997 | loc->pspace = frame_pspace; | |
a5606eee | 1998 | loc->address = addr; |
bb9d5f81 PP |
1999 | |
2000 | if (bitsize != 0) | |
2001 | { | |
2002 | /* Just cover the bytes that make up the bitfield. */ | |
2003 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2004 | } | |
2005 | else | |
2006 | loc->length = TYPE_LENGTH (value_type (v)); | |
2007 | ||
a5606eee VP |
2008 | loc->watchpoint_type = type; |
2009 | } | |
2010 | } | |
9fa40276 TJB |
2011 | } |
2012 | ||
2013 | /* Change the type of breakpoint between hardware assisted or | |
2014 | an ordinary watchpoint depending on the hardware support | |
2015 | and free hardware slots. REPARSE is set when the inferior | |
2016 | is started. */ | |
a9634178 | 2017 | if (reparse) |
9fa40276 | 2018 | { |
e09342b5 | 2019 | int reg_cnt; |
9fa40276 TJB |
2020 | enum bp_loc_type loc_type; |
2021 | struct bp_location *bl; | |
a5606eee | 2022 | |
a9634178 | 2023 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2024 | |
2025 | if (reg_cnt) | |
9fa40276 TJB |
2026 | { |
2027 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2028 | enum bptype type; |
9fa40276 | 2029 | |
a9634178 TJB |
2030 | /* Use an exact watchpoint when there's only one memory region to be |
2031 | watched, and only one debug register is needed to watch it. */ | |
2032 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2033 | ||
9fa40276 | 2034 | /* We need to determine how many resources are already |
e09342b5 TJB |
2035 | used for all other hardware watchpoints plus this one |
2036 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2037 | this watchpoint in as well. */ |
2038 | ||
2039 | /* If this is a software watchpoint, we try to turn it | |
2040 | to a hardware one -- count resources as if B was of | |
2041 | hardware watchpoint type. */ | |
2042 | type = b->base.type; | |
2043 | if (type == bp_watchpoint) | |
2044 | type = bp_hardware_watchpoint; | |
2045 | ||
2046 | /* This watchpoint may or may not have been placed on | |
2047 | the list yet at this point (it won't be in the list | |
2048 | if we're trying to create it for the first time, | |
2049 | through watch_command), so always account for it | |
2050 | manually. */ | |
2051 | ||
2052 | /* Count resources used by all watchpoints except B. */ | |
2053 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
2054 | ||
2055 | /* Add in the resources needed for B. */ | |
2056 | i += hw_watchpoint_use_count (&b->base); | |
2057 | ||
2058 | target_resources_ok | |
2059 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2060 | if (target_resources_ok <= 0) |
a9634178 | 2061 | { |
3a5c3e22 | 2062 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
2063 | |
2064 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2065 | error (_("Target does not support this type of " |
2066 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2067 | else if (target_resources_ok < 0 && !sw_mode) |
2068 | error (_("There are not enough available hardware " | |
2069 | "resources for this watchpoint.")); | |
a1398e0c PA |
2070 | |
2071 | /* Downgrade to software watchpoint. */ | |
2072 | b->base.type = bp_watchpoint; | |
2073 | } | |
2074 | else | |
2075 | { | |
2076 | /* If this was a software watchpoint, we've just | |
2077 | found we have enough resources to turn it to a | |
2078 | hardware watchpoint. Otherwise, this is a | |
2079 | nop. */ | |
2080 | b->base.type = type; | |
a9634178 | 2081 | } |
9fa40276 | 2082 | } |
3a5c3e22 | 2083 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2084 | { |
2085 | if (!can_use_hw_watchpoints) | |
2086 | error (_("Can't set read/access watchpoint when " | |
2087 | "hardware watchpoints are disabled.")); | |
2088 | else | |
2089 | error (_("Expression cannot be implemented with " | |
2090 | "read/access watchpoint.")); | |
2091 | } | |
9fa40276 | 2092 | else |
3a5c3e22 | 2093 | b->base.type = bp_watchpoint; |
9fa40276 | 2094 | |
3a5c3e22 | 2095 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2096 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2097 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2098 | bl->loc_type = loc_type; |
2099 | } | |
2100 | ||
2101 | for (v = val_chain; v; v = next) | |
2102 | { | |
a5606eee VP |
2103 | next = value_next (v); |
2104 | if (v != b->val) | |
2105 | value_free (v); | |
2106 | } | |
2107 | ||
c7437ca6 PA |
2108 | /* If a software watchpoint is not watching any memory, then the |
2109 | above left it without any location set up. But, | |
2110 | bpstat_stop_status requires a location to be able to report | |
2111 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2112 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 2113 | { |
3a5c3e22 PA |
2114 | struct breakpoint *base = &b->base; |
2115 | base->loc = allocate_bp_location (base); | |
2116 | base->loc->pspace = frame_pspace; | |
2117 | base->loc->address = -1; | |
2118 | base->loc->length = -1; | |
2119 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 2120 | } |
a5606eee VP |
2121 | } |
2122 | else if (!within_current_scope) | |
7270d8f2 | 2123 | { |
ac74f770 MS |
2124 | printf_filtered (_("\ |
2125 | Watchpoint %d deleted because the program has left the block\n\ | |
2126 | in which its expression is valid.\n"), | |
3a5c3e22 | 2127 | b->base.number); |
d0fb5eae | 2128 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2129 | } |
a5606eee VP |
2130 | |
2131 | /* Restore the selected frame. */ | |
66076460 DJ |
2132 | if (frame_saved) |
2133 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2134 | } |
2135 | ||
a5606eee | 2136 | |
74960c60 | 2137 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2138 | inserted in the inferior. We don't differentiate the type of BL's owner |
2139 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2140 | breakpoint_ops is not defined, because in insert_bp_location, | |
2141 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2142 | static int |
35df4500 | 2143 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2144 | { |
35df4500 | 2145 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2146 | return 0; |
2147 | ||
35df4500 | 2148 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2149 | return 0; |
2150 | ||
35df4500 | 2151 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2152 | return 0; |
2153 | ||
f8eba3c6 TT |
2154 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2155 | return 0; | |
2156 | ||
56710373 PA |
2157 | /* This is set for example, when we're attached to the parent of a |
2158 | vfork, and have detached from the child. The child is running | |
2159 | free, and we expect it to do an exec or exit, at which point the | |
2160 | OS makes the parent schedulable again (and the target reports | |
2161 | that the vfork is done). Until the child is done with the shared | |
2162 | memory region, do not insert breakpoints in the parent, otherwise | |
2163 | the child could still trip on the parent's breakpoints. Since | |
2164 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2165 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2166 | return 0; |
2167 | ||
31e77af2 PA |
2168 | /* Don't insert a breakpoint if we're trying to step past its |
2169 | location. */ | |
2170 | if ((bl->loc_type == bp_loc_software_breakpoint | |
2171 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2172 | && stepping_past_instruction_at (bl->pspace->aspace, | |
2173 | bl->address)) | |
e558d7c1 PA |
2174 | { |
2175 | if (debug_infrun) | |
2176 | { | |
2177 | fprintf_unfiltered (gdb_stdlog, | |
2178 | "infrun: skipping breakpoint: " | |
2179 | "stepping past insn at: %s\n", | |
2180 | paddress (bl->gdbarch, bl->address)); | |
2181 | } | |
2182 | return 0; | |
2183 | } | |
31e77af2 | 2184 | |
963f9c80 PA |
2185 | /* Don't insert watchpoints if we're trying to step past the |
2186 | instruction that triggered one. */ | |
2187 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2188 | && stepping_past_nonsteppable_watchpoint ()) | |
2189 | { | |
2190 | if (debug_infrun) | |
2191 | { | |
2192 | fprintf_unfiltered (gdb_stdlog, | |
2193 | "infrun: stepping past non-steppable watchpoint. " | |
2194 | "skipping watchpoint at %s:%d\n", | |
2195 | paddress (bl->gdbarch, bl->address), | |
2196 | bl->length); | |
2197 | } | |
2198 | return 0; | |
2199 | } | |
2200 | ||
74960c60 VP |
2201 | return 1; |
2202 | } | |
2203 | ||
934709f0 PW |
2204 | /* Same as should_be_inserted but does the check assuming |
2205 | that the location is not duplicated. */ | |
2206 | ||
2207 | static int | |
2208 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2209 | { | |
2210 | int result; | |
2211 | const int save_duplicate = bl->duplicate; | |
2212 | ||
2213 | bl->duplicate = 0; | |
2214 | result = should_be_inserted (bl); | |
2215 | bl->duplicate = save_duplicate; | |
2216 | return result; | |
2217 | } | |
2218 | ||
b775012e LM |
2219 | /* Parses a conditional described by an expression COND into an |
2220 | agent expression bytecode suitable for evaluation | |
2221 | by the bytecode interpreter. Return NULL if there was | |
2222 | any error during parsing. */ | |
2223 | ||
2224 | static struct agent_expr * | |
2225 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2226 | { | |
2227 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2228 | volatile struct gdb_exception ex; |
2229 | ||
2230 | if (!cond) | |
2231 | return NULL; | |
2232 | ||
2233 | /* We don't want to stop processing, so catch any errors | |
2234 | that may show up. */ | |
2235 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2236 | { | |
2237 | aexpr = gen_eval_for_expr (scope, cond); | |
2238 | } | |
2239 | ||
2240 | if (ex.reason < 0) | |
2241 | { | |
2242 | /* If we got here, it means the condition could not be parsed to a valid | |
2243 | bytecode expression and thus can't be evaluated on the target's side. | |
2244 | It's no use iterating through the conditions. */ | |
2245 | return NULL; | |
2246 | } | |
2247 | ||
2248 | /* We have a valid agent expression. */ | |
2249 | return aexpr; | |
2250 | } | |
2251 | ||
2252 | /* Based on location BL, create a list of breakpoint conditions to be | |
2253 | passed on to the target. If we have duplicated locations with different | |
2254 | conditions, we will add such conditions to the list. The idea is that the | |
2255 | target will evaluate the list of conditions and will only notify GDB when | |
2256 | one of them is true. */ | |
2257 | ||
2258 | static void | |
2259 | build_target_condition_list (struct bp_location *bl) | |
2260 | { | |
2261 | struct bp_location **locp = NULL, **loc2p; | |
2262 | int null_condition_or_parse_error = 0; | |
2263 | int modified = bl->needs_update; | |
2264 | struct bp_location *loc; | |
2265 | ||
8b4f3082 PA |
2266 | /* Release conditions left over from a previous insert. */ |
2267 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2268 | ||
b775012e LM |
2269 | /* This is only meaningful if the target is |
2270 | evaluating conditions and if the user has | |
2271 | opted for condition evaluation on the target's | |
2272 | side. */ | |
2273 | if (gdb_evaluates_breakpoint_condition_p () | |
2274 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2275 | return; | |
2276 | ||
2277 | /* Do a first pass to check for locations with no assigned | |
2278 | conditions or conditions that fail to parse to a valid agent expression | |
2279 | bytecode. If any of these happen, then it's no use to send conditions | |
2280 | to the target since this location will always trigger and generate a | |
2281 | response back to GDB. */ | |
2282 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2283 | { | |
2284 | loc = (*loc2p); | |
2285 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2286 | { | |
2287 | if (modified) | |
2288 | { | |
2289 | struct agent_expr *aexpr; | |
2290 | ||
2291 | /* Re-parse the conditions since something changed. In that | |
2292 | case we already freed the condition bytecodes (see | |
2293 | force_breakpoint_reinsertion). We just | |
2294 | need to parse the condition to bytecodes again. */ | |
2295 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2296 | loc->cond_bytecode = aexpr; | |
2297 | ||
2298 | /* Check if we managed to parse the conditional expression | |
2299 | correctly. If not, we will not send this condition | |
2300 | to the target. */ | |
2301 | if (aexpr) | |
2302 | continue; | |
2303 | } | |
2304 | ||
2305 | /* If we have a NULL bytecode expression, it means something | |
2306 | went wrong or we have a null condition expression. */ | |
2307 | if (!loc->cond_bytecode) | |
2308 | { | |
2309 | null_condition_or_parse_error = 1; | |
2310 | break; | |
2311 | } | |
2312 | } | |
2313 | } | |
2314 | ||
2315 | /* If any of these happened, it means we will have to evaluate the conditions | |
2316 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2317 | for all the other duplicate locations, thus we free all of them here. | |
2318 | ||
2319 | This is so we have a finer control over which locations' conditions are | |
2320 | being evaluated by GDB or the remote stub. */ | |
2321 | if (null_condition_or_parse_error) | |
2322 | { | |
2323 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2324 | { | |
2325 | loc = (*loc2p); | |
2326 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2327 | { | |
2328 | /* Only go as far as the first NULL bytecode is | |
2329 | located. */ | |
2330 | if (!loc->cond_bytecode) | |
2331 | return; | |
2332 | ||
2333 | free_agent_expr (loc->cond_bytecode); | |
2334 | loc->cond_bytecode = NULL; | |
2335 | } | |
2336 | } | |
2337 | } | |
2338 | ||
2339 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2340 | for this location's address. */ | |
2341 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2342 | { | |
2343 | loc = (*loc2p); | |
2344 | if (loc->cond | |
2345 | && is_breakpoint (loc->owner) | |
2346 | && loc->pspace->num == bl->pspace->num | |
2347 | && loc->owner->enable_state == bp_enabled | |
2348 | && loc->enabled) | |
2349 | /* Add the condition to the vector. This will be used later to send the | |
2350 | conditions to the target. */ | |
2351 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2352 | loc->cond_bytecode); | |
2353 | } | |
2354 | ||
2355 | return; | |
2356 | } | |
2357 | ||
d3ce09f5 SS |
2358 | /* Parses a command described by string CMD into an agent expression |
2359 | bytecode suitable for evaluation by the bytecode interpreter. | |
2360 | Return NULL if there was any error during parsing. */ | |
2361 | ||
2362 | static struct agent_expr * | |
2363 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2364 | { | |
2365 | struct cleanup *old_cleanups = 0; | |
2366 | struct expression *expr, **argvec; | |
2367 | struct agent_expr *aexpr = NULL; | |
d3ce09f5 | 2368 | volatile struct gdb_exception ex; |
bbc13ae3 KS |
2369 | const char *cmdrest; |
2370 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2371 | struct format_piece *fpieces; |
2372 | int nargs; | |
2373 | struct gdbarch *gdbarch = get_current_arch (); | |
2374 | ||
2375 | if (!cmd) | |
2376 | return NULL; | |
2377 | ||
2378 | cmdrest = cmd; | |
2379 | ||
2380 | if (*cmdrest == ',') | |
2381 | ++cmdrest; | |
bbc13ae3 | 2382 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2383 | |
2384 | if (*cmdrest++ != '"') | |
2385 | error (_("No format string following the location")); | |
2386 | ||
2387 | format_start = cmdrest; | |
2388 | ||
2389 | fpieces = parse_format_string (&cmdrest); | |
2390 | ||
2391 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2392 | ||
2393 | format_end = cmdrest; | |
2394 | ||
2395 | if (*cmdrest++ != '"') | |
2396 | error (_("Bad format string, non-terminated '\"'.")); | |
2397 | ||
bbc13ae3 | 2398 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2399 | |
2400 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2401 | error (_("Invalid argument syntax")); | |
2402 | ||
2403 | if (*cmdrest == ',') | |
2404 | cmdrest++; | |
bbc13ae3 | 2405 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2406 | |
2407 | /* For each argument, make an expression. */ | |
2408 | ||
2409 | argvec = (struct expression **) alloca (strlen (cmd) | |
2410 | * sizeof (struct expression *)); | |
2411 | ||
2412 | nargs = 0; | |
2413 | while (*cmdrest != '\0') | |
2414 | { | |
bbc13ae3 | 2415 | const char *cmd1; |
d3ce09f5 SS |
2416 | |
2417 | cmd1 = cmdrest; | |
2418 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2419 | argvec[nargs++] = expr; | |
2420 | cmdrest = cmd1; | |
2421 | if (*cmdrest == ',') | |
2422 | ++cmdrest; | |
2423 | } | |
2424 | ||
2425 | /* We don't want to stop processing, so catch any errors | |
2426 | that may show up. */ | |
2427 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
2428 | { | |
2429 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2430 | format_start, format_end - format_start, | |
2431 | fpieces, nargs, argvec); | |
2432 | } | |
2433 | ||
752eb8b4 TT |
2434 | do_cleanups (old_cleanups); |
2435 | ||
d3ce09f5 SS |
2436 | if (ex.reason < 0) |
2437 | { | |
2438 | /* If we got here, it means the command could not be parsed to a valid | |
2439 | bytecode expression and thus can't be evaluated on the target's side. | |
2440 | It's no use iterating through the other commands. */ | |
2441 | return NULL; | |
2442 | } | |
2443 | ||
d3ce09f5 SS |
2444 | /* We have a valid agent expression, return it. */ |
2445 | return aexpr; | |
2446 | } | |
2447 | ||
2448 | /* Based on location BL, create a list of breakpoint commands to be | |
2449 | passed on to the target. If we have duplicated locations with | |
2450 | different commands, we will add any such to the list. */ | |
2451 | ||
2452 | static void | |
2453 | build_target_command_list (struct bp_location *bl) | |
2454 | { | |
2455 | struct bp_location **locp = NULL, **loc2p; | |
2456 | int null_command_or_parse_error = 0; | |
2457 | int modified = bl->needs_update; | |
2458 | struct bp_location *loc; | |
2459 | ||
8b4f3082 PA |
2460 | /* Release commands left over from a previous insert. */ |
2461 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2462 | ||
41fac0cf | 2463 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2464 | return; |
2465 | ||
41fac0cf PA |
2466 | /* For now, limit to agent-style dprintf breakpoints. */ |
2467 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2468 | return; |
2469 | ||
41fac0cf PA |
2470 | /* For now, if we have any duplicate location that isn't a dprintf, |
2471 | don't install the target-side commands, as that would make the | |
2472 | breakpoint not be reported to the core, and we'd lose | |
2473 | control. */ | |
2474 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2475 | { | |
2476 | loc = (*loc2p); | |
2477 | if (is_breakpoint (loc->owner) | |
2478 | && loc->pspace->num == bl->pspace->num | |
2479 | && loc->owner->type != bp_dprintf) | |
2480 | return; | |
2481 | } | |
2482 | ||
d3ce09f5 SS |
2483 | /* Do a first pass to check for locations with no assigned |
2484 | conditions or conditions that fail to parse to a valid agent expression | |
2485 | bytecode. If any of these happen, then it's no use to send conditions | |
2486 | to the target since this location will always trigger and generate a | |
2487 | response back to GDB. */ | |
2488 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2489 | { | |
2490 | loc = (*loc2p); | |
2491 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2492 | { | |
2493 | if (modified) | |
2494 | { | |
2495 | struct agent_expr *aexpr; | |
2496 | ||
2497 | /* Re-parse the commands since something changed. In that | |
2498 | case we already freed the command bytecodes (see | |
2499 | force_breakpoint_reinsertion). We just | |
2500 | need to parse the command to bytecodes again. */ | |
2501 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2502 | loc->owner->extra_string); | |
2503 | loc->cmd_bytecode = aexpr; | |
2504 | ||
2505 | if (!aexpr) | |
2506 | continue; | |
2507 | } | |
2508 | ||
2509 | /* If we have a NULL bytecode expression, it means something | |
2510 | went wrong or we have a null command expression. */ | |
2511 | if (!loc->cmd_bytecode) | |
2512 | { | |
2513 | null_command_or_parse_error = 1; | |
2514 | break; | |
2515 | } | |
2516 | } | |
2517 | } | |
2518 | ||
2519 | /* If anything failed, then we're not doing target-side commands, | |
2520 | and so clean up. */ | |
2521 | if (null_command_or_parse_error) | |
2522 | { | |
2523 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2524 | { | |
2525 | loc = (*loc2p); | |
2526 | if (is_breakpoint (loc->owner) | |
2527 | && loc->pspace->num == bl->pspace->num) | |
2528 | { | |
2529 | /* Only go as far as the first NULL bytecode is | |
2530 | located. */ | |
40fb6c5e | 2531 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2532 | return; |
2533 | ||
40fb6c5e HZ |
2534 | free_agent_expr (loc->cmd_bytecode); |
2535 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2536 | } |
2537 | } | |
2538 | } | |
2539 | ||
2540 | /* No NULL commands or failed bytecode generation. Build a command list | |
2541 | for this location's address. */ | |
2542 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2543 | { | |
2544 | loc = (*loc2p); | |
2545 | if (loc->owner->extra_string | |
2546 | && is_breakpoint (loc->owner) | |
2547 | && loc->pspace->num == bl->pspace->num | |
2548 | && loc->owner->enable_state == bp_enabled | |
2549 | && loc->enabled) | |
2550 | /* Add the command to the vector. This will be used later | |
2551 | to send the commands to the target. */ | |
2552 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2553 | loc->cmd_bytecode); | |
2554 | } | |
2555 | ||
2556 | bl->target_info.persist = 0; | |
2557 | /* Maybe flag this location as persistent. */ | |
2558 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2559 | bl->target_info.persist = 1; | |
2560 | } | |
2561 | ||
35df4500 TJB |
2562 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2563 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2564 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2565 | Returns 0 for success, 1 if the bp_location type is not supported or |
2566 | -1 for failure. | |
879bfdc2 | 2567 | |
4a64f543 MS |
2568 | NOTE drow/2003-09-09: This routine could be broken down to an |
2569 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2570 | static int |
35df4500 | 2571 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2572 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2573 | int *disabled_breaks, |
dd61ec5c MW |
2574 | int *hw_breakpoint_error, |
2575 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2576 | { |
0000e5cc PA |
2577 | enum errors bp_err = GDB_NO_ERROR; |
2578 | const char *bp_err_message = NULL; | |
c90a6fb7 | 2579 | volatile struct gdb_exception e; |
879bfdc2 | 2580 | |
b775012e | 2581 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2582 | return 0; |
2583 | ||
35c63cd8 JB |
2584 | /* Note we don't initialize bl->target_info, as that wipes out |
2585 | the breakpoint location's shadow_contents if the breakpoint | |
2586 | is still inserted at that location. This in turn breaks | |
2587 | target_read_memory which depends on these buffers when | |
2588 | a memory read is requested at the breakpoint location: | |
2589 | Once the target_info has been wiped, we fail to see that | |
2590 | we have a breakpoint inserted at that address and thus | |
2591 | read the breakpoint instead of returning the data saved in | |
2592 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2593 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2594 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2595 | bl->target_info.length = bl->length; |
8181d85f | 2596 | |
b775012e LM |
2597 | /* When working with target-side conditions, we must pass all the conditions |
2598 | for the same breakpoint address down to the target since GDB will not | |
2599 | insert those locations. With a list of breakpoint conditions, the target | |
2600 | can decide when to stop and notify GDB. */ | |
2601 | ||
2602 | if (is_breakpoint (bl->owner)) | |
2603 | { | |
2604 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2605 | build_target_command_list (bl); |
2606 | /* Reset the modification marker. */ | |
b775012e LM |
2607 | bl->needs_update = 0; |
2608 | } | |
2609 | ||
35df4500 TJB |
2610 | if (bl->loc_type == bp_loc_software_breakpoint |
2611 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2612 | { |
35df4500 | 2613 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2614 | { |
2615 | /* If the explicitly specified breakpoint type | |
2616 | is not hardware breakpoint, check the memory map to see | |
2617 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2618 | |
765dc015 VP |
2619 | Two important cases are: |
2620 | - location type is not hardware breakpoint, memory | |
2621 | is readonly. We change the type of the location to | |
2622 | hardware breakpoint. | |
4a64f543 MS |
2623 | - location type is hardware breakpoint, memory is |
2624 | read-write. This means we've previously made the | |
2625 | location hardware one, but then the memory map changed, | |
2626 | so we undo. | |
765dc015 | 2627 | |
4a64f543 MS |
2628 | When breakpoints are removed, remove_breakpoints will use |
2629 | location types we've just set here, the only possible | |
2630 | problem is that memory map has changed during running | |
2631 | program, but it's not going to work anyway with current | |
2632 | gdb. */ | |
765dc015 | 2633 | struct mem_region *mr |
0d5ed153 | 2634 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2635 | |
2636 | if (mr) | |
2637 | { | |
2638 | if (automatic_hardware_breakpoints) | |
2639 | { | |
765dc015 VP |
2640 | enum bp_loc_type new_type; |
2641 | ||
2642 | if (mr->attrib.mode != MEM_RW) | |
2643 | new_type = bp_loc_hardware_breakpoint; | |
2644 | else | |
2645 | new_type = bp_loc_software_breakpoint; | |
2646 | ||
35df4500 | 2647 | if (new_type != bl->loc_type) |
765dc015 VP |
2648 | { |
2649 | static int said = 0; | |
cc59ec59 | 2650 | |
35df4500 | 2651 | bl->loc_type = new_type; |
765dc015 VP |
2652 | if (!said) |
2653 | { | |
3e43a32a MS |
2654 | fprintf_filtered (gdb_stdout, |
2655 | _("Note: automatically using " | |
2656 | "hardware breakpoints for " | |
2657 | "read-only addresses.\n")); | |
765dc015 VP |
2658 | said = 1; |
2659 | } | |
2660 | } | |
2661 | } | |
35df4500 | 2662 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2663 | && mr->attrib.mode != MEM_RW) |
2664 | { | |
2665 | fprintf_unfiltered (tmp_error_stream, | |
2666 | _("Cannot insert breakpoint %d.\n" | |
2667 | "Cannot set software breakpoint " | |
2668 | "at read-only address %s\n"), | |
2669 | bl->owner->number, | |
2670 | paddress (bl->gdbarch, bl->address)); | |
2671 | return 1; | |
2672 | } | |
765dc015 VP |
2673 | } |
2674 | } | |
2675 | ||
879bfdc2 DJ |
2676 | /* First check to see if we have to handle an overlay. */ |
2677 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2678 | || bl->section == NULL |
2679 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2680 | { |
2681 | /* No overlay handling: just set the breakpoint. */ | |
dd61ec5c MW |
2682 | TRY_CATCH (e, RETURN_MASK_ALL) |
2683 | { | |
0000e5cc PA |
2684 | int val; |
2685 | ||
dd61ec5c | 2686 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2687 | if (val) |
2688 | bp_err = GENERIC_ERROR; | |
dd61ec5c MW |
2689 | } |
2690 | if (e.reason < 0) | |
2691 | { | |
0000e5cc PA |
2692 | bp_err = e.error; |
2693 | bp_err_message = e.message; | |
dd61ec5c | 2694 | } |
879bfdc2 DJ |
2695 | } |
2696 | else | |
2697 | { | |
4a64f543 | 2698 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2699 | Shall we set a breakpoint at the LMA? */ |
2700 | if (!overlay_events_enabled) | |
2701 | { | |
2702 | /* Yes -- overlay event support is not active, | |
2703 | so we must try to set a breakpoint at the LMA. | |
2704 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2705 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2706 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2707 | bl->owner->number); |
879bfdc2 DJ |
2708 | else |
2709 | { | |
35df4500 TJB |
2710 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2711 | bl->section); | |
879bfdc2 | 2712 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2713 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2714 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2715 | |
2716 | /* No overlay handling: just set the breakpoint. */ | |
2717 | TRY_CATCH (e, RETURN_MASK_ALL) | |
2718 | { | |
2719 | int val; | |
2720 | ||
2721 | val = target_insert_breakpoint (bl->gdbarch, | |
2722 | &bl->overlay_target_info); | |
2723 | if (val) | |
2724 | bp_err = GENERIC_ERROR; | |
2725 | } | |
2726 | if (e.reason < 0) | |
2727 | { | |
2728 | bp_err = e.error; | |
2729 | bp_err_message = e.message; | |
2730 | } | |
2731 | ||
2732 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2733 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2734 | "Overlay breakpoint %d " |
2735 | "failed: in ROM?\n", | |
35df4500 | 2736 | bl->owner->number); |
879bfdc2 DJ |
2737 | } |
2738 | } | |
2739 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2740 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2741 | { |
2742 | /* Yes. This overlay section is mapped into memory. */ | |
dd61ec5c MW |
2743 | TRY_CATCH (e, RETURN_MASK_ALL) |
2744 | { | |
0000e5cc PA |
2745 | int val; |
2746 | ||
dd61ec5c | 2747 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2748 | if (val) |
2749 | bp_err = GENERIC_ERROR; | |
dd61ec5c MW |
2750 | } |
2751 | if (e.reason < 0) | |
2752 | { | |
0000e5cc PA |
2753 | bp_err = e.error; |
2754 | bp_err_message = e.message; | |
dd61ec5c | 2755 | } |
879bfdc2 DJ |
2756 | } |
2757 | else | |
2758 | { | |
2759 | /* No. This breakpoint will not be inserted. | |
2760 | No error, but do not mark the bp as 'inserted'. */ | |
2761 | return 0; | |
2762 | } | |
2763 | } | |
2764 | ||
0000e5cc | 2765 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2766 | { |
2767 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2768 | |
2769 | /* In some cases, we might not be able to insert a | |
2770 | breakpoint in a shared library that has already been | |
2771 | removed, but we have not yet processed the shlib unload | |
2772 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2773 | breakpoint insertion themselves can't tell why the |
2774 | breakpoint insertion failed (e.g., the remote target | |
2775 | doesn't define error codes), so we must treat generic | |
2776 | errors as memory errors. */ | |
0000e5cc | 2777 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2778 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2779 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2780 | || shared_objfile_contains_address_p (bl->pspace, |
2781 | bl->address))) | |
879bfdc2 | 2782 | { |
4a64f543 | 2783 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2784 | bl->shlib_disabled = 1; |
8d3788bd | 2785 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2786 | if (!*disabled_breaks) |
2787 | { | |
2788 | fprintf_unfiltered (tmp_error_stream, | |
2789 | "Cannot insert breakpoint %d.\n", | |
2790 | bl->owner->number); | |
2791 | fprintf_unfiltered (tmp_error_stream, | |
2792 | "Temporarily disabling shared " | |
2793 | "library breakpoints:\n"); | |
2794 | } | |
2795 | *disabled_breaks = 1; | |
879bfdc2 | 2796 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2797 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2798 | return 0; |
879bfdc2 DJ |
2799 | } |
2800 | else | |
879bfdc2 | 2801 | { |
35df4500 | 2802 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2803 | { |
0000e5cc PA |
2804 | *hw_breakpoint_error = 1; |
2805 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2806 | fprintf_unfiltered (tmp_error_stream, |
2807 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2808 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2809 | if (bp_err_message != NULL) | |
2810 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2811 | } |
2812 | else | |
2813 | { | |
0000e5cc PA |
2814 | if (bp_err_message == NULL) |
2815 | { | |
2816 | char *message | |
2817 | = memory_error_message (TARGET_XFER_E_IO, | |
2818 | bl->gdbarch, bl->address); | |
2819 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2820 | ||
2821 | fprintf_unfiltered (tmp_error_stream, | |
2822 | "Cannot insert breakpoint %d.\n" | |
2823 | "%s\n", | |
2824 | bl->owner->number, message); | |
2825 | do_cleanups (old_chain); | |
2826 | } | |
2827 | else | |
2828 | { | |
2829 | fprintf_unfiltered (tmp_error_stream, | |
2830 | "Cannot insert breakpoint %d: %s\n", | |
2831 | bl->owner->number, | |
2832 | bp_err_message); | |
2833 | } | |
879bfdc2 | 2834 | } |
0000e5cc | 2835 | return 1; |
879bfdc2 DJ |
2836 | |
2837 | } | |
2838 | } | |
2839 | else | |
35df4500 | 2840 | bl->inserted = 1; |
879bfdc2 | 2841 | |
0000e5cc | 2842 | return 0; |
879bfdc2 DJ |
2843 | } |
2844 | ||
35df4500 | 2845 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2846 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2847 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2848 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2849 | { |
0000e5cc PA |
2850 | int val; |
2851 | ||
77b06cd7 TJB |
2852 | gdb_assert (bl->owner->ops != NULL |
2853 | && bl->owner->ops->insert_location != NULL); | |
2854 | ||
2855 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2856 | |
2857 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2858 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2859 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2860 | { |
2861 | struct bp_location *loc, **loc_temp; | |
2862 | ||
2863 | /* But don't try to insert it, if there's already another | |
2864 | hw_access location that would be considered a duplicate | |
2865 | of this one. */ | |
2866 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2867 | if (loc != bl |
85d721b8 | 2868 | && loc->watchpoint_type == hw_access |
35df4500 | 2869 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2870 | { |
35df4500 TJB |
2871 | bl->duplicate = 1; |
2872 | bl->inserted = 1; | |
2873 | bl->target_info = loc->target_info; | |
2874 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2875 | val = 0; |
2876 | break; | |
2877 | } | |
2878 | ||
2879 | if (val == 1) | |
2880 | { | |
77b06cd7 TJB |
2881 | bl->watchpoint_type = hw_access; |
2882 | val = bl->owner->ops->insert_location (bl); | |
2883 | ||
2884 | if (val) | |
2885 | /* Back to the original value. */ | |
2886 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2887 | } |
2888 | } | |
2889 | ||
35df4500 | 2890 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2891 | } |
2892 | ||
35df4500 | 2893 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2894 | { |
0000e5cc PA |
2895 | int val; |
2896 | ||
77b06cd7 TJB |
2897 | gdb_assert (bl->owner->ops != NULL |
2898 | && bl->owner->ops->insert_location != NULL); | |
2899 | ||
2900 | val = bl->owner->ops->insert_location (bl); | |
2901 | if (val) | |
2902 | { | |
2903 | bl->owner->enable_state = bp_disabled; | |
2904 | ||
2905 | if (val == 1) | |
2906 | warning (_("\ | |
2907 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2908 | of catchpoint."), bl->owner->number); | |
2909 | else | |
2910 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2911 | } | |
2912 | ||
2913 | bl->inserted = (val == 0); | |
1640b821 DJ |
2914 | |
2915 | /* We've already printed an error message if there was a problem | |
2916 | inserting this catchpoint, and we've disabled the catchpoint, | |
2917 | so just return success. */ | |
2918 | return 0; | |
879bfdc2 DJ |
2919 | } |
2920 | ||
2921 | return 0; | |
2922 | } | |
2923 | ||
6c95b8df PA |
2924 | /* This function is called when program space PSPACE is about to be |
2925 | deleted. It takes care of updating breakpoints to not reference | |
2926 | PSPACE anymore. */ | |
2927 | ||
2928 | void | |
2929 | breakpoint_program_space_exit (struct program_space *pspace) | |
2930 | { | |
2931 | struct breakpoint *b, *b_temp; | |
876fa593 | 2932 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2933 | |
2934 | /* Remove any breakpoint that was set through this program space. */ | |
2935 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2936 | { | |
2937 | if (b->pspace == pspace) | |
2938 | delete_breakpoint (b); | |
2939 | } | |
2940 | ||
2941 | /* Breakpoints set through other program spaces could have locations | |
2942 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2943 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2944 | { |
2945 | struct bp_location *tmp; | |
2946 | ||
2947 | if (loc->pspace == pspace) | |
2948 | { | |
2bdf28a0 | 2949 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2950 | if (loc->owner->loc == loc) |
2951 | loc->owner->loc = loc->next; | |
2952 | else | |
2953 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2954 | if (tmp->next == loc) | |
2955 | { | |
2956 | tmp->next = loc->next; | |
2957 | break; | |
2958 | } | |
2959 | } | |
2960 | } | |
2961 | ||
2962 | /* Now update the global location list to permanently delete the | |
2963 | removed locations above. */ | |
44702360 | 2964 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2965 | } |
2966 | ||
74960c60 VP |
2967 | /* Make sure all breakpoints are inserted in inferior. |
2968 | Throws exception on any error. | |
2969 | A breakpoint that is already inserted won't be inserted | |
2970 | again, so calling this function twice is safe. */ | |
2971 | void | |
2972 | insert_breakpoints (void) | |
2973 | { | |
2974 | struct breakpoint *bpt; | |
2975 | ||
2976 | ALL_BREAKPOINTS (bpt) | |
2977 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2978 | { |
2979 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2980 | ||
2981 | update_watchpoint (w, 0 /* don't reparse. */); | |
2982 | } | |
74960c60 | 2983 | |
04086b45 PA |
2984 | /* Updating watchpoints creates new locations, so update the global |
2985 | location list. Explicitly tell ugll to insert locations and | |
2986 | ignore breakpoints_always_inserted_mode. */ | |
2987 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
2988 | } |
2989 | ||
20388dd6 YQ |
2990 | /* Invoke CALLBACK for each of bp_location. */ |
2991 | ||
2992 | void | |
2993 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2994 | { | |
2995 | struct bp_location *loc, **loc_tmp; | |
2996 | ||
2997 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2998 | { | |
2999 | callback (loc, NULL); | |
3000 | } | |
3001 | } | |
3002 | ||
b775012e LM |
3003 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3004 | target. It is the case with deleting and disabling of breakpoints when using | |
3005 | always-inserted mode. */ | |
3006 | ||
3007 | static void | |
3008 | update_inserted_breakpoint_locations (void) | |
3009 | { | |
3010 | struct bp_location *bl, **blp_tmp; | |
3011 | int error_flag = 0; | |
3012 | int val = 0; | |
3013 | int disabled_breaks = 0; | |
3014 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3015 | int hw_bp_details_reported = 0; |
b775012e LM |
3016 | |
3017 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
3018 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
3019 | ||
3020 | /* Explicitly mark the warning -- this will only be printed if | |
3021 | there was an error. */ | |
3022 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
3023 | ||
3024 | save_current_space_and_thread (); | |
3025 | ||
3026 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3027 | { | |
3028 | /* We only want to update software breakpoints and hardware | |
3029 | breakpoints. */ | |
3030 | if (!is_breakpoint (bl->owner)) | |
3031 | continue; | |
3032 | ||
3033 | /* We only want to update locations that are already inserted | |
3034 | and need updating. This is to avoid unwanted insertion during | |
3035 | deletion of breakpoints. */ | |
3036 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3037 | continue; | |
3038 | ||
3039 | switch_to_program_space_and_thread (bl->pspace); | |
3040 | ||
3041 | /* For targets that support global breakpoints, there's no need | |
3042 | to select an inferior to insert breakpoint to. In fact, even | |
3043 | if we aren't attached to any process yet, we should still | |
3044 | insert breakpoints. */ | |
f5656ead | 3045 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3046 | && ptid_equal (inferior_ptid, null_ptid)) |
3047 | continue; | |
3048 | ||
3049 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 3050 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3051 | if (val) |
3052 | error_flag = val; | |
3053 | } | |
3054 | ||
3055 | if (error_flag) | |
3056 | { | |
3057 | target_terminal_ours_for_output (); | |
3058 | error_stream (tmp_error_stream); | |
3059 | } | |
3060 | ||
3061 | do_cleanups (cleanups); | |
3062 | } | |
3063 | ||
c30eee59 | 3064 | /* Used when starting or continuing the program. */ |
c906108c | 3065 | |
74960c60 VP |
3066 | static void |
3067 | insert_breakpoint_locations (void) | |
c906108c | 3068 | { |
a5606eee | 3069 | struct breakpoint *bpt; |
35df4500 | 3070 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3071 | int error_flag = 0; |
c906108c | 3072 | int val = 0; |
3fbb6ffa | 3073 | int disabled_breaks = 0; |
81d0cc19 | 3074 | int hw_breakpoint_error = 0; |
dd61ec5c | 3075 | int hw_bp_error_explained_already = 0; |
c906108c | 3076 | |
81d0cc19 | 3077 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 3078 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 3079 | |
81d0cc19 GS |
3080 | /* Explicitly mark the warning -- this will only be printed if |
3081 | there was an error. */ | |
3082 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
3083 | |
3084 | save_current_space_and_thread (); | |
3085 | ||
35df4500 | 3086 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3087 | { |
b775012e | 3088 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3089 | continue; |
3090 | ||
4a64f543 MS |
3091 | /* There is no point inserting thread-specific breakpoints if |
3092 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3093 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
3094 | if (bl->owner->thread != -1 |
3095 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
3096 | continue; |
3097 | ||
35df4500 | 3098 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3099 | |
3100 | /* For targets that support global breakpoints, there's no need | |
3101 | to select an inferior to insert breakpoint to. In fact, even | |
3102 | if we aren't attached to any process yet, we should still | |
3103 | insert breakpoints. */ | |
f5656ead | 3104 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3105 | && ptid_equal (inferior_ptid, null_ptid)) |
3106 | continue; | |
3107 | ||
3fbb6ffa | 3108 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3109 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3110 | if (val) |
eacd795a | 3111 | error_flag = val; |
879bfdc2 | 3112 | } |
c906108c | 3113 | |
4a64f543 MS |
3114 | /* If we failed to insert all locations of a watchpoint, remove |
3115 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3116 | ALL_BREAKPOINTS (bpt) |
3117 | { | |
3118 | int some_failed = 0; | |
3119 | struct bp_location *loc; | |
3120 | ||
3121 | if (!is_hardware_watchpoint (bpt)) | |
3122 | continue; | |
3123 | ||
d6b74ac4 | 3124 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3125 | continue; |
74960c60 VP |
3126 | |
3127 | if (bpt->disposition == disp_del_at_next_stop) | |
3128 | continue; | |
a5606eee VP |
3129 | |
3130 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3131 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3132 | { |
3133 | some_failed = 1; | |
3134 | break; | |
3135 | } | |
3136 | if (some_failed) | |
3137 | { | |
3138 | for (loc = bpt->loc; loc; loc = loc->next) | |
3139 | if (loc->inserted) | |
3140 | remove_breakpoint (loc, mark_uninserted); | |
3141 | ||
3142 | hw_breakpoint_error = 1; | |
3143 | fprintf_unfiltered (tmp_error_stream, | |
3144 | "Could not insert hardware watchpoint %d.\n", | |
3145 | bpt->number); | |
eacd795a | 3146 | error_flag = -1; |
a5606eee VP |
3147 | } |
3148 | } | |
3149 | ||
eacd795a | 3150 | if (error_flag) |
81d0cc19 GS |
3151 | { |
3152 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3153 | message about possibly exhausted resources. */ | |
dd61ec5c | 3154 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3155 | { |
c6510018 MS |
3156 | fprintf_unfiltered (tmp_error_stream, |
3157 | "Could not insert hardware breakpoints:\n\ | |
3158 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3159 | } |
81d0cc19 GS |
3160 | target_terminal_ours_for_output (); |
3161 | error_stream (tmp_error_stream); | |
3162 | } | |
f7545552 TT |
3163 | |
3164 | do_cleanups (cleanups); | |
c906108c SS |
3165 | } |
3166 | ||
c30eee59 TJB |
3167 | /* Used when the program stops. |
3168 | Returns zero if successful, or non-zero if there was a problem | |
3169 | removing a breakpoint location. */ | |
3170 | ||
c906108c | 3171 | int |
fba45db2 | 3172 | remove_breakpoints (void) |
c906108c | 3173 | { |
35df4500 | 3174 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3175 | int val = 0; |
c906108c | 3176 | |
35df4500 | 3177 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3178 | { |
1e4d1764 | 3179 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 3180 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 3181 | } |
3a1bae8e | 3182 | return val; |
c906108c SS |
3183 | } |
3184 | ||
49fa26b0 PA |
3185 | /* When a thread exits, remove breakpoints that are related to |
3186 | that thread. */ | |
3187 | ||
3188 | static void | |
3189 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3190 | { | |
3191 | struct breakpoint *b, *b_tmp; | |
3192 | ||
3193 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3194 | { | |
96181529 | 3195 | if (b->thread == tp->num && user_breakpoint_p (b)) |
49fa26b0 PA |
3196 | { |
3197 | b->disposition = disp_del_at_next_stop; | |
3198 | ||
3199 | printf_filtered (_("\ | |
46ecd527 | 3200 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
49fa26b0 PA |
3201 | b->number, tp->num); |
3202 | ||
3203 | /* Hide it from the user. */ | |
3204 | b->number = 0; | |
3205 | } | |
3206 | } | |
3207 | } | |
3208 | ||
6c95b8df PA |
3209 | /* Remove breakpoints of process PID. */ |
3210 | ||
3211 | int | |
3212 | remove_breakpoints_pid (int pid) | |
3213 | { | |
35df4500 | 3214 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3215 | int val; |
3216 | struct inferior *inf = find_inferior_pid (pid); | |
3217 | ||
35df4500 | 3218 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3219 | { |
35df4500 | 3220 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3221 | continue; |
3222 | ||
fc126975 | 3223 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3224 | { |
35df4500 | 3225 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
3226 | if (val != 0) |
3227 | return val; | |
3228 | } | |
3229 | } | |
3230 | return 0; | |
3231 | } | |
3232 | ||
c906108c | 3233 | int |
fba45db2 | 3234 | reattach_breakpoints (int pid) |
c906108c | 3235 | { |
6c95b8df | 3236 | struct cleanup *old_chain; |
35df4500 | 3237 | struct bp_location *bl, **blp_tmp; |
c906108c | 3238 | int val; |
86b887df | 3239 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3240 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3241 | struct inferior *inf; |
3242 | struct thread_info *tp; | |
3243 | ||
3244 | tp = any_live_thread_of_process (pid); | |
3245 | if (tp == NULL) | |
3246 | return 1; | |
3247 | ||
3248 | inf = find_inferior_pid (pid); | |
3249 | old_chain = save_inferior_ptid (); | |
3250 | ||
3251 | inferior_ptid = tp->ptid; | |
a4954f26 | 3252 | |
86b887df | 3253 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3254 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3255 | |
35df4500 | 3256 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3257 | { |
35df4500 | 3258 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3259 | continue; |
3260 | ||
35df4500 | 3261 | if (bl->inserted) |
c5aa993b | 3262 | { |
35df4500 | 3263 | bl->inserted = 0; |
dd61ec5c | 3264 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3265 | if (val != 0) |
3266 | { | |
ce696e05 | 3267 | do_cleanups (old_chain); |
c5aa993b JM |
3268 | return val; |
3269 | } | |
3270 | } | |
3271 | } | |
ce696e05 | 3272 | do_cleanups (old_chain); |
c906108c SS |
3273 | return 0; |
3274 | } | |
3275 | ||
e58b0e63 PA |
3276 | static int internal_breakpoint_number = -1; |
3277 | ||
84f4c1fe PM |
3278 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3279 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3280 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3281 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3282 | breakpoint_count and that value incremented. Internal breakpoints |
3283 | do not set the internal var bpnum. */ | |
3284 | static void | |
3285 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3286 | { | |
3287 | if (internal) | |
3288 | b->number = internal_breakpoint_number--; | |
3289 | else | |
3290 | { | |
3291 | set_breakpoint_count (breakpoint_count + 1); | |
3292 | b->number = breakpoint_count; | |
3293 | } | |
3294 | } | |
3295 | ||
e62c965a | 3296 | static struct breakpoint * |
a6d9a66e | 3297 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3298 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3299 | const struct breakpoint_ops *ops) |
e62c965a | 3300 | { |
e62c965a PP |
3301 | struct symtab_and_line sal; |
3302 | struct breakpoint *b; | |
3303 | ||
4a64f543 | 3304 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3305 | |
3306 | sal.pc = address; | |
3307 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3308 | sal.pspace = current_program_space; |
e62c965a | 3309 | |
06edf0c0 | 3310 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3311 | b->number = internal_breakpoint_number--; |
3312 | b->disposition = disp_donttouch; | |
3313 | ||
3314 | return b; | |
3315 | } | |
3316 | ||
17450429 PP |
3317 | static const char *const longjmp_names[] = |
3318 | { | |
3319 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3320 | }; | |
3321 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3322 | ||
3323 | /* Per-objfile data private to breakpoint.c. */ | |
3324 | struct breakpoint_objfile_data | |
3325 | { | |
3326 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3327 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3328 | |
3329 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3330 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3331 | |
28106bc2 SDJ |
3332 | /* True if we have looked for longjmp probes. */ |
3333 | int longjmp_searched; | |
3334 | ||
3335 | /* SystemTap probe points for longjmp (if any). */ | |
3336 | VEC (probe_p) *longjmp_probes; | |
3337 | ||
17450429 | 3338 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3339 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3340 | |
3341 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3342 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3343 | |
3344 | /* True if we have looked for exception probes. */ | |
3345 | int exception_searched; | |
3346 | ||
3347 | /* SystemTap probe points for unwinding (if any). */ | |
3348 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3349 | }; |
3350 | ||
3351 | static const struct objfile_data *breakpoint_objfile_key; | |
3352 | ||
3353 | /* Minimal symbol not found sentinel. */ | |
3354 | static struct minimal_symbol msym_not_found; | |
3355 | ||
3356 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3357 | ||
3358 | static int | |
3359 | msym_not_found_p (const struct minimal_symbol *msym) | |
3360 | { | |
3361 | return msym == &msym_not_found; | |
3362 | } | |
3363 | ||
3364 | /* Return per-objfile data needed by breakpoint.c. | |
3365 | Allocate the data if necessary. */ | |
3366 | ||
3367 | static struct breakpoint_objfile_data * | |
3368 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3369 | { | |
3370 | struct breakpoint_objfile_data *bp_objfile_data; | |
3371 | ||
3372 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
3373 | if (bp_objfile_data == NULL) | |
3374 | { | |
3375 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
3376 | sizeof (*bp_objfile_data)); | |
3377 | ||
3378 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3379 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3380 | } | |
3381 | return bp_objfile_data; | |
3382 | } | |
3383 | ||
28106bc2 SDJ |
3384 | static void |
3385 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3386 | { | |
3387 | struct breakpoint_objfile_data *bp_objfile_data = data; | |
3388 | ||
3389 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3390 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3391 | } | |
3392 | ||
e62c965a | 3393 | static void |
af02033e | 3394 | create_overlay_event_breakpoint (void) |
e62c965a | 3395 | { |
69de3c6a | 3396 | struct objfile *objfile; |
af02033e | 3397 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3398 | |
69de3c6a PP |
3399 | ALL_OBJFILES (objfile) |
3400 | { | |
3401 | struct breakpoint *b; | |
17450429 PP |
3402 | struct breakpoint_objfile_data *bp_objfile_data; |
3403 | CORE_ADDR addr; | |
69de3c6a | 3404 | |
17450429 PP |
3405 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3406 | ||
3b7344d5 | 3407 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3408 | continue; |
3409 | ||
3b7344d5 | 3410 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3411 | { |
3b7344d5 | 3412 | struct bound_minimal_symbol m; |
17450429 PP |
3413 | |
3414 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3415 | if (m.minsym == NULL) |
17450429 PP |
3416 | { |
3417 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3418 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3419 | continue; |
3420 | } | |
3421 | bp_objfile_data->overlay_msym = m; | |
3422 | } | |
e62c965a | 3423 | |
77e371c0 | 3424 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3425 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3426 | bp_overlay_event, |
3427 | &internal_breakpoint_ops); | |
69de3c6a | 3428 | b->addr_string = xstrdup (func_name); |
e62c965a | 3429 | |
69de3c6a PP |
3430 | if (overlay_debugging == ovly_auto) |
3431 | { | |
3432 | b->enable_state = bp_enabled; | |
3433 | overlay_events_enabled = 1; | |
3434 | } | |
3435 | else | |
3436 | { | |
3437 | b->enable_state = bp_disabled; | |
3438 | overlay_events_enabled = 0; | |
3439 | } | |
e62c965a | 3440 | } |
44702360 | 3441 | update_global_location_list (UGLL_MAY_INSERT); |
e62c965a PP |
3442 | } |
3443 | ||
0fd8e87f | 3444 | static void |
af02033e | 3445 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3446 | { |
6c95b8df | 3447 | struct program_space *pspace; |
6c95b8df PA |
3448 | struct cleanup *old_chain; |
3449 | ||
3450 | old_chain = save_current_program_space (); | |
0fd8e87f | 3451 | |
6c95b8df | 3452 | ALL_PSPACES (pspace) |
af02033e PP |
3453 | { |
3454 | struct objfile *objfile; | |
3455 | ||
3456 | set_current_program_space (pspace); | |
3457 | ||
3458 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3459 | { |
af02033e PP |
3460 | int i; |
3461 | struct gdbarch *gdbarch; | |
17450429 | 3462 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3463 | |
af02033e | 3464 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3465 | |
17450429 PP |
3466 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3467 | ||
28106bc2 SDJ |
3468 | if (!bp_objfile_data->longjmp_searched) |
3469 | { | |
25f9533e SDJ |
3470 | VEC (probe_p) *ret; |
3471 | ||
3472 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3473 | if (ret != NULL) | |
3474 | { | |
3475 | /* We are only interested in checking one element. */ | |
3476 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3477 | ||
3478 | if (!can_evaluate_probe_arguments (p)) | |
3479 | { | |
3480 | /* We cannot use the probe interface here, because it does | |
3481 | not know how to evaluate arguments. */ | |
3482 | VEC_free (probe_p, ret); | |
3483 | ret = NULL; | |
3484 | } | |
3485 | } | |
3486 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3487 | bp_objfile_data->longjmp_searched = 1; |
3488 | } | |
3489 | ||
3490 | if (bp_objfile_data->longjmp_probes != NULL) | |
3491 | { | |
3492 | int i; | |
3493 | struct probe *probe; | |
3494 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3495 | ||
3496 | for (i = 0; | |
3497 | VEC_iterate (probe_p, | |
3498 | bp_objfile_data->longjmp_probes, | |
3499 | i, probe); | |
3500 | ++i) | |
3501 | { | |
3502 | struct breakpoint *b; | |
3503 | ||
729662a5 TT |
3504 | b = create_internal_breakpoint (gdbarch, |
3505 | get_probe_address (probe, | |
3506 | objfile), | |
28106bc2 SDJ |
3507 | bp_longjmp_master, |
3508 | &internal_breakpoint_ops); | |
3509 | b->addr_string = xstrdup ("-probe-stap libc:longjmp"); | |
3510 | b->enable_state = bp_disabled; | |
3511 | } | |
3512 | ||
3513 | continue; | |
3514 | } | |
3515 | ||
0569175e TSD |
3516 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3517 | continue; | |
3518 | ||
17450429 | 3519 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3520 | { |
3521 | struct breakpoint *b; | |
af02033e | 3522 | const char *func_name; |
17450429 | 3523 | CORE_ADDR addr; |
6c95b8df | 3524 | |
3b7344d5 | 3525 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3526 | continue; |
0fd8e87f | 3527 | |
17450429 | 3528 | func_name = longjmp_names[i]; |
3b7344d5 | 3529 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3530 | { |
3b7344d5 | 3531 | struct bound_minimal_symbol m; |
17450429 PP |
3532 | |
3533 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3534 | if (m.minsym == NULL) |
17450429 PP |
3535 | { |
3536 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3537 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3538 | continue; |
3539 | } | |
3540 | bp_objfile_data->longjmp_msym[i] = m; | |
3541 | } | |
3542 | ||
77e371c0 | 3543 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3544 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3545 | &internal_breakpoint_ops); | |
af02033e PP |
3546 | b->addr_string = xstrdup (func_name); |
3547 | b->enable_state = bp_disabled; | |
3548 | } | |
0fd8e87f | 3549 | } |
af02033e | 3550 | } |
44702360 | 3551 | update_global_location_list (UGLL_MAY_INSERT); |
6c95b8df PA |
3552 | |
3553 | do_cleanups (old_chain); | |
0fd8e87f UW |
3554 | } |
3555 | ||
af02033e | 3556 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3557 | static void |
af02033e | 3558 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3559 | { |
3560 | struct program_space *pspace; | |
aa7d318d | 3561 | struct cleanup *old_chain; |
af02033e | 3562 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3563 | |
3564 | old_chain = save_current_program_space (); | |
3565 | ||
3566 | ALL_PSPACES (pspace) | |
17450429 PP |
3567 | { |
3568 | struct objfile *objfile; | |
3569 | CORE_ADDR addr; | |
3570 | ||
3571 | set_current_program_space (pspace); | |
3572 | ||
aa7d318d TT |
3573 | ALL_OBJFILES (objfile) |
3574 | { | |
3575 | struct breakpoint *b; | |
17450429 | 3576 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 3577 | |
17450429 | 3578 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3579 | |
3b7344d5 | 3580 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3581 | continue; |
3582 | ||
3b7344d5 | 3583 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3584 | { |
3b7344d5 | 3585 | struct bound_minimal_symbol m; |
17450429 PP |
3586 | |
3587 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3588 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3589 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3590 | { |
3591 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3592 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3593 | continue; |
3594 | } | |
3595 | bp_objfile_data->terminate_msym = m; | |
3596 | } | |
aa7d318d | 3597 | |
77e371c0 | 3598 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3599 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3600 | bp_std_terminate_master, |
3601 | &internal_breakpoint_ops); | |
aa7d318d TT |
3602 | b->addr_string = xstrdup (func_name); |
3603 | b->enable_state = bp_disabled; | |
3604 | } | |
17450429 PP |
3605 | } |
3606 | ||
44702360 | 3607 | update_global_location_list (UGLL_MAY_INSERT); |
aa7d318d TT |
3608 | |
3609 | do_cleanups (old_chain); | |
3610 | } | |
3611 | ||
186c406b TT |
3612 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3613 | ||
70221824 | 3614 | static void |
186c406b TT |
3615 | create_exception_master_breakpoint (void) |
3616 | { | |
3617 | struct objfile *objfile; | |
17450429 | 3618 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3619 | |
3620 | ALL_OBJFILES (objfile) | |
3621 | { | |
17450429 PP |
3622 | struct breakpoint *b; |
3623 | struct gdbarch *gdbarch; | |
3624 | struct breakpoint_objfile_data *bp_objfile_data; | |
3625 | CORE_ADDR addr; | |
3626 | ||
3627 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3628 | ||
28106bc2 SDJ |
3629 | /* We prefer the SystemTap probe point if it exists. */ |
3630 | if (!bp_objfile_data->exception_searched) | |
3631 | { | |
25f9533e SDJ |
3632 | VEC (probe_p) *ret; |
3633 | ||
3634 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3635 | ||
3636 | if (ret != NULL) | |
3637 | { | |
3638 | /* We are only interested in checking one element. */ | |
3639 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3640 | ||
3641 | if (!can_evaluate_probe_arguments (p)) | |
3642 | { | |
3643 | /* We cannot use the probe interface here, because it does | |
3644 | not know how to evaluate arguments. */ | |
3645 | VEC_free (probe_p, ret); | |
3646 | ret = NULL; | |
3647 | } | |
3648 | } | |
3649 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3650 | bp_objfile_data->exception_searched = 1; |
3651 | } | |
3652 | ||
3653 | if (bp_objfile_data->exception_probes != NULL) | |
3654 | { | |
3655 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3656 | int i; | |
3657 | struct probe *probe; | |
3658 | ||
3659 | for (i = 0; | |
3660 | VEC_iterate (probe_p, | |
3661 | bp_objfile_data->exception_probes, | |
3662 | i, probe); | |
3663 | ++i) | |
3664 | { | |
3665 | struct breakpoint *b; | |
3666 | ||
729662a5 TT |
3667 | b = create_internal_breakpoint (gdbarch, |
3668 | get_probe_address (probe, | |
3669 | objfile), | |
28106bc2 SDJ |
3670 | bp_exception_master, |
3671 | &internal_breakpoint_ops); | |
3672 | b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); | |
3673 | b->enable_state = bp_disabled; | |
3674 | } | |
3675 | ||
3676 | continue; | |
3677 | } | |
3678 | ||
3679 | /* Otherwise, try the hook function. */ | |
3680 | ||
3b7344d5 | 3681 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3682 | continue; |
3683 | ||
3684 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3685 | |
3b7344d5 | 3686 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3687 | { |
3b7344d5 | 3688 | struct bound_minimal_symbol debug_hook; |
186c406b | 3689 | |
17450429 | 3690 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3691 | if (debug_hook.minsym == NULL) |
17450429 | 3692 | { |
3b7344d5 | 3693 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3694 | continue; |
3695 | } | |
3696 | ||
3697 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3698 | } |
17450429 | 3699 | |
77e371c0 | 3700 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3701 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3702 | ¤t_target); | |
06edf0c0 PA |
3703 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3704 | &internal_breakpoint_ops); | |
17450429 PP |
3705 | b->addr_string = xstrdup (func_name); |
3706 | b->enable_state = bp_disabled; | |
186c406b TT |
3707 | } |
3708 | ||
44702360 | 3709 | update_global_location_list (UGLL_MAY_INSERT); |
186c406b TT |
3710 | } |
3711 | ||
c906108c | 3712 | void |
fba45db2 | 3713 | update_breakpoints_after_exec (void) |
c906108c | 3714 | { |
35df4500 | 3715 | struct breakpoint *b, *b_tmp; |
876fa593 | 3716 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3717 | |
25b22b0a PA |
3718 | /* We're about to delete breakpoints from GDB's lists. If the |
3719 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3720 | writing the breakpoints' "shadow contents" back into memory. The | |
3721 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3722 | do that. Instead, the target is responsible from marking | |
3723 | breakpoints out as soon as it detects an exec. We don't do that | |
3724 | here instead, because there may be other attempts to delete | |
3725 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3726 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3727 | if (bploc->pspace == current_program_space) |
3728 | gdb_assert (!bploc->inserted); | |
c906108c | 3729 | |
35df4500 | 3730 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3731 | { |
6c95b8df PA |
3732 | if (b->pspace != current_program_space) |
3733 | continue; | |
3734 | ||
4a64f543 | 3735 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3736 | if (b->type == bp_shlib_event) |
3737 | { | |
3738 | delete_breakpoint (b); | |
3739 | continue; | |
3740 | } | |
c906108c | 3741 | |
4a64f543 | 3742 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3743 | if (b->type == bp_jit_event) |
3744 | { | |
3745 | delete_breakpoint (b); | |
3746 | continue; | |
3747 | } | |
3748 | ||
1900040c | 3749 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3750 | as must overlay event and longjmp master breakpoints. */ |
3751 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3752 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3753 | || b->type == bp_exception_master) | |
c4093a6a JM |
3754 | { |
3755 | delete_breakpoint (b); | |
3756 | continue; | |
3757 | } | |
3758 | ||
4a64f543 | 3759 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3760 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3761 | { |
3762 | delete_breakpoint (b); | |
3763 | continue; | |
3764 | } | |
3765 | ||
7c16b83e PA |
3766 | /* Just like single-step breakpoints. */ |
3767 | if (b->type == bp_single_step) | |
3768 | { | |
3769 | delete_breakpoint (b); | |
3770 | continue; | |
3771 | } | |
3772 | ||
611c83ae PA |
3773 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3774 | after an exec. */ | |
186c406b | 3775 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3776 | || b->type == bp_longjmp_call_dummy |
186c406b | 3777 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3778 | { |
3779 | delete_breakpoint (b); | |
3780 | continue; | |
3781 | } | |
3782 | ||
ce78b96d JB |
3783 | if (b->type == bp_catchpoint) |
3784 | { | |
3785 | /* For now, none of the bp_catchpoint breakpoints need to | |
3786 | do anything at this point. In the future, if some of | |
3787 | the catchpoints need to something, we will need to add | |
3788 | a new method, and call this method from here. */ | |
3789 | continue; | |
3790 | } | |
3791 | ||
c5aa993b JM |
3792 | /* bp_finish is a special case. The only way we ought to be able |
3793 | to see one of these when an exec() has happened, is if the user | |
3794 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3795 | carries them to the call-site of the current callee, by setting | |
3796 | a temporary bp there and resuming. But in this case, the finish | |
3797 | will carry them entirely through the vfork & exec. | |
3798 | ||
3799 | We don't want to allow a bp_finish to remain inserted now. But | |
3800 | we can't safely delete it, 'cause finish_command has a handle to | |
3801 | the bp on a bpstat, and will later want to delete it. There's a | |
3802 | chance (and I've seen it happen) that if we delete the bp_finish | |
3803 | here, that its storage will get reused by the time finish_command | |
3804 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3805 | We really must allow finish_command to delete a bp_finish. | |
3806 | ||
e5dd4106 | 3807 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3808 | it's safe to delete something others may have handles to?" |
3809 | problem, what we'll do here is just uninsert the bp_finish, and | |
3810 | let finish_command delete it. | |
3811 | ||
3812 | (We know the bp_finish is "doomed" in the sense that it's | |
3813 | momentary, and will be deleted as soon as finish_command sees | |
3814 | the inferior stopped. So it doesn't matter that the bp's | |
3815 | address is probably bogus in the new a.out, unlike e.g., the | |
3816 | solib breakpoints.) */ | |
c5aa993b | 3817 | |
c5aa993b JM |
3818 | if (b->type == bp_finish) |
3819 | { | |
3820 | continue; | |
3821 | } | |
3822 | ||
3823 | /* Without a symbolic address, we have little hope of the | |
3824 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3825 | a.out. */ |
c5aa993b JM |
3826 | if (b->addr_string == NULL) |
3827 | { | |
3828 | delete_breakpoint (b); | |
3829 | continue; | |
3830 | } | |
c5aa993b | 3831 | } |
c906108c SS |
3832 | } |
3833 | ||
3834 | int | |
d80ee84f | 3835 | detach_breakpoints (ptid_t ptid) |
c906108c | 3836 | { |
35df4500 | 3837 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3838 | int val = 0; |
ce696e05 | 3839 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3840 | struct inferior *inf = current_inferior (); |
c5aa993b | 3841 | |
dfd4cc63 | 3842 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3843 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3844 | |
6c95b8df | 3845 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3846 | inferior_ptid = ptid; |
35df4500 | 3847 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3848 | { |
35df4500 | 3849 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3850 | continue; |
3851 | ||
bd9673a4 PW |
3852 | /* This function must physically remove breakpoints locations |
3853 | from the specified ptid, without modifying the breakpoint | |
3854 | package's state. Locations of type bp_loc_other are only | |
3855 | maintained at GDB side. So, there is no need to remove | |
3856 | these bp_loc_other locations. Moreover, removing these | |
3857 | would modify the breakpoint package's state. */ | |
3858 | if (bl->loc_type == bp_loc_other) | |
3859 | continue; | |
3860 | ||
35df4500 TJB |
3861 | if (bl->inserted) |
3862 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3863 | } |
d03285ec | 3864 | |
ce696e05 | 3865 | do_cleanups (old_chain); |
3a1bae8e | 3866 | return val; |
c906108c SS |
3867 | } |
3868 | ||
35df4500 | 3869 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3870 | Note that this is used to detach breakpoints from a child fork. |
3871 | When we get here, the child isn't in the inferior list, and neither | |
3872 | do we have objects to represent its address space --- we should | |
35df4500 | 3873 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3874 | |
c906108c | 3875 | static int |
35df4500 | 3876 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3877 | { |
3878 | int val; | |
c5aa993b | 3879 | |
35df4500 TJB |
3880 | /* BL is never in moribund_locations by our callers. */ |
3881 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3882 | |
1a853c52 | 3883 | if (bl->permanent) |
c2c6d25f JM |
3884 | /* Permanent breakpoints cannot be inserted or removed. */ |
3885 | return 0; | |
3886 | ||
74960c60 VP |
3887 | /* The type of none suggests that owner is actually deleted. |
3888 | This should not ever happen. */ | |
35df4500 | 3889 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3890 | |
35df4500 TJB |
3891 | if (bl->loc_type == bp_loc_software_breakpoint |
3892 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3893 | { |
c02f5703 MS |
3894 | /* "Normal" instruction breakpoint: either the standard |
3895 | trap-instruction bp (bp_breakpoint), or a | |
3896 | bp_hardware_breakpoint. */ | |
3897 | ||
3898 | /* First check to see if we have to handle an overlay. */ | |
3899 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3900 | || bl->section == NULL |
3901 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3902 | { |
3903 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3904 | |
3905 | /* If we're trying to uninsert a memory breakpoint that we | |
3906 | know is set in a dynamic object that is marked | |
3907 | shlib_disabled, then either the dynamic object was | |
3908 | removed with "remove-symbol-file" or with | |
3909 | "nosharedlibrary". In the former case, we don't know | |
3910 | whether another dynamic object might have loaded over the | |
3911 | breakpoint's address -- the user might well let us know | |
3912 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3913 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3914 | list of dynamically loaded objects). If we have the |
3915 | breakpoint's shadow memory, that is, this is a software | |
3916 | breakpoint managed by GDB, check whether the breakpoint | |
3917 | is still inserted in memory, to avoid overwriting wrong | |
3918 | code with stale saved shadow contents. Note that HW | |
3919 | breakpoints don't have shadow memory, as they're | |
3920 | implemented using a mechanism that is not dependent on | |
3921 | being able to modify the target's memory, and as such | |
3922 | they should always be removed. */ | |
3923 | if (bl->shlib_disabled | |
3924 | && bl->target_info.shadow_len != 0 | |
3925 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3926 | val = 0; | |
3927 | else | |
3928 | val = bl->owner->ops->remove_location (bl); | |
c02f5703 | 3929 | } |
c906108c SS |
3930 | else |
3931 | { | |
4a64f543 | 3932 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3933 | Did we set a breakpoint at the LMA? */ |
3934 | if (!overlay_events_enabled) | |
3935 | { | |
3936 | /* Yes -- overlay event support is not active, so we | |
3937 | should have set a breakpoint at the LMA. Remove it. | |
3938 | */ | |
c02f5703 MS |
3939 | /* Ignore any failures: if the LMA is in ROM, we will |
3940 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3941 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3942 | target_remove_hw_breakpoint (bl->gdbarch, | |
3943 | &bl->overlay_target_info); | |
c02f5703 | 3944 | else |
35df4500 TJB |
3945 | target_remove_breakpoint (bl->gdbarch, |
3946 | &bl->overlay_target_info); | |
c02f5703 MS |
3947 | } |
3948 | /* Did we set a breakpoint at the VMA? | |
3949 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3950 | if (bl->inserted) |
c906108c | 3951 | { |
c02f5703 MS |
3952 | /* Yes -- remove it. Previously we did not bother to |
3953 | remove the breakpoint if the section had been | |
3954 | unmapped, but let's not rely on that being safe. We | |
3955 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3956 | |
3957 | /* However, we should remove *software* breakpoints only | |
3958 | if the section is still mapped, or else we overwrite | |
3959 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3960 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3961 | || section_is_mapped (bl->section)) | |
3962 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3963 | else |
3964 | val = 0; | |
c906108c | 3965 | } |
c02f5703 MS |
3966 | else |
3967 | { | |
3968 | /* No -- not inserted, so no need to remove. No error. */ | |
3969 | val = 0; | |
3970 | } | |
c906108c | 3971 | } |
879d1e6b | 3972 | |
08351840 PA |
3973 | /* In some cases, we might not be able to remove a breakpoint in |
3974 | a shared library that has already been removed, but we have | |
3975 | not yet processed the shlib unload event. Similarly for an | |
3976 | unloaded add-symbol-file object - the user might not yet have | |
3977 | had the chance to remove-symbol-file it. shlib_disabled will | |
3978 | be set if the library/object has already been removed, but | |
3979 | the breakpoint hasn't been uninserted yet, e.g., after | |
3980 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3981 | always-inserted mode. */ | |
076855f9 | 3982 | if (val |
08351840 PA |
3983 | && (bl->loc_type == bp_loc_software_breakpoint |
3984 | && (bl->shlib_disabled | |
3985 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3986 | || shared_objfile_contains_address_p (bl->pspace, |
3987 | bl->address)))) | |
879d1e6b UW |
3988 | val = 0; |
3989 | ||
c906108c SS |
3990 | if (val) |
3991 | return val; | |
35df4500 | 3992 | bl->inserted = (is == mark_inserted); |
c906108c | 3993 | } |
35df4500 | 3994 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3995 | { |
77b06cd7 TJB |
3996 | gdb_assert (bl->owner->ops != NULL |
3997 | && bl->owner->ops->remove_location != NULL); | |
3998 | ||
35df4500 | 3999 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 4000 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 4001 | |
c906108c | 4002 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 4003 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 4004 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4005 | bl->owner->number); |
c906108c | 4006 | } |
35df4500 TJB |
4007 | else if (bl->owner->type == bp_catchpoint |
4008 | && breakpoint_enabled (bl->owner) | |
4009 | && !bl->duplicate) | |
ce78b96d | 4010 | { |
77b06cd7 TJB |
4011 | gdb_assert (bl->owner->ops != NULL |
4012 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4013 | |
77b06cd7 | 4014 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
4015 | if (val) |
4016 | return val; | |
77b06cd7 | 4017 | |
35df4500 | 4018 | bl->inserted = (is == mark_inserted); |
ce78b96d | 4019 | } |
c906108c SS |
4020 | |
4021 | return 0; | |
4022 | } | |
4023 | ||
6c95b8df | 4024 | static int |
35df4500 | 4025 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
4026 | { |
4027 | int ret; | |
4028 | struct cleanup *old_chain; | |
4029 | ||
35df4500 TJB |
4030 | /* BL is never in moribund_locations by our callers. */ |
4031 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4032 | |
1a853c52 | 4033 | if (bl->permanent) |
6c95b8df PA |
4034 | /* Permanent breakpoints cannot be inserted or removed. */ |
4035 | return 0; | |
4036 | ||
4037 | /* The type of none suggests that owner is actually deleted. | |
4038 | This should not ever happen. */ | |
35df4500 | 4039 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4040 | |
4041 | old_chain = save_current_space_and_thread (); | |
4042 | ||
35df4500 | 4043 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4044 | |
35df4500 | 4045 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
4046 | |
4047 | do_cleanups (old_chain); | |
4048 | return ret; | |
4049 | } | |
4050 | ||
c906108c SS |
4051 | /* Clear the "inserted" flag in all breakpoints. */ |
4052 | ||
25b22b0a | 4053 | void |
fba45db2 | 4054 | mark_breakpoints_out (void) |
c906108c | 4055 | { |
35df4500 | 4056 | struct bp_location *bl, **blp_tmp; |
c906108c | 4057 | |
35df4500 | 4058 | ALL_BP_LOCATIONS (bl, blp_tmp) |
1a853c52 PA |
4059 | if (bl->pspace == current_program_space |
4060 | && !bl->permanent) | |
35df4500 | 4061 | bl->inserted = 0; |
c906108c SS |
4062 | } |
4063 | ||
53a5351d JM |
4064 | /* Clear the "inserted" flag in all breakpoints and delete any |
4065 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4066 | |
4067 | Plus other such housekeeping that has to be done for breakpoints | |
4068 | between runs. | |
4069 | ||
53a5351d JM |
4070 | Note: this function gets called at the end of a run (by |
4071 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4072 | init_wait_for_inferior). */ |
c906108c SS |
4073 | |
4074 | ||
4075 | ||
4076 | void | |
fba45db2 | 4077 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4078 | { |
35df4500 TJB |
4079 | struct breakpoint *b, *b_tmp; |
4080 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 4081 | int ix; |
6c95b8df | 4082 | struct program_space *pspace = current_program_space; |
c906108c | 4083 | |
50c71eaf PA |
4084 | /* If breakpoint locations are shared across processes, then there's |
4085 | nothing to do. */ | |
f5656ead | 4086 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4087 | return; |
4088 | ||
1a853c52 | 4089 | mark_breakpoints_out (); |
075f6582 | 4090 | |
35df4500 | 4091 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4092 | { |
6c95b8df PA |
4093 | if (b->loc && b->loc->pspace != pspace) |
4094 | continue; | |
4095 | ||
c5aa993b JM |
4096 | switch (b->type) |
4097 | { | |
4098 | case bp_call_dummy: | |
e2e4d78b | 4099 | case bp_longjmp_call_dummy: |
c906108c | 4100 | |
c5aa993b | 4101 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4102 | cause problems when the inferior is rerun, so we better get |
4103 | rid of it. */ | |
4104 | ||
4105 | case bp_watchpoint_scope: | |
4106 | ||
4107 | /* Also get rid of scope breakpoints. */ | |
4108 | ||
4109 | case bp_shlib_event: | |
4110 | ||
4111 | /* Also remove solib event breakpoints. Their addresses may | |
4112 | have changed since the last time we ran the program. | |
4113 | Actually we may now be debugging against different target; | |
4114 | and so the solib backend that installed this breakpoint may | |
4115 | not be used in by the target. E.g., | |
4116 | ||
4117 | (gdb) file prog-linux | |
4118 | (gdb) run # native linux target | |
4119 | ... | |
4120 | (gdb) kill | |
4121 | (gdb) file prog-win.exe | |
4122 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4123 | */ | |
c906108c | 4124 | |
f59f708a PA |
4125 | case bp_step_resume: |
4126 | ||
4127 | /* Also remove step-resume breakpoints. */ | |
4128 | ||
7c16b83e PA |
4129 | case bp_single_step: |
4130 | ||
4131 | /* Also remove single-step breakpoints. */ | |
4132 | ||
c5aa993b JM |
4133 | delete_breakpoint (b); |
4134 | break; | |
c906108c | 4135 | |
c5aa993b JM |
4136 | case bp_watchpoint: |
4137 | case bp_hardware_watchpoint: | |
4138 | case bp_read_watchpoint: | |
4139 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4140 | { |
4141 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4142 | |
3a5c3e22 PA |
4143 | /* Likewise for watchpoints on local expressions. */ |
4144 | if (w->exp_valid_block != NULL) | |
4145 | delete_breakpoint (b); | |
4146 | else if (context == inf_starting) | |
4147 | { | |
4148 | /* Reset val field to force reread of starting value in | |
4149 | insert_breakpoints. */ | |
4150 | if (w->val) | |
4151 | value_free (w->val); | |
4152 | w->val = NULL; | |
4153 | w->val_valid = 0; | |
c860120c | 4154 | } |
3a5c3e22 | 4155 | } |
c5aa993b JM |
4156 | break; |
4157 | default: | |
c5aa993b JM |
4158 | break; |
4159 | } | |
4160 | } | |
1c5cfe86 PA |
4161 | |
4162 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4163 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4164 | decref_bp_location (&bl); | |
1c5cfe86 | 4165 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4166 | } |
4167 | ||
6c95b8df PA |
4168 | /* These functions concern about actual breakpoints inserted in the |
4169 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4170 | we need to hop over the bkpt --- so we check for address space | |
4171 | match, not program space. */ | |
4172 | ||
c2c6d25f JM |
4173 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4174 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4175 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4176 | permanent breakpoint. | |
4177 | - When continuing from a location with an ordinary breakpoint, we | |
4178 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4179 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4180 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4181 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4182 | |
c2c6d25f | 4183 | enum breakpoint_here |
6c95b8df | 4184 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4185 | { |
35df4500 | 4186 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4187 | int any_breakpoint_here = 0; |
c906108c | 4188 | |
35df4500 | 4189 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4190 | { |
35df4500 TJB |
4191 | if (bl->loc_type != bp_loc_software_breakpoint |
4192 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4193 | continue; |
4194 | ||
f1310107 | 4195 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4196 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4197 | || bl->permanent) |
f1310107 | 4198 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4199 | { |
4200 | if (overlay_debugging | |
35df4500 TJB |
4201 | && section_is_overlay (bl->section) |
4202 | && !section_is_mapped (bl->section)) | |
075f6582 | 4203 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4204 | else if (bl->permanent) |
075f6582 DJ |
4205 | return permanent_breakpoint_here; |
4206 | else | |
4207 | any_breakpoint_here = 1; | |
4208 | } | |
4209 | } | |
c906108c | 4210 | |
c2c6d25f | 4211 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
4212 | } |
4213 | ||
1c5cfe86 PA |
4214 | /* Return true if there's a moribund breakpoint at PC. */ |
4215 | ||
4216 | int | |
6c95b8df | 4217 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4218 | { |
4219 | struct bp_location *loc; | |
4220 | int ix; | |
4221 | ||
4222 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4223 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4224 | return 1; |
4225 | ||
4226 | return 0; | |
4227 | } | |
c2c6d25f | 4228 | |
f7ce857f PA |
4229 | /* Returns non-zero iff BL is inserted at PC, in address space |
4230 | ASPACE. */ | |
4231 | ||
4232 | static int | |
4233 | bp_location_inserted_here_p (struct bp_location *bl, | |
4234 | struct address_space *aspace, CORE_ADDR pc) | |
4235 | { | |
4236 | if (bl->inserted | |
4237 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4238 | aspace, pc)) | |
4239 | { | |
4240 | if (overlay_debugging | |
4241 | && section_is_overlay (bl->section) | |
4242 | && !section_is_mapped (bl->section)) | |
4243 | return 0; /* unmapped overlay -- can't be a match */ | |
4244 | else | |
4245 | return 1; | |
4246 | } | |
4247 | return 0; | |
4248 | } | |
4249 | ||
a1fd2fa5 | 4250 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4251 | |
4252 | int | |
a1fd2fa5 | 4253 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4254 | { |
f7ce857f PA |
4255 | struct bp_location **blp, **blp_tmp = NULL; |
4256 | struct bp_location *bl; | |
c906108c | 4257 | |
f7ce857f | 4258 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4259 | { |
f7ce857f PA |
4260 | struct bp_location *bl = *blp; |
4261 | ||
35df4500 TJB |
4262 | if (bl->loc_type != bp_loc_software_breakpoint |
4263 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4264 | continue; |
4265 | ||
f7ce857f PA |
4266 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4267 | return 1; | |
c5aa993b | 4268 | } |
c36b740a VP |
4269 | return 0; |
4270 | } | |
4271 | ||
a1fd2fa5 PA |
4272 | /* This function returns non-zero iff there is a software breakpoint |
4273 | inserted at PC. */ | |
c36b740a VP |
4274 | |
4275 | int | |
a1fd2fa5 PA |
4276 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4277 | CORE_ADDR pc) | |
4fa8626c | 4278 | { |
f7ce857f PA |
4279 | struct bp_location **blp, **blp_tmp = NULL; |
4280 | struct bp_location *bl; | |
4fa8626c | 4281 | |
f7ce857f | 4282 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4283 | { |
f7ce857f PA |
4284 | struct bp_location *bl = *blp; |
4285 | ||
35df4500 | 4286 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4287 | continue; |
4288 | ||
f7ce857f PA |
4289 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4290 | return 1; | |
4fa8626c DJ |
4291 | } |
4292 | ||
4293 | return 0; | |
9c02b525 PA |
4294 | } |
4295 | ||
4296 | /* See breakpoint.h. */ | |
4297 | ||
4298 | int | |
4299 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4300 | CORE_ADDR pc) | |
4301 | { | |
4302 | struct bp_location **blp, **blp_tmp = NULL; | |
4303 | struct bp_location *bl; | |
4304 | ||
4305 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4306 | { | |
4307 | struct bp_location *bl = *blp; | |
4308 | ||
4309 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4310 | continue; | |
4311 | ||
4312 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4313 | return 1; | |
4314 | } | |
4315 | ||
4316 | return 0; | |
4fa8626c DJ |
4317 | } |
4318 | ||
9093389c PA |
4319 | int |
4320 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4321 | CORE_ADDR addr, ULONGEST len) | |
4322 | { | |
4323 | struct breakpoint *bpt; | |
4324 | ||
4325 | ALL_BREAKPOINTS (bpt) | |
4326 | { | |
4327 | struct bp_location *loc; | |
4328 | ||
4329 | if (bpt->type != bp_hardware_watchpoint | |
4330 | && bpt->type != bp_access_watchpoint) | |
4331 | continue; | |
4332 | ||
4333 | if (!breakpoint_enabled (bpt)) | |
4334 | continue; | |
4335 | ||
4336 | for (loc = bpt->loc; loc; loc = loc->next) | |
4337 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4338 | { | |
4339 | CORE_ADDR l, h; | |
4340 | ||
4341 | /* Check for intersection. */ | |
4342 | l = max (loc->address, addr); | |
4343 | h = min (loc->address + loc->length, addr + len); | |
4344 | if (l < h) | |
4345 | return 1; | |
4346 | } | |
4347 | } | |
4348 | return 0; | |
4349 | } | |
c906108c | 4350 | \f |
c5aa993b | 4351 | |
c906108c SS |
4352 | /* bpstat stuff. External routines' interfaces are documented |
4353 | in breakpoint.h. */ | |
4354 | ||
4355 | int | |
c326b90e | 4356 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4357 | { |
533be4dd | 4358 | return (ep->type == bp_catchpoint); |
c906108c SS |
4359 | } |
4360 | ||
f431efe5 PA |
4361 | /* Frees any storage that is part of a bpstat. Does not walk the |
4362 | 'next' chain. */ | |
4363 | ||
4364 | static void | |
198757a8 VP |
4365 | bpstat_free (bpstat bs) |
4366 | { | |
4367 | if (bs->old_val != NULL) | |
4368 | value_free (bs->old_val); | |
9add0f1b | 4369 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4370 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4371 | xfree (bs); |
4372 | } | |
4373 | ||
c906108c SS |
4374 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4375 | Also free any storage that is part of a bpstat. */ | |
4376 | ||
4377 | void | |
fba45db2 | 4378 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4379 | { |
4380 | bpstat p; | |
4381 | bpstat q; | |
4382 | ||
4383 | if (bsp == 0) | |
4384 | return; | |
4385 | p = *bsp; | |
4386 | while (p != NULL) | |
4387 | { | |
4388 | q = p->next; | |
198757a8 | 4389 | bpstat_free (p); |
c906108c SS |
4390 | p = q; |
4391 | } | |
4392 | *bsp = NULL; | |
4393 | } | |
4394 | ||
4395 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4396 | is part of the bpstat is copied as well. */ | |
4397 | ||
4398 | bpstat | |
fba45db2 | 4399 | bpstat_copy (bpstat bs) |
c906108c SS |
4400 | { |
4401 | bpstat p = NULL; | |
4402 | bpstat tmp; | |
4403 | bpstat retval = NULL; | |
4404 | ||
4405 | if (bs == NULL) | |
4406 | return bs; | |
4407 | ||
4408 | for (; bs != NULL; bs = bs->next) | |
4409 | { | |
4410 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4411 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4412 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4413 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4414 | if (bs->old_val != NULL) |
3c3185ac JK |
4415 | { |
4416 | tmp->old_val = value_copy (bs->old_val); | |
4417 | release_value (tmp->old_val); | |
4418 | } | |
31cc81e9 | 4419 | |
c906108c SS |
4420 | if (p == NULL) |
4421 | /* This is the first thing in the chain. */ | |
4422 | retval = tmp; | |
4423 | else | |
4424 | p->next = tmp; | |
4425 | p = tmp; | |
4426 | } | |
4427 | p->next = NULL; | |
4428 | return retval; | |
4429 | } | |
4430 | ||
4a64f543 | 4431 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4432 | |
4433 | bpstat | |
fba45db2 | 4434 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4435 | { |
c5aa993b JM |
4436 | if (bsp == NULL) |
4437 | return NULL; | |
c906108c | 4438 | |
c5aa993b JM |
4439 | for (; bsp != NULL; bsp = bsp->next) |
4440 | { | |
f431efe5 | 4441 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4442 | return bsp; |
4443 | } | |
c906108c SS |
4444 | return NULL; |
4445 | } | |
4446 | ||
ab04a2af TT |
4447 | /* See breakpoint.h. */ |
4448 | ||
47591c29 | 4449 | int |
427cd150 | 4450 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4451 | { |
ab04a2af TT |
4452 | for (; bsp != NULL; bsp = bsp->next) |
4453 | { | |
427cd150 TT |
4454 | if (bsp->breakpoint_at == NULL) |
4455 | { | |
4456 | /* A moribund location can never explain a signal other than | |
4457 | GDB_SIGNAL_TRAP. */ | |
4458 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4459 | return 1; |
427cd150 TT |
4460 | } |
4461 | else | |
47591c29 PA |
4462 | { |
4463 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4464 | sig)) | |
4465 | return 1; | |
4466 | } | |
ab04a2af TT |
4467 | } |
4468 | ||
47591c29 | 4469 | return 0; |
ab04a2af TT |
4470 | } |
4471 | ||
4a64f543 MS |
4472 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4473 | stopped at. *BSP upon return is a bpstat which points to the | |
4474 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4475 | good for anything but further calls to bpstat_num). | |
4476 | ||
8671a17b PA |
4477 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4478 | Return -1 if stopped at a breakpoint that has been deleted since | |
4479 | we set it. | |
4480 | Return 1 otherwise. */ | |
c906108c SS |
4481 | |
4482 | int | |
8671a17b | 4483 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4484 | { |
4485 | struct breakpoint *b; | |
4486 | ||
4487 | if ((*bsp) == NULL) | |
4488 | return 0; /* No more breakpoint values */ | |
8671a17b | 4489 | |
4a64f543 MS |
4490 | /* We assume we'll never have several bpstats that correspond to a |
4491 | single breakpoint -- otherwise, this function might return the | |
4492 | same number more than once and this will look ugly. */ | |
f431efe5 | 4493 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4494 | *bsp = (*bsp)->next; |
4495 | if (b == NULL) | |
4496 | return -1; /* breakpoint that's been deleted since */ | |
4497 | ||
4498 | *num = b->number; /* We have its number */ | |
4499 | return 1; | |
c906108c SS |
4500 | } |
4501 | ||
e93ca019 | 4502 | /* See breakpoint.h. */ |
c906108c SS |
4503 | |
4504 | void | |
e93ca019 | 4505 | bpstat_clear_actions (void) |
c906108c | 4506 | { |
e93ca019 JK |
4507 | struct thread_info *tp; |
4508 | bpstat bs; | |
4509 | ||
4510 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4511 | return; | |
4512 | ||
4513 | tp = find_thread_ptid (inferior_ptid); | |
4514 | if (tp == NULL) | |
4515 | return; | |
4516 | ||
4517 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4518 | { |
9add0f1b | 4519 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4520 | |
c906108c SS |
4521 | if (bs->old_val != NULL) |
4522 | { | |
4523 | value_free (bs->old_val); | |
4524 | bs->old_val = NULL; | |
4525 | } | |
4526 | } | |
4527 | } | |
4528 | ||
f3b1572e PA |
4529 | /* Called when a command is about to proceed the inferior. */ |
4530 | ||
4531 | static void | |
4532 | breakpoint_about_to_proceed (void) | |
4533 | { | |
4534 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4535 | { | |
4536 | struct thread_info *tp = inferior_thread (); | |
4537 | ||
4538 | /* Allow inferior function calls in breakpoint commands to not | |
4539 | interrupt the command list. When the call finishes | |
4540 | successfully, the inferior will be standing at the same | |
4541 | breakpoint as if nothing happened. */ | |
16c381f0 | 4542 | if (tp->control.in_infcall) |
f3b1572e PA |
4543 | return; |
4544 | } | |
4545 | ||
4546 | breakpoint_proceeded = 1; | |
4547 | } | |
4548 | ||
4a64f543 MS |
4549 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4550 | command. */ | |
c906108c | 4551 | static void |
4efb68b1 | 4552 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4553 | { |
4554 | executing_breakpoint_commands = 0; | |
4555 | } | |
4556 | ||
abf85f46 JK |
4557 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4558 | or its equivalent. */ | |
4559 | ||
4560 | static int | |
4561 | command_line_is_silent (struct command_line *cmd) | |
4562 | { | |
4563 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
4564 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
4565 | } | |
4566 | ||
4a64f543 MS |
4567 | /* Execute all the commands associated with all the breakpoints at |
4568 | this location. Any of these commands could cause the process to | |
4569 | proceed beyond this point, etc. We look out for such changes by | |
4570 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4571 | |
347bddb7 PA |
4572 | Returns true if a breakpoint command resumed the inferior. In that |
4573 | case, it is the caller's responsibility to recall it again with the | |
4574 | bpstat of the current thread. */ | |
4575 | ||
4576 | static int | |
4577 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4578 | { |
4579 | bpstat bs; | |
4580 | struct cleanup *old_chain; | |
347bddb7 | 4581 | int again = 0; |
c906108c SS |
4582 | |
4583 | /* Avoid endless recursion if a `source' command is contained | |
4584 | in bs->commands. */ | |
4585 | if (executing_breakpoint_commands) | |
347bddb7 | 4586 | return 0; |
c906108c SS |
4587 | |
4588 | executing_breakpoint_commands = 1; | |
4589 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4590 | ||
cf6c5ffb TT |
4591 | prevent_dont_repeat (); |
4592 | ||
4a64f543 | 4593 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4594 | bs = *bsp; |
4595 | ||
4596 | breakpoint_proceeded = 0; | |
4597 | for (; bs != NULL; bs = bs->next) | |
4598 | { | |
9add0f1b | 4599 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4600 | struct command_line *cmd; |
4601 | struct cleanup *this_cmd_tree_chain; | |
4602 | ||
4603 | /* Take ownership of the BSP's command tree, if it has one. | |
4604 | ||
4605 | The command tree could legitimately contain commands like | |
4606 | 'step' and 'next', which call clear_proceed_status, which | |
4607 | frees stop_bpstat's command tree. To make sure this doesn't | |
4608 | free the tree we're executing out from under us, we need to | |
4609 | take ownership of the tree ourselves. Since a given bpstat's | |
4610 | commands are only executed once, we don't need to copy it; we | |
4611 | can clear the pointer in the bpstat, and make sure we free | |
4612 | the tree when we're done. */ | |
9add0f1b TT |
4613 | ccmd = bs->commands; |
4614 | bs->commands = NULL; | |
abf85f46 JK |
4615 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4616 | cmd = ccmd ? ccmd->commands : NULL; | |
4617 | if (command_line_is_silent (cmd)) | |
4618 | { | |
4619 | /* The action has been already done by bpstat_stop_status. */ | |
4620 | cmd = cmd->next; | |
4621 | } | |
6c50ab1c | 4622 | |
c906108c SS |
4623 | while (cmd != NULL) |
4624 | { | |
4625 | execute_control_command (cmd); | |
4626 | ||
4627 | if (breakpoint_proceeded) | |
4628 | break; | |
4629 | else | |
4630 | cmd = cmd->next; | |
4631 | } | |
6c50ab1c JB |
4632 | |
4633 | /* We can free this command tree now. */ | |
4634 | do_cleanups (this_cmd_tree_chain); | |
4635 | ||
c906108c | 4636 | if (breakpoint_proceeded) |
32c1e744 VP |
4637 | { |
4638 | if (target_can_async_p ()) | |
347bddb7 PA |
4639 | /* If we are in async mode, then the target might be still |
4640 | running, not stopped at any breakpoint, so nothing for | |
4641 | us to do here -- just return to the event loop. */ | |
4642 | ; | |
32c1e744 VP |
4643 | else |
4644 | /* In sync mode, when execute_control_command returns | |
4645 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4646 | Breakpoint commands for that stop were not run, since |
4647 | execute_command does not run breakpoint commands -- | |
4648 | only command_line_handler does, but that one is not | |
4649 | involved in execution of breakpoint commands. So, we | |
4650 | can now execute breakpoint commands. It should be | |
4651 | noted that making execute_command do bpstat actions is | |
4652 | not an option -- in this case we'll have recursive | |
4653 | invocation of bpstat for each breakpoint with a | |
4654 | command, and can easily blow up GDB stack. Instead, we | |
4655 | return true, which will trigger the caller to recall us | |
4656 | with the new stop_bpstat. */ | |
4657 | again = 1; | |
4658 | break; | |
32c1e744 | 4659 | } |
c906108c | 4660 | } |
c2b8ed2c | 4661 | do_cleanups (old_chain); |
347bddb7 PA |
4662 | return again; |
4663 | } | |
4664 | ||
4665 | void | |
4666 | bpstat_do_actions (void) | |
4667 | { | |
353d1d73 JK |
4668 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4669 | ||
347bddb7 PA |
4670 | /* Do any commands attached to breakpoint we are stopped at. */ |
4671 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4672 | && target_has_execution | |
4673 | && !is_exited (inferior_ptid) | |
4674 | && !is_executing (inferior_ptid)) | |
4675 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4676 | and only return when it is stopped at the next breakpoint, we | |
4677 | keep doing breakpoint actions until it returns false to | |
4678 | indicate the inferior was not resumed. */ | |
16c381f0 | 4679 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4680 | break; |
353d1d73 JK |
4681 | |
4682 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4683 | } |
4684 | ||
fa4727a6 DJ |
4685 | /* Print out the (old or new) value associated with a watchpoint. */ |
4686 | ||
4687 | static void | |
4688 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4689 | { | |
4690 | if (val == NULL) | |
4691 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4692 | else | |
79a45b7d TT |
4693 | { |
4694 | struct value_print_options opts; | |
4695 | get_user_print_options (&opts); | |
4696 | value_print (val, stream, &opts); | |
4697 | } | |
fa4727a6 DJ |
4698 | } |
4699 | ||
e514a9d6 | 4700 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4701 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4702 | 'print_it' in the bpstat structure. Under some circumstances we |
4703 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4704 | normal_stop(). */ |
e514a9d6 JM |
4705 | |
4706 | static enum print_stop_action | |
4707 | print_bp_stop_message (bpstat bs) | |
4708 | { | |
4709 | switch (bs->print_it) | |
4710 | { | |
4711 | case print_it_noop: | |
4a64f543 | 4712 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4713 | return PRINT_UNKNOWN; |
4714 | break; | |
4715 | ||
4716 | case print_it_done: | |
4717 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4718 | relevant messages. */ |
e514a9d6 JM |
4719 | return PRINT_SRC_AND_LOC; |
4720 | break; | |
4721 | ||
4722 | case print_it_normal: | |
4f8d1dc6 | 4723 | { |
f431efe5 PA |
4724 | struct breakpoint *b = bs->breakpoint_at; |
4725 | ||
1a6a67de TJB |
4726 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4727 | which has since been deleted. */ | |
4728 | if (b == NULL) | |
4729 | return PRINT_UNKNOWN; | |
4730 | ||
348d480f PA |
4731 | /* Normal case. Call the breakpoint's print_it method. */ |
4732 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4733 | } |
348d480f | 4734 | break; |
3086aeae | 4735 | |
e514a9d6 | 4736 | default: |
8e65ff28 | 4737 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4738 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4739 | break; |
c906108c | 4740 | } |
c906108c SS |
4741 | } |
4742 | ||
edcc5120 TT |
4743 | /* A helper function that prints a shared library stopped event. */ |
4744 | ||
4745 | static void | |
4746 | print_solib_event (int is_catchpoint) | |
4747 | { | |
4748 | int any_deleted | |
4749 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4750 | int any_added | |
4751 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4752 | ||
4753 | if (!is_catchpoint) | |
4754 | { | |
4755 | if (any_added || any_deleted) | |
4756 | ui_out_text (current_uiout, | |
4757 | _("Stopped due to shared library event:\n")); | |
4758 | else | |
4759 | ui_out_text (current_uiout, | |
4760 | _("Stopped due to shared library event (no " | |
4761 | "libraries added or removed)\n")); | |
4762 | } | |
4763 | ||
4764 | if (ui_out_is_mi_like_p (current_uiout)) | |
4765 | ui_out_field_string (current_uiout, "reason", | |
4766 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4767 | ||
4768 | if (any_deleted) | |
4769 | { | |
4770 | struct cleanup *cleanup; | |
4771 | char *name; | |
4772 | int ix; | |
4773 | ||
4774 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4775 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4776 | "removed"); | |
4777 | for (ix = 0; | |
4778 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4779 | ix, name); | |
4780 | ++ix) | |
4781 | { | |
4782 | if (ix > 0) | |
4783 | ui_out_text (current_uiout, " "); | |
4784 | ui_out_field_string (current_uiout, "library", name); | |
4785 | ui_out_text (current_uiout, "\n"); | |
4786 | } | |
4787 | ||
4788 | do_cleanups (cleanup); | |
4789 | } | |
4790 | ||
4791 | if (any_added) | |
4792 | { | |
4793 | struct so_list *iter; | |
4794 | int ix; | |
4795 | struct cleanup *cleanup; | |
4796 | ||
4797 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4798 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4799 | "added"); | |
4800 | for (ix = 0; | |
4801 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4802 | ix, iter); | |
4803 | ++ix) | |
4804 | { | |
4805 | if (ix > 0) | |
4806 | ui_out_text (current_uiout, " "); | |
4807 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4808 | ui_out_text (current_uiout, "\n"); | |
4809 | } | |
4810 | ||
4811 | do_cleanups (cleanup); | |
4812 | } | |
4813 | } | |
4814 | ||
e514a9d6 JM |
4815 | /* Print a message indicating what happened. This is called from |
4816 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4817 | list - a list of the eventpoints that caused this stop. KIND is |
4818 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4819 | routine calls the generic print routine for printing a message |
4820 | about reasons for stopping. This will print (for example) the | |
4821 | "Breakpoint n," part of the output. The return value of this | |
4822 | routine is one of: | |
c906108c | 4823 | |
4a64f543 | 4824 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4825 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4826 | code to print the location. An example is |
c5aa993b JM |
4827 | "Breakpoint 1, " which should be followed by |
4828 | the location. | |
917317f4 | 4829 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4830 | to also print the location part of the message. |
4831 | An example is the catch/throw messages, which | |
4a64f543 | 4832 | don't require a location appended to the end. |
917317f4 | 4833 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4834 | further info to be printed. */ |
c906108c | 4835 | |
917317f4 | 4836 | enum print_stop_action |
36dfb11c | 4837 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4838 | { |
4839 | int val; | |
c5aa993b | 4840 | |
c906108c | 4841 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4842 | (Currently all watchpoints go on the bpstat whether hit or not. |
4843 | That probably could (should) be changed, provided care is taken | |
c906108c | 4844 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4845 | for (; bs; bs = bs->next) |
4846 | { | |
4847 | val = print_bp_stop_message (bs); | |
4848 | if (val == PRINT_SRC_ONLY | |
4849 | || val == PRINT_SRC_AND_LOC | |
4850 | || val == PRINT_NOTHING) | |
4851 | return val; | |
4852 | } | |
c906108c | 4853 | |
36dfb11c TT |
4854 | /* If we had hit a shared library event breakpoint, |
4855 | print_bp_stop_message would print out this message. If we hit an | |
4856 | OS-level shared library event, do the same thing. */ | |
4857 | if (kind == TARGET_WAITKIND_LOADED) | |
4858 | { | |
edcc5120 | 4859 | print_solib_event (0); |
36dfb11c TT |
4860 | return PRINT_NOTHING; |
4861 | } | |
4862 | ||
e514a9d6 | 4863 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4864 | with and nothing was printed. */ |
917317f4 | 4865 | return PRINT_UNKNOWN; |
c906108c SS |
4866 | } |
4867 | ||
c42bd95a DE |
4868 | /* Evaluate the expression EXP and return 1 if value is zero. |
4869 | This returns the inverse of the condition because it is called | |
4870 | from catch_errors which returns 0 if an exception happened, and if an | |
4871 | exception happens we want execution to stop. | |
4a64f543 | 4872 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4873 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4874 | |
4875 | static int | |
4efb68b1 | 4876 | breakpoint_cond_eval (void *exp) |
c906108c | 4877 | { |
278cd55f | 4878 | struct value *mark = value_mark (); |
c5aa993b | 4879 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4880 | |
c906108c SS |
4881 | value_free_to_mark (mark); |
4882 | return i; | |
4883 | } | |
4884 | ||
5760d0ab | 4885 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4886 | |
4887 | static bpstat | |
5760d0ab | 4888 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4889 | { |
4890 | bpstat bs; | |
4891 | ||
4892 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4893 | bs->next = NULL; |
4894 | **bs_link_pointer = bs; | |
4895 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4896 | bs->breakpoint_at = bl->owner; |
4897 | bs->bp_location_at = bl; | |
4898 | incref_bp_location (bl); | |
c906108c SS |
4899 | /* If the condition is false, etc., don't do the commands. */ |
4900 | bs->commands = NULL; | |
4901 | bs->old_val = NULL; | |
4902 | bs->print_it = print_it_normal; | |
4903 | return bs; | |
4904 | } | |
4905 | \f | |
d983da9c DJ |
4906 | /* The target has stopped with waitstatus WS. Check if any hardware |
4907 | watchpoints have triggered, according to the target. */ | |
4908 | ||
4909 | int | |
4910 | watchpoints_triggered (struct target_waitstatus *ws) | |
4911 | { | |
d92524f1 | 4912 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4913 | CORE_ADDR addr; |
4914 | struct breakpoint *b; | |
4915 | ||
4916 | if (!stopped_by_watchpoint) | |
4917 | { | |
4918 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4919 | as not triggered. */ | |
4920 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4921 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4922 | { |
4923 | struct watchpoint *w = (struct watchpoint *) b; | |
4924 | ||
4925 | w->watchpoint_triggered = watch_triggered_no; | |
4926 | } | |
d983da9c DJ |
4927 | |
4928 | return 0; | |
4929 | } | |
4930 | ||
4931 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4932 | { | |
4933 | /* We were stopped by a watchpoint, but we don't know where. | |
4934 | Mark all watchpoints as unknown. */ | |
4935 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4936 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4937 | { |
4938 | struct watchpoint *w = (struct watchpoint *) b; | |
4939 | ||
4940 | w->watchpoint_triggered = watch_triggered_unknown; | |
4941 | } | |
d983da9c | 4942 | |
3c4797ba | 4943 | return 1; |
d983da9c DJ |
4944 | } |
4945 | ||
4946 | /* The target could report the data address. Mark watchpoints | |
4947 | affected by this data address as triggered, and all others as not | |
4948 | triggered. */ | |
4949 | ||
4950 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4951 | if (is_hardware_watchpoint (b)) |
d983da9c | 4952 | { |
3a5c3e22 | 4953 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4954 | struct bp_location *loc; |
d983da9c | 4955 | |
3a5c3e22 | 4956 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4957 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4958 | { |
3a5c3e22 | 4959 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4960 | { |
3a5c3e22 PA |
4961 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4962 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4963 | |
4964 | if (newaddr == start) | |
4965 | { | |
3a5c3e22 | 4966 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4967 | break; |
4968 | } | |
4969 | } | |
4970 | /* Exact match not required. Within range is sufficient. */ | |
4971 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4972 | addr, loc->address, | |
4973 | loc->length)) | |
4974 | { | |
3a5c3e22 | 4975 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4976 | break; |
4977 | } | |
4978 | } | |
d983da9c DJ |
4979 | } |
4980 | ||
4981 | return 1; | |
4982 | } | |
4983 | ||
c906108c SS |
4984 | /* Possible return values for watchpoint_check (this can't be an enum |
4985 | because of check_errors). */ | |
4986 | /* The watchpoint has been deleted. */ | |
4987 | #define WP_DELETED 1 | |
4988 | /* The value has changed. */ | |
4989 | #define WP_VALUE_CHANGED 2 | |
4990 | /* The value has not changed. */ | |
4991 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
4992 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
4993 | #define WP_IGNORE 4 | |
c906108c SS |
4994 | |
4995 | #define BP_TEMPFLAG 1 | |
4996 | #define BP_HARDWAREFLAG 2 | |
4997 | ||
4a64f543 MS |
4998 | /* Evaluate watchpoint condition expression and check if its value |
4999 | changed. | |
553e4c11 JB |
5000 | |
5001 | P should be a pointer to struct bpstat, but is defined as a void * | |
5002 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5003 | |
5004 | static int | |
4efb68b1 | 5005 | watchpoint_check (void *p) |
c906108c SS |
5006 | { |
5007 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5008 | struct watchpoint *b; |
c906108c SS |
5009 | struct frame_info *fr; |
5010 | int within_current_scope; | |
5011 | ||
f431efe5 | 5012 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5013 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5014 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5015 | |
f6bc2008 PA |
5016 | /* If this is a local watchpoint, we only want to check if the |
5017 | watchpoint frame is in scope if the current thread is the thread | |
5018 | that was used to create the watchpoint. */ | |
5019 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5020 | return WP_IGNORE; |
f6bc2008 | 5021 | |
c906108c SS |
5022 | if (b->exp_valid_block == NULL) |
5023 | within_current_scope = 1; | |
5024 | else | |
5025 | { | |
edb3359d DJ |
5026 | struct frame_info *frame = get_current_frame (); |
5027 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5028 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5029 | ||
4a64f543 MS |
5030 | /* in_function_epilogue_p() returns a non-zero value if we're |
5031 | still in the function but the stack frame has already been | |
5032 | invalidated. Since we can't rely on the values of local | |
5033 | variables after the stack has been destroyed, we are treating | |
5034 | the watchpoint in that state as `not changed' without further | |
5035 | checking. Don't mark watchpoints as changed if the current | |
5036 | frame is in an epilogue - even if they are in some other | |
5037 | frame, our view of the stack is likely to be wrong and | |
5038 | frame_find_by_id could error out. */ | |
a0f49112 | 5039 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 5040 | return WP_IGNORE; |
a0f49112 | 5041 | |
101dcfbe | 5042 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5043 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5044 | |
5045 | /* If we've gotten confused in the unwinder, we might have | |
5046 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5047 | if (within_current_scope) |
5048 | { | |
5049 | struct symbol *function; | |
5050 | ||
5051 | function = get_frame_function (fr); | |
5052 | if (function == NULL | |
5053 | || !contained_in (b->exp_valid_block, | |
5054 | SYMBOL_BLOCK_VALUE (function))) | |
5055 | within_current_scope = 0; | |
5056 | } | |
69fbadd5 | 5057 | |
edb3359d | 5058 | if (within_current_scope) |
c906108c SS |
5059 | /* If we end up stopping, the current frame will get selected |
5060 | in normal_stop. So this call to select_frame won't affect | |
5061 | the user. */ | |
0f7d239c | 5062 | select_frame (fr); |
c906108c | 5063 | } |
c5aa993b | 5064 | |
c906108c SS |
5065 | if (within_current_scope) |
5066 | { | |
4a64f543 MS |
5067 | /* We use value_{,free_to_}mark because it could be a *long* |
5068 | time before we return to the command level and call | |
5069 | free_all_values. We can't call free_all_values because we | |
5070 | might be in the middle of evaluating a function call. */ | |
c906108c | 5071 | |
0cf6dd15 | 5072 | int pc = 0; |
9c06b0b4 | 5073 | struct value *mark; |
fa4727a6 DJ |
5074 | struct value *new_val; |
5075 | ||
3a5c3e22 | 5076 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5077 | /* Since we don't know the exact trigger address (from |
5078 | stopped_data_address), just tell the user we've triggered | |
5079 | a mask watchpoint. */ | |
5080 | return WP_VALUE_CHANGED; | |
5081 | ||
5082 | mark = value_mark (); | |
3a1115a0 | 5083 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5084 | |
bb9d5f81 PP |
5085 | if (b->val_bitsize != 0) |
5086 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5087 | ||
4a64f543 MS |
5088 | /* We use value_equal_contents instead of value_equal because |
5089 | the latter coerces an array to a pointer, thus comparing just | |
5090 | the address of the array instead of its contents. This is | |
5091 | not what we want. */ | |
fa4727a6 | 5092 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5093 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5094 | { |
fa4727a6 DJ |
5095 | if (new_val != NULL) |
5096 | { | |
5097 | release_value (new_val); | |
5098 | value_free_to_mark (mark); | |
5099 | } | |
c906108c SS |
5100 | bs->old_val = b->val; |
5101 | b->val = new_val; | |
fa4727a6 | 5102 | b->val_valid = 1; |
c906108c SS |
5103 | return WP_VALUE_CHANGED; |
5104 | } | |
5105 | else | |
5106 | { | |
60e1c644 | 5107 | /* Nothing changed. */ |
c906108c | 5108 | value_free_to_mark (mark); |
c906108c SS |
5109 | return WP_VALUE_NOT_CHANGED; |
5110 | } | |
5111 | } | |
5112 | else | |
5113 | { | |
79a45e25 PA |
5114 | struct ui_out *uiout = current_uiout; |
5115 | ||
c906108c | 5116 | /* This seems like the only logical thing to do because |
c5aa993b JM |
5117 | if we temporarily ignored the watchpoint, then when |
5118 | we reenter the block in which it is valid it contains | |
5119 | garbage (in the case of a function, it may have two | |
5120 | garbage values, one before and one after the prologue). | |
5121 | So we can't even detect the first assignment to it and | |
5122 | watch after that (since the garbage may or may not equal | |
5123 | the first value assigned). */ | |
348d480f PA |
5124 | /* We print all the stop information in |
5125 | breakpoint_ops->print_it, but in this case, by the time we | |
5126 | call breakpoint_ops->print_it this bp will be deleted | |
5127 | already. So we have no choice but print the information | |
5128 | here. */ | |
9dc5e2a9 | 5129 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
5130 | ui_out_field_string |
5131 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 5132 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 5133 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
5134 | ui_out_text (uiout, |
5135 | " deleted because the program has left the block in\n\ | |
8b93c638 | 5136 | which its expression is valid.\n"); |
4ce44c66 | 5137 | |
cdac0397 | 5138 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5139 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5140 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5141 | |
5142 | return WP_DELETED; | |
5143 | } | |
5144 | } | |
5145 | ||
18a18393 | 5146 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5147 | breakpoint location BL. This function does not check if we should |
5148 | stop, only if BL explains the stop. */ | |
5149 | ||
18a18393 | 5150 | static int |
6c95b8df | 5151 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5152 | struct address_space *aspace, CORE_ADDR bp_addr, |
5153 | const struct target_waitstatus *ws) | |
18a18393 VP |
5154 | { |
5155 | struct breakpoint *b = bl->owner; | |
5156 | ||
348d480f | 5157 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5158 | gdb_assert (b != NULL); |
5159 | ||
09ac7c10 | 5160 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5161 | } |
5162 | ||
3a5c3e22 PA |
5163 | /* Determine if the watched values have actually changed, and we |
5164 | should stop. If not, set BS->stop to 0. */ | |
5165 | ||
18a18393 VP |
5166 | static void |
5167 | bpstat_check_watchpoint (bpstat bs) | |
5168 | { | |
2bdf28a0 | 5169 | const struct bp_location *bl; |
3a5c3e22 | 5170 | struct watchpoint *b; |
2bdf28a0 JK |
5171 | |
5172 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5173 | bl = bs->bp_location_at; |
2bdf28a0 | 5174 | gdb_assert (bl != NULL); |
3a5c3e22 | 5175 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5176 | gdb_assert (b != NULL); |
18a18393 | 5177 | |
18a18393 | 5178 | { |
18a18393 VP |
5179 | int must_check_value = 0; |
5180 | ||
3a5c3e22 | 5181 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5182 | /* For a software watchpoint, we must always check the |
5183 | watched value. */ | |
5184 | must_check_value = 1; | |
5185 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5186 | /* We have a hardware watchpoint (read, write, or access) | |
5187 | and the target earlier reported an address watched by | |
5188 | this watchpoint. */ | |
5189 | must_check_value = 1; | |
5190 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5191 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5192 | /* We were stopped by a hardware watchpoint, but the target could |
5193 | not report the data address. We must check the watchpoint's | |
5194 | value. Access and read watchpoints are out of luck; without | |
5195 | a data address, we can't figure it out. */ | |
5196 | must_check_value = 1; | |
3a5c3e22 | 5197 | |
18a18393 VP |
5198 | if (must_check_value) |
5199 | { | |
3e43a32a MS |
5200 | char *message |
5201 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5202 | b->base.number); |
18a18393 VP |
5203 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5204 | int e = catch_errors (watchpoint_check, bs, message, | |
5205 | RETURN_MASK_ALL); | |
5206 | do_cleanups (cleanups); | |
5207 | switch (e) | |
5208 | { | |
5209 | case WP_DELETED: | |
5210 | /* We've already printed what needs to be printed. */ | |
5211 | bs->print_it = print_it_done; | |
5212 | /* Stop. */ | |
5213 | break; | |
60e1c644 PA |
5214 | case WP_IGNORE: |
5215 | bs->print_it = print_it_noop; | |
5216 | bs->stop = 0; | |
5217 | break; | |
18a18393 | 5218 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5219 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5220 | { |
85d721b8 PA |
5221 | /* There are two cases to consider here: |
5222 | ||
4a64f543 | 5223 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5224 | In that case, trust the target, and always report |
5225 | the watchpoint hit to the user. Even though | |
5226 | reads don't cause value changes, the value may | |
5227 | have changed since the last time it was read, and | |
5228 | since we're not trapping writes, we will not see | |
5229 | those, and as such we should ignore our notion of | |
5230 | old value. | |
5231 | ||
4a64f543 | 5232 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5233 | reads and writes. There are two ways this may |
5234 | happen: | |
5235 | ||
4a64f543 | 5236 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5237 | reads only, but can break on accesses (reads or |
5238 | writes), such as e.g., x86. We detect this case | |
5239 | at the time we try to insert read watchpoints. | |
5240 | ||
4a64f543 | 5241 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5242 | watchpoints, but, the user set an access or write |
5243 | watchpoint watching the same memory as this read | |
5244 | watchpoint. | |
5245 | ||
5246 | If we're watching memory writes as well as reads, | |
5247 | ignore watchpoint hits when we find that the | |
5248 | value hasn't changed, as reads don't cause | |
5249 | changes. This still gives false positives when | |
5250 | the program writes the same value to memory as | |
5251 | what there was already in memory (we will confuse | |
5252 | it for a read), but it's much better than | |
5253 | nothing. */ | |
5254 | ||
5255 | int other_write_watchpoint = 0; | |
5256 | ||
5257 | if (bl->watchpoint_type == hw_read) | |
5258 | { | |
5259 | struct breakpoint *other_b; | |
5260 | ||
5261 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5262 | if (other_b->type == bp_hardware_watchpoint |
5263 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5264 | { |
3a5c3e22 PA |
5265 | struct watchpoint *other_w = |
5266 | (struct watchpoint *) other_b; | |
5267 | ||
5268 | if (other_w->watchpoint_triggered | |
5269 | == watch_triggered_yes) | |
5270 | { | |
5271 | other_write_watchpoint = 1; | |
5272 | break; | |
5273 | } | |
85d721b8 PA |
5274 | } |
5275 | } | |
5276 | ||
5277 | if (other_write_watchpoint | |
5278 | || bl->watchpoint_type == hw_access) | |
5279 | { | |
5280 | /* We're watching the same memory for writes, | |
5281 | and the value changed since the last time we | |
5282 | updated it, so this trap must be for a write. | |
5283 | Ignore it. */ | |
5284 | bs->print_it = print_it_noop; | |
5285 | bs->stop = 0; | |
5286 | } | |
18a18393 VP |
5287 | } |
5288 | break; | |
5289 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5290 | if (b->base.type == bp_hardware_watchpoint |
5291 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5292 | { |
5293 | /* Don't stop: write watchpoints shouldn't fire if | |
5294 | the value hasn't changed. */ | |
5295 | bs->print_it = print_it_noop; | |
5296 | bs->stop = 0; | |
5297 | } | |
5298 | /* Stop. */ | |
5299 | break; | |
5300 | default: | |
5301 | /* Can't happen. */ | |
5302 | case 0: | |
5303 | /* Error from catch_errors. */ | |
3a5c3e22 | 5304 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5305 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5306 | /* We've already printed what needs to be printed. */ |
5307 | bs->print_it = print_it_done; | |
5308 | break; | |
5309 | } | |
5310 | } | |
5311 | else /* must_check_value == 0 */ | |
5312 | { | |
5313 | /* This is a case where some watchpoint(s) triggered, but | |
5314 | not at the address of this watchpoint, or else no | |
5315 | watchpoint triggered after all. So don't print | |
5316 | anything for this watchpoint. */ | |
5317 | bs->print_it = print_it_noop; | |
5318 | bs->stop = 0; | |
5319 | } | |
5320 | } | |
5321 | } | |
5322 | ||
7d4df6a4 DE |
5323 | /* For breakpoints that are currently marked as telling gdb to stop, |
5324 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5325 | of breakpoint referred to by BS. If we should not stop for this |
5326 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5327 | |
18a18393 VP |
5328 | static void |
5329 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5330 | { | |
2bdf28a0 JK |
5331 | const struct bp_location *bl; |
5332 | struct breakpoint *b; | |
7d4df6a4 DE |
5333 | int value_is_zero = 0; |
5334 | struct expression *cond; | |
5335 | ||
5336 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5337 | |
5338 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5339 | bl = bs->bp_location_at; |
2bdf28a0 | 5340 | gdb_assert (bl != NULL); |
f431efe5 | 5341 | b = bs->breakpoint_at; |
2bdf28a0 | 5342 | gdb_assert (b != NULL); |
18a18393 | 5343 | |
b775012e LM |
5344 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5345 | need to do so again since GDB does not know if we stopped due to a | |
5346 | breakpoint or a single step breakpoint. */ | |
5347 | ||
18a18393 | 5348 | if (frame_id_p (b->frame_id) |
edb3359d | 5349 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5350 | { |
7d4df6a4 DE |
5351 | bs->stop = 0; |
5352 | return; | |
5353 | } | |
60e1c644 | 5354 | |
12ab52e9 PA |
5355 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5356 | evaluating the condition if this isn't the specified | |
5357 | thread/task. */ | |
5358 | if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid)) | |
5359 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) | |
5360 | ||
6c1b0f7b DE |
5361 | { |
5362 | bs->stop = 0; | |
5363 | return; | |
5364 | } | |
5365 | ||
6dddc817 DE |
5366 | /* Evaluate extension language breakpoints that have a "stop" method |
5367 | implemented. */ | |
5368 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5369 | |
7d4df6a4 DE |
5370 | if (is_watchpoint (b)) |
5371 | { | |
5372 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5373 | |
7d4df6a4 DE |
5374 | cond = w->cond_exp; |
5375 | } | |
5376 | else | |
5377 | cond = bl->cond; | |
60e1c644 | 5378 | |
7d4df6a4 DE |
5379 | if (cond && b->disposition != disp_del_at_next_stop) |
5380 | { | |
5381 | int within_current_scope = 1; | |
5382 | struct watchpoint * w; | |
60e1c644 | 5383 | |
7d4df6a4 DE |
5384 | /* We use value_mark and value_free_to_mark because it could |
5385 | be a long time before we return to the command level and | |
5386 | call free_all_values. We can't call free_all_values | |
5387 | because we might be in the middle of evaluating a | |
5388 | function call. */ | |
5389 | struct value *mark = value_mark (); | |
5390 | ||
5391 | if (is_watchpoint (b)) | |
5392 | w = (struct watchpoint *) b; | |
5393 | else | |
5394 | w = NULL; | |
5395 | ||
5396 | /* Need to select the frame, with all that implies so that | |
5397 | the conditions will have the right context. Because we | |
5398 | use the frame, we will not see an inlined function's | |
5399 | variables when we arrive at a breakpoint at the start | |
5400 | of the inlined function; the current frame will be the | |
5401 | call site. */ | |
5402 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5403 | select_frame (get_current_frame ()); | |
5404 | else | |
18a18393 | 5405 | { |
7d4df6a4 DE |
5406 | struct frame_info *frame; |
5407 | ||
5408 | /* For local watchpoint expressions, which particular | |
5409 | instance of a local is being watched matters, so we | |
5410 | keep track of the frame to evaluate the expression | |
5411 | in. To evaluate the condition however, it doesn't | |
5412 | really matter which instantiation of the function | |
5413 | where the condition makes sense triggers the | |
5414 | watchpoint. This allows an expression like "watch | |
5415 | global if q > 10" set in `func', catch writes to | |
5416 | global on all threads that call `func', or catch | |
5417 | writes on all recursive calls of `func' by a single | |
5418 | thread. We simply always evaluate the condition in | |
5419 | the innermost frame that's executing where it makes | |
5420 | sense to evaluate the condition. It seems | |
5421 | intuitive. */ | |
5422 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5423 | if (frame != NULL) | |
5424 | select_frame (frame); | |
5425 | else | |
5426 | within_current_scope = 0; | |
18a18393 | 5427 | } |
7d4df6a4 DE |
5428 | if (within_current_scope) |
5429 | value_is_zero | |
5430 | = catch_errors (breakpoint_cond_eval, cond, | |
5431 | "Error in testing breakpoint condition:\n", | |
5432 | RETURN_MASK_ALL); | |
5433 | else | |
18a18393 | 5434 | { |
7d4df6a4 DE |
5435 | warning (_("Watchpoint condition cannot be tested " |
5436 | "in the current scope")); | |
5437 | /* If we failed to set the right context for this | |
5438 | watchpoint, unconditionally report it. */ | |
5439 | value_is_zero = 0; | |
18a18393 | 5440 | } |
7d4df6a4 DE |
5441 | /* FIXME-someday, should give breakpoint #. */ |
5442 | value_free_to_mark (mark); | |
18a18393 | 5443 | } |
7d4df6a4 DE |
5444 | |
5445 | if (cond && value_is_zero) | |
5446 | { | |
5447 | bs->stop = 0; | |
5448 | } | |
7d4df6a4 DE |
5449 | else if (b->ignore_count > 0) |
5450 | { | |
5451 | b->ignore_count--; | |
5452 | bs->stop = 0; | |
5453 | /* Increase the hit count even though we don't stop. */ | |
5454 | ++(b->hit_count); | |
5455 | observer_notify_breakpoint_modified (b); | |
5456 | } | |
18a18393 VP |
5457 | } |
5458 | ||
5459 | ||
9709f61c | 5460 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5461 | BP_ADDR in thread PTID. |
c906108c | 5462 | |
d983da9c | 5463 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5464 | don't understand this stop. Result is a chain of bpstat's such |
5465 | that: | |
c906108c | 5466 | |
c5aa993b | 5467 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5468 | |
c5aa993b | 5469 | if we understand why we stopped, the result is not null. |
c906108c | 5470 | |
c5aa993b JM |
5471 | Each element of the chain refers to a particular breakpoint or |
5472 | watchpoint at which we have stopped. (We may have stopped for | |
5473 | several reasons concurrently.) | |
c906108c | 5474 | |
c5aa993b JM |
5475 | Each element of the chain has valid next, breakpoint_at, |
5476 | commands, FIXME??? fields. */ | |
c906108c SS |
5477 | |
5478 | bpstat | |
6c95b8df | 5479 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5480 | CORE_ADDR bp_addr, ptid_t ptid, |
5481 | const struct target_waitstatus *ws) | |
c906108c | 5482 | { |
0d381245 | 5483 | struct breakpoint *b = NULL; |
afe38095 | 5484 | struct bp_location *bl; |
20874c92 | 5485 | struct bp_location *loc; |
5760d0ab JK |
5486 | /* First item of allocated bpstat's. */ |
5487 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5488 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5489 | bpstat bs; |
20874c92 | 5490 | int ix; |
429374b8 | 5491 | int need_remove_insert; |
f431efe5 | 5492 | int removed_any; |
c906108c | 5493 | |
f431efe5 PA |
5494 | /* First, build the bpstat chain with locations that explain a |
5495 | target stop, while being careful to not set the target running, | |
5496 | as that may invalidate locations (in particular watchpoint | |
5497 | locations are recreated). Resuming will happen here with | |
5498 | breakpoint conditions or watchpoint expressions that include | |
5499 | inferior function calls. */ | |
c5aa993b | 5500 | |
429374b8 JK |
5501 | ALL_BREAKPOINTS (b) |
5502 | { | |
1a853c52 | 5503 | if (!breakpoint_enabled (b)) |
429374b8 | 5504 | continue; |
a5606eee | 5505 | |
429374b8 JK |
5506 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5507 | { | |
4a64f543 MS |
5508 | /* For hardware watchpoints, we look only at the first |
5509 | location. The watchpoint_check function will work on the | |
5510 | entire expression, not the individual locations. For | |
5511 | read watchpoints, the watchpoints_triggered function has | |
5512 | checked all locations already. */ | |
429374b8 JK |
5513 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5514 | break; | |
18a18393 | 5515 | |
f6592439 | 5516 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5517 | continue; |
c5aa993b | 5518 | |
09ac7c10 | 5519 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5520 | continue; |
c5aa993b | 5521 | |
4a64f543 MS |
5522 | /* Come here if it's a watchpoint, or if the break address |
5523 | matches. */ | |
c5aa993b | 5524 | |
4a64f543 MS |
5525 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5526 | explain stop. */ | |
c5aa993b | 5527 | |
f431efe5 PA |
5528 | /* Assume we stop. Should we find a watchpoint that is not |
5529 | actually triggered, or if the condition of the breakpoint | |
5530 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5531 | bs->stop = 1; |
5532 | bs->print = 1; | |
d983da9c | 5533 | |
f431efe5 PA |
5534 | /* If this is a scope breakpoint, mark the associated |
5535 | watchpoint as triggered so that we will handle the | |
5536 | out-of-scope event. We'll get to the watchpoint next | |
5537 | iteration. */ | |
d0fb5eae | 5538 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5539 | { |
5540 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5541 | ||
5542 | w->watchpoint_triggered = watch_triggered_yes; | |
5543 | } | |
f431efe5 PA |
5544 | } |
5545 | } | |
5546 | ||
7c16b83e | 5547 | /* Check if a moribund breakpoint explains the stop. */ |
f431efe5 PA |
5548 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
5549 | { | |
f1310107 | 5550 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 5551 | { |
5760d0ab | 5552 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
5553 | /* For hits of moribund locations, we should just proceed. */ |
5554 | bs->stop = 0; | |
5555 | bs->print = 0; | |
5556 | bs->print_it = print_it_noop; | |
5557 | } | |
5558 | } | |
5559 | ||
edcc5120 TT |
5560 | /* A bit of special processing for shlib breakpoints. We need to |
5561 | process solib loading here, so that the lists of loaded and | |
5562 | unloaded libraries are correct before we handle "catch load" and | |
5563 | "catch unload". */ | |
5564 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5565 | { | |
5d268276 | 5566 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5567 | { |
5568 | handle_solib_event (); | |
5569 | break; | |
5570 | } | |
5571 | } | |
5572 | ||
f431efe5 PA |
5573 | /* Now go through the locations that caused the target to stop, and |
5574 | check whether we're interested in reporting this stop to higher | |
5575 | layers, or whether we should resume the target transparently. */ | |
5576 | ||
5577 | removed_any = 0; | |
5578 | ||
5760d0ab | 5579 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5580 | { |
5581 | if (!bs->stop) | |
5582 | continue; | |
5583 | ||
f431efe5 | 5584 | b = bs->breakpoint_at; |
348d480f PA |
5585 | b->ops->check_status (bs); |
5586 | if (bs->stop) | |
28010a5d | 5587 | { |
348d480f | 5588 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5589 | |
429374b8 JK |
5590 | if (bs->stop) |
5591 | { | |
5592 | ++(b->hit_count); | |
8d3788bd | 5593 | observer_notify_breakpoint_modified (b); |
c906108c | 5594 | |
4a64f543 | 5595 | /* We will stop here. */ |
429374b8 JK |
5596 | if (b->disposition == disp_disable) |
5597 | { | |
816338b5 | 5598 | --(b->enable_count); |
1a853c52 | 5599 | if (b->enable_count <= 0) |
429374b8 | 5600 | b->enable_state = bp_disabled; |
f431efe5 | 5601 | removed_any = 1; |
429374b8 JK |
5602 | } |
5603 | if (b->silent) | |
5604 | bs->print = 0; | |
5605 | bs->commands = b->commands; | |
9add0f1b | 5606 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5607 | if (command_line_is_silent (bs->commands |
5608 | ? bs->commands->commands : NULL)) | |
5609 | bs->print = 0; | |
9d6e6e84 HZ |
5610 | |
5611 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5612 | } |
5613 | ||
348d480f | 5614 | } |
a9b3a50f PA |
5615 | |
5616 | /* Print nothing for this entry if we don't stop or don't | |
5617 | print. */ | |
5618 | if (!bs->stop || !bs->print) | |
5619 | bs->print_it = print_it_noop; | |
429374b8 | 5620 | } |
876fa593 | 5621 | |
d983da9c DJ |
5622 | /* If we aren't stopping, the value of some hardware watchpoint may |
5623 | not have changed, but the intermediate memory locations we are | |
5624 | watching may have. Don't bother if we're stopping; this will get | |
5625 | done later. */ | |
d832cb68 | 5626 | need_remove_insert = 0; |
5760d0ab JK |
5627 | if (! bpstat_causes_stop (bs_head)) |
5628 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5629 | if (!bs->stop |
f431efe5 PA |
5630 | && bs->breakpoint_at |
5631 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5632 | { |
3a5c3e22 PA |
5633 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5634 | ||
5635 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5636 | need_remove_insert = 1; |
d983da9c DJ |
5637 | } |
5638 | ||
d832cb68 | 5639 | if (need_remove_insert) |
44702360 | 5640 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5641 | else if (removed_any) |
44702360 | 5642 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5643 | |
5760d0ab | 5644 | return bs_head; |
c906108c | 5645 | } |
628fe4e4 JK |
5646 | |
5647 | static void | |
5648 | handle_jit_event (void) | |
5649 | { | |
5650 | struct frame_info *frame; | |
5651 | struct gdbarch *gdbarch; | |
5652 | ||
5653 | /* Switch terminal for any messages produced by | |
5654 | breakpoint_re_set. */ | |
5655 | target_terminal_ours_for_output (); | |
5656 | ||
5657 | frame = get_current_frame (); | |
5658 | gdbarch = get_frame_arch (frame); | |
5659 | ||
5660 | jit_event_handler (gdbarch); | |
5661 | ||
5662 | target_terminal_inferior (); | |
5663 | } | |
5664 | ||
5665 | /* Prepare WHAT final decision for infrun. */ | |
5666 | ||
5667 | /* Decide what infrun needs to do with this bpstat. */ | |
5668 | ||
c906108c | 5669 | struct bpstat_what |
0e30163f | 5670 | bpstat_what (bpstat bs_head) |
c906108c | 5671 | { |
c906108c | 5672 | struct bpstat_what retval; |
628fe4e4 | 5673 | int jit_event = 0; |
0e30163f | 5674 | bpstat bs; |
c906108c | 5675 | |
628fe4e4 | 5676 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5677 | retval.call_dummy = STOP_NONE; |
186c406b | 5678 | retval.is_longjmp = 0; |
628fe4e4 | 5679 | |
0e30163f | 5680 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5681 | { |
628fe4e4 JK |
5682 | /* Extract this BS's action. After processing each BS, we check |
5683 | if its action overrides all we've seem so far. */ | |
5684 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5685 | enum bptype bptype; | |
5686 | ||
c906108c | 5687 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5688 | { |
5689 | /* I suspect this can happen if it was a momentary | |
5690 | breakpoint which has since been deleted. */ | |
5691 | bptype = bp_none; | |
5692 | } | |
20874c92 | 5693 | else |
f431efe5 | 5694 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5695 | |
5696 | switch (bptype) | |
c906108c SS |
5697 | { |
5698 | case bp_none: | |
628fe4e4 | 5699 | break; |
c906108c SS |
5700 | case bp_breakpoint: |
5701 | case bp_hardware_breakpoint: | |
7c16b83e | 5702 | case bp_single_step: |
c906108c SS |
5703 | case bp_until: |
5704 | case bp_finish: | |
a9b3a50f | 5705 | case bp_shlib_event: |
c906108c SS |
5706 | if (bs->stop) |
5707 | { | |
5708 | if (bs->print) | |
628fe4e4 | 5709 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5710 | else |
628fe4e4 | 5711 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5712 | } |
5713 | else | |
628fe4e4 | 5714 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5715 | break; |
5716 | case bp_watchpoint: | |
5717 | case bp_hardware_watchpoint: | |
5718 | case bp_read_watchpoint: | |
5719 | case bp_access_watchpoint: | |
5720 | if (bs->stop) | |
5721 | { | |
5722 | if (bs->print) | |
628fe4e4 | 5723 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5724 | else |
628fe4e4 | 5725 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5726 | } |
5727 | else | |
628fe4e4 JK |
5728 | { |
5729 | /* There was a watchpoint, but we're not stopping. | |
5730 | This requires no further action. */ | |
5731 | } | |
c906108c SS |
5732 | break; |
5733 | case bp_longjmp: | |
e2e4d78b | 5734 | case bp_longjmp_call_dummy: |
186c406b | 5735 | case bp_exception: |
628fe4e4 | 5736 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
e2e4d78b | 5737 | retval.is_longjmp = bptype != bp_exception; |
c906108c SS |
5738 | break; |
5739 | case bp_longjmp_resume: | |
186c406b | 5740 | case bp_exception_resume: |
628fe4e4 | 5741 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 5742 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
5743 | break; |
5744 | case bp_step_resume: | |
5745 | if (bs->stop) | |
628fe4e4 JK |
5746 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5747 | else | |
c906108c | 5748 | { |
628fe4e4 JK |
5749 | /* It is for the wrong frame. */ |
5750 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5751 | } |
c906108c | 5752 | break; |
2c03e5be PA |
5753 | case bp_hp_step_resume: |
5754 | if (bs->stop) | |
5755 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5756 | else | |
5757 | { | |
5758 | /* It is for the wrong frame. */ | |
5759 | this_action = BPSTAT_WHAT_SINGLE; | |
5760 | } | |
5761 | break; | |
c906108c | 5762 | case bp_watchpoint_scope: |
c4093a6a | 5763 | case bp_thread_event: |
1900040c | 5764 | case bp_overlay_event: |
0fd8e87f | 5765 | case bp_longjmp_master: |
aa7d318d | 5766 | case bp_std_terminate_master: |
186c406b | 5767 | case bp_exception_master: |
628fe4e4 | 5768 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5769 | break; |
ce78b96d | 5770 | case bp_catchpoint: |
c5aa993b JM |
5771 | if (bs->stop) |
5772 | { | |
5773 | if (bs->print) | |
628fe4e4 | 5774 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5775 | else |
628fe4e4 | 5776 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5777 | } |
5778 | else | |
628fe4e4 JK |
5779 | { |
5780 | /* There was a catchpoint, but we're not stopping. | |
5781 | This requires no further action. */ | |
5782 | } | |
5783 | break; | |
628fe4e4 JK |
5784 | case bp_jit_event: |
5785 | jit_event = 1; | |
5786 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5787 | break; |
c906108c | 5788 | case bp_call_dummy: |
53a5351d JM |
5789 | /* Make sure the action is stop (silent or noisy), |
5790 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5791 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5792 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5793 | break; |
5794 | case bp_std_terminate: | |
5795 | /* Make sure the action is stop (silent or noisy), | |
5796 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5797 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5798 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5799 | break; |
1042e4c0 | 5800 | case bp_tracepoint: |
7a697b8d | 5801 | case bp_fast_tracepoint: |
0fb4aa4b | 5802 | case bp_static_tracepoint: |
1042e4c0 SS |
5803 | /* Tracepoint hits should not be reported back to GDB, and |
5804 | if one got through somehow, it should have been filtered | |
5805 | out already. */ | |
5806 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5807 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5808 | break; |
5809 | case bp_gnu_ifunc_resolver: | |
5810 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5811 | this_action = BPSTAT_WHAT_SINGLE; | |
5812 | break; | |
5813 | case bp_gnu_ifunc_resolver_return: | |
5814 | /* The breakpoint will be removed, execution will restart from the | |
5815 | PC of the former breakpoint. */ | |
5816 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5817 | break; | |
e7e0cddf SS |
5818 | |
5819 | case bp_dprintf: | |
a11cfd87 HZ |
5820 | if (bs->stop) |
5821 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5822 | else | |
5823 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5824 | break; |
5825 | ||
628fe4e4 JK |
5826 | default: |
5827 | internal_error (__FILE__, __LINE__, | |
5828 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5829 | } |
628fe4e4 JK |
5830 | |
5831 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5832 | } |
628fe4e4 | 5833 | |
0e30163f JK |
5834 | /* These operations may affect the bs->breakpoint_at state so they are |
5835 | delayed after MAIN_ACTION is decided above. */ | |
5836 | ||
628fe4e4 JK |
5837 | if (jit_event) |
5838 | { | |
5839 | if (debug_infrun) | |
5840 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5841 | ||
5842 | handle_jit_event (); | |
5843 | } | |
5844 | ||
0e30163f JK |
5845 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5846 | { | |
5847 | struct breakpoint *b = bs->breakpoint_at; | |
5848 | ||
5849 | if (b == NULL) | |
5850 | continue; | |
5851 | switch (b->type) | |
5852 | { | |
5853 | case bp_gnu_ifunc_resolver: | |
5854 | gnu_ifunc_resolver_stop (b); | |
5855 | break; | |
5856 | case bp_gnu_ifunc_resolver_return: | |
5857 | gnu_ifunc_resolver_return_stop (b); | |
5858 | break; | |
5859 | } | |
5860 | } | |
5861 | ||
c906108c SS |
5862 | return retval; |
5863 | } | |
5864 | ||
5865 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5866 | without hardware support). This isn't related to a specific bpstat, | |
5867 | just to things like whether watchpoints are set. */ | |
5868 | ||
c5aa993b | 5869 | int |
fba45db2 | 5870 | bpstat_should_step (void) |
c906108c SS |
5871 | { |
5872 | struct breakpoint *b; | |
cc59ec59 | 5873 | |
c906108c | 5874 | ALL_BREAKPOINTS (b) |
717a8278 | 5875 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5876 | return 1; |
c906108c SS |
5877 | return 0; |
5878 | } | |
5879 | ||
67822962 PA |
5880 | int |
5881 | bpstat_causes_stop (bpstat bs) | |
5882 | { | |
5883 | for (; bs != NULL; bs = bs->next) | |
5884 | if (bs->stop) | |
5885 | return 1; | |
5886 | ||
5887 | return 0; | |
5888 | } | |
5889 | ||
c906108c | 5890 | \f |
c5aa993b | 5891 | |
170b53b2 UW |
5892 | /* Compute a string of spaces suitable to indent the next line |
5893 | so it starts at the position corresponding to the table column | |
5894 | named COL_NAME in the currently active table of UIOUT. */ | |
5895 | ||
5896 | static char * | |
5897 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5898 | { | |
5899 | static char wrap_indent[80]; | |
5900 | int i, total_width, width, align; | |
5901 | char *text; | |
5902 | ||
5903 | total_width = 0; | |
5904 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5905 | { | |
5906 | if (strcmp (text, col_name) == 0) | |
5907 | { | |
5908 | gdb_assert (total_width < sizeof wrap_indent); | |
5909 | memset (wrap_indent, ' ', total_width); | |
5910 | wrap_indent[total_width] = 0; | |
5911 | ||
5912 | return wrap_indent; | |
5913 | } | |
5914 | ||
5915 | total_width += width + 1; | |
5916 | } | |
5917 | ||
5918 | return NULL; | |
5919 | } | |
5920 | ||
b775012e LM |
5921 | /* Determine if the locations of this breakpoint will have their conditions |
5922 | evaluated by the target, host or a mix of both. Returns the following: | |
5923 | ||
5924 | "host": Host evals condition. | |
5925 | "host or target": Host or Target evals condition. | |
5926 | "target": Target evals condition. | |
5927 | */ | |
5928 | ||
5929 | static const char * | |
5930 | bp_condition_evaluator (struct breakpoint *b) | |
5931 | { | |
5932 | struct bp_location *bl; | |
5933 | char host_evals = 0; | |
5934 | char target_evals = 0; | |
5935 | ||
5936 | if (!b) | |
5937 | return NULL; | |
5938 | ||
5939 | if (!is_breakpoint (b)) | |
5940 | return NULL; | |
5941 | ||
5942 | if (gdb_evaluates_breakpoint_condition_p () | |
5943 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5944 | return condition_evaluation_host; | |
5945 | ||
5946 | for (bl = b->loc; bl; bl = bl->next) | |
5947 | { | |
5948 | if (bl->cond_bytecode) | |
5949 | target_evals++; | |
5950 | else | |
5951 | host_evals++; | |
5952 | } | |
5953 | ||
5954 | if (host_evals && target_evals) | |
5955 | return condition_evaluation_both; | |
5956 | else if (target_evals) | |
5957 | return condition_evaluation_target; | |
5958 | else | |
5959 | return condition_evaluation_host; | |
5960 | } | |
5961 | ||
5962 | /* Determine the breakpoint location's condition evaluator. This is | |
5963 | similar to bp_condition_evaluator, but for locations. */ | |
5964 | ||
5965 | static const char * | |
5966 | bp_location_condition_evaluator (struct bp_location *bl) | |
5967 | { | |
5968 | if (bl && !is_breakpoint (bl->owner)) | |
5969 | return NULL; | |
5970 | ||
5971 | if (gdb_evaluates_breakpoint_condition_p () | |
5972 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5973 | return condition_evaluation_host; | |
5974 | ||
5975 | if (bl && bl->cond_bytecode) | |
5976 | return condition_evaluation_target; | |
5977 | else | |
5978 | return condition_evaluation_host; | |
5979 | } | |
5980 | ||
859825b8 JK |
5981 | /* Print the LOC location out of the list of B->LOC locations. */ |
5982 | ||
170b53b2 UW |
5983 | static void |
5984 | print_breakpoint_location (struct breakpoint *b, | |
5985 | struct bp_location *loc) | |
0d381245 | 5986 | { |
79a45e25 | 5987 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
5988 | struct cleanup *old_chain = save_current_program_space (); |
5989 | ||
859825b8 JK |
5990 | if (loc != NULL && loc->shlib_disabled) |
5991 | loc = NULL; | |
5992 | ||
6c95b8df PA |
5993 | if (loc != NULL) |
5994 | set_current_program_space (loc->pspace); | |
5995 | ||
56435ebe TT |
5996 | if (b->display_canonical) |
5997 | ui_out_field_string (uiout, "what", b->addr_string); | |
2f202fde | 5998 | else if (loc && loc->symtab) |
0d381245 VP |
5999 | { |
6000 | struct symbol *sym | |
6001 | = find_pc_sect_function (loc->address, loc->section); | |
6002 | if (sym) | |
6003 | { | |
6004 | ui_out_text (uiout, "in "); | |
6005 | ui_out_field_string (uiout, "func", | |
6006 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
6007 | ui_out_text (uiout, " "); |
6008 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
6009 | ui_out_text (uiout, "at "); | |
0d381245 | 6010 | } |
05cba821 JK |
6011 | ui_out_field_string (uiout, "file", |
6012 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 6013 | ui_out_text (uiout, ":"); |
05cba821 | 6014 | |
0d381245 | 6015 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
6016 | ui_out_field_string (uiout, "fullname", |
6017 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 6018 | |
f8eba3c6 | 6019 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 6020 | } |
859825b8 | 6021 | else if (loc) |
0d381245 | 6022 | { |
f99d8bf4 PA |
6023 | struct ui_file *stb = mem_fileopen (); |
6024 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 6025 | |
f99d8bf4 | 6026 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 6027 | demangle, ""); |
0d381245 | 6028 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
6029 | |
6030 | do_cleanups (stb_chain); | |
0d381245 | 6031 | } |
859825b8 JK |
6032 | else |
6033 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 6034 | |
b775012e LM |
6035 | if (loc && is_breakpoint (b) |
6036 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6037 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6038 | { | |
6039 | ui_out_text (uiout, " ("); | |
6040 | ui_out_field_string (uiout, "evaluated-by", | |
6041 | bp_location_condition_evaluator (loc)); | |
6042 | ui_out_text (uiout, ")"); | |
6043 | } | |
6044 | ||
6c95b8df | 6045 | do_cleanups (old_chain); |
0d381245 VP |
6046 | } |
6047 | ||
269b11a2 PA |
6048 | static const char * |
6049 | bptype_string (enum bptype type) | |
c906108c | 6050 | { |
c4093a6a JM |
6051 | struct ep_type_description |
6052 | { | |
6053 | enum bptype type; | |
6054 | char *description; | |
6055 | }; | |
6056 | static struct ep_type_description bptypes[] = | |
c906108c | 6057 | { |
c5aa993b JM |
6058 | {bp_none, "?deleted?"}, |
6059 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6060 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6061 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6062 | {bp_until, "until"}, |
6063 | {bp_finish, "finish"}, | |
6064 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6065 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6066 | {bp_read_watchpoint, "read watchpoint"}, |
6067 | {bp_access_watchpoint, "acc watchpoint"}, | |
6068 | {bp_longjmp, "longjmp"}, | |
6069 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6070 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6071 | {bp_exception, "exception"}, |
6072 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6073 | {bp_step_resume, "step resume"}, |
2c03e5be | 6074 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6075 | {bp_watchpoint_scope, "watchpoint scope"}, |
6076 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6077 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6078 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6079 | {bp_thread_event, "thread events"}, |
1900040c | 6080 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6081 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6082 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6083 | {bp_exception_master, "exception master"}, |
ce78b96d | 6084 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6085 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6086 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6087 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6088 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6089 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6090 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6091 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6092 | }; |
269b11a2 PA |
6093 | |
6094 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6095 | || ((int) type != bptypes[(int) type].type)) | |
6096 | internal_error (__FILE__, __LINE__, | |
6097 | _("bptypes table does not describe type #%d."), | |
6098 | (int) type); | |
6099 | ||
6100 | return bptypes[(int) type].description; | |
6101 | } | |
6102 | ||
998580f1 MK |
6103 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6104 | For CLI, prefix the list with the string 'inf'. */ | |
6105 | ||
6106 | static void | |
6107 | output_thread_groups (struct ui_out *uiout, | |
6108 | const char *field_name, | |
6109 | VEC(int) *inf_num, | |
6110 | int mi_only) | |
6111 | { | |
752eb8b4 | 6112 | struct cleanup *back_to; |
998580f1 MK |
6113 | int is_mi = ui_out_is_mi_like_p (uiout); |
6114 | int inf; | |
6115 | int i; | |
6116 | ||
6117 | /* For backward compatibility, don't display inferiors in CLI unless | |
6118 | there are several. Always display them for MI. */ | |
6119 | if (!is_mi && mi_only) | |
6120 | return; | |
6121 | ||
752eb8b4 TT |
6122 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6123 | ||
998580f1 MK |
6124 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6125 | { | |
6126 | if (is_mi) | |
6127 | { | |
6128 | char mi_group[10]; | |
6129 | ||
6130 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6131 | ui_out_field_string (uiout, NULL, mi_group); | |
6132 | } | |
6133 | else | |
6134 | { | |
6135 | if (i == 0) | |
6136 | ui_out_text (uiout, " inf "); | |
6137 | else | |
6138 | ui_out_text (uiout, ", "); | |
6139 | ||
6140 | ui_out_text (uiout, plongest (inf)); | |
6141 | } | |
6142 | } | |
6143 | ||
6144 | do_cleanups (back_to); | |
6145 | } | |
6146 | ||
269b11a2 PA |
6147 | /* Print B to gdb_stdout. */ |
6148 | ||
6149 | static void | |
6150 | print_one_breakpoint_location (struct breakpoint *b, | |
6151 | struct bp_location *loc, | |
6152 | int loc_number, | |
6153 | struct bp_location **last_loc, | |
269b11a2 PA |
6154 | int allflag) |
6155 | { | |
6156 | struct command_line *l; | |
c2c6d25f | 6157 | static char bpenables[] = "nynny"; |
c906108c | 6158 | |
79a45e25 | 6159 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6160 | int header_of_multiple = 0; |
6161 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6162 | struct value_print_options opts; |
6163 | ||
6164 | get_user_print_options (&opts); | |
0d381245 VP |
6165 | |
6166 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6167 | /* See comment in print_one_breakpoint concerning treatment of |
6168 | breakpoints with single disabled location. */ | |
0d381245 VP |
6169 | if (loc == NULL |
6170 | && (b->loc != NULL | |
6171 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6172 | header_of_multiple = 1; | |
6173 | if (loc == NULL) | |
6174 | loc = b->loc; | |
6175 | ||
c4093a6a JM |
6176 | annotate_record (); |
6177 | ||
6178 | /* 1 */ | |
6179 | annotate_field (0); | |
0d381245 VP |
6180 | if (part_of_multiple) |
6181 | { | |
6182 | char *formatted; | |
0c6773c1 | 6183 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6184 | ui_out_field_string (uiout, "number", formatted); |
6185 | xfree (formatted); | |
6186 | } | |
6187 | else | |
6188 | { | |
6189 | ui_out_field_int (uiout, "number", b->number); | |
6190 | } | |
c4093a6a JM |
6191 | |
6192 | /* 2 */ | |
6193 | annotate_field (1); | |
0d381245 VP |
6194 | if (part_of_multiple) |
6195 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6196 | else |
6197 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6198 | |
6199 | /* 3 */ | |
6200 | annotate_field (2); | |
0d381245 VP |
6201 | if (part_of_multiple) |
6202 | ui_out_field_skip (uiout, "disp"); | |
6203 | else | |
2cec12e5 | 6204 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6205 | |
c4093a6a JM |
6206 | |
6207 | /* 4 */ | |
6208 | annotate_field (3); | |
0d381245 | 6209 | if (part_of_multiple) |
54e52265 | 6210 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6211 | else |
4a64f543 MS |
6212 | ui_out_field_fmt (uiout, "enabled", "%c", |
6213 | bpenables[(int) b->enable_state]); | |
54e52265 | 6214 | ui_out_spaces (uiout, 2); |
0d381245 | 6215 | |
c4093a6a JM |
6216 | |
6217 | /* 5 and 6 */ | |
3086aeae | 6218 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6219 | { |
4a64f543 MS |
6220 | /* Although the print_one can possibly print all locations, |
6221 | calling it here is not likely to get any nice result. So, | |
6222 | make sure there's just one location. */ | |
0d381245 | 6223 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6224 | b->ops->print_one (b, last_loc); |
0d381245 | 6225 | } |
3086aeae DJ |
6226 | else |
6227 | switch (b->type) | |
6228 | { | |
6229 | case bp_none: | |
6230 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6231 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6232 | break; |
c906108c | 6233 | |
3086aeae DJ |
6234 | case bp_watchpoint: |
6235 | case bp_hardware_watchpoint: | |
6236 | case bp_read_watchpoint: | |
6237 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6238 | { |
6239 | struct watchpoint *w = (struct watchpoint *) b; | |
6240 | ||
6241 | /* Field 4, the address, is omitted (which makes the columns | |
6242 | not line up too nicely with the headers, but the effect | |
6243 | is relatively readable). */ | |
6244 | if (opts.addressprint) | |
6245 | ui_out_field_skip (uiout, "addr"); | |
6246 | annotate_field (5); | |
6247 | ui_out_field_string (uiout, "what", w->exp_string); | |
6248 | } | |
3086aeae DJ |
6249 | break; |
6250 | ||
3086aeae DJ |
6251 | case bp_breakpoint: |
6252 | case bp_hardware_breakpoint: | |
7c16b83e | 6253 | case bp_single_step: |
3086aeae DJ |
6254 | case bp_until: |
6255 | case bp_finish: | |
6256 | case bp_longjmp: | |
6257 | case bp_longjmp_resume: | |
e2e4d78b | 6258 | case bp_longjmp_call_dummy: |
186c406b TT |
6259 | case bp_exception: |
6260 | case bp_exception_resume: | |
3086aeae | 6261 | case bp_step_resume: |
2c03e5be | 6262 | case bp_hp_step_resume: |
3086aeae DJ |
6263 | case bp_watchpoint_scope: |
6264 | case bp_call_dummy: | |
aa7d318d | 6265 | case bp_std_terminate: |
3086aeae DJ |
6266 | case bp_shlib_event: |
6267 | case bp_thread_event: | |
6268 | case bp_overlay_event: | |
0fd8e87f | 6269 | case bp_longjmp_master: |
aa7d318d | 6270 | case bp_std_terminate_master: |
186c406b | 6271 | case bp_exception_master: |
1042e4c0 | 6272 | case bp_tracepoint: |
7a697b8d | 6273 | case bp_fast_tracepoint: |
0fb4aa4b | 6274 | case bp_static_tracepoint: |
e7e0cddf | 6275 | case bp_dprintf: |
4efc6507 | 6276 | case bp_jit_event: |
0e30163f JK |
6277 | case bp_gnu_ifunc_resolver: |
6278 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6279 | if (opts.addressprint) |
3086aeae DJ |
6280 | { |
6281 | annotate_field (4); | |
54e52265 | 6282 | if (header_of_multiple) |
0d381245 | 6283 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6284 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6285 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6286 | else |
5af949e3 UW |
6287 | ui_out_field_core_addr (uiout, "addr", |
6288 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6289 | } |
6290 | annotate_field (5); | |
0d381245 | 6291 | if (!header_of_multiple) |
170b53b2 | 6292 | print_breakpoint_location (b, loc); |
0d381245 | 6293 | if (b->loc) |
a6d9a66e | 6294 | *last_loc = b->loc; |
3086aeae DJ |
6295 | break; |
6296 | } | |
c906108c | 6297 | |
6c95b8df | 6298 | |
998580f1 | 6299 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6300 | { |
6301 | struct inferior *inf; | |
998580f1 MK |
6302 | VEC(int) *inf_num = NULL; |
6303 | int mi_only = 1; | |
6c95b8df | 6304 | |
998580f1 | 6305 | ALL_INFERIORS (inf) |
6c95b8df PA |
6306 | { |
6307 | if (inf->pspace == loc->pspace) | |
998580f1 | 6308 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6309 | } |
998580f1 MK |
6310 | |
6311 | /* For backward compatibility, don't display inferiors in CLI unless | |
6312 | there are several. Always display for MI. */ | |
6313 | if (allflag | |
6314 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6315 | && (number_of_program_spaces () > 1 | |
6316 | || number_of_inferiors () > 1) | |
6317 | /* LOC is for existing B, it cannot be in | |
6318 | moribund_locations and thus having NULL OWNER. */ | |
6319 | && loc->owner->type != bp_catchpoint)) | |
6320 | mi_only = 0; | |
6321 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6322 | VEC_free (int, inf_num); | |
6c95b8df PA |
6323 | } |
6324 | ||
4a306c9a | 6325 | if (!part_of_multiple) |
c4093a6a | 6326 | { |
4a306c9a JB |
6327 | if (b->thread != -1) |
6328 | { | |
6329 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6330 | "stop only in" line a little further down. */ |
4a306c9a JB |
6331 | ui_out_text (uiout, " thread "); |
6332 | ui_out_field_int (uiout, "thread", b->thread); | |
6333 | } | |
6334 | else if (b->task != 0) | |
6335 | { | |
6336 | ui_out_text (uiout, " task "); | |
6337 | ui_out_field_int (uiout, "task", b->task); | |
6338 | } | |
c4093a6a | 6339 | } |
f1310107 | 6340 | |
8b93c638 | 6341 | ui_out_text (uiout, "\n"); |
f1310107 | 6342 | |
348d480f | 6343 | if (!part_of_multiple) |
f1310107 TJB |
6344 | b->ops->print_one_detail (b, uiout); |
6345 | ||
0d381245 | 6346 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6347 | { |
6348 | annotate_field (6); | |
8b93c638 | 6349 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6350 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6351 | the frame ID. */ |
5af949e3 UW |
6352 | ui_out_field_core_addr (uiout, "frame", |
6353 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6354 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6355 | } |
6356 | ||
28010a5d | 6357 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6358 | { |
6359 | annotate_field (7); | |
d77f58be | 6360 | if (is_tracepoint (b)) |
1042e4c0 SS |
6361 | ui_out_text (uiout, "\ttrace only if "); |
6362 | else | |
6363 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6364 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6365 | |
6366 | /* Print whether the target is doing the breakpoint's condition | |
6367 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6368 | if (is_breakpoint (b) | |
6369 | && breakpoint_condition_evaluation_mode () | |
6370 | == condition_evaluation_target) | |
6371 | { | |
6372 | ui_out_text (uiout, " ("); | |
6373 | ui_out_field_string (uiout, "evaluated-by", | |
6374 | bp_condition_evaluator (b)); | |
6375 | ui_out_text (uiout, " evals)"); | |
6376 | } | |
0101ce28 JJ |
6377 | ui_out_text (uiout, "\n"); |
6378 | } | |
6379 | ||
0d381245 | 6380 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6381 | { |
4a64f543 | 6382 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6383 | ui_out_text (uiout, "\tstop only in thread "); |
6384 | ui_out_field_int (uiout, "thread", b->thread); | |
6385 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6386 | } |
6387 | ||
556ec64d YQ |
6388 | if (!part_of_multiple) |
6389 | { | |
6390 | if (b->hit_count) | |
31f56a27 YQ |
6391 | { |
6392 | /* FIXME should make an annotation for this. */ | |
6393 | if (is_catchpoint (b)) | |
6394 | ui_out_text (uiout, "\tcatchpoint"); | |
6395 | else if (is_tracepoint (b)) | |
6396 | ui_out_text (uiout, "\ttracepoint"); | |
6397 | else | |
6398 | ui_out_text (uiout, "\tbreakpoint"); | |
6399 | ui_out_text (uiout, " already hit "); | |
6400 | ui_out_field_int (uiout, "times", b->hit_count); | |
6401 | if (b->hit_count == 1) | |
6402 | ui_out_text (uiout, " time\n"); | |
6403 | else | |
6404 | ui_out_text (uiout, " times\n"); | |
6405 | } | |
556ec64d YQ |
6406 | else |
6407 | { | |
31f56a27 YQ |
6408 | /* Output the count also if it is zero, but only if this is mi. */ |
6409 | if (ui_out_is_mi_like_p (uiout)) | |
6410 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6411 | } |
6412 | } | |
8b93c638 | 6413 | |
0d381245 | 6414 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6415 | { |
6416 | annotate_field (8); | |
8b93c638 JM |
6417 | ui_out_text (uiout, "\tignore next "); |
6418 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6419 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6420 | } |
059fb39f | 6421 | |
816338b5 SS |
6422 | /* Note that an enable count of 1 corresponds to "enable once" |
6423 | behavior, which is reported by the combination of enablement and | |
6424 | disposition, so we don't need to mention it here. */ | |
6425 | if (!part_of_multiple && b->enable_count > 1) | |
6426 | { | |
6427 | annotate_field (8); | |
6428 | ui_out_text (uiout, "\tdisable after "); | |
6429 | /* Tweak the wording to clarify that ignore and enable counts | |
6430 | are distinct, and have additive effect. */ | |
6431 | if (b->ignore_count) | |
6432 | ui_out_text (uiout, "additional "); | |
6433 | else | |
6434 | ui_out_text (uiout, "next "); | |
6435 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6436 | ui_out_text (uiout, " hits\n"); | |
6437 | } | |
6438 | ||
f196051f SS |
6439 | if (!part_of_multiple && is_tracepoint (b)) |
6440 | { | |
6441 | struct tracepoint *tp = (struct tracepoint *) b; | |
6442 | ||
6443 | if (tp->traceframe_usage) | |
6444 | { | |
6445 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6446 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6447 | ui_out_text (uiout, " bytes\n"); | |
6448 | } | |
6449 | } | |
d3ce09f5 | 6450 | |
9add0f1b | 6451 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6452 | if (!part_of_multiple && l) |
c4093a6a | 6453 | { |
3b31d625 EZ |
6454 | struct cleanup *script_chain; |
6455 | ||
c4093a6a | 6456 | annotate_field (9); |
3b31d625 | 6457 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6458 | print_command_lines (uiout, l, 4); |
3b31d625 | 6459 | do_cleanups (script_chain); |
c4093a6a | 6460 | } |
d24317b4 | 6461 | |
d9b3f62e | 6462 | if (is_tracepoint (b)) |
1042e4c0 | 6463 | { |
d9b3f62e PA |
6464 | struct tracepoint *t = (struct tracepoint *) b; |
6465 | ||
6466 | if (!part_of_multiple && t->pass_count) | |
6467 | { | |
6468 | annotate_field (10); | |
6469 | ui_out_text (uiout, "\tpass count "); | |
6470 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6471 | ui_out_text (uiout, " \n"); | |
6472 | } | |
f2a8bc8a YQ |
6473 | |
6474 | /* Don't display it when tracepoint or tracepoint location is | |
6475 | pending. */ | |
6476 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6477 | { | |
6478 | annotate_field (11); | |
6479 | ||
6480 | if (ui_out_is_mi_like_p (uiout)) | |
6481 | ui_out_field_string (uiout, "installed", | |
6482 | loc->inserted ? "y" : "n"); | |
6483 | else | |
6484 | { | |
6485 | if (loc->inserted) | |
6486 | ui_out_text (uiout, "\t"); | |
6487 | else | |
6488 | ui_out_text (uiout, "\tnot "); | |
6489 | ui_out_text (uiout, "installed on target\n"); | |
6490 | } | |
6491 | } | |
1042e4c0 SS |
6492 | } |
6493 | ||
d24317b4 VP |
6494 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6495 | { | |
3a5c3e22 PA |
6496 | if (is_watchpoint (b)) |
6497 | { | |
6498 | struct watchpoint *w = (struct watchpoint *) b; | |
6499 | ||
6500 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6501 | } | |
6502 | else if (b->addr_string) | |
d24317b4 | 6503 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 6504 | } |
c4093a6a | 6505 | } |
c5aa993b | 6506 | |
0d381245 VP |
6507 | static void |
6508 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6509 | struct bp_location **last_loc, |
6c95b8df | 6510 | int allflag) |
0d381245 | 6511 | { |
8d3788bd | 6512 | struct cleanup *bkpt_chain; |
79a45e25 | 6513 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6514 | |
6515 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6516 | ||
12c5a436 | 6517 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6518 | do_cleanups (bkpt_chain); |
0d381245 VP |
6519 | |
6520 | /* If this breakpoint has custom print function, | |
6521 | it's already printed. Otherwise, print individual | |
6522 | locations, if any. */ | |
6523 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6524 | { | |
4a64f543 MS |
6525 | /* If breakpoint has a single location that is disabled, we |
6526 | print it as if it had several locations, since otherwise it's | |
6527 | hard to represent "breakpoint enabled, location disabled" | |
6528 | situation. | |
6529 | ||
6530 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6531 | internally, that's not a property exposed to user. */ |
0d381245 | 6532 | if (b->loc |
a5606eee | 6533 | && !is_hardware_watchpoint (b) |
8d3788bd | 6534 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6535 | { |
6536 | struct bp_location *loc; | |
6537 | int n = 1; | |
8d3788bd | 6538 | |
0d381245 | 6539 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6540 | { |
6541 | struct cleanup *inner2 = | |
6542 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6543 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6544 | do_cleanups (inner2); | |
6545 | } | |
0d381245 VP |
6546 | } |
6547 | } | |
6548 | } | |
6549 | ||
a6d9a66e UW |
6550 | static int |
6551 | breakpoint_address_bits (struct breakpoint *b) | |
6552 | { | |
6553 | int print_address_bits = 0; | |
6554 | struct bp_location *loc; | |
6555 | ||
6556 | for (loc = b->loc; loc; loc = loc->next) | |
6557 | { | |
c7437ca6 PA |
6558 | int addr_bit; |
6559 | ||
6560 | /* Software watchpoints that aren't watching memory don't have | |
6561 | an address to print. */ | |
6562 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
6563 | continue; | |
6564 | ||
6565 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
6566 | if (addr_bit > print_address_bits) |
6567 | print_address_bits = addr_bit; | |
6568 | } | |
6569 | ||
6570 | return print_address_bits; | |
6571 | } | |
0d381245 | 6572 | |
c4093a6a JM |
6573 | struct captured_breakpoint_query_args |
6574 | { | |
6575 | int bnum; | |
6576 | }; | |
c5aa993b | 6577 | |
c4093a6a | 6578 | static int |
2b65245e | 6579 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
6580 | { |
6581 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 6582 | struct breakpoint *b; |
a6d9a66e | 6583 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6584 | |
c4093a6a JM |
6585 | ALL_BREAKPOINTS (b) |
6586 | { | |
6587 | if (args->bnum == b->number) | |
c5aa993b | 6588 | { |
12c5a436 | 6589 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6590 | return GDB_RC_OK; |
c5aa993b | 6591 | } |
c4093a6a JM |
6592 | } |
6593 | return GDB_RC_NONE; | |
6594 | } | |
c5aa993b | 6595 | |
c4093a6a | 6596 | enum gdb_rc |
4a64f543 MS |
6597 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6598 | char **error_message) | |
c4093a6a JM |
6599 | { |
6600 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6601 | |
c4093a6a JM |
6602 | args.bnum = bnum; |
6603 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6604 | an error. */ |
b0b13bb4 DJ |
6605 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6606 | error_message, RETURN_MASK_ALL) < 0) | |
6607 | return GDB_RC_FAIL; | |
6608 | else | |
6609 | return GDB_RC_OK; | |
c4093a6a | 6610 | } |
c5aa993b | 6611 | |
09d682a4 TT |
6612 | /* Return true if this breakpoint was set by the user, false if it is |
6613 | internal or momentary. */ | |
6614 | ||
6615 | int | |
6616 | user_breakpoint_p (struct breakpoint *b) | |
6617 | { | |
46c6471b | 6618 | return b->number > 0; |
09d682a4 TT |
6619 | } |
6620 | ||
7f3b0473 | 6621 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6622 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6623 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6624 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6625 | ones for which it returns non-zero. Return the total number of | |
6626 | breakpoints listed. */ | |
c906108c | 6627 | |
d77f58be | 6628 | static int |
e5a67952 | 6629 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6630 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6631 | { |
52f0bd74 | 6632 | struct breakpoint *b; |
a6d9a66e | 6633 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6634 | int nr_printable_breakpoints; |
3b31d625 | 6635 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6636 | struct value_print_options opts; |
a6d9a66e | 6637 | int print_address_bits = 0; |
269b11a2 | 6638 | int print_type_col_width = 14; |
79a45e25 | 6639 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6640 | |
79a45b7d TT |
6641 | get_user_print_options (&opts); |
6642 | ||
4a64f543 MS |
6643 | /* Compute the number of rows in the table, as well as the size |
6644 | required for address fields. */ | |
7f3b0473 AC |
6645 | nr_printable_breakpoints = 0; |
6646 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6647 | { |
6648 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6649 | if (filter && !filter (b)) | |
6650 | continue; | |
6651 | ||
6652 | /* If we have an "args" string, it is a list of breakpoints to | |
6653 | accept. Skip the others. */ | |
6654 | if (args != NULL && *args != '\0') | |
6655 | { | |
6656 | if (allflag && parse_and_eval_long (args) != b->number) | |
6657 | continue; | |
6658 | if (!allflag && !number_is_in_list (args, b->number)) | |
6659 | continue; | |
6660 | } | |
269b11a2 | 6661 | |
e5a67952 MS |
6662 | if (allflag || user_breakpoint_p (b)) |
6663 | { | |
6664 | int addr_bit, type_len; | |
a6d9a66e | 6665 | |
e5a67952 MS |
6666 | addr_bit = breakpoint_address_bits (b); |
6667 | if (addr_bit > print_address_bits) | |
6668 | print_address_bits = addr_bit; | |
269b11a2 | 6669 | |
e5a67952 MS |
6670 | type_len = strlen (bptype_string (b->type)); |
6671 | if (type_len > print_type_col_width) | |
6672 | print_type_col_width = type_len; | |
6673 | ||
6674 | nr_printable_breakpoints++; | |
6675 | } | |
6676 | } | |
7f3b0473 | 6677 | |
79a45b7d | 6678 | if (opts.addressprint) |
3b31d625 | 6679 | bkpttbl_chain |
3e43a32a MS |
6680 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6681 | nr_printable_breakpoints, | |
3b31d625 | 6682 | "BreakpointTable"); |
8b93c638 | 6683 | else |
3b31d625 | 6684 | bkpttbl_chain |
3e43a32a MS |
6685 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6686 | nr_printable_breakpoints, | |
3b31d625 | 6687 | "BreakpointTable"); |
8b93c638 | 6688 | |
7f3b0473 | 6689 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6690 | annotate_breakpoints_headers (); |
6691 | if (nr_printable_breakpoints > 0) | |
6692 | annotate_field (0); | |
4a64f543 | 6693 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6694 | if (nr_printable_breakpoints > 0) |
6695 | annotate_field (1); | |
269b11a2 | 6696 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6697 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6698 | if (nr_printable_breakpoints > 0) |
6699 | annotate_field (2); | |
4a64f543 | 6700 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6701 | if (nr_printable_breakpoints > 0) |
6702 | annotate_field (3); | |
54e52265 | 6703 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6704 | if (opts.addressprint) |
e5a67952 MS |
6705 | { |
6706 | if (nr_printable_breakpoints > 0) | |
6707 | annotate_field (4); | |
6708 | if (print_address_bits <= 32) | |
6709 | ui_out_table_header (uiout, 10, ui_left, | |
6710 | "addr", "Address"); /* 5 */ | |
6711 | else | |
6712 | ui_out_table_header (uiout, 18, ui_left, | |
6713 | "addr", "Address"); /* 5 */ | |
6714 | } | |
d7faa9e7 AC |
6715 | if (nr_printable_breakpoints > 0) |
6716 | annotate_field (5); | |
6717 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6718 | ui_out_table_body (uiout); | |
6719 | if (nr_printable_breakpoints > 0) | |
6720 | annotate_breakpoints_table (); | |
7f3b0473 | 6721 | |
c4093a6a | 6722 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6723 | { |
6724 | QUIT; | |
6725 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6726 | if (filter && !filter (b)) | |
6727 | continue; | |
6728 | ||
6729 | /* If we have an "args" string, it is a list of breakpoints to | |
6730 | accept. Skip the others. */ | |
6731 | ||
6732 | if (args != NULL && *args != '\0') | |
6733 | { | |
6734 | if (allflag) /* maintenance info breakpoint */ | |
6735 | { | |
6736 | if (parse_and_eval_long (args) != b->number) | |
6737 | continue; | |
6738 | } | |
6739 | else /* all others */ | |
6740 | { | |
6741 | if (!number_is_in_list (args, b->number)) | |
6742 | continue; | |
6743 | } | |
6744 | } | |
6745 | /* We only print out user settable breakpoints unless the | |
6746 | allflag is set. */ | |
6747 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6748 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6749 | } |
6750 | ||
3b31d625 | 6751 | do_cleanups (bkpttbl_chain); |
698384cd | 6752 | |
7f3b0473 | 6753 | if (nr_printable_breakpoints == 0) |
c906108c | 6754 | { |
4a64f543 MS |
6755 | /* If there's a filter, let the caller decide how to report |
6756 | empty list. */ | |
d77f58be SS |
6757 | if (!filter) |
6758 | { | |
e5a67952 | 6759 | if (args == NULL || *args == '\0') |
d77f58be SS |
6760 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6761 | else | |
4a64f543 | 6762 | ui_out_message (uiout, 0, |
e5a67952 MS |
6763 | "No breakpoint or watchpoint matching '%s'.\n", |
6764 | args); | |
d77f58be | 6765 | } |
c906108c SS |
6766 | } |
6767 | else | |
c4093a6a | 6768 | { |
a6d9a66e UW |
6769 | if (last_loc && !server_command) |
6770 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6771 | } |
c906108c | 6772 | |
4a64f543 | 6773 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6774 | there have been breakpoints? */ |
c906108c | 6775 | annotate_breakpoints_table_end (); |
d77f58be SS |
6776 | |
6777 | return nr_printable_breakpoints; | |
c906108c SS |
6778 | } |
6779 | ||
ad443146 SS |
6780 | /* Display the value of default-collect in a way that is generally |
6781 | compatible with the breakpoint list. */ | |
6782 | ||
6783 | static void | |
6784 | default_collect_info (void) | |
6785 | { | |
79a45e25 PA |
6786 | struct ui_out *uiout = current_uiout; |
6787 | ||
ad443146 SS |
6788 | /* If it has no value (which is frequently the case), say nothing; a |
6789 | message like "No default-collect." gets in user's face when it's | |
6790 | not wanted. */ | |
6791 | if (!*default_collect) | |
6792 | return; | |
6793 | ||
6794 | /* The following phrase lines up nicely with per-tracepoint collect | |
6795 | actions. */ | |
6796 | ui_out_text (uiout, "default collect "); | |
6797 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6798 | ui_out_text (uiout, " \n"); | |
6799 | } | |
6800 | ||
c906108c | 6801 | static void |
e5a67952 | 6802 | breakpoints_info (char *args, int from_tty) |
c906108c | 6803 | { |
e5a67952 | 6804 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6805 | |
6806 | default_collect_info (); | |
d77f58be SS |
6807 | } |
6808 | ||
6809 | static void | |
e5a67952 | 6810 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6811 | { |
e5a67952 | 6812 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6813 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6814 | |
6815 | if (num_printed == 0) | |
6816 | { | |
e5a67952 | 6817 | if (args == NULL || *args == '\0') |
d77f58be SS |
6818 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6819 | else | |
e5a67952 | 6820 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6821 | } |
c906108c SS |
6822 | } |
6823 | ||
7a292a7a | 6824 | static void |
e5a67952 | 6825 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6826 | { |
e5a67952 | 6827 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6828 | |
6829 | default_collect_info (); | |
c906108c SS |
6830 | } |
6831 | ||
0d381245 | 6832 | static int |
714835d5 | 6833 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6834 | struct program_space *pspace, |
714835d5 | 6835 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6836 | { |
6837 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6838 | |
0d381245 VP |
6839 | for (; bl; bl = bl->next) |
6840 | { | |
6c95b8df PA |
6841 | if (bl->pspace == pspace |
6842 | && bl->address == pc | |
0d381245 VP |
6843 | && (!overlay_debugging || bl->section == section)) |
6844 | return 1; | |
6845 | } | |
6846 | return 0; | |
6847 | } | |
6848 | ||
672f9b60 | 6849 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6850 | concerns with logical breakpoints, so we match program spaces, not |
6851 | address spaces. */ | |
c906108c SS |
6852 | |
6853 | static void | |
6c95b8df PA |
6854 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6855 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6856 | struct obj_section *section, int thread) |
c906108c | 6857 | { |
52f0bd74 AC |
6858 | int others = 0; |
6859 | struct breakpoint *b; | |
c906108c SS |
6860 | |
6861 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6862 | others += (user_breakpoint_p (b) |
6863 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6864 | if (others > 0) |
6865 | { | |
a3f17187 AC |
6866 | if (others == 1) |
6867 | printf_filtered (_("Note: breakpoint ")); | |
6868 | else /* if (others == ???) */ | |
6869 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6870 | ALL_BREAKPOINTS (b) |
672f9b60 | 6871 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6872 | { |
6873 | others--; | |
6874 | printf_filtered ("%d", b->number); | |
6875 | if (b->thread == -1 && thread != -1) | |
6876 | printf_filtered (" (all threads)"); | |
6877 | else if (b->thread != -1) | |
6878 | printf_filtered (" (thread %d)", b->thread); | |
6879 | printf_filtered ("%s%s ", | |
059fb39f | 6880 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6881 | || b->enable_state == bp_call_disabled) |
0d381245 | 6882 | ? " (disabled)" |
0d381245 VP |
6883 | : ""), |
6884 | (others > 1) ? "," | |
6885 | : ((others == 1) ? " and" : "")); | |
6886 | } | |
a3f17187 | 6887 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6888 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6889 | printf_filtered (".\n"); |
6890 | } | |
6891 | } | |
6892 | \f | |
c906108c | 6893 | |
e4f237da KB |
6894 | /* Return true iff it is meaningful to use the address member of |
6895 | BPT. For some breakpoint types, the address member is irrelevant | |
6896 | and it makes no sense to attempt to compare it to other addresses | |
6897 | (or use it for any other purpose either). | |
6898 | ||
4a64f543 MS |
6899 | More specifically, each of the following breakpoint types will |
6900 | always have a zero valued address and we don't want to mark | |
6901 | breakpoints of any of these types to be a duplicate of an actual | |
6902 | breakpoint at address zero: | |
e4f237da KB |
6903 | |
6904 | bp_watchpoint | |
2d134ed3 PA |
6905 | bp_catchpoint |
6906 | ||
6907 | */ | |
e4f237da KB |
6908 | |
6909 | static int | |
6910 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6911 | { | |
6912 | enum bptype type = bpt->type; | |
6913 | ||
2d134ed3 PA |
6914 | return (type != bp_watchpoint && type != bp_catchpoint); |
6915 | } | |
6916 | ||
6917 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6918 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6919 | ||
6920 | static int | |
4a64f543 MS |
6921 | watchpoint_locations_match (struct bp_location *loc1, |
6922 | struct bp_location *loc2) | |
2d134ed3 | 6923 | { |
3a5c3e22 PA |
6924 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6925 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6926 | ||
6927 | /* Both of them must exist. */ | |
6928 | gdb_assert (w1 != NULL); | |
6929 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6930 | |
4a64f543 MS |
6931 | /* If the target can evaluate the condition expression in hardware, |
6932 | then we we need to insert both watchpoints even if they are at | |
6933 | the same place. Otherwise the watchpoint will only trigger when | |
6934 | the condition of whichever watchpoint was inserted evaluates to | |
6935 | true, not giving a chance for GDB to check the condition of the | |
6936 | other watchpoint. */ | |
3a5c3e22 | 6937 | if ((w1->cond_exp |
4a64f543 MS |
6938 | && target_can_accel_watchpoint_condition (loc1->address, |
6939 | loc1->length, | |
0cf6dd15 | 6940 | loc1->watchpoint_type, |
3a5c3e22 PA |
6941 | w1->cond_exp)) |
6942 | || (w2->cond_exp | |
4a64f543 MS |
6943 | && target_can_accel_watchpoint_condition (loc2->address, |
6944 | loc2->length, | |
0cf6dd15 | 6945 | loc2->watchpoint_type, |
3a5c3e22 | 6946 | w2->cond_exp))) |
0cf6dd15 TJB |
6947 | return 0; |
6948 | ||
85d721b8 PA |
6949 | /* Note that this checks the owner's type, not the location's. In |
6950 | case the target does not support read watchpoints, but does | |
6951 | support access watchpoints, we'll have bp_read_watchpoint | |
6952 | watchpoints with hw_access locations. Those should be considered | |
6953 | duplicates of hw_read locations. The hw_read locations will | |
6954 | become hw_access locations later. */ | |
2d134ed3 PA |
6955 | return (loc1->owner->type == loc2->owner->type |
6956 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6957 | && loc1->address == loc2->address | |
6958 | && loc1->length == loc2->length); | |
e4f237da KB |
6959 | } |
6960 | ||
31e77af2 | 6961 | /* See breakpoint.h. */ |
6c95b8df | 6962 | |
31e77af2 | 6963 | int |
6c95b8df PA |
6964 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
6965 | struct address_space *aspace2, CORE_ADDR addr2) | |
6966 | { | |
f5656ead | 6967 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6968 | || aspace1 == aspace2) |
6969 | && addr1 == addr2); | |
6970 | } | |
6971 | ||
f1310107 TJB |
6972 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6973 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6974 | matches ASPACE2. On targets that have global breakpoints, the address | |
6975 | space doesn't really matter. */ | |
6976 | ||
6977 | static int | |
6978 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
6979 | int len1, struct address_space *aspace2, | |
6980 | CORE_ADDR addr2) | |
6981 | { | |
f5656ead | 6982 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6983 | || aspace1 == aspace2) |
6984 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6985 | } | |
6986 | ||
6987 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6988 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6989 | matches the breakpoint's address space. On targets that have global | |
6990 | breakpoints, the address space doesn't really matter. */ | |
6991 | ||
6992 | static int | |
6993 | breakpoint_location_address_match (struct bp_location *bl, | |
6994 | struct address_space *aspace, | |
6995 | CORE_ADDR addr) | |
6996 | { | |
6997 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6998 | aspace, addr) | |
6999 | || (bl->length | |
7000 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7001 | bl->address, bl->length, | |
7002 | aspace, addr))); | |
7003 | } | |
7004 | ||
1e4d1764 YQ |
7005 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7006 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7007 | true, otherwise returns false. */ | |
7008 | ||
7009 | static int | |
7010 | tracepoint_locations_match (struct bp_location *loc1, | |
7011 | struct bp_location *loc2) | |
7012 | { | |
7013 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7014 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7015 | locations at the same address of different tracepoints are regarded as | |
7016 | different locations. */ | |
7017 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7018 | else | |
7019 | return 0; | |
7020 | } | |
7021 | ||
2d134ed3 PA |
7022 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7023 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7024 | represent the same location. */ | |
7025 | ||
7026 | static int | |
4a64f543 MS |
7027 | breakpoint_locations_match (struct bp_location *loc1, |
7028 | struct bp_location *loc2) | |
2d134ed3 | 7029 | { |
2bdf28a0 JK |
7030 | int hw_point1, hw_point2; |
7031 | ||
7032 | /* Both of them must not be in moribund_locations. */ | |
7033 | gdb_assert (loc1->owner != NULL); | |
7034 | gdb_assert (loc2->owner != NULL); | |
7035 | ||
7036 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7037 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7038 | |
7039 | if (hw_point1 != hw_point2) | |
7040 | return 0; | |
7041 | else if (hw_point1) | |
7042 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7043 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7044 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7045 | else |
f1310107 TJB |
7046 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7047 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7048 | loc2->pspace->aspace, loc2->address) | |
7049 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7050 | } |
7051 | ||
76897487 KB |
7052 | static void |
7053 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7054 | int bnum, int have_bnum) | |
7055 | { | |
f63fbe86 MS |
7056 | /* The longest string possibly returned by hex_string_custom |
7057 | is 50 chars. These must be at least that big for safety. */ | |
7058 | char astr1[64]; | |
7059 | char astr2[64]; | |
76897487 | 7060 | |
bb599908 PH |
7061 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7062 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7063 | if (have_bnum) |
8a3fe4f8 | 7064 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7065 | bnum, astr1, astr2); |
7066 | else | |
8a3fe4f8 | 7067 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7068 | } |
7069 | ||
4a64f543 MS |
7070 | /* Adjust a breakpoint's address to account for architectural |
7071 | constraints on breakpoint placement. Return the adjusted address. | |
7072 | Note: Very few targets require this kind of adjustment. For most | |
7073 | targets, this function is simply the identity function. */ | |
76897487 KB |
7074 | |
7075 | static CORE_ADDR | |
a6d9a66e UW |
7076 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7077 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7078 | { |
a6d9a66e | 7079 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7080 | { |
7081 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7082 | return bpaddr; | |
7083 | } | |
88f7da05 KB |
7084 | else if (bptype == bp_watchpoint |
7085 | || bptype == bp_hardware_watchpoint | |
7086 | || bptype == bp_read_watchpoint | |
7087 | || bptype == bp_access_watchpoint | |
fe798b75 | 7088 | || bptype == bp_catchpoint) |
88f7da05 KB |
7089 | { |
7090 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7091 | have their addresses modified. */ | |
7092 | return bpaddr; | |
7093 | } | |
7c16b83e PA |
7094 | else if (bptype == bp_single_step) |
7095 | { | |
7096 | /* Single-step breakpoints should not have their addresses | |
7097 | modified. If there's any architectural constrain that | |
7098 | applies to this address, then it should have already been | |
7099 | taken into account when the breakpoint was created in the | |
7100 | first place. If we didn't do this, stepping through e.g., | |
7101 | Thumb-2 IT blocks would break. */ | |
7102 | return bpaddr; | |
7103 | } | |
76897487 KB |
7104 | else |
7105 | { | |
7106 | CORE_ADDR adjusted_bpaddr; | |
7107 | ||
7108 | /* Some targets have architectural constraints on the placement | |
7109 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7110 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7111 | |
7112 | /* An adjusted breakpoint address can significantly alter | |
7113 | a user's expectations. Print a warning if an adjustment | |
7114 | is required. */ | |
7115 | if (adjusted_bpaddr != bpaddr) | |
7116 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7117 | ||
7118 | return adjusted_bpaddr; | |
7119 | } | |
7120 | } | |
7121 | ||
28010a5d PA |
7122 | void |
7123 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7124 | struct breakpoint *owner) | |
7cc221ef | 7125 | { |
7cc221ef DJ |
7126 | memset (loc, 0, sizeof (*loc)); |
7127 | ||
348d480f PA |
7128 | gdb_assert (ops != NULL); |
7129 | ||
28010a5d PA |
7130 | loc->ops = ops; |
7131 | loc->owner = owner; | |
511a6cd4 | 7132 | loc->cond = NULL; |
b775012e | 7133 | loc->cond_bytecode = NULL; |
0d381245 VP |
7134 | loc->shlib_disabled = 0; |
7135 | loc->enabled = 1; | |
e049a4b5 | 7136 | |
28010a5d | 7137 | switch (owner->type) |
e049a4b5 DJ |
7138 | { |
7139 | case bp_breakpoint: | |
7c16b83e | 7140 | case bp_single_step: |
e049a4b5 DJ |
7141 | case bp_until: |
7142 | case bp_finish: | |
7143 | case bp_longjmp: | |
7144 | case bp_longjmp_resume: | |
e2e4d78b | 7145 | case bp_longjmp_call_dummy: |
186c406b TT |
7146 | case bp_exception: |
7147 | case bp_exception_resume: | |
e049a4b5 | 7148 | case bp_step_resume: |
2c03e5be | 7149 | case bp_hp_step_resume: |
e049a4b5 DJ |
7150 | case bp_watchpoint_scope: |
7151 | case bp_call_dummy: | |
aa7d318d | 7152 | case bp_std_terminate: |
e049a4b5 DJ |
7153 | case bp_shlib_event: |
7154 | case bp_thread_event: | |
7155 | case bp_overlay_event: | |
4efc6507 | 7156 | case bp_jit_event: |
0fd8e87f | 7157 | case bp_longjmp_master: |
aa7d318d | 7158 | case bp_std_terminate_master: |
186c406b | 7159 | case bp_exception_master: |
0e30163f JK |
7160 | case bp_gnu_ifunc_resolver: |
7161 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7162 | case bp_dprintf: |
e049a4b5 | 7163 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7164 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7165 | break; |
7166 | case bp_hardware_breakpoint: | |
7167 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7168 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7169 | break; |
7170 | case bp_hardware_watchpoint: | |
7171 | case bp_read_watchpoint: | |
7172 | case bp_access_watchpoint: | |
7173 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7174 | break; | |
7175 | case bp_watchpoint: | |
ce78b96d | 7176 | case bp_catchpoint: |
15c3d785 PA |
7177 | case bp_tracepoint: |
7178 | case bp_fast_tracepoint: | |
0fb4aa4b | 7179 | case bp_static_tracepoint: |
e049a4b5 DJ |
7180 | loc->loc_type = bp_loc_other; |
7181 | break; | |
7182 | default: | |
e2e0b3e5 | 7183 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7184 | } |
7185 | ||
f431efe5 | 7186 | loc->refc = 1; |
28010a5d PA |
7187 | } |
7188 | ||
7189 | /* Allocate a struct bp_location. */ | |
7190 | ||
7191 | static struct bp_location * | |
7192 | allocate_bp_location (struct breakpoint *bpt) | |
7193 | { | |
348d480f PA |
7194 | return bpt->ops->allocate_location (bpt); |
7195 | } | |
7cc221ef | 7196 | |
f431efe5 PA |
7197 | static void |
7198 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7199 | { |
348d480f | 7200 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7201 | xfree (loc); |
7202 | } | |
7203 | ||
f431efe5 PA |
7204 | /* Increment reference count. */ |
7205 | ||
7206 | static void | |
7207 | incref_bp_location (struct bp_location *bl) | |
7208 | { | |
7209 | ++bl->refc; | |
7210 | } | |
7211 | ||
7212 | /* Decrement reference count. If the reference count reaches 0, | |
7213 | destroy the bp_location. Sets *BLP to NULL. */ | |
7214 | ||
7215 | static void | |
7216 | decref_bp_location (struct bp_location **blp) | |
7217 | { | |
0807b50c PA |
7218 | gdb_assert ((*blp)->refc > 0); |
7219 | ||
f431efe5 PA |
7220 | if (--(*blp)->refc == 0) |
7221 | free_bp_location (*blp); | |
7222 | *blp = NULL; | |
7223 | } | |
7224 | ||
346774a9 | 7225 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7226 | |
346774a9 PA |
7227 | static void |
7228 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7229 | { |
346774a9 | 7230 | struct breakpoint *b1; |
c906108c | 7231 | |
346774a9 PA |
7232 | /* Add this breakpoint to the end of the chain so that a list of |
7233 | breakpoints will come out in order of increasing numbers. */ | |
7234 | ||
7235 | b1 = breakpoint_chain; | |
7236 | if (b1 == 0) | |
7237 | breakpoint_chain = b; | |
7238 | else | |
7239 | { | |
7240 | while (b1->next) | |
7241 | b1 = b1->next; | |
7242 | b1->next = b; | |
7243 | } | |
7244 | } | |
7245 | ||
7246 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7247 | ||
7248 | static void | |
7249 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7250 | struct gdbarch *gdbarch, | |
28010a5d | 7251 | enum bptype bptype, |
c0a91b2b | 7252 | const struct breakpoint_ops *ops) |
346774a9 | 7253 | { |
c906108c | 7254 | memset (b, 0, sizeof (*b)); |
2219d63c | 7255 | |
348d480f PA |
7256 | gdb_assert (ops != NULL); |
7257 | ||
28010a5d | 7258 | b->ops = ops; |
4d28f7a8 | 7259 | b->type = bptype; |
a6d9a66e | 7260 | b->gdbarch = gdbarch; |
c906108c SS |
7261 | b->language = current_language->la_language; |
7262 | b->input_radix = input_radix; | |
7263 | b->thread = -1; | |
b5de0fa7 | 7264 | b->enable_state = bp_enabled; |
c906108c SS |
7265 | b->next = 0; |
7266 | b->silent = 0; | |
7267 | b->ignore_count = 0; | |
7268 | b->commands = NULL; | |
818dd999 | 7269 | b->frame_id = null_frame_id; |
0d381245 | 7270 | b->condition_not_parsed = 0; |
84f4c1fe | 7271 | b->py_bp_object = NULL; |
d0fb5eae | 7272 | b->related_breakpoint = b; |
346774a9 PA |
7273 | } |
7274 | ||
7275 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7276 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7277 | |
7278 | static struct breakpoint * | |
7279 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7280 | enum bptype bptype, |
c0a91b2b | 7281 | const struct breakpoint_ops *ops) |
346774a9 PA |
7282 | { |
7283 | struct breakpoint *b = XNEW (struct breakpoint); | |
7284 | ||
348d480f | 7285 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7286 | add_to_breakpoint_chain (b); |
0d381245 VP |
7287 | return b; |
7288 | } | |
7289 | ||
0e30163f JK |
7290 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7291 | resolutions should be made as the user specified the location explicitly | |
7292 | enough. */ | |
7293 | ||
0d381245 | 7294 | static void |
0e30163f | 7295 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7296 | { |
2bdf28a0 JK |
7297 | gdb_assert (loc->owner != NULL); |
7298 | ||
0d381245 | 7299 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7300 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7301 | || is_tracepoint (loc->owner)) |
0d381245 | 7302 | { |
0e30163f | 7303 | int is_gnu_ifunc; |
2c02bd72 | 7304 | const char *function_name; |
6a3a010b | 7305 | CORE_ADDR func_addr; |
0e30163f | 7306 | |
2c02bd72 | 7307 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7308 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7309 | |
7310 | if (is_gnu_ifunc && !explicit_loc) | |
7311 | { | |
7312 | struct breakpoint *b = loc->owner; | |
7313 | ||
7314 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7315 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7316 | &loc->requested_address)) |
7317 | { | |
7318 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7319 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7320 | loc->requested_address, | |
7321 | b->type); | |
7322 | } | |
7323 | else if (b->type == bp_breakpoint && b->loc == loc | |
7324 | && loc->next == NULL && b->related_breakpoint == b) | |
7325 | { | |
7326 | /* Create only the whole new breakpoint of this type but do not | |
7327 | mess more complicated breakpoints with multiple locations. */ | |
7328 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7329 | /* Remember the resolver's address for use by the return |
7330 | breakpoint. */ | |
7331 | loc->related_address = func_addr; | |
0e30163f JK |
7332 | } |
7333 | } | |
7334 | ||
2c02bd72 DE |
7335 | if (function_name) |
7336 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7337 | } |
7338 | } | |
7339 | ||
a6d9a66e | 7340 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7341 | struct gdbarch * |
a6d9a66e UW |
7342 | get_sal_arch (struct symtab_and_line sal) |
7343 | { | |
7344 | if (sal.section) | |
7345 | return get_objfile_arch (sal.section->objfile); | |
7346 | if (sal.symtab) | |
eb822aa6 | 7347 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7348 | |
7349 | return NULL; | |
7350 | } | |
7351 | ||
346774a9 PA |
7352 | /* Low level routine for partially initializing a breakpoint of type |
7353 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7354 | file name, and line number are provided by SAL. |
0d381245 VP |
7355 | |
7356 | It is expected that the caller will complete the initialization of | |
7357 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7358 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7359 | |
346774a9 PA |
7360 | static void |
7361 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7362 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7363 | const struct breakpoint_ops *ops) |
0d381245 | 7364 | { |
28010a5d | 7365 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7366 | |
3742cc8b | 7367 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7368 | |
6c95b8df PA |
7369 | if (bptype != bp_catchpoint) |
7370 | gdb_assert (sal.pspace != NULL); | |
7371 | ||
f8eba3c6 TT |
7372 | /* Store the program space that was used to set the breakpoint, |
7373 | except for ordinary breakpoints, which are independent of the | |
7374 | program space. */ | |
7375 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7376 | b->pspace = sal.pspace; | |
346774a9 | 7377 | } |
c906108c | 7378 | |
346774a9 PA |
7379 | /* set_raw_breakpoint is a low level routine for allocating and |
7380 | partially initializing a breakpoint of type BPTYPE. The newly | |
7381 | created breakpoint's address, section, source file name, and line | |
7382 | number are provided by SAL. The newly created and partially | |
7383 | initialized breakpoint is added to the breakpoint chain and | |
7384 | is also returned as the value of this function. | |
7385 | ||
7386 | It is expected that the caller will complete the initialization of | |
7387 | the newly created breakpoint struct as well as output any status | |
7388 | information regarding the creation of a new breakpoint. In | |
7389 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7390 | number! Care should be taken to not allow an error to occur | |
7391 | prior to completing the initialization of the breakpoint. If this | |
7392 | should happen, a bogus breakpoint will be left on the chain. */ | |
7393 | ||
7394 | struct breakpoint * | |
7395 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7396 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7397 | const struct breakpoint_ops *ops) |
346774a9 PA |
7398 | { |
7399 | struct breakpoint *b = XNEW (struct breakpoint); | |
7400 | ||
348d480f | 7401 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7402 | add_to_breakpoint_chain (b); |
c906108c SS |
7403 | return b; |
7404 | } | |
7405 | ||
c2c6d25f JM |
7406 | |
7407 | /* Note that the breakpoint object B describes a permanent breakpoint | |
7408 | instruction, hard-wired into the inferior's code. */ | |
7409 | void | |
7410 | make_breakpoint_permanent (struct breakpoint *b) | |
7411 | { | |
0d381245 | 7412 | struct bp_location *bl; |
cc59ec59 | 7413 | |
4a64f543 MS |
7414 | /* By definition, permanent breakpoints are already present in the |
7415 | code. Mark all locations as inserted. For now, | |
7416 | make_breakpoint_permanent is called in just one place, so it's | |
7417 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 7418 | multiple locations or not, but it's easy to implement. */ |
0d381245 | 7419 | for (bl = b->loc; bl; bl = bl->next) |
1a853c52 PA |
7420 | { |
7421 | bl->permanent = 1; | |
7422 | bl->inserted = 1; | |
7423 | } | |
c2c6d25f JM |
7424 | } |
7425 | ||
53a5351d | 7426 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7427 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7428 | initiated the operation. */ | |
c906108c SS |
7429 | |
7430 | void | |
186c406b | 7431 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7432 | { |
35df4500 | 7433 | struct breakpoint *b, *b_tmp; |
186c406b | 7434 | int thread = tp->num; |
0fd8e87f UW |
7435 | |
7436 | /* To avoid having to rescan all objfile symbols at every step, | |
7437 | we maintain a list of continually-inserted but always disabled | |
7438 | longjmp "master" breakpoints. Here, we simply create momentary | |
7439 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7440 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7441 | if (b->pspace == current_program_space |
186c406b TT |
7442 | && (b->type == bp_longjmp_master |
7443 | || b->type == bp_exception_master)) | |
0fd8e87f | 7444 | { |
06edf0c0 PA |
7445 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7446 | struct breakpoint *clone; | |
cc59ec59 | 7447 | |
e2e4d78b JK |
7448 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7449 | after their removal. */ | |
06edf0c0 | 7450 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7451 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7452 | clone->thread = thread; |
7453 | } | |
186c406b TT |
7454 | |
7455 | tp->initiating_frame = frame; | |
c906108c SS |
7456 | } |
7457 | ||
611c83ae | 7458 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7459 | void |
611c83ae | 7460 | delete_longjmp_breakpoint (int thread) |
c906108c | 7461 | { |
35df4500 | 7462 | struct breakpoint *b, *b_tmp; |
c906108c | 7463 | |
35df4500 | 7464 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7465 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7466 | { |
7467 | if (b->thread == thread) | |
7468 | delete_breakpoint (b); | |
7469 | } | |
c906108c SS |
7470 | } |
7471 | ||
f59f708a PA |
7472 | void |
7473 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7474 | { | |
7475 | struct breakpoint *b, *b_tmp; | |
7476 | ||
7477 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7478 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7479 | { | |
7480 | if (b->thread == thread) | |
7481 | b->disposition = disp_del_at_next_stop; | |
7482 | } | |
7483 | } | |
7484 | ||
e2e4d78b JK |
7485 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7486 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7487 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7488 | breakpoints. */ | |
7489 | ||
7490 | struct breakpoint * | |
7491 | set_longjmp_breakpoint_for_call_dummy (void) | |
7492 | { | |
7493 | struct breakpoint *b, *retval = NULL; | |
7494 | ||
7495 | ALL_BREAKPOINTS (b) | |
7496 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7497 | { | |
7498 | struct breakpoint *new_b; | |
7499 | ||
7500 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7501 | &momentary_breakpoint_ops, |
7502 | 1); | |
e2e4d78b JK |
7503 | new_b->thread = pid_to_thread_id (inferior_ptid); |
7504 | ||
7505 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7506 | ||
7507 | gdb_assert (new_b->related_breakpoint == new_b); | |
7508 | if (retval == NULL) | |
7509 | retval = new_b; | |
7510 | new_b->related_breakpoint = retval; | |
7511 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7512 | retval = retval->related_breakpoint; | |
7513 | retval->related_breakpoint = new_b; | |
7514 | } | |
7515 | ||
7516 | return retval; | |
7517 | } | |
7518 | ||
7519 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7520 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7521 | stack. |
7522 | ||
7523 | You should call this function only at places where it is safe to currently | |
7524 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7525 | frames. */ | |
7526 | ||
7527 | void | |
b67a2c6f | 7528 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7529 | { |
7530 | struct breakpoint *b, *b_tmp; | |
7531 | ||
7532 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
b67a2c6f | 7533 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->num) |
e2e4d78b JK |
7534 | { |
7535 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7536 | ||
7537 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7538 | dummy_b = dummy_b->related_breakpoint; | |
7539 | if (dummy_b->type != bp_call_dummy | |
7540 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7541 | continue; | |
7542 | ||
b67a2c6f | 7543 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7544 | |
7545 | while (b->related_breakpoint != b) | |
7546 | { | |
7547 | if (b_tmp == b->related_breakpoint) | |
7548 | b_tmp = b->related_breakpoint->next; | |
7549 | delete_breakpoint (b->related_breakpoint); | |
7550 | } | |
7551 | delete_breakpoint (b); | |
7552 | } | |
7553 | } | |
7554 | ||
1900040c MS |
7555 | void |
7556 | enable_overlay_breakpoints (void) | |
7557 | { | |
52f0bd74 | 7558 | struct breakpoint *b; |
1900040c MS |
7559 | |
7560 | ALL_BREAKPOINTS (b) | |
7561 | if (b->type == bp_overlay_event) | |
7562 | { | |
7563 | b->enable_state = bp_enabled; | |
44702360 | 7564 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7565 | overlay_events_enabled = 1; |
1900040c MS |
7566 | } |
7567 | } | |
7568 | ||
7569 | void | |
7570 | disable_overlay_breakpoints (void) | |
7571 | { | |
52f0bd74 | 7572 | struct breakpoint *b; |
1900040c MS |
7573 | |
7574 | ALL_BREAKPOINTS (b) | |
7575 | if (b->type == bp_overlay_event) | |
7576 | { | |
7577 | b->enable_state = bp_disabled; | |
44702360 | 7578 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7579 | overlay_events_enabled = 0; |
1900040c MS |
7580 | } |
7581 | } | |
7582 | ||
aa7d318d TT |
7583 | /* Set an active std::terminate breakpoint for each std::terminate |
7584 | master breakpoint. */ | |
7585 | void | |
7586 | set_std_terminate_breakpoint (void) | |
7587 | { | |
35df4500 | 7588 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7589 | |
35df4500 | 7590 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7591 | if (b->pspace == current_program_space |
7592 | && b->type == bp_std_terminate_master) | |
7593 | { | |
06edf0c0 | 7594 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7595 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7596 | } |
7597 | } | |
7598 | ||
7599 | /* Delete all the std::terminate breakpoints. */ | |
7600 | void | |
7601 | delete_std_terminate_breakpoint (void) | |
7602 | { | |
35df4500 | 7603 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7604 | |
35df4500 | 7605 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7606 | if (b->type == bp_std_terminate) |
7607 | delete_breakpoint (b); | |
7608 | } | |
7609 | ||
c4093a6a | 7610 | struct breakpoint * |
a6d9a66e | 7611 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7612 | { |
7613 | struct breakpoint *b; | |
c4093a6a | 7614 | |
06edf0c0 PA |
7615 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7616 | &internal_breakpoint_ops); | |
7617 | ||
b5de0fa7 | 7618 | b->enable_state = bp_enabled; |
c4093a6a | 7619 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
7620 | b->addr_string |
7621 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 7622 | |
44702360 | 7623 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7624 | |
c4093a6a JM |
7625 | return b; |
7626 | } | |
7627 | ||
7628 | void | |
7629 | remove_thread_event_breakpoints (void) | |
7630 | { | |
35df4500 | 7631 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7632 | |
35df4500 | 7633 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7634 | if (b->type == bp_thread_event |
7635 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7636 | delete_breakpoint (b); |
7637 | } | |
7638 | ||
0101ce28 JJ |
7639 | struct lang_and_radix |
7640 | { | |
7641 | enum language lang; | |
7642 | int radix; | |
7643 | }; | |
7644 | ||
4efc6507 DE |
7645 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7646 | ||
7647 | struct breakpoint * | |
7648 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7649 | { | |
7650 | struct breakpoint *b; | |
7651 | ||
06edf0c0 PA |
7652 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7653 | &internal_breakpoint_ops); | |
44702360 | 7654 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
4efc6507 DE |
7655 | return b; |
7656 | } | |
0101ce28 | 7657 | |
03673fc7 PP |
7658 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7659 | ||
7660 | void | |
7661 | remove_jit_event_breakpoints (void) | |
7662 | { | |
7663 | struct breakpoint *b, *b_tmp; | |
7664 | ||
7665 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7666 | if (b->type == bp_jit_event | |
7667 | && b->loc->pspace == current_program_space) | |
7668 | delete_breakpoint (b); | |
7669 | } | |
7670 | ||
cae688ec JJ |
7671 | void |
7672 | remove_solib_event_breakpoints (void) | |
7673 | { | |
35df4500 | 7674 | struct breakpoint *b, *b_tmp; |
cae688ec | 7675 | |
35df4500 | 7676 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7677 | if (b->type == bp_shlib_event |
7678 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7679 | delete_breakpoint (b); |
7680 | } | |
7681 | ||
f37f681c PA |
7682 | /* See breakpoint.h. */ |
7683 | ||
7684 | void | |
7685 | remove_solib_event_breakpoints_at_next_stop (void) | |
7686 | { | |
7687 | struct breakpoint *b, *b_tmp; | |
7688 | ||
7689 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7690 | if (b->type == bp_shlib_event | |
7691 | && b->loc->pspace == current_program_space) | |
7692 | b->disposition = disp_del_at_next_stop; | |
7693 | } | |
7694 | ||
04086b45 PA |
7695 | /* Helper for create_solib_event_breakpoint / |
7696 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7697 | INSERT_MODE to pass through to update_global_location_list. */ | |
7698 | ||
7699 | static struct breakpoint * | |
7700 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7701 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7702 | { |
7703 | struct breakpoint *b; | |
7704 | ||
06edf0c0 PA |
7705 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7706 | &internal_breakpoint_ops); | |
04086b45 | 7707 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7708 | return b; |
7709 | } | |
7710 | ||
04086b45 PA |
7711 | struct breakpoint * |
7712 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7713 | { | |
7714 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7715 | } | |
7716 | ||
f37f681c PA |
7717 | /* See breakpoint.h. */ |
7718 | ||
7719 | struct breakpoint * | |
7720 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7721 | { | |
7722 | struct breakpoint *b; | |
7723 | ||
04086b45 PA |
7724 | /* Explicitly tell update_global_location_list to insert |
7725 | locations. */ | |
7726 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7727 | if (!b->loc->inserted) |
7728 | { | |
7729 | delete_breakpoint (b); | |
7730 | return NULL; | |
7731 | } | |
7732 | return b; | |
7733 | } | |
7734 | ||
cae688ec JJ |
7735 | /* Disable any breakpoints that are on code in shared libraries. Only |
7736 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7737 | ||
7738 | void | |
cb851954 | 7739 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7740 | { |
876fa593 | 7741 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7742 | |
876fa593 | 7743 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7744 | { |
2bdf28a0 | 7745 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7746 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7747 | |
4a64f543 MS |
7748 | /* We apply the check to all breakpoints, including disabled for |
7749 | those with loc->duplicate set. This is so that when breakpoint | |
7750 | becomes enabled, or the duplicate is removed, gdb will try to | |
7751 | insert all breakpoints. If we don't set shlib_disabled here, | |
7752 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7753 | if (((b->type == bp_breakpoint) |
508ccb1f | 7754 | || (b->type == bp_jit_event) |
1042e4c0 | 7755 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7756 | || (is_tracepoint (b))) |
6c95b8df | 7757 | && loc->pspace == current_program_space |
0d381245 | 7758 | && !loc->shlib_disabled |
6c95b8df | 7759 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7760 | ) |
0d381245 VP |
7761 | { |
7762 | loc->shlib_disabled = 1; | |
7763 | } | |
cae688ec JJ |
7764 | } |
7765 | } | |
7766 | ||
63644780 NB |
7767 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7768 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7769 | disabled ones can just stay disabled. */ | |
84acb35a | 7770 | |
75149521 | 7771 | static void |
84acb35a JJ |
7772 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7773 | { | |
876fa593 | 7774 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7775 | int disabled_shlib_breaks = 0; |
7776 | ||
c86cf029 VP |
7777 | /* SunOS a.out shared libraries are always mapped, so do not |
7778 | disable breakpoints; they will only be reported as unloaded | |
7779 | through clear_solib when GDB discards its shared library | |
7780 | list. See clear_solib for more information. */ | |
7781 | if (exec_bfd != NULL | |
7782 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7783 | return; | |
7784 | ||
876fa593 | 7785 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7786 | { |
2bdf28a0 | 7787 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7788 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7789 | |
1e4d1764 | 7790 | if (solib->pspace == loc->pspace |
e2dd7057 | 7791 | && !loc->shlib_disabled |
1e4d1764 YQ |
7792 | && (((b->type == bp_breakpoint |
7793 | || b->type == bp_jit_event | |
7794 | || b->type == bp_hardware_breakpoint) | |
7795 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7796 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7797 | || is_tracepoint (b)) | |
e2dd7057 | 7798 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7799 | { |
e2dd7057 PP |
7800 | loc->shlib_disabled = 1; |
7801 | /* At this point, we cannot rely on remove_breakpoint | |
7802 | succeeding so we must mark the breakpoint as not inserted | |
7803 | to prevent future errors occurring in remove_breakpoints. */ | |
7804 | loc->inserted = 0; | |
8d3788bd VP |
7805 | |
7806 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7807 | observer_notify_breakpoint_modified (b); | |
7808 | ||
e2dd7057 PP |
7809 | if (!disabled_shlib_breaks) |
7810 | { | |
7811 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7812 | warning (_("Temporarily disabling breakpoints " |
7813 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7814 | solib->so_name); |
84acb35a | 7815 | } |
e2dd7057 | 7816 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7817 | } |
7818 | } | |
84acb35a JJ |
7819 | } |
7820 | ||
63644780 NB |
7821 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7822 | notification of free_objfile. Only apply to enabled breakpoints, | |
7823 | disabled ones can just stay disabled. */ | |
7824 | ||
7825 | static void | |
7826 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7827 | { | |
7828 | struct breakpoint *b; | |
7829 | ||
7830 | if (objfile == NULL) | |
7831 | return; | |
7832 | ||
d03de421 PA |
7833 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7834 | managed by the user with add-symbol-file/remove-symbol-file. | |
7835 | Similarly to how breakpoints in shared libraries are handled in | |
7836 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7837 | shlib_disabled so they end up uninserted on the next global |
7838 | location list update. Shared libraries not loaded by the user | |
7839 | aren't handled here -- they're already handled in | |
7840 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7841 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7842 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7843 | main objfile). */ | |
7844 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7845 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7846 | return; |
7847 | ||
7848 | ALL_BREAKPOINTS (b) | |
7849 | { | |
7850 | struct bp_location *loc; | |
7851 | int bp_modified = 0; | |
7852 | ||
7853 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7854 | continue; | |
7855 | ||
7856 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7857 | { | |
7858 | CORE_ADDR loc_addr = loc->address; | |
7859 | ||
7860 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7861 | && loc->loc_type != bp_loc_software_breakpoint) | |
7862 | continue; | |
7863 | ||
7864 | if (loc->shlib_disabled != 0) | |
7865 | continue; | |
7866 | ||
7867 | if (objfile->pspace != loc->pspace) | |
7868 | continue; | |
7869 | ||
7870 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7871 | && loc->loc_type != bp_loc_software_breakpoint) | |
7872 | continue; | |
7873 | ||
7874 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7875 | { | |
7876 | loc->shlib_disabled = 1; | |
08351840 PA |
7877 | /* At this point, we don't know whether the object was |
7878 | unmapped from the inferior or not, so leave the | |
7879 | inserted flag alone. We'll handle failure to | |
7880 | uninsert quietly, in case the object was indeed | |
7881 | unmapped. */ | |
63644780 NB |
7882 | |
7883 | mark_breakpoint_location_modified (loc); | |
7884 | ||
7885 | bp_modified = 1; | |
7886 | } | |
7887 | } | |
7888 | ||
7889 | if (bp_modified) | |
7890 | observer_notify_breakpoint_modified (b); | |
7891 | } | |
7892 | } | |
7893 | ||
ce78b96d JB |
7894 | /* FORK & VFORK catchpoints. */ |
7895 | ||
e29a4733 PA |
7896 | /* An instance of this type is used to represent a fork or vfork |
7897 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
7898 | class; users downcast to "struct breakpoint *" when needed. A | |
7899 | breakpoint is really of this type iff its ops pointer points to | |
7900 | CATCH_FORK_BREAKPOINT_OPS. */ | |
7901 | ||
7902 | struct fork_catchpoint | |
7903 | { | |
7904 | /* The base class. */ | |
7905 | struct breakpoint base; | |
7906 | ||
7907 | /* Process id of a child process whose forking triggered this | |
7908 | catchpoint. This field is only valid immediately after this | |
7909 | catchpoint has triggered. */ | |
7910 | ptid_t forked_inferior_pid; | |
7911 | }; | |
7912 | ||
4a64f543 MS |
7913 | /* Implement the "insert" breakpoint_ops method for fork |
7914 | catchpoints. */ | |
ce78b96d | 7915 | |
77b06cd7 TJB |
7916 | static int |
7917 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7918 | { |
dfd4cc63 | 7919 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7920 | } |
7921 | ||
4a64f543 MS |
7922 | /* Implement the "remove" breakpoint_ops method for fork |
7923 | catchpoints. */ | |
ce78b96d JB |
7924 | |
7925 | static int | |
77b06cd7 | 7926 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 7927 | { |
dfd4cc63 | 7928 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7929 | } |
7930 | ||
7931 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7932 | catchpoints. */ | |
7933 | ||
7934 | static int | |
f1310107 | 7935 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7936 | struct address_space *aspace, CORE_ADDR bp_addr, |
7937 | const struct target_waitstatus *ws) | |
ce78b96d | 7938 | { |
e29a4733 PA |
7939 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7940 | ||
f90263c1 TT |
7941 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7942 | return 0; | |
7943 | ||
7944 | c->forked_inferior_pid = ws->value.related_pid; | |
7945 | return 1; | |
ce78b96d JB |
7946 | } |
7947 | ||
4a64f543 MS |
7948 | /* Implement the "print_it" breakpoint_ops method for fork |
7949 | catchpoints. */ | |
ce78b96d JB |
7950 | |
7951 | static enum print_stop_action | |
348d480f | 7952 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7953 | { |
36dfb11c | 7954 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7955 | struct breakpoint *b = bs->breakpoint_at; |
7956 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7957 | |
ce78b96d | 7958 | annotate_catchpoint (b->number); |
36dfb11c TT |
7959 | if (b->disposition == disp_del) |
7960 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7961 | else | |
7962 | ui_out_text (uiout, "\nCatchpoint "); | |
7963 | if (ui_out_is_mi_like_p (uiout)) | |
7964 | { | |
7965 | ui_out_field_string (uiout, "reason", | |
7966 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
7967 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7968 | } | |
7969 | ui_out_field_int (uiout, "bkptno", b->number); | |
7970 | ui_out_text (uiout, " (forked process "); | |
7971 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7972 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7973 | return PRINT_SRC_AND_LOC; |
7974 | } | |
7975 | ||
4a64f543 MS |
7976 | /* Implement the "print_one" breakpoint_ops method for fork |
7977 | catchpoints. */ | |
ce78b96d JB |
7978 | |
7979 | static void | |
a6d9a66e | 7980 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7981 | { |
e29a4733 | 7982 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7983 | struct value_print_options opts; |
79a45e25 | 7984 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7985 | |
7986 | get_user_print_options (&opts); | |
7987 | ||
4a64f543 MS |
7988 | /* Field 4, the address, is omitted (which makes the columns not |
7989 | line up too nicely with the headers, but the effect is relatively | |
7990 | readable). */ | |
79a45b7d | 7991 | if (opts.addressprint) |
ce78b96d JB |
7992 | ui_out_field_skip (uiout, "addr"); |
7993 | annotate_field (5); | |
7994 | ui_out_text (uiout, "fork"); | |
e29a4733 | 7995 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7996 | { |
7997 | ui_out_text (uiout, ", process "); | |
7998 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7999 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8000 | ui_out_spaces (uiout, 1); |
8001 | } | |
8ac3646f TT |
8002 | |
8003 | if (ui_out_is_mi_like_p (uiout)) | |
8004 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
8005 | } |
8006 | ||
8007 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8008 | catchpoints. */ | |
8009 | ||
8010 | static void | |
8011 | print_mention_catch_fork (struct breakpoint *b) | |
8012 | { | |
8013 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8014 | } | |
8015 | ||
6149aea9 PA |
8016 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8017 | catchpoints. */ | |
8018 | ||
8019 | static void | |
8020 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8021 | { | |
8022 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8023 | print_recreate_thread (b, fp); |
6149aea9 PA |
8024 | } |
8025 | ||
ce78b96d JB |
8026 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8027 | ||
2060206e | 8028 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8029 | |
4a64f543 MS |
8030 | /* Implement the "insert" breakpoint_ops method for vfork |
8031 | catchpoints. */ | |
ce78b96d | 8032 | |
77b06cd7 TJB |
8033 | static int |
8034 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8035 | { |
dfd4cc63 | 8036 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8037 | } |
8038 | ||
4a64f543 MS |
8039 | /* Implement the "remove" breakpoint_ops method for vfork |
8040 | catchpoints. */ | |
ce78b96d JB |
8041 | |
8042 | static int | |
77b06cd7 | 8043 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 8044 | { |
dfd4cc63 | 8045 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8046 | } |
8047 | ||
8048 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8049 | catchpoints. */ | |
8050 | ||
8051 | static int | |
f1310107 | 8052 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8053 | struct address_space *aspace, CORE_ADDR bp_addr, |
8054 | const struct target_waitstatus *ws) | |
ce78b96d | 8055 | { |
e29a4733 PA |
8056 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8057 | ||
f90263c1 TT |
8058 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8059 | return 0; | |
8060 | ||
8061 | c->forked_inferior_pid = ws->value.related_pid; | |
8062 | return 1; | |
ce78b96d JB |
8063 | } |
8064 | ||
4a64f543 MS |
8065 | /* Implement the "print_it" breakpoint_ops method for vfork |
8066 | catchpoints. */ | |
ce78b96d JB |
8067 | |
8068 | static enum print_stop_action | |
348d480f | 8069 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8070 | { |
36dfb11c | 8071 | struct ui_out *uiout = current_uiout; |
348d480f | 8072 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8073 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8074 | ||
ce78b96d | 8075 | annotate_catchpoint (b->number); |
36dfb11c TT |
8076 | if (b->disposition == disp_del) |
8077 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8078 | else | |
8079 | ui_out_text (uiout, "\nCatchpoint "); | |
8080 | if (ui_out_is_mi_like_p (uiout)) | |
8081 | { | |
8082 | ui_out_field_string (uiout, "reason", | |
8083 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8084 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8085 | } | |
8086 | ui_out_field_int (uiout, "bkptno", b->number); | |
8087 | ui_out_text (uiout, " (vforked process "); | |
8088 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8089 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8090 | return PRINT_SRC_AND_LOC; |
8091 | } | |
8092 | ||
4a64f543 MS |
8093 | /* Implement the "print_one" breakpoint_ops method for vfork |
8094 | catchpoints. */ | |
ce78b96d JB |
8095 | |
8096 | static void | |
a6d9a66e | 8097 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8098 | { |
e29a4733 | 8099 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8100 | struct value_print_options opts; |
79a45e25 | 8101 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8102 | |
8103 | get_user_print_options (&opts); | |
4a64f543 MS |
8104 | /* Field 4, the address, is omitted (which makes the columns not |
8105 | line up too nicely with the headers, but the effect is relatively | |
8106 | readable). */ | |
79a45b7d | 8107 | if (opts.addressprint) |
ce78b96d JB |
8108 | ui_out_field_skip (uiout, "addr"); |
8109 | annotate_field (5); | |
8110 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8111 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8112 | { |
8113 | ui_out_text (uiout, ", process "); | |
8114 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8115 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8116 | ui_out_spaces (uiout, 1); |
8117 | } | |
8ac3646f TT |
8118 | |
8119 | if (ui_out_is_mi_like_p (uiout)) | |
8120 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8121 | } |
8122 | ||
8123 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8124 | catchpoints. */ | |
8125 | ||
8126 | static void | |
8127 | print_mention_catch_vfork (struct breakpoint *b) | |
8128 | { | |
8129 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8130 | } | |
8131 | ||
6149aea9 PA |
8132 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8133 | catchpoints. */ | |
8134 | ||
8135 | static void | |
8136 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8137 | { | |
8138 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8139 | print_recreate_thread (b, fp); |
6149aea9 PA |
8140 | } |
8141 | ||
ce78b96d JB |
8142 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8143 | ||
2060206e | 8144 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8145 | |
edcc5120 TT |
8146 | /* An instance of this type is used to represent an solib catchpoint. |
8147 | It includes a "struct breakpoint" as a kind of base class; users | |
8148 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8149 | really of this type iff its ops pointer points to | |
8150 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8151 | ||
8152 | struct solib_catchpoint | |
8153 | { | |
8154 | /* The base class. */ | |
8155 | struct breakpoint base; | |
8156 | ||
8157 | /* True for "catch load", false for "catch unload". */ | |
8158 | unsigned char is_load; | |
8159 | ||
8160 | /* Regular expression to match, if any. COMPILED is only valid when | |
8161 | REGEX is non-NULL. */ | |
8162 | char *regex; | |
8163 | regex_t compiled; | |
8164 | }; | |
8165 | ||
8166 | static void | |
8167 | dtor_catch_solib (struct breakpoint *b) | |
8168 | { | |
8169 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8170 | ||
8171 | if (self->regex) | |
8172 | regfree (&self->compiled); | |
8173 | xfree (self->regex); | |
8174 | ||
8175 | base_breakpoint_ops.dtor (b); | |
8176 | } | |
8177 | ||
8178 | static int | |
8179 | insert_catch_solib (struct bp_location *ignore) | |
8180 | { | |
8181 | return 0; | |
8182 | } | |
8183 | ||
8184 | static int | |
8185 | remove_catch_solib (struct bp_location *ignore) | |
8186 | { | |
8187 | return 0; | |
8188 | } | |
8189 | ||
8190 | static int | |
8191 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8192 | struct address_space *aspace, | |
8193 | CORE_ADDR bp_addr, | |
8194 | const struct target_waitstatus *ws) | |
8195 | { | |
8196 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8197 | struct breakpoint *other; | |
8198 | ||
8199 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8200 | return 1; | |
8201 | ||
8202 | ALL_BREAKPOINTS (other) | |
8203 | { | |
8204 | struct bp_location *other_bl; | |
8205 | ||
8206 | if (other == bl->owner) | |
8207 | continue; | |
8208 | ||
8209 | if (other->type != bp_shlib_event) | |
8210 | continue; | |
8211 | ||
8212 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8213 | continue; | |
8214 | ||
8215 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8216 | { | |
8217 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8218 | return 1; | |
8219 | } | |
8220 | } | |
8221 | ||
8222 | return 0; | |
8223 | } | |
8224 | ||
8225 | static void | |
8226 | check_status_catch_solib (struct bpstats *bs) | |
8227 | { | |
8228 | struct solib_catchpoint *self | |
8229 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8230 | int ix; | |
8231 | ||
8232 | if (self->is_load) | |
8233 | { | |
8234 | struct so_list *iter; | |
8235 | ||
8236 | for (ix = 0; | |
8237 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8238 | ix, iter); | |
8239 | ++ix) | |
8240 | { | |
8241 | if (!self->regex | |
8242 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8243 | return; | |
8244 | } | |
8245 | } | |
8246 | else | |
8247 | { | |
8248 | char *iter; | |
8249 | ||
8250 | for (ix = 0; | |
8251 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8252 | ix, iter); | |
8253 | ++ix) | |
8254 | { | |
8255 | if (!self->regex | |
8256 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8257 | return; | |
8258 | } | |
8259 | } | |
8260 | ||
8261 | bs->stop = 0; | |
8262 | bs->print_it = print_it_noop; | |
8263 | } | |
8264 | ||
8265 | static enum print_stop_action | |
8266 | print_it_catch_solib (bpstat bs) | |
8267 | { | |
8268 | struct breakpoint *b = bs->breakpoint_at; | |
8269 | struct ui_out *uiout = current_uiout; | |
8270 | ||
8271 | annotate_catchpoint (b->number); | |
8272 | if (b->disposition == disp_del) | |
8273 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8274 | else | |
8275 | ui_out_text (uiout, "\nCatchpoint "); | |
8276 | ui_out_field_int (uiout, "bkptno", b->number); | |
8277 | ui_out_text (uiout, "\n"); | |
8278 | if (ui_out_is_mi_like_p (uiout)) | |
8279 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8280 | print_solib_event (1); | |
8281 | return PRINT_SRC_AND_LOC; | |
8282 | } | |
8283 | ||
8284 | static void | |
8285 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8286 | { | |
8287 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8288 | struct value_print_options opts; | |
8289 | struct ui_out *uiout = current_uiout; | |
8290 | char *msg; | |
8291 | ||
8292 | get_user_print_options (&opts); | |
8293 | /* Field 4, the address, is omitted (which makes the columns not | |
8294 | line up too nicely with the headers, but the effect is relatively | |
8295 | readable). */ | |
8296 | if (opts.addressprint) | |
8297 | { | |
8298 | annotate_field (4); | |
8299 | ui_out_field_skip (uiout, "addr"); | |
8300 | } | |
8301 | ||
8302 | annotate_field (5); | |
8303 | if (self->is_load) | |
8304 | { | |
8305 | if (self->regex) | |
8306 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8307 | else | |
8308 | msg = xstrdup (_("load of library")); | |
8309 | } | |
8310 | else | |
8311 | { | |
8312 | if (self->regex) | |
8313 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8314 | else | |
8315 | msg = xstrdup (_("unload of library")); | |
8316 | } | |
8317 | ui_out_field_string (uiout, "what", msg); | |
8318 | xfree (msg); | |
8ac3646f TT |
8319 | |
8320 | if (ui_out_is_mi_like_p (uiout)) | |
8321 | ui_out_field_string (uiout, "catch-type", | |
8322 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8323 | } |
8324 | ||
8325 | static void | |
8326 | print_mention_catch_solib (struct breakpoint *b) | |
8327 | { | |
8328 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8329 | ||
8330 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8331 | self->is_load ? "load" : "unload"); | |
8332 | } | |
8333 | ||
8334 | static void | |
8335 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8336 | { | |
8337 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8338 | ||
8339 | fprintf_unfiltered (fp, "%s %s", | |
8340 | b->disposition == disp_del ? "tcatch" : "catch", | |
8341 | self->is_load ? "load" : "unload"); | |
8342 | if (self->regex) | |
8343 | fprintf_unfiltered (fp, " %s", self->regex); | |
8344 | fprintf_unfiltered (fp, "\n"); | |
8345 | } | |
8346 | ||
8347 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8348 | ||
91985142 MG |
8349 | /* Shared helper function (MI and CLI) for creating and installing |
8350 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8351 | the events to be caught are load events, otherwise they are | |
8352 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8353 | temporary one. If ENABLED is non-zero the catchpoint is | |
8354 | created in an enabled state. */ | |
edcc5120 | 8355 | |
91985142 MG |
8356 | void |
8357 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8358 | { |
8359 | struct solib_catchpoint *c; | |
8360 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8361 | struct cleanup *cleanup; |
8362 | ||
edcc5120 TT |
8363 | if (!arg) |
8364 | arg = ""; | |
8365 | arg = skip_spaces (arg); | |
8366 | ||
8367 | c = XCNEW (struct solib_catchpoint); | |
8368 | cleanup = make_cleanup (xfree, c); | |
8369 | ||
8370 | if (*arg != '\0') | |
8371 | { | |
8372 | int errcode; | |
8373 | ||
8374 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8375 | if (errcode != 0) | |
8376 | { | |
8377 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8378 | ||
8379 | make_cleanup (xfree, err); | |
8380 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8381 | } | |
8382 | c->regex = xstrdup (arg); | |
8383 | } | |
8384 | ||
8385 | c->is_load = is_load; | |
91985142 | 8386 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8387 | &catch_solib_breakpoint_ops); |
8388 | ||
91985142 MG |
8389 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8390 | ||
edcc5120 TT |
8391 | discard_cleanups (cleanup); |
8392 | install_breakpoint (0, &c->base, 1); | |
8393 | } | |
8394 | ||
91985142 MG |
8395 | /* A helper function that does all the work for "catch load" and |
8396 | "catch unload". */ | |
8397 | ||
8398 | static void | |
8399 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8400 | struct cmd_list_element *command) | |
8401 | { | |
8402 | int tempflag; | |
8403 | const int enabled = 1; | |
8404 | ||
8405 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8406 | ||
8407 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8408 | } | |
8409 | ||
edcc5120 TT |
8410 | static void |
8411 | catch_load_command_1 (char *arg, int from_tty, | |
8412 | struct cmd_list_element *command) | |
8413 | { | |
8414 | catch_load_or_unload (arg, from_tty, 1, command); | |
8415 | } | |
8416 | ||
8417 | static void | |
8418 | catch_unload_command_1 (char *arg, int from_tty, | |
8419 | struct cmd_list_element *command) | |
8420 | { | |
8421 | catch_load_or_unload (arg, from_tty, 0, command); | |
8422 | } | |
8423 | ||
be5c67c1 PA |
8424 | /* An instance of this type is used to represent a syscall catchpoint. |
8425 | It includes a "struct breakpoint" as a kind of base class; users | |
8426 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8427 | really of this type iff its ops pointer points to | |
8428 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
8429 | ||
8430 | struct syscall_catchpoint | |
8431 | { | |
8432 | /* The base class. */ | |
8433 | struct breakpoint base; | |
8434 | ||
8435 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
8436 | syscall has been specified for filtering, its value is NULL. | |
8437 | Otherwise, it holds a list of all syscalls to be caught. The | |
8438 | list elements are allocated with xmalloc. */ | |
8439 | VEC(int) *syscalls_to_be_caught; | |
8440 | }; | |
8441 | ||
8442 | /* Implement the "dtor" breakpoint_ops method for syscall | |
8443 | catchpoints. */ | |
8444 | ||
8445 | static void | |
8446 | dtor_catch_syscall (struct breakpoint *b) | |
8447 | { | |
8448 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
8449 | ||
8450 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 8451 | |
2060206e | 8452 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
8453 | } |
8454 | ||
fa3064dd YQ |
8455 | static const struct inferior_data *catch_syscall_inferior_data = NULL; |
8456 | ||
8457 | struct catch_syscall_inferior_data | |
8458 | { | |
8459 | /* We keep a count of the number of times the user has requested a | |
8460 | particular syscall to be tracked, and pass this information to the | |
8461 | target. This lets capable targets implement filtering directly. */ | |
8462 | ||
8463 | /* Number of times that "any" syscall is requested. */ | |
8464 | int any_syscall_count; | |
8465 | ||
8466 | /* Count of each system call. */ | |
8467 | VEC(int) *syscalls_counts; | |
8468 | ||
8469 | /* This counts all syscall catch requests, so we can readily determine | |
8470 | if any catching is necessary. */ | |
8471 | int total_syscalls_count; | |
8472 | }; | |
8473 | ||
8474 | static struct catch_syscall_inferior_data* | |
8475 | get_catch_syscall_inferior_data (struct inferior *inf) | |
8476 | { | |
8477 | struct catch_syscall_inferior_data *inf_data; | |
8478 | ||
8479 | inf_data = inferior_data (inf, catch_syscall_inferior_data); | |
8480 | if (inf_data == NULL) | |
8481 | { | |
41bf6aca | 8482 | inf_data = XCNEW (struct catch_syscall_inferior_data); |
fa3064dd YQ |
8483 | set_inferior_data (inf, catch_syscall_inferior_data, inf_data); |
8484 | } | |
8485 | ||
8486 | return inf_data; | |
8487 | } | |
8488 | ||
8489 | static void | |
8490 | catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) | |
8491 | { | |
8492 | xfree (arg); | |
8493 | } | |
8494 | ||
8495 | ||
a96d9b2e SDJ |
8496 | /* Implement the "insert" breakpoint_ops method for syscall |
8497 | catchpoints. */ | |
8498 | ||
77b06cd7 TJB |
8499 | static int |
8500 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 8501 | { |
be5c67c1 | 8502 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8503 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8504 | struct catch_syscall_inferior_data *inf_data |
8505 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8506 | |
fa3064dd | 8507 | ++inf_data->total_syscalls_count; |
be5c67c1 | 8508 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8509 | ++inf_data->any_syscall_count; |
a96d9b2e SDJ |
8510 | else |
8511 | { | |
8512 | int i, iter; | |
cc59ec59 | 8513 | |
a96d9b2e | 8514 | for (i = 0; |
be5c67c1 | 8515 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8516 | i++) |
8517 | { | |
8518 | int elem; | |
cc59ec59 | 8519 | |
fa3064dd | 8520 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e | 8521 | { |
fa3064dd | 8522 | int old_size = VEC_length (int, inf_data->syscalls_counts); |
3e43a32a MS |
8523 | uintptr_t vec_addr_offset |
8524 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e | 8525 | uintptr_t vec_addr; |
fa3064dd YQ |
8526 | VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); |
8527 | vec_addr = ((uintptr_t) VEC_address (int, | |
8528 | inf_data->syscalls_counts) | |
8529 | + vec_addr_offset); | |
a96d9b2e SDJ |
8530 | memset ((void *) vec_addr, 0, |
8531 | (iter + 1 - old_size) * sizeof (int)); | |
8532 | } | |
fa3064dd YQ |
8533 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8534 | VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); | |
a96d9b2e SDJ |
8535 | } |
8536 | } | |
8537 | ||
dfd4cc63 | 8538 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8539 | inf_data->total_syscalls_count != 0, |
8540 | inf_data->any_syscall_count, | |
8541 | VEC_length (int, | |
8542 | inf_data->syscalls_counts), | |
8543 | VEC_address (int, | |
8544 | inf_data->syscalls_counts)); | |
a96d9b2e SDJ |
8545 | } |
8546 | ||
8547 | /* Implement the "remove" breakpoint_ops method for syscall | |
8548 | catchpoints. */ | |
8549 | ||
8550 | static int | |
77b06cd7 | 8551 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 8552 | { |
be5c67c1 | 8553 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8554 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8555 | struct catch_syscall_inferior_data *inf_data |
8556 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8557 | |
fa3064dd | 8558 | --inf_data->total_syscalls_count; |
be5c67c1 | 8559 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8560 | --inf_data->any_syscall_count; |
a96d9b2e SDJ |
8561 | else |
8562 | { | |
8563 | int i, iter; | |
cc59ec59 | 8564 | |
a96d9b2e | 8565 | for (i = 0; |
be5c67c1 | 8566 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8567 | i++) |
8568 | { | |
8569 | int elem; | |
fa3064dd | 8570 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e SDJ |
8571 | /* Shouldn't happen. */ |
8572 | continue; | |
fa3064dd YQ |
8573 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8574 | VEC_replace (int, inf_data->syscalls_counts, iter, --elem); | |
a96d9b2e SDJ |
8575 | } |
8576 | } | |
8577 | ||
dfd4cc63 | 8578 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8579 | inf_data->total_syscalls_count != 0, |
8580 | inf_data->any_syscall_count, | |
8581 | VEC_length (int, | |
8582 | inf_data->syscalls_counts), | |
3e43a32a | 8583 | VEC_address (int, |
fa3064dd | 8584 | inf_data->syscalls_counts)); |
a96d9b2e SDJ |
8585 | } |
8586 | ||
8587 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
8588 | catchpoints. */ | |
8589 | ||
8590 | static int | |
f1310107 | 8591 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
8592 | struct address_space *aspace, CORE_ADDR bp_addr, |
8593 | const struct target_waitstatus *ws) | |
a96d9b2e | 8594 | { |
4a64f543 MS |
8595 | /* We must check if we are catching specific syscalls in this |
8596 | breakpoint. If we are, then we must guarantee that the called | |
8597 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 8598 | int syscall_number = 0; |
be5c67c1 PA |
8599 | const struct syscall_catchpoint *c |
8600 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 8601 | |
f90263c1 TT |
8602 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
8603 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
8604 | return 0; |
8605 | ||
f90263c1 TT |
8606 | syscall_number = ws->value.syscall_number; |
8607 | ||
a96d9b2e | 8608 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 8609 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8610 | { |
8611 | int i, iter; | |
cc59ec59 | 8612 | |
a96d9b2e | 8613 | for (i = 0; |
be5c67c1 | 8614 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8615 | i++) |
8616 | if (syscall_number == iter) | |
4924df79 GKB |
8617 | return 1; |
8618 | ||
8619 | return 0; | |
a96d9b2e SDJ |
8620 | } |
8621 | ||
8622 | return 1; | |
8623 | } | |
8624 | ||
8625 | /* Implement the "print_it" breakpoint_ops method for syscall | |
8626 | catchpoints. */ | |
8627 | ||
8628 | static enum print_stop_action | |
348d480f | 8629 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 8630 | { |
36dfb11c | 8631 | struct ui_out *uiout = current_uiout; |
348d480f | 8632 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
8633 | /* These are needed because we want to know in which state a |
8634 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
8635 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
8636 | must print "called syscall" or "returned from syscall". */ | |
8637 | ptid_t ptid; | |
8638 | struct target_waitstatus last; | |
8639 | struct syscall s; | |
458c8db8 | 8640 | struct gdbarch *gdbarch = bs->bp_location_at->gdbarch; |
a96d9b2e SDJ |
8641 | |
8642 | get_last_target_status (&ptid, &last); | |
8643 | ||
458c8db8 | 8644 | get_syscall_by_number (gdbarch, last.value.syscall_number, &s); |
a96d9b2e SDJ |
8645 | |
8646 | annotate_catchpoint (b->number); | |
8647 | ||
36dfb11c TT |
8648 | if (b->disposition == disp_del) |
8649 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 8650 | else |
36dfb11c TT |
8651 | ui_out_text (uiout, "\nCatchpoint "); |
8652 | if (ui_out_is_mi_like_p (uiout)) | |
8653 | { | |
8654 | ui_out_field_string (uiout, "reason", | |
8655 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
8656 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
8657 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
8658 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8659 | } | |
8660 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
8661 | |
8662 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
8663 | ui_out_text (uiout, " (call to syscall "); |
8664 | else | |
8665 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 8666 | |
36dfb11c TT |
8667 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
8668 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
8669 | if (s.name != NULL) | |
8670 | ui_out_field_string (uiout, "syscall-name", s.name); | |
8671 | ||
8672 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
8673 | |
8674 | return PRINT_SRC_AND_LOC; | |
8675 | } | |
8676 | ||
8677 | /* Implement the "print_one" breakpoint_ops method for syscall | |
8678 | catchpoints. */ | |
8679 | ||
8680 | static void | |
8681 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 8682 | struct bp_location **last_loc) |
a96d9b2e | 8683 | { |
be5c67c1 | 8684 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 8685 | struct value_print_options opts; |
79a45e25 | 8686 | struct ui_out *uiout = current_uiout; |
458c8db8 | 8687 | struct gdbarch *gdbarch = b->loc->gdbarch; |
a96d9b2e SDJ |
8688 | |
8689 | get_user_print_options (&opts); | |
4a64f543 MS |
8690 | /* Field 4, the address, is omitted (which makes the columns not |
8691 | line up too nicely with the headers, but the effect is relatively | |
8692 | readable). */ | |
a96d9b2e SDJ |
8693 | if (opts.addressprint) |
8694 | ui_out_field_skip (uiout, "addr"); | |
8695 | annotate_field (5); | |
8696 | ||
be5c67c1 PA |
8697 | if (c->syscalls_to_be_caught |
8698 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
8699 | ui_out_text (uiout, "syscalls \""); |
8700 | else | |
8701 | ui_out_text (uiout, "syscall \""); | |
8702 | ||
be5c67c1 | 8703 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8704 | { |
8705 | int i, iter; | |
8706 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 8707 | |
a96d9b2e | 8708 | for (i = 0; |
be5c67c1 | 8709 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8710 | i++) |
8711 | { | |
8712 | char *x = text; | |
8713 | struct syscall s; | |
458c8db8 | 8714 | get_syscall_by_number (gdbarch, iter, &s); |
a96d9b2e SDJ |
8715 | |
8716 | if (s.name != NULL) | |
8717 | text = xstrprintf ("%s%s, ", text, s.name); | |
8718 | else | |
8719 | text = xstrprintf ("%s%d, ", text, iter); | |
8720 | ||
8721 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 8722 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
8723 | on every call. */ |
8724 | xfree (x); | |
8725 | } | |
8726 | /* Remove the last comma. */ | |
8727 | text[strlen (text) - 2] = '\0'; | |
8728 | ui_out_field_string (uiout, "what", text); | |
8729 | } | |
8730 | else | |
8731 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
8732 | ui_out_text (uiout, "\" "); | |
8ac3646f TT |
8733 | |
8734 | if (ui_out_is_mi_like_p (uiout)) | |
8735 | ui_out_field_string (uiout, "catch-type", "syscall"); | |
a96d9b2e SDJ |
8736 | } |
8737 | ||
8738 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
8739 | catchpoints. */ | |
8740 | ||
8741 | static void | |
8742 | print_mention_catch_syscall (struct breakpoint *b) | |
8743 | { | |
be5c67c1 | 8744 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
458c8db8 | 8745 | struct gdbarch *gdbarch = b->loc->gdbarch; |
be5c67c1 PA |
8746 | |
8747 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
8748 | { |
8749 | int i, iter; | |
8750 | ||
be5c67c1 | 8751 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
8752 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
8753 | else | |
8754 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
8755 | ||
8756 | for (i = 0; | |
be5c67c1 | 8757 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8758 | i++) |
8759 | { | |
8760 | struct syscall s; | |
458c8db8 | 8761 | get_syscall_by_number (gdbarch, iter, &s); |
a96d9b2e SDJ |
8762 | |
8763 | if (s.name) | |
8764 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
8765 | else | |
8766 | printf_filtered (" %d", s.number); | |
8767 | } | |
8768 | printf_filtered (")"); | |
8769 | } | |
8770 | else | |
8771 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
8772 | b->number); | |
8773 | } | |
8774 | ||
6149aea9 PA |
8775 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
8776 | catchpoints. */ | |
8777 | ||
8778 | static void | |
8779 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
8780 | { | |
be5c67c1 | 8781 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
458c8db8 | 8782 | struct gdbarch *gdbarch = b->loc->gdbarch; |
be5c67c1 | 8783 | |
6149aea9 PA |
8784 | fprintf_unfiltered (fp, "catch syscall"); |
8785 | ||
be5c67c1 | 8786 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
8787 | { |
8788 | int i, iter; | |
8789 | ||
8790 | for (i = 0; | |
be5c67c1 | 8791 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
8792 | i++) |
8793 | { | |
8794 | struct syscall s; | |
8795 | ||
458c8db8 | 8796 | get_syscall_by_number (gdbarch, iter, &s); |
6149aea9 PA |
8797 | if (s.name) |
8798 | fprintf_unfiltered (fp, " %s", s.name); | |
8799 | else | |
8800 | fprintf_unfiltered (fp, " %d", s.number); | |
8801 | } | |
8802 | } | |
d9b3f62e | 8803 | print_recreate_thread (b, fp); |
6149aea9 PA |
8804 | } |
8805 | ||
a96d9b2e SDJ |
8806 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
8807 | ||
2060206e | 8808 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
8809 | |
8810 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
8811 | ||
8812 | static int | |
8813 | syscall_catchpoint_p (struct breakpoint *b) | |
8814 | { | |
8815 | return (b->ops == &catch_syscall_breakpoint_ops); | |
8816 | } | |
8817 | ||
346774a9 PA |
8818 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8819 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8820 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8821 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8822 | |
ab04a2af | 8823 | void |
346774a9 PA |
8824 | init_catchpoint (struct breakpoint *b, |
8825 | struct gdbarch *gdbarch, int tempflag, | |
8826 | char *cond_string, | |
c0a91b2b | 8827 | const struct breakpoint_ops *ops) |
c906108c | 8828 | { |
c5aa993b | 8829 | struct symtab_and_line sal; |
346774a9 | 8830 | |
fe39c653 | 8831 | init_sal (&sal); |
6c95b8df | 8832 | sal.pspace = current_program_space; |
c5aa993b | 8833 | |
28010a5d | 8834 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8835 | |
1b36a34b | 8836 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8837 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8838 | } |
8839 | ||
28010a5d | 8840 | void |
3ea46bff | 8841 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8842 | { |
8843 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8844 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8845 | if (is_tracepoint (b)) |
8846 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8847 | if (!internal) |
8848 | mention (b); | |
c56053d2 | 8849 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8850 | |
8851 | if (update_gll) | |
44702360 | 8852 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8853 | } |
8854 | ||
9b70b993 | 8855 | static void |
a6d9a66e UW |
8856 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8857 | int tempflag, char *cond_string, | |
c0a91b2b | 8858 | const struct breakpoint_ops *ops) |
c906108c | 8859 | { |
e29a4733 | 8860 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8861 | |
e29a4733 PA |
8862 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8863 | ||
8864 | c->forked_inferior_pid = null_ptid; | |
8865 | ||
3ea46bff | 8866 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8867 | } |
8868 | ||
fe798b75 JB |
8869 | /* Exec catchpoints. */ |
8870 | ||
b4d90040 PA |
8871 | /* An instance of this type is used to represent an exec catchpoint. |
8872 | It includes a "struct breakpoint" as a kind of base class; users | |
8873 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8874 | really of this type iff its ops pointer points to | |
8875 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8876 | ||
8877 | struct exec_catchpoint | |
8878 | { | |
8879 | /* The base class. */ | |
8880 | struct breakpoint base; | |
8881 | ||
8882 | /* Filename of a program whose exec triggered this catchpoint. | |
8883 | This field is only valid immediately after this catchpoint has | |
8884 | triggered. */ | |
8885 | char *exec_pathname; | |
8886 | }; | |
8887 | ||
8888 | /* Implement the "dtor" breakpoint_ops method for exec | |
8889 | catchpoints. */ | |
8890 | ||
8891 | static void | |
8892 | dtor_catch_exec (struct breakpoint *b) | |
8893 | { | |
8894 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8895 | ||
8896 | xfree (c->exec_pathname); | |
348d480f | 8897 | |
2060206e | 8898 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8899 | } |
8900 | ||
77b06cd7 TJB |
8901 | static int |
8902 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8903 | { |
dfd4cc63 | 8904 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8905 | } |
c906108c | 8906 | |
fe798b75 | 8907 | static int |
77b06cd7 | 8908 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8909 | { |
dfd4cc63 | 8910 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8911 | } |
c906108c | 8912 | |
fe798b75 | 8913 | static int |
f1310107 | 8914 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8915 | struct address_space *aspace, CORE_ADDR bp_addr, |
8916 | const struct target_waitstatus *ws) | |
fe798b75 | 8917 | { |
b4d90040 PA |
8918 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8919 | ||
f90263c1 TT |
8920 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8921 | return 0; | |
8922 | ||
8923 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8924 | return 1; | |
fe798b75 | 8925 | } |
c906108c | 8926 | |
fe798b75 | 8927 | static enum print_stop_action |
348d480f | 8928 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8929 | { |
36dfb11c | 8930 | struct ui_out *uiout = current_uiout; |
348d480f | 8931 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8932 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8933 | ||
fe798b75 | 8934 | annotate_catchpoint (b->number); |
36dfb11c TT |
8935 | if (b->disposition == disp_del) |
8936 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8937 | else | |
8938 | ui_out_text (uiout, "\nCatchpoint "); | |
8939 | if (ui_out_is_mi_like_p (uiout)) | |
8940 | { | |
8941 | ui_out_field_string (uiout, "reason", | |
8942 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8943 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8944 | } | |
8945 | ui_out_field_int (uiout, "bkptno", b->number); | |
8946 | ui_out_text (uiout, " (exec'd "); | |
8947 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8948 | ui_out_text (uiout, "), "); | |
8949 | ||
fe798b75 | 8950 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8951 | } |
8952 | ||
fe798b75 | 8953 | static void |
a6d9a66e | 8954 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8955 | { |
b4d90040 | 8956 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8957 | struct value_print_options opts; |
79a45e25 | 8958 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8959 | |
8960 | get_user_print_options (&opts); | |
8961 | ||
8962 | /* Field 4, the address, is omitted (which makes the columns | |
8963 | not line up too nicely with the headers, but the effect | |
8964 | is relatively readable). */ | |
8965 | if (opts.addressprint) | |
8966 | ui_out_field_skip (uiout, "addr"); | |
8967 | annotate_field (5); | |
8968 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8969 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8970 | { |
8971 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8972 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8973 | ui_out_text (uiout, "\" "); |
8974 | } | |
8ac3646f TT |
8975 | |
8976 | if (ui_out_is_mi_like_p (uiout)) | |
8977 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8978 | } |
8979 | ||
8980 | static void | |
8981 | print_mention_catch_exec (struct breakpoint *b) | |
8982 | { | |
8983 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8984 | } | |
8985 | ||
6149aea9 PA |
8986 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8987 | catchpoints. */ | |
8988 | ||
8989 | static void | |
8990 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8991 | { | |
8992 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8993 | print_recreate_thread (b, fp); |
6149aea9 PA |
8994 | } |
8995 | ||
2060206e | 8996 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8997 | |
a96d9b2e SDJ |
8998 | static void |
8999 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 9000 | const struct breakpoint_ops *ops) |
a96d9b2e | 9001 | { |
be5c67c1 | 9002 | struct syscall_catchpoint *c; |
a96d9b2e | 9003 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 9004 | |
be5c67c1 PA |
9005 | c = XNEW (struct syscall_catchpoint); |
9006 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
9007 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 9008 | |
3ea46bff | 9009 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
9010 | } |
9011 | ||
c906108c | 9012 | static int |
fba45db2 | 9013 | hw_breakpoint_used_count (void) |
c906108c | 9014 | { |
c906108c | 9015 | int i = 0; |
f1310107 TJB |
9016 | struct breakpoint *b; |
9017 | struct bp_location *bl; | |
c906108c SS |
9018 | |
9019 | ALL_BREAKPOINTS (b) | |
c5aa993b | 9020 | { |
d6b74ac4 | 9021 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
9022 | for (bl = b->loc; bl; bl = bl->next) |
9023 | { | |
9024 | /* Special types of hardware breakpoints may use more than | |
9025 | one register. */ | |
348d480f | 9026 | i += b->ops->resources_needed (bl); |
f1310107 | 9027 | } |
c5aa993b | 9028 | } |
c906108c SS |
9029 | |
9030 | return i; | |
9031 | } | |
9032 | ||
a1398e0c PA |
9033 | /* Returns the resources B would use if it were a hardware |
9034 | watchpoint. */ | |
9035 | ||
c906108c | 9036 | static int |
a1398e0c | 9037 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 9038 | { |
c906108c | 9039 | int i = 0; |
e09342b5 | 9040 | struct bp_location *bl; |
c906108c | 9041 | |
a1398e0c PA |
9042 | if (!breakpoint_enabled (b)) |
9043 | return 0; | |
9044 | ||
9045 | for (bl = b->loc; bl; bl = bl->next) | |
9046 | { | |
9047 | /* Special types of hardware watchpoints may use more than | |
9048 | one register. */ | |
9049 | i += b->ops->resources_needed (bl); | |
9050 | } | |
9051 | ||
9052 | return i; | |
9053 | } | |
9054 | ||
9055 | /* Returns the sum the used resources of all hardware watchpoints of | |
9056 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
9057 | the sum of the used resources of all hardware watchpoints of other | |
9058 | types _not_ TYPE. */ | |
9059 | ||
9060 | static int | |
9061 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
9062 | enum bptype type, int *other_type_used) | |
9063 | { | |
9064 | int i = 0; | |
9065 | struct breakpoint *b; | |
9066 | ||
c906108c SS |
9067 | *other_type_used = 0; |
9068 | ALL_BREAKPOINTS (b) | |
e09342b5 | 9069 | { |
a1398e0c PA |
9070 | if (b == except) |
9071 | continue; | |
e09342b5 TJB |
9072 | if (!breakpoint_enabled (b)) |
9073 | continue; | |
9074 | ||
a1398e0c PA |
9075 | if (b->type == type) |
9076 | i += hw_watchpoint_use_count (b); | |
9077 | else if (is_hardware_watchpoint (b)) | |
9078 | *other_type_used = 1; | |
e09342b5 TJB |
9079 | } |
9080 | ||
c906108c SS |
9081 | return i; |
9082 | } | |
9083 | ||
c906108c | 9084 | void |
fba45db2 | 9085 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 9086 | { |
c5aa993b | 9087 | struct breakpoint *b; |
c906108c SS |
9088 | |
9089 | ALL_BREAKPOINTS (b) | |
c5aa993b | 9090 | { |
cc60f2e3 | 9091 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 9092 | { |
b5de0fa7 | 9093 | b->enable_state = bp_call_disabled; |
44702360 | 9094 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
9095 | } |
9096 | } | |
c906108c SS |
9097 | } |
9098 | ||
9099 | void | |
fba45db2 | 9100 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 9101 | { |
c5aa993b | 9102 | struct breakpoint *b; |
c906108c SS |
9103 | |
9104 | ALL_BREAKPOINTS (b) | |
c5aa993b | 9105 | { |
cc60f2e3 | 9106 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 9107 | { |
b5de0fa7 | 9108 | b->enable_state = bp_enabled; |
44702360 | 9109 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
9110 | } |
9111 | } | |
c906108c SS |
9112 | } |
9113 | ||
8bea4e01 UW |
9114 | void |
9115 | disable_breakpoints_before_startup (void) | |
9116 | { | |
6c95b8df | 9117 | current_program_space->executing_startup = 1; |
44702360 | 9118 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
9119 | } |
9120 | ||
9121 | void | |
9122 | enable_breakpoints_after_startup (void) | |
9123 | { | |
6c95b8df | 9124 | current_program_space->executing_startup = 0; |
f8eba3c6 | 9125 | breakpoint_re_set (); |
8bea4e01 UW |
9126 | } |
9127 | ||
7c16b83e PA |
9128 | /* Create a new single-step breakpoint for thread THREAD, with no |
9129 | locations. */ | |
c906108c | 9130 | |
7c16b83e PA |
9131 | static struct breakpoint * |
9132 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
9133 | { | |
9134 | struct breakpoint *b = XNEW (struct breakpoint); | |
9135 | ||
9136 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
9137 | &momentary_breakpoint_ops); | |
9138 | ||
9139 | b->disposition = disp_donttouch; | |
9140 | b->frame_id = null_frame_id; | |
9141 | ||
9142 | b->thread = thread; | |
9143 | gdb_assert (b->thread != 0); | |
9144 | ||
9145 | add_to_breakpoint_chain (b); | |
9146 | ||
9147 | return b; | |
9148 | } | |
9149 | ||
9150 | /* Set a momentary breakpoint of type TYPE at address specified by | |
9151 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
9152 | frame. */ | |
c906108c SS |
9153 | |
9154 | struct breakpoint * | |
a6d9a66e UW |
9155 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
9156 | struct frame_id frame_id, enum bptype type) | |
c906108c | 9157 | { |
52f0bd74 | 9158 | struct breakpoint *b; |
edb3359d | 9159 | |
193facb3 JK |
9160 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
9161 | tail-called one. */ | |
9162 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 9163 | |
06edf0c0 | 9164 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
9165 | b->enable_state = bp_enabled; |
9166 | b->disposition = disp_donttouch; | |
818dd999 | 9167 | b->frame_id = frame_id; |
c906108c | 9168 | |
4a64f543 MS |
9169 | /* If we're debugging a multi-threaded program, then we want |
9170 | momentary breakpoints to be active in only a single thread of | |
9171 | control. */ | |
39f77062 KB |
9172 | if (in_thread_list (inferior_ptid)) |
9173 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 9174 | |
44702360 | 9175 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 9176 | |
c906108c SS |
9177 | return b; |
9178 | } | |
611c83ae | 9179 | |
06edf0c0 | 9180 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
9181 | The new breakpoint will have type TYPE, use OPS as its |
9182 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 9183 | |
06edf0c0 PA |
9184 | static struct breakpoint * |
9185 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
9186 | enum bptype type, | |
a1aa2221 LM |
9187 | const struct breakpoint_ops *ops, |
9188 | int loc_enabled) | |
e58b0e63 PA |
9189 | { |
9190 | struct breakpoint *copy; | |
9191 | ||
06edf0c0 | 9192 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 9193 | copy->loc = allocate_bp_location (copy); |
0e30163f | 9194 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 9195 | |
a6d9a66e | 9196 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
9197 | copy->loc->requested_address = orig->loc->requested_address; |
9198 | copy->loc->address = orig->loc->address; | |
9199 | copy->loc->section = orig->loc->section; | |
6c95b8df | 9200 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 9201 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 9202 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 9203 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 9204 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
9205 | copy->frame_id = orig->frame_id; |
9206 | copy->thread = orig->thread; | |
6c95b8df | 9207 | copy->pspace = orig->pspace; |
e58b0e63 PA |
9208 | |
9209 | copy->enable_state = bp_enabled; | |
9210 | copy->disposition = disp_donttouch; | |
9211 | copy->number = internal_breakpoint_number--; | |
9212 | ||
44702360 | 9213 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
9214 | return copy; |
9215 | } | |
9216 | ||
06edf0c0 PA |
9217 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
9218 | ORIG is NULL. */ | |
9219 | ||
9220 | struct breakpoint * | |
9221 | clone_momentary_breakpoint (struct breakpoint *orig) | |
9222 | { | |
9223 | /* If there's nothing to clone, then return nothing. */ | |
9224 | if (orig == NULL) | |
9225 | return NULL; | |
9226 | ||
a1aa2221 | 9227 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
9228 | } |
9229 | ||
611c83ae | 9230 | struct breakpoint * |
a6d9a66e UW |
9231 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
9232 | enum bptype type) | |
611c83ae PA |
9233 | { |
9234 | struct symtab_and_line sal; | |
9235 | ||
9236 | sal = find_pc_line (pc, 0); | |
9237 | sal.pc = pc; | |
9238 | sal.section = find_pc_overlay (pc); | |
9239 | sal.explicit_pc = 1; | |
9240 | ||
a6d9a66e | 9241 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 9242 | } |
c906108c | 9243 | \f |
c5aa993b | 9244 | |
c906108c SS |
9245 | /* Tell the user we have just set a breakpoint B. */ |
9246 | ||
9247 | static void | |
fba45db2 | 9248 | mention (struct breakpoint *b) |
c906108c | 9249 | { |
348d480f | 9250 | b->ops->print_mention (b); |
79a45e25 | 9251 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 9252 | return; |
c906108c SS |
9253 | printf_filtered ("\n"); |
9254 | } | |
c906108c | 9255 | \f |
c5aa993b | 9256 | |
1a853c52 PA |
9257 | static int bp_loc_is_permanent (struct bp_location *loc); |
9258 | ||
0d381245 | 9259 | static struct bp_location * |
39d61571 | 9260 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
9261 | const struct symtab_and_line *sal) |
9262 | { | |
9263 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9264 | CORE_ADDR adjusted_address; |
9265 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9266 | ||
9267 | if (loc_gdbarch == NULL) | |
9268 | loc_gdbarch = b->gdbarch; | |
9269 | ||
9270 | /* Adjust the breakpoint's address prior to allocating a location. | |
9271 | Once we call allocate_bp_location(), that mostly uninitialized | |
9272 | location will be placed on the location chain. Adjustment of the | |
9273 | breakpoint may cause target_read_memory() to be called and we do | |
9274 | not want its scan of the location chain to find a breakpoint and | |
9275 | location that's only been partially initialized. */ | |
9276 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9277 | sal->pc, b->type); | |
0d381245 | 9278 | |
d30113d4 | 9279 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9280 | loc = allocate_bp_location (b); |
d30113d4 JK |
9281 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9282 | tmp = &((*tmp)->next)) | |
0d381245 | 9283 | ; |
d30113d4 | 9284 | loc->next = *tmp; |
0d381245 | 9285 | *tmp = loc; |
3742cc8b | 9286 | |
0d381245 | 9287 | loc->requested_address = sal->pc; |
3742cc8b | 9288 | loc->address = adjusted_address; |
6c95b8df | 9289 | loc->pspace = sal->pspace; |
729662a5 TT |
9290 | loc->probe.probe = sal->probe; |
9291 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9292 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9293 | loc->section = sal->section; |
3742cc8b | 9294 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9295 | loc->line_number = sal->line; |
2f202fde | 9296 | loc->symtab = sal->symtab; |
f8eba3c6 | 9297 | |
0e30163f JK |
9298 | set_breakpoint_location_function (loc, |
9299 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 PA |
9300 | |
9301 | if (bp_loc_is_permanent (loc)) | |
9302 | { | |
9303 | loc->inserted = 1; | |
9304 | loc->permanent = 1; | |
9305 | } | |
9306 | ||
0d381245 VP |
9307 | return loc; |
9308 | } | |
514f746b AR |
9309 | \f |
9310 | ||
9311 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9312 | return 0 otherwise. */ | |
9313 | ||
9314 | static int | |
9315 | bp_loc_is_permanent (struct bp_location *loc) | |
9316 | { | |
9317 | int len; | |
9318 | CORE_ADDR addr; | |
1afeeb75 | 9319 | const gdb_byte *bpoint; |
514f746b | 9320 | gdb_byte *target_mem; |
939c61fa JK |
9321 | struct cleanup *cleanup; |
9322 | int retval = 0; | |
514f746b AR |
9323 | |
9324 | gdb_assert (loc != NULL); | |
9325 | ||
e8af5d7a JB |
9326 | /* bp_call_dummy breakpoint locations are usually memory locations |
9327 | where GDB just wrote a breakpoint instruction, making it look | |
9328 | as if there is a permanent breakpoint at that location. Considering | |
9329 | it permanent makes GDB rely on that breakpoint instruction to stop | |
9330 | the program, thus removing the need to insert its own breakpoint | |
9331 | there. This is normally expected to work, except that some versions | |
9332 | of QEMU (Eg: QEMU 2.0.0 for SPARC) just report a fatal problem (Trap | |
9333 | 0x02 while interrupts disabled, Error state) instead of reporting | |
9334 | a SIGTRAP. QEMU should probably be fixed, but in the interest of | |
9335 | compatibility with versions that behave this way, we always consider | |
9336 | bp_call_dummy breakpoint locations as non-permanent. */ | |
9337 | if (loc->owner->type == bp_call_dummy) | |
9338 | return 0; | |
9339 | ||
514f746b | 9340 | addr = loc->address; |
1afeeb75 | 9341 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 9342 | |
939c61fa | 9343 | /* Software breakpoints unsupported? */ |
1afeeb75 | 9344 | if (bpoint == NULL) |
939c61fa JK |
9345 | return 0; |
9346 | ||
514f746b AR |
9347 | target_mem = alloca (len); |
9348 | ||
939c61fa JK |
9349 | /* Enable the automatic memory restoration from breakpoints while |
9350 | we read the memory. Otherwise we could say about our temporary | |
9351 | breakpoints they are permanent. */ | |
6c95b8df PA |
9352 | cleanup = save_current_space_and_thread (); |
9353 | ||
9354 | switch_to_program_space_and_thread (loc->pspace); | |
9355 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 9356 | |
514f746b | 9357 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 9358 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 9359 | retval = 1; |
514f746b | 9360 | |
939c61fa JK |
9361 | do_cleanups (cleanup); |
9362 | ||
9363 | return retval; | |
514f746b AR |
9364 | } |
9365 | ||
e7e0cddf SS |
9366 | /* Build a command list for the dprintf corresponding to the current |
9367 | settings of the dprintf style options. */ | |
9368 | ||
9369 | static void | |
9370 | update_dprintf_command_list (struct breakpoint *b) | |
9371 | { | |
9372 | char *dprintf_args = b->extra_string; | |
9373 | char *printf_line = NULL; | |
9374 | ||
9375 | if (!dprintf_args) | |
9376 | return; | |
9377 | ||
9378 | dprintf_args = skip_spaces (dprintf_args); | |
9379 | ||
9380 | /* Allow a comma, as it may have terminated a location, but don't | |
9381 | insist on it. */ | |
9382 | if (*dprintf_args == ',') | |
9383 | ++dprintf_args; | |
9384 | dprintf_args = skip_spaces (dprintf_args); | |
9385 | ||
9386 | if (*dprintf_args != '"') | |
9387 | error (_("Bad format string, missing '\"'.")); | |
9388 | ||
d3ce09f5 | 9389 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9390 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9391 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9392 | { |
9393 | if (!dprintf_function) | |
9394 | error (_("No function supplied for dprintf call")); | |
9395 | ||
9396 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9397 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9398 | dprintf_function, | |
9399 | dprintf_channel, | |
9400 | dprintf_args); | |
9401 | else | |
9402 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9403 | dprintf_function, | |
9404 | dprintf_args); | |
9405 | } | |
d3ce09f5 SS |
9406 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9407 | { | |
9408 | if (target_can_run_breakpoint_commands ()) | |
9409 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9410 | else | |
9411 | { | |
9412 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9413 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9414 | } | |
9415 | } | |
e7e0cddf SS |
9416 | else |
9417 | internal_error (__FILE__, __LINE__, | |
9418 | _("Invalid dprintf style.")); | |
9419 | ||
f28045c2 | 9420 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9421 | /* Manufacture a printf sequence. */ |
f28045c2 | 9422 | { |
9d6e6e84 HZ |
9423 | struct command_line *printf_cmd_line |
9424 | = xmalloc (sizeof (struct command_line)); | |
e7e0cddf | 9425 | |
f28045c2 YQ |
9426 | printf_cmd_line = xmalloc (sizeof (struct command_line)); |
9427 | printf_cmd_line->control_type = simple_control; | |
9428 | printf_cmd_line->body_count = 0; | |
9429 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9430 | printf_cmd_line->next = NULL; |
f28045c2 | 9431 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9432 | |
f28045c2 YQ |
9433 | breakpoint_set_commands (b, printf_cmd_line); |
9434 | } | |
e7e0cddf SS |
9435 | } |
9436 | ||
9437 | /* Update all dprintf commands, making their command lists reflect | |
9438 | current style settings. */ | |
9439 | ||
9440 | static void | |
9441 | update_dprintf_commands (char *args, int from_tty, | |
9442 | struct cmd_list_element *c) | |
9443 | { | |
9444 | struct breakpoint *b; | |
9445 | ||
9446 | ALL_BREAKPOINTS (b) | |
9447 | { | |
9448 | if (b->type == bp_dprintf) | |
9449 | update_dprintf_command_list (b); | |
9450 | } | |
9451 | } | |
c3f6f71d | 9452 | |
018d34a4 VP |
9453 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
9454 | as textual description of the location, and COND_STRING | |
db107f19 | 9455 | as condition expression. */ |
018d34a4 VP |
9456 | |
9457 | static void | |
d9b3f62e PA |
9458 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
9459 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9460 | char *filter, char *cond_string, |
e7e0cddf | 9461 | char *extra_string, |
d9b3f62e PA |
9462 | enum bptype type, enum bpdisp disposition, |
9463 | int thread, int task, int ignore_count, | |
c0a91b2b | 9464 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9465 | int enabled, int internal, unsigned flags, |
9466 | int display_canonical) | |
018d34a4 | 9467 | { |
0d381245 | 9468 | int i; |
018d34a4 VP |
9469 | |
9470 | if (type == bp_hardware_breakpoint) | |
9471 | { | |
fbbd034e AS |
9472 | int target_resources_ok; |
9473 | ||
9474 | i = hw_breakpoint_used_count (); | |
9475 | target_resources_ok = | |
9476 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9477 | i + 1, 0); |
9478 | if (target_resources_ok == 0) | |
9479 | error (_("No hardware breakpoint support in the target.")); | |
9480 | else if (target_resources_ok < 0) | |
9481 | error (_("Hardware breakpoints used exceeds limit.")); | |
9482 | } | |
9483 | ||
6c95b8df PA |
9484 | gdb_assert (sals.nelts > 0); |
9485 | ||
0d381245 VP |
9486 | for (i = 0; i < sals.nelts; ++i) |
9487 | { | |
9488 | struct symtab_and_line sal = sals.sals[i]; | |
9489 | struct bp_location *loc; | |
9490 | ||
9491 | if (from_tty) | |
5af949e3 UW |
9492 | { |
9493 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9494 | if (!loc_gdbarch) | |
9495 | loc_gdbarch = gdbarch; | |
9496 | ||
9497 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9498 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9499 | } |
0d381245 VP |
9500 | |
9501 | if (i == 0) | |
9502 | { | |
d9b3f62e | 9503 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9504 | b->thread = thread; |
4a306c9a | 9505 | b->task = task; |
855a6e68 | 9506 | |
0d381245 | 9507 | b->cond_string = cond_string; |
e7e0cddf | 9508 | b->extra_string = extra_string; |
0d381245 | 9509 | b->ignore_count = ignore_count; |
41447f92 | 9510 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9511 | b->disposition = disposition; |
6c95b8df | 9512 | |
44f238bb PA |
9513 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9514 | b->loc->inserted = 1; | |
9515 | ||
0fb4aa4b PA |
9516 | if (type == bp_static_tracepoint) |
9517 | { | |
d9b3f62e | 9518 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9519 | struct static_tracepoint_marker marker; |
9520 | ||
983af33b | 9521 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9522 | { |
9523 | /* We already know the marker exists, otherwise, we | |
9524 | wouldn't see a sal for it. */ | |
9525 | char *p = &addr_string[3]; | |
9526 | char *endp; | |
9527 | char *marker_str; | |
0fb4aa4b | 9528 | |
e9cafbcc | 9529 | p = skip_spaces (p); |
0fb4aa4b | 9530 | |
e9cafbcc | 9531 | endp = skip_to_space (p); |
0fb4aa4b PA |
9532 | |
9533 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9534 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9535 | |
3e43a32a MS |
9536 | printf_filtered (_("Probed static tracepoint " |
9537 | "marker \"%s\"\n"), | |
d9b3f62e | 9538 | t->static_trace_marker_id); |
0fb4aa4b PA |
9539 | } |
9540 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9541 | { | |
d9b3f62e | 9542 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9543 | release_static_tracepoint_marker (&marker); |
9544 | ||
3e43a32a MS |
9545 | printf_filtered (_("Probed static tracepoint " |
9546 | "marker \"%s\"\n"), | |
d9b3f62e | 9547 | t->static_trace_marker_id); |
0fb4aa4b PA |
9548 | } |
9549 | else | |
3e43a32a MS |
9550 | warning (_("Couldn't determine the static " |
9551 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9552 | } |
9553 | ||
0d381245 VP |
9554 | loc = b->loc; |
9555 | } | |
9556 | else | |
018d34a4 | 9557 | { |
39d61571 | 9558 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9559 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9560 | loc->inserted = 1; | |
0d381245 VP |
9561 | } |
9562 | ||
9563 | if (b->cond_string) | |
9564 | { | |
bbc13ae3 KS |
9565 | const char *arg = b->cond_string; |
9566 | ||
1bb9788d TT |
9567 | loc->cond = parse_exp_1 (&arg, loc->address, |
9568 | block_for_pc (loc->address), 0); | |
0d381245 | 9569 | if (*arg) |
588ae58c | 9570 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9571 | } |
e7e0cddf SS |
9572 | |
9573 | /* Dynamic printf requires and uses additional arguments on the | |
9574 | command line, otherwise it's an error. */ | |
9575 | if (type == bp_dprintf) | |
9576 | { | |
9577 | if (b->extra_string) | |
9578 | update_dprintf_command_list (b); | |
9579 | else | |
9580 | error (_("Format string required")); | |
9581 | } | |
9582 | else if (b->extra_string) | |
588ae58c | 9583 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9584 | } |
018d34a4 | 9585 | |
56435ebe | 9586 | b->display_canonical = display_canonical; |
018d34a4 VP |
9587 | if (addr_string) |
9588 | b->addr_string = addr_string; | |
9589 | else | |
9590 | /* addr_string has to be used or breakpoint_re_set will delete | |
9591 | me. */ | |
5af949e3 UW |
9592 | b->addr_string |
9593 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 9594 | b->filter = filter; |
d9b3f62e | 9595 | } |
018d34a4 | 9596 | |
d9b3f62e PA |
9597 | static void |
9598 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
9599 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9600 | char *filter, char *cond_string, |
e7e0cddf | 9601 | char *extra_string, |
d9b3f62e PA |
9602 | enum bptype type, enum bpdisp disposition, |
9603 | int thread, int task, int ignore_count, | |
c0a91b2b | 9604 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9605 | int enabled, int internal, unsigned flags, |
9606 | int display_canonical) | |
d9b3f62e PA |
9607 | { |
9608 | struct breakpoint *b; | |
9609 | struct cleanup *old_chain; | |
9610 | ||
9611 | if (is_tracepoint_type (type)) | |
9612 | { | |
9613 | struct tracepoint *t; | |
9614 | ||
9615 | t = XCNEW (struct tracepoint); | |
9616 | b = &t->base; | |
9617 | } | |
9618 | else | |
9619 | b = XNEW (struct breakpoint); | |
9620 | ||
9621 | old_chain = make_cleanup (xfree, b); | |
9622 | ||
9623 | init_breakpoint_sal (b, gdbarch, | |
9624 | sals, addr_string, | |
e7e0cddf | 9625 | filter, cond_string, extra_string, |
d9b3f62e PA |
9626 | type, disposition, |
9627 | thread, task, ignore_count, | |
9628 | ops, from_tty, | |
44f238bb PA |
9629 | enabled, internal, flags, |
9630 | display_canonical); | |
d9b3f62e PA |
9631 | discard_cleanups (old_chain); |
9632 | ||
3ea46bff | 9633 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9634 | } |
9635 | ||
9636 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9637 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9638 | value. COND_STRING, if not NULL, specified the condition to be | |
9639 | used for all breakpoints. Essentially the only case where | |
9640 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9641 | function. In that case, it's still not possible to specify | |
9642 | separate conditions for different overloaded functions, so | |
9643 | we take just a single condition string. | |
9644 | ||
c3f6f71d | 9645 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9646 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9647 | array contents). If the function fails (error() is called), the |
9648 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9649 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9650 | |
9651 | static void | |
8cdf0e15 | 9652 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9653 | struct linespec_result *canonical, |
e7e0cddf | 9654 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9655 | enum bptype type, enum bpdisp disposition, |
9656 | int thread, int task, int ignore_count, | |
c0a91b2b | 9657 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9658 | int enabled, int internal, unsigned flags) |
c906108c | 9659 | { |
018d34a4 | 9660 | int i; |
f8eba3c6 | 9661 | struct linespec_sals *lsal; |
cc59ec59 | 9662 | |
f8eba3c6 TT |
9663 | if (canonical->pre_expanded) |
9664 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9665 | ||
9666 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9667 | { |
f8eba3c6 TT |
9668 | /* Note that 'addr_string' can be NULL in the case of a plain |
9669 | 'break', without arguments. */ | |
9670 | char *addr_string = (canonical->addr_string | |
9671 | ? xstrdup (canonical->addr_string) | |
9672 | : NULL); | |
9673 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
9674 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 9675 | |
f8eba3c6 TT |
9676 | make_cleanup (xfree, filter_string); |
9677 | create_breakpoint_sal (gdbarch, lsal->sals, | |
9678 | addr_string, | |
9679 | filter_string, | |
e7e0cddf SS |
9680 | cond_string, extra_string, |
9681 | type, disposition, | |
84f4c1fe | 9682 | thread, task, ignore_count, ops, |
44f238bb | 9683 | from_tty, enabled, internal, flags, |
56435ebe | 9684 | canonical->special_display); |
f8eba3c6 | 9685 | discard_cleanups (inner); |
c3f6f71d | 9686 | } |
c3f6f71d | 9687 | } |
c906108c | 9688 | |
9998af43 | 9689 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 9690 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 9691 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
9692 | address strings. ADDRESS points to the end of the SAL. |
9693 | ||
9694 | The array and the line spec strings are allocated on the heap, it is | |
9695 | the caller's responsibility to free them. */ | |
c906108c | 9696 | |
b9362cc7 | 9697 | static void |
c3f6f71d | 9698 | parse_breakpoint_sals (char **address, |
58438ac1 | 9699 | struct linespec_result *canonical) |
c3f6f71d | 9700 | { |
c3f6f71d | 9701 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 9702 | breakpoint. */ |
c3f6f71d JM |
9703 | if ((*address) == NULL |
9704 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 9705 | { |
1bfeeb0f JL |
9706 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
9707 | address. */ | |
9708 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9709 | { |
f8eba3c6 | 9710 | struct linespec_sals lsal; |
c3f6f71d | 9711 | struct symtab_and_line sal; |
1c8cdcb1 | 9712 | CORE_ADDR pc; |
cc59ec59 | 9713 | |
4a64f543 | 9714 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 9715 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 9716 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
9717 | |
9718 | /* Set sal's pspace, pc, symtab, and line to the values | |
1c8cdcb1 JK |
9719 | corresponding to the last call to print_frame_info. |
9720 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9721 | as the breakpoint line number is inappropriate otherwise. | |
9722 | find_pc_line would adjust PC, re-set it back. */ | |
1bfeeb0f | 9723 | get_last_displayed_sal (&sal); |
1c8cdcb1 JK |
9724 | pc = sal.pc; |
9725 | sal = find_pc_line (pc, 0); | |
00903456 | 9726 | |
4a64f543 | 9727 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
9728 | where PC is the last displayed codepoint's address. So |
9729 | make sure to set sal.explicit_pc to prevent GDB from | |
9730 | trying to expand the list of sals to include all other | |
9731 | instances with the same symtab and line. */ | |
1c8cdcb1 | 9732 | sal.pc = pc; |
00903456 JK |
9733 | sal.explicit_pc = 1; |
9734 | ||
f8eba3c6 TT |
9735 | lsal.sals.sals[0] = sal; |
9736 | lsal.sals.nelts = 1; | |
9737 | lsal.canonical = NULL; | |
9738 | ||
9739 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
9740 | } |
9741 | else | |
8a3fe4f8 | 9742 | error (_("No default breakpoint address now.")); |
c906108c SS |
9743 | } |
9744 | else | |
9745 | { | |
cc80f267 JK |
9746 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
9747 | ||
c906108c | 9748 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
9749 | current_source_symtab (which is decode_line_1's default). |
9750 | This should produce the results we want almost all of the | |
cc80f267 JK |
9751 | time while leaving default_breakpoint_* alone. |
9752 | ||
9753 | ObjC: However, don't match an Objective-C method name which | |
9754 | may have a '+' or '-' succeeded by a '['. */ | |
9755 | if (last_displayed_sal_is_valid () | |
9756 | && (!cursal.symtab | |
9757 | || ((strchr ("+-", (*address)[0]) != NULL) | |
9758 | && ((*address)[1] != '[')))) | |
f8eba3c6 TT |
9759 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
9760 | get_last_displayed_symtab (), | |
9761 | get_last_displayed_line (), | |
9762 | canonical, NULL, NULL); | |
c906108c | 9763 | else |
f8eba3c6 | 9764 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
cc80f267 | 9765 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c906108c | 9766 | } |
c3f6f71d | 9767 | } |
c906108c | 9768 | |
c906108c | 9769 | |
c3f6f71d | 9770 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9771 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9772 | |
b9362cc7 | 9773 | static void |
23e7acfb | 9774 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9775 | { |
9776 | int i; | |
cc59ec59 | 9777 | |
c3f6f71d | 9778 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9779 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9780 | } |
9781 | ||
7a697b8d SS |
9782 | /* Fast tracepoints may have restrictions on valid locations. For |
9783 | instance, a fast tracepoint using a jump instead of a trap will | |
9784 | likely have to overwrite more bytes than a trap would, and so can | |
9785 | only be placed where the instruction is longer than the jump, or a | |
9786 | multi-instruction sequence does not have a jump into the middle of | |
9787 | it, etc. */ | |
9788 | ||
9789 | static void | |
9790 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9791 | struct symtabs_and_lines *sals) | |
9792 | { | |
9793 | int i, rslt; | |
9794 | struct symtab_and_line *sal; | |
9795 | char *msg; | |
9796 | struct cleanup *old_chain; | |
9797 | ||
9798 | for (i = 0; i < sals->nelts; i++) | |
9799 | { | |
f8eba3c6 TT |
9800 | struct gdbarch *sarch; |
9801 | ||
7a697b8d SS |
9802 | sal = &sals->sals[i]; |
9803 | ||
f8eba3c6 TT |
9804 | sarch = get_sal_arch (*sal); |
9805 | /* We fall back to GDBARCH if there is no architecture | |
9806 | associated with SAL. */ | |
9807 | if (sarch == NULL) | |
9808 | sarch = gdbarch; | |
9809 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
9810 | NULL, &msg); |
9811 | old_chain = make_cleanup (xfree, msg); | |
9812 | ||
9813 | if (!rslt) | |
9814 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9815 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9816 | |
9817 | do_cleanups (old_chain); | |
9818 | } | |
9819 | } | |
9820 | ||
af4908ba KS |
9821 | /* Issue an invalid thread ID error. */ |
9822 | ||
9823 | static void ATTRIBUTE_NORETURN | |
9824 | invalid_thread_id_error (int id) | |
9825 | { | |
9826 | error (_("Unknown thread %d."), id); | |
9827 | } | |
9828 | ||
018d34a4 VP |
9829 | /* Given TOK, a string specification of condition and thread, as |
9830 | accepted by the 'break' command, extract the condition | |
9831 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9832 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9833 | If no condition is found, *COND_STRING is set to NULL. |
9834 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9835 | |
9836 | static void | |
bbc13ae3 | 9837 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9838 | char **cond_string, int *thread, int *task, |
9839 | char **rest) | |
018d34a4 VP |
9840 | { |
9841 | *cond_string = NULL; | |
9842 | *thread = -1; | |
ed1d1739 KS |
9843 | *task = 0; |
9844 | *rest = NULL; | |
9845 | ||
018d34a4 VP |
9846 | while (tok && *tok) |
9847 | { | |
bbc13ae3 | 9848 | const char *end_tok; |
018d34a4 | 9849 | int toklen; |
bbc13ae3 KS |
9850 | const char *cond_start = NULL; |
9851 | const char *cond_end = NULL; | |
cc59ec59 | 9852 | |
bbc13ae3 | 9853 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9854 | |
9855 | if ((*tok == '"' || *tok == ',') && rest) | |
9856 | { | |
9857 | *rest = savestring (tok, strlen (tok)); | |
9858 | return; | |
9859 | } | |
9860 | ||
bbc13ae3 | 9861 | end_tok = skip_to_space_const (tok); |
d634f2de | 9862 | |
018d34a4 | 9863 | toklen = end_tok - tok; |
d634f2de | 9864 | |
018d34a4 VP |
9865 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9866 | { | |
f7545552 TT |
9867 | struct expression *expr; |
9868 | ||
018d34a4 | 9869 | tok = cond_start = end_tok + 1; |
1bb9788d | 9870 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9871 | xfree (expr); |
018d34a4 | 9872 | cond_end = tok; |
d634f2de | 9873 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9874 | } |
9875 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9876 | { | |
9877 | char *tmptok; | |
d634f2de | 9878 | |
018d34a4 | 9879 | tok = end_tok + 1; |
bbc13ae3 | 9880 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9881 | if (tok == tmptok) |
9882 | error (_("Junk after thread keyword.")); | |
9883 | if (!valid_thread_id (*thread)) | |
af4908ba | 9884 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9885 | tok = tmptok; |
018d34a4 | 9886 | } |
4a306c9a JB |
9887 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9888 | { | |
9889 | char *tmptok; | |
9890 | ||
9891 | tok = end_tok + 1; | |
bbc13ae3 | 9892 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9893 | if (tok == tmptok) |
9894 | error (_("Junk after task keyword.")); | |
9895 | if (!valid_task_id (*task)) | |
b6199126 | 9896 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9897 | tok = tmptok; |
4a306c9a | 9898 | } |
e7e0cddf SS |
9899 | else if (rest) |
9900 | { | |
9901 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9902 | return; |
e7e0cddf | 9903 | } |
018d34a4 VP |
9904 | else |
9905 | error (_("Junk at end of arguments.")); | |
9906 | } | |
9907 | } | |
9908 | ||
0fb4aa4b PA |
9909 | /* Decode a static tracepoint marker spec. */ |
9910 | ||
9911 | static struct symtabs_and_lines | |
9912 | decode_static_tracepoint_spec (char **arg_p) | |
9913 | { | |
9914 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9915 | struct symtabs_and_lines sals; | |
0fb4aa4b PA |
9916 | struct cleanup *old_chain; |
9917 | char *p = &(*arg_p)[3]; | |
9918 | char *endp; | |
9919 | char *marker_str; | |
9920 | int i; | |
9921 | ||
e9cafbcc | 9922 | p = skip_spaces (p); |
0fb4aa4b | 9923 | |
e9cafbcc | 9924 | endp = skip_to_space (p); |
0fb4aa4b PA |
9925 | |
9926 | marker_str = savestring (p, endp - p); | |
9927 | old_chain = make_cleanup (xfree, marker_str); | |
9928 | ||
9929 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9930 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9931 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9932 | ||
9933 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
9934 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
9935 | ||
9936 | for (i = 0; i < sals.nelts; i++) | |
9937 | { | |
9938 | struct static_tracepoint_marker *marker; | |
9939 | ||
9940 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9941 | ||
9942 | init_sal (&sals.sals[i]); | |
9943 | ||
9944 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9945 | sals.sals[i].pc = marker->address; | |
9946 | ||
9947 | release_static_tracepoint_marker (marker); | |
9948 | } | |
9949 | ||
9950 | do_cleanups (old_chain); | |
9951 | ||
9952 | *arg_p = endp; | |
9953 | return sals; | |
9954 | } | |
9955 | ||
fd9b8c24 PA |
9956 | /* Set a breakpoint. This function is shared between CLI and MI |
9957 | functions for setting a breakpoint. This function has two major | |
f6de8ec2 PA |
9958 | modes of operations, selected by the PARSE_ARG parameter. If |
9959 | non-zero, the function will parse ARG, extracting location, | |
9960 | condition, thread and extra string. Otherwise, ARG is just the | |
9961 | breakpoint's location, with condition, thread, and extra string | |
9962 | specified by the COND_STRING, THREAD and EXTRA_STRING parameters. | |
9963 | If INTERNAL is non-zero, the breakpoint number will be allocated | |
9964 | from the internal breakpoint count. Returns true if any breakpoint | |
9965 | was created; false otherwise. */ | |
0101ce28 | 9966 | |
8cdf0e15 VP |
9967 | int |
9968 | create_breakpoint (struct gdbarch *gdbarch, | |
e7e0cddf SS |
9969 | char *arg, char *cond_string, |
9970 | int thread, char *extra_string, | |
f6de8ec2 | 9971 | int parse_arg, |
0fb4aa4b | 9972 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9973 | int ignore_count, |
9974 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9975 | const struct breakpoint_ops *ops, |
44f238bb PA |
9976 | int from_tty, int enabled, int internal, |
9977 | unsigned flags) | |
c3f6f71d | 9978 | { |
b78a6381 | 9979 | volatile struct gdb_exception e; |
f8eba3c6 | 9980 | char *copy_arg = NULL; |
c3f6f71d | 9981 | char *addr_start = arg; |
7efd8fc2 | 9982 | struct linespec_result canonical; |
c3f6f71d | 9983 | struct cleanup *old_chain; |
80c99de1 | 9984 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9985 | int pending = 0; |
4a306c9a | 9986 | int task = 0; |
86b17b60 | 9987 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9988 | |
348d480f PA |
9989 | gdb_assert (ops != NULL); |
9990 | ||
7efd8fc2 | 9991 | init_linespec_result (&canonical); |
c3f6f71d | 9992 | |
b78a6381 TT |
9993 | TRY_CATCH (e, RETURN_MASK_ALL) |
9994 | { | |
983af33b SDJ |
9995 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
9996 | addr_start, ©_arg); | |
b78a6381 | 9997 | } |
0101ce28 JJ |
9998 | |
9999 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 10000 | switch (e.reason) |
0101ce28 | 10001 | { |
983af33b SDJ |
10002 | case GDB_NO_ERROR: |
10003 | if (VEC_empty (linespec_sals, canonical.sals)) | |
10004 | return 0; | |
10005 | break; | |
05ff989b AC |
10006 | case RETURN_ERROR: |
10007 | switch (e.error) | |
0101ce28 | 10008 | { |
05ff989b | 10009 | case NOT_FOUND_ERROR: |
0101ce28 | 10010 | |
05ff989b AC |
10011 | /* If pending breakpoint support is turned off, throw |
10012 | error. */ | |
fa8d40ab JJ |
10013 | |
10014 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
10015 | throw_exception (e); |
10016 | ||
10017 | exception_print (gdb_stderr, e); | |
fa8d40ab | 10018 | |
05ff989b AC |
10019 | /* If pending breakpoint support is auto query and the user |
10020 | selects no, then simply return the error code. */ | |
059fb39f | 10021 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
10022 | && !nquery (_("Make %s pending on future shared library load? "), |
10023 | bptype_string (type_wanted))) | |
fd9b8c24 | 10024 | return 0; |
fa8d40ab | 10025 | |
05ff989b AC |
10026 | /* At this point, either the user was queried about setting |
10027 | a pending breakpoint and selected yes, or pending | |
10028 | breakpoint behavior is on and thus a pending breakpoint | |
10029 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
10030 | { |
10031 | struct linespec_sals lsal; | |
10032 | ||
10033 | copy_arg = xstrdup (addr_start); | |
10034 | lsal.canonical = xstrdup (copy_arg); | |
10035 | lsal.sals.nelts = 1; | |
10036 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
10037 | init_sal (&lsal.sals.sals[0]); | |
10038 | pending = 1; | |
10039 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
10040 | } | |
05ff989b AC |
10041 | break; |
10042 | default: | |
98deb0da | 10043 | throw_exception (e); |
0101ce28 | 10044 | } |
2abae994 | 10045 | break; |
05ff989b | 10046 | default: |
983af33b | 10047 | throw_exception (e); |
0101ce28 | 10048 | } |
c3f6f71d | 10049 | |
4a64f543 | 10050 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 10051 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 10052 | |
c3f6f71d JM |
10053 | /* ----------------------------- SNIP ----------------------------- |
10054 | Anything added to the cleanup chain beyond this point is assumed | |
10055 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
10056 | then the memory is not reclaimed. */ |
10057 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 10058 | |
c3f6f71d JM |
10059 | /* Resolve all line numbers to PC's and verify that the addresses |
10060 | are ok for the target. */ | |
0101ce28 | 10061 | if (!pending) |
f8eba3c6 TT |
10062 | { |
10063 | int ix; | |
10064 | struct linespec_sals *iter; | |
10065 | ||
10066 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
10067 | breakpoint_sals_to_pc (&iter->sals); | |
10068 | } | |
c3f6f71d | 10069 | |
7a697b8d | 10070 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 10071 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
10072 | { |
10073 | int ix; | |
10074 | struct linespec_sals *iter; | |
10075 | ||
10076 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
10077 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
10078 | } | |
7a697b8d | 10079 | |
c3f6f71d JM |
10080 | /* Verify that condition can be parsed, before setting any |
10081 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 10082 | breakpoint. */ |
0101ce28 | 10083 | if (!pending) |
c3f6f71d | 10084 | { |
f6de8ec2 | 10085 | if (parse_arg) |
72b2ff0e | 10086 | { |
0878d0fa | 10087 | char *rest; |
52d361e1 YQ |
10088 | struct linespec_sals *lsal; |
10089 | ||
10090 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
10091 | ||
0878d0fa YQ |
10092 | /* Here we only parse 'arg' to separate condition |
10093 | from thread number, so parsing in context of first | |
10094 | sal is OK. When setting the breakpoint we'll | |
10095 | re-parse it in context of each sal. */ | |
10096 | ||
10097 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, | |
10098 | &thread, &task, &rest); | |
10099 | if (cond_string) | |
10100 | make_cleanup (xfree, cond_string); | |
10101 | if (rest) | |
10102 | make_cleanup (xfree, rest); | |
10103 | if (rest) | |
10104 | extra_string = rest; | |
72b2ff0e | 10105 | } |
2f069f6f | 10106 | else |
72b2ff0e | 10107 | { |
0878d0fa YQ |
10108 | if (*arg != '\0') |
10109 | error (_("Garbage '%s' at end of location"), arg); | |
10110 | ||
10111 | /* Create a private copy of condition string. */ | |
10112 | if (cond_string) | |
10113 | { | |
10114 | cond_string = xstrdup (cond_string); | |
10115 | make_cleanup (xfree, cond_string); | |
10116 | } | |
10117 | /* Create a private copy of any extra string. */ | |
10118 | if (extra_string) | |
10119 | { | |
10120 | extra_string = xstrdup (extra_string); | |
10121 | make_cleanup (xfree, extra_string); | |
10122 | } | |
72b2ff0e | 10123 | } |
0fb4aa4b | 10124 | |
52d361e1 | 10125 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 10126 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
10127 | tempflag ? disp_del : disp_donttouch, |
10128 | thread, task, ignore_count, ops, | |
44f238bb | 10129 | from_tty, enabled, internal, flags); |
c906108c | 10130 | } |
0101ce28 JJ |
10131 | else |
10132 | { | |
0101ce28 JJ |
10133 | struct breakpoint *b; |
10134 | ||
0101ce28 JJ |
10135 | make_cleanup (xfree, copy_arg); |
10136 | ||
bfccc43c YQ |
10137 | if (is_tracepoint_type (type_wanted)) |
10138 | { | |
10139 | struct tracepoint *t; | |
10140 | ||
10141 | t = XCNEW (struct tracepoint); | |
10142 | b = &t->base; | |
10143 | } | |
10144 | else | |
10145 | b = XNEW (struct breakpoint); | |
10146 | ||
10147 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
10148 | ||
f8eba3c6 | 10149 | b->addr_string = copy_arg; |
f6de8ec2 | 10150 | if (parse_arg) |
e12c7713 MK |
10151 | b->cond_string = NULL; |
10152 | else | |
10153 | { | |
10154 | /* Create a private copy of condition string. */ | |
10155 | if (cond_string) | |
10156 | { | |
10157 | cond_string = xstrdup (cond_string); | |
10158 | make_cleanup (xfree, cond_string); | |
10159 | } | |
10160 | b->cond_string = cond_string; | |
10161 | } | |
e7e0cddf | 10162 | b->extra_string = NULL; |
0101ce28 | 10163 | b->ignore_count = ignore_count; |
0101ce28 | 10164 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 10165 | b->condition_not_parsed = 1; |
41447f92 | 10166 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
10167 | if ((type_wanted != bp_breakpoint |
10168 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 10169 | b->pspace = current_program_space; |
8bea4e01 | 10170 | |
bfccc43c | 10171 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
10172 | } |
10173 | ||
f8eba3c6 | 10174 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 10175 | { |
3e43a32a MS |
10176 | warning (_("Multiple breakpoints were set.\nUse the " |
10177 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 10178 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
10179 | } |
10180 | ||
80c99de1 PA |
10181 | /* That's it. Discard the cleanups for data inserted into the |
10182 | breakpoint. */ | |
10183 | discard_cleanups (bkpt_chain); | |
10184 | /* But cleanup everything else. */ | |
c3f6f71d | 10185 | do_cleanups (old_chain); |
217dc9e2 | 10186 | |
80c99de1 | 10187 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 10188 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
10189 | |
10190 | return 1; | |
c3f6f71d | 10191 | } |
c906108c | 10192 | |
348d480f | 10193 | /* Set a breakpoint. |
72b2ff0e VP |
10194 | ARG is a string describing breakpoint address, |
10195 | condition, and thread. | |
10196 | FLAG specifies if a breakpoint is hardware on, | |
10197 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
10198 | and BP_TEMPFLAG. */ | |
348d480f | 10199 | |
98deb0da | 10200 | static void |
72b2ff0e | 10201 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 10202 | { |
72b2ff0e | 10203 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
10204 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
10205 | ? bp_hardware_breakpoint | |
10206 | : bp_breakpoint); | |
55aa24fb SDJ |
10207 | struct breakpoint_ops *ops; |
10208 | const char *arg_cp = arg; | |
10209 | ||
10210 | /* Matching breakpoints on probes. */ | |
10211 | if (arg && probe_linespec_to_ops (&arg_cp) != NULL) | |
10212 | ops = &bkpt_probe_breakpoint_ops; | |
10213 | else | |
10214 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 10215 | |
8cdf0e15 VP |
10216 | create_breakpoint (get_current_arch (), |
10217 | arg, | |
e7e0cddf | 10218 | NULL, 0, NULL, 1 /* parse arg */, |
0fb4aa4b | 10219 | tempflag, type_wanted, |
8cdf0e15 VP |
10220 | 0 /* Ignore count */, |
10221 | pending_break_support, | |
55aa24fb | 10222 | ops, |
8cdf0e15 | 10223 | from_tty, |
84f4c1fe | 10224 | 1 /* enabled */, |
44f238bb PA |
10225 | 0 /* internal */, |
10226 | 0); | |
c906108c SS |
10227 | } |
10228 | ||
c906108c SS |
10229 | /* Helper function for break_command_1 and disassemble_command. */ |
10230 | ||
10231 | void | |
fba45db2 | 10232 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
10233 | { |
10234 | CORE_ADDR pc; | |
10235 | ||
10236 | if (sal->pc == 0 && sal->symtab != NULL) | |
10237 | { | |
10238 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 10239 | error (_("No line %d in file \"%s\"."), |
05cba821 | 10240 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 10241 | sal->pc = pc; |
6a048695 | 10242 | |
4a64f543 MS |
10243 | /* If this SAL corresponds to a breakpoint inserted using a line |
10244 | number, then skip the function prologue if necessary. */ | |
6a048695 | 10245 | if (sal->explicit_line) |
059acae7 | 10246 | skip_prologue_sal (sal); |
c906108c SS |
10247 | } |
10248 | ||
10249 | if (sal->section == 0 && sal->symtab != NULL) | |
10250 | { | |
346d1dfe | 10251 | const struct blockvector *bv; |
3977b71f | 10252 | const struct block *b; |
c5aa993b | 10253 | struct symbol *sym; |
c906108c | 10254 | |
43f3e411 DE |
10255 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
10256 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
10257 | if (bv != NULL) |
10258 | { | |
7f0df278 | 10259 | sym = block_linkage_function (b); |
c906108c SS |
10260 | if (sym != NULL) |
10261 | { | |
eb822aa6 DE |
10262 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
10263 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
10264 | sym); | |
c906108c SS |
10265 | } |
10266 | else | |
10267 | { | |
4a64f543 MS |
10268 | /* It really is worthwhile to have the section, so we'll |
10269 | just have to look harder. This case can be executed | |
10270 | if we have line numbers but no functions (as can | |
10271 | happen in assembly source). */ | |
c906108c | 10272 | |
7cbd4a93 | 10273 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10274 | struct cleanup *old_chain = save_current_space_and_thread (); |
10275 | ||
10276 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10277 | |
10278 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10279 | if (msym.minsym) |
efd66ac6 | 10280 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10281 | |
10282 | do_cleanups (old_chain); | |
c906108c SS |
10283 | } |
10284 | } | |
10285 | } | |
10286 | } | |
10287 | ||
10288 | void | |
fba45db2 | 10289 | break_command (char *arg, int from_tty) |
c906108c | 10290 | { |
db107f19 | 10291 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10292 | } |
10293 | ||
c906108c | 10294 | void |
fba45db2 | 10295 | tbreak_command (char *arg, int from_tty) |
c906108c | 10296 | { |
db107f19 | 10297 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10298 | } |
10299 | ||
c906108c | 10300 | static void |
fba45db2 | 10301 | hbreak_command (char *arg, int from_tty) |
c906108c | 10302 | { |
db107f19 | 10303 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10304 | } |
10305 | ||
10306 | static void | |
fba45db2 | 10307 | thbreak_command (char *arg, int from_tty) |
c906108c | 10308 | { |
db107f19 | 10309 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10310 | } |
10311 | ||
10312 | static void | |
fba45db2 | 10313 | stop_command (char *arg, int from_tty) |
c906108c | 10314 | { |
a3f17187 | 10315 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10316 | Usage: stop in <function | address>\n\ |
a3f17187 | 10317 | stop at <line>\n")); |
c906108c SS |
10318 | } |
10319 | ||
10320 | static void | |
fba45db2 | 10321 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10322 | { |
10323 | int badInput = 0; | |
10324 | ||
c5aa993b | 10325 | if (arg == (char *) NULL) |
c906108c SS |
10326 | badInput = 1; |
10327 | else if (*arg != '*') | |
10328 | { | |
10329 | char *argptr = arg; | |
10330 | int hasColon = 0; | |
10331 | ||
4a64f543 | 10332 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10333 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10334 | function/method name. */ |
c906108c | 10335 | while (*argptr && !hasColon) |
c5aa993b JM |
10336 | { |
10337 | hasColon = (*argptr == ':'); | |
10338 | argptr++; | |
10339 | } | |
c906108c SS |
10340 | |
10341 | if (hasColon) | |
c5aa993b | 10342 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10343 | else |
c5aa993b | 10344 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10345 | } |
10346 | ||
10347 | if (badInput) | |
a3f17187 | 10348 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10349 | else |
db107f19 | 10350 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10351 | } |
10352 | ||
10353 | static void | |
fba45db2 | 10354 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10355 | { |
10356 | int badInput = 0; | |
10357 | ||
c5aa993b | 10358 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10359 | badInput = 1; |
10360 | else | |
10361 | { | |
10362 | char *argptr = arg; | |
10363 | int hasColon = 0; | |
10364 | ||
4a64f543 MS |
10365 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10366 | it is probably a line number. */ | |
c906108c | 10367 | while (*argptr && !hasColon) |
c5aa993b JM |
10368 | { |
10369 | hasColon = (*argptr == ':'); | |
10370 | argptr++; | |
10371 | } | |
c906108c SS |
10372 | |
10373 | if (hasColon) | |
c5aa993b | 10374 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10375 | else |
c5aa993b | 10376 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10377 | } |
10378 | ||
10379 | if (badInput) | |
a3f17187 | 10380 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10381 | else |
db107f19 | 10382 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10383 | } |
10384 | ||
e7e0cddf SS |
10385 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10386 | with a prewired command list consisting of a single output command, | |
10387 | built from extra arguments supplied on the dprintf command | |
10388 | line. */ | |
10389 | ||
da821c7b | 10390 | static void |
e7e0cddf SS |
10391 | dprintf_command (char *arg, int from_tty) |
10392 | { | |
10393 | create_breakpoint (get_current_arch (), | |
10394 | arg, | |
10395 | NULL, 0, NULL, 1 /* parse arg */, | |
10396 | 0, bp_dprintf, | |
10397 | 0 /* Ignore count */, | |
10398 | pending_break_support, | |
10399 | &dprintf_breakpoint_ops, | |
10400 | from_tty, | |
10401 | 1 /* enabled */, | |
10402 | 0 /* internal */, | |
10403 | 0); | |
10404 | } | |
10405 | ||
d3ce09f5 SS |
10406 | static void |
10407 | agent_printf_command (char *arg, int from_tty) | |
10408 | { | |
10409 | error (_("May only run agent-printf on the target")); | |
10410 | } | |
10411 | ||
f1310107 TJB |
10412 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10413 | ranged breakpoints. */ | |
10414 | ||
10415 | static int | |
10416 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10417 | struct address_space *aspace, | |
09ac7c10 TT |
10418 | CORE_ADDR bp_addr, |
10419 | const struct target_waitstatus *ws) | |
f1310107 | 10420 | { |
09ac7c10 | 10421 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10422 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10423 | return 0; |
10424 | ||
f1310107 TJB |
10425 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10426 | bl->length, aspace, bp_addr); | |
10427 | } | |
10428 | ||
10429 | /* Implement the "resources_needed" breakpoint_ops method for | |
10430 | ranged breakpoints. */ | |
10431 | ||
10432 | static int | |
10433 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10434 | { | |
10435 | return target_ranged_break_num_registers (); | |
10436 | } | |
10437 | ||
10438 | /* Implement the "print_it" breakpoint_ops method for | |
10439 | ranged breakpoints. */ | |
10440 | ||
10441 | static enum print_stop_action | |
348d480f | 10442 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10443 | { |
348d480f | 10444 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10445 | struct bp_location *bl = b->loc; |
79a45e25 | 10446 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10447 | |
10448 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10449 | ||
10450 | /* Ranged breakpoints have only one location. */ | |
10451 | gdb_assert (bl && bl->next == NULL); | |
10452 | ||
10453 | annotate_breakpoint (b->number); | |
10454 | if (b->disposition == disp_del) | |
10455 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10456 | else | |
10457 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10458 | if (ui_out_is_mi_like_p (uiout)) | |
10459 | { | |
10460 | ui_out_field_string (uiout, "reason", | |
10461 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10462 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10463 | } | |
10464 | ui_out_field_int (uiout, "bkptno", b->number); | |
10465 | ui_out_text (uiout, ", "); | |
10466 | ||
10467 | return PRINT_SRC_AND_LOC; | |
10468 | } | |
10469 | ||
10470 | /* Implement the "print_one" breakpoint_ops method for | |
10471 | ranged breakpoints. */ | |
10472 | ||
10473 | static void | |
10474 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10475 | struct bp_location **last_loc) | |
10476 | { | |
10477 | struct bp_location *bl = b->loc; | |
10478 | struct value_print_options opts; | |
79a45e25 | 10479 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10480 | |
10481 | /* Ranged breakpoints have only one location. */ | |
10482 | gdb_assert (bl && bl->next == NULL); | |
10483 | ||
10484 | get_user_print_options (&opts); | |
10485 | ||
10486 | if (opts.addressprint) | |
10487 | /* We don't print the address range here, it will be printed later | |
10488 | by print_one_detail_ranged_breakpoint. */ | |
10489 | ui_out_field_skip (uiout, "addr"); | |
10490 | annotate_field (5); | |
10491 | print_breakpoint_location (b, bl); | |
10492 | *last_loc = bl; | |
10493 | } | |
10494 | ||
10495 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10496 | ranged breakpoints. */ | |
10497 | ||
10498 | static void | |
10499 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10500 | struct ui_out *uiout) | |
10501 | { | |
10502 | CORE_ADDR address_start, address_end; | |
10503 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10504 | struct ui_file *stb = mem_fileopen (); |
10505 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10506 | |
10507 | gdb_assert (bl); | |
10508 | ||
10509 | address_start = bl->address; | |
10510 | address_end = address_start + bl->length - 1; | |
10511 | ||
10512 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10513 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10514 | print_core_address (bl->gdbarch, address_start), |
10515 | print_core_address (bl->gdbarch, address_end)); | |
10516 | ui_out_field_stream (uiout, "addr", stb); | |
10517 | ui_out_text (uiout, "\n"); | |
10518 | ||
10519 | do_cleanups (cleanup); | |
10520 | } | |
10521 | ||
10522 | /* Implement the "print_mention" breakpoint_ops method for | |
10523 | ranged breakpoints. */ | |
10524 | ||
10525 | static void | |
10526 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10527 | { | |
10528 | struct bp_location *bl = b->loc; | |
79a45e25 | 10529 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10530 | |
10531 | gdb_assert (bl); | |
10532 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10533 | ||
10534 | if (ui_out_is_mi_like_p (uiout)) | |
10535 | return; | |
10536 | ||
10537 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10538 | b->number, paddress (bl->gdbarch, bl->address), | |
10539 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10540 | } | |
10541 | ||
10542 | /* Implement the "print_recreate" breakpoint_ops method for | |
10543 | ranged breakpoints. */ | |
10544 | ||
10545 | static void | |
10546 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10547 | { | |
10548 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
10549 | b->addr_string_range_end); | |
d9b3f62e | 10550 | print_recreate_thread (b, fp); |
f1310107 TJB |
10551 | } |
10552 | ||
10553 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10554 | ||
2060206e | 10555 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10556 | |
10557 | /* Find the address where the end of the breakpoint range should be | |
10558 | placed, given the SAL of the end of the range. This is so that if | |
10559 | the user provides a line number, the end of the range is set to the | |
10560 | last instruction of the given line. */ | |
10561 | ||
10562 | static CORE_ADDR | |
10563 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10564 | { | |
10565 | CORE_ADDR end; | |
10566 | ||
10567 | /* If the user provided a PC value, use it. Otherwise, | |
10568 | find the address of the end of the given location. */ | |
10569 | if (sal.explicit_pc) | |
10570 | end = sal.pc; | |
10571 | else | |
10572 | { | |
10573 | int ret; | |
10574 | CORE_ADDR start; | |
10575 | ||
10576 | ret = find_line_pc_range (sal, &start, &end); | |
10577 | if (!ret) | |
10578 | error (_("Could not find location of the end of the range.")); | |
10579 | ||
10580 | /* find_line_pc_range returns the start of the next line. */ | |
10581 | end--; | |
10582 | } | |
10583 | ||
10584 | return end; | |
10585 | } | |
10586 | ||
10587 | /* Implement the "break-range" CLI command. */ | |
10588 | ||
10589 | static void | |
10590 | break_range_command (char *arg, int from_tty) | |
10591 | { | |
10592 | char *arg_start, *addr_string_start, *addr_string_end; | |
10593 | struct linespec_result canonical_start, canonical_end; | |
10594 | int bp_count, can_use_bp, length; | |
10595 | CORE_ADDR end; | |
10596 | struct breakpoint *b; | |
10597 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10598 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10599 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10600 | |
10601 | /* We don't support software ranged breakpoints. */ | |
10602 | if (target_ranged_break_num_registers () < 0) | |
10603 | error (_("This target does not support hardware ranged breakpoints.")); | |
10604 | ||
10605 | bp_count = hw_breakpoint_used_count (); | |
10606 | bp_count += target_ranged_break_num_registers (); | |
10607 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10608 | bp_count, 0); | |
10609 | if (can_use_bp < 0) | |
10610 | error (_("Hardware breakpoints used exceeds limit.")); | |
10611 | ||
f8eba3c6 | 10612 | arg = skip_spaces (arg); |
f1310107 TJB |
10613 | if (arg == NULL || arg[0] == '\0') |
10614 | error(_("No address range specified.")); | |
10615 | ||
f1310107 TJB |
10616 | init_linespec_result (&canonical_start); |
10617 | ||
f8eba3c6 TT |
10618 | arg_start = arg; |
10619 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 10620 | |
f8eba3c6 | 10621 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
10622 | |
10623 | if (arg[0] != ',') | |
10624 | error (_("Too few arguments.")); | |
f8eba3c6 | 10625 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10626 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10627 | |
10628 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10629 | ||
10630 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10631 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10632 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10633 | ||
f8eba3c6 TT |
10634 | sal_start = lsal_start->sals.sals[0]; |
10635 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10636 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10637 | |
10638 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10639 | arg = skip_spaces (arg); |
f1310107 TJB |
10640 | |
10641 | /* Parse the end location. */ | |
10642 | ||
f1310107 TJB |
10643 | init_linespec_result (&canonical_end); |
10644 | arg_start = arg; | |
10645 | ||
f8eba3c6 | 10646 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10647 | parse_breakpoint_sals because we need to specify the start location's |
10648 | symtab and line as the default symtab and line for the end of the | |
10649 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10650 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
10651 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
10652 | sal_start.symtab, sal_start.line, | |
10653 | &canonical_end, NULL, NULL); | |
10654 | ||
10655 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10656 | |
f8eba3c6 | 10657 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10658 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10659 | |
10660 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10661 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10662 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10663 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10664 | ||
f8eba3c6 TT |
10665 | sal_end = lsal_end->sals.sals[0]; |
10666 | addr_string_end = savestring (arg_start, arg - arg_start); | |
10667 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
10668 | |
10669 | end = find_breakpoint_range_end (sal_end); | |
10670 | if (sal_start.pc > end) | |
177b42fe | 10671 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10672 | |
10673 | length = end - sal_start.pc + 1; | |
10674 | if (length < 0) | |
10675 | /* Length overflowed. */ | |
10676 | error (_("Address range too large.")); | |
10677 | else if (length == 1) | |
10678 | { | |
10679 | /* This range is simple enough to be handled by | |
10680 | the `hbreak' command. */ | |
10681 | hbreak_command (addr_string_start, 1); | |
10682 | ||
10683 | do_cleanups (cleanup_bkpt); | |
10684 | ||
10685 | return; | |
10686 | } | |
10687 | ||
10688 | /* Now set up the breakpoint. */ | |
10689 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10690 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10691 | set_breakpoint_count (breakpoint_count + 1); |
10692 | b->number = breakpoint_count; | |
10693 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
10694 | b->addr_string = xstrdup (addr_string_start); |
10695 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
10696 | b->loc->length = length; |
10697 | ||
f8eba3c6 | 10698 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10699 | |
10700 | mention (b); | |
8d3788bd | 10701 | observer_notify_breakpoint_created (b); |
44702360 | 10702 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10703 | } |
10704 | ||
4a64f543 MS |
10705 | /* Return non-zero if EXP is verified as constant. Returned zero |
10706 | means EXP is variable. Also the constant detection may fail for | |
10707 | some constant expressions and in such case still falsely return | |
10708 | zero. */ | |
2e6e3d9c | 10709 | |
65d79d4b SDJ |
10710 | static int |
10711 | watchpoint_exp_is_const (const struct expression *exp) | |
10712 | { | |
10713 | int i = exp->nelts; | |
10714 | ||
10715 | while (i > 0) | |
10716 | { | |
10717 | int oplenp, argsp; | |
10718 | ||
10719 | /* We are only interested in the descriptor of each element. */ | |
10720 | operator_length (exp, i, &oplenp, &argsp); | |
10721 | i -= oplenp; | |
10722 | ||
10723 | switch (exp->elts[i].opcode) | |
10724 | { | |
10725 | case BINOP_ADD: | |
10726 | case BINOP_SUB: | |
10727 | case BINOP_MUL: | |
10728 | case BINOP_DIV: | |
10729 | case BINOP_REM: | |
10730 | case BINOP_MOD: | |
10731 | case BINOP_LSH: | |
10732 | case BINOP_RSH: | |
10733 | case BINOP_LOGICAL_AND: | |
10734 | case BINOP_LOGICAL_OR: | |
10735 | case BINOP_BITWISE_AND: | |
10736 | case BINOP_BITWISE_IOR: | |
10737 | case BINOP_BITWISE_XOR: | |
10738 | case BINOP_EQUAL: | |
10739 | case BINOP_NOTEQUAL: | |
10740 | case BINOP_LESS: | |
10741 | case BINOP_GTR: | |
10742 | case BINOP_LEQ: | |
10743 | case BINOP_GEQ: | |
10744 | case BINOP_REPEAT: | |
10745 | case BINOP_COMMA: | |
10746 | case BINOP_EXP: | |
10747 | case BINOP_MIN: | |
10748 | case BINOP_MAX: | |
10749 | case BINOP_INTDIV: | |
10750 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10751 | case TERNOP_COND: |
10752 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10753 | |
10754 | case OP_LONG: | |
10755 | case OP_DOUBLE: | |
10756 | case OP_DECFLOAT: | |
10757 | case OP_LAST: | |
10758 | case OP_COMPLEX: | |
10759 | case OP_STRING: | |
65d79d4b SDJ |
10760 | case OP_ARRAY: |
10761 | case OP_TYPE: | |
608b4967 TT |
10762 | case OP_TYPEOF: |
10763 | case OP_DECLTYPE: | |
6e72ca20 | 10764 | case OP_TYPEID: |
65d79d4b SDJ |
10765 | case OP_NAME: |
10766 | case OP_OBJC_NSSTRING: | |
10767 | ||
10768 | case UNOP_NEG: | |
10769 | case UNOP_LOGICAL_NOT: | |
10770 | case UNOP_COMPLEMENT: | |
10771 | case UNOP_ADDR: | |
10772 | case UNOP_HIGH: | |
aeaa2474 | 10773 | case UNOP_CAST: |
9eaf6705 TT |
10774 | |
10775 | case UNOP_CAST_TYPE: | |
10776 | case UNOP_REINTERPRET_CAST: | |
10777 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10778 | /* Unary, binary and ternary operators: We have to check |
10779 | their operands. If they are constant, then so is the | |
10780 | result of that operation. For instance, if A and B are | |
10781 | determined to be constants, then so is "A + B". | |
10782 | ||
10783 | UNOP_IND is one exception to the rule above, because the | |
10784 | value of *ADDR is not necessarily a constant, even when | |
10785 | ADDR is. */ | |
65d79d4b SDJ |
10786 | break; |
10787 | ||
10788 | case OP_VAR_VALUE: | |
10789 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10790 | |
65d79d4b | 10791 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10792 | possible that a buggy compiler could mark a variable as |
10793 | constant even when it is not, and TYPE_CONST would return | |
10794 | true in this case, while SYMBOL_CLASS wouldn't. | |
10795 | ||
10796 | We also have to check for function symbols because they | |
10797 | are always constant. */ | |
65d79d4b SDJ |
10798 | { |
10799 | struct symbol *s = exp->elts[i + 2].symbol; | |
10800 | ||
10801 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10802 | && SYMBOL_CLASS (s) != LOC_CONST | |
10803 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10804 | return 0; | |
10805 | break; | |
10806 | } | |
10807 | ||
10808 | /* The default action is to return 0 because we are using | |
10809 | the optimistic approach here: If we don't know something, | |
10810 | then it is not a constant. */ | |
10811 | default: | |
10812 | return 0; | |
10813 | } | |
10814 | } | |
10815 | ||
10816 | return 1; | |
10817 | } | |
10818 | ||
3a5c3e22 PA |
10819 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10820 | ||
10821 | static void | |
10822 | dtor_watchpoint (struct breakpoint *self) | |
10823 | { | |
10824 | struct watchpoint *w = (struct watchpoint *) self; | |
10825 | ||
10826 | xfree (w->cond_exp); | |
10827 | xfree (w->exp); | |
10828 | xfree (w->exp_string); | |
10829 | xfree (w->exp_string_reparse); | |
10830 | value_free (w->val); | |
10831 | ||
10832 | base_breakpoint_ops.dtor (self); | |
10833 | } | |
10834 | ||
348d480f PA |
10835 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10836 | ||
10837 | static void | |
10838 | re_set_watchpoint (struct breakpoint *b) | |
10839 | { | |
3a5c3e22 PA |
10840 | struct watchpoint *w = (struct watchpoint *) b; |
10841 | ||
348d480f PA |
10842 | /* Watchpoint can be either on expression using entirely global |
10843 | variables, or it can be on local variables. | |
10844 | ||
10845 | Watchpoints of the first kind are never auto-deleted, and even | |
10846 | persist across program restarts. Since they can use variables | |
10847 | from shared libraries, we need to reparse expression as libraries | |
10848 | are loaded and unloaded. | |
10849 | ||
10850 | Watchpoints on local variables can also change meaning as result | |
10851 | of solib event. For example, if a watchpoint uses both a local | |
10852 | and a global variables in expression, it's a local watchpoint, | |
10853 | but unloading of a shared library will make the expression | |
10854 | invalid. This is not a very common use case, but we still | |
10855 | re-evaluate expression, to avoid surprises to the user. | |
10856 | ||
10857 | Note that for local watchpoints, we re-evaluate it only if | |
10858 | watchpoints frame id is still valid. If it's not, it means the | |
10859 | watchpoint is out of scope and will be deleted soon. In fact, | |
10860 | I'm not sure we'll ever be called in this case. | |
10861 | ||
10862 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10863 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10864 | |
3a5c3e22 PA |
10865 | Don't do anything about disabled watchpoints, since they will be |
10866 | reevaluated again when enabled. */ | |
10867 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10868 | } |
10869 | ||
77b06cd7 TJB |
10870 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10871 | ||
10872 | static int | |
10873 | insert_watchpoint (struct bp_location *bl) | |
10874 | { | |
3a5c3e22 PA |
10875 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10876 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10877 | |
10878 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10879 | w->cond_exp); |
77b06cd7 TJB |
10880 | } |
10881 | ||
10882 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10883 | ||
10884 | static int | |
10885 | remove_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_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10891 | w->cond_exp); |
e09342b5 TJB |
10892 | } |
10893 | ||
e09342b5 | 10894 | static int |
348d480f | 10895 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10896 | struct address_space *aspace, CORE_ADDR bp_addr, |
10897 | const struct target_waitstatus *ws) | |
e09342b5 | 10898 | { |
348d480f | 10899 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10900 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10901 | |
348d480f PA |
10902 | /* Continuable hardware watchpoints are treated as non-existent if the |
10903 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10904 | some data address). Otherwise gdb won't stop on a break instruction | |
10905 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10906 | been defined. Also skip watchpoints which we know did not trigger | |
10907 | (did not match the data address). */ | |
10908 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10909 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10910 | return 0; |
9c06b0b4 | 10911 | |
348d480f | 10912 | return 1; |
9c06b0b4 TJB |
10913 | } |
10914 | ||
348d480f PA |
10915 | static void |
10916 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10917 | { |
348d480f | 10918 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10919 | |
348d480f | 10920 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10921 | } |
10922 | ||
10923 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10924 | hardware watchpoints. */ |
9c06b0b4 TJB |
10925 | |
10926 | static int | |
348d480f | 10927 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10928 | { |
3a5c3e22 PA |
10929 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10930 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10931 | |
10932 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10933 | } |
10934 | ||
10935 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10936 | hardware watchpoints. */ |
9c06b0b4 TJB |
10937 | |
10938 | static int | |
348d480f | 10939 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10940 | { |
efa80663 PA |
10941 | /* Read and access watchpoints only work with hardware support. */ |
10942 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10943 | } |
10944 | ||
9c06b0b4 | 10945 | static enum print_stop_action |
348d480f | 10946 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10947 | { |
348d480f PA |
10948 | struct cleanup *old_chain; |
10949 | struct breakpoint *b; | |
f99d8bf4 | 10950 | struct ui_file *stb; |
348d480f | 10951 | enum print_stop_action result; |
3a5c3e22 | 10952 | struct watchpoint *w; |
79a45e25 | 10953 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10954 | |
10955 | gdb_assert (bs->bp_location_at != NULL); | |
10956 | ||
348d480f | 10957 | b = bs->breakpoint_at; |
3a5c3e22 | 10958 | w = (struct watchpoint *) b; |
348d480f | 10959 | |
f99d8bf4 PA |
10960 | stb = mem_fileopen (); |
10961 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10962 | |
10963 | switch (b->type) | |
10964 | { | |
348d480f | 10965 | case bp_watchpoint: |
9c06b0b4 TJB |
10966 | case bp_hardware_watchpoint: |
10967 | annotate_watchpoint (b->number); | |
10968 | if (ui_out_is_mi_like_p (uiout)) | |
10969 | ui_out_field_string | |
10970 | (uiout, "reason", | |
10971 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10972 | mention (b); |
10973 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10974 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10975 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10976 | ui_out_field_stream (uiout, "old", stb); |
10977 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10978 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10979 | ui_out_field_stream (uiout, "new", stb); |
10980 | ui_out_text (uiout, "\n"); | |
10981 | /* More than one watchpoint may have been triggered. */ | |
10982 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10983 | break; |
10984 | ||
10985 | case bp_read_watchpoint: | |
10986 | if (ui_out_is_mi_like_p (uiout)) | |
10987 | ui_out_field_string | |
10988 | (uiout, "reason", | |
10989 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10990 | mention (b); |
10991 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10992 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10993 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10994 | ui_out_field_stream (uiout, "value", stb); |
10995 | ui_out_text (uiout, "\n"); | |
10996 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10997 | break; |
10998 | ||
10999 | case bp_access_watchpoint: | |
348d480f PA |
11000 | if (bs->old_val != NULL) |
11001 | { | |
11002 | annotate_watchpoint (b->number); | |
11003 | if (ui_out_is_mi_like_p (uiout)) | |
11004 | ui_out_field_string | |
11005 | (uiout, "reason", | |
11006 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11007 | mention (b); | |
11008 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
11009 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 11010 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
11011 | ui_out_field_stream (uiout, "old", stb); |
11012 | ui_out_text (uiout, "\nNew value = "); | |
11013 | } | |
11014 | else | |
11015 | { | |
11016 | mention (b); | |
11017 | if (ui_out_is_mi_like_p (uiout)) | |
11018 | ui_out_field_string | |
11019 | (uiout, "reason", | |
11020 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11021 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
11022 | ui_out_text (uiout, "\nValue = "); | |
11023 | } | |
f99d8bf4 | 11024 | watchpoint_value_print (w->val, stb); |
348d480f PA |
11025 | ui_out_field_stream (uiout, "new", stb); |
11026 | ui_out_text (uiout, "\n"); | |
11027 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
11028 | break; |
11029 | default: | |
348d480f | 11030 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
11031 | } |
11032 | ||
348d480f PA |
11033 | do_cleanups (old_chain); |
11034 | return result; | |
11035 | } | |
11036 | ||
11037 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
11038 | watchpoints. */ | |
11039 | ||
11040 | static void | |
11041 | print_mention_watchpoint (struct breakpoint *b) | |
11042 | { | |
11043 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 11044 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11045 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11046 | |
11047 | switch (b->type) | |
11048 | { | |
11049 | case bp_watchpoint: | |
11050 | ui_out_text (uiout, "Watchpoint "); | |
11051 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11052 | break; | |
11053 | case bp_hardware_watchpoint: | |
11054 | ui_out_text (uiout, "Hardware watchpoint "); | |
11055 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11056 | break; | |
11057 | case bp_read_watchpoint: | |
11058 | ui_out_text (uiout, "Hardware read watchpoint "); | |
11059 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11060 | break; | |
11061 | case bp_access_watchpoint: | |
11062 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
11063 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11064 | break; | |
11065 | default: | |
11066 | internal_error (__FILE__, __LINE__, | |
11067 | _("Invalid hardware watchpoint type.")); | |
11068 | } | |
11069 | ||
11070 | ui_out_field_int (uiout, "number", b->number); | |
11071 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11072 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
11073 | do_cleanups (ui_out_chain); |
11074 | } | |
11075 | ||
11076 | /* Implement the "print_recreate" breakpoint_ops method for | |
11077 | watchpoints. */ | |
11078 | ||
11079 | static void | |
11080 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11081 | { | |
3a5c3e22 PA |
11082 | struct watchpoint *w = (struct watchpoint *) b; |
11083 | ||
348d480f PA |
11084 | switch (b->type) |
11085 | { | |
11086 | case bp_watchpoint: | |
11087 | case bp_hardware_watchpoint: | |
11088 | fprintf_unfiltered (fp, "watch"); | |
11089 | break; | |
11090 | case bp_read_watchpoint: | |
11091 | fprintf_unfiltered (fp, "rwatch"); | |
11092 | break; | |
11093 | case bp_access_watchpoint: | |
11094 | fprintf_unfiltered (fp, "awatch"); | |
11095 | break; | |
11096 | default: | |
11097 | internal_error (__FILE__, __LINE__, | |
11098 | _("Invalid watchpoint type.")); | |
11099 | } | |
11100 | ||
3a5c3e22 | 11101 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 11102 | print_recreate_thread (b, fp); |
348d480f PA |
11103 | } |
11104 | ||
427cd150 TT |
11105 | /* Implement the "explains_signal" breakpoint_ops method for |
11106 | watchpoints. */ | |
11107 | ||
47591c29 | 11108 | static int |
427cd150 TT |
11109 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
11110 | { | |
11111 | /* A software watchpoint cannot cause a signal other than | |
11112 | GDB_SIGNAL_TRAP. */ | |
11113 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 11114 | return 0; |
427cd150 | 11115 | |
47591c29 | 11116 | return 1; |
427cd150 TT |
11117 | } |
11118 | ||
348d480f PA |
11119 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
11120 | ||
2060206e | 11121 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
11122 | |
11123 | /* Implement the "insert" breakpoint_ops method for | |
11124 | masked hardware watchpoints. */ | |
11125 | ||
11126 | static int | |
11127 | insert_masked_watchpoint (struct bp_location *bl) | |
11128 | { | |
3a5c3e22 PA |
11129 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
11130 | ||
11131 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
11132 | bl->watchpoint_type); |
11133 | } | |
11134 | ||
11135 | /* Implement the "remove" breakpoint_ops method for | |
11136 | masked hardware watchpoints. */ | |
11137 | ||
11138 | static int | |
11139 | remove_masked_watchpoint (struct bp_location *bl) | |
11140 | { | |
3a5c3e22 PA |
11141 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
11142 | ||
11143 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
11144 | bl->watchpoint_type); |
11145 | } | |
11146 | ||
11147 | /* Implement the "resources_needed" breakpoint_ops method for | |
11148 | masked hardware watchpoints. */ | |
11149 | ||
11150 | static int | |
11151 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
11152 | { | |
3a5c3e22 PA |
11153 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
11154 | ||
11155 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
11156 | } |
11157 | ||
11158 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
11159 | masked hardware watchpoints. */ | |
11160 | ||
11161 | static int | |
11162 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
11163 | { | |
11164 | return 0; | |
11165 | } | |
11166 | ||
11167 | /* Implement the "print_it" breakpoint_ops method for | |
11168 | masked hardware watchpoints. */ | |
11169 | ||
11170 | static enum print_stop_action | |
11171 | print_it_masked_watchpoint (bpstat bs) | |
11172 | { | |
11173 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 11174 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11175 | |
11176 | /* Masked watchpoints have only one location. */ | |
11177 | gdb_assert (b->loc && b->loc->next == NULL); | |
11178 | ||
11179 | switch (b->type) | |
11180 | { | |
11181 | case bp_hardware_watchpoint: | |
11182 | annotate_watchpoint (b->number); | |
11183 | if (ui_out_is_mi_like_p (uiout)) | |
11184 | ui_out_field_string | |
11185 | (uiout, "reason", | |
11186 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
11187 | break; | |
11188 | ||
11189 | case bp_read_watchpoint: | |
11190 | if (ui_out_is_mi_like_p (uiout)) | |
11191 | ui_out_field_string | |
11192 | (uiout, "reason", | |
11193 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
11194 | break; | |
11195 | ||
11196 | case bp_access_watchpoint: | |
11197 | if (ui_out_is_mi_like_p (uiout)) | |
11198 | ui_out_field_string | |
11199 | (uiout, "reason", | |
11200 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11201 | break; | |
11202 | default: | |
11203 | internal_error (__FILE__, __LINE__, | |
11204 | _("Invalid hardware watchpoint type.")); | |
11205 | } | |
11206 | ||
11207 | mention (b); | |
9c06b0b4 TJB |
11208 | ui_out_text (uiout, _("\n\ |
11209 | Check the underlying instruction at PC for the memory\n\ | |
11210 | address and value which triggered this watchpoint.\n")); | |
11211 | ui_out_text (uiout, "\n"); | |
11212 | ||
11213 | /* More than one watchpoint may have been triggered. */ | |
11214 | return PRINT_UNKNOWN; | |
11215 | } | |
11216 | ||
11217 | /* Implement the "print_one_detail" breakpoint_ops method for | |
11218 | masked hardware watchpoints. */ | |
11219 | ||
11220 | static void | |
11221 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
11222 | struct ui_out *uiout) | |
11223 | { | |
3a5c3e22 PA |
11224 | struct watchpoint *w = (struct watchpoint *) b; |
11225 | ||
9c06b0b4 TJB |
11226 | /* Masked watchpoints have only one location. */ |
11227 | gdb_assert (b->loc && b->loc->next == NULL); | |
11228 | ||
11229 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 11230 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
11231 | ui_out_text (uiout, "\n"); |
11232 | } | |
11233 | ||
11234 | /* Implement the "print_mention" breakpoint_ops method for | |
11235 | masked hardware watchpoints. */ | |
11236 | ||
11237 | static void | |
11238 | print_mention_masked_watchpoint (struct breakpoint *b) | |
11239 | { | |
3a5c3e22 | 11240 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11241 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
11242 | struct cleanup *ui_out_chain; |
11243 | ||
11244 | switch (b->type) | |
11245 | { | |
11246 | case bp_hardware_watchpoint: | |
11247 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
11248 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11249 | break; | |
11250 | case bp_read_watchpoint: | |
11251 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
11252 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11253 | break; | |
11254 | case bp_access_watchpoint: | |
11255 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
11256 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11257 | break; | |
11258 | default: | |
11259 | internal_error (__FILE__, __LINE__, | |
11260 | _("Invalid hardware watchpoint type.")); | |
11261 | } | |
11262 | ||
11263 | ui_out_field_int (uiout, "number", b->number); | |
11264 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11265 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
11266 | do_cleanups (ui_out_chain); |
11267 | } | |
11268 | ||
11269 | /* Implement the "print_recreate" breakpoint_ops method for | |
11270 | masked hardware watchpoints. */ | |
11271 | ||
11272 | static void | |
11273 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11274 | { | |
3a5c3e22 | 11275 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11276 | char tmp[40]; |
11277 | ||
11278 | switch (b->type) | |
11279 | { | |
11280 | case bp_hardware_watchpoint: | |
11281 | fprintf_unfiltered (fp, "watch"); | |
11282 | break; | |
11283 | case bp_read_watchpoint: | |
11284 | fprintf_unfiltered (fp, "rwatch"); | |
11285 | break; | |
11286 | case bp_access_watchpoint: | |
11287 | fprintf_unfiltered (fp, "awatch"); | |
11288 | break; | |
11289 | default: | |
11290 | internal_error (__FILE__, __LINE__, | |
11291 | _("Invalid hardware watchpoint type.")); | |
11292 | } | |
11293 | ||
3a5c3e22 PA |
11294 | sprintf_vma (tmp, w->hw_wp_mask); |
11295 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11296 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11297 | } |
11298 | ||
11299 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11300 | ||
2060206e | 11301 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11302 | |
11303 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11304 | ||
11305 | static int | |
11306 | is_masked_watchpoint (const struct breakpoint *b) | |
11307 | { | |
11308 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11309 | } | |
11310 | ||
53a5351d JM |
11311 | /* accessflag: hw_write: watch write, |
11312 | hw_read: watch read, | |
11313 | hw_access: watch access (read or write) */ | |
c906108c | 11314 | static void |
bbc13ae3 | 11315 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11316 | int just_location, int internal) |
c906108c | 11317 | { |
a9634178 | 11318 | volatile struct gdb_exception e; |
d983da9c | 11319 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11320 | struct expression *exp; |
270140bd | 11321 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11322 | struct value *val, *mark, *result; |
bb9d5f81 | 11323 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 11324 | struct frame_info *frame; |
bbc13ae3 KS |
11325 | const char *exp_start = NULL; |
11326 | const char *exp_end = NULL; | |
11327 | const char *tok, *end_tok; | |
9c06b0b4 | 11328 | int toklen = -1; |
bbc13ae3 KS |
11329 | const char *cond_start = NULL; |
11330 | const char *cond_end = NULL; | |
c906108c | 11331 | enum bptype bp_type; |
37e4754d | 11332 | int thread = -1; |
0cf6dd15 | 11333 | int pc = 0; |
9c06b0b4 TJB |
11334 | /* Flag to indicate whether we are going to use masks for |
11335 | the hardware watchpoint. */ | |
11336 | int use_mask = 0; | |
11337 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11338 | struct watchpoint *w; |
bbc13ae3 KS |
11339 | char *expression; |
11340 | struct cleanup *back_to; | |
c906108c | 11341 | |
37e4754d LM |
11342 | /* Make sure that we actually have parameters to parse. */ |
11343 | if (arg != NULL && arg[0] != '\0') | |
11344 | { | |
bbc13ae3 KS |
11345 | const char *value_start; |
11346 | ||
11347 | exp_end = arg + strlen (arg); | |
37e4754d | 11348 | |
9c06b0b4 TJB |
11349 | /* Look for "parameter value" pairs at the end |
11350 | of the arguments string. */ | |
bbc13ae3 | 11351 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11352 | { |
11353 | /* Skip whitespace at the end of the argument list. */ | |
11354 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11355 | tok--; | |
11356 | ||
11357 | /* Find the beginning of the last token. | |
11358 | This is the value of the parameter. */ | |
11359 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11360 | tok--; | |
11361 | value_start = tok + 1; | |
11362 | ||
11363 | /* Skip whitespace. */ | |
11364 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11365 | tok--; | |
11366 | ||
11367 | end_tok = tok; | |
11368 | ||
11369 | /* Find the beginning of the second to last token. | |
11370 | This is the parameter itself. */ | |
11371 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11372 | tok--; | |
11373 | tok++; | |
11374 | toklen = end_tok - tok + 1; | |
11375 | ||
11376 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
11377 | { | |
11378 | /* At this point we've found a "thread" token, which means | |
11379 | the user is trying to set a watchpoint that triggers | |
11380 | only in a specific thread. */ | |
11381 | char *endp; | |
37e4754d | 11382 | |
9c06b0b4 TJB |
11383 | if (thread != -1) |
11384 | error(_("You can specify only one thread.")); | |
37e4754d | 11385 | |
9c06b0b4 TJB |
11386 | /* Extract the thread ID from the next token. */ |
11387 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 11388 | |
9c06b0b4 TJB |
11389 | /* Check if the user provided a valid numeric value for the |
11390 | thread ID. */ | |
11391 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
11392 | error (_("Invalid thread ID specification %s."), value_start); | |
11393 | ||
11394 | /* Check if the thread actually exists. */ | |
11395 | if (!valid_thread_id (thread)) | |
af4908ba | 11396 | invalid_thread_id_error (thread); |
9c06b0b4 TJB |
11397 | } |
11398 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
11399 | { | |
11400 | /* We've found a "mask" token, which means the user wants to | |
11401 | create a hardware watchpoint that is going to have the mask | |
11402 | facility. */ | |
11403 | struct value *mask_value, *mark; | |
37e4754d | 11404 | |
9c06b0b4 TJB |
11405 | if (use_mask) |
11406 | error(_("You can specify only one mask.")); | |
37e4754d | 11407 | |
9c06b0b4 | 11408 | use_mask = just_location = 1; |
37e4754d | 11409 | |
9c06b0b4 TJB |
11410 | mark = value_mark (); |
11411 | mask_value = parse_to_comma_and_eval (&value_start); | |
11412 | mask = value_as_address (mask_value); | |
11413 | value_free_to_mark (mark); | |
11414 | } | |
11415 | else | |
11416 | /* We didn't recognize what we found. We should stop here. */ | |
11417 | break; | |
37e4754d | 11418 | |
9c06b0b4 TJB |
11419 | /* Truncate the string and get rid of the "parameter value" pair before |
11420 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11421 | exp_end = tok; |
9c06b0b4 | 11422 | } |
37e4754d | 11423 | } |
bbc13ae3 KS |
11424 | else |
11425 | exp_end = arg; | |
37e4754d | 11426 | |
bbc13ae3 KS |
11427 | /* Parse the rest of the arguments. From here on out, everything |
11428 | is in terms of a newly allocated string instead of the original | |
11429 | ARG. */ | |
c906108c | 11430 | innermost_block = NULL; |
bbc13ae3 KS |
11431 | expression = savestring (arg, exp_end - arg); |
11432 | back_to = make_cleanup (xfree, expression); | |
11433 | exp_start = arg = expression; | |
1bb9788d | 11434 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11435 | exp_end = arg; |
fa8a61dc TT |
11436 | /* Remove trailing whitespace from the expression before saving it. |
11437 | This makes the eventual display of the expression string a bit | |
11438 | prettier. */ | |
11439 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11440 | --exp_end; | |
11441 | ||
65d79d4b SDJ |
11442 | /* Checking if the expression is not constant. */ |
11443 | if (watchpoint_exp_is_const (exp)) | |
11444 | { | |
11445 | int len; | |
11446 | ||
11447 | len = exp_end - exp_start; | |
11448 | while (len > 0 && isspace (exp_start[len - 1])) | |
11449 | len--; | |
11450 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11451 | } | |
11452 | ||
c906108c SS |
11453 | exp_valid_block = innermost_block; |
11454 | mark = value_mark (); | |
3a1115a0 | 11455 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b | 11456 | |
bb9d5f81 PP |
11457 | if (val != NULL && just_location) |
11458 | { | |
11459 | saved_bitpos = value_bitpos (val); | |
11460 | saved_bitsize = value_bitsize (val); | |
11461 | } | |
11462 | ||
06a64a0b TT |
11463 | if (just_location) |
11464 | { | |
9c06b0b4 TJB |
11465 | int ret; |
11466 | ||
06a64a0b | 11467 | exp_valid_block = NULL; |
a1442452 | 11468 | val = value_addr (result); |
06a64a0b TT |
11469 | release_value (val); |
11470 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11471 | |
11472 | if (use_mask) | |
11473 | { | |
11474 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11475 | mask); | |
11476 | if (ret == -1) | |
11477 | error (_("This target does not support masked watchpoints.")); | |
11478 | else if (ret == -2) | |
11479 | error (_("Invalid mask or memory region.")); | |
11480 | } | |
06a64a0b TT |
11481 | } |
11482 | else if (val != NULL) | |
fa4727a6 | 11483 | release_value (val); |
c906108c | 11484 | |
bbc13ae3 KS |
11485 | tok = skip_spaces_const (arg); |
11486 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11487 | |
11488 | toklen = end_tok - tok; | |
11489 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11490 | { | |
2d134ed3 PA |
11491 | struct expression *cond; |
11492 | ||
60e1c644 | 11493 | innermost_block = NULL; |
c906108c | 11494 | tok = cond_start = end_tok + 1; |
1bb9788d | 11495 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11496 | |
11497 | /* The watchpoint expression may not be local, but the condition | |
11498 | may still be. E.g.: `watch global if local > 0'. */ | |
11499 | cond_exp_valid_block = innermost_block; | |
11500 | ||
2d134ed3 | 11501 | xfree (cond); |
c906108c SS |
11502 | cond_end = tok; |
11503 | } | |
11504 | if (*tok) | |
8a3fe4f8 | 11505 | error (_("Junk at end of command.")); |
c906108c | 11506 | |
d983da9c | 11507 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11508 | |
11509 | /* If the expression is "local", then set up a "watchpoint scope" | |
11510 | breakpoint at the point where we've left the scope of the watchpoint | |
11511 | expression. Create the scope breakpoint before the watchpoint, so | |
11512 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11513 | if (exp_valid_block && frame) |
d983da9c | 11514 | { |
edb3359d DJ |
11515 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11516 | { | |
11517 | scope_breakpoint | |
a6d9a66e UW |
11518 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11519 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11520 | bp_watchpoint_scope, |
11521 | &momentary_breakpoint_ops); | |
d983da9c | 11522 | |
edb3359d | 11523 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11524 | |
edb3359d DJ |
11525 | /* Automatically delete the breakpoint when it hits. */ |
11526 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11527 | |
edb3359d DJ |
11528 | /* Only break in the proper frame (help with recursion). */ |
11529 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11530 | |
edb3359d | 11531 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11532 | scope_breakpoint->loc->gdbarch |
11533 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11534 | scope_breakpoint->loc->requested_address |
11535 | = frame_unwind_caller_pc (frame); | |
11536 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11537 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11538 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11539 | scope_breakpoint->type); |
11540 | } | |
d983da9c DJ |
11541 | } |
11542 | ||
e8369a73 AB |
11543 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11544 | watchpoints here even if hardware watchpoints are turned off, a call | |
11545 | to update_watchpoint later in this function will cause the type to | |
11546 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11547 | ||
11548 | if (accessflag == hw_read) | |
11549 | bp_type = bp_read_watchpoint; | |
11550 | else if (accessflag == hw_access) | |
11551 | bp_type = bp_access_watchpoint; | |
11552 | else | |
11553 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11554 | |
11555 | w = XCNEW (struct watchpoint); | |
11556 | b = &w->base; | |
348d480f | 11557 | if (use_mask) |
3a5c3e22 PA |
11558 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11559 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11560 | else |
3a5c3e22 PA |
11561 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11562 | &watchpoint_breakpoint_ops); | |
37e4754d | 11563 | b->thread = thread; |
b5de0fa7 | 11564 | b->disposition = disp_donttouch; |
348d480f | 11565 | b->pspace = current_program_space; |
3a5c3e22 PA |
11566 | w->exp = exp; |
11567 | w->exp_valid_block = exp_valid_block; | |
11568 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11569 | if (just_location) |
11570 | { | |
11571 | struct type *t = value_type (val); | |
11572 | CORE_ADDR addr = value_as_address (val); | |
11573 | char *name; | |
11574 | ||
11575 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11576 | name = type_to_string (t); | |
11577 | ||
3a5c3e22 | 11578 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11579 | core_addr_to_string (addr)); |
06a64a0b TT |
11580 | xfree (name); |
11581 | ||
3a5c3e22 | 11582 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11583 | (int) (exp_end - exp_start), exp_start); |
11584 | ||
06a64a0b TT |
11585 | /* The above expression is in C. */ |
11586 | b->language = language_c; | |
11587 | } | |
11588 | else | |
3a5c3e22 | 11589 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11590 | |
11591 | if (use_mask) | |
11592 | { | |
3a5c3e22 | 11593 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11594 | } |
11595 | else | |
11596 | { | |
3a5c3e22 | 11597 | w->val = val; |
bb9d5f81 PP |
11598 | w->val_bitpos = saved_bitpos; |
11599 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11600 | w->val_valid = 1; |
9c06b0b4 | 11601 | } |
77b06cd7 | 11602 | |
c906108c SS |
11603 | if (cond_start) |
11604 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11605 | else | |
11606 | b->cond_string = 0; | |
c5aa993b | 11607 | |
c906108c | 11608 | if (frame) |
f6bc2008 | 11609 | { |
3a5c3e22 PA |
11610 | w->watchpoint_frame = get_frame_id (frame); |
11611 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11612 | } |
c906108c | 11613 | else |
f6bc2008 | 11614 | { |
3a5c3e22 PA |
11615 | w->watchpoint_frame = null_frame_id; |
11616 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11617 | } |
c906108c | 11618 | |
d983da9c | 11619 | if (scope_breakpoint != NULL) |
c906108c | 11620 | { |
d983da9c DJ |
11621 | /* The scope breakpoint is related to the watchpoint. We will |
11622 | need to act on them together. */ | |
11623 | b->related_breakpoint = scope_breakpoint; | |
11624 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11625 | } |
d983da9c | 11626 | |
06a64a0b TT |
11627 | if (!just_location) |
11628 | value_free_to_mark (mark); | |
2d134ed3 | 11629 | |
a9634178 TJB |
11630 | TRY_CATCH (e, RETURN_MASK_ALL) |
11631 | { | |
11632 | /* Finally update the new watchpoint. This creates the locations | |
11633 | that should be inserted. */ | |
3a5c3e22 | 11634 | update_watchpoint (w, 1); |
a9634178 TJB |
11635 | } |
11636 | if (e.reason < 0) | |
11637 | { | |
11638 | delete_breakpoint (b); | |
11639 | throw_exception (e); | |
11640 | } | |
11641 | ||
3ea46bff | 11642 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11643 | do_cleanups (back_to); |
c906108c SS |
11644 | } |
11645 | ||
e09342b5 | 11646 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11647 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11648 | |
c906108c | 11649 | static int |
a9634178 | 11650 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11651 | { |
11652 | int found_memory_cnt = 0; | |
2e70b7b9 | 11653 | struct value *head = v; |
c906108c SS |
11654 | |
11655 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11656 | if (!can_use_hw_watchpoints) |
c906108c | 11657 | return 0; |
c5aa993b | 11658 | |
5c44784c JM |
11659 | /* Make sure that the value of the expression depends only upon |
11660 | memory contents, and values computed from them within GDB. If we | |
11661 | find any register references or function calls, we can't use a | |
11662 | hardware watchpoint. | |
11663 | ||
11664 | The idea here is that evaluating an expression generates a series | |
11665 | of values, one holding the value of every subexpression. (The | |
11666 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11667 | a*b+c.) GDB's values hold almost enough information to establish | |
11668 | the criteria given above --- they identify memory lvalues, | |
11669 | register lvalues, computed values, etcetera. So we can evaluate | |
11670 | the expression, and then scan the chain of values that leaves | |
11671 | behind to decide whether we can detect any possible change to the | |
11672 | expression's final value using only hardware watchpoints. | |
11673 | ||
11674 | However, I don't think that the values returned by inferior | |
11675 | function calls are special in any way. So this function may not | |
11676 | notice that an expression involving an inferior function call | |
11677 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11678 | for (; v; v = value_next (v)) |
c906108c | 11679 | { |
5c44784c | 11680 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11681 | { |
8464be76 DJ |
11682 | if (v != head && value_lazy (v)) |
11683 | /* A lazy memory lvalue in the chain is one that GDB never | |
11684 | needed to fetch; we either just used its address (e.g., | |
11685 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11686 | in `a,b'). This doesn't apply to HEAD; if that is | |
11687 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11688 | ; |
53a5351d | 11689 | else |
5c44784c JM |
11690 | { |
11691 | /* Ahh, memory we actually used! Check if we can cover | |
11692 | it with hardware watchpoints. */ | |
df407dfe | 11693 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11694 | |
11695 | /* We only watch structs and arrays if user asked for it | |
11696 | explicitly, never if they just happen to appear in a | |
11697 | middle of some value chain. */ | |
11698 | if (v == head | |
11699 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11700 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11701 | { | |
42ae5230 | 11702 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11703 | int len; |
11704 | int num_regs; | |
11705 | ||
a9634178 | 11706 | len = (target_exact_watchpoints |
e09342b5 TJB |
11707 | && is_scalar_type_recursive (vtype))? |
11708 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11709 | |
e09342b5 TJB |
11710 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11711 | if (!num_regs) | |
2e70b7b9 MS |
11712 | return 0; |
11713 | else | |
e09342b5 | 11714 | found_memory_cnt += num_regs; |
2e70b7b9 | 11715 | } |
5c44784c | 11716 | } |
c5aa993b | 11717 | } |
5086187c AC |
11718 | else if (VALUE_LVAL (v) != not_lval |
11719 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11720 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11721 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11722 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11723 | } |
11724 | ||
11725 | /* The expression itself looks suitable for using a hardware | |
11726 | watchpoint, but give the target machine a chance to reject it. */ | |
11727 | return found_memory_cnt; | |
11728 | } | |
11729 | ||
8b93c638 | 11730 | void |
84f4c1fe | 11731 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11732 | { |
84f4c1fe | 11733 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11734 | } |
11735 | ||
06a64a0b TT |
11736 | /* A helper function that looks for the "-location" argument and then |
11737 | calls watch_command_1. */ | |
11738 | ||
11739 | static void | |
11740 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11741 | { | |
11742 | int just_location = 0; | |
11743 | ||
11744 | if (arg | |
11745 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11746 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11747 | { | |
e9cafbcc | 11748 | arg = skip_spaces (arg); |
06a64a0b TT |
11749 | just_location = 1; |
11750 | } | |
11751 | ||
84f4c1fe | 11752 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11753 | } |
8926118c | 11754 | |
c5aa993b | 11755 | static void |
fba45db2 | 11756 | watch_command (char *arg, int from_tty) |
c906108c | 11757 | { |
06a64a0b | 11758 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11759 | } |
11760 | ||
8b93c638 | 11761 | void |
84f4c1fe | 11762 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11763 | { |
84f4c1fe | 11764 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11765 | } |
8926118c | 11766 | |
c5aa993b | 11767 | static void |
fba45db2 | 11768 | rwatch_command (char *arg, int from_tty) |
c906108c | 11769 | { |
06a64a0b | 11770 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11771 | } |
11772 | ||
8b93c638 | 11773 | void |
84f4c1fe | 11774 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11775 | { |
84f4c1fe | 11776 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11777 | } |
8926118c | 11778 | |
c5aa993b | 11779 | static void |
fba45db2 | 11780 | awatch_command (char *arg, int from_tty) |
c906108c | 11781 | { |
06a64a0b | 11782 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11783 | } |
c906108c | 11784 | \f |
c5aa993b | 11785 | |
43ff13b4 | 11786 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
11787 | because it uses the mechanisms of breakpoints. */ |
11788 | ||
bfec99b2 PA |
11789 | struct until_break_command_continuation_args |
11790 | { | |
11791 | struct breakpoint *breakpoint; | |
11792 | struct breakpoint *breakpoint2; | |
186c406b | 11793 | int thread_num; |
bfec99b2 PA |
11794 | }; |
11795 | ||
43ff13b4 | 11796 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 11797 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 11798 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 11799 | command. */ |
c2c6d25f | 11800 | static void |
fa4cd53f | 11801 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 11802 | { |
bfec99b2 PA |
11803 | struct until_break_command_continuation_args *a = arg; |
11804 | ||
11805 | delete_breakpoint (a->breakpoint); | |
11806 | if (a->breakpoint2) | |
11807 | delete_breakpoint (a->breakpoint2); | |
186c406b | 11808 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
11809 | } |
11810 | ||
c906108c | 11811 | void |
ae66c1fc | 11812 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11813 | { |
11814 | struct symtabs_and_lines sals; | |
11815 | struct symtab_and_line sal; | |
8556afb4 PA |
11816 | struct frame_info *frame; |
11817 | struct gdbarch *frame_gdbarch; | |
11818 | struct frame_id stack_frame_id; | |
11819 | struct frame_id caller_frame_id; | |
c906108c | 11820 | struct breakpoint *breakpoint; |
f107f563 | 11821 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 11822 | struct cleanup *old_chain; |
186c406b TT |
11823 | int thread; |
11824 | struct thread_info *tp; | |
c906108c | 11825 | |
70509625 | 11826 | clear_proceed_status (0); |
c906108c SS |
11827 | |
11828 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11829 | this function. */ |
c5aa993b | 11830 | |
1bfeeb0f | 11831 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 11832 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11833 | get_last_displayed_symtab (), |
f8eba3c6 | 11834 | get_last_displayed_line ()); |
c906108c | 11835 | else |
f8eba3c6 TT |
11836 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
11837 | (struct symtab *) NULL, 0); | |
c5aa993b | 11838 | |
c906108c | 11839 | if (sals.nelts != 1) |
8a3fe4f8 | 11840 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11841 | |
c906108c | 11842 | sal = sals.sals[0]; |
4a64f543 | 11843 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11844 | |
c906108c | 11845 | if (*arg) |
8a3fe4f8 | 11846 | error (_("Junk at end of arguments.")); |
c5aa993b | 11847 | |
c906108c | 11848 | resolve_sal_pc (&sal); |
c5aa993b | 11849 | |
186c406b TT |
11850 | tp = inferior_thread (); |
11851 | thread = tp->num; | |
11852 | ||
883bc8d1 PA |
11853 | old_chain = make_cleanup (null_cleanup, NULL); |
11854 | ||
8556afb4 PA |
11855 | /* Note linespec handling above invalidates the frame chain. |
11856 | Installing a breakpoint also invalidates the frame chain (as it | |
11857 | may need to switch threads), so do any frame handling before | |
11858 | that. */ | |
11859 | ||
11860 | frame = get_selected_frame (NULL); | |
11861 | frame_gdbarch = get_frame_arch (frame); | |
11862 | stack_frame_id = get_stack_frame_id (frame); | |
11863 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11864 | |
ae66c1fc EZ |
11865 | /* Keep within the current frame, or in frames called by the current |
11866 | one. */ | |
edb3359d | 11867 | |
883bc8d1 | 11868 | if (frame_id_p (caller_frame_id)) |
c906108c | 11869 | { |
883bc8d1 PA |
11870 | struct symtab_and_line sal2; |
11871 | ||
11872 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11873 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 11874 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
11875 | sal2, |
11876 | caller_frame_id, | |
f107f563 VP |
11877 | bp_until); |
11878 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 11879 | |
883bc8d1 | 11880 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11881 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11882 | } |
c5aa993b | 11883 | |
c70a6932 JK |
11884 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11885 | frame = NULL; | |
11886 | ||
883bc8d1 PA |
11887 | if (anywhere) |
11888 | /* If the user told us to continue until a specified location, | |
11889 | we don't specify a frame at which we need to stop. */ | |
11890 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11891 | null_frame_id, bp_until); | |
11892 | else | |
11893 | /* Otherwise, specify the selected frame, because we want to stop | |
11894 | only at the very same frame. */ | |
11895 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11896 | stack_frame_id, bp_until); | |
11897 | make_cleanup_delete_breakpoint (breakpoint); | |
11898 | ||
a493e3e2 | 11899 | proceed (-1, GDB_SIGNAL_DEFAULT, 0); |
f107f563 | 11900 | |
4a64f543 MS |
11901 | /* If we are running asynchronously, and proceed call above has |
11902 | actually managed to start the target, arrange for breakpoints to | |
11903 | be deleted when the target stops. Otherwise, we're already | |
11904 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 11905 | |
8ea051c5 | 11906 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 11907 | { |
bfec99b2 PA |
11908 | struct until_break_command_continuation_args *args; |
11909 | args = xmalloc (sizeof (*args)); | |
f107f563 | 11910 | |
bfec99b2 PA |
11911 | args->breakpoint = breakpoint; |
11912 | args->breakpoint2 = breakpoint2; | |
186c406b | 11913 | args->thread_num = thread; |
f107f563 VP |
11914 | |
11915 | discard_cleanups (old_chain); | |
95e54da7 PA |
11916 | add_continuation (inferior_thread (), |
11917 | until_break_command_continuation, args, | |
604ead4a | 11918 | xfree); |
f107f563 VP |
11919 | } |
11920 | else | |
c5aa993b | 11921 | do_cleanups (old_chain); |
c906108c | 11922 | } |
ae66c1fc | 11923 | |
c906108c SS |
11924 | /* This function attempts to parse an optional "if <cond>" clause |
11925 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11926 | |
c906108c SS |
11927 | Else, it returns a pointer to the condition string. (It does not |
11928 | attempt to evaluate the string against a particular block.) And, | |
11929 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11930 | if clause in the arg string. */ |
53a5351d | 11931 | |
916703c0 | 11932 | char * |
fba45db2 | 11933 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11934 | { |
c5aa993b JM |
11935 | char *cond_string; |
11936 | ||
11937 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11938 | return NULL; |
c5aa993b | 11939 | |
4a64f543 | 11940 | /* Skip the "if" keyword. */ |
c906108c | 11941 | (*arg) += 2; |
c5aa993b | 11942 | |
c906108c | 11943 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11944 | condition string. */ |
e9cafbcc | 11945 | *arg = skip_spaces (*arg); |
c906108c | 11946 | cond_string = *arg; |
c5aa993b | 11947 | |
4a64f543 MS |
11948 | /* Assume that the condition occupies the remainder of the arg |
11949 | string. */ | |
c906108c | 11950 | (*arg) += strlen (cond_string); |
c5aa993b | 11951 | |
c906108c SS |
11952 | return cond_string; |
11953 | } | |
c5aa993b | 11954 | |
c906108c SS |
11955 | /* Commands to deal with catching events, such as signals, exceptions, |
11956 | process start/exit, etc. */ | |
c5aa993b JM |
11957 | |
11958 | typedef enum | |
11959 | { | |
44feb3ce TT |
11960 | catch_fork_temporary, catch_vfork_temporary, |
11961 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11962 | } |
11963 | catch_fork_kind; | |
11964 | ||
c906108c | 11965 | static void |
cc59ec59 MS |
11966 | catch_fork_command_1 (char *arg, int from_tty, |
11967 | struct cmd_list_element *command) | |
c906108c | 11968 | { |
a6d9a66e | 11969 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11970 | char *cond_string = NULL; |
44feb3ce TT |
11971 | catch_fork_kind fork_kind; |
11972 | int tempflag; | |
11973 | ||
11974 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11975 | tempflag = (fork_kind == catch_fork_temporary | |
11976 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11977 | |
44feb3ce TT |
11978 | if (!arg) |
11979 | arg = ""; | |
e9cafbcc | 11980 | arg = skip_spaces (arg); |
c5aa993b | 11981 | |
c906108c | 11982 | /* The allowed syntax is: |
c5aa993b JM |
11983 | catch [v]fork |
11984 | catch [v]fork if <cond> | |
11985 | ||
4a64f543 | 11986 | First, check if there's an if clause. */ |
c906108c | 11987 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11988 | |
c906108c | 11989 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11990 | error (_("Junk at end of arguments.")); |
c5aa993b | 11991 | |
c906108c | 11992 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11993 | and enable reporting of such events. */ |
c5aa993b JM |
11994 | switch (fork_kind) |
11995 | { | |
44feb3ce TT |
11996 | case catch_fork_temporary: |
11997 | case catch_fork_permanent: | |
a6d9a66e | 11998 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11999 | &catch_fork_breakpoint_ops); |
c906108c | 12000 | break; |
44feb3ce TT |
12001 | case catch_vfork_temporary: |
12002 | case catch_vfork_permanent: | |
a6d9a66e | 12003 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 12004 | &catch_vfork_breakpoint_ops); |
c906108c | 12005 | break; |
c5aa993b | 12006 | default: |
8a3fe4f8 | 12007 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 12008 | break; |
c5aa993b | 12009 | } |
c906108c SS |
12010 | } |
12011 | ||
12012 | static void | |
cc59ec59 MS |
12013 | catch_exec_command_1 (char *arg, int from_tty, |
12014 | struct cmd_list_element *command) | |
c906108c | 12015 | { |
b4d90040 | 12016 | struct exec_catchpoint *c; |
a6d9a66e | 12017 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 12018 | int tempflag; |
c5aa993b | 12019 | char *cond_string = NULL; |
c906108c | 12020 | |
44feb3ce TT |
12021 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
12022 | ||
12023 | if (!arg) | |
12024 | arg = ""; | |
e9cafbcc | 12025 | arg = skip_spaces (arg); |
c906108c SS |
12026 | |
12027 | /* The allowed syntax is: | |
c5aa993b JM |
12028 | catch exec |
12029 | catch exec if <cond> | |
c906108c | 12030 | |
4a64f543 | 12031 | First, check if there's an if clause. */ |
c906108c SS |
12032 | cond_string = ep_parse_optional_if_clause (&arg); |
12033 | ||
12034 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 12035 | error (_("Junk at end of arguments.")); |
c906108c | 12036 | |
b4d90040 PA |
12037 | c = XNEW (struct exec_catchpoint); |
12038 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
12039 | &catch_exec_breakpoint_ops); | |
12040 | c->exec_pathname = NULL; | |
12041 | ||
3ea46bff | 12042 | install_breakpoint (0, &c->base, 1); |
c906108c | 12043 | } |
c5aa993b | 12044 | |
9ac4176b | 12045 | void |
28010a5d PA |
12046 | init_ada_exception_breakpoint (struct breakpoint *b, |
12047 | struct gdbarch *gdbarch, | |
12048 | struct symtab_and_line sal, | |
12049 | char *addr_string, | |
c0a91b2b | 12050 | const struct breakpoint_ops *ops, |
28010a5d | 12051 | int tempflag, |
349774ef | 12052 | int enabled, |
28010a5d | 12053 | int from_tty) |
f7f9143b | 12054 | { |
f7f9143b JB |
12055 | if (from_tty) |
12056 | { | |
5af949e3 UW |
12057 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
12058 | if (!loc_gdbarch) | |
12059 | loc_gdbarch = gdbarch; | |
12060 | ||
6c95b8df PA |
12061 | describe_other_breakpoints (loc_gdbarch, |
12062 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
12063 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
12064 | version for exception catchpoints, because two catchpoints | |
12065 | used for different exception names will use the same address. | |
12066 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 12067 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 12068 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
12069 | the user what type of catchpoint it is. The above is good |
12070 | enough for now, though. */ | |
12071 | } | |
12072 | ||
28010a5d | 12073 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 12074 | |
349774ef | 12075 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 12076 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f7f9143b JB |
12077 | b->addr_string = addr_string; |
12078 | b->language = language_ada; | |
f7f9143b JB |
12079 | } |
12080 | ||
a96d9b2e SDJ |
12081 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
12082 | filter list, or NULL if no filtering is required. */ | |
12083 | static VEC(int) * | |
12084 | catch_syscall_split_args (char *arg) | |
12085 | { | |
12086 | VEC(int) *result = NULL; | |
29d0bb3d | 12087 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
458c8db8 | 12088 | struct gdbarch *gdbarch = target_gdbarch (); |
a96d9b2e SDJ |
12089 | |
12090 | while (*arg != '\0') | |
12091 | { | |
12092 | int i, syscall_number; | |
12093 | char *endptr; | |
12094 | char cur_name[128]; | |
12095 | struct syscall s; | |
12096 | ||
12097 | /* Skip whitespace. */ | |
529480d0 | 12098 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
12099 | |
12100 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
12101 | cur_name[i] = arg[i]; | |
12102 | cur_name[i] = '\0'; | |
12103 | arg += i; | |
12104 | ||
12105 | /* Check if the user provided a syscall name or a number. */ | |
12106 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
12107 | if (*endptr == '\0') | |
458c8db8 | 12108 | get_syscall_by_number (gdbarch, syscall_number, &s); |
a96d9b2e SDJ |
12109 | else |
12110 | { | |
12111 | /* We have a name. Let's check if it's valid and convert it | |
12112 | to a number. */ | |
458c8db8 | 12113 | get_syscall_by_name (gdbarch, cur_name, &s); |
a96d9b2e SDJ |
12114 | |
12115 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
12116 | /* Here we have to issue an error instead of a warning, |
12117 | because GDB cannot do anything useful if there's no | |
12118 | syscall number to be caught. */ | |
a96d9b2e SDJ |
12119 | error (_("Unknown syscall name '%s'."), cur_name); |
12120 | } | |
12121 | ||
12122 | /* Ok, it's valid. */ | |
12123 | VEC_safe_push (int, result, s.number); | |
12124 | } | |
12125 | ||
12126 | discard_cleanups (cleanup); | |
12127 | return result; | |
12128 | } | |
12129 | ||
12130 | /* Implement the "catch syscall" command. */ | |
12131 | ||
12132 | static void | |
cc59ec59 MS |
12133 | catch_syscall_command_1 (char *arg, int from_tty, |
12134 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
12135 | { |
12136 | int tempflag; | |
12137 | VEC(int) *filter; | |
12138 | struct syscall s; | |
12139 | struct gdbarch *gdbarch = get_current_arch (); | |
12140 | ||
12141 | /* Checking if the feature if supported. */ | |
12142 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
12143 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 12144 | this architecture yet.")); |
a96d9b2e SDJ |
12145 | |
12146 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
12147 | ||
e9cafbcc | 12148 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
12149 | |
12150 | /* We need to do this first "dummy" translation in order | |
12151 | to get the syscall XML file loaded or, most important, | |
12152 | to display a warning to the user if there's no XML file | |
12153 | for his/her architecture. */ | |
458c8db8 | 12154 | get_syscall_by_number (gdbarch, 0, &s); |
a96d9b2e SDJ |
12155 | |
12156 | /* The allowed syntax is: | |
12157 | catch syscall | |
12158 | catch syscall <name | number> [<name | number> ... <name | number>] | |
12159 | ||
12160 | Let's check if there's a syscall name. */ | |
12161 | ||
12162 | if (arg != NULL) | |
12163 | filter = catch_syscall_split_args (arg); | |
12164 | else | |
12165 | filter = NULL; | |
12166 | ||
12167 | create_syscall_event_catchpoint (tempflag, filter, | |
12168 | &catch_syscall_breakpoint_ops); | |
12169 | } | |
12170 | ||
c906108c | 12171 | static void |
fba45db2 | 12172 | catch_command (char *arg, int from_tty) |
c906108c | 12173 | { |
44feb3ce | 12174 | error (_("Catch requires an event name.")); |
c906108c SS |
12175 | } |
12176 | \f | |
12177 | ||
12178 | static void | |
fba45db2 | 12179 | tcatch_command (char *arg, int from_tty) |
c906108c | 12180 | { |
44feb3ce | 12181 | error (_("Catch requires an event name.")); |
c906108c SS |
12182 | } |
12183 | ||
8a2c437b TT |
12184 | /* A qsort comparison function that sorts breakpoints in order. */ |
12185 | ||
12186 | static int | |
12187 | compare_breakpoints (const void *a, const void *b) | |
12188 | { | |
12189 | const breakpoint_p *ba = a; | |
12190 | uintptr_t ua = (uintptr_t) *ba; | |
12191 | const breakpoint_p *bb = b; | |
12192 | uintptr_t ub = (uintptr_t) *bb; | |
12193 | ||
12194 | if ((*ba)->number < (*bb)->number) | |
12195 | return -1; | |
12196 | else if ((*ba)->number > (*bb)->number) | |
12197 | return 1; | |
12198 | ||
12199 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
12200 | the number 0. */ | |
12201 | if (ua < ub) | |
12202 | return -1; | |
94b0e70d | 12203 | return ua > ub ? 1 : 0; |
8a2c437b TT |
12204 | } |
12205 | ||
80f8a6eb | 12206 | /* Delete breakpoints by address or line. */ |
c906108c SS |
12207 | |
12208 | static void | |
fba45db2 | 12209 | clear_command (char *arg, int from_tty) |
c906108c | 12210 | { |
8a2c437b | 12211 | struct breakpoint *b, *prev; |
d6e956e5 VP |
12212 | VEC(breakpoint_p) *found = 0; |
12213 | int ix; | |
c906108c SS |
12214 | int default_match; |
12215 | struct symtabs_and_lines sals; | |
12216 | struct symtab_and_line sal; | |
c906108c | 12217 | int i; |
8a2c437b | 12218 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
12219 | |
12220 | if (arg) | |
12221 | { | |
39cf75f7 DE |
12222 | sals = decode_line_with_current_source (arg, |
12223 | (DECODE_LINE_FUNFIRSTLINE | |
12224 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 12225 | make_cleanup (xfree, sals.sals); |
c906108c SS |
12226 | default_match = 0; |
12227 | } | |
12228 | else | |
12229 | { | |
c5aa993b | 12230 | sals.sals = (struct symtab_and_line *) |
c906108c | 12231 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 12232 | make_cleanup (xfree, sals.sals); |
4a64f543 | 12233 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
12234 | |
12235 | /* Set sal's line, symtab, pc, and pspace to the values | |
12236 | corresponding to the last call to print_frame_info. If the | |
12237 | codepoint is not valid, this will set all the fields to 0. */ | |
12238 | get_last_displayed_sal (&sal); | |
c906108c | 12239 | if (sal.symtab == 0) |
8a3fe4f8 | 12240 | error (_("No source file specified.")); |
c906108c SS |
12241 | |
12242 | sals.sals[0] = sal; | |
12243 | sals.nelts = 1; | |
12244 | ||
12245 | default_match = 1; | |
12246 | } | |
12247 | ||
4a64f543 MS |
12248 | /* We don't call resolve_sal_pc here. That's not as bad as it |
12249 | seems, because all existing breakpoints typically have both | |
12250 | file/line and pc set. So, if clear is given file/line, we can | |
12251 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
12252 | |
12253 | We only support clearing given the address explicitly | |
12254 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 12255 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 12256 | due to optimization, all in one block. |
4a64f543 MS |
12257 | |
12258 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
12259 | PC corresponding to the same file:line, the breakpoint won't |
12260 | be cleared. We probably can still clear the breakpoint, but | |
12261 | since the other PC value is never presented to user, user | |
12262 | can only find it by guessing, and it does not seem important | |
12263 | to support that. */ | |
12264 | ||
4a64f543 MS |
12265 | /* For each line spec given, delete bps which correspond to it. Do |
12266 | it in two passes, solely to preserve the current behavior that | |
12267 | from_tty is forced true if we delete more than one | |
12268 | breakpoint. */ | |
c906108c | 12269 | |
80f8a6eb | 12270 | found = NULL; |
8a2c437b | 12271 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12272 | for (i = 0; i < sals.nelts; i++) |
12273 | { | |
05cba821 JK |
12274 | const char *sal_fullname; |
12275 | ||
c906108c | 12276 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12277 | If line given (pc == 0), clear all bpts on specified line. |
12278 | If defaulting, clear all bpts on default line | |
c906108c | 12279 | or at default pc. |
c5aa993b JM |
12280 | |
12281 | defaulting sal.pc != 0 tests to do | |
12282 | ||
12283 | 0 1 pc | |
12284 | 1 1 pc _and_ line | |
12285 | 0 0 line | |
12286 | 1 0 <can't happen> */ | |
c906108c SS |
12287 | |
12288 | sal = sals.sals[i]; | |
05cba821 JK |
12289 | sal_fullname = (sal.symtab == NULL |
12290 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12291 | |
4a64f543 | 12292 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12293 | ALL_BREAKPOINTS (b) |
c5aa993b | 12294 | { |
0d381245 | 12295 | int match = 0; |
4a64f543 | 12296 | /* Are we going to delete b? */ |
cc60f2e3 | 12297 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12298 | { |
12299 | struct bp_location *loc = b->loc; | |
12300 | for (; loc; loc = loc->next) | |
12301 | { | |
f8eba3c6 TT |
12302 | /* If the user specified file:line, don't allow a PC |
12303 | match. This matches historical gdb behavior. */ | |
12304 | int pc_match = (!sal.explicit_line | |
12305 | && sal.pc | |
12306 | && (loc->pspace == sal.pspace) | |
12307 | && (loc->address == sal.pc) | |
12308 | && (!section_is_overlay (loc->section) | |
12309 | || loc->section == sal.section)); | |
4aac40c8 TT |
12310 | int line_match = 0; |
12311 | ||
12312 | if ((default_match || sal.explicit_line) | |
2f202fde | 12313 | && loc->symtab != NULL |
05cba821 | 12314 | && sal_fullname != NULL |
4aac40c8 | 12315 | && sal.pspace == loc->pspace |
05cba821 JK |
12316 | && loc->line_number == sal.line |
12317 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12318 | sal_fullname) == 0) | |
12319 | line_match = 1; | |
4aac40c8 | 12320 | |
0d381245 VP |
12321 | if (pc_match || line_match) |
12322 | { | |
12323 | match = 1; | |
12324 | break; | |
12325 | } | |
12326 | } | |
12327 | } | |
12328 | ||
12329 | if (match) | |
d6e956e5 | 12330 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12331 | } |
80f8a6eb | 12332 | } |
8a2c437b | 12333 | |
80f8a6eb | 12334 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12335 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12336 | { |
12337 | if (arg) | |
8a3fe4f8 | 12338 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12339 | else |
8a3fe4f8 | 12340 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12341 | } |
c906108c | 12342 | |
8a2c437b TT |
12343 | /* Remove duplicates from the vec. */ |
12344 | qsort (VEC_address (breakpoint_p, found), | |
12345 | VEC_length (breakpoint_p, found), | |
12346 | sizeof (breakpoint_p), | |
12347 | compare_breakpoints); | |
12348 | prev = VEC_index (breakpoint_p, found, 0); | |
12349 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12350 | { | |
12351 | if (b == prev) | |
12352 | { | |
12353 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12354 | --ix; | |
12355 | } | |
12356 | } | |
12357 | ||
d6e956e5 | 12358 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12359 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12360 | if (from_tty) |
a3f17187 | 12361 | { |
d6e956e5 | 12362 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12363 | printf_unfiltered (_("Deleted breakpoint ")); |
12364 | else | |
12365 | printf_unfiltered (_("Deleted breakpoints ")); | |
12366 | } | |
d6e956e5 VP |
12367 | |
12368 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12369 | { |
c5aa993b | 12370 | if (from_tty) |
d6e956e5 VP |
12371 | printf_unfiltered ("%d ", b->number); |
12372 | delete_breakpoint (b); | |
c906108c | 12373 | } |
80f8a6eb MS |
12374 | if (from_tty) |
12375 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12376 | |
12377 | do_cleanups (cleanups); | |
c906108c SS |
12378 | } |
12379 | \f | |
12380 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12381 | all breakpoints that are marked for deletion, whether hit or not. | |
12382 | This is called after any breakpoint is hit, or after errors. */ | |
12383 | ||
12384 | void | |
fba45db2 | 12385 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12386 | { |
35df4500 | 12387 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12388 | |
12389 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12390 | if (bs->breakpoint_at |
12391 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12392 | && bs->stop) |
f431efe5 | 12393 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12394 | |
35df4500 | 12395 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12396 | { |
b5de0fa7 | 12397 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12398 | delete_breakpoint (b); |
12399 | } | |
c906108c SS |
12400 | } |
12401 | ||
4a64f543 MS |
12402 | /* A comparison function for bp_location AP and BP being interfaced to |
12403 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12404 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 12405 | secondarily by ordering first permanent elements and |
4a64f543 | 12406 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 12407 | qsort being an unstable algorithm. */ |
876fa593 JK |
12408 | |
12409 | static int | |
494cfb0f | 12410 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12411 | { |
494cfb0f JK |
12412 | struct bp_location *a = *(void **) ap; |
12413 | struct bp_location *b = *(void **) bp; | |
876fa593 JK |
12414 | |
12415 | if (a->address != b->address) | |
12416 | return (a->address > b->address) - (a->address < b->address); | |
12417 | ||
dea2aa5f LM |
12418 | /* Sort locations at the same address by their pspace number, keeping |
12419 | locations of the same inferior (in a multi-inferior environment) | |
12420 | grouped. */ | |
12421 | ||
12422 | if (a->pspace->num != b->pspace->num) | |
12423 | return ((a->pspace->num > b->pspace->num) | |
12424 | - (a->pspace->num < b->pspace->num)); | |
12425 | ||
876fa593 | 12426 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
12427 | if (a->permanent != b->permanent) |
12428 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 12429 | |
c56a97f9 JK |
12430 | /* Make the internal GDB representation stable across GDB runs |
12431 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12432 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12433 | |
12434 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12435 | return ((a->owner->number > b->owner->number) |
12436 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12437 | |
12438 | return (a > b) - (a < b); | |
12439 | } | |
12440 | ||
876fa593 | 12441 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12442 | bp_location_shadow_len_after_address_max according to the current |
12443 | content of the bp_location array. */ | |
f7545552 TT |
12444 | |
12445 | static void | |
876fa593 | 12446 | bp_location_target_extensions_update (void) |
f7545552 | 12447 | { |
876fa593 JK |
12448 | struct bp_location *bl, **blp_tmp; |
12449 | ||
12450 | bp_location_placed_address_before_address_max = 0; | |
12451 | bp_location_shadow_len_after_address_max = 0; | |
12452 | ||
12453 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12454 | { | |
12455 | CORE_ADDR start, end, addr; | |
12456 | ||
12457 | if (!bp_location_has_shadow (bl)) | |
12458 | continue; | |
12459 | ||
12460 | start = bl->target_info.placed_address; | |
12461 | end = start + bl->target_info.shadow_len; | |
12462 | ||
12463 | gdb_assert (bl->address >= start); | |
12464 | addr = bl->address - start; | |
12465 | if (addr > bp_location_placed_address_before_address_max) | |
12466 | bp_location_placed_address_before_address_max = addr; | |
12467 | ||
12468 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12469 | ||
12470 | gdb_assert (bl->address < end); | |
12471 | addr = end - bl->address; | |
12472 | if (addr > bp_location_shadow_len_after_address_max) | |
12473 | bp_location_shadow_len_after_address_max = addr; | |
12474 | } | |
f7545552 TT |
12475 | } |
12476 | ||
1e4d1764 YQ |
12477 | /* Download tracepoint locations if they haven't been. */ |
12478 | ||
12479 | static void | |
12480 | download_tracepoint_locations (void) | |
12481 | { | |
7ed2c994 | 12482 | struct breakpoint *b; |
1e4d1764 YQ |
12483 | struct cleanup *old_chain; |
12484 | ||
12485 | if (!target_can_download_tracepoint ()) | |
12486 | return; | |
12487 | ||
12488 | old_chain = save_current_space_and_thread (); | |
12489 | ||
7ed2c994 | 12490 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12491 | { |
7ed2c994 | 12492 | struct bp_location *bl; |
1e4d1764 | 12493 | struct tracepoint *t; |
f2a8bc8a | 12494 | int bp_location_downloaded = 0; |
1e4d1764 | 12495 | |
7ed2c994 | 12496 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12497 | ? !may_insert_fast_tracepoints |
12498 | : !may_insert_tracepoints)) | |
12499 | continue; | |
12500 | ||
7ed2c994 YQ |
12501 | for (bl = b->loc; bl; bl = bl->next) |
12502 | { | |
12503 | /* In tracepoint, locations are _never_ duplicated, so | |
12504 | should_be_inserted is equivalent to | |
12505 | unduplicated_should_be_inserted. */ | |
12506 | if (!should_be_inserted (bl) || bl->inserted) | |
12507 | continue; | |
1e4d1764 | 12508 | |
7ed2c994 | 12509 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12510 | |
7ed2c994 | 12511 | target_download_tracepoint (bl); |
1e4d1764 | 12512 | |
7ed2c994 | 12513 | bl->inserted = 1; |
f2a8bc8a | 12514 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12515 | } |
12516 | t = (struct tracepoint *) b; | |
12517 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12518 | if (bp_location_downloaded) |
12519 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12520 | } |
12521 | ||
12522 | do_cleanups (old_chain); | |
12523 | } | |
12524 | ||
934709f0 PW |
12525 | /* Swap the insertion/duplication state between two locations. */ |
12526 | ||
12527 | static void | |
12528 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12529 | { | |
12530 | const int left_inserted = left->inserted; | |
12531 | const int left_duplicate = left->duplicate; | |
b775012e | 12532 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12533 | const struct bp_target_info left_target_info = left->target_info; |
12534 | ||
1e4d1764 YQ |
12535 | /* Locations of tracepoints can never be duplicated. */ |
12536 | if (is_tracepoint (left->owner)) | |
12537 | gdb_assert (!left->duplicate); | |
12538 | if (is_tracepoint (right->owner)) | |
12539 | gdb_assert (!right->duplicate); | |
12540 | ||
934709f0 PW |
12541 | left->inserted = right->inserted; |
12542 | left->duplicate = right->duplicate; | |
b775012e | 12543 | left->needs_update = right->needs_update; |
934709f0 PW |
12544 | left->target_info = right->target_info; |
12545 | right->inserted = left_inserted; | |
12546 | right->duplicate = left_duplicate; | |
b775012e | 12547 | right->needs_update = left_needs_update; |
934709f0 PW |
12548 | right->target_info = left_target_info; |
12549 | } | |
12550 | ||
b775012e LM |
12551 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12552 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12553 | conditions on the target's side. Such conditions need to be updated on | |
12554 | the target. */ | |
12555 | ||
12556 | static void | |
12557 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12558 | { | |
12559 | struct bp_location **locp = NULL, **loc2p; | |
12560 | struct bp_location *loc; | |
12561 | CORE_ADDR address = 0; | |
12562 | int pspace_num; | |
12563 | ||
12564 | address = bl->address; | |
12565 | pspace_num = bl->pspace->num; | |
12566 | ||
12567 | /* This is only meaningful if the target is | |
12568 | evaluating conditions and if the user has | |
12569 | opted for condition evaluation on the target's | |
12570 | side. */ | |
12571 | if (gdb_evaluates_breakpoint_condition_p () | |
12572 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12573 | return; | |
12574 | ||
12575 | /* Flag all breakpoint locations with this address and | |
12576 | the same program space as the location | |
12577 | as "its condition has changed". We need to | |
12578 | update the conditions on the target's side. */ | |
12579 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12580 | { | |
12581 | loc = *loc2p; | |
12582 | ||
12583 | if (!is_breakpoint (loc->owner) | |
12584 | || pspace_num != loc->pspace->num) | |
12585 | continue; | |
12586 | ||
12587 | /* Flag the location appropriately. We use a different state to | |
12588 | let everyone know that we already updated the set of locations | |
12589 | with addr bl->address and program space bl->pspace. This is so | |
12590 | we don't have to keep calling these functions just to mark locations | |
12591 | that have already been marked. */ | |
12592 | loc->condition_changed = condition_updated; | |
12593 | ||
12594 | /* Free the agent expression bytecode as well. We will compute | |
12595 | it later on. */ | |
12596 | if (loc->cond_bytecode) | |
12597 | { | |
12598 | free_agent_expr (loc->cond_bytecode); | |
12599 | loc->cond_bytecode = NULL; | |
12600 | } | |
12601 | } | |
12602 | } | |
44702360 PA |
12603 | /* Called whether new breakpoints are created, or existing breakpoints |
12604 | deleted, to update the global location list and recompute which | |
12605 | locations are duplicate of which. | |
b775012e | 12606 | |
04086b45 PA |
12607 | The INSERT_MODE flag determines whether locations may not, may, or |
12608 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12609 | info. */ | |
b60e7edf | 12610 | |
0d381245 | 12611 | static void |
44702360 | 12612 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12613 | { |
74960c60 | 12614 | struct breakpoint *b; |
876fa593 | 12615 | struct bp_location **locp, *loc; |
f7545552 | 12616 | struct cleanup *cleanups; |
b775012e LM |
12617 | /* Last breakpoint location address that was marked for update. */ |
12618 | CORE_ADDR last_addr = 0; | |
12619 | /* Last breakpoint location program space that was marked for update. */ | |
12620 | int last_pspace_num = -1; | |
f7545552 | 12621 | |
2d134ed3 PA |
12622 | /* Used in the duplicates detection below. When iterating over all |
12623 | bp_locations, points to the first bp_location of a given address. | |
12624 | Breakpoints and watchpoints of different types are never | |
12625 | duplicates of each other. Keep one pointer for each type of | |
12626 | breakpoint/watchpoint, so we only need to loop over all locations | |
12627 | once. */ | |
12628 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12629 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12630 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12631 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12632 | |
4a64f543 MS |
12633 | /* Saved former bp_location array which we compare against the newly |
12634 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12635 | struct bp_location **old_location, **old_locp; |
12636 | unsigned old_location_count; | |
12637 | ||
12638 | old_location = bp_location; | |
12639 | old_location_count = bp_location_count; | |
12640 | bp_location = NULL; | |
12641 | bp_location_count = 0; | |
12642 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12643 | |
74960c60 | 12644 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12645 | for (loc = b->loc; loc; loc = loc->next) |
12646 | bp_location_count++; | |
12647 | ||
12648 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
12649 | locp = bp_location; | |
12650 | ALL_BREAKPOINTS (b) | |
12651 | for (loc = b->loc; loc; loc = loc->next) | |
12652 | *locp++ = loc; | |
12653 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12654 | bp_location_compare); |
876fa593 JK |
12655 | |
12656 | bp_location_target_extensions_update (); | |
74960c60 | 12657 | |
4a64f543 MS |
12658 | /* Identify bp_location instances that are no longer present in the |
12659 | new list, and therefore should be freed. Note that it's not | |
12660 | necessary that those locations should be removed from inferior -- | |
12661 | if there's another location at the same address (previously | |
12662 | marked as duplicate), we don't need to remove/insert the | |
12663 | location. | |
876fa593 | 12664 | |
4a64f543 MS |
12665 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12666 | and former bp_location array state respectively. */ | |
876fa593 JK |
12667 | |
12668 | locp = bp_location; | |
12669 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12670 | old_locp++) | |
74960c60 | 12671 | { |
876fa593 | 12672 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12673 | struct bp_location **loc2p; |
876fa593 | 12674 | |
e5dd4106 | 12675 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12676 | not, we have to free it. */ |
c7d46a38 | 12677 | int found_object = 0; |
20874c92 VP |
12678 | /* Tells if the location should remain inserted in the target. */ |
12679 | int keep_in_target = 0; | |
12680 | int removed = 0; | |
876fa593 | 12681 | |
4a64f543 MS |
12682 | /* Skip LOCP entries which will definitely never be needed. |
12683 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12684 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12685 | && (*locp)->address < old_loc->address) |
876fa593 | 12686 | locp++; |
c7d46a38 PA |
12687 | |
12688 | for (loc2p = locp; | |
12689 | (loc2p < bp_location + bp_location_count | |
12690 | && (*loc2p)->address == old_loc->address); | |
12691 | loc2p++) | |
12692 | { | |
b775012e LM |
12693 | /* Check if this is a new/duplicated location or a duplicated |
12694 | location that had its condition modified. If so, we want to send | |
12695 | its condition to the target if evaluation of conditions is taking | |
12696 | place there. */ | |
12697 | if ((*loc2p)->condition_changed == condition_modified | |
12698 | && (last_addr != old_loc->address | |
12699 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12700 | { |
b775012e LM |
12701 | force_breakpoint_reinsertion (*loc2p); |
12702 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12703 | } |
b775012e LM |
12704 | |
12705 | if (*loc2p == old_loc) | |
12706 | found_object = 1; | |
c7d46a38 | 12707 | } |
74960c60 | 12708 | |
b775012e LM |
12709 | /* We have already handled this address, update it so that we don't |
12710 | have to go through updates again. */ | |
12711 | last_addr = old_loc->address; | |
12712 | ||
12713 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12714 | if (!found_object) | |
12715 | force_breakpoint_reinsertion (old_loc); | |
12716 | ||
4a64f543 MS |
12717 | /* If this location is no longer present, and inserted, look if |
12718 | there's maybe a new location at the same address. If so, | |
12719 | mark that one inserted, and don't remove this one. This is | |
12720 | needed so that we don't have a time window where a breakpoint | |
12721 | at certain location is not inserted. */ | |
74960c60 | 12722 | |
876fa593 | 12723 | if (old_loc->inserted) |
0d381245 | 12724 | { |
4a64f543 MS |
12725 | /* If the location is inserted now, we might have to remove |
12726 | it. */ | |
74960c60 | 12727 | |
876fa593 | 12728 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12729 | { |
4a64f543 MS |
12730 | /* The location is still present in the location list, |
12731 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12732 | keep_in_target = 1; |
74960c60 VP |
12733 | } |
12734 | else | |
12735 | { | |
b775012e LM |
12736 | /* This location still exists, but it won't be kept in the |
12737 | target since it may have been disabled. We proceed to | |
12738 | remove its target-side condition. */ | |
12739 | ||
4a64f543 MS |
12740 | /* The location is either no longer present, or got |
12741 | disabled. See if there's another location at the | |
12742 | same address, in which case we don't need to remove | |
12743 | this one from the target. */ | |
876fa593 | 12744 | |
2bdf28a0 | 12745 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12746 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12747 | { | |
876fa593 | 12748 | for (loc2p = locp; |
c7d46a38 PA |
12749 | (loc2p < bp_location + bp_location_count |
12750 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12751 | loc2p++) |
12752 | { | |
12753 | struct bp_location *loc2 = *loc2p; | |
12754 | ||
2d134ed3 | 12755 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12756 | { |
85d721b8 PA |
12757 | /* Read watchpoint locations are switched to |
12758 | access watchpoints, if the former are not | |
12759 | supported, but the latter are. */ | |
12760 | if (is_hardware_watchpoint (old_loc->owner)) | |
12761 | { | |
12762 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12763 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12764 | } | |
12765 | ||
934709f0 PW |
12766 | /* loc2 is a duplicated location. We need to check |
12767 | if it should be inserted in case it will be | |
12768 | unduplicated. */ | |
12769 | if (loc2 != old_loc | |
12770 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12771 | { |
934709f0 | 12772 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12773 | keep_in_target = 1; |
12774 | break; | |
12775 | } | |
876fa593 JK |
12776 | } |
12777 | } | |
12778 | } | |
74960c60 VP |
12779 | } |
12780 | ||
20874c92 VP |
12781 | if (!keep_in_target) |
12782 | { | |
876fa593 | 12783 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12784 | { |
4a64f543 MS |
12785 | /* This is just about all we can do. We could keep |
12786 | this location on the global list, and try to | |
12787 | remove it next time, but there's no particular | |
12788 | reason why we will succeed next time. | |
20874c92 | 12789 | |
4a64f543 MS |
12790 | Note that at this point, old_loc->owner is still |
12791 | valid, as delete_breakpoint frees the breakpoint | |
12792 | only after calling us. */ | |
3e43a32a MS |
12793 | printf_filtered (_("warning: Error removing " |
12794 | "breakpoint %d\n"), | |
876fa593 | 12795 | old_loc->owner->number); |
20874c92 VP |
12796 | } |
12797 | removed = 1; | |
12798 | } | |
0d381245 | 12799 | } |
74960c60 VP |
12800 | |
12801 | if (!found_object) | |
1c5cfe86 | 12802 | { |
db82e815 PA |
12803 | if (removed && non_stop |
12804 | && breakpoint_address_is_meaningful (old_loc->owner) | |
12805 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 12806 | { |
db82e815 PA |
12807 | /* This location was removed from the target. In |
12808 | non-stop mode, a race condition is possible where | |
12809 | we've removed a breakpoint, but stop events for that | |
12810 | breakpoint are already queued and will arrive later. | |
12811 | We apply an heuristic to be able to distinguish such | |
12812 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12813 | breakpoint location for a bit, and will retire it | |
12814 | after we see some number of events. The theory here | |
12815 | is that reporting of events should, "on the average", | |
12816 | be fair, so after a while we'll see events from all | |
12817 | threads that have anything of interest, and no longer | |
12818 | need to keep this breakpoint location around. We | |
12819 | don't hold locations forever so to reduce chances of | |
12820 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12821 | SIGTRAP. | |
12822 | ||
12823 | The heuristic failing can be disastrous on | |
12824 | decr_pc_after_break targets. | |
12825 | ||
12826 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12827 | if we fail to recognize a late breakpoint SIGTRAP, | |
12828 | because events_till_retirement has reached 0 too | |
12829 | soon, we'll fail to do the PC adjustment, and report | |
12830 | a random SIGTRAP to the user. When the user resumes | |
12831 | the inferior, it will most likely immediately crash | |
2dec564e | 12832 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12833 | corrupted, because of being resumed e.g., in the |
12834 | middle of a multi-byte instruction, or skipped a | |
12835 | one-byte instruction. This was actually seen happen | |
12836 | on native x86-linux, and should be less rare on | |
12837 | targets that do not support new thread events, like | |
12838 | remote, due to the heuristic depending on | |
12839 | thread_count. | |
12840 | ||
12841 | Mistaking a random SIGTRAP for a breakpoint trap | |
12842 | causes similar symptoms (PC adjustment applied when | |
12843 | it shouldn't), but then again, playing with SIGTRAPs | |
12844 | behind the debugger's back is asking for trouble. | |
12845 | ||
12846 | Since hardware watchpoint traps are always | |
12847 | distinguishable from other traps, so we don't need to | |
12848 | apply keep hardware watchpoint moribund locations | |
12849 | around. We simply always ignore hardware watchpoint | |
12850 | traps we can no longer explain. */ | |
12851 | ||
876fa593 JK |
12852 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12853 | old_loc->owner = NULL; | |
20874c92 | 12854 | |
876fa593 | 12855 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12856 | } |
12857 | else | |
f431efe5 PA |
12858 | { |
12859 | old_loc->owner = NULL; | |
12860 | decref_bp_location (&old_loc); | |
12861 | } | |
20874c92 | 12862 | } |
74960c60 | 12863 | } |
1c5cfe86 | 12864 | |
348d480f PA |
12865 | /* Rescan breakpoints at the same address and section, marking the |
12866 | first one as "first" and any others as "duplicates". This is so | |
12867 | that the bpt instruction is only inserted once. If we have a | |
12868 | permanent breakpoint at the same place as BPT, make that one the | |
12869 | official one, and the rest as duplicates. Permanent breakpoints | |
12870 | are sorted first for the same address. | |
12871 | ||
12872 | Do the same for hardware watchpoints, but also considering the | |
12873 | watchpoint's type (regular/access/read) and length. */ | |
12874 | ||
12875 | bp_loc_first = NULL; | |
12876 | wp_loc_first = NULL; | |
12877 | awp_loc_first = NULL; | |
12878 | rwp_loc_first = NULL; | |
12879 | ALL_BP_LOCATIONS (loc, locp) | |
12880 | { | |
12881 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12882 | non-NULL. */ | |
348d480f | 12883 | struct bp_location **loc_first_p; |
d3fbdd86 | 12884 | b = loc->owner; |
348d480f | 12885 | |
6f380991 | 12886 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12887 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12888 | /* Don't detect duplicate for tracepoint locations because they are |
12889 | never duplicated. See the comments in field `duplicate' of | |
12890 | `struct bp_location'. */ | |
348d480f | 12891 | || is_tracepoint (b)) |
b775012e LM |
12892 | { |
12893 | /* Clear the condition modification flag. */ | |
12894 | loc->condition_changed = condition_unchanged; | |
12895 | continue; | |
12896 | } | |
348d480f PA |
12897 | |
12898 | /* Permanent breakpoint should always be inserted. */ | |
1a853c52 | 12899 | if (loc->permanent && ! loc->inserted) |
348d480f PA |
12900 | internal_error (__FILE__, __LINE__, |
12901 | _("allegedly permanent breakpoint is not " | |
12902 | "actually inserted")); | |
12903 | ||
12904 | if (b->type == bp_hardware_watchpoint) | |
12905 | loc_first_p = &wp_loc_first; | |
12906 | else if (b->type == bp_read_watchpoint) | |
12907 | loc_first_p = &rwp_loc_first; | |
12908 | else if (b->type == bp_access_watchpoint) | |
12909 | loc_first_p = &awp_loc_first; | |
12910 | else | |
12911 | loc_first_p = &bp_loc_first; | |
12912 | ||
12913 | if (*loc_first_p == NULL | |
12914 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12915 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12916 | { | |
12917 | *loc_first_p = loc; | |
12918 | loc->duplicate = 0; | |
b775012e LM |
12919 | |
12920 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12921 | { | |
12922 | loc->needs_update = 1; | |
12923 | /* Clear the condition modification flag. */ | |
12924 | loc->condition_changed = condition_unchanged; | |
12925 | } | |
348d480f PA |
12926 | continue; |
12927 | } | |
12928 | ||
934709f0 PW |
12929 | |
12930 | /* This and the above ensure the invariant that the first location | |
12931 | is not duplicated, and is the inserted one. | |
12932 | All following are marked as duplicated, and are not inserted. */ | |
12933 | if (loc->inserted) | |
12934 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12935 | loc->duplicate = 1; |
12936 | ||
b775012e LM |
12937 | /* Clear the condition modification flag. */ |
12938 | loc->condition_changed = condition_unchanged; | |
12939 | ||
1a853c52 PA |
12940 | if (loc->inserted && !loc->permanent |
12941 | && (*loc_first_p)->permanent) | |
348d480f PA |
12942 | internal_error (__FILE__, __LINE__, |
12943 | _("another breakpoint was inserted on top of " | |
12944 | "a permanent breakpoint")); | |
12945 | } | |
12946 | ||
a25a5a45 | 12947 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12948 | { |
04086b45 | 12949 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12950 | insert_breakpoint_locations (); |
12951 | else | |
12952 | { | |
44702360 PA |
12953 | /* Even though the caller told us to not insert new |
12954 | locations, we may still need to update conditions on the | |
12955 | target's side of breakpoints that were already inserted | |
12956 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12957 | only update conditions for locations that are marked |
12958 | "needs_update". */ | |
12959 | update_inserted_breakpoint_locations (); | |
12960 | } | |
12961 | } | |
348d480f | 12962 | |
04086b45 | 12963 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12964 | download_tracepoint_locations (); |
12965 | ||
348d480f PA |
12966 | do_cleanups (cleanups); |
12967 | } | |
12968 | ||
12969 | void | |
12970 | breakpoint_retire_moribund (void) | |
12971 | { | |
12972 | struct bp_location *loc; | |
12973 | int ix; | |
12974 | ||
12975 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12976 | if (--(loc->events_till_retirement) == 0) | |
12977 | { | |
12978 | decref_bp_location (&loc); | |
12979 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12980 | --ix; | |
12981 | } | |
12982 | } | |
12983 | ||
12984 | static void | |
44702360 | 12985 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12986 | { |
bfd189b1 | 12987 | volatile struct gdb_exception e; |
348d480f PA |
12988 | |
12989 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
44702360 | 12990 | update_global_location_list (insert_mode); |
348d480f PA |
12991 | } |
12992 | ||
12993 | /* Clear BKP from a BPS. */ | |
12994 | ||
12995 | static void | |
12996 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12997 | { | |
12998 | bpstat bs; | |
12999 | ||
13000 | for (bs = bps; bs; bs = bs->next) | |
13001 | if (bs->breakpoint_at == bpt) | |
13002 | { | |
13003 | bs->breakpoint_at = NULL; | |
13004 | bs->old_val = NULL; | |
13005 | /* bs->commands will be freed later. */ | |
13006 | } | |
13007 | } | |
13008 | ||
13009 | /* Callback for iterate_over_threads. */ | |
13010 | static int | |
13011 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
13012 | { | |
13013 | struct breakpoint *bpt = data; | |
13014 | ||
13015 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
13016 | return 0; | |
13017 | } | |
13018 | ||
13019 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
13020 | callbacks. */ | |
13021 | ||
13022 | static void | |
13023 | say_where (struct breakpoint *b) | |
13024 | { | |
13025 | struct value_print_options opts; | |
13026 | ||
13027 | get_user_print_options (&opts); | |
13028 | ||
13029 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
13030 | single string. */ | |
13031 | if (b->loc == NULL) | |
13032 | { | |
13033 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
13034 | } | |
13035 | else | |
13036 | { | |
2f202fde | 13037 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
13038 | { |
13039 | printf_filtered (" at "); | |
13040 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
13041 | gdb_stdout); | |
13042 | } | |
2f202fde | 13043 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
13044 | { |
13045 | /* If there is a single location, we can print the location | |
13046 | more nicely. */ | |
13047 | if (b->loc->next == NULL) | |
13048 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
13049 | symtab_to_filename_for_display (b->loc->symtab), |
13050 | b->loc->line_number); | |
f8eba3c6 TT |
13051 | else |
13052 | /* This is not ideal, but each location may have a | |
13053 | different file name, and this at least reflects the | |
13054 | real situation somewhat. */ | |
13055 | printf_filtered (": %s.", b->addr_string); | |
13056 | } | |
348d480f PA |
13057 | |
13058 | if (b->loc->next) | |
13059 | { | |
13060 | struct bp_location *loc = b->loc; | |
13061 | int n = 0; | |
13062 | for (; loc; loc = loc->next) | |
13063 | ++n; | |
13064 | printf_filtered (" (%d locations)", n); | |
13065 | } | |
13066 | } | |
13067 | } | |
13068 | ||
348d480f PA |
13069 | /* Default bp_location_ops methods. */ |
13070 | ||
13071 | static void | |
13072 | bp_location_dtor (struct bp_location *self) | |
13073 | { | |
13074 | xfree (self->cond); | |
b775012e LM |
13075 | if (self->cond_bytecode) |
13076 | free_agent_expr (self->cond_bytecode); | |
348d480f | 13077 | xfree (self->function_name); |
8b4f3082 PA |
13078 | |
13079 | VEC_free (agent_expr_p, self->target_info.conditions); | |
13080 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
13081 | } |
13082 | ||
13083 | static const struct bp_location_ops bp_location_ops = | |
13084 | { | |
13085 | bp_location_dtor | |
13086 | }; | |
13087 | ||
2060206e PA |
13088 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
13089 | inherit from. */ | |
348d480f | 13090 | |
2060206e PA |
13091 | static void |
13092 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
13093 | { |
13094 | decref_counted_command_line (&self->commands); | |
13095 | xfree (self->cond_string); | |
fb81d016 | 13096 | xfree (self->extra_string); |
348d480f | 13097 | xfree (self->addr_string); |
f8eba3c6 | 13098 | xfree (self->filter); |
348d480f | 13099 | xfree (self->addr_string_range_end); |
348d480f PA |
13100 | } |
13101 | ||
2060206e PA |
13102 | static struct bp_location * |
13103 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
13104 | { |
13105 | struct bp_location *loc; | |
13106 | ||
13107 | loc = XNEW (struct bp_location); | |
13108 | init_bp_location (loc, &bp_location_ops, self); | |
13109 | return loc; | |
13110 | } | |
13111 | ||
2060206e PA |
13112 | static void |
13113 | base_breakpoint_re_set (struct breakpoint *b) | |
13114 | { | |
13115 | /* Nothing to re-set. */ | |
13116 | } | |
13117 | ||
13118 | #define internal_error_pure_virtual_called() \ | |
13119 | gdb_assert_not_reached ("pure virtual function called") | |
13120 | ||
13121 | static int | |
13122 | base_breakpoint_insert_location (struct bp_location *bl) | |
13123 | { | |
13124 | internal_error_pure_virtual_called (); | |
13125 | } | |
13126 | ||
13127 | static int | |
13128 | base_breakpoint_remove_location (struct bp_location *bl) | |
13129 | { | |
13130 | internal_error_pure_virtual_called (); | |
13131 | } | |
13132 | ||
13133 | static int | |
13134 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
13135 | struct address_space *aspace, | |
09ac7c10 TT |
13136 | CORE_ADDR bp_addr, |
13137 | const struct target_waitstatus *ws) | |
2060206e PA |
13138 | { |
13139 | internal_error_pure_virtual_called (); | |
13140 | } | |
13141 | ||
13142 | static void | |
13143 | base_breakpoint_check_status (bpstat bs) | |
13144 | { | |
13145 | /* Always stop. */ | |
13146 | } | |
13147 | ||
13148 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
13149 | errors. */ | |
13150 | ||
13151 | static int | |
13152 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
13153 | { | |
13154 | internal_error_pure_virtual_called (); | |
13155 | } | |
13156 | ||
13157 | /* A "resources_needed" breakpoint_ops method that just internal | |
13158 | errors. */ | |
13159 | ||
13160 | static int | |
13161 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
13162 | { | |
13163 | internal_error_pure_virtual_called (); | |
13164 | } | |
13165 | ||
13166 | static enum print_stop_action | |
13167 | base_breakpoint_print_it (bpstat bs) | |
13168 | { | |
13169 | internal_error_pure_virtual_called (); | |
13170 | } | |
13171 | ||
13172 | static void | |
13173 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
13174 | struct ui_out *uiout) | |
13175 | { | |
13176 | /* nothing */ | |
13177 | } | |
13178 | ||
13179 | static void | |
13180 | base_breakpoint_print_mention (struct breakpoint *b) | |
13181 | { | |
13182 | internal_error_pure_virtual_called (); | |
13183 | } | |
13184 | ||
13185 | static void | |
13186 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
13187 | { | |
13188 | internal_error_pure_virtual_called (); | |
13189 | } | |
13190 | ||
983af33b SDJ |
13191 | static void |
13192 | base_breakpoint_create_sals_from_address (char **arg, | |
13193 | struct linespec_result *canonical, | |
13194 | enum bptype type_wanted, | |
13195 | char *addr_start, | |
13196 | char **copy_arg) | |
13197 | { | |
13198 | internal_error_pure_virtual_called (); | |
13199 | } | |
13200 | ||
13201 | static void | |
13202 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13203 | struct linespec_result *c, | |
983af33b | 13204 | char *cond_string, |
e7e0cddf | 13205 | char *extra_string, |
983af33b SDJ |
13206 | enum bptype type_wanted, |
13207 | enum bpdisp disposition, | |
13208 | int thread, | |
13209 | int task, int ignore_count, | |
13210 | const struct breakpoint_ops *o, | |
13211 | int from_tty, int enabled, | |
44f238bb | 13212 | int internal, unsigned flags) |
983af33b SDJ |
13213 | { |
13214 | internal_error_pure_virtual_called (); | |
13215 | } | |
13216 | ||
13217 | static void | |
13218 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
13219 | struct symtabs_and_lines *sals) | |
13220 | { | |
13221 | internal_error_pure_virtual_called (); | |
13222 | } | |
13223 | ||
ab04a2af TT |
13224 | /* The default 'explains_signal' method. */ |
13225 | ||
47591c29 | 13226 | static int |
427cd150 | 13227 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 13228 | { |
47591c29 | 13229 | return 1; |
ab04a2af TT |
13230 | } |
13231 | ||
9d6e6e84 HZ |
13232 | /* The default "after_condition_true" method. */ |
13233 | ||
13234 | static void | |
13235 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
13236 | { | |
13237 | /* Nothing to do. */ | |
13238 | } | |
13239 | ||
ab04a2af | 13240 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
13241 | { |
13242 | base_breakpoint_dtor, | |
13243 | base_breakpoint_allocate_location, | |
13244 | base_breakpoint_re_set, | |
13245 | base_breakpoint_insert_location, | |
13246 | base_breakpoint_remove_location, | |
13247 | base_breakpoint_breakpoint_hit, | |
13248 | base_breakpoint_check_status, | |
13249 | base_breakpoint_resources_needed, | |
13250 | base_breakpoint_works_in_software_mode, | |
13251 | base_breakpoint_print_it, | |
13252 | NULL, | |
13253 | base_breakpoint_print_one_detail, | |
13254 | base_breakpoint_print_mention, | |
983af33b SDJ |
13255 | base_breakpoint_print_recreate, |
13256 | base_breakpoint_create_sals_from_address, | |
13257 | base_breakpoint_create_breakpoints_sal, | |
13258 | base_breakpoint_decode_linespec, | |
9d6e6e84 HZ |
13259 | base_breakpoint_explains_signal, |
13260 | base_breakpoint_after_condition_true, | |
2060206e PA |
13261 | }; |
13262 | ||
13263 | /* Default breakpoint_ops methods. */ | |
13264 | ||
13265 | static void | |
348d480f PA |
13266 | bkpt_re_set (struct breakpoint *b) |
13267 | { | |
06edf0c0 PA |
13268 | /* FIXME: is this still reachable? */ |
13269 | if (b->addr_string == NULL) | |
13270 | { | |
13271 | /* Anything without a string can't be re-set. */ | |
348d480f | 13272 | delete_breakpoint (b); |
06edf0c0 | 13273 | return; |
348d480f | 13274 | } |
06edf0c0 PA |
13275 | |
13276 | breakpoint_re_set_default (b); | |
348d480f PA |
13277 | } |
13278 | ||
2060206e | 13279 | static int |
348d480f PA |
13280 | bkpt_insert_location (struct bp_location *bl) |
13281 | { | |
13282 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
7c16b83e | 13283 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 13284 | else |
7c16b83e | 13285 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13286 | } |
13287 | ||
2060206e | 13288 | static int |
348d480f PA |
13289 | bkpt_remove_location (struct bp_location *bl) |
13290 | { | |
13291 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13292 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13293 | else | |
7c16b83e | 13294 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13295 | } |
13296 | ||
2060206e | 13297 | static int |
348d480f | 13298 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13299 | struct address_space *aspace, CORE_ADDR bp_addr, |
13300 | const struct target_waitstatus *ws) | |
348d480f | 13301 | { |
09ac7c10 | 13302 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13303 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13304 | return 0; |
13305 | ||
348d480f PA |
13306 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13307 | aspace, bp_addr)) | |
13308 | return 0; | |
13309 | ||
13310 | if (overlay_debugging /* unmapped overlay section */ | |
13311 | && section_is_overlay (bl->section) | |
13312 | && !section_is_mapped (bl->section)) | |
13313 | return 0; | |
13314 | ||
13315 | return 1; | |
13316 | } | |
13317 | ||
cd1608cc PA |
13318 | static int |
13319 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
13320 | struct address_space *aspace, CORE_ADDR bp_addr, | |
13321 | const struct target_waitstatus *ws) | |
13322 | { | |
13323 | if (dprintf_style == dprintf_style_agent | |
13324 | && target_can_run_breakpoint_commands ()) | |
13325 | { | |
13326 | /* An agent-style dprintf never causes a stop. If we see a trap | |
13327 | for this address it must be for a breakpoint that happens to | |
13328 | be set at the same address. */ | |
13329 | return 0; | |
13330 | } | |
13331 | ||
13332 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
13333 | } | |
13334 | ||
2060206e | 13335 | static int |
348d480f PA |
13336 | bkpt_resources_needed (const struct bp_location *bl) |
13337 | { | |
13338 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13339 | ||
13340 | return 1; | |
13341 | } | |
13342 | ||
2060206e | 13343 | static enum print_stop_action |
348d480f PA |
13344 | bkpt_print_it (bpstat bs) |
13345 | { | |
348d480f PA |
13346 | struct breakpoint *b; |
13347 | const struct bp_location *bl; | |
001c8c33 | 13348 | int bp_temp; |
79a45e25 | 13349 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13350 | |
13351 | gdb_assert (bs->bp_location_at != NULL); | |
13352 | ||
13353 | bl = bs->bp_location_at; | |
13354 | b = bs->breakpoint_at; | |
13355 | ||
001c8c33 PA |
13356 | bp_temp = b->disposition == disp_del; |
13357 | if (bl->address != bl->requested_address) | |
13358 | breakpoint_adjustment_warning (bl->requested_address, | |
13359 | bl->address, | |
13360 | b->number, 1); | |
13361 | annotate_breakpoint (b->number); | |
13362 | if (bp_temp) | |
13363 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
13364 | else | |
13365 | ui_out_text (uiout, "\nBreakpoint "); | |
13366 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 13367 | { |
001c8c33 PA |
13368 | ui_out_field_string (uiout, "reason", |
13369 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13370 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13371 | } |
001c8c33 PA |
13372 | ui_out_field_int (uiout, "bkptno", b->number); |
13373 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13374 | |
001c8c33 | 13375 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13376 | } |
13377 | ||
2060206e | 13378 | static void |
06edf0c0 PA |
13379 | bkpt_print_mention (struct breakpoint *b) |
13380 | { | |
79a45e25 | 13381 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13382 | return; |
13383 | ||
13384 | switch (b->type) | |
13385 | { | |
13386 | case bp_breakpoint: | |
13387 | case bp_gnu_ifunc_resolver: | |
13388 | if (b->disposition == disp_del) | |
13389 | printf_filtered (_("Temporary breakpoint")); | |
13390 | else | |
13391 | printf_filtered (_("Breakpoint")); | |
13392 | printf_filtered (_(" %d"), b->number); | |
13393 | if (b->type == bp_gnu_ifunc_resolver) | |
13394 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13395 | break; | |
13396 | case bp_hardware_breakpoint: | |
13397 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13398 | break; | |
e7e0cddf SS |
13399 | case bp_dprintf: |
13400 | printf_filtered (_("Dprintf %d"), b->number); | |
13401 | break; | |
06edf0c0 PA |
13402 | } |
13403 | ||
13404 | say_where (b); | |
13405 | } | |
13406 | ||
2060206e | 13407 | static void |
06edf0c0 PA |
13408 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13409 | { | |
13410 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13411 | fprintf_unfiltered (fp, "tbreak"); | |
13412 | else if (tp->type == bp_breakpoint) | |
13413 | fprintf_unfiltered (fp, "break"); | |
13414 | else if (tp->type == bp_hardware_breakpoint | |
13415 | && tp->disposition == disp_del) | |
13416 | fprintf_unfiltered (fp, "thbreak"); | |
13417 | else if (tp->type == bp_hardware_breakpoint) | |
13418 | fprintf_unfiltered (fp, "hbreak"); | |
13419 | else | |
13420 | internal_error (__FILE__, __LINE__, | |
13421 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13422 | ||
2060206e | 13423 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 13424 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13425 | } |
13426 | ||
983af33b SDJ |
13427 | static void |
13428 | bkpt_create_sals_from_address (char **arg, | |
13429 | struct linespec_result *canonical, | |
13430 | enum bptype type_wanted, | |
13431 | char *addr_start, char **copy_arg) | |
13432 | { | |
13433 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13434 | addr_start, copy_arg); | |
13435 | } | |
13436 | ||
13437 | static void | |
13438 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13439 | struct linespec_result *canonical, | |
983af33b | 13440 | char *cond_string, |
e7e0cddf | 13441 | char *extra_string, |
983af33b SDJ |
13442 | enum bptype type_wanted, |
13443 | enum bpdisp disposition, | |
13444 | int thread, | |
13445 | int task, int ignore_count, | |
13446 | const struct breakpoint_ops *ops, | |
13447 | int from_tty, int enabled, | |
44f238bb | 13448 | int internal, unsigned flags) |
983af33b | 13449 | { |
023fa29b | 13450 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13451 | cond_string, extra_string, |
13452 | type_wanted, | |
983af33b SDJ |
13453 | disposition, thread, task, |
13454 | ignore_count, ops, from_tty, | |
44f238bb | 13455 | enabled, internal, flags); |
983af33b SDJ |
13456 | } |
13457 | ||
13458 | static void | |
13459 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
13460 | struct symtabs_and_lines *sals) | |
13461 | { | |
13462 | decode_linespec_default (b, s, sals); | |
13463 | } | |
13464 | ||
06edf0c0 PA |
13465 | /* Virtual table for internal breakpoints. */ |
13466 | ||
13467 | static void | |
13468 | internal_bkpt_re_set (struct breakpoint *b) | |
13469 | { | |
13470 | switch (b->type) | |
13471 | { | |
13472 | /* Delete overlay event and longjmp master breakpoints; they | |
13473 | will be reset later by breakpoint_re_set. */ | |
13474 | case bp_overlay_event: | |
13475 | case bp_longjmp_master: | |
13476 | case bp_std_terminate_master: | |
13477 | case bp_exception_master: | |
13478 | delete_breakpoint (b); | |
13479 | break; | |
13480 | ||
13481 | /* This breakpoint is special, it's set up when the inferior | |
13482 | starts and we really don't want to touch it. */ | |
13483 | case bp_shlib_event: | |
13484 | ||
13485 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13486 | it is set up, we do not want to touch it. */ | |
13487 | case bp_thread_event: | |
13488 | break; | |
13489 | } | |
13490 | } | |
13491 | ||
13492 | static void | |
13493 | internal_bkpt_check_status (bpstat bs) | |
13494 | { | |
a9b3a50f PA |
13495 | if (bs->breakpoint_at->type == bp_shlib_event) |
13496 | { | |
13497 | /* If requested, stop when the dynamic linker notifies GDB of | |
13498 | events. This allows the user to get control and place | |
13499 | breakpoints in initializer routines for dynamically loaded | |
13500 | objects (among other things). */ | |
13501 | bs->stop = stop_on_solib_events; | |
13502 | bs->print = stop_on_solib_events; | |
13503 | } | |
13504 | else | |
13505 | bs->stop = 0; | |
06edf0c0 PA |
13506 | } |
13507 | ||
13508 | static enum print_stop_action | |
13509 | internal_bkpt_print_it (bpstat bs) | |
13510 | { | |
06edf0c0 | 13511 | struct breakpoint *b; |
06edf0c0 | 13512 | |
06edf0c0 PA |
13513 | b = bs->breakpoint_at; |
13514 | ||
06edf0c0 PA |
13515 | switch (b->type) |
13516 | { | |
348d480f PA |
13517 | case bp_shlib_event: |
13518 | /* Did we stop because the user set the stop_on_solib_events | |
13519 | variable? (If so, we report this as a generic, "Stopped due | |
13520 | to shlib event" message.) */ | |
edcc5120 | 13521 | print_solib_event (0); |
348d480f PA |
13522 | break; |
13523 | ||
13524 | case bp_thread_event: | |
13525 | /* Not sure how we will get here. | |
13526 | GDB should not stop for these breakpoints. */ | |
13527 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13528 | break; |
13529 | ||
13530 | case bp_overlay_event: | |
13531 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13532 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13533 | break; |
13534 | ||
13535 | case bp_longjmp_master: | |
13536 | /* These should never be enabled. */ | |
13537 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13538 | break; |
13539 | ||
13540 | case bp_std_terminate_master: | |
13541 | /* These should never be enabled. */ | |
13542 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13543 | "gdb should not stop!\n")); | |
348d480f PA |
13544 | break; |
13545 | ||
13546 | case bp_exception_master: | |
13547 | /* These should never be enabled. */ | |
13548 | printf_filtered (_("Exception Master Breakpoint: " | |
13549 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13550 | break; |
13551 | } | |
13552 | ||
001c8c33 | 13553 | return PRINT_NOTHING; |
06edf0c0 PA |
13554 | } |
13555 | ||
13556 | static void | |
13557 | internal_bkpt_print_mention (struct breakpoint *b) | |
13558 | { | |
13559 | /* Nothing to mention. These breakpoints are internal. */ | |
13560 | } | |
13561 | ||
06edf0c0 PA |
13562 | /* Virtual table for momentary breakpoints */ |
13563 | ||
13564 | static void | |
13565 | momentary_bkpt_re_set (struct breakpoint *b) | |
13566 | { | |
13567 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13568 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13569 | Otherwise these should have been blown away via the cleanup chain |
13570 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13571 | } | |
13572 | ||
13573 | static void | |
13574 | momentary_bkpt_check_status (bpstat bs) | |
13575 | { | |
13576 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13577 | } | |
13578 | ||
13579 | static enum print_stop_action | |
13580 | momentary_bkpt_print_it (bpstat bs) | |
13581 | { | |
79a45e25 PA |
13582 | struct ui_out *uiout = current_uiout; |
13583 | ||
001c8c33 | 13584 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 13585 | { |
001c8c33 | 13586 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 13587 | |
001c8c33 PA |
13588 | switch (b->type) |
13589 | { | |
13590 | case bp_finish: | |
13591 | ui_out_field_string | |
13592 | (uiout, "reason", | |
13593 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
13594 | break; | |
348d480f | 13595 | |
001c8c33 PA |
13596 | case bp_until: |
13597 | ui_out_field_string | |
13598 | (uiout, "reason", | |
13599 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
13600 | break; | |
13601 | } | |
348d480f PA |
13602 | } |
13603 | ||
001c8c33 | 13604 | return PRINT_UNKNOWN; |
348d480f PA |
13605 | } |
13606 | ||
06edf0c0 PA |
13607 | static void |
13608 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13609 | { |
06edf0c0 | 13610 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13611 | } |
13612 | ||
e2e4d78b JK |
13613 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13614 | ||
13615 | It gets cleared already on the removal of the first one of such placed | |
13616 | breakpoints. This is OK as they get all removed altogether. */ | |
13617 | ||
13618 | static void | |
13619 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13620 | { | |
13621 | struct thread_info *tp = find_thread_id (self->thread); | |
13622 | ||
13623 | if (tp) | |
13624 | tp->initiating_frame = null_frame_id; | |
13625 | ||
13626 | momentary_breakpoint_ops.dtor (self); | |
13627 | } | |
13628 | ||
55aa24fb SDJ |
13629 | /* Specific methods for probe breakpoints. */ |
13630 | ||
13631 | static int | |
13632 | bkpt_probe_insert_location (struct bp_location *bl) | |
13633 | { | |
13634 | int v = bkpt_insert_location (bl); | |
13635 | ||
13636 | if (v == 0) | |
13637 | { | |
13638 | /* The insertion was successful, now let's set the probe's semaphore | |
13639 | if needed. */ | |
0ea5cda8 SDJ |
13640 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13641 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13642 | bl->probe.objfile, | |
13643 | bl->gdbarch); | |
55aa24fb SDJ |
13644 | } |
13645 | ||
13646 | return v; | |
13647 | } | |
13648 | ||
13649 | static int | |
13650 | bkpt_probe_remove_location (struct bp_location *bl) | |
13651 | { | |
13652 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13653 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13654 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13655 | bl->probe.objfile, | |
13656 | bl->gdbarch); | |
55aa24fb SDJ |
13657 | |
13658 | return bkpt_remove_location (bl); | |
13659 | } | |
13660 | ||
13661 | static void | |
13662 | bkpt_probe_create_sals_from_address (char **arg, | |
13663 | struct linespec_result *canonical, | |
13664 | enum bptype type_wanted, | |
13665 | char *addr_start, char **copy_arg) | |
13666 | { | |
13667 | struct linespec_sals lsal; | |
13668 | ||
13669 | lsal.sals = parse_probes (arg, canonical); | |
13670 | ||
13671 | *copy_arg = xstrdup (canonical->addr_string); | |
13672 | lsal.canonical = xstrdup (*copy_arg); | |
13673 | ||
13674 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13675 | } | |
13676 | ||
13677 | static void | |
13678 | bkpt_probe_decode_linespec (struct breakpoint *b, char **s, | |
13679 | struct symtabs_and_lines *sals) | |
13680 | { | |
13681 | *sals = parse_probes (s, NULL); | |
13682 | if (!sals->sals) | |
13683 | error (_("probe not found")); | |
13684 | } | |
13685 | ||
348d480f | 13686 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13687 | |
348d480f PA |
13688 | static void |
13689 | tracepoint_re_set (struct breakpoint *b) | |
13690 | { | |
13691 | breakpoint_re_set_default (b); | |
13692 | } | |
876fa593 | 13693 | |
348d480f PA |
13694 | static int |
13695 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13696 | struct address_space *aspace, CORE_ADDR bp_addr, |
13697 | const struct target_waitstatus *ws) | |
348d480f PA |
13698 | { |
13699 | /* By definition, the inferior does not report stops at | |
13700 | tracepoints. */ | |
13701 | return 0; | |
74960c60 VP |
13702 | } |
13703 | ||
13704 | static void | |
348d480f PA |
13705 | tracepoint_print_one_detail (const struct breakpoint *self, |
13706 | struct ui_out *uiout) | |
74960c60 | 13707 | { |
d9b3f62e PA |
13708 | struct tracepoint *tp = (struct tracepoint *) self; |
13709 | if (tp->static_trace_marker_id) | |
348d480f PA |
13710 | { |
13711 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13712 | |
348d480f PA |
13713 | ui_out_text (uiout, "\tmarker id is "); |
13714 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13715 | tp->static_trace_marker_id); |
348d480f PA |
13716 | ui_out_text (uiout, "\n"); |
13717 | } | |
0d381245 VP |
13718 | } |
13719 | ||
a474d7c2 | 13720 | static void |
348d480f | 13721 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13722 | { |
79a45e25 | 13723 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13724 | return; |
cc59ec59 | 13725 | |
348d480f PA |
13726 | switch (b->type) |
13727 | { | |
13728 | case bp_tracepoint: | |
13729 | printf_filtered (_("Tracepoint")); | |
13730 | printf_filtered (_(" %d"), b->number); | |
13731 | break; | |
13732 | case bp_fast_tracepoint: | |
13733 | printf_filtered (_("Fast tracepoint")); | |
13734 | printf_filtered (_(" %d"), b->number); | |
13735 | break; | |
13736 | case bp_static_tracepoint: | |
13737 | printf_filtered (_("Static tracepoint")); | |
13738 | printf_filtered (_(" %d"), b->number); | |
13739 | break; | |
13740 | default: | |
13741 | internal_error (__FILE__, __LINE__, | |
13742 | _("unhandled tracepoint type %d"), (int) b->type); | |
13743 | } | |
13744 | ||
13745 | say_where (b); | |
a474d7c2 PA |
13746 | } |
13747 | ||
348d480f | 13748 | static void |
d9b3f62e | 13749 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13750 | { |
d9b3f62e PA |
13751 | struct tracepoint *tp = (struct tracepoint *) self; |
13752 | ||
13753 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13754 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13755 | if (self->type == bp_static_tracepoint) |
348d480f | 13756 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13757 | else if (self->type == bp_tracepoint) |
348d480f PA |
13758 | fprintf_unfiltered (fp, "trace"); |
13759 | else | |
13760 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13761 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13762 | |
d9b3f62e PA |
13763 | fprintf_unfiltered (fp, " %s", self->addr_string); |
13764 | print_recreate_thread (self, fp); | |
13765 | ||
13766 | if (tp->pass_count) | |
13767 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13768 | } |
13769 | ||
983af33b SDJ |
13770 | static void |
13771 | tracepoint_create_sals_from_address (char **arg, | |
13772 | struct linespec_result *canonical, | |
13773 | enum bptype type_wanted, | |
13774 | char *addr_start, char **copy_arg) | |
13775 | { | |
13776 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13777 | addr_start, copy_arg); | |
13778 | } | |
13779 | ||
13780 | static void | |
13781 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13782 | struct linespec_result *canonical, | |
983af33b | 13783 | char *cond_string, |
e7e0cddf | 13784 | char *extra_string, |
983af33b SDJ |
13785 | enum bptype type_wanted, |
13786 | enum bpdisp disposition, | |
13787 | int thread, | |
13788 | int task, int ignore_count, | |
13789 | const struct breakpoint_ops *ops, | |
13790 | int from_tty, int enabled, | |
44f238bb | 13791 | int internal, unsigned flags) |
983af33b | 13792 | { |
023fa29b | 13793 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13794 | cond_string, extra_string, |
13795 | type_wanted, | |
983af33b SDJ |
13796 | disposition, thread, task, |
13797 | ignore_count, ops, from_tty, | |
44f238bb | 13798 | enabled, internal, flags); |
983af33b SDJ |
13799 | } |
13800 | ||
13801 | static void | |
13802 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
13803 | struct symtabs_and_lines *sals) | |
13804 | { | |
13805 | decode_linespec_default (b, s, sals); | |
13806 | } | |
13807 | ||
2060206e | 13808 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13809 | |
55aa24fb SDJ |
13810 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13811 | static probe. */ | |
13812 | ||
13813 | static void | |
13814 | tracepoint_probe_create_sals_from_address (char **arg, | |
13815 | struct linespec_result *canonical, | |
13816 | enum bptype type_wanted, | |
13817 | char *addr_start, char **copy_arg) | |
13818 | { | |
13819 | /* We use the same method for breakpoint on probes. */ | |
13820 | bkpt_probe_create_sals_from_address (arg, canonical, type_wanted, | |
13821 | addr_start, copy_arg); | |
13822 | } | |
13823 | ||
13824 | static void | |
13825 | tracepoint_probe_decode_linespec (struct breakpoint *b, char **s, | |
13826 | struct symtabs_and_lines *sals) | |
13827 | { | |
13828 | /* We use the same method for breakpoint on probes. */ | |
13829 | bkpt_probe_decode_linespec (b, s, sals); | |
13830 | } | |
13831 | ||
13832 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13833 | ||
5c2b4418 HZ |
13834 | /* Dprintf breakpoint_ops methods. */ |
13835 | ||
13836 | static void | |
13837 | dprintf_re_set (struct breakpoint *b) | |
13838 | { | |
13839 | breakpoint_re_set_default (b); | |
13840 | ||
13841 | /* This breakpoint could have been pending, and be resolved now, and | |
13842 | if so, we should now have the extra string. If we don't, the | |
13843 | dprintf was malformed when created, but we couldn't tell because | |
13844 | we can't extract the extra string until the location is | |
13845 | resolved. */ | |
13846 | if (b->loc != NULL && b->extra_string == NULL) | |
13847 | error (_("Format string required")); | |
13848 | ||
13849 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13850 | 2 - create a dprintf, which resolves fine. | |
13851 | 3 - disconnect from target 1 | |
13852 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13853 | ||
13854 | After steps #3/#4, you'll want the dprintf command list to | |
13855 | be updated, because target 1 and 2 may well return different | |
13856 | answers for target_can_run_breakpoint_commands(). | |
13857 | Given absence of finer grained resetting, we get to do | |
13858 | it all the time. */ | |
13859 | if (b->extra_string != NULL) | |
13860 | update_dprintf_command_list (b); | |
13861 | } | |
13862 | ||
2d9442cc HZ |
13863 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13864 | ||
13865 | static void | |
13866 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13867 | { | |
13868 | fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string, | |
13869 | tp->extra_string); | |
13870 | print_recreate_thread (tp, fp); | |
13871 | } | |
13872 | ||
9d6e6e84 HZ |
13873 | /* Implement the "after_condition_true" breakpoint_ops method for |
13874 | dprintf. | |
13875 | ||
13876 | dprintf's are implemented with regular commands in their command | |
13877 | list, but we run the commands here instead of before presenting the | |
13878 | stop to the user, as dprintf's don't actually cause a stop. This | |
13879 | also makes it so that the commands of multiple dprintfs at the same | |
13880 | address are all handled. */ | |
13881 | ||
13882 | static void | |
13883 | dprintf_after_condition_true (struct bpstats *bs) | |
13884 | { | |
13885 | struct cleanup *old_chain; | |
13886 | struct bpstats tmp_bs = { NULL }; | |
13887 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13888 | ||
13889 | /* dprintf's never cause a stop. This wasn't set in the | |
13890 | check_status hook instead because that would make the dprintf's | |
13891 | condition not be evaluated. */ | |
13892 | bs->stop = 0; | |
13893 | ||
13894 | /* Run the command list here. Take ownership of it instead of | |
13895 | copying. We never want these commands to run later in | |
13896 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13897 | be set at same address as this dprintf, or even if running the | |
13898 | commands here throws. */ | |
13899 | tmp_bs.commands = bs->commands; | |
13900 | bs->commands = NULL; | |
13901 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13902 | ||
13903 | bpstat_do_actions_1 (&tmp_bs_p); | |
13904 | ||
13905 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13906 | bpstat_do_actions_1 may return early without processing the whole | |
13907 | list. */ | |
13908 | do_cleanups (old_chain); | |
13909 | } | |
13910 | ||
983af33b SDJ |
13911 | /* The breakpoint_ops structure to be used on static tracepoints with |
13912 | markers (`-m'). */ | |
13913 | ||
13914 | static void | |
13915 | strace_marker_create_sals_from_address (char **arg, | |
13916 | struct linespec_result *canonical, | |
13917 | enum bptype type_wanted, | |
13918 | char *addr_start, char **copy_arg) | |
13919 | { | |
13920 | struct linespec_sals lsal; | |
13921 | ||
13922 | lsal.sals = decode_static_tracepoint_spec (arg); | |
13923 | ||
13924 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
13925 | ||
13926 | canonical->addr_string = xstrdup (*copy_arg); | |
13927 | lsal.canonical = xstrdup (*copy_arg); | |
13928 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13929 | } | |
13930 | ||
13931 | static void | |
13932 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13933 | struct linespec_result *canonical, | |
983af33b | 13934 | char *cond_string, |
e7e0cddf | 13935 | char *extra_string, |
983af33b SDJ |
13936 | enum bptype type_wanted, |
13937 | enum bpdisp disposition, | |
13938 | int thread, | |
13939 | int task, int ignore_count, | |
13940 | const struct breakpoint_ops *ops, | |
13941 | int from_tty, int enabled, | |
44f238bb | 13942 | int internal, unsigned flags) |
983af33b SDJ |
13943 | { |
13944 | int i; | |
52d361e1 YQ |
13945 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13946 | canonical->sals, 0); | |
983af33b SDJ |
13947 | |
13948 | /* If the user is creating a static tracepoint by marker id | |
13949 | (strace -m MARKER_ID), then store the sals index, so that | |
13950 | breakpoint_re_set can try to match up which of the newly | |
13951 | found markers corresponds to this one, and, don't try to | |
13952 | expand multiple locations for each sal, given than SALS | |
13953 | already should contain all sals for MARKER_ID. */ | |
13954 | ||
13955 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13956 | { | |
13957 | struct symtabs_and_lines expanded; | |
13958 | struct tracepoint *tp; | |
13959 | struct cleanup *old_chain; | |
13960 | char *addr_string; | |
13961 | ||
13962 | expanded.nelts = 1; | |
13963 | expanded.sals = &lsal->sals.sals[i]; | |
13964 | ||
13965 | addr_string = xstrdup (canonical->addr_string); | |
13966 | old_chain = make_cleanup (xfree, addr_string); | |
13967 | ||
13968 | tp = XCNEW (struct tracepoint); | |
13969 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
13970 | addr_string, NULL, | |
e7e0cddf SS |
13971 | cond_string, extra_string, |
13972 | type_wanted, disposition, | |
983af33b | 13973 | thread, task, ignore_count, ops, |
44f238bb | 13974 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13975 | canonical->special_display); |
13976 | /* Given that its possible to have multiple markers with | |
13977 | the same string id, if the user is creating a static | |
13978 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13979 | store the sals index, so that breakpoint_re_set can | |
13980 | try to match up which of the newly found markers | |
13981 | corresponds to this one */ | |
13982 | tp->static_trace_marker_id_idx = i; | |
13983 | ||
13984 | install_breakpoint (internal, &tp->base, 0); | |
13985 | ||
13986 | discard_cleanups (old_chain); | |
13987 | } | |
13988 | } | |
13989 | ||
13990 | static void | |
13991 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
13992 | struct symtabs_and_lines *sals) | |
13993 | { | |
13994 | struct tracepoint *tp = (struct tracepoint *) b; | |
13995 | ||
13996 | *sals = decode_static_tracepoint_spec (s); | |
13997 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
13998 | { | |
13999 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
14000 | sals->nelts = 1; | |
14001 | } | |
14002 | else | |
14003 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
14004 | } | |
14005 | ||
14006 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
14007 | ||
14008 | static int | |
14009 | strace_marker_p (struct breakpoint *b) | |
14010 | { | |
14011 | return b->ops == &strace_marker_breakpoint_ops; | |
14012 | } | |
14013 | ||
53a5351d | 14014 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 14015 | structures. */ |
c906108c SS |
14016 | |
14017 | void | |
fba45db2 | 14018 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 14019 | { |
52f0bd74 | 14020 | struct breakpoint *b; |
c906108c | 14021 | |
8a3fe4f8 | 14022 | gdb_assert (bpt != NULL); |
c906108c | 14023 | |
4a64f543 MS |
14024 | /* Has this bp already been deleted? This can happen because |
14025 | multiple lists can hold pointers to bp's. bpstat lists are | |
14026 | especial culprits. | |
14027 | ||
14028 | One example of this happening is a watchpoint's scope bp. When | |
14029 | the scope bp triggers, we notice that the watchpoint is out of | |
14030 | scope, and delete it. We also delete its scope bp. But the | |
14031 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
14032 | That bpstat is then checked for auto-deleting bp's, which are | |
14033 | deleted. | |
14034 | ||
14035 | A real solution to this problem might involve reference counts in | |
14036 | bp's, and/or giving them pointers back to their referencing | |
14037 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
14038 | storage when no more references were extent. A cheaper bandaid | |
14039 | was chosen. */ | |
c906108c SS |
14040 | if (bpt->type == bp_none) |
14041 | return; | |
14042 | ||
4a64f543 MS |
14043 | /* At least avoid this stale reference until the reference counting |
14044 | of breakpoints gets resolved. */ | |
d0fb5eae | 14045 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 14046 | { |
d0fb5eae | 14047 | struct breakpoint *related; |
3a5c3e22 | 14048 | struct watchpoint *w; |
d0fb5eae JK |
14049 | |
14050 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 14051 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 14052 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
14053 | w = (struct watchpoint *) bpt; |
14054 | else | |
14055 | w = NULL; | |
14056 | if (w != NULL) | |
14057 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
14058 | |
14059 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
14060 | for (related = bpt; related->related_breakpoint != bpt; | |
14061 | related = related->related_breakpoint); | |
14062 | related->related_breakpoint = bpt->related_breakpoint; | |
14063 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
14064 | } |
14065 | ||
a9634178 TJB |
14066 | /* watch_command_1 creates a watchpoint but only sets its number if |
14067 | update_watchpoint succeeds in creating its bp_locations. If there's | |
14068 | a problem in that process, we'll be asked to delete the half-created | |
14069 | watchpoint. In that case, don't announce the deletion. */ | |
14070 | if (bpt->number) | |
14071 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 14072 | |
c906108c SS |
14073 | if (breakpoint_chain == bpt) |
14074 | breakpoint_chain = bpt->next; | |
14075 | ||
c906108c SS |
14076 | ALL_BREAKPOINTS (b) |
14077 | if (b->next == bpt) | |
c5aa993b JM |
14078 | { |
14079 | b->next = bpt->next; | |
14080 | break; | |
14081 | } | |
c906108c | 14082 | |
f431efe5 PA |
14083 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
14084 | been freed. */ | |
14085 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 14086 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
14087 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
14088 | commands are associated with the bpstat; if we remove it here, | |
14089 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
14090 | event-top.c won't do anything, and temporary breakpoints with | |
14091 | commands won't work. */ | |
14092 | ||
14093 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
14094 | ||
4a64f543 MS |
14095 | /* Now that breakpoint is removed from breakpoint list, update the |
14096 | global location list. This will remove locations that used to | |
14097 | belong to this breakpoint. Do this before freeing the breakpoint | |
14098 | itself, since remove_breakpoint looks at location's owner. It | |
14099 | might be better design to have location completely | |
14100 | self-contained, but it's not the case now. */ | |
44702360 | 14101 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 14102 | |
348d480f | 14103 | bpt->ops->dtor (bpt); |
4a64f543 MS |
14104 | /* On the chance that someone will soon try again to delete this |
14105 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 14106 | bpt->type = bp_none; |
b8c9b27d | 14107 | xfree (bpt); |
c906108c SS |
14108 | } |
14109 | ||
4d6140d9 AC |
14110 | static void |
14111 | do_delete_breakpoint_cleanup (void *b) | |
14112 | { | |
14113 | delete_breakpoint (b); | |
14114 | } | |
14115 | ||
14116 | struct cleanup * | |
14117 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
14118 | { | |
14119 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
14120 | } | |
14121 | ||
51be5b68 PA |
14122 | /* Iterator function to call a user-provided callback function once |
14123 | for each of B and its related breakpoints. */ | |
14124 | ||
14125 | static void | |
14126 | iterate_over_related_breakpoints (struct breakpoint *b, | |
14127 | void (*function) (struct breakpoint *, | |
14128 | void *), | |
14129 | void *data) | |
14130 | { | |
14131 | struct breakpoint *related; | |
14132 | ||
14133 | related = b; | |
14134 | do | |
14135 | { | |
14136 | struct breakpoint *next; | |
14137 | ||
14138 | /* FUNCTION may delete RELATED. */ | |
14139 | next = related->related_breakpoint; | |
14140 | ||
14141 | if (next == related) | |
14142 | { | |
14143 | /* RELATED is the last ring entry. */ | |
14144 | function (related, data); | |
14145 | ||
14146 | /* FUNCTION may have deleted it, so we'd never reach back to | |
14147 | B. There's nothing left to do anyway, so just break | |
14148 | out. */ | |
14149 | break; | |
14150 | } | |
14151 | else | |
14152 | function (related, data); | |
14153 | ||
14154 | related = next; | |
14155 | } | |
14156 | while (related != b); | |
14157 | } | |
95a42b64 TT |
14158 | |
14159 | static void | |
14160 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
14161 | { | |
14162 | delete_breakpoint (b); | |
14163 | } | |
14164 | ||
51be5b68 PA |
14165 | /* A callback for map_breakpoint_numbers that calls |
14166 | delete_breakpoint. */ | |
14167 | ||
14168 | static void | |
14169 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
14170 | { | |
14171 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
14172 | } | |
14173 | ||
c906108c | 14174 | void |
fba45db2 | 14175 | delete_command (char *arg, int from_tty) |
c906108c | 14176 | { |
35df4500 | 14177 | struct breakpoint *b, *b_tmp; |
c906108c | 14178 | |
ea9365bb TT |
14179 | dont_repeat (); |
14180 | ||
c906108c SS |
14181 | if (arg == 0) |
14182 | { | |
14183 | int breaks_to_delete = 0; | |
14184 | ||
46c6471b PA |
14185 | /* Delete all breakpoints if no argument. Do not delete |
14186 | internal breakpoints, these have to be deleted with an | |
14187 | explicit breakpoint number argument. */ | |
c5aa993b | 14188 | ALL_BREAKPOINTS (b) |
46c6471b | 14189 | if (user_breakpoint_p (b)) |
973d738b DJ |
14190 | { |
14191 | breaks_to_delete = 1; | |
14192 | break; | |
14193 | } | |
c906108c SS |
14194 | |
14195 | /* Ask user only if there are some breakpoints to delete. */ | |
14196 | if (!from_tty | |
e2e0b3e5 | 14197 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 14198 | { |
35df4500 | 14199 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14200 | if (user_breakpoint_p (b)) |
c5aa993b | 14201 | delete_breakpoint (b); |
c906108c SS |
14202 | } |
14203 | } | |
14204 | else | |
51be5b68 | 14205 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
14206 | } |
14207 | ||
0d381245 VP |
14208 | static int |
14209 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 14210 | { |
0d381245 | 14211 | for (; loc; loc = loc->next) |
8645ff69 UW |
14212 | if (!loc->shlib_disabled |
14213 | && !loc->pspace->executing_startup) | |
0d381245 VP |
14214 | return 0; |
14215 | return 1; | |
fe3f5fa8 VP |
14216 | } |
14217 | ||
776592bf DE |
14218 | /* Subroutine of update_breakpoint_locations to simplify it. |
14219 | Return non-zero if multiple fns in list LOC have the same name. | |
14220 | Null names are ignored. */ | |
14221 | ||
14222 | static int | |
14223 | ambiguous_names_p (struct bp_location *loc) | |
14224 | { | |
14225 | struct bp_location *l; | |
14226 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
14227 | (int (*) (const void *, |
14228 | const void *)) streq, | |
776592bf DE |
14229 | NULL, xcalloc, xfree); |
14230 | ||
14231 | for (l = loc; l != NULL; l = l->next) | |
14232 | { | |
14233 | const char **slot; | |
14234 | const char *name = l->function_name; | |
14235 | ||
14236 | /* Allow for some names to be NULL, ignore them. */ | |
14237 | if (name == NULL) | |
14238 | continue; | |
14239 | ||
14240 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
14241 | INSERT); | |
4a64f543 MS |
14242 | /* NOTE: We can assume slot != NULL here because xcalloc never |
14243 | returns NULL. */ | |
776592bf DE |
14244 | if (*slot != NULL) |
14245 | { | |
14246 | htab_delete (htab); | |
14247 | return 1; | |
14248 | } | |
14249 | *slot = name; | |
14250 | } | |
14251 | ||
14252 | htab_delete (htab); | |
14253 | return 0; | |
14254 | } | |
14255 | ||
0fb4aa4b PA |
14256 | /* When symbols change, it probably means the sources changed as well, |
14257 | and it might mean the static tracepoint markers are no longer at | |
14258 | the same address or line numbers they used to be at last we | |
14259 | checked. Losing your static tracepoints whenever you rebuild is | |
14260 | undesirable. This function tries to resync/rematch gdb static | |
14261 | tracepoints with the markers on the target, for static tracepoints | |
14262 | that have not been set by marker id. Static tracepoint that have | |
14263 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14264 | The heuristic is: | |
14265 | ||
14266 | 1) For a tracepoint set at a specific address, look for a marker at | |
14267 | the old PC. If one is found there, assume to be the same marker. | |
14268 | If the name / string id of the marker found is different from the | |
14269 | previous known name, assume that means the user renamed the marker | |
14270 | in the sources, and output a warning. | |
14271 | ||
14272 | 2) For a tracepoint set at a given line number, look for a marker | |
14273 | at the new address of the old line number. If one is found there, | |
14274 | assume to be the same marker. If the name / string id of the | |
14275 | marker found is different from the previous known name, assume that | |
14276 | means the user renamed the marker in the sources, and output a | |
14277 | warning. | |
14278 | ||
14279 | 3) If a marker is no longer found at the same address or line, it | |
14280 | may mean the marker no longer exists. But it may also just mean | |
14281 | the code changed a bit. Maybe the user added a few lines of code | |
14282 | that made the marker move up or down (in line number terms). Ask | |
14283 | the target for info about the marker with the string id as we knew | |
14284 | it. If found, update line number and address in the matching | |
14285 | static tracepoint. This will get confused if there's more than one | |
14286 | marker with the same ID (possible in UST, although unadvised | |
14287 | precisely because it confuses tools). */ | |
14288 | ||
14289 | static struct symtab_and_line | |
14290 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14291 | { | |
d9b3f62e | 14292 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14293 | struct static_tracepoint_marker marker; |
14294 | CORE_ADDR pc; | |
0fb4aa4b PA |
14295 | |
14296 | pc = sal.pc; | |
14297 | if (sal.line) | |
14298 | find_line_pc (sal.symtab, sal.line, &pc); | |
14299 | ||
14300 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14301 | { | |
d9b3f62e | 14302 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14303 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14304 | b->number, | |
d9b3f62e | 14305 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14306 | |
d9b3f62e PA |
14307 | xfree (tp->static_trace_marker_id); |
14308 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14309 | release_static_tracepoint_marker (&marker); |
14310 | ||
14311 | return sal; | |
14312 | } | |
14313 | ||
14314 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14315 | by string ID. */ | |
14316 | if (!sal.explicit_pc | |
14317 | && sal.line != 0 | |
14318 | && sal.symtab != NULL | |
d9b3f62e | 14319 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14320 | { |
14321 | VEC(static_tracepoint_marker_p) *markers; | |
14322 | ||
14323 | markers | |
d9b3f62e | 14324 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14325 | |
14326 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14327 | { | |
80e1d417 | 14328 | struct symtab_and_line sal2; |
0fb4aa4b | 14329 | struct symbol *sym; |
80e1d417 | 14330 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14331 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 14332 | |
80e1d417 | 14333 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14334 | |
d9b3f62e | 14335 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14336 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14337 | |
14338 | warning (_("marker for static tracepoint %d (%s) not " | |
14339 | "found at previous line number"), | |
d9b3f62e | 14340 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14341 | |
80e1d417 | 14342 | init_sal (&sal2); |
0fb4aa4b | 14343 | |
80e1d417 | 14344 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14345 | |
80e1d417 AS |
14346 | sal2 = find_pc_line (tpmarker->address, 0); |
14347 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14348 | ui_out_text (uiout, "Now in "); |
14349 | if (sym) | |
14350 | { | |
14351 | ui_out_field_string (uiout, "func", | |
14352 | SYMBOL_PRINT_NAME (sym)); | |
14353 | ui_out_text (uiout, " at "); | |
14354 | } | |
05cba821 JK |
14355 | ui_out_field_string (uiout, "file", |
14356 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14357 | ui_out_text (uiout, ":"); |
14358 | ||
14359 | if (ui_out_is_mi_like_p (uiout)) | |
14360 | { | |
0b0865da | 14361 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14362 | |
f35a17b5 | 14363 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14364 | } |
14365 | ||
80e1d417 | 14366 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14367 | ui_out_text (uiout, "\n"); |
14368 | ||
80e1d417 | 14369 | b->loc->line_number = sal2.line; |
2f202fde | 14370 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b PA |
14371 | |
14372 | xfree (b->addr_string); | |
14373 | b->addr_string = xstrprintf ("%s:%d", | |
05cba821 | 14374 | symtab_to_filename_for_display (sal2.symtab), |
f8eba3c6 | 14375 | b->loc->line_number); |
0fb4aa4b PA |
14376 | |
14377 | /* Might be nice to check if function changed, and warn if | |
14378 | so. */ | |
14379 | ||
80e1d417 | 14380 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14381 | } |
14382 | } | |
14383 | return sal; | |
14384 | } | |
14385 | ||
8d3788bd VP |
14386 | /* Returns 1 iff locations A and B are sufficiently same that |
14387 | we don't need to report breakpoint as changed. */ | |
14388 | ||
14389 | static int | |
14390 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14391 | { | |
14392 | while (a && b) | |
14393 | { | |
14394 | if (a->address != b->address) | |
14395 | return 0; | |
14396 | ||
14397 | if (a->shlib_disabled != b->shlib_disabled) | |
14398 | return 0; | |
14399 | ||
14400 | if (a->enabled != b->enabled) | |
14401 | return 0; | |
14402 | ||
14403 | a = a->next; | |
14404 | b = b->next; | |
14405 | } | |
14406 | ||
14407 | if ((a == NULL) != (b == NULL)) | |
14408 | return 0; | |
14409 | ||
14410 | return 1; | |
14411 | } | |
14412 | ||
f1310107 TJB |
14413 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
14414 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
14415 | a ranged breakpoint. */ | |
14416 | ||
0e30163f | 14417 | void |
0d381245 | 14418 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
14419 | struct symtabs_and_lines sals, |
14420 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14421 | { |
14422 | int i; | |
0d381245 VP |
14423 | struct bp_location *existing_locations = b->loc; |
14424 | ||
f8eba3c6 TT |
14425 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14426 | { | |
14427 | /* Ranged breakpoints have only one start location and one end | |
14428 | location. */ | |
14429 | b->enable_state = bp_disabled; | |
44702360 | 14430 | update_global_location_list (UGLL_MAY_INSERT); |
f8eba3c6 TT |
14431 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14432 | "multiple locations found\n"), | |
14433 | b->number); | |
14434 | return; | |
14435 | } | |
f1310107 | 14436 | |
4a64f543 MS |
14437 | /* If there's no new locations, and all existing locations are |
14438 | pending, don't do anything. This optimizes the common case where | |
14439 | all locations are in the same shared library, that was unloaded. | |
14440 | We'd like to retain the location, so that when the library is | |
14441 | loaded again, we don't loose the enabled/disabled status of the | |
14442 | individual locations. */ | |
0d381245 | 14443 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
14444 | return; |
14445 | ||
fe3f5fa8 VP |
14446 | b->loc = NULL; |
14447 | ||
0d381245 | 14448 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14449 | { |
f8eba3c6 TT |
14450 | struct bp_location *new_loc; |
14451 | ||
14452 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14453 | ||
14454 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14455 | |
0d381245 VP |
14456 | /* Reparse conditions, they might contain references to the |
14457 | old symtab. */ | |
14458 | if (b->cond_string != NULL) | |
14459 | { | |
bbc13ae3 | 14460 | const char *s; |
bfd189b1 | 14461 | volatile struct gdb_exception e; |
fe3f5fa8 | 14462 | |
0d381245 VP |
14463 | s = b->cond_string; |
14464 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14465 | { | |
1bb9788d TT |
14466 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14467 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14468 | 0); |
14469 | } | |
14470 | if (e.reason < 0) | |
14471 | { | |
3e43a32a MS |
14472 | warning (_("failed to reevaluate condition " |
14473 | "for breakpoint %d: %s"), | |
0d381245 VP |
14474 | b->number, e.message); |
14475 | new_loc->enabled = 0; | |
14476 | } | |
14477 | } | |
fe3f5fa8 | 14478 | |
f1310107 TJB |
14479 | if (sals_end.nelts) |
14480 | { | |
14481 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14482 | ||
14483 | new_loc->length = end - sals.sals[0].pc + 1; | |
14484 | } | |
0d381245 | 14485 | } |
fe3f5fa8 | 14486 | |
4a64f543 MS |
14487 | /* If possible, carry over 'disable' status from existing |
14488 | breakpoints. */ | |
0d381245 VP |
14489 | { |
14490 | struct bp_location *e = existing_locations; | |
776592bf DE |
14491 | /* If there are multiple breakpoints with the same function name, |
14492 | e.g. for inline functions, comparing function names won't work. | |
14493 | Instead compare pc addresses; this is just a heuristic as things | |
14494 | may have moved, but in practice it gives the correct answer | |
14495 | often enough until a better solution is found. */ | |
14496 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14497 | ||
0d381245 VP |
14498 | for (; e; e = e->next) |
14499 | { | |
14500 | if (!e->enabled && e->function_name) | |
14501 | { | |
14502 | struct bp_location *l = b->loc; | |
776592bf DE |
14503 | if (have_ambiguous_names) |
14504 | { | |
14505 | for (; l; l = l->next) | |
f1310107 | 14506 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14507 | { |
14508 | l->enabled = 0; | |
14509 | break; | |
14510 | } | |
14511 | } | |
14512 | else | |
14513 | { | |
14514 | for (; l; l = l->next) | |
14515 | if (l->function_name | |
14516 | && strcmp (e->function_name, l->function_name) == 0) | |
14517 | { | |
14518 | l->enabled = 0; | |
14519 | break; | |
14520 | } | |
14521 | } | |
0d381245 VP |
14522 | } |
14523 | } | |
14524 | } | |
fe3f5fa8 | 14525 | |
8d3788bd VP |
14526 | if (!locations_are_equal (existing_locations, b->loc)) |
14527 | observer_notify_breakpoint_modified (b); | |
14528 | ||
44702360 | 14529 | update_global_location_list (UGLL_MAY_INSERT); |
fe3f5fa8 VP |
14530 | } |
14531 | ||
ef23e705 TJB |
14532 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
14533 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
14534 | ||
14535 | static struct symtabs_and_lines | |
14536 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
14537 | { | |
14538 | char *s; | |
02d20e4a | 14539 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 14540 | volatile struct gdb_exception e; |
ef23e705 | 14541 | |
983af33b | 14542 | gdb_assert (b->ops != NULL); |
ef23e705 | 14543 | s = addr_string; |
ef23e705 TJB |
14544 | |
14545 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14546 | { | |
983af33b | 14547 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
14548 | } |
14549 | if (e.reason < 0) | |
14550 | { | |
14551 | int not_found_and_ok = 0; | |
14552 | /* For pending breakpoints, it's expected that parsing will | |
14553 | fail until the right shared library is loaded. User has | |
14554 | already told to create pending breakpoints and don't need | |
14555 | extra messages. If breakpoint is in bp_shlib_disabled | |
14556 | state, then user already saw the message about that | |
14557 | breakpoint being disabled, and don't want to see more | |
14558 | errors. */ | |
58438ac1 | 14559 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14560 | && (b->condition_not_parsed |
14561 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14562 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14563 | || b->enable_state == bp_disabled)) |
14564 | not_found_and_ok = 1; | |
14565 | ||
14566 | if (!not_found_and_ok) | |
14567 | { | |
14568 | /* We surely don't want to warn about the same breakpoint | |
14569 | 10 times. One solution, implemented here, is disable | |
14570 | the breakpoint on error. Another solution would be to | |
14571 | have separate 'warning emitted' flag. Since this | |
14572 | happens only when a binary has changed, I don't know | |
14573 | which approach is better. */ | |
14574 | b->enable_state = bp_disabled; | |
14575 | throw_exception (e); | |
14576 | } | |
14577 | } | |
14578 | ||
58438ac1 | 14579 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 14580 | { |
f8eba3c6 | 14581 | int i; |
ef23e705 | 14582 | |
f8eba3c6 TT |
14583 | for (i = 0; i < sals.nelts; ++i) |
14584 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
14585 | if (b->condition_not_parsed && s && s[0]) |
14586 | { | |
ed1d1739 KS |
14587 | char *cond_string, *extra_string; |
14588 | int thread, task; | |
ef23e705 TJB |
14589 | |
14590 | find_condition_and_thread (s, sals.sals[0].pc, | |
e7e0cddf SS |
14591 | &cond_string, &thread, &task, |
14592 | &extra_string); | |
ef23e705 TJB |
14593 | if (cond_string) |
14594 | b->cond_string = cond_string; | |
14595 | b->thread = thread; | |
14596 | b->task = task; | |
e7e0cddf SS |
14597 | if (extra_string) |
14598 | b->extra_string = extra_string; | |
ef23e705 TJB |
14599 | b->condition_not_parsed = 0; |
14600 | } | |
14601 | ||
983af33b | 14602 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14603 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14604 | |
58438ac1 TT |
14605 | *found = 1; |
14606 | } | |
14607 | else | |
14608 | *found = 0; | |
ef23e705 TJB |
14609 | |
14610 | return sals; | |
14611 | } | |
14612 | ||
348d480f PA |
14613 | /* The default re_set method, for typical hardware or software |
14614 | breakpoints. Reevaluate the breakpoint and recreate its | |
14615 | locations. */ | |
14616 | ||
14617 | static void | |
28010a5d | 14618 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14619 | { |
14620 | int found; | |
f1310107 | 14621 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14622 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14623 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
14624 | |
14625 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
14626 | if (found) | |
14627 | { | |
14628 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14629 | expanded = sals; |
ef23e705 TJB |
14630 | } |
14631 | ||
f1310107 TJB |
14632 | if (b->addr_string_range_end) |
14633 | { | |
14634 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
14635 | if (found) | |
14636 | { | |
14637 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14638 | expanded_end = sals_end; |
f1310107 TJB |
14639 | } |
14640 | } | |
14641 | ||
14642 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14643 | } |
14644 | ||
983af33b SDJ |
14645 | /* Default method for creating SALs from an address string. It basically |
14646 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14647 | ||
14648 | static void | |
14649 | create_sals_from_address_default (char **arg, | |
14650 | struct linespec_result *canonical, | |
14651 | enum bptype type_wanted, | |
14652 | char *addr_start, char **copy_arg) | |
14653 | { | |
14654 | parse_breakpoint_sals (arg, canonical); | |
14655 | } | |
14656 | ||
14657 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14658 | function for the `create_breakpoints_sal' method of | |
14659 | breakpoint_ops. */ | |
14660 | ||
14661 | static void | |
14662 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14663 | struct linespec_result *canonical, | |
983af33b | 14664 | char *cond_string, |
e7e0cddf | 14665 | char *extra_string, |
983af33b SDJ |
14666 | enum bptype type_wanted, |
14667 | enum bpdisp disposition, | |
14668 | int thread, | |
14669 | int task, int ignore_count, | |
14670 | const struct breakpoint_ops *ops, | |
14671 | int from_tty, int enabled, | |
44f238bb | 14672 | int internal, unsigned flags) |
983af33b SDJ |
14673 | { |
14674 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14675 | extra_string, |
983af33b SDJ |
14676 | type_wanted, disposition, |
14677 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14678 | enabled, internal, flags); |
983af33b SDJ |
14679 | } |
14680 | ||
14681 | /* Decode the line represented by S by calling decode_line_full. This is the | |
14682 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
14683 | ||
14684 | static void | |
14685 | decode_linespec_default (struct breakpoint *b, char **s, | |
14686 | struct symtabs_and_lines *sals) | |
14687 | { | |
14688 | struct linespec_result canonical; | |
14689 | ||
14690 | init_linespec_result (&canonical); | |
14691 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
14692 | (struct symtab *) NULL, 0, | |
14693 | &canonical, multiple_symbols_all, | |
14694 | b->filter); | |
14695 | ||
14696 | /* We should get 0 or 1 resulting SALs. */ | |
14697 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14698 | ||
14699 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14700 | { | |
14701 | struct linespec_sals *lsal; | |
14702 | ||
14703 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14704 | *sals = lsal->sals; | |
14705 | /* Arrange it so the destructor does not free the | |
14706 | contents. */ | |
14707 | lsal->sals.sals = NULL; | |
14708 | } | |
14709 | ||
14710 | destroy_linespec_result (&canonical); | |
14711 | } | |
14712 | ||
28010a5d PA |
14713 | /* Prepare the global context for a re-set of breakpoint B. */ |
14714 | ||
14715 | static struct cleanup * | |
14716 | prepare_re_set_context (struct breakpoint *b) | |
14717 | { | |
14718 | struct cleanup *cleanups; | |
14719 | ||
14720 | input_radix = b->input_radix; | |
14721 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14722 | if (b->pspace != NULL) |
14723 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14724 | set_language (b->language); |
14725 | ||
14726 | return cleanups; | |
ef23e705 TJB |
14727 | } |
14728 | ||
c906108c SS |
14729 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14730 | The value we return ends up being the return value from catch_errors. | |
14731 | Unused in this case. */ | |
14732 | ||
14733 | static int | |
4efb68b1 | 14734 | breakpoint_re_set_one (void *bint) |
c906108c | 14735 | { |
4a64f543 | 14736 | /* Get past catch_errs. */ |
53a5351d | 14737 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14738 | struct cleanup *cleanups; |
c906108c | 14739 | |
348d480f PA |
14740 | cleanups = prepare_re_set_context (b); |
14741 | b->ops->re_set (b); | |
14742 | do_cleanups (cleanups); | |
c906108c SS |
14743 | return 0; |
14744 | } | |
14745 | ||
69de3c6a | 14746 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14747 | void |
69de3c6a | 14748 | breakpoint_re_set (void) |
c906108c | 14749 | { |
35df4500 | 14750 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14751 | enum language save_language; |
14752 | int save_input_radix; | |
6c95b8df | 14753 | struct cleanup *old_chain; |
c5aa993b | 14754 | |
c906108c SS |
14755 | save_language = current_language->la_language; |
14756 | save_input_radix = input_radix; | |
6c95b8df PA |
14757 | old_chain = save_current_program_space (); |
14758 | ||
35df4500 | 14759 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14760 | { |
4a64f543 | 14761 | /* Format possible error msg. */ |
fe3f5fa8 | 14762 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14763 | b->number); |
14764 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14765 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14766 | do_cleanups (cleanups); |
c5aa993b | 14767 | } |
c906108c SS |
14768 | set_language (save_language); |
14769 | input_radix = save_input_radix; | |
e62c965a | 14770 | |
0756c555 | 14771 | jit_breakpoint_re_set (); |
4efc6507 | 14772 | |
6c95b8df PA |
14773 | do_cleanups (old_chain); |
14774 | ||
af02033e PP |
14775 | create_overlay_event_breakpoint (); |
14776 | create_longjmp_master_breakpoint (); | |
14777 | create_std_terminate_master_breakpoint (); | |
186c406b | 14778 | create_exception_master_breakpoint (); |
c906108c SS |
14779 | } |
14780 | \f | |
c906108c SS |
14781 | /* Reset the thread number of this breakpoint: |
14782 | ||
14783 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14784 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14785 | void |
fba45db2 | 14786 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14787 | { |
14788 | if (b->thread != -1) | |
14789 | { | |
39f77062 KB |
14790 | if (in_thread_list (inferior_ptid)) |
14791 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14792 | |
14793 | /* We're being called after following a fork. The new fork is | |
14794 | selected as current, and unless this was a vfork will have a | |
14795 | different program space from the original thread. Reset that | |
14796 | as well. */ | |
14797 | b->loc->pspace = current_program_space; | |
c906108c SS |
14798 | } |
14799 | } | |
14800 | ||
03ac34d5 MS |
14801 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14802 | If from_tty is nonzero, it prints a message to that effect, | |
14803 | which ends with a period (no newline). */ | |
14804 | ||
c906108c | 14805 | void |
fba45db2 | 14806 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14807 | { |
52f0bd74 | 14808 | struct breakpoint *b; |
c906108c SS |
14809 | |
14810 | if (count < 0) | |
14811 | count = 0; | |
14812 | ||
14813 | ALL_BREAKPOINTS (b) | |
14814 | if (b->number == bptnum) | |
c5aa993b | 14815 | { |
d77f58be SS |
14816 | if (is_tracepoint (b)) |
14817 | { | |
14818 | if (from_tty && count != 0) | |
14819 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14820 | bptnum); | |
14821 | return; | |
14822 | } | |
14823 | ||
c5aa993b | 14824 | b->ignore_count = count; |
221ea385 KS |
14825 | if (from_tty) |
14826 | { | |
14827 | if (count == 0) | |
3e43a32a MS |
14828 | printf_filtered (_("Will stop next time " |
14829 | "breakpoint %d is reached."), | |
221ea385 KS |
14830 | bptnum); |
14831 | else if (count == 1) | |
a3f17187 | 14832 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14833 | bptnum); |
14834 | else | |
3e43a32a MS |
14835 | printf_filtered (_("Will ignore next %d " |
14836 | "crossings of breakpoint %d."), | |
221ea385 KS |
14837 | count, bptnum); |
14838 | } | |
8d3788bd | 14839 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14840 | return; |
14841 | } | |
c906108c | 14842 | |
8a3fe4f8 | 14843 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14844 | } |
14845 | ||
c906108c SS |
14846 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14847 | ||
14848 | static void | |
fba45db2 | 14849 | ignore_command (char *args, int from_tty) |
c906108c SS |
14850 | { |
14851 | char *p = args; | |
52f0bd74 | 14852 | int num; |
c906108c SS |
14853 | |
14854 | if (p == 0) | |
e2e0b3e5 | 14855 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14856 | |
c906108c | 14857 | num = get_number (&p); |
5c44784c | 14858 | if (num == 0) |
8a3fe4f8 | 14859 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14860 | if (*p == 0) |
8a3fe4f8 | 14861 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14862 | |
14863 | set_ignore_count (num, | |
14864 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14865 | from_tty); | |
221ea385 KS |
14866 | if (from_tty) |
14867 | printf_filtered ("\n"); | |
c906108c SS |
14868 | } |
14869 | \f | |
14870 | /* Call FUNCTION on each of the breakpoints | |
14871 | whose numbers are given in ARGS. */ | |
14872 | ||
14873 | static void | |
95a42b64 TT |
14874 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14875 | void *), | |
14876 | void *data) | |
c906108c | 14877 | { |
52f0bd74 AC |
14878 | int num; |
14879 | struct breakpoint *b, *tmp; | |
11cf8741 | 14880 | int match; |
197f0a60 | 14881 | struct get_number_or_range_state state; |
c906108c | 14882 | |
197f0a60 | 14883 | if (args == 0) |
e2e0b3e5 | 14884 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14885 | |
197f0a60 TT |
14886 | init_number_or_range (&state, args); |
14887 | ||
14888 | while (!state.finished) | |
c906108c | 14889 | { |
e799154c | 14890 | const char *p = state.string; |
197f0a60 | 14891 | |
11cf8741 | 14892 | match = 0; |
c5aa993b | 14893 | |
197f0a60 | 14894 | num = get_number_or_range (&state); |
5c44784c | 14895 | if (num == 0) |
c5aa993b | 14896 | { |
8a3fe4f8 | 14897 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14898 | } |
14899 | else | |
14900 | { | |
14901 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14902 | if (b->number == num) | |
14903 | { | |
11cf8741 | 14904 | match = 1; |
cdac0397 | 14905 | function (b, data); |
11cf8741 | 14906 | break; |
5c44784c | 14907 | } |
11cf8741 | 14908 | if (match == 0) |
a3f17187 | 14909 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14910 | } |
c906108c SS |
14911 | } |
14912 | } | |
14913 | ||
0d381245 VP |
14914 | static struct bp_location * |
14915 | find_location_by_number (char *number) | |
14916 | { | |
14917 | char *dot = strchr (number, '.'); | |
14918 | char *p1; | |
14919 | int bp_num; | |
14920 | int loc_num; | |
14921 | struct breakpoint *b; | |
14922 | struct bp_location *loc; | |
14923 | ||
14924 | *dot = '\0'; | |
14925 | ||
14926 | p1 = number; | |
197f0a60 | 14927 | bp_num = get_number (&p1); |
0d381245 VP |
14928 | if (bp_num == 0) |
14929 | error (_("Bad breakpoint number '%s'"), number); | |
14930 | ||
14931 | ALL_BREAKPOINTS (b) | |
14932 | if (b->number == bp_num) | |
14933 | { | |
14934 | break; | |
14935 | } | |
14936 | ||
14937 | if (!b || b->number != bp_num) | |
14938 | error (_("Bad breakpoint number '%s'"), number); | |
14939 | ||
14940 | p1 = dot+1; | |
197f0a60 | 14941 | loc_num = get_number (&p1); |
0d381245 VP |
14942 | if (loc_num == 0) |
14943 | error (_("Bad breakpoint location number '%s'"), number); | |
14944 | ||
14945 | --loc_num; | |
14946 | loc = b->loc; | |
14947 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14948 | ; | |
14949 | if (!loc) | |
14950 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14951 | ||
14952 | return loc; | |
14953 | } | |
14954 | ||
14955 | ||
1900040c MS |
14956 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14957 | If from_tty is nonzero, it prints a message to that effect, | |
14958 | which ends with a period (no newline). */ | |
14959 | ||
c906108c | 14960 | void |
fba45db2 | 14961 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14962 | { |
14963 | /* Never disable a watchpoint scope breakpoint; we want to | |
14964 | hit them when we leave scope so we can delete both the | |
14965 | watchpoint and its scope breakpoint at that time. */ | |
14966 | if (bpt->type == bp_watchpoint_scope) | |
14967 | return; | |
14968 | ||
b5de0fa7 | 14969 | bpt->enable_state = bp_disabled; |
c906108c | 14970 | |
b775012e LM |
14971 | /* Mark breakpoint locations modified. */ |
14972 | mark_breakpoint_modified (bpt); | |
14973 | ||
d248b706 KY |
14974 | if (target_supports_enable_disable_tracepoint () |
14975 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14976 | { | |
14977 | struct bp_location *location; | |
14978 | ||
14979 | for (location = bpt->loc; location; location = location->next) | |
14980 | target_disable_tracepoint (location); | |
14981 | } | |
14982 | ||
44702360 | 14983 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14984 | |
8d3788bd | 14985 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14986 | } |
14987 | ||
51be5b68 PA |
14988 | /* A callback for iterate_over_related_breakpoints. */ |
14989 | ||
14990 | static void | |
14991 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14992 | { | |
14993 | disable_breakpoint (b); | |
14994 | } | |
14995 | ||
95a42b64 TT |
14996 | /* A callback for map_breakpoint_numbers that calls |
14997 | disable_breakpoint. */ | |
14998 | ||
14999 | static void | |
15000 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
15001 | { | |
51be5b68 | 15002 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
15003 | } |
15004 | ||
c906108c | 15005 | static void |
fba45db2 | 15006 | disable_command (char *args, int from_tty) |
c906108c | 15007 | { |
c906108c | 15008 | if (args == 0) |
46c6471b PA |
15009 | { |
15010 | struct breakpoint *bpt; | |
15011 | ||
15012 | ALL_BREAKPOINTS (bpt) | |
15013 | if (user_breakpoint_p (bpt)) | |
15014 | disable_breakpoint (bpt); | |
15015 | } | |
9eaabc75 | 15016 | else |
0d381245 | 15017 | { |
9eaabc75 MW |
15018 | char *num = extract_arg (&args); |
15019 | ||
15020 | while (num) | |
d248b706 | 15021 | { |
9eaabc75 | 15022 | if (strchr (num, '.')) |
b775012e | 15023 | { |
9eaabc75 MW |
15024 | struct bp_location *loc = find_location_by_number (num); |
15025 | ||
15026 | if (loc) | |
15027 | { | |
15028 | if (loc->enabled) | |
15029 | { | |
15030 | loc->enabled = 0; | |
15031 | mark_breakpoint_location_modified (loc); | |
15032 | } | |
15033 | if (target_supports_enable_disable_tracepoint () | |
15034 | && current_trace_status ()->running && loc->owner | |
15035 | && is_tracepoint (loc->owner)) | |
15036 | target_disable_tracepoint (loc); | |
15037 | } | |
44702360 | 15038 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 15039 | } |
9eaabc75 MW |
15040 | else |
15041 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
15042 | num = extract_arg (&args); | |
d248b706 | 15043 | } |
0d381245 | 15044 | } |
c906108c SS |
15045 | } |
15046 | ||
15047 | static void | |
816338b5 SS |
15048 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
15049 | int count) | |
c906108c | 15050 | { |
afe38095 | 15051 | int target_resources_ok; |
c906108c SS |
15052 | |
15053 | if (bpt->type == bp_hardware_breakpoint) | |
15054 | { | |
15055 | int i; | |
c5aa993b | 15056 | i = hw_breakpoint_used_count (); |
53a5351d | 15057 | target_resources_ok = |
d92524f1 | 15058 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 15059 | i + 1, 0); |
c906108c | 15060 | if (target_resources_ok == 0) |
8a3fe4f8 | 15061 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 15062 | else if (target_resources_ok < 0) |
8a3fe4f8 | 15063 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
15064 | } |
15065 | ||
cc60f2e3 | 15066 | if (is_watchpoint (bpt)) |
c906108c | 15067 | { |
d07205c2 JK |
15068 | /* Initialize it just to avoid a GCC false warning. */ |
15069 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 15070 | volatile struct gdb_exception e; |
dde02812 ES |
15071 | |
15072 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 15073 | { |
3a5c3e22 PA |
15074 | struct watchpoint *w = (struct watchpoint *) bpt; |
15075 | ||
1e718ff1 TJB |
15076 | orig_enable_state = bpt->enable_state; |
15077 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 15078 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 15079 | } |
dde02812 | 15080 | if (e.reason < 0) |
c5aa993b | 15081 | { |
1e718ff1 | 15082 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
15083 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
15084 | bpt->number); | |
15085 | return; | |
c5aa993b | 15086 | } |
c906108c | 15087 | } |
0101ce28 | 15088 | |
b775012e LM |
15089 | bpt->enable_state = bp_enabled; |
15090 | ||
15091 | /* Mark breakpoint locations modified. */ | |
15092 | mark_breakpoint_modified (bpt); | |
15093 | ||
d248b706 KY |
15094 | if (target_supports_enable_disable_tracepoint () |
15095 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
15096 | { | |
15097 | struct bp_location *location; | |
15098 | ||
15099 | for (location = bpt->loc; location; location = location->next) | |
15100 | target_enable_tracepoint (location); | |
15101 | } | |
15102 | ||
b4c291bb | 15103 | bpt->disposition = disposition; |
816338b5 | 15104 | bpt->enable_count = count; |
44702360 | 15105 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 15106 | |
8d3788bd | 15107 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
15108 | } |
15109 | ||
fe3f5fa8 | 15110 | |
c906108c | 15111 | void |
fba45db2 | 15112 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 15113 | { |
816338b5 | 15114 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
15115 | } |
15116 | ||
15117 | static void | |
15118 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
15119 | { | |
15120 | enable_breakpoint (bpt); | |
c906108c SS |
15121 | } |
15122 | ||
95a42b64 TT |
15123 | /* A callback for map_breakpoint_numbers that calls |
15124 | enable_breakpoint. */ | |
15125 | ||
15126 | static void | |
15127 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
15128 | { | |
51be5b68 | 15129 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
15130 | } |
15131 | ||
c906108c SS |
15132 | /* The enable command enables the specified breakpoints (or all defined |
15133 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 15134 | in stopping the inferior. */ |
c906108c | 15135 | |
c906108c | 15136 | static void |
fba45db2 | 15137 | enable_command (char *args, int from_tty) |
c906108c | 15138 | { |
c906108c | 15139 | if (args == 0) |
46c6471b PA |
15140 | { |
15141 | struct breakpoint *bpt; | |
15142 | ||
15143 | ALL_BREAKPOINTS (bpt) | |
15144 | if (user_breakpoint_p (bpt)) | |
15145 | enable_breakpoint (bpt); | |
15146 | } | |
9eaabc75 | 15147 | else |
0d381245 | 15148 | { |
9eaabc75 MW |
15149 | char *num = extract_arg (&args); |
15150 | ||
15151 | while (num) | |
d248b706 | 15152 | { |
9eaabc75 | 15153 | if (strchr (num, '.')) |
b775012e | 15154 | { |
9eaabc75 MW |
15155 | struct bp_location *loc = find_location_by_number (num); |
15156 | ||
15157 | if (loc) | |
15158 | { | |
15159 | if (!loc->enabled) | |
15160 | { | |
15161 | loc->enabled = 1; | |
15162 | mark_breakpoint_location_modified (loc); | |
15163 | } | |
15164 | if (target_supports_enable_disable_tracepoint () | |
15165 | && current_trace_status ()->running && loc->owner | |
15166 | && is_tracepoint (loc->owner)) | |
15167 | target_enable_tracepoint (loc); | |
15168 | } | |
44702360 | 15169 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 15170 | } |
9eaabc75 MW |
15171 | else |
15172 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
15173 | num = extract_arg (&args); | |
d248b706 | 15174 | } |
0d381245 | 15175 | } |
c906108c SS |
15176 | } |
15177 | ||
816338b5 SS |
15178 | /* This struct packages up disposition data for application to multiple |
15179 | breakpoints. */ | |
15180 | ||
15181 | struct disp_data | |
15182 | { | |
15183 | enum bpdisp disp; | |
15184 | int count; | |
15185 | }; | |
15186 | ||
c906108c | 15187 | static void |
51be5b68 PA |
15188 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
15189 | { | |
816338b5 | 15190 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 15191 | |
816338b5 | 15192 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
15193 | } |
15194 | ||
15195 | static void | |
15196 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 15197 | { |
816338b5 | 15198 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
15199 | |
15200 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15201 | } |
15202 | ||
c906108c | 15203 | static void |
fba45db2 | 15204 | enable_once_command (char *args, int from_tty) |
c906108c | 15205 | { |
51be5b68 | 15206 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
15207 | } |
15208 | ||
816338b5 SS |
15209 | static void |
15210 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
15211 | { | |
15212 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
15213 | ||
15214 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
15215 | } | |
15216 | ||
15217 | static void | |
15218 | enable_count_command (char *args, int from_tty) | |
15219 | { | |
15220 | int count = get_number (&args); | |
15221 | ||
15222 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
15223 | } | |
15224 | ||
c906108c | 15225 | static void |
51be5b68 | 15226 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 15227 | { |
816338b5 | 15228 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
15229 | |
15230 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15231 | } |
15232 | ||
c906108c | 15233 | static void |
fba45db2 | 15234 | enable_delete_command (char *args, int from_tty) |
c906108c | 15235 | { |
51be5b68 | 15236 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15237 | } |
15238 | \f | |
fa8d40ab JJ |
15239 | static void |
15240 | set_breakpoint_cmd (char *args, int from_tty) | |
15241 | { | |
15242 | } | |
15243 | ||
15244 | static void | |
15245 | show_breakpoint_cmd (char *args, int from_tty) | |
15246 | { | |
15247 | } | |
15248 | ||
1f3b5d1b PP |
15249 | /* Invalidate last known value of any hardware watchpoint if |
15250 | the memory which that value represents has been written to by | |
15251 | GDB itself. */ | |
15252 | ||
15253 | static void | |
8de0566d YQ |
15254 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15255 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15256 | const bfd_byte *data) |
15257 | { | |
15258 | struct breakpoint *bp; | |
15259 | ||
15260 | ALL_BREAKPOINTS (bp) | |
15261 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15262 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15263 | { |
3a5c3e22 | 15264 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15265 | |
3a5c3e22 PA |
15266 | if (wp->val_valid && wp->val) |
15267 | { | |
15268 | struct bp_location *loc; | |
15269 | ||
15270 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15271 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15272 | && loc->address + loc->length > addr | |
15273 | && addr + len > loc->address) | |
15274 | { | |
15275 | value_free (wp->val); | |
15276 | wp->val = NULL; | |
15277 | wp->val_valid = 0; | |
15278 | } | |
15279 | } | |
1f3b5d1b PP |
15280 | } |
15281 | } | |
15282 | ||
8181d85f DJ |
15283 | /* Create and insert a breakpoint for software single step. */ |
15284 | ||
15285 | void | |
6c95b8df | 15286 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15287 | struct address_space *aspace, |
15288 | CORE_ADDR next_pc) | |
8181d85f | 15289 | { |
7c16b83e PA |
15290 | struct thread_info *tp = inferior_thread (); |
15291 | struct symtab_and_line sal; | |
15292 | CORE_ADDR pc = next_pc; | |
8181d85f | 15293 | |
34b7e8a6 PA |
15294 | if (tp->control.single_step_breakpoints == NULL) |
15295 | { | |
15296 | tp->control.single_step_breakpoints | |
15297 | = new_single_step_breakpoint (tp->num, gdbarch); | |
15298 | } | |
8181d85f | 15299 | |
7c16b83e PA |
15300 | sal = find_pc_line (pc, 0); |
15301 | sal.pc = pc; | |
15302 | sal.section = find_pc_overlay (pc); | |
15303 | sal.explicit_pc = 1; | |
34b7e8a6 | 15304 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 15305 | |
7c16b83e | 15306 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
15307 | } |
15308 | ||
34b7e8a6 | 15309 | /* See breakpoint.h. */ |
f02253f1 HZ |
15310 | |
15311 | int | |
7c16b83e PA |
15312 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
15313 | struct address_space *aspace, | |
15314 | CORE_ADDR pc) | |
1aafd4da | 15315 | { |
7c16b83e | 15316 | struct bp_location *loc; |
1aafd4da | 15317 | |
7c16b83e PA |
15318 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
15319 | if (loc->inserted | |
15320 | && breakpoint_location_address_match (loc, aspace, pc)) | |
15321 | return 1; | |
1aafd4da | 15322 | |
7c16b83e | 15323 | return 0; |
ef370185 JB |
15324 | } |
15325 | ||
15326 | /* Check whether a software single-step breakpoint is inserted at | |
15327 | PC. */ | |
15328 | ||
15329 | int | |
15330 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15331 | CORE_ADDR pc) | |
15332 | { | |
34b7e8a6 PA |
15333 | struct breakpoint *bpt; |
15334 | ||
15335 | ALL_BREAKPOINTS (bpt) | |
15336 | { | |
15337 | if (bpt->type == bp_single_step | |
15338 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
15339 | return 1; | |
15340 | } | |
15341 | return 0; | |
1aafd4da UW |
15342 | } |
15343 | ||
a96d9b2e SDJ |
15344 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
15345 | non-zero otherwise. */ | |
15346 | static int | |
15347 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
15348 | { | |
15349 | if (syscall_catchpoint_p (bp) | |
15350 | && bp->enable_state != bp_disabled | |
15351 | && bp->enable_state != bp_call_disabled) | |
15352 | return 1; | |
15353 | else | |
15354 | return 0; | |
15355 | } | |
15356 | ||
15357 | int | |
15358 | catch_syscall_enabled (void) | |
15359 | { | |
fa3064dd YQ |
15360 | struct catch_syscall_inferior_data *inf_data |
15361 | = get_catch_syscall_inferior_data (current_inferior ()); | |
a96d9b2e | 15362 | |
fa3064dd | 15363 | return inf_data->total_syscalls_count != 0; |
a96d9b2e SDJ |
15364 | } |
15365 | ||
15366 | int | |
15367 | catching_syscall_number (int syscall_number) | |
15368 | { | |
15369 | struct breakpoint *bp; | |
15370 | ||
15371 | ALL_BREAKPOINTS (bp) | |
15372 | if (is_syscall_catchpoint_enabled (bp)) | |
15373 | { | |
be5c67c1 PA |
15374 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
15375 | ||
15376 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
15377 | { |
15378 | int i, iter; | |
15379 | for (i = 0; | |
be5c67c1 | 15380 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
15381 | i++) |
15382 | if (syscall_number == iter) | |
15383 | return 1; | |
15384 | } | |
15385 | else | |
15386 | return 1; | |
15387 | } | |
15388 | ||
15389 | return 0; | |
15390 | } | |
15391 | ||
15392 | /* Complete syscall names. Used by "catch syscall". */ | |
49c4e619 | 15393 | static VEC (char_ptr) * |
a96d9b2e | 15394 | catch_syscall_completer (struct cmd_list_element *cmd, |
6f937416 | 15395 | const char *text, const char *word) |
a96d9b2e | 15396 | { |
458c8db8 | 15397 | const char **list = get_syscall_names (get_current_arch ()); |
49c4e619 | 15398 | VEC (char_ptr) *retlist |
b45627a0 | 15399 | = (list == NULL) ? NULL : complete_on_enum (list, word, word); |
cc59ec59 | 15400 | |
c38eea1a MS |
15401 | xfree (list); |
15402 | return retlist; | |
a96d9b2e SDJ |
15403 | } |
15404 | ||
1042e4c0 SS |
15405 | /* Tracepoint-specific operations. */ |
15406 | ||
15407 | /* Set tracepoint count to NUM. */ | |
15408 | static void | |
15409 | set_tracepoint_count (int num) | |
15410 | { | |
15411 | tracepoint_count = num; | |
4fa62494 | 15412 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15413 | } |
15414 | ||
70221824 | 15415 | static void |
1042e4c0 SS |
15416 | trace_command (char *arg, int from_tty) |
15417 | { | |
55aa24fb SDJ |
15418 | struct breakpoint_ops *ops; |
15419 | const char *arg_cp = arg; | |
15420 | ||
15421 | if (arg && probe_linespec_to_ops (&arg_cp)) | |
15422 | ops = &tracepoint_probe_breakpoint_ops; | |
15423 | else | |
15424 | ops = &tracepoint_breakpoint_ops; | |
15425 | ||
558a9d82 YQ |
15426 | create_breakpoint (get_current_arch (), |
15427 | arg, | |
15428 | NULL, 0, NULL, 1 /* parse arg */, | |
15429 | 0 /* tempflag */, | |
15430 | bp_tracepoint /* type_wanted */, | |
15431 | 0 /* Ignore count */, | |
15432 | pending_break_support, | |
15433 | ops, | |
15434 | from_tty, | |
15435 | 1 /* enabled */, | |
15436 | 0 /* internal */, 0); | |
1042e4c0 SS |
15437 | } |
15438 | ||
70221824 | 15439 | static void |
7a697b8d SS |
15440 | ftrace_command (char *arg, int from_tty) |
15441 | { | |
558a9d82 YQ |
15442 | create_breakpoint (get_current_arch (), |
15443 | arg, | |
15444 | NULL, 0, NULL, 1 /* parse arg */, | |
15445 | 0 /* tempflag */, | |
15446 | bp_fast_tracepoint /* type_wanted */, | |
15447 | 0 /* Ignore count */, | |
15448 | pending_break_support, | |
15449 | &tracepoint_breakpoint_ops, | |
15450 | from_tty, | |
15451 | 1 /* enabled */, | |
15452 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15453 | } |
15454 | ||
15455 | /* strace command implementation. Creates a static tracepoint. */ | |
15456 | ||
70221824 | 15457 | static void |
0fb4aa4b PA |
15458 | strace_command (char *arg, int from_tty) |
15459 | { | |
983af33b SDJ |
15460 | struct breakpoint_ops *ops; |
15461 | ||
15462 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15463 | or with a normal static tracepoint. */ | |
15464 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
15465 | ops = &strace_marker_breakpoint_ops; | |
15466 | else | |
15467 | ops = &tracepoint_breakpoint_ops; | |
15468 | ||
558a9d82 YQ |
15469 | create_breakpoint (get_current_arch (), |
15470 | arg, | |
15471 | NULL, 0, NULL, 1 /* parse arg */, | |
15472 | 0 /* tempflag */, | |
15473 | bp_static_tracepoint /* type_wanted */, | |
15474 | 0 /* Ignore count */, | |
15475 | pending_break_support, | |
15476 | ops, | |
15477 | from_tty, | |
15478 | 1 /* enabled */, | |
15479 | 0 /* internal */, 0); | |
7a697b8d SS |
15480 | } |
15481 | ||
409873ef SS |
15482 | /* Set up a fake reader function that gets command lines from a linked |
15483 | list that was acquired during tracepoint uploading. */ | |
15484 | ||
15485 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15486 | static int next_cmd; |
409873ef SS |
15487 | |
15488 | static char * | |
15489 | read_uploaded_action (void) | |
15490 | { | |
15491 | char *rslt; | |
15492 | ||
3149d8c1 | 15493 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15494 | |
3149d8c1 | 15495 | next_cmd++; |
409873ef SS |
15496 | |
15497 | return rslt; | |
15498 | } | |
15499 | ||
00bf0b85 SS |
15500 | /* Given information about a tracepoint as recorded on a target (which |
15501 | can be either a live system or a trace file), attempt to create an | |
15502 | equivalent GDB tracepoint. This is not a reliable process, since | |
15503 | the target does not necessarily have all the information used when | |
15504 | the tracepoint was originally defined. */ | |
15505 | ||
d9b3f62e | 15506 | struct tracepoint * |
00bf0b85 | 15507 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15508 | { |
409873ef | 15509 | char *addr_str, small_buf[100]; |
d9b3f62e | 15510 | struct tracepoint *tp; |
fd9b8c24 | 15511 | |
409873ef SS |
15512 | if (utp->at_string) |
15513 | addr_str = utp->at_string; | |
15514 | else | |
15515 | { | |
15516 | /* In the absence of a source location, fall back to raw | |
15517 | address. Since there is no way to confirm that the address | |
15518 | means the same thing as when the trace was started, warn the | |
15519 | user. */ | |
3e43a32a MS |
15520 | warning (_("Uploaded tracepoint %d has no " |
15521 | "source location, using raw address"), | |
409873ef | 15522 | utp->number); |
8c042590 | 15523 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15524 | addr_str = small_buf; |
15525 | } | |
15526 | ||
15527 | /* There's not much we can do with a sequence of bytecodes. */ | |
15528 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15529 | warning (_("Uploaded tracepoint %d condition " |
15530 | "has no source form, ignoring it"), | |
409873ef | 15531 | utp->number); |
d5551862 | 15532 | |
8cdf0e15 | 15533 | if (!create_breakpoint (get_current_arch (), |
409873ef | 15534 | addr_str, |
e7e0cddf SS |
15535 | utp->cond_string, -1, NULL, |
15536 | 0 /* parse cond/thread */, | |
8cdf0e15 | 15537 | 0 /* tempflag */, |
0fb4aa4b | 15538 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15539 | 0 /* Ignore count */, |
15540 | pending_break_support, | |
348d480f | 15541 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15542 | 0 /* from_tty */, |
84f4c1fe | 15543 | utp->enabled /* enabled */, |
44f238bb PA |
15544 | 0 /* internal */, |
15545 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
15546 | return NULL; |
15547 | ||
409873ef | 15548 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15549 | tp = get_tracepoint (tracepoint_count); |
15550 | gdb_assert (tp != NULL); | |
d5551862 | 15551 | |
00bf0b85 SS |
15552 | if (utp->pass > 0) |
15553 | { | |
8c042590 PM |
15554 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15555 | tp->base.number); | |
00bf0b85 | 15556 | |
409873ef | 15557 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15558 | } |
15559 | ||
409873ef SS |
15560 | /* If we have uploaded versions of the original commands, set up a |
15561 | special-purpose "reader" function and call the usual command line | |
15562 | reader, then pass the result to the breakpoint command-setting | |
15563 | function. */ | |
3149d8c1 | 15564 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15565 | { |
409873ef | 15566 | struct command_line *cmd_list; |
00bf0b85 | 15567 | |
409873ef | 15568 | this_utp = utp; |
3149d8c1 | 15569 | next_cmd = 0; |
d5551862 | 15570 | |
409873ef SS |
15571 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15572 | ||
d9b3f62e | 15573 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15574 | } |
3149d8c1 SS |
15575 | else if (!VEC_empty (char_ptr, utp->actions) |
15576 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15577 | warning (_("Uploaded tracepoint %d actions " |
15578 | "have no source form, ignoring them"), | |
409873ef | 15579 | utp->number); |
00bf0b85 | 15580 | |
f196051f SS |
15581 | /* Copy any status information that might be available. */ |
15582 | tp->base.hit_count = utp->hit_count; | |
15583 | tp->traceframe_usage = utp->traceframe_usage; | |
15584 | ||
00bf0b85 | 15585 | return tp; |
d9b3f62e | 15586 | } |
00bf0b85 | 15587 | |
1042e4c0 SS |
15588 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15589 | omitted. */ | |
15590 | ||
15591 | static void | |
e5a67952 | 15592 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15593 | { |
79a45e25 | 15594 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15595 | int num_printed; |
1042e4c0 | 15596 | |
e5a67952 | 15597 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15598 | |
15599 | if (num_printed == 0) | |
1042e4c0 | 15600 | { |
e5a67952 | 15601 | if (args == NULL || *args == '\0') |
d77f58be SS |
15602 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15603 | else | |
e5a67952 | 15604 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15605 | } |
ad443146 SS |
15606 | |
15607 | default_collect_info (); | |
1042e4c0 SS |
15608 | } |
15609 | ||
4a64f543 | 15610 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15611 | Not supported by all targets. */ |
15612 | static void | |
15613 | enable_trace_command (char *args, int from_tty) | |
15614 | { | |
15615 | enable_command (args, from_tty); | |
15616 | } | |
15617 | ||
4a64f543 | 15618 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15619 | Not supported by all targets. */ |
15620 | static void | |
15621 | disable_trace_command (char *args, int from_tty) | |
15622 | { | |
15623 | disable_command (args, from_tty); | |
15624 | } | |
15625 | ||
4a64f543 | 15626 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15627 | static void |
15628 | delete_trace_command (char *arg, int from_tty) | |
15629 | { | |
35df4500 | 15630 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15631 | |
15632 | dont_repeat (); | |
15633 | ||
15634 | if (arg == 0) | |
15635 | { | |
15636 | int breaks_to_delete = 0; | |
15637 | ||
15638 | /* Delete all breakpoints if no argument. | |
15639 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15640 | have to be deleted with an explicit breakpoint number |
15641 | argument. */ | |
1042e4c0 | 15642 | ALL_TRACEPOINTS (b) |
46c6471b | 15643 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15644 | { |
15645 | breaks_to_delete = 1; | |
15646 | break; | |
15647 | } | |
1042e4c0 SS |
15648 | |
15649 | /* Ask user only if there are some breakpoints to delete. */ | |
15650 | if (!from_tty | |
15651 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15652 | { | |
35df4500 | 15653 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15654 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15655 | delete_breakpoint (b); |
1042e4c0 SS |
15656 | } |
15657 | } | |
15658 | else | |
51be5b68 | 15659 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15660 | } |
15661 | ||
197f0a60 TT |
15662 | /* Helper function for trace_pass_command. */ |
15663 | ||
15664 | static void | |
d9b3f62e | 15665 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15666 | { |
d9b3f62e | 15667 | tp->pass_count = count; |
6f6484cd | 15668 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15669 | if (from_tty) |
15670 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15671 | tp->base.number, count); |
197f0a60 TT |
15672 | } |
15673 | ||
1042e4c0 SS |
15674 | /* Set passcount for tracepoint. |
15675 | ||
15676 | First command argument is passcount, second is tracepoint number. | |
15677 | If tracepoint number omitted, apply to most recently defined. | |
15678 | Also accepts special argument "all". */ | |
15679 | ||
15680 | static void | |
15681 | trace_pass_command (char *args, int from_tty) | |
15682 | { | |
d9b3f62e | 15683 | struct tracepoint *t1; |
1042e4c0 | 15684 | unsigned int count; |
1042e4c0 SS |
15685 | |
15686 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15687 | error (_("passcount command requires an " |
15688 | "argument (count + optional TP num)")); | |
1042e4c0 | 15689 | |
4a64f543 | 15690 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15691 | |
529480d0 | 15692 | args = skip_spaces (args); |
1042e4c0 SS |
15693 | if (*args && strncasecmp (args, "all", 3) == 0) |
15694 | { | |
d9b3f62e PA |
15695 | struct breakpoint *b; |
15696 | ||
1042e4c0 | 15697 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15698 | if (*args) |
15699 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15700 | |
d9b3f62e | 15701 | ALL_TRACEPOINTS (b) |
197f0a60 | 15702 | { |
d9b3f62e | 15703 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15704 | trace_pass_set_count (t1, count, from_tty); |
15705 | } | |
15706 | } | |
15707 | else if (*args == '\0') | |
1042e4c0 | 15708 | { |
5fa1d40e | 15709 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15710 | if (t1) |
197f0a60 TT |
15711 | trace_pass_set_count (t1, count, from_tty); |
15712 | } | |
15713 | else | |
15714 | { | |
15715 | struct get_number_or_range_state state; | |
15716 | ||
15717 | init_number_or_range (&state, args); | |
15718 | while (!state.finished) | |
1042e4c0 | 15719 | { |
5fa1d40e | 15720 | t1 = get_tracepoint_by_number (&args, &state); |
197f0a60 TT |
15721 | if (t1) |
15722 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15723 | } |
15724 | } | |
1042e4c0 SS |
15725 | } |
15726 | ||
d9b3f62e | 15727 | struct tracepoint * |
1042e4c0 SS |
15728 | get_tracepoint (int num) |
15729 | { | |
15730 | struct breakpoint *t; | |
15731 | ||
15732 | ALL_TRACEPOINTS (t) | |
15733 | if (t->number == num) | |
d9b3f62e | 15734 | return (struct tracepoint *) t; |
1042e4c0 SS |
15735 | |
15736 | return NULL; | |
15737 | } | |
15738 | ||
d5551862 SS |
15739 | /* Find the tracepoint with the given target-side number (which may be |
15740 | different from the tracepoint number after disconnecting and | |
15741 | reconnecting). */ | |
15742 | ||
d9b3f62e | 15743 | struct tracepoint * |
d5551862 SS |
15744 | get_tracepoint_by_number_on_target (int num) |
15745 | { | |
d9b3f62e | 15746 | struct breakpoint *b; |
d5551862 | 15747 | |
d9b3f62e PA |
15748 | ALL_TRACEPOINTS (b) |
15749 | { | |
15750 | struct tracepoint *t = (struct tracepoint *) b; | |
15751 | ||
15752 | if (t->number_on_target == num) | |
15753 | return t; | |
15754 | } | |
d5551862 SS |
15755 | |
15756 | return NULL; | |
15757 | } | |
15758 | ||
1042e4c0 | 15759 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15760 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15761 | If the argument is missing, the most recent tracepoint |
15762 | (tracepoint_count) is returned. */ | |
15763 | ||
d9b3f62e | 15764 | struct tracepoint * |
197f0a60 | 15765 | get_tracepoint_by_number (char **arg, |
5fa1d40e | 15766 | struct get_number_or_range_state *state) |
1042e4c0 | 15767 | { |
1042e4c0 SS |
15768 | struct breakpoint *t; |
15769 | int tpnum; | |
15770 | char *instring = arg == NULL ? NULL : *arg; | |
15771 | ||
197f0a60 TT |
15772 | if (state) |
15773 | { | |
15774 | gdb_assert (!state->finished); | |
15775 | tpnum = get_number_or_range (state); | |
15776 | } | |
15777 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15778 | tpnum = tracepoint_count; |
1042e4c0 | 15779 | else |
197f0a60 | 15780 | tpnum = get_number (arg); |
1042e4c0 SS |
15781 | |
15782 | if (tpnum <= 0) | |
15783 | { | |
15784 | if (instring && *instring) | |
15785 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15786 | instring); | |
15787 | else | |
5fa1d40e | 15788 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15789 | return NULL; |
15790 | } | |
15791 | ||
15792 | ALL_TRACEPOINTS (t) | |
15793 | if (t->number == tpnum) | |
15794 | { | |
d9b3f62e | 15795 | return (struct tracepoint *) t; |
1042e4c0 SS |
15796 | } |
15797 | ||
1042e4c0 SS |
15798 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15799 | return NULL; | |
15800 | } | |
15801 | ||
d9b3f62e PA |
15802 | void |
15803 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15804 | { | |
15805 | if (b->thread != -1) | |
15806 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15807 | ||
15808 | if (b->task != 0) | |
15809 | fprintf_unfiltered (fp, " task %d", b->task); | |
15810 | ||
15811 | fprintf_unfiltered (fp, "\n"); | |
15812 | } | |
15813 | ||
6149aea9 PA |
15814 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15815 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15816 | on each breakpoint and only include the ones for which it returns | |
15817 | non-zero. */ | |
15818 | ||
1042e4c0 | 15819 | static void |
6149aea9 PA |
15820 | save_breakpoints (char *filename, int from_tty, |
15821 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15822 | { |
15823 | struct breakpoint *tp; | |
6149aea9 | 15824 | int any = 0; |
1042e4c0 | 15825 | struct cleanup *cleanup; |
a7bdde9e | 15826 | struct ui_file *fp; |
6149aea9 | 15827 | int extra_trace_bits = 0; |
1042e4c0 | 15828 | |
6149aea9 PA |
15829 | if (filename == 0 || *filename == 0) |
15830 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15831 | |
15832 | /* See if we have anything to save. */ | |
6149aea9 | 15833 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15834 | { |
6149aea9 | 15835 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15836 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15837 | continue; |
15838 | ||
15839 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15840 | if (filter && !filter (tp)) | |
15841 | continue; | |
15842 | ||
15843 | any = 1; | |
15844 | ||
15845 | if (is_tracepoint (tp)) | |
15846 | { | |
15847 | extra_trace_bits = 1; | |
15848 | ||
15849 | /* We can stop searching. */ | |
15850 | break; | |
15851 | } | |
1042e4c0 | 15852 | } |
6149aea9 PA |
15853 | |
15854 | if (!any) | |
1042e4c0 | 15855 | { |
6149aea9 | 15856 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15857 | return; |
15858 | } | |
15859 | ||
c718be47 PA |
15860 | filename = tilde_expand (filename); |
15861 | cleanup = make_cleanup (xfree, filename); | |
15862 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15863 | if (!fp) |
6149aea9 PA |
15864 | error (_("Unable to open file '%s' for saving (%s)"), |
15865 | filename, safe_strerror (errno)); | |
a7bdde9e | 15866 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15867 | |
6149aea9 PA |
15868 | if (extra_trace_bits) |
15869 | save_trace_state_variables (fp); | |
8bf6485c | 15870 | |
6149aea9 | 15871 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15872 | { |
6149aea9 | 15873 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15874 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15875 | continue; |
8bf6485c | 15876 | |
6149aea9 PA |
15877 | /* If we have a filter, only save the breakpoints it accepts. */ |
15878 | if (filter && !filter (tp)) | |
15879 | continue; | |
15880 | ||
348d480f | 15881 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15882 | |
6149aea9 PA |
15883 | /* Note, we can't rely on tp->number for anything, as we can't |
15884 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15885 | instead. */ | |
15886 | ||
15887 | if (tp->cond_string) | |
15888 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15889 | ||
15890 | if (tp->ignore_count) | |
15891 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15892 | ||
2d9442cc | 15893 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15894 | { |
a7bdde9e VP |
15895 | volatile struct gdb_exception ex; |
15896 | ||
6149aea9 | 15897 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15898 | |
79a45e25 | 15899 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 15900 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 15901 | { |
79a45e25 | 15902 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15903 | } |
79a45e25 | 15904 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 15905 | |
a7bdde9e VP |
15906 | if (ex.reason < 0) |
15907 | throw_exception (ex); | |
1042e4c0 | 15908 | |
a7bdde9e | 15909 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15910 | } |
6149aea9 PA |
15911 | |
15912 | if (tp->enable_state == bp_disabled) | |
99894e11 | 15913 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
6149aea9 PA |
15914 | |
15915 | /* If this is a multi-location breakpoint, check if the locations | |
15916 | should be individually disabled. Watchpoint locations are | |
15917 | special, and not user visible. */ | |
15918 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15919 | { | |
15920 | struct bp_location *loc; | |
15921 | int n = 1; | |
15922 | ||
15923 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15924 | if (!loc->enabled) | |
15925 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15926 | } | |
1042e4c0 | 15927 | } |
8bf6485c | 15928 | |
6149aea9 | 15929 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15930 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15931 | ||
1042e4c0 | 15932 | if (from_tty) |
6149aea9 | 15933 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15934 | do_cleanups (cleanup); |
6149aea9 PA |
15935 | } |
15936 | ||
15937 | /* The `save breakpoints' command. */ | |
15938 | ||
15939 | static void | |
15940 | save_breakpoints_command (char *args, int from_tty) | |
15941 | { | |
15942 | save_breakpoints (args, from_tty, NULL); | |
15943 | } | |
15944 | ||
15945 | /* The `save tracepoints' command. */ | |
15946 | ||
15947 | static void | |
15948 | save_tracepoints_command (char *args, int from_tty) | |
15949 | { | |
15950 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15951 | } |
15952 | ||
15953 | /* Create a vector of all tracepoints. */ | |
15954 | ||
15955 | VEC(breakpoint_p) * | |
eeae04df | 15956 | all_tracepoints (void) |
1042e4c0 SS |
15957 | { |
15958 | VEC(breakpoint_p) *tp_vec = 0; | |
15959 | struct breakpoint *tp; | |
15960 | ||
15961 | ALL_TRACEPOINTS (tp) | |
15962 | { | |
15963 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15964 | } | |
15965 | ||
15966 | return tp_vec; | |
15967 | } | |
15968 | ||
c906108c | 15969 | \f |
4a64f543 MS |
15970 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15971 | commands. It is defined as a macro to prevent duplication. | |
15972 | COMMAND should be a string constant containing the name of the | |
15973 | command. */ | |
31e2b00f | 15974 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15975 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15976 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15977 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
15978 | guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\ | |
31e2b00f AS |
15979 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
15980 | If a line number is specified, break at start of code for that line.\n\ | |
15981 | If a function is specified, break at start of code for that function.\n\ | |
15982 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
15983 | With no LOCATION, uses current execution address of the selected\n\ |
15984 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15985 | \n\ |
15986 | THREADNUM is the number from \"info threads\".\n\ | |
15987 | CONDITION is a boolean expression.\n\ | |
15988 | \n\ | |
d41c0fc8 PA |
15989 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15990 | conditions are different.\n\ | |
31e2b00f AS |
15991 | \n\ |
15992 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15993 | ||
44feb3ce TT |
15994 | /* List of subcommands for "catch". */ |
15995 | static struct cmd_list_element *catch_cmdlist; | |
15996 | ||
15997 | /* List of subcommands for "tcatch". */ | |
15998 | static struct cmd_list_element *tcatch_cmdlist; | |
15999 | ||
9ac4176b | 16000 | void |
44feb3ce | 16001 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 16002 | cmd_sfunc_ftype *sfunc, |
625e8578 | 16003 | completer_ftype *completer, |
44feb3ce TT |
16004 | void *user_data_catch, |
16005 | void *user_data_tcatch) | |
16006 | { | |
16007 | struct cmd_list_element *command; | |
16008 | ||
16009 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
16010 | &catch_cmdlist); | |
16011 | set_cmd_sfunc (command, sfunc); | |
16012 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 16013 | set_cmd_completer (command, completer); |
44feb3ce TT |
16014 | |
16015 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
16016 | &tcatch_cmdlist); | |
16017 | set_cmd_sfunc (command, sfunc); | |
16018 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 16019 | set_cmd_completer (command, completer); |
44feb3ce TT |
16020 | } |
16021 | ||
6c95b8df | 16022 | static void |
a79b8f6e | 16023 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 16024 | { |
fa3064dd YQ |
16025 | struct catch_syscall_inferior_data *inf_data |
16026 | = get_catch_syscall_inferior_data (inf); | |
16027 | ||
16028 | inf_data->total_syscalls_count = 0; | |
16029 | inf_data->any_syscall_count = 0; | |
16030 | VEC_free (int, inf_data->syscalls_counts); | |
6c95b8df PA |
16031 | } |
16032 | ||
6149aea9 PA |
16033 | static void |
16034 | save_command (char *arg, int from_tty) | |
16035 | { | |
3e43a32a MS |
16036 | printf_unfiltered (_("\"save\" must be followed by " |
16037 | "the name of a save subcommand.\n")); | |
635c7e8a | 16038 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
16039 | } |
16040 | ||
84f4c1fe PM |
16041 | struct breakpoint * |
16042 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
16043 | void *data) | |
16044 | { | |
35df4500 | 16045 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 16046 | |
35df4500 | 16047 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
16048 | { |
16049 | if ((*callback) (b, data)) | |
16050 | return b; | |
16051 | } | |
16052 | ||
16053 | return NULL; | |
16054 | } | |
16055 | ||
0574c78f GB |
16056 | /* Zero if any of the breakpoint's locations could be a location where |
16057 | functions have been inlined, nonzero otherwise. */ | |
16058 | ||
16059 | static int | |
16060 | is_non_inline_function (struct breakpoint *b) | |
16061 | { | |
16062 | /* The shared library event breakpoint is set on the address of a | |
16063 | non-inline function. */ | |
16064 | if (b->type == bp_shlib_event) | |
16065 | return 1; | |
16066 | ||
16067 | return 0; | |
16068 | } | |
16069 | ||
16070 | /* Nonzero if the specified PC cannot be a location where functions | |
16071 | have been inlined. */ | |
16072 | ||
16073 | int | |
09ac7c10 TT |
16074 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
16075 | const struct target_waitstatus *ws) | |
0574c78f GB |
16076 | { |
16077 | struct breakpoint *b; | |
16078 | struct bp_location *bl; | |
16079 | ||
16080 | ALL_BREAKPOINTS (b) | |
16081 | { | |
16082 | if (!is_non_inline_function (b)) | |
16083 | continue; | |
16084 | ||
16085 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
16086 | { | |
16087 | if (!bl->shlib_disabled | |
09ac7c10 | 16088 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
16089 | return 1; |
16090 | } | |
16091 | } | |
16092 | ||
16093 | return 0; | |
16094 | } | |
16095 | ||
2f202fde JK |
16096 | /* Remove any references to OBJFILE which is going to be freed. */ |
16097 | ||
16098 | void | |
16099 | breakpoint_free_objfile (struct objfile *objfile) | |
16100 | { | |
16101 | struct bp_location **locp, *loc; | |
16102 | ||
16103 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 16104 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
16105 | loc->symtab = NULL; |
16106 | } | |
16107 | ||
2060206e PA |
16108 | void |
16109 | initialize_breakpoint_ops (void) | |
16110 | { | |
16111 | static int initialized = 0; | |
16112 | ||
16113 | struct breakpoint_ops *ops; | |
16114 | ||
16115 | if (initialized) | |
16116 | return; | |
16117 | initialized = 1; | |
16118 | ||
16119 | /* The breakpoint_ops structure to be inherit by all kinds of | |
16120 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
16121 | internal and momentary breakpoints, etc.). */ | |
16122 | ops = &bkpt_base_breakpoint_ops; | |
16123 | *ops = base_breakpoint_ops; | |
16124 | ops->re_set = bkpt_re_set; | |
16125 | ops->insert_location = bkpt_insert_location; | |
16126 | ops->remove_location = bkpt_remove_location; | |
16127 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
16128 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
16129 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
16130 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
16131 | |
16132 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
16133 | ops = &bkpt_breakpoint_ops; | |
16134 | *ops = bkpt_base_breakpoint_ops; | |
16135 | ops->re_set = bkpt_re_set; | |
16136 | ops->resources_needed = bkpt_resources_needed; | |
16137 | ops->print_it = bkpt_print_it; | |
16138 | ops->print_mention = bkpt_print_mention; | |
16139 | ops->print_recreate = bkpt_print_recreate; | |
16140 | ||
16141 | /* Ranged breakpoints. */ | |
16142 | ops = &ranged_breakpoint_ops; | |
16143 | *ops = bkpt_breakpoint_ops; | |
16144 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
16145 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
16146 | ops->print_it = print_it_ranged_breakpoint; | |
16147 | ops->print_one = print_one_ranged_breakpoint; | |
16148 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
16149 | ops->print_mention = print_mention_ranged_breakpoint; | |
16150 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
16151 | ||
16152 | /* Internal breakpoints. */ | |
16153 | ops = &internal_breakpoint_ops; | |
16154 | *ops = bkpt_base_breakpoint_ops; | |
16155 | ops->re_set = internal_bkpt_re_set; | |
16156 | ops->check_status = internal_bkpt_check_status; | |
16157 | ops->print_it = internal_bkpt_print_it; | |
16158 | ops->print_mention = internal_bkpt_print_mention; | |
16159 | ||
16160 | /* Momentary breakpoints. */ | |
16161 | ops = &momentary_breakpoint_ops; | |
16162 | *ops = bkpt_base_breakpoint_ops; | |
16163 | ops->re_set = momentary_bkpt_re_set; | |
16164 | ops->check_status = momentary_bkpt_check_status; | |
16165 | ops->print_it = momentary_bkpt_print_it; | |
16166 | ops->print_mention = momentary_bkpt_print_mention; | |
16167 | ||
e2e4d78b JK |
16168 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
16169 | ops = &longjmp_breakpoint_ops; | |
16170 | *ops = momentary_breakpoint_ops; | |
16171 | ops->dtor = longjmp_bkpt_dtor; | |
16172 | ||
55aa24fb SDJ |
16173 | /* Probe breakpoints. */ |
16174 | ops = &bkpt_probe_breakpoint_ops; | |
16175 | *ops = bkpt_breakpoint_ops; | |
16176 | ops->insert_location = bkpt_probe_insert_location; | |
16177 | ops->remove_location = bkpt_probe_remove_location; | |
16178 | ops->create_sals_from_address = bkpt_probe_create_sals_from_address; | |
16179 | ops->decode_linespec = bkpt_probe_decode_linespec; | |
16180 | ||
2060206e PA |
16181 | /* Watchpoints. */ |
16182 | ops = &watchpoint_breakpoint_ops; | |
16183 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 16184 | ops->dtor = dtor_watchpoint; |
2060206e PA |
16185 | ops->re_set = re_set_watchpoint; |
16186 | ops->insert_location = insert_watchpoint; | |
16187 | ops->remove_location = remove_watchpoint; | |
16188 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
16189 | ops->check_status = check_status_watchpoint; | |
16190 | ops->resources_needed = resources_needed_watchpoint; | |
16191 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
16192 | ops->print_it = print_it_watchpoint; | |
16193 | ops->print_mention = print_mention_watchpoint; | |
16194 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 16195 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
16196 | |
16197 | /* Masked watchpoints. */ | |
16198 | ops = &masked_watchpoint_breakpoint_ops; | |
16199 | *ops = watchpoint_breakpoint_ops; | |
16200 | ops->insert_location = insert_masked_watchpoint; | |
16201 | ops->remove_location = remove_masked_watchpoint; | |
16202 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16203 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16204 | ops->print_it = print_it_masked_watchpoint; | |
16205 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16206 | ops->print_mention = print_mention_masked_watchpoint; | |
16207 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16208 | ||
16209 | /* Tracepoints. */ | |
16210 | ops = &tracepoint_breakpoint_ops; | |
16211 | *ops = base_breakpoint_ops; | |
16212 | ops->re_set = tracepoint_re_set; | |
16213 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16214 | ops->print_one_detail = tracepoint_print_one_detail; | |
16215 | ops->print_mention = tracepoint_print_mention; | |
16216 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
16217 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
16218 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
16219 | ops->decode_linespec = tracepoint_decode_linespec; | |
16220 | ||
55aa24fb SDJ |
16221 | /* Probe tracepoints. */ |
16222 | ops = &tracepoint_probe_breakpoint_ops; | |
16223 | *ops = tracepoint_breakpoint_ops; | |
16224 | ops->create_sals_from_address = tracepoint_probe_create_sals_from_address; | |
16225 | ops->decode_linespec = tracepoint_probe_decode_linespec; | |
16226 | ||
983af33b SDJ |
16227 | /* Static tracepoints with marker (`-m'). */ |
16228 | ops = &strace_marker_breakpoint_ops; | |
16229 | *ops = tracepoint_breakpoint_ops; | |
16230 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
16231 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
16232 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
16233 | |
16234 | /* Fork catchpoints. */ | |
16235 | ops = &catch_fork_breakpoint_ops; | |
16236 | *ops = base_breakpoint_ops; | |
16237 | ops->insert_location = insert_catch_fork; | |
16238 | ops->remove_location = remove_catch_fork; | |
16239 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16240 | ops->print_it = print_it_catch_fork; | |
16241 | ops->print_one = print_one_catch_fork; | |
16242 | ops->print_mention = print_mention_catch_fork; | |
16243 | ops->print_recreate = print_recreate_catch_fork; | |
16244 | ||
16245 | /* Vfork catchpoints. */ | |
16246 | ops = &catch_vfork_breakpoint_ops; | |
16247 | *ops = base_breakpoint_ops; | |
16248 | ops->insert_location = insert_catch_vfork; | |
16249 | ops->remove_location = remove_catch_vfork; | |
16250 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16251 | ops->print_it = print_it_catch_vfork; | |
16252 | ops->print_one = print_one_catch_vfork; | |
16253 | ops->print_mention = print_mention_catch_vfork; | |
16254 | ops->print_recreate = print_recreate_catch_vfork; | |
16255 | ||
16256 | /* Exec catchpoints. */ | |
16257 | ops = &catch_exec_breakpoint_ops; | |
16258 | *ops = base_breakpoint_ops; | |
16259 | ops->dtor = dtor_catch_exec; | |
16260 | ops->insert_location = insert_catch_exec; | |
16261 | ops->remove_location = remove_catch_exec; | |
16262 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16263 | ops->print_it = print_it_catch_exec; | |
16264 | ops->print_one = print_one_catch_exec; | |
16265 | ops->print_mention = print_mention_catch_exec; | |
16266 | ops->print_recreate = print_recreate_catch_exec; | |
16267 | ||
16268 | /* Syscall catchpoints. */ | |
16269 | ops = &catch_syscall_breakpoint_ops; | |
16270 | *ops = base_breakpoint_ops; | |
16271 | ops->dtor = dtor_catch_syscall; | |
16272 | ops->insert_location = insert_catch_syscall; | |
16273 | ops->remove_location = remove_catch_syscall; | |
16274 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
16275 | ops->print_it = print_it_catch_syscall; | |
16276 | ops->print_one = print_one_catch_syscall; | |
16277 | ops->print_mention = print_mention_catch_syscall; | |
16278 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
16279 | |
16280 | /* Solib-related catchpoints. */ | |
16281 | ops = &catch_solib_breakpoint_ops; | |
16282 | *ops = base_breakpoint_ops; | |
16283 | ops->dtor = dtor_catch_solib; | |
16284 | ops->insert_location = insert_catch_solib; | |
16285 | ops->remove_location = remove_catch_solib; | |
16286 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16287 | ops->check_status = check_status_catch_solib; | |
16288 | ops->print_it = print_it_catch_solib; | |
16289 | ops->print_one = print_one_catch_solib; | |
16290 | ops->print_mention = print_mention_catch_solib; | |
16291 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16292 | |
16293 | ops = &dprintf_breakpoint_ops; | |
16294 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16295 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16296 | ops->resources_needed = bkpt_resources_needed; |
16297 | ops->print_it = bkpt_print_it; | |
16298 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16299 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16300 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 16301 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
16302 | } |
16303 | ||
8bfd80db YQ |
16304 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16305 | ||
16306 | static struct cmd_list_element *enablebreaklist = NULL; | |
16307 | ||
c906108c | 16308 | void |
fba45db2 | 16309 | _initialize_breakpoint (void) |
c906108c SS |
16310 | { |
16311 | struct cmd_list_element *c; | |
16312 | ||
2060206e PA |
16313 | initialize_breakpoint_ops (); |
16314 | ||
84acb35a | 16315 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16316 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
6c95b8df | 16317 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 16318 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16319 | |
55aa24fb SDJ |
16320 | breakpoint_objfile_key |
16321 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16322 | |
fa3064dd | 16323 | catch_syscall_inferior_data |
8e260fc0 TT |
16324 | = register_inferior_data_with_cleanup (NULL, |
16325 | catch_syscall_inferior_data_cleanup); | |
fa3064dd | 16326 | |
c906108c SS |
16327 | breakpoint_chain = 0; |
16328 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16329 | before a breakpoint is set. */ | |
16330 | breakpoint_count = 0; | |
16331 | ||
1042e4c0 SS |
16332 | tracepoint_count = 0; |
16333 | ||
1bedd215 AC |
16334 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16335 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16336 | Usage is `ignore N COUNT'.")); | |
c906108c | 16337 | if (xdb_commands) |
c5aa993b | 16338 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 16339 | |
1bedd215 AC |
16340 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16341 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16342 | Give breakpoint number as argument after \"commands\".\n\ |
16343 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16344 | The commands themselves follow starting on the next line.\n\ | |
16345 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16346 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16347 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16348 | |
d55637df | 16349 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16350 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16351 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16352 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16353 | set_cmd_completer (c, condition_completer); |
c906108c | 16354 | |
1bedd215 | 16355 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16356 | Set a temporary breakpoint.\n\ |
c906108c SS |
16357 | Like \"break\" except the breakpoint is only temporary,\n\ |
16358 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16359 | by using \"enable delete\" on the breakpoint number.\n\ |
16360 | \n" | |
16361 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16362 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16363 | |
1bedd215 | 16364 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16365 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16366 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16367 | some target hardware may not have this support.\n\ |
16368 | \n" | |
16369 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16370 | set_cmd_completer (c, location_completer); |
c906108c | 16371 | |
1bedd215 | 16372 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16373 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16374 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16375 | so it will be deleted when hit.\n\ |
16376 | \n" | |
16377 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16378 | set_cmd_completer (c, location_completer); |
c906108c | 16379 | |
1bedd215 AC |
16380 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16381 | Enable some breakpoints.\n\ | |
c906108c SS |
16382 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16383 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16384 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16385 | With a subcommand you can enable temporarily."), |
c906108c SS |
16386 | &enablelist, "enable ", 1, &cmdlist); |
16387 | if (xdb_commands) | |
1bedd215 AC |
16388 | add_com ("ab", class_breakpoint, enable_command, _("\ |
16389 | Enable some breakpoints.\n\ | |
c906108c SS |
16390 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16391 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16392 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16393 | With a subcommand you can enable temporarily.")); |
c906108c SS |
16394 | |
16395 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16396 | ||
84951ab5 | 16397 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16398 | Enable some breakpoints.\n\ |
c906108c SS |
16399 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16400 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16401 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16402 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16403 | |
1a966eab AC |
16404 | add_cmd ("once", no_class, enable_once_command, _("\ |
16405 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16406 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16407 | &enablebreaklist); |
16408 | ||
1a966eab AC |
16409 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16410 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16411 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16412 | &enablebreaklist); |
16413 | ||
816338b5 SS |
16414 | add_cmd ("count", no_class, enable_count_command, _("\ |
16415 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16416 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16417 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16418 | &enablebreaklist); | |
16419 | ||
1a966eab AC |
16420 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16421 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16422 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16423 | &enablelist); |
16424 | ||
1a966eab AC |
16425 | add_cmd ("once", no_class, enable_once_command, _("\ |
16426 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16427 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16428 | &enablelist); |
16429 | ||
16430 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16431 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16432 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16433 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16434 | &enablelist); |
16435 | ||
1bedd215 AC |
16436 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16437 | Disable some breakpoints.\n\ | |
c906108c SS |
16438 | Arguments are breakpoint numbers with spaces in between.\n\ |
16439 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16440 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16441 | &disablelist, "disable ", 1, &cmdlist); |
16442 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16443 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
16444 | if (xdb_commands) | |
1bedd215 AC |
16445 | add_com ("sb", class_breakpoint, disable_command, _("\ |
16446 | Disable some breakpoints.\n\ | |
c906108c SS |
16447 | Arguments are breakpoint numbers with spaces in between.\n\ |
16448 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16449 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 16450 | |
1a966eab AC |
16451 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16452 | Disable some breakpoints.\n\ | |
c906108c SS |
16453 | Arguments are breakpoint numbers with spaces in between.\n\ |
16454 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16455 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16456 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16457 | &disablelist); |
16458 | ||
1bedd215 AC |
16459 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16460 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16461 | Arguments are breakpoint numbers with spaces in between.\n\ |
16462 | To delete all breakpoints, give no argument.\n\ | |
16463 | \n\ | |
16464 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16465 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16466 | &deletelist, "delete ", 1, &cmdlist); |
16467 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16468 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16469 | if (xdb_commands) |
1bedd215 AC |
16470 | add_com ("db", class_breakpoint, delete_command, _("\ |
16471 | Delete some breakpoints.\n\ | |
c906108c | 16472 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 16473 | To delete all breakpoints, give no argument.\n")); |
c906108c | 16474 | |
1a966eab AC |
16475 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16476 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16477 | Arguments are breakpoint numbers with spaces in between.\n\ |
16478 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16479 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16480 | &deletelist); |
16481 | ||
1bedd215 AC |
16482 | add_com ("clear", class_breakpoint, clear_command, _("\ |
16483 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
16484 | Argument may be line number, function name, or \"*\" and an address.\n\ |
16485 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
16486 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
16487 | If an address is specified, breakpoints at that address are cleared.\n\ |
16488 | \n\ | |
16489 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
16490 | is executing in.\n\ |
16491 | \n\ | |
1bedd215 | 16492 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16493 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16494 | |
1bedd215 | 16495 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
16496 | Set breakpoint at specified line or function.\n" |
16497 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 16498 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16499 | |
c906108c SS |
16500 | add_com_alias ("b", "break", class_run, 1); |
16501 | add_com_alias ("br", "break", class_run, 1); | |
16502 | add_com_alias ("bre", "break", class_run, 1); | |
16503 | add_com_alias ("brea", "break", class_run, 1); | |
16504 | ||
7681d515 PM |
16505 | if (xdb_commands) |
16506 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
16507 | |
16508 | if (dbx_commands) | |
16509 | { | |
1bedd215 AC |
16510 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16511 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16512 | &stoplist, "stop ", 1, &cmdlist); |
16513 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16514 | _("Break in function or address."), &stoplist); |
c5aa993b | 16515 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16516 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16517 | add_com ("status", class_info, breakpoints_info, _("\ |
16518 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16519 | The \"Type\" column indicates one of:\n\ |
16520 | \tbreakpoint - normal breakpoint\n\ | |
16521 | \twatchpoint - watchpoint\n\ | |
16522 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16523 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16524 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16525 | address and file/line number respectively.\n\ |
16526 | \n\ | |
16527 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16528 | are set to the address of the last breakpoint listed unless the command\n\ |
16529 | is prefixed with \"server \".\n\n\ | |
c906108c | 16530 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16531 | breakpoint set.")); |
c906108c SS |
16532 | } |
16533 | ||
1bedd215 | 16534 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16535 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16536 | The \"Type\" column indicates one of:\n\ |
16537 | \tbreakpoint - normal breakpoint\n\ | |
16538 | \twatchpoint - watchpoint\n\ | |
16539 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16540 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16541 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16542 | address and file/line number respectively.\n\ |
16543 | \n\ | |
16544 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16545 | are set to the address of the last breakpoint listed unless the command\n\ |
16546 | is prefixed with \"server \".\n\n\ | |
c906108c | 16547 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16548 | breakpoint set.")); |
c906108c | 16549 | |
6b04bdb7 MS |
16550 | add_info_alias ("b", "breakpoints", 1); |
16551 | ||
c906108c | 16552 | if (xdb_commands) |
1bedd215 AC |
16553 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
16554 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16555 | The \"Type\" column indicates one of:\n\ |
16556 | \tbreakpoint - normal breakpoint\n\ | |
16557 | \twatchpoint - watchpoint\n\ | |
16558 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16559 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16560 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16561 | address and file/line number respectively.\n\ |
16562 | \n\ | |
16563 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16564 | are set to the address of the last breakpoint listed unless the command\n\ |
16565 | is prefixed with \"server \".\n\n\ | |
c906108c | 16566 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16567 | breakpoint set.")); |
c906108c | 16568 | |
1a966eab AC |
16569 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16570 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16571 | The \"Type\" column indicates one of:\n\ |
16572 | \tbreakpoint - normal breakpoint\n\ | |
16573 | \twatchpoint - watchpoint\n\ | |
16574 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16575 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16576 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16577 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16578 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16579 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16580 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16581 | address and file/line number respectively.\n\ |
16582 | \n\ | |
16583 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16584 | are set to the address of the last breakpoint listed unless the command\n\ |
16585 | is prefixed with \"server \".\n\n\ | |
c906108c | 16586 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16587 | breakpoint set."), |
c906108c SS |
16588 | &maintenanceinfolist); |
16589 | ||
44feb3ce TT |
16590 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16591 | Set catchpoints to catch events."), | |
16592 | &catch_cmdlist, "catch ", | |
16593 | 0/*allow-unknown*/, &cmdlist); | |
16594 | ||
16595 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16596 | Set temporary catchpoints to catch events."), | |
16597 | &tcatch_cmdlist, "tcatch ", | |
16598 | 0/*allow-unknown*/, &cmdlist); | |
16599 | ||
44feb3ce TT |
16600 | add_catch_command ("fork", _("Catch calls to fork."), |
16601 | catch_fork_command_1, | |
a96d9b2e | 16602 | NULL, |
44feb3ce TT |
16603 | (void *) (uintptr_t) catch_fork_permanent, |
16604 | (void *) (uintptr_t) catch_fork_temporary); | |
16605 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16606 | catch_fork_command_1, | |
a96d9b2e | 16607 | NULL, |
44feb3ce TT |
16608 | (void *) (uintptr_t) catch_vfork_permanent, |
16609 | (void *) (uintptr_t) catch_vfork_temporary); | |
16610 | add_catch_command ("exec", _("Catch calls to exec."), | |
16611 | catch_exec_command_1, | |
a96d9b2e SDJ |
16612 | NULL, |
16613 | CATCH_PERMANENT, | |
16614 | CATCH_TEMPORARY); | |
edcc5120 TT |
16615 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16616 | Usage: catch load [REGEX]\n\ | |
16617 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16618 | catch_load_command_1, | |
16619 | NULL, | |
16620 | CATCH_PERMANENT, | |
16621 | CATCH_TEMPORARY); | |
16622 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16623 | Usage: catch unload [REGEX]\n\ | |
16624 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16625 | catch_unload_command_1, | |
16626 | NULL, | |
16627 | CATCH_PERMANENT, | |
16628 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
16629 | add_catch_command ("syscall", _("\ |
16630 | Catch system calls by their names and/or numbers.\n\ | |
16631 | Arguments say which system calls to catch. If no arguments\n\ | |
16632 | are given, every system call will be caught.\n\ | |
16633 | Arguments, if given, should be one or more system call names\n\ | |
16634 | (if your system supports that), or system call numbers."), | |
16635 | catch_syscall_command_1, | |
16636 | catch_syscall_completer, | |
44feb3ce TT |
16637 | CATCH_PERMANENT, |
16638 | CATCH_TEMPORARY); | |
c5aa993b | 16639 | |
1bedd215 AC |
16640 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16641 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16642 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16643 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16644 | an expression changes.\n\ |
16645 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16646 | the memory to which it refers.")); | |
65d12d83 | 16647 | set_cmd_completer (c, expression_completer); |
c906108c | 16648 | |
1bedd215 AC |
16649 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16650 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16651 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16652 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16653 | an expression is read.\n\ |
16654 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16655 | the memory to which it refers.")); | |
65d12d83 | 16656 | set_cmd_completer (c, expression_completer); |
c906108c | 16657 | |
1bedd215 AC |
16658 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16659 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16660 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16661 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16662 | an expression is either read or written.\n\ |
16663 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16664 | the memory to which it refers.")); | |
65d12d83 | 16665 | set_cmd_completer (c, expression_completer); |
c906108c | 16666 | |
d77f58be | 16667 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16668 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16669 | |
920d2a44 AC |
16670 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16671 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16672 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16673 | &can_use_hw_watchpoints, _("\ | |
16674 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16675 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16676 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16677 | such is available. (However, any hardware watchpoints that were\n\ | |
16678 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16679 | hardware.)"), |
16680 | NULL, | |
920d2a44 | 16681 | show_can_use_hw_watchpoints, |
85c07804 | 16682 | &setlist, &showlist); |
c906108c SS |
16683 | |
16684 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16685 | |
1042e4c0 SS |
16686 | /* Tracepoint manipulation commands. */ |
16687 | ||
16688 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
16689 | Set a tracepoint at specified line or function.\n\ | |
16690 | \n" | |
16691 | BREAK_ARGS_HELP ("trace") "\n\ | |
16692 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16693 | set_cmd_completer (c, location_completer); | |
16694 | ||
16695 | add_com_alias ("tp", "trace", class_alias, 0); | |
16696 | add_com_alias ("tr", "trace", class_alias, 1); | |
16697 | add_com_alias ("tra", "trace", class_alias, 1); | |
16698 | add_com_alias ("trac", "trace", class_alias, 1); | |
16699 | ||
7a697b8d SS |
16700 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
16701 | Set a fast tracepoint at specified line or function.\n\ | |
16702 | \n" | |
16703 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16704 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16705 | set_cmd_completer (c, location_completer); | |
16706 | ||
0fb4aa4b PA |
16707 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
16708 | Set a static tracepoint at specified line, function or marker.\n\ | |
16709 | \n\ | |
16710 | strace [LOCATION] [if CONDITION]\n\ | |
16711 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
16712 | or -m MARKER_ID.\n\ | |
16713 | If a line number is specified, probe the marker at start of code\n\ | |
16714 | for that line. If a function is specified, probe the marker at start\n\ | |
16715 | of code for that function. If an address is specified, probe the marker\n\ | |
16716 | at that exact address. If a marker id is specified, probe the marker\n\ | |
16717 | with that name. With no LOCATION, uses current execution address of\n\ | |
16718 | the selected stack frame.\n\ | |
16719 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
16720 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16721 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16722 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16723 | \n\ | |
16724 | CONDITION is a boolean expression.\n\ | |
16725 | \n\ | |
d41c0fc8 PA |
16726 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16727 | conditions are different.\n\ | |
0fb4aa4b PA |
16728 | \n\ |
16729 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16730 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16731 | set_cmd_completer (c, location_completer); | |
16732 | ||
1042e4c0 | 16733 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16734 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16735 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16736 | last tracepoint set.")); | |
16737 | ||
16738 | add_info_alias ("tp", "tracepoints", 1); | |
16739 | ||
16740 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16741 | Delete specified tracepoints.\n\ | |
16742 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16743 | No argument means delete all tracepoints."), | |
16744 | &deletelist); | |
7e20dfcd | 16745 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16746 | |
16747 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16748 | Disable specified tracepoints.\n\ | |
16749 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16750 | No argument means disable all tracepoints."), | |
16751 | &disablelist); | |
16752 | deprecate_cmd (c, "disable"); | |
16753 | ||
16754 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16755 | Enable specified tracepoints.\n\ | |
16756 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16757 | No argument means enable all tracepoints."), | |
16758 | &enablelist); | |
16759 | deprecate_cmd (c, "enable"); | |
16760 | ||
16761 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16762 | Set the passcount for a tracepoint.\n\ | |
16763 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16764 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16765 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16766 | ||
6149aea9 PA |
16767 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16768 | _("Save breakpoint definitions as a script."), | |
16769 | &save_cmdlist, "save ", | |
16770 | 0/*allow-unknown*/, &cmdlist); | |
16771 | ||
16772 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16773 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16774 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16775 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16776 | session to restore them."), | |
16777 | &save_cmdlist); | |
16778 | set_cmd_completer (c, filename_completer); | |
16779 | ||
16780 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16781 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16782 | Use the 'source' command in another debug session to restore them."), |
16783 | &save_cmdlist); | |
1042e4c0 SS |
16784 | set_cmd_completer (c, filename_completer); |
16785 | ||
6149aea9 PA |
16786 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16787 | deprecate_cmd (c, "save tracepoints"); | |
16788 | ||
1bedd215 | 16789 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16790 | Breakpoint specific settings\n\ |
16791 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16792 | pending breakpoint behavior"), |
fa8d40ab JJ |
16793 | &breakpoint_set_cmdlist, "set breakpoint ", |
16794 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16795 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16796 | Breakpoint specific settings\n\ |
16797 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16798 | pending breakpoint behavior"), |
fa8d40ab JJ |
16799 | &breakpoint_show_cmdlist, "show breakpoint ", |
16800 | 0/*allow-unknown*/, &showlist); | |
16801 | ||
7915a72c AC |
16802 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16803 | &pending_break_support, _("\ | |
16804 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16805 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16806 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16807 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16808 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16809 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16810 | NULL, |
920d2a44 | 16811 | show_pending_break_support, |
6e1d7d6c AC |
16812 | &breakpoint_set_cmdlist, |
16813 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16814 | |
16815 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16816 | |
16817 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16818 | &automatic_hardware_breakpoints, _("\ | |
16819 | Set automatic usage of hardware breakpoints."), _("\ | |
16820 | Show automatic usage of hardware breakpoints."), _("\ | |
16821 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16822 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16823 | a warning will be emitted for such breakpoints."), | |
16824 | NULL, | |
16825 | show_automatic_hardware_breakpoints, | |
16826 | &breakpoint_set_cmdlist, | |
16827 | &breakpoint_show_cmdlist); | |
74960c60 | 16828 | |
a25a5a45 PA |
16829 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16830 | &always_inserted_mode, _("\ | |
74960c60 VP |
16831 | Set mode for inserting breakpoints."), _("\ |
16832 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16833 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16834 | they're created, kept inserted even when execution stops, and removed\n\ | |
16835 | only when the user deletes them. When this mode is off (the default),\n\ | |
16836 | breakpoints are inserted only when execution continues, and removed\n\ | |
16837 | when execution stops."), | |
72d0e2c5 YQ |
16838 | NULL, |
16839 | &show_always_inserted_mode, | |
16840 | &breakpoint_set_cmdlist, | |
16841 | &breakpoint_show_cmdlist); | |
f1310107 | 16842 | |
b775012e LM |
16843 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16844 | condition_evaluation_enums, | |
16845 | &condition_evaluation_mode_1, _("\ | |
16846 | Set mode of breakpoint condition evaluation."), _("\ | |
16847 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16848 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16849 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16850 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16851 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16852 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16853 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16854 | be set to \"gdb\""), | |
16855 | &set_condition_evaluation_mode, | |
16856 | &show_condition_evaluation_mode, | |
16857 | &breakpoint_set_cmdlist, | |
16858 | &breakpoint_show_cmdlist); | |
16859 | ||
f1310107 TJB |
16860 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16861 | Set a breakpoint for an address range.\n\ | |
16862 | break-range START-LOCATION, END-LOCATION\n\ | |
16863 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16864 | LINENUM, for that line in the current file,\n\ | |
16865 | FILE:LINENUM, for that line in that file,\n\ | |
16866 | +OFFSET, for that number of lines after the current line\n\ | |
16867 | or the start of the range\n\ | |
16868 | FUNCTION, for the first line in that function,\n\ | |
16869 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16870 | *ADDRESS, for the instruction at that address.\n\ | |
16871 | \n\ | |
16872 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16873 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16874 | range (including START-LOCATION and END-LOCATION).")); | |
16875 | ||
e7e0cddf SS |
16876 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
16877 | Set a dynamic printf at specified line or function.\n\ | |
16878 | dprintf location,format string,arg1,arg2,...\n\ | |
16879 | location may be a line number, function name, or \"*\" and an address.\n\ | |
16880 | If a line number is specified, break at start of code for that line.\n\ | |
0e4777df | 16881 | If a function is specified, break at start of code for that function.")); |
e7e0cddf SS |
16882 | set_cmd_completer (c, location_completer); |
16883 | ||
16884 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16885 | dprintf_style_enums, &dprintf_style, _("\ | |
16886 | Set the style of usage for dynamic printf."), _("\ | |
16887 | Show the style of usage for dynamic printf."), _("\ | |
16888 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16889 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16890 | console, as with the \"printf\" command.\n\ | |
16891 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16892 | program; by default printf(), but you can choose a different function or\n\ | |
16893 | output stream by setting dprintf-function and dprintf-channel."), | |
16894 | update_dprintf_commands, NULL, | |
16895 | &setlist, &showlist); | |
16896 | ||
16897 | dprintf_function = xstrdup ("printf"); | |
16898 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16899 | &dprintf_function, _("\ | |
16900 | Set the function to use for dynamic printf"), _("\ | |
16901 | Show the function to use for dynamic printf"), NULL, | |
16902 | update_dprintf_commands, NULL, | |
16903 | &setlist, &showlist); | |
16904 | ||
16905 | dprintf_channel = xstrdup (""); | |
16906 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16907 | &dprintf_channel, _("\ | |
16908 | Set the channel to use for dynamic printf"), _("\ | |
16909 | Show the channel to use for dynamic printf"), NULL, | |
16910 | update_dprintf_commands, NULL, | |
16911 | &setlist, &showlist); | |
16912 | ||
d3ce09f5 SS |
16913 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16914 | &disconnected_dprintf, _("\ | |
16915 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16916 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16917 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16918 | even if GDB disconnects or detaches from the target."), | |
16919 | NULL, | |
16920 | NULL, | |
16921 | &setlist, &showlist); | |
16922 | ||
16923 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16924 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16925 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16926 | ||
765dc015 | 16927 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16928 | |
16929 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16930 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16931 | } |