Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
ecd75fc8 | 3 | Copyright (C) 1986-2014 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
45741a9c | 35 | #include "infrun.h" |
c906108c SS |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
38 | #include "language.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
fe898f56 | 50 | #include "block.h" |
a77053c2 | 51 | #include "solib.h" |
84acb35a JJ |
52 | #include "solist.h" |
53 | #include "observer.h" | |
765dc015 | 54 | #include "memattr.h" |
f7f9143b | 55 | #include "ada-lang.h" |
d1aa2f50 | 56 | #include "top.h" |
79a45b7d | 57 | #include "valprint.h" |
4efc6507 | 58 | #include "jit.h" |
a96d9b2e | 59 | #include "xml-syscall.h" |
65d79d4b | 60 | #include "parser-defs.h" |
55aa24fb SDJ |
61 | #include "gdb_regex.h" |
62 | #include "probe.h" | |
e9cafbcc | 63 | #include "cli/cli-utils.h" |
be34f849 | 64 | #include "continuations.h" |
1bfeeb0f JL |
65 | #include "stack.h" |
66 | #include "skip.h" | |
b775012e | 67 | #include "ax-gdb.h" |
e2e4d78b | 68 | #include "dummy-frame.h" |
c906108c | 69 | |
d3ce09f5 SS |
70 | #include "format.h" |
71 | ||
1042e4c0 SS |
72 | /* readline include files */ |
73 | #include "readline/readline.h" | |
74 | #include "readline/history.h" | |
75 | ||
76 | /* readline defines this. */ | |
77 | #undef savestring | |
78 | ||
034dad6f | 79 | #include "mi/mi-common.h" |
6dddc817 | 80 | #include "extension.h" |
104c1213 | 81 | |
e7e8980f YQ |
82 | /* Enums for exception-handling support. */ |
83 | enum exception_event_kind | |
84 | { | |
85 | EX_EVENT_THROW, | |
591f19e8 | 86 | EX_EVENT_RETHROW, |
e7e8980f YQ |
87 | EX_EVENT_CATCH |
88 | }; | |
89 | ||
4a64f543 | 90 | /* Prototypes for local functions. */ |
c906108c | 91 | |
a14ed312 | 92 | static void enable_delete_command (char *, int); |
c906108c | 93 | |
a14ed312 | 94 | static void enable_once_command (char *, int); |
c906108c | 95 | |
816338b5 SS |
96 | static void enable_count_command (char *, int); |
97 | ||
a14ed312 | 98 | static void disable_command (char *, int); |
c906108c | 99 | |
a14ed312 | 100 | static void enable_command (char *, int); |
c906108c | 101 | |
95a42b64 TT |
102 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
103 | void *), | |
104 | void *); | |
c906108c | 105 | |
a14ed312 | 106 | static void ignore_command (char *, int); |
c906108c | 107 | |
4efb68b1 | 108 | static int breakpoint_re_set_one (void *); |
c906108c | 109 | |
348d480f PA |
110 | static void breakpoint_re_set_default (struct breakpoint *); |
111 | ||
983af33b SDJ |
112 | static void create_sals_from_address_default (char **, |
113 | struct linespec_result *, | |
114 | enum bptype, char *, | |
115 | char **); | |
116 | ||
117 | static void create_breakpoints_sal_default (struct gdbarch *, | |
118 | struct linespec_result *, | |
e7e0cddf | 119 | char *, char *, enum bptype, |
983af33b SDJ |
120 | enum bpdisp, int, int, |
121 | int, | |
122 | const struct breakpoint_ops *, | |
44f238bb | 123 | int, int, int, unsigned); |
983af33b SDJ |
124 | |
125 | static void decode_linespec_default (struct breakpoint *, char **, | |
126 | struct symtabs_and_lines *); | |
127 | ||
a14ed312 | 128 | static void clear_command (char *, int); |
c906108c | 129 | |
a14ed312 | 130 | static void catch_command (char *, int); |
c906108c | 131 | |
a9634178 | 132 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 133 | |
98deb0da | 134 | static void break_command_1 (char *, int, int); |
c906108c | 135 | |
a14ed312 | 136 | static void mention (struct breakpoint *); |
c906108c | 137 | |
348d480f PA |
138 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
139 | enum bptype, | |
c0a91b2b | 140 | const struct breakpoint_ops *); |
3742cc8b YQ |
141 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
142 | const struct symtab_and_line *); | |
143 | ||
4a64f543 MS |
144 | /* This function is used in gdbtk sources and thus can not be made |
145 | static. */ | |
63c252f8 | 146 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 147 | struct symtab_and_line, |
c0a91b2b TT |
148 | enum bptype, |
149 | const struct breakpoint_ops *); | |
c906108c | 150 | |
06edf0c0 PA |
151 | static struct breakpoint * |
152 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
153 | enum bptype type, | |
a1aa2221 LM |
154 | const struct breakpoint_ops *ops, |
155 | int loc_enabled); | |
06edf0c0 | 156 | |
76897487 KB |
157 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
158 | ||
a6d9a66e UW |
159 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
160 | CORE_ADDR bpaddr, | |
88f7da05 | 161 | enum bptype bptype); |
76897487 | 162 | |
6c95b8df PA |
163 | static void describe_other_breakpoints (struct gdbarch *, |
164 | struct program_space *, CORE_ADDR, | |
5af949e3 | 165 | struct obj_section *, int); |
c906108c | 166 | |
85d721b8 PA |
167 | static int watchpoint_locations_match (struct bp_location *loc1, |
168 | struct bp_location *loc2); | |
169 | ||
f1310107 TJB |
170 | static int breakpoint_location_address_match (struct bp_location *bl, |
171 | struct address_space *aspace, | |
172 | CORE_ADDR addr); | |
173 | ||
a14ed312 | 174 | static void breakpoints_info (char *, int); |
c906108c | 175 | |
d77f58be SS |
176 | static void watchpoints_info (char *, int); |
177 | ||
e5a67952 MS |
178 | static int breakpoint_1 (char *, int, |
179 | int (*) (const struct breakpoint *)); | |
c906108c | 180 | |
4efb68b1 | 181 | static int breakpoint_cond_eval (void *); |
c906108c | 182 | |
4efb68b1 | 183 | static void cleanup_executing_breakpoints (void *); |
c906108c | 184 | |
a14ed312 | 185 | static void commands_command (char *, int); |
c906108c | 186 | |
a14ed312 | 187 | static void condition_command (char *, int); |
c906108c | 188 | |
c5aa993b JM |
189 | typedef enum |
190 | { | |
191 | mark_inserted, | |
192 | mark_uninserted | |
193 | } | |
194 | insertion_state_t; | |
c906108c | 195 | |
0bde7532 | 196 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 197 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 198 | |
e514a9d6 | 199 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 200 | |
4efb68b1 | 201 | static int watchpoint_check (void *); |
c906108c | 202 | |
a14ed312 | 203 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 204 | |
a14ed312 | 205 | static int hw_breakpoint_used_count (void); |
c906108c | 206 | |
a1398e0c PA |
207 | static int hw_watchpoint_use_count (struct breakpoint *); |
208 | ||
209 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
210 | enum bptype type, | |
211 | int *other_type_used); | |
c906108c | 212 | |
a14ed312 | 213 | static void hbreak_command (char *, int); |
c906108c | 214 | |
a14ed312 | 215 | static void thbreak_command (char *, int); |
c906108c | 216 | |
816338b5 SS |
217 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
218 | int count); | |
c906108c | 219 | |
a14ed312 | 220 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 221 | |
a14ed312 | 222 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 223 | |
a14ed312 | 224 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 225 | |
a14ed312 | 226 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 227 | |
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 | ||
d3ce09f5 SS |
3223 | if (bl->owner->type == bp_dprintf) |
3224 | continue; | |
3225 | ||
35df4500 | 3226 | if (bl->inserted) |
6c95b8df | 3227 | { |
35df4500 | 3228 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
3229 | if (val != 0) |
3230 | return val; | |
3231 | } | |
3232 | } | |
3233 | return 0; | |
3234 | } | |
3235 | ||
c906108c | 3236 | int |
fba45db2 | 3237 | reattach_breakpoints (int pid) |
c906108c | 3238 | { |
6c95b8df | 3239 | struct cleanup *old_chain; |
35df4500 | 3240 | struct bp_location *bl, **blp_tmp; |
c906108c | 3241 | int val; |
86b887df | 3242 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3243 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3244 | struct inferior *inf; |
3245 | struct thread_info *tp; | |
3246 | ||
3247 | tp = any_live_thread_of_process (pid); | |
3248 | if (tp == NULL) | |
3249 | return 1; | |
3250 | ||
3251 | inf = find_inferior_pid (pid); | |
3252 | old_chain = save_inferior_ptid (); | |
3253 | ||
3254 | inferior_ptid = tp->ptid; | |
a4954f26 | 3255 | |
86b887df | 3256 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3257 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3258 | |
35df4500 | 3259 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3260 | { |
35df4500 | 3261 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3262 | continue; |
3263 | ||
35df4500 | 3264 | if (bl->inserted) |
c5aa993b | 3265 | { |
35df4500 | 3266 | bl->inserted = 0; |
dd61ec5c | 3267 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3268 | if (val != 0) |
3269 | { | |
ce696e05 | 3270 | do_cleanups (old_chain); |
c5aa993b JM |
3271 | return val; |
3272 | } | |
3273 | } | |
3274 | } | |
ce696e05 | 3275 | do_cleanups (old_chain); |
c906108c SS |
3276 | return 0; |
3277 | } | |
3278 | ||
e58b0e63 PA |
3279 | static int internal_breakpoint_number = -1; |
3280 | ||
84f4c1fe PM |
3281 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3282 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3283 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3284 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3285 | breakpoint_count and that value incremented. Internal breakpoints |
3286 | do not set the internal var bpnum. */ | |
3287 | static void | |
3288 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3289 | { | |
3290 | if (internal) | |
3291 | b->number = internal_breakpoint_number--; | |
3292 | else | |
3293 | { | |
3294 | set_breakpoint_count (breakpoint_count + 1); | |
3295 | b->number = breakpoint_count; | |
3296 | } | |
3297 | } | |
3298 | ||
e62c965a | 3299 | static struct breakpoint * |
a6d9a66e | 3300 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3301 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3302 | const struct breakpoint_ops *ops) |
e62c965a | 3303 | { |
e62c965a PP |
3304 | struct symtab_and_line sal; |
3305 | struct breakpoint *b; | |
3306 | ||
4a64f543 | 3307 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3308 | |
3309 | sal.pc = address; | |
3310 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3311 | sal.pspace = current_program_space; |
e62c965a | 3312 | |
06edf0c0 | 3313 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3314 | b->number = internal_breakpoint_number--; |
3315 | b->disposition = disp_donttouch; | |
3316 | ||
3317 | return b; | |
3318 | } | |
3319 | ||
17450429 PP |
3320 | static const char *const longjmp_names[] = |
3321 | { | |
3322 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3323 | }; | |
3324 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3325 | ||
3326 | /* Per-objfile data private to breakpoint.c. */ | |
3327 | struct breakpoint_objfile_data | |
3328 | { | |
3329 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3330 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3331 | |
3332 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3333 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3334 | |
28106bc2 SDJ |
3335 | /* True if we have looked for longjmp probes. */ |
3336 | int longjmp_searched; | |
3337 | ||
3338 | /* SystemTap probe points for longjmp (if any). */ | |
3339 | VEC (probe_p) *longjmp_probes; | |
3340 | ||
17450429 | 3341 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3342 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3343 | |
3344 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3345 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3346 | |
3347 | /* True if we have looked for exception probes. */ | |
3348 | int exception_searched; | |
3349 | ||
3350 | /* SystemTap probe points for unwinding (if any). */ | |
3351 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3352 | }; |
3353 | ||
3354 | static const struct objfile_data *breakpoint_objfile_key; | |
3355 | ||
3356 | /* Minimal symbol not found sentinel. */ | |
3357 | static struct minimal_symbol msym_not_found; | |
3358 | ||
3359 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3360 | ||
3361 | static int | |
3362 | msym_not_found_p (const struct minimal_symbol *msym) | |
3363 | { | |
3364 | return msym == &msym_not_found; | |
3365 | } | |
3366 | ||
3367 | /* Return per-objfile data needed by breakpoint.c. | |
3368 | Allocate the data if necessary. */ | |
3369 | ||
3370 | static struct breakpoint_objfile_data * | |
3371 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3372 | { | |
3373 | struct breakpoint_objfile_data *bp_objfile_data; | |
3374 | ||
3375 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
3376 | if (bp_objfile_data == NULL) | |
3377 | { | |
3378 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
3379 | sizeof (*bp_objfile_data)); | |
3380 | ||
3381 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3382 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3383 | } | |
3384 | return bp_objfile_data; | |
3385 | } | |
3386 | ||
28106bc2 SDJ |
3387 | static void |
3388 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3389 | { | |
3390 | struct breakpoint_objfile_data *bp_objfile_data = data; | |
3391 | ||
3392 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3393 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3394 | } | |
3395 | ||
e62c965a | 3396 | static void |
af02033e | 3397 | create_overlay_event_breakpoint (void) |
e62c965a | 3398 | { |
69de3c6a | 3399 | struct objfile *objfile; |
af02033e | 3400 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3401 | |
69de3c6a PP |
3402 | ALL_OBJFILES (objfile) |
3403 | { | |
3404 | struct breakpoint *b; | |
17450429 PP |
3405 | struct breakpoint_objfile_data *bp_objfile_data; |
3406 | CORE_ADDR addr; | |
69de3c6a | 3407 | |
17450429 PP |
3408 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3409 | ||
3b7344d5 | 3410 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3411 | continue; |
3412 | ||
3b7344d5 | 3413 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3414 | { |
3b7344d5 | 3415 | struct bound_minimal_symbol m; |
17450429 PP |
3416 | |
3417 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3418 | if (m.minsym == NULL) |
17450429 PP |
3419 | { |
3420 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3421 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3422 | continue; |
3423 | } | |
3424 | bp_objfile_data->overlay_msym = m; | |
3425 | } | |
e62c965a | 3426 | |
77e371c0 | 3427 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3428 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3429 | bp_overlay_event, |
3430 | &internal_breakpoint_ops); | |
69de3c6a | 3431 | b->addr_string = xstrdup (func_name); |
e62c965a | 3432 | |
69de3c6a PP |
3433 | if (overlay_debugging == ovly_auto) |
3434 | { | |
3435 | b->enable_state = bp_enabled; | |
3436 | overlay_events_enabled = 1; | |
3437 | } | |
3438 | else | |
3439 | { | |
3440 | b->enable_state = bp_disabled; | |
3441 | overlay_events_enabled = 0; | |
3442 | } | |
e62c965a | 3443 | } |
44702360 | 3444 | update_global_location_list (UGLL_MAY_INSERT); |
e62c965a PP |
3445 | } |
3446 | ||
0fd8e87f | 3447 | static void |
af02033e | 3448 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3449 | { |
6c95b8df | 3450 | struct program_space *pspace; |
6c95b8df PA |
3451 | struct cleanup *old_chain; |
3452 | ||
3453 | old_chain = save_current_program_space (); | |
0fd8e87f | 3454 | |
6c95b8df | 3455 | ALL_PSPACES (pspace) |
af02033e PP |
3456 | { |
3457 | struct objfile *objfile; | |
3458 | ||
3459 | set_current_program_space (pspace); | |
3460 | ||
3461 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3462 | { |
af02033e PP |
3463 | int i; |
3464 | struct gdbarch *gdbarch; | |
17450429 | 3465 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3466 | |
af02033e | 3467 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3468 | |
17450429 PP |
3469 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3470 | ||
28106bc2 SDJ |
3471 | if (!bp_objfile_data->longjmp_searched) |
3472 | { | |
25f9533e SDJ |
3473 | VEC (probe_p) *ret; |
3474 | ||
3475 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3476 | if (ret != NULL) | |
3477 | { | |
3478 | /* We are only interested in checking one element. */ | |
3479 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3480 | ||
3481 | if (!can_evaluate_probe_arguments (p)) | |
3482 | { | |
3483 | /* We cannot use the probe interface here, because it does | |
3484 | not know how to evaluate arguments. */ | |
3485 | VEC_free (probe_p, ret); | |
3486 | ret = NULL; | |
3487 | } | |
3488 | } | |
3489 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3490 | bp_objfile_data->longjmp_searched = 1; |
3491 | } | |
3492 | ||
3493 | if (bp_objfile_data->longjmp_probes != NULL) | |
3494 | { | |
3495 | int i; | |
3496 | struct probe *probe; | |
3497 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3498 | ||
3499 | for (i = 0; | |
3500 | VEC_iterate (probe_p, | |
3501 | bp_objfile_data->longjmp_probes, | |
3502 | i, probe); | |
3503 | ++i) | |
3504 | { | |
3505 | struct breakpoint *b; | |
3506 | ||
729662a5 TT |
3507 | b = create_internal_breakpoint (gdbarch, |
3508 | get_probe_address (probe, | |
3509 | objfile), | |
28106bc2 SDJ |
3510 | bp_longjmp_master, |
3511 | &internal_breakpoint_ops); | |
3512 | b->addr_string = xstrdup ("-probe-stap libc:longjmp"); | |
3513 | b->enable_state = bp_disabled; | |
3514 | } | |
3515 | ||
3516 | continue; | |
3517 | } | |
3518 | ||
0569175e TSD |
3519 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3520 | continue; | |
3521 | ||
17450429 | 3522 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3523 | { |
3524 | struct breakpoint *b; | |
af02033e | 3525 | const char *func_name; |
17450429 | 3526 | CORE_ADDR addr; |
6c95b8df | 3527 | |
3b7344d5 | 3528 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3529 | continue; |
0fd8e87f | 3530 | |
17450429 | 3531 | func_name = longjmp_names[i]; |
3b7344d5 | 3532 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3533 | { |
3b7344d5 | 3534 | struct bound_minimal_symbol m; |
17450429 PP |
3535 | |
3536 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3537 | if (m.minsym == NULL) |
17450429 PP |
3538 | { |
3539 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3540 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3541 | continue; |
3542 | } | |
3543 | bp_objfile_data->longjmp_msym[i] = m; | |
3544 | } | |
3545 | ||
77e371c0 | 3546 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3547 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3548 | &internal_breakpoint_ops); | |
af02033e PP |
3549 | b->addr_string = xstrdup (func_name); |
3550 | b->enable_state = bp_disabled; | |
3551 | } | |
0fd8e87f | 3552 | } |
af02033e | 3553 | } |
44702360 | 3554 | update_global_location_list (UGLL_MAY_INSERT); |
6c95b8df PA |
3555 | |
3556 | do_cleanups (old_chain); | |
0fd8e87f UW |
3557 | } |
3558 | ||
af02033e | 3559 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3560 | static void |
af02033e | 3561 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3562 | { |
3563 | struct program_space *pspace; | |
aa7d318d | 3564 | struct cleanup *old_chain; |
af02033e | 3565 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3566 | |
3567 | old_chain = save_current_program_space (); | |
3568 | ||
3569 | ALL_PSPACES (pspace) | |
17450429 PP |
3570 | { |
3571 | struct objfile *objfile; | |
3572 | CORE_ADDR addr; | |
3573 | ||
3574 | set_current_program_space (pspace); | |
3575 | ||
aa7d318d TT |
3576 | ALL_OBJFILES (objfile) |
3577 | { | |
3578 | struct breakpoint *b; | |
17450429 | 3579 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 3580 | |
17450429 | 3581 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3582 | |
3b7344d5 | 3583 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3584 | continue; |
3585 | ||
3b7344d5 | 3586 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3587 | { |
3b7344d5 | 3588 | struct bound_minimal_symbol m; |
17450429 PP |
3589 | |
3590 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3591 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3592 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3593 | { |
3594 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3595 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3596 | continue; |
3597 | } | |
3598 | bp_objfile_data->terminate_msym = m; | |
3599 | } | |
aa7d318d | 3600 | |
77e371c0 | 3601 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3602 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3603 | bp_std_terminate_master, |
3604 | &internal_breakpoint_ops); | |
aa7d318d TT |
3605 | b->addr_string = xstrdup (func_name); |
3606 | b->enable_state = bp_disabled; | |
3607 | } | |
17450429 PP |
3608 | } |
3609 | ||
44702360 | 3610 | update_global_location_list (UGLL_MAY_INSERT); |
aa7d318d TT |
3611 | |
3612 | do_cleanups (old_chain); | |
3613 | } | |
3614 | ||
186c406b TT |
3615 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3616 | ||
70221824 | 3617 | static void |
186c406b TT |
3618 | create_exception_master_breakpoint (void) |
3619 | { | |
3620 | struct objfile *objfile; | |
17450429 | 3621 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3622 | |
3623 | ALL_OBJFILES (objfile) | |
3624 | { | |
17450429 PP |
3625 | struct breakpoint *b; |
3626 | struct gdbarch *gdbarch; | |
3627 | struct breakpoint_objfile_data *bp_objfile_data; | |
3628 | CORE_ADDR addr; | |
3629 | ||
3630 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3631 | ||
28106bc2 SDJ |
3632 | /* We prefer the SystemTap probe point if it exists. */ |
3633 | if (!bp_objfile_data->exception_searched) | |
3634 | { | |
25f9533e SDJ |
3635 | VEC (probe_p) *ret; |
3636 | ||
3637 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3638 | ||
3639 | if (ret != NULL) | |
3640 | { | |
3641 | /* We are only interested in checking one element. */ | |
3642 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3643 | ||
3644 | if (!can_evaluate_probe_arguments (p)) | |
3645 | { | |
3646 | /* We cannot use the probe interface here, because it does | |
3647 | not know how to evaluate arguments. */ | |
3648 | VEC_free (probe_p, ret); | |
3649 | ret = NULL; | |
3650 | } | |
3651 | } | |
3652 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3653 | bp_objfile_data->exception_searched = 1; |
3654 | } | |
3655 | ||
3656 | if (bp_objfile_data->exception_probes != NULL) | |
3657 | { | |
3658 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3659 | int i; | |
3660 | struct probe *probe; | |
3661 | ||
3662 | for (i = 0; | |
3663 | VEC_iterate (probe_p, | |
3664 | bp_objfile_data->exception_probes, | |
3665 | i, probe); | |
3666 | ++i) | |
3667 | { | |
3668 | struct breakpoint *b; | |
3669 | ||
729662a5 TT |
3670 | b = create_internal_breakpoint (gdbarch, |
3671 | get_probe_address (probe, | |
3672 | objfile), | |
28106bc2 SDJ |
3673 | bp_exception_master, |
3674 | &internal_breakpoint_ops); | |
3675 | b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); | |
3676 | b->enable_state = bp_disabled; | |
3677 | } | |
3678 | ||
3679 | continue; | |
3680 | } | |
3681 | ||
3682 | /* Otherwise, try the hook function. */ | |
3683 | ||
3b7344d5 | 3684 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3685 | continue; |
3686 | ||
3687 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3688 | |
3b7344d5 | 3689 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3690 | { |
3b7344d5 | 3691 | struct bound_minimal_symbol debug_hook; |
186c406b | 3692 | |
17450429 | 3693 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3694 | if (debug_hook.minsym == NULL) |
17450429 | 3695 | { |
3b7344d5 | 3696 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3697 | continue; |
3698 | } | |
3699 | ||
3700 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3701 | } |
17450429 | 3702 | |
77e371c0 | 3703 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3704 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3705 | ¤t_target); | |
06edf0c0 PA |
3706 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3707 | &internal_breakpoint_ops); | |
17450429 PP |
3708 | b->addr_string = xstrdup (func_name); |
3709 | b->enable_state = bp_disabled; | |
186c406b TT |
3710 | } |
3711 | ||
44702360 | 3712 | update_global_location_list (UGLL_MAY_INSERT); |
186c406b TT |
3713 | } |
3714 | ||
c906108c | 3715 | void |
fba45db2 | 3716 | update_breakpoints_after_exec (void) |
c906108c | 3717 | { |
35df4500 | 3718 | struct breakpoint *b, *b_tmp; |
876fa593 | 3719 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3720 | |
25b22b0a PA |
3721 | /* We're about to delete breakpoints from GDB's lists. If the |
3722 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3723 | writing the breakpoints' "shadow contents" back into memory. The | |
3724 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3725 | do that. Instead, the target is responsible from marking | |
3726 | breakpoints out as soon as it detects an exec. We don't do that | |
3727 | here instead, because there may be other attempts to delete | |
3728 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3729 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3730 | if (bploc->pspace == current_program_space) |
3731 | gdb_assert (!bploc->inserted); | |
c906108c | 3732 | |
35df4500 | 3733 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3734 | { |
6c95b8df PA |
3735 | if (b->pspace != current_program_space) |
3736 | continue; | |
3737 | ||
4a64f543 | 3738 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3739 | if (b->type == bp_shlib_event) |
3740 | { | |
3741 | delete_breakpoint (b); | |
3742 | continue; | |
3743 | } | |
c906108c | 3744 | |
4a64f543 | 3745 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3746 | if (b->type == bp_jit_event) |
3747 | { | |
3748 | delete_breakpoint (b); | |
3749 | continue; | |
3750 | } | |
3751 | ||
1900040c | 3752 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3753 | as must overlay event and longjmp master breakpoints. */ |
3754 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3755 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3756 | || b->type == bp_exception_master) | |
c4093a6a JM |
3757 | { |
3758 | delete_breakpoint (b); | |
3759 | continue; | |
3760 | } | |
3761 | ||
4a64f543 | 3762 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3763 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3764 | { |
3765 | delete_breakpoint (b); | |
3766 | continue; | |
3767 | } | |
3768 | ||
7c16b83e PA |
3769 | /* Just like single-step breakpoints. */ |
3770 | if (b->type == bp_single_step) | |
3771 | { | |
3772 | delete_breakpoint (b); | |
3773 | continue; | |
3774 | } | |
3775 | ||
611c83ae PA |
3776 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3777 | after an exec. */ | |
186c406b | 3778 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3779 | || b->type == bp_longjmp_call_dummy |
186c406b | 3780 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3781 | { |
3782 | delete_breakpoint (b); | |
3783 | continue; | |
3784 | } | |
3785 | ||
ce78b96d JB |
3786 | if (b->type == bp_catchpoint) |
3787 | { | |
3788 | /* For now, none of the bp_catchpoint breakpoints need to | |
3789 | do anything at this point. In the future, if some of | |
3790 | the catchpoints need to something, we will need to add | |
3791 | a new method, and call this method from here. */ | |
3792 | continue; | |
3793 | } | |
3794 | ||
c5aa993b JM |
3795 | /* bp_finish is a special case. The only way we ought to be able |
3796 | to see one of these when an exec() has happened, is if the user | |
3797 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3798 | carries them to the call-site of the current callee, by setting | |
3799 | a temporary bp there and resuming. But in this case, the finish | |
3800 | will carry them entirely through the vfork & exec. | |
3801 | ||
3802 | We don't want to allow a bp_finish to remain inserted now. But | |
3803 | we can't safely delete it, 'cause finish_command has a handle to | |
3804 | the bp on a bpstat, and will later want to delete it. There's a | |
3805 | chance (and I've seen it happen) that if we delete the bp_finish | |
3806 | here, that its storage will get reused by the time finish_command | |
3807 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3808 | We really must allow finish_command to delete a bp_finish. | |
3809 | ||
e5dd4106 | 3810 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3811 | it's safe to delete something others may have handles to?" |
3812 | problem, what we'll do here is just uninsert the bp_finish, and | |
3813 | let finish_command delete it. | |
3814 | ||
3815 | (We know the bp_finish is "doomed" in the sense that it's | |
3816 | momentary, and will be deleted as soon as finish_command sees | |
3817 | the inferior stopped. So it doesn't matter that the bp's | |
3818 | address is probably bogus in the new a.out, unlike e.g., the | |
3819 | solib breakpoints.) */ | |
c5aa993b | 3820 | |
c5aa993b JM |
3821 | if (b->type == bp_finish) |
3822 | { | |
3823 | continue; | |
3824 | } | |
3825 | ||
3826 | /* Without a symbolic address, we have little hope of the | |
3827 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3828 | a.out. */ |
c5aa993b JM |
3829 | if (b->addr_string == NULL) |
3830 | { | |
3831 | delete_breakpoint (b); | |
3832 | continue; | |
3833 | } | |
c5aa993b | 3834 | } |
c906108c SS |
3835 | } |
3836 | ||
3837 | int | |
d80ee84f | 3838 | detach_breakpoints (ptid_t ptid) |
c906108c | 3839 | { |
35df4500 | 3840 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3841 | int val = 0; |
ce696e05 | 3842 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3843 | struct inferior *inf = current_inferior (); |
c5aa993b | 3844 | |
dfd4cc63 | 3845 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3846 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3847 | |
6c95b8df | 3848 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3849 | inferior_ptid = ptid; |
35df4500 | 3850 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3851 | { |
35df4500 | 3852 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3853 | continue; |
3854 | ||
bd9673a4 PW |
3855 | /* This function must physically remove breakpoints locations |
3856 | from the specified ptid, without modifying the breakpoint | |
3857 | package's state. Locations of type bp_loc_other are only | |
3858 | maintained at GDB side. So, there is no need to remove | |
3859 | these bp_loc_other locations. Moreover, removing these | |
3860 | would modify the breakpoint package's state. */ | |
3861 | if (bl->loc_type == bp_loc_other) | |
3862 | continue; | |
3863 | ||
35df4500 TJB |
3864 | if (bl->inserted) |
3865 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3866 | } |
d03285ec | 3867 | |
ce696e05 | 3868 | do_cleanups (old_chain); |
3a1bae8e | 3869 | return val; |
c906108c SS |
3870 | } |
3871 | ||
35df4500 | 3872 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3873 | Note that this is used to detach breakpoints from a child fork. |
3874 | When we get here, the child isn't in the inferior list, and neither | |
3875 | do we have objects to represent its address space --- we should | |
35df4500 | 3876 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3877 | |
c906108c | 3878 | static int |
35df4500 | 3879 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3880 | { |
3881 | int val; | |
c5aa993b | 3882 | |
35df4500 TJB |
3883 | /* BL is never in moribund_locations by our callers. */ |
3884 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3885 | |
1a853c52 | 3886 | if (bl->permanent) |
c2c6d25f JM |
3887 | /* Permanent breakpoints cannot be inserted or removed. */ |
3888 | return 0; | |
3889 | ||
74960c60 VP |
3890 | /* The type of none suggests that owner is actually deleted. |
3891 | This should not ever happen. */ | |
35df4500 | 3892 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3893 | |
35df4500 TJB |
3894 | if (bl->loc_type == bp_loc_software_breakpoint |
3895 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3896 | { |
c02f5703 MS |
3897 | /* "Normal" instruction breakpoint: either the standard |
3898 | trap-instruction bp (bp_breakpoint), or a | |
3899 | bp_hardware_breakpoint. */ | |
3900 | ||
3901 | /* First check to see if we have to handle an overlay. */ | |
3902 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3903 | || bl->section == NULL |
3904 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3905 | { |
3906 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3907 | |
3908 | /* If we're trying to uninsert a memory breakpoint that we | |
3909 | know is set in a dynamic object that is marked | |
3910 | shlib_disabled, then either the dynamic object was | |
3911 | removed with "remove-symbol-file" or with | |
3912 | "nosharedlibrary". In the former case, we don't know | |
3913 | whether another dynamic object might have loaded over the | |
3914 | breakpoint's address -- the user might well let us know | |
3915 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3916 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3917 | list of dynamically loaded objects). If we have the |
3918 | breakpoint's shadow memory, that is, this is a software | |
3919 | breakpoint managed by GDB, check whether the breakpoint | |
3920 | is still inserted in memory, to avoid overwriting wrong | |
3921 | code with stale saved shadow contents. Note that HW | |
3922 | breakpoints don't have shadow memory, as they're | |
3923 | implemented using a mechanism that is not dependent on | |
3924 | being able to modify the target's memory, and as such | |
3925 | they should always be removed. */ | |
3926 | if (bl->shlib_disabled | |
3927 | && bl->target_info.shadow_len != 0 | |
3928 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3929 | val = 0; | |
3930 | else | |
3931 | val = bl->owner->ops->remove_location (bl); | |
c02f5703 | 3932 | } |
c906108c SS |
3933 | else |
3934 | { | |
4a64f543 | 3935 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3936 | Did we set a breakpoint at the LMA? */ |
3937 | if (!overlay_events_enabled) | |
3938 | { | |
3939 | /* Yes -- overlay event support is not active, so we | |
3940 | should have set a breakpoint at the LMA. Remove it. | |
3941 | */ | |
c02f5703 MS |
3942 | /* Ignore any failures: if the LMA is in ROM, we will |
3943 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3944 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3945 | target_remove_hw_breakpoint (bl->gdbarch, | |
3946 | &bl->overlay_target_info); | |
c02f5703 | 3947 | else |
35df4500 TJB |
3948 | target_remove_breakpoint (bl->gdbarch, |
3949 | &bl->overlay_target_info); | |
c02f5703 MS |
3950 | } |
3951 | /* Did we set a breakpoint at the VMA? | |
3952 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3953 | if (bl->inserted) |
c906108c | 3954 | { |
c02f5703 MS |
3955 | /* Yes -- remove it. Previously we did not bother to |
3956 | remove the breakpoint if the section had been | |
3957 | unmapped, but let's not rely on that being safe. We | |
3958 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3959 | |
3960 | /* However, we should remove *software* breakpoints only | |
3961 | if the section is still mapped, or else we overwrite | |
3962 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3963 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3964 | || section_is_mapped (bl->section)) | |
3965 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
3966 | else |
3967 | val = 0; | |
c906108c | 3968 | } |
c02f5703 MS |
3969 | else |
3970 | { | |
3971 | /* No -- not inserted, so no need to remove. No error. */ | |
3972 | val = 0; | |
3973 | } | |
c906108c | 3974 | } |
879d1e6b | 3975 | |
08351840 PA |
3976 | /* In some cases, we might not be able to remove a breakpoint in |
3977 | a shared library that has already been removed, but we have | |
3978 | not yet processed the shlib unload event. Similarly for an | |
3979 | unloaded add-symbol-file object - the user might not yet have | |
3980 | had the chance to remove-symbol-file it. shlib_disabled will | |
3981 | be set if the library/object has already been removed, but | |
3982 | the breakpoint hasn't been uninserted yet, e.g., after | |
3983 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3984 | always-inserted mode. */ | |
076855f9 | 3985 | if (val |
08351840 PA |
3986 | && (bl->loc_type == bp_loc_software_breakpoint |
3987 | && (bl->shlib_disabled | |
3988 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3989 | || shared_objfile_contains_address_p (bl->pspace, |
3990 | bl->address)))) | |
879d1e6b UW |
3991 | val = 0; |
3992 | ||
c906108c SS |
3993 | if (val) |
3994 | return val; | |
35df4500 | 3995 | bl->inserted = (is == mark_inserted); |
c906108c | 3996 | } |
35df4500 | 3997 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3998 | { |
77b06cd7 TJB |
3999 | gdb_assert (bl->owner->ops != NULL |
4000 | && bl->owner->ops->remove_location != NULL); | |
4001 | ||
35df4500 | 4002 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 4003 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 4004 | |
c906108c | 4005 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 4006 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 4007 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4008 | bl->owner->number); |
c906108c | 4009 | } |
35df4500 TJB |
4010 | else if (bl->owner->type == bp_catchpoint |
4011 | && breakpoint_enabled (bl->owner) | |
4012 | && !bl->duplicate) | |
ce78b96d | 4013 | { |
77b06cd7 TJB |
4014 | gdb_assert (bl->owner->ops != NULL |
4015 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4016 | |
77b06cd7 | 4017 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
4018 | if (val) |
4019 | return val; | |
77b06cd7 | 4020 | |
35df4500 | 4021 | bl->inserted = (is == mark_inserted); |
ce78b96d | 4022 | } |
c906108c SS |
4023 | |
4024 | return 0; | |
4025 | } | |
4026 | ||
6c95b8df | 4027 | static int |
35df4500 | 4028 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
4029 | { |
4030 | int ret; | |
4031 | struct cleanup *old_chain; | |
4032 | ||
35df4500 TJB |
4033 | /* BL is never in moribund_locations by our callers. */ |
4034 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4035 | |
1a853c52 | 4036 | if (bl->permanent) |
6c95b8df PA |
4037 | /* Permanent breakpoints cannot be inserted or removed. */ |
4038 | return 0; | |
4039 | ||
4040 | /* The type of none suggests that owner is actually deleted. | |
4041 | This should not ever happen. */ | |
35df4500 | 4042 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4043 | |
4044 | old_chain = save_current_space_and_thread (); | |
4045 | ||
35df4500 | 4046 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4047 | |
35df4500 | 4048 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
4049 | |
4050 | do_cleanups (old_chain); | |
4051 | return ret; | |
4052 | } | |
4053 | ||
c906108c SS |
4054 | /* Clear the "inserted" flag in all breakpoints. */ |
4055 | ||
25b22b0a | 4056 | void |
fba45db2 | 4057 | mark_breakpoints_out (void) |
c906108c | 4058 | { |
35df4500 | 4059 | struct bp_location *bl, **blp_tmp; |
c906108c | 4060 | |
35df4500 | 4061 | ALL_BP_LOCATIONS (bl, blp_tmp) |
1a853c52 PA |
4062 | if (bl->pspace == current_program_space |
4063 | && !bl->permanent) | |
35df4500 | 4064 | bl->inserted = 0; |
c906108c SS |
4065 | } |
4066 | ||
53a5351d JM |
4067 | /* Clear the "inserted" flag in all breakpoints and delete any |
4068 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4069 | |
4070 | Plus other such housekeeping that has to be done for breakpoints | |
4071 | between runs. | |
4072 | ||
53a5351d JM |
4073 | Note: this function gets called at the end of a run (by |
4074 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4075 | init_wait_for_inferior). */ |
c906108c SS |
4076 | |
4077 | ||
4078 | ||
4079 | void | |
fba45db2 | 4080 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4081 | { |
35df4500 TJB |
4082 | struct breakpoint *b, *b_tmp; |
4083 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 4084 | int ix; |
6c95b8df | 4085 | struct program_space *pspace = current_program_space; |
c906108c | 4086 | |
50c71eaf PA |
4087 | /* If breakpoint locations are shared across processes, then there's |
4088 | nothing to do. */ | |
f5656ead | 4089 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4090 | return; |
4091 | ||
1a853c52 | 4092 | mark_breakpoints_out (); |
075f6582 | 4093 | |
35df4500 | 4094 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4095 | { |
6c95b8df PA |
4096 | if (b->loc && b->loc->pspace != pspace) |
4097 | continue; | |
4098 | ||
c5aa993b JM |
4099 | switch (b->type) |
4100 | { | |
4101 | case bp_call_dummy: | |
e2e4d78b | 4102 | case bp_longjmp_call_dummy: |
c906108c | 4103 | |
c5aa993b | 4104 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4105 | cause problems when the inferior is rerun, so we better get |
4106 | rid of it. */ | |
4107 | ||
4108 | case bp_watchpoint_scope: | |
4109 | ||
4110 | /* Also get rid of scope breakpoints. */ | |
4111 | ||
4112 | case bp_shlib_event: | |
4113 | ||
4114 | /* Also remove solib event breakpoints. Their addresses may | |
4115 | have changed since the last time we ran the program. | |
4116 | Actually we may now be debugging against different target; | |
4117 | and so the solib backend that installed this breakpoint may | |
4118 | not be used in by the target. E.g., | |
4119 | ||
4120 | (gdb) file prog-linux | |
4121 | (gdb) run # native linux target | |
4122 | ... | |
4123 | (gdb) kill | |
4124 | (gdb) file prog-win.exe | |
4125 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4126 | */ | |
c906108c | 4127 | |
f59f708a PA |
4128 | case bp_step_resume: |
4129 | ||
4130 | /* Also remove step-resume breakpoints. */ | |
4131 | ||
7c16b83e PA |
4132 | case bp_single_step: |
4133 | ||
4134 | /* Also remove single-step breakpoints. */ | |
4135 | ||
c5aa993b JM |
4136 | delete_breakpoint (b); |
4137 | break; | |
c906108c | 4138 | |
c5aa993b JM |
4139 | case bp_watchpoint: |
4140 | case bp_hardware_watchpoint: | |
4141 | case bp_read_watchpoint: | |
4142 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4143 | { |
4144 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4145 | |
3a5c3e22 PA |
4146 | /* Likewise for watchpoints on local expressions. */ |
4147 | if (w->exp_valid_block != NULL) | |
4148 | delete_breakpoint (b); | |
4149 | else if (context == inf_starting) | |
4150 | { | |
4151 | /* Reset val field to force reread of starting value in | |
4152 | insert_breakpoints. */ | |
4153 | if (w->val) | |
4154 | value_free (w->val); | |
4155 | w->val = NULL; | |
4156 | w->val_valid = 0; | |
c860120c | 4157 | } |
3a5c3e22 | 4158 | } |
c5aa993b JM |
4159 | break; |
4160 | default: | |
c5aa993b JM |
4161 | break; |
4162 | } | |
4163 | } | |
1c5cfe86 PA |
4164 | |
4165 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4166 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4167 | decref_bp_location (&bl); | |
1c5cfe86 | 4168 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4169 | } |
4170 | ||
6c95b8df PA |
4171 | /* These functions concern about actual breakpoints inserted in the |
4172 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4173 | we need to hop over the bkpt --- so we check for address space | |
4174 | match, not program space. */ | |
4175 | ||
c2c6d25f JM |
4176 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4177 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4178 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4179 | permanent breakpoint. | |
4180 | - When continuing from a location with an ordinary breakpoint, we | |
4181 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4182 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4183 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4184 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4185 | |
c2c6d25f | 4186 | enum breakpoint_here |
6c95b8df | 4187 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4188 | { |
35df4500 | 4189 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4190 | int any_breakpoint_here = 0; |
c906108c | 4191 | |
35df4500 | 4192 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4193 | { |
35df4500 TJB |
4194 | if (bl->loc_type != bp_loc_software_breakpoint |
4195 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4196 | continue; |
4197 | ||
f1310107 | 4198 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4199 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4200 | || bl->permanent) |
f1310107 | 4201 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4202 | { |
4203 | if (overlay_debugging | |
35df4500 TJB |
4204 | && section_is_overlay (bl->section) |
4205 | && !section_is_mapped (bl->section)) | |
075f6582 | 4206 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4207 | else if (bl->permanent) |
075f6582 DJ |
4208 | return permanent_breakpoint_here; |
4209 | else | |
4210 | any_breakpoint_here = 1; | |
4211 | } | |
4212 | } | |
c906108c | 4213 | |
c2c6d25f | 4214 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
4215 | } |
4216 | ||
1c5cfe86 PA |
4217 | /* Return true if there's a moribund breakpoint at PC. */ |
4218 | ||
4219 | int | |
6c95b8df | 4220 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4221 | { |
4222 | struct bp_location *loc; | |
4223 | int ix; | |
4224 | ||
4225 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4226 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4227 | return 1; |
4228 | ||
4229 | return 0; | |
4230 | } | |
c2c6d25f | 4231 | |
a1fd2fa5 | 4232 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4233 | |
4234 | int | |
a1fd2fa5 | 4235 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4236 | { |
35df4500 | 4237 | struct bp_location *bl, **blp_tmp; |
c906108c | 4238 | |
35df4500 | 4239 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 4240 | { |
35df4500 TJB |
4241 | if (bl->loc_type != bp_loc_software_breakpoint |
4242 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4243 | continue; |
4244 | ||
35df4500 | 4245 | if (bl->inserted |
f1310107 | 4246 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4247 | { |
4248 | if (overlay_debugging | |
35df4500 TJB |
4249 | && section_is_overlay (bl->section) |
4250 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
4251 | continue; /* unmapped overlay -- can't be a match */ |
4252 | else | |
4253 | return 1; | |
4254 | } | |
c5aa993b | 4255 | } |
c36b740a VP |
4256 | return 0; |
4257 | } | |
4258 | ||
a1fd2fa5 PA |
4259 | /* This function returns non-zero iff there is a software breakpoint |
4260 | inserted at PC. */ | |
c36b740a VP |
4261 | |
4262 | int | |
a1fd2fa5 PA |
4263 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4264 | CORE_ADDR pc) | |
4fa8626c | 4265 | { |
35df4500 | 4266 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 4267 | |
35df4500 | 4268 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 4269 | { |
35df4500 | 4270 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4271 | continue; |
4272 | ||
35df4500 TJB |
4273 | if (bl->inserted |
4274 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 4275 | aspace, pc)) |
4fa8626c DJ |
4276 | { |
4277 | if (overlay_debugging | |
35df4500 TJB |
4278 | && section_is_overlay (bl->section) |
4279 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
4280 | continue; /* unmapped overlay -- can't be a match */ |
4281 | else | |
a1fd2fa5 | 4282 | return 1; |
4fa8626c DJ |
4283 | } |
4284 | } | |
4285 | ||
4286 | return 0; | |
4287 | } | |
4288 | ||
9093389c PA |
4289 | int |
4290 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4291 | CORE_ADDR addr, ULONGEST len) | |
4292 | { | |
4293 | struct breakpoint *bpt; | |
4294 | ||
4295 | ALL_BREAKPOINTS (bpt) | |
4296 | { | |
4297 | struct bp_location *loc; | |
4298 | ||
4299 | if (bpt->type != bp_hardware_watchpoint | |
4300 | && bpt->type != bp_access_watchpoint) | |
4301 | continue; | |
4302 | ||
4303 | if (!breakpoint_enabled (bpt)) | |
4304 | continue; | |
4305 | ||
4306 | for (loc = bpt->loc; loc; loc = loc->next) | |
4307 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4308 | { | |
4309 | CORE_ADDR l, h; | |
4310 | ||
4311 | /* Check for intersection. */ | |
4312 | l = max (loc->address, addr); | |
4313 | h = min (loc->address + loc->length, addr + len); | |
4314 | if (l < h) | |
4315 | return 1; | |
4316 | } | |
4317 | } | |
4318 | return 0; | |
4319 | } | |
c906108c | 4320 | \f |
c5aa993b | 4321 | |
c906108c SS |
4322 | /* bpstat stuff. External routines' interfaces are documented |
4323 | in breakpoint.h. */ | |
4324 | ||
4325 | int | |
c326b90e | 4326 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4327 | { |
533be4dd | 4328 | return (ep->type == bp_catchpoint); |
c906108c SS |
4329 | } |
4330 | ||
f431efe5 PA |
4331 | /* Frees any storage that is part of a bpstat. Does not walk the |
4332 | 'next' chain. */ | |
4333 | ||
4334 | static void | |
198757a8 VP |
4335 | bpstat_free (bpstat bs) |
4336 | { | |
4337 | if (bs->old_val != NULL) | |
4338 | value_free (bs->old_val); | |
9add0f1b | 4339 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4340 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4341 | xfree (bs); |
4342 | } | |
4343 | ||
c906108c SS |
4344 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4345 | Also free any storage that is part of a bpstat. */ | |
4346 | ||
4347 | void | |
fba45db2 | 4348 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4349 | { |
4350 | bpstat p; | |
4351 | bpstat q; | |
4352 | ||
4353 | if (bsp == 0) | |
4354 | return; | |
4355 | p = *bsp; | |
4356 | while (p != NULL) | |
4357 | { | |
4358 | q = p->next; | |
198757a8 | 4359 | bpstat_free (p); |
c906108c SS |
4360 | p = q; |
4361 | } | |
4362 | *bsp = NULL; | |
4363 | } | |
4364 | ||
4365 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4366 | is part of the bpstat is copied as well. */ | |
4367 | ||
4368 | bpstat | |
fba45db2 | 4369 | bpstat_copy (bpstat bs) |
c906108c SS |
4370 | { |
4371 | bpstat p = NULL; | |
4372 | bpstat tmp; | |
4373 | bpstat retval = NULL; | |
4374 | ||
4375 | if (bs == NULL) | |
4376 | return bs; | |
4377 | ||
4378 | for (; bs != NULL; bs = bs->next) | |
4379 | { | |
4380 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4381 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4382 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4383 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4384 | if (bs->old_val != NULL) |
3c3185ac JK |
4385 | { |
4386 | tmp->old_val = value_copy (bs->old_val); | |
4387 | release_value (tmp->old_val); | |
4388 | } | |
31cc81e9 | 4389 | |
c906108c SS |
4390 | if (p == NULL) |
4391 | /* This is the first thing in the chain. */ | |
4392 | retval = tmp; | |
4393 | else | |
4394 | p->next = tmp; | |
4395 | p = tmp; | |
4396 | } | |
4397 | p->next = NULL; | |
4398 | return retval; | |
4399 | } | |
4400 | ||
4a64f543 | 4401 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4402 | |
4403 | bpstat | |
fba45db2 | 4404 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4405 | { |
c5aa993b JM |
4406 | if (bsp == NULL) |
4407 | return NULL; | |
c906108c | 4408 | |
c5aa993b JM |
4409 | for (; bsp != NULL; bsp = bsp->next) |
4410 | { | |
f431efe5 | 4411 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4412 | return bsp; |
4413 | } | |
c906108c SS |
4414 | return NULL; |
4415 | } | |
4416 | ||
ab04a2af TT |
4417 | /* See breakpoint.h. */ |
4418 | ||
47591c29 | 4419 | int |
427cd150 | 4420 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4421 | { |
ab04a2af TT |
4422 | for (; bsp != NULL; bsp = bsp->next) |
4423 | { | |
427cd150 TT |
4424 | if (bsp->breakpoint_at == NULL) |
4425 | { | |
4426 | /* A moribund location can never explain a signal other than | |
4427 | GDB_SIGNAL_TRAP. */ | |
4428 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4429 | return 1; |
427cd150 TT |
4430 | } |
4431 | else | |
47591c29 PA |
4432 | { |
4433 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4434 | sig)) | |
4435 | return 1; | |
4436 | } | |
ab04a2af TT |
4437 | } |
4438 | ||
47591c29 | 4439 | return 0; |
ab04a2af TT |
4440 | } |
4441 | ||
4a64f543 MS |
4442 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4443 | stopped at. *BSP upon return is a bpstat which points to the | |
4444 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4445 | good for anything but further calls to bpstat_num). | |
4446 | ||
8671a17b PA |
4447 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4448 | Return -1 if stopped at a breakpoint that has been deleted since | |
4449 | we set it. | |
4450 | Return 1 otherwise. */ | |
c906108c SS |
4451 | |
4452 | int | |
8671a17b | 4453 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4454 | { |
4455 | struct breakpoint *b; | |
4456 | ||
4457 | if ((*bsp) == NULL) | |
4458 | return 0; /* No more breakpoint values */ | |
8671a17b | 4459 | |
4a64f543 MS |
4460 | /* We assume we'll never have several bpstats that correspond to a |
4461 | single breakpoint -- otherwise, this function might return the | |
4462 | same number more than once and this will look ugly. */ | |
f431efe5 | 4463 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4464 | *bsp = (*bsp)->next; |
4465 | if (b == NULL) | |
4466 | return -1; /* breakpoint that's been deleted since */ | |
4467 | ||
4468 | *num = b->number; /* We have its number */ | |
4469 | return 1; | |
c906108c SS |
4470 | } |
4471 | ||
e93ca019 | 4472 | /* See breakpoint.h. */ |
c906108c SS |
4473 | |
4474 | void | |
e93ca019 | 4475 | bpstat_clear_actions (void) |
c906108c | 4476 | { |
e93ca019 JK |
4477 | struct thread_info *tp; |
4478 | bpstat bs; | |
4479 | ||
4480 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4481 | return; | |
4482 | ||
4483 | tp = find_thread_ptid (inferior_ptid); | |
4484 | if (tp == NULL) | |
4485 | return; | |
4486 | ||
4487 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4488 | { |
9add0f1b | 4489 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4490 | |
c906108c SS |
4491 | if (bs->old_val != NULL) |
4492 | { | |
4493 | value_free (bs->old_val); | |
4494 | bs->old_val = NULL; | |
4495 | } | |
4496 | } | |
4497 | } | |
4498 | ||
f3b1572e PA |
4499 | /* Called when a command is about to proceed the inferior. */ |
4500 | ||
4501 | static void | |
4502 | breakpoint_about_to_proceed (void) | |
4503 | { | |
4504 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4505 | { | |
4506 | struct thread_info *tp = inferior_thread (); | |
4507 | ||
4508 | /* Allow inferior function calls in breakpoint commands to not | |
4509 | interrupt the command list. When the call finishes | |
4510 | successfully, the inferior will be standing at the same | |
4511 | breakpoint as if nothing happened. */ | |
16c381f0 | 4512 | if (tp->control.in_infcall) |
f3b1572e PA |
4513 | return; |
4514 | } | |
4515 | ||
4516 | breakpoint_proceeded = 1; | |
4517 | } | |
4518 | ||
4a64f543 MS |
4519 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4520 | command. */ | |
c906108c | 4521 | static void |
4efb68b1 | 4522 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4523 | { |
4524 | executing_breakpoint_commands = 0; | |
4525 | } | |
4526 | ||
abf85f46 JK |
4527 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4528 | or its equivalent. */ | |
4529 | ||
4530 | static int | |
4531 | command_line_is_silent (struct command_line *cmd) | |
4532 | { | |
4533 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
4534 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
4535 | } | |
4536 | ||
4a64f543 MS |
4537 | /* Execute all the commands associated with all the breakpoints at |
4538 | this location. Any of these commands could cause the process to | |
4539 | proceed beyond this point, etc. We look out for such changes by | |
4540 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4541 | |
347bddb7 PA |
4542 | Returns true if a breakpoint command resumed the inferior. In that |
4543 | case, it is the caller's responsibility to recall it again with the | |
4544 | bpstat of the current thread. */ | |
4545 | ||
4546 | static int | |
4547 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4548 | { |
4549 | bpstat bs; | |
4550 | struct cleanup *old_chain; | |
347bddb7 | 4551 | int again = 0; |
c906108c SS |
4552 | |
4553 | /* Avoid endless recursion if a `source' command is contained | |
4554 | in bs->commands. */ | |
4555 | if (executing_breakpoint_commands) | |
347bddb7 | 4556 | return 0; |
c906108c SS |
4557 | |
4558 | executing_breakpoint_commands = 1; | |
4559 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4560 | ||
cf6c5ffb TT |
4561 | prevent_dont_repeat (); |
4562 | ||
4a64f543 | 4563 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4564 | bs = *bsp; |
4565 | ||
4566 | breakpoint_proceeded = 0; | |
4567 | for (; bs != NULL; bs = bs->next) | |
4568 | { | |
9add0f1b | 4569 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4570 | struct command_line *cmd; |
4571 | struct cleanup *this_cmd_tree_chain; | |
4572 | ||
4573 | /* Take ownership of the BSP's command tree, if it has one. | |
4574 | ||
4575 | The command tree could legitimately contain commands like | |
4576 | 'step' and 'next', which call clear_proceed_status, which | |
4577 | frees stop_bpstat's command tree. To make sure this doesn't | |
4578 | free the tree we're executing out from under us, we need to | |
4579 | take ownership of the tree ourselves. Since a given bpstat's | |
4580 | commands are only executed once, we don't need to copy it; we | |
4581 | can clear the pointer in the bpstat, and make sure we free | |
4582 | the tree when we're done. */ | |
9add0f1b TT |
4583 | ccmd = bs->commands; |
4584 | bs->commands = NULL; | |
abf85f46 JK |
4585 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4586 | cmd = ccmd ? ccmd->commands : NULL; | |
4587 | if (command_line_is_silent (cmd)) | |
4588 | { | |
4589 | /* The action has been already done by bpstat_stop_status. */ | |
4590 | cmd = cmd->next; | |
4591 | } | |
6c50ab1c | 4592 | |
c906108c SS |
4593 | while (cmd != NULL) |
4594 | { | |
4595 | execute_control_command (cmd); | |
4596 | ||
4597 | if (breakpoint_proceeded) | |
4598 | break; | |
4599 | else | |
4600 | cmd = cmd->next; | |
4601 | } | |
6c50ab1c JB |
4602 | |
4603 | /* We can free this command tree now. */ | |
4604 | do_cleanups (this_cmd_tree_chain); | |
4605 | ||
c906108c | 4606 | if (breakpoint_proceeded) |
32c1e744 VP |
4607 | { |
4608 | if (target_can_async_p ()) | |
347bddb7 PA |
4609 | /* If we are in async mode, then the target might be still |
4610 | running, not stopped at any breakpoint, so nothing for | |
4611 | us to do here -- just return to the event loop. */ | |
4612 | ; | |
32c1e744 VP |
4613 | else |
4614 | /* In sync mode, when execute_control_command returns | |
4615 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4616 | Breakpoint commands for that stop were not run, since |
4617 | execute_command does not run breakpoint commands -- | |
4618 | only command_line_handler does, but that one is not | |
4619 | involved in execution of breakpoint commands. So, we | |
4620 | can now execute breakpoint commands. It should be | |
4621 | noted that making execute_command do bpstat actions is | |
4622 | not an option -- in this case we'll have recursive | |
4623 | invocation of bpstat for each breakpoint with a | |
4624 | command, and can easily blow up GDB stack. Instead, we | |
4625 | return true, which will trigger the caller to recall us | |
4626 | with the new stop_bpstat. */ | |
4627 | again = 1; | |
4628 | break; | |
32c1e744 | 4629 | } |
c906108c | 4630 | } |
c2b8ed2c | 4631 | do_cleanups (old_chain); |
347bddb7 PA |
4632 | return again; |
4633 | } | |
4634 | ||
4635 | void | |
4636 | bpstat_do_actions (void) | |
4637 | { | |
353d1d73 JK |
4638 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4639 | ||
347bddb7 PA |
4640 | /* Do any commands attached to breakpoint we are stopped at. */ |
4641 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4642 | && target_has_execution | |
4643 | && !is_exited (inferior_ptid) | |
4644 | && !is_executing (inferior_ptid)) | |
4645 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4646 | and only return when it is stopped at the next breakpoint, we | |
4647 | keep doing breakpoint actions until it returns false to | |
4648 | indicate the inferior was not resumed. */ | |
16c381f0 | 4649 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4650 | break; |
353d1d73 JK |
4651 | |
4652 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4653 | } |
4654 | ||
fa4727a6 DJ |
4655 | /* Print out the (old or new) value associated with a watchpoint. */ |
4656 | ||
4657 | static void | |
4658 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4659 | { | |
4660 | if (val == NULL) | |
4661 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4662 | else | |
79a45b7d TT |
4663 | { |
4664 | struct value_print_options opts; | |
4665 | get_user_print_options (&opts); | |
4666 | value_print (val, stream, &opts); | |
4667 | } | |
fa4727a6 DJ |
4668 | } |
4669 | ||
e514a9d6 | 4670 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4671 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4672 | 'print_it' in the bpstat structure. Under some circumstances we |
4673 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4674 | normal_stop(). */ |
e514a9d6 JM |
4675 | |
4676 | static enum print_stop_action | |
4677 | print_bp_stop_message (bpstat bs) | |
4678 | { | |
4679 | switch (bs->print_it) | |
4680 | { | |
4681 | case print_it_noop: | |
4a64f543 | 4682 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4683 | return PRINT_UNKNOWN; |
4684 | break; | |
4685 | ||
4686 | case print_it_done: | |
4687 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4688 | relevant messages. */ |
e514a9d6 JM |
4689 | return PRINT_SRC_AND_LOC; |
4690 | break; | |
4691 | ||
4692 | case print_it_normal: | |
4f8d1dc6 | 4693 | { |
f431efe5 PA |
4694 | struct breakpoint *b = bs->breakpoint_at; |
4695 | ||
1a6a67de TJB |
4696 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4697 | which has since been deleted. */ | |
4698 | if (b == NULL) | |
4699 | return PRINT_UNKNOWN; | |
4700 | ||
348d480f PA |
4701 | /* Normal case. Call the breakpoint's print_it method. */ |
4702 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4703 | } |
348d480f | 4704 | break; |
3086aeae | 4705 | |
e514a9d6 | 4706 | default: |
8e65ff28 | 4707 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4708 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4709 | break; |
c906108c | 4710 | } |
c906108c SS |
4711 | } |
4712 | ||
edcc5120 TT |
4713 | /* A helper function that prints a shared library stopped event. */ |
4714 | ||
4715 | static void | |
4716 | print_solib_event (int is_catchpoint) | |
4717 | { | |
4718 | int any_deleted | |
4719 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4720 | int any_added | |
4721 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4722 | ||
4723 | if (!is_catchpoint) | |
4724 | { | |
4725 | if (any_added || any_deleted) | |
4726 | ui_out_text (current_uiout, | |
4727 | _("Stopped due to shared library event:\n")); | |
4728 | else | |
4729 | ui_out_text (current_uiout, | |
4730 | _("Stopped due to shared library event (no " | |
4731 | "libraries added or removed)\n")); | |
4732 | } | |
4733 | ||
4734 | if (ui_out_is_mi_like_p (current_uiout)) | |
4735 | ui_out_field_string (current_uiout, "reason", | |
4736 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4737 | ||
4738 | if (any_deleted) | |
4739 | { | |
4740 | struct cleanup *cleanup; | |
4741 | char *name; | |
4742 | int ix; | |
4743 | ||
4744 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4745 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4746 | "removed"); | |
4747 | for (ix = 0; | |
4748 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4749 | ix, name); | |
4750 | ++ix) | |
4751 | { | |
4752 | if (ix > 0) | |
4753 | ui_out_text (current_uiout, " "); | |
4754 | ui_out_field_string (current_uiout, "library", name); | |
4755 | ui_out_text (current_uiout, "\n"); | |
4756 | } | |
4757 | ||
4758 | do_cleanups (cleanup); | |
4759 | } | |
4760 | ||
4761 | if (any_added) | |
4762 | { | |
4763 | struct so_list *iter; | |
4764 | int ix; | |
4765 | struct cleanup *cleanup; | |
4766 | ||
4767 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4768 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4769 | "added"); | |
4770 | for (ix = 0; | |
4771 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4772 | ix, iter); | |
4773 | ++ix) | |
4774 | { | |
4775 | if (ix > 0) | |
4776 | ui_out_text (current_uiout, " "); | |
4777 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4778 | ui_out_text (current_uiout, "\n"); | |
4779 | } | |
4780 | ||
4781 | do_cleanups (cleanup); | |
4782 | } | |
4783 | } | |
4784 | ||
e514a9d6 JM |
4785 | /* Print a message indicating what happened. This is called from |
4786 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4787 | list - a list of the eventpoints that caused this stop. KIND is |
4788 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4789 | routine calls the generic print routine for printing a message |
4790 | about reasons for stopping. This will print (for example) the | |
4791 | "Breakpoint n," part of the output. The return value of this | |
4792 | routine is one of: | |
c906108c | 4793 | |
4a64f543 | 4794 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4795 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4796 | code to print the location. An example is |
c5aa993b JM |
4797 | "Breakpoint 1, " which should be followed by |
4798 | the location. | |
917317f4 | 4799 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4800 | to also print the location part of the message. |
4801 | An example is the catch/throw messages, which | |
4a64f543 | 4802 | don't require a location appended to the end. |
917317f4 | 4803 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4804 | further info to be printed. */ |
c906108c | 4805 | |
917317f4 | 4806 | enum print_stop_action |
36dfb11c | 4807 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
4808 | { |
4809 | int val; | |
c5aa993b | 4810 | |
c906108c | 4811 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4812 | (Currently all watchpoints go on the bpstat whether hit or not. |
4813 | That probably could (should) be changed, provided care is taken | |
c906108c | 4814 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4815 | for (; bs; bs = bs->next) |
4816 | { | |
4817 | val = print_bp_stop_message (bs); | |
4818 | if (val == PRINT_SRC_ONLY | |
4819 | || val == PRINT_SRC_AND_LOC | |
4820 | || val == PRINT_NOTHING) | |
4821 | return val; | |
4822 | } | |
c906108c | 4823 | |
36dfb11c TT |
4824 | /* If we had hit a shared library event breakpoint, |
4825 | print_bp_stop_message would print out this message. If we hit an | |
4826 | OS-level shared library event, do the same thing. */ | |
4827 | if (kind == TARGET_WAITKIND_LOADED) | |
4828 | { | |
edcc5120 | 4829 | print_solib_event (0); |
36dfb11c TT |
4830 | return PRINT_NOTHING; |
4831 | } | |
4832 | ||
e514a9d6 | 4833 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4834 | with and nothing was printed. */ |
917317f4 | 4835 | return PRINT_UNKNOWN; |
c906108c SS |
4836 | } |
4837 | ||
c42bd95a DE |
4838 | /* Evaluate the expression EXP and return 1 if value is zero. |
4839 | This returns the inverse of the condition because it is called | |
4840 | from catch_errors which returns 0 if an exception happened, and if an | |
4841 | exception happens we want execution to stop. | |
4a64f543 | 4842 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4843 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4844 | |
4845 | static int | |
4efb68b1 | 4846 | breakpoint_cond_eval (void *exp) |
c906108c | 4847 | { |
278cd55f | 4848 | struct value *mark = value_mark (); |
c5aa993b | 4849 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4850 | |
c906108c SS |
4851 | value_free_to_mark (mark); |
4852 | return i; | |
4853 | } | |
4854 | ||
5760d0ab | 4855 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4856 | |
4857 | static bpstat | |
5760d0ab | 4858 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
4859 | { |
4860 | bpstat bs; | |
4861 | ||
4862 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
4863 | bs->next = NULL; |
4864 | **bs_link_pointer = bs; | |
4865 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
4866 | bs->breakpoint_at = bl->owner; |
4867 | bs->bp_location_at = bl; | |
4868 | incref_bp_location (bl); | |
c906108c SS |
4869 | /* If the condition is false, etc., don't do the commands. */ |
4870 | bs->commands = NULL; | |
4871 | bs->old_val = NULL; | |
4872 | bs->print_it = print_it_normal; | |
4873 | return bs; | |
4874 | } | |
4875 | \f | |
d983da9c DJ |
4876 | /* The target has stopped with waitstatus WS. Check if any hardware |
4877 | watchpoints have triggered, according to the target. */ | |
4878 | ||
4879 | int | |
4880 | watchpoints_triggered (struct target_waitstatus *ws) | |
4881 | { | |
d92524f1 | 4882 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4883 | CORE_ADDR addr; |
4884 | struct breakpoint *b; | |
4885 | ||
4886 | if (!stopped_by_watchpoint) | |
4887 | { | |
4888 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4889 | as not triggered. */ | |
4890 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4891 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4892 | { |
4893 | struct watchpoint *w = (struct watchpoint *) b; | |
4894 | ||
4895 | w->watchpoint_triggered = watch_triggered_no; | |
4896 | } | |
d983da9c DJ |
4897 | |
4898 | return 0; | |
4899 | } | |
4900 | ||
4901 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4902 | { | |
4903 | /* We were stopped by a watchpoint, but we don't know where. | |
4904 | Mark all watchpoints as unknown. */ | |
4905 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4906 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4907 | { |
4908 | struct watchpoint *w = (struct watchpoint *) b; | |
4909 | ||
4910 | w->watchpoint_triggered = watch_triggered_unknown; | |
4911 | } | |
d983da9c | 4912 | |
3c4797ba | 4913 | return 1; |
d983da9c DJ |
4914 | } |
4915 | ||
4916 | /* The target could report the data address. Mark watchpoints | |
4917 | affected by this data address as triggered, and all others as not | |
4918 | triggered. */ | |
4919 | ||
4920 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4921 | if (is_hardware_watchpoint (b)) |
d983da9c | 4922 | { |
3a5c3e22 | 4923 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4924 | struct bp_location *loc; |
d983da9c | 4925 | |
3a5c3e22 | 4926 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4927 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4928 | { |
3a5c3e22 | 4929 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4930 | { |
3a5c3e22 PA |
4931 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4932 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4933 | |
4934 | if (newaddr == start) | |
4935 | { | |
3a5c3e22 | 4936 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4937 | break; |
4938 | } | |
4939 | } | |
4940 | /* Exact match not required. Within range is sufficient. */ | |
4941 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4942 | addr, loc->address, | |
4943 | loc->length)) | |
4944 | { | |
3a5c3e22 | 4945 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4946 | break; |
4947 | } | |
4948 | } | |
d983da9c DJ |
4949 | } |
4950 | ||
4951 | return 1; | |
4952 | } | |
4953 | ||
c906108c SS |
4954 | /* Possible return values for watchpoint_check (this can't be an enum |
4955 | because of check_errors). */ | |
4956 | /* The watchpoint has been deleted. */ | |
4957 | #define WP_DELETED 1 | |
4958 | /* The value has changed. */ | |
4959 | #define WP_VALUE_CHANGED 2 | |
4960 | /* The value has not changed. */ | |
4961 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
4962 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
4963 | #define WP_IGNORE 4 | |
c906108c SS |
4964 | |
4965 | #define BP_TEMPFLAG 1 | |
4966 | #define BP_HARDWAREFLAG 2 | |
4967 | ||
4a64f543 MS |
4968 | /* Evaluate watchpoint condition expression and check if its value |
4969 | changed. | |
553e4c11 JB |
4970 | |
4971 | P should be a pointer to struct bpstat, but is defined as a void * | |
4972 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
4973 | |
4974 | static int | |
4efb68b1 | 4975 | watchpoint_check (void *p) |
c906108c SS |
4976 | { |
4977 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 4978 | struct watchpoint *b; |
c906108c SS |
4979 | struct frame_info *fr; |
4980 | int within_current_scope; | |
4981 | ||
f431efe5 | 4982 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4983 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4984 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4985 | |
f6bc2008 PA |
4986 | /* If this is a local watchpoint, we only want to check if the |
4987 | watchpoint frame is in scope if the current thread is the thread | |
4988 | that was used to create the watchpoint. */ | |
4989 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4990 | return WP_IGNORE; |
f6bc2008 | 4991 | |
c906108c SS |
4992 | if (b->exp_valid_block == NULL) |
4993 | within_current_scope = 1; | |
4994 | else | |
4995 | { | |
edb3359d DJ |
4996 | struct frame_info *frame = get_current_frame (); |
4997 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4998 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4999 | ||
4a64f543 MS |
5000 | /* in_function_epilogue_p() returns a non-zero value if we're |
5001 | still in the function but the stack frame has already been | |
5002 | invalidated. Since we can't rely on the values of local | |
5003 | variables after the stack has been destroyed, we are treating | |
5004 | the watchpoint in that state as `not changed' without further | |
5005 | checking. Don't mark watchpoints as changed if the current | |
5006 | frame is in an epilogue - even if they are in some other | |
5007 | frame, our view of the stack is likely to be wrong and | |
5008 | frame_find_by_id could error out. */ | |
a0f49112 | 5009 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 5010 | return WP_IGNORE; |
a0f49112 | 5011 | |
101dcfbe | 5012 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5013 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5014 | |
5015 | /* If we've gotten confused in the unwinder, we might have | |
5016 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5017 | if (within_current_scope) |
5018 | { | |
5019 | struct symbol *function; | |
5020 | ||
5021 | function = get_frame_function (fr); | |
5022 | if (function == NULL | |
5023 | || !contained_in (b->exp_valid_block, | |
5024 | SYMBOL_BLOCK_VALUE (function))) | |
5025 | within_current_scope = 0; | |
5026 | } | |
69fbadd5 | 5027 | |
edb3359d | 5028 | if (within_current_scope) |
c906108c SS |
5029 | /* If we end up stopping, the current frame will get selected |
5030 | in normal_stop. So this call to select_frame won't affect | |
5031 | the user. */ | |
0f7d239c | 5032 | select_frame (fr); |
c906108c | 5033 | } |
c5aa993b | 5034 | |
c906108c SS |
5035 | if (within_current_scope) |
5036 | { | |
4a64f543 MS |
5037 | /* We use value_{,free_to_}mark because it could be a *long* |
5038 | time before we return to the command level and call | |
5039 | free_all_values. We can't call free_all_values because we | |
5040 | might be in the middle of evaluating a function call. */ | |
c906108c | 5041 | |
0cf6dd15 | 5042 | int pc = 0; |
9c06b0b4 | 5043 | struct value *mark; |
fa4727a6 DJ |
5044 | struct value *new_val; |
5045 | ||
3a5c3e22 | 5046 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5047 | /* Since we don't know the exact trigger address (from |
5048 | stopped_data_address), just tell the user we've triggered | |
5049 | a mask watchpoint. */ | |
5050 | return WP_VALUE_CHANGED; | |
5051 | ||
5052 | mark = value_mark (); | |
3a1115a0 | 5053 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5054 | |
bb9d5f81 PP |
5055 | if (b->val_bitsize != 0) |
5056 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5057 | ||
4a64f543 MS |
5058 | /* We use value_equal_contents instead of value_equal because |
5059 | the latter coerces an array to a pointer, thus comparing just | |
5060 | the address of the array instead of its contents. This is | |
5061 | not what we want. */ | |
fa4727a6 | 5062 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5063 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5064 | { |
fa4727a6 DJ |
5065 | if (new_val != NULL) |
5066 | { | |
5067 | release_value (new_val); | |
5068 | value_free_to_mark (mark); | |
5069 | } | |
c906108c SS |
5070 | bs->old_val = b->val; |
5071 | b->val = new_val; | |
fa4727a6 | 5072 | b->val_valid = 1; |
c906108c SS |
5073 | return WP_VALUE_CHANGED; |
5074 | } | |
5075 | else | |
5076 | { | |
60e1c644 | 5077 | /* Nothing changed. */ |
c906108c | 5078 | value_free_to_mark (mark); |
c906108c SS |
5079 | return WP_VALUE_NOT_CHANGED; |
5080 | } | |
5081 | } | |
5082 | else | |
5083 | { | |
79a45e25 PA |
5084 | struct ui_out *uiout = current_uiout; |
5085 | ||
c906108c | 5086 | /* This seems like the only logical thing to do because |
c5aa993b JM |
5087 | if we temporarily ignored the watchpoint, then when |
5088 | we reenter the block in which it is valid it contains | |
5089 | garbage (in the case of a function, it may have two | |
5090 | garbage values, one before and one after the prologue). | |
5091 | So we can't even detect the first assignment to it and | |
5092 | watch after that (since the garbage may or may not equal | |
5093 | the first value assigned). */ | |
348d480f PA |
5094 | /* We print all the stop information in |
5095 | breakpoint_ops->print_it, but in this case, by the time we | |
5096 | call breakpoint_ops->print_it this bp will be deleted | |
5097 | already. So we have no choice but print the information | |
5098 | here. */ | |
9dc5e2a9 | 5099 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
5100 | ui_out_field_string |
5101 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 5102 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 5103 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
5104 | ui_out_text (uiout, |
5105 | " deleted because the program has left the block in\n\ | |
8b93c638 | 5106 | which its expression is valid.\n"); |
4ce44c66 | 5107 | |
cdac0397 | 5108 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5109 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5110 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5111 | |
5112 | return WP_DELETED; | |
5113 | } | |
5114 | } | |
5115 | ||
18a18393 | 5116 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5117 | breakpoint location BL. This function does not check if we should |
5118 | stop, only if BL explains the stop. */ | |
5119 | ||
18a18393 | 5120 | static int |
6c95b8df | 5121 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5122 | struct address_space *aspace, CORE_ADDR bp_addr, |
5123 | const struct target_waitstatus *ws) | |
18a18393 VP |
5124 | { |
5125 | struct breakpoint *b = bl->owner; | |
5126 | ||
348d480f | 5127 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5128 | gdb_assert (b != NULL); |
5129 | ||
09ac7c10 | 5130 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5131 | } |
5132 | ||
3a5c3e22 PA |
5133 | /* Determine if the watched values have actually changed, and we |
5134 | should stop. If not, set BS->stop to 0. */ | |
5135 | ||
18a18393 VP |
5136 | static void |
5137 | bpstat_check_watchpoint (bpstat bs) | |
5138 | { | |
2bdf28a0 | 5139 | const struct bp_location *bl; |
3a5c3e22 | 5140 | struct watchpoint *b; |
2bdf28a0 JK |
5141 | |
5142 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5143 | bl = bs->bp_location_at; |
2bdf28a0 | 5144 | gdb_assert (bl != NULL); |
3a5c3e22 | 5145 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5146 | gdb_assert (b != NULL); |
18a18393 | 5147 | |
18a18393 | 5148 | { |
18a18393 VP |
5149 | int must_check_value = 0; |
5150 | ||
3a5c3e22 | 5151 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5152 | /* For a software watchpoint, we must always check the |
5153 | watched value. */ | |
5154 | must_check_value = 1; | |
5155 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5156 | /* We have a hardware watchpoint (read, write, or access) | |
5157 | and the target earlier reported an address watched by | |
5158 | this watchpoint. */ | |
5159 | must_check_value = 1; | |
5160 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5161 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5162 | /* We were stopped by a hardware watchpoint, but the target could |
5163 | not report the data address. We must check the watchpoint's | |
5164 | value. Access and read watchpoints are out of luck; without | |
5165 | a data address, we can't figure it out. */ | |
5166 | must_check_value = 1; | |
3a5c3e22 | 5167 | |
18a18393 VP |
5168 | if (must_check_value) |
5169 | { | |
3e43a32a MS |
5170 | char *message |
5171 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5172 | b->base.number); |
18a18393 VP |
5173 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5174 | int e = catch_errors (watchpoint_check, bs, message, | |
5175 | RETURN_MASK_ALL); | |
5176 | do_cleanups (cleanups); | |
5177 | switch (e) | |
5178 | { | |
5179 | case WP_DELETED: | |
5180 | /* We've already printed what needs to be printed. */ | |
5181 | bs->print_it = print_it_done; | |
5182 | /* Stop. */ | |
5183 | break; | |
60e1c644 PA |
5184 | case WP_IGNORE: |
5185 | bs->print_it = print_it_noop; | |
5186 | bs->stop = 0; | |
5187 | break; | |
18a18393 | 5188 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5189 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5190 | { |
85d721b8 PA |
5191 | /* There are two cases to consider here: |
5192 | ||
4a64f543 | 5193 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5194 | In that case, trust the target, and always report |
5195 | the watchpoint hit to the user. Even though | |
5196 | reads don't cause value changes, the value may | |
5197 | have changed since the last time it was read, and | |
5198 | since we're not trapping writes, we will not see | |
5199 | those, and as such we should ignore our notion of | |
5200 | old value. | |
5201 | ||
4a64f543 | 5202 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5203 | reads and writes. There are two ways this may |
5204 | happen: | |
5205 | ||
4a64f543 | 5206 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5207 | reads only, but can break on accesses (reads or |
5208 | writes), such as e.g., x86. We detect this case | |
5209 | at the time we try to insert read watchpoints. | |
5210 | ||
4a64f543 | 5211 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5212 | watchpoints, but, the user set an access or write |
5213 | watchpoint watching the same memory as this read | |
5214 | watchpoint. | |
5215 | ||
5216 | If we're watching memory writes as well as reads, | |
5217 | ignore watchpoint hits when we find that the | |
5218 | value hasn't changed, as reads don't cause | |
5219 | changes. This still gives false positives when | |
5220 | the program writes the same value to memory as | |
5221 | what there was already in memory (we will confuse | |
5222 | it for a read), but it's much better than | |
5223 | nothing. */ | |
5224 | ||
5225 | int other_write_watchpoint = 0; | |
5226 | ||
5227 | if (bl->watchpoint_type == hw_read) | |
5228 | { | |
5229 | struct breakpoint *other_b; | |
5230 | ||
5231 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5232 | if (other_b->type == bp_hardware_watchpoint |
5233 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5234 | { |
3a5c3e22 PA |
5235 | struct watchpoint *other_w = |
5236 | (struct watchpoint *) other_b; | |
5237 | ||
5238 | if (other_w->watchpoint_triggered | |
5239 | == watch_triggered_yes) | |
5240 | { | |
5241 | other_write_watchpoint = 1; | |
5242 | break; | |
5243 | } | |
85d721b8 PA |
5244 | } |
5245 | } | |
5246 | ||
5247 | if (other_write_watchpoint | |
5248 | || bl->watchpoint_type == hw_access) | |
5249 | { | |
5250 | /* We're watching the same memory for writes, | |
5251 | and the value changed since the last time we | |
5252 | updated it, so this trap must be for a write. | |
5253 | Ignore it. */ | |
5254 | bs->print_it = print_it_noop; | |
5255 | bs->stop = 0; | |
5256 | } | |
18a18393 VP |
5257 | } |
5258 | break; | |
5259 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5260 | if (b->base.type == bp_hardware_watchpoint |
5261 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5262 | { |
5263 | /* Don't stop: write watchpoints shouldn't fire if | |
5264 | the value hasn't changed. */ | |
5265 | bs->print_it = print_it_noop; | |
5266 | bs->stop = 0; | |
5267 | } | |
5268 | /* Stop. */ | |
5269 | break; | |
5270 | default: | |
5271 | /* Can't happen. */ | |
5272 | case 0: | |
5273 | /* Error from catch_errors. */ | |
3a5c3e22 | 5274 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5275 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5276 | /* We've already printed what needs to be printed. */ |
5277 | bs->print_it = print_it_done; | |
5278 | break; | |
5279 | } | |
5280 | } | |
5281 | else /* must_check_value == 0 */ | |
5282 | { | |
5283 | /* This is a case where some watchpoint(s) triggered, but | |
5284 | not at the address of this watchpoint, or else no | |
5285 | watchpoint triggered after all. So don't print | |
5286 | anything for this watchpoint. */ | |
5287 | bs->print_it = print_it_noop; | |
5288 | bs->stop = 0; | |
5289 | } | |
5290 | } | |
5291 | } | |
5292 | ||
7d4df6a4 DE |
5293 | /* For breakpoints that are currently marked as telling gdb to stop, |
5294 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5295 | of breakpoint referred to by BS. If we should not stop for this |
5296 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5297 | |
18a18393 VP |
5298 | static void |
5299 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5300 | { | |
2bdf28a0 JK |
5301 | const struct bp_location *bl; |
5302 | struct breakpoint *b; | |
7d4df6a4 DE |
5303 | int value_is_zero = 0; |
5304 | struct expression *cond; | |
5305 | ||
5306 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5307 | |
5308 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5309 | bl = bs->bp_location_at; |
2bdf28a0 | 5310 | gdb_assert (bl != NULL); |
f431efe5 | 5311 | b = bs->breakpoint_at; |
2bdf28a0 | 5312 | gdb_assert (b != NULL); |
18a18393 | 5313 | |
b775012e LM |
5314 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5315 | need to do so again since GDB does not know if we stopped due to a | |
5316 | breakpoint or a single step breakpoint. */ | |
5317 | ||
18a18393 | 5318 | if (frame_id_p (b->frame_id) |
edb3359d | 5319 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5320 | { |
7d4df6a4 DE |
5321 | bs->stop = 0; |
5322 | return; | |
5323 | } | |
60e1c644 | 5324 | |
12ab52e9 PA |
5325 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5326 | evaluating the condition if this isn't the specified | |
5327 | thread/task. */ | |
5328 | if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid)) | |
5329 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) | |
5330 | ||
6c1b0f7b DE |
5331 | { |
5332 | bs->stop = 0; | |
5333 | return; | |
5334 | } | |
5335 | ||
6dddc817 DE |
5336 | /* Evaluate extension language breakpoints that have a "stop" method |
5337 | implemented. */ | |
5338 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5339 | |
7d4df6a4 DE |
5340 | if (is_watchpoint (b)) |
5341 | { | |
5342 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5343 | |
7d4df6a4 DE |
5344 | cond = w->cond_exp; |
5345 | } | |
5346 | else | |
5347 | cond = bl->cond; | |
60e1c644 | 5348 | |
7d4df6a4 DE |
5349 | if (cond && b->disposition != disp_del_at_next_stop) |
5350 | { | |
5351 | int within_current_scope = 1; | |
5352 | struct watchpoint * w; | |
60e1c644 | 5353 | |
7d4df6a4 DE |
5354 | /* We use value_mark and value_free_to_mark because it could |
5355 | be a long time before we return to the command level and | |
5356 | call free_all_values. We can't call free_all_values | |
5357 | because we might be in the middle of evaluating a | |
5358 | function call. */ | |
5359 | struct value *mark = value_mark (); | |
5360 | ||
5361 | if (is_watchpoint (b)) | |
5362 | w = (struct watchpoint *) b; | |
5363 | else | |
5364 | w = NULL; | |
5365 | ||
5366 | /* Need to select the frame, with all that implies so that | |
5367 | the conditions will have the right context. Because we | |
5368 | use the frame, we will not see an inlined function's | |
5369 | variables when we arrive at a breakpoint at the start | |
5370 | of the inlined function; the current frame will be the | |
5371 | call site. */ | |
5372 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5373 | select_frame (get_current_frame ()); | |
5374 | else | |
18a18393 | 5375 | { |
7d4df6a4 DE |
5376 | struct frame_info *frame; |
5377 | ||
5378 | /* For local watchpoint expressions, which particular | |
5379 | instance of a local is being watched matters, so we | |
5380 | keep track of the frame to evaluate the expression | |
5381 | in. To evaluate the condition however, it doesn't | |
5382 | really matter which instantiation of the function | |
5383 | where the condition makes sense triggers the | |
5384 | watchpoint. This allows an expression like "watch | |
5385 | global if q > 10" set in `func', catch writes to | |
5386 | global on all threads that call `func', or catch | |
5387 | writes on all recursive calls of `func' by a single | |
5388 | thread. We simply always evaluate the condition in | |
5389 | the innermost frame that's executing where it makes | |
5390 | sense to evaluate the condition. It seems | |
5391 | intuitive. */ | |
5392 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5393 | if (frame != NULL) | |
5394 | select_frame (frame); | |
5395 | else | |
5396 | within_current_scope = 0; | |
18a18393 | 5397 | } |
7d4df6a4 DE |
5398 | if (within_current_scope) |
5399 | value_is_zero | |
5400 | = catch_errors (breakpoint_cond_eval, cond, | |
5401 | "Error in testing breakpoint condition:\n", | |
5402 | RETURN_MASK_ALL); | |
5403 | else | |
18a18393 | 5404 | { |
7d4df6a4 DE |
5405 | warning (_("Watchpoint condition cannot be tested " |
5406 | "in the current scope")); | |
5407 | /* If we failed to set the right context for this | |
5408 | watchpoint, unconditionally report it. */ | |
5409 | value_is_zero = 0; | |
18a18393 | 5410 | } |
7d4df6a4 DE |
5411 | /* FIXME-someday, should give breakpoint #. */ |
5412 | value_free_to_mark (mark); | |
18a18393 | 5413 | } |
7d4df6a4 DE |
5414 | |
5415 | if (cond && value_is_zero) | |
5416 | { | |
5417 | bs->stop = 0; | |
5418 | } | |
7d4df6a4 DE |
5419 | else if (b->ignore_count > 0) |
5420 | { | |
5421 | b->ignore_count--; | |
5422 | bs->stop = 0; | |
5423 | /* Increase the hit count even though we don't stop. */ | |
5424 | ++(b->hit_count); | |
5425 | observer_notify_breakpoint_modified (b); | |
5426 | } | |
18a18393 VP |
5427 | } |
5428 | ||
5429 | ||
9709f61c | 5430 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5431 | BP_ADDR in thread PTID. |
c906108c | 5432 | |
d983da9c | 5433 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5434 | don't understand this stop. Result is a chain of bpstat's such |
5435 | that: | |
c906108c | 5436 | |
c5aa993b | 5437 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5438 | |
c5aa993b | 5439 | if we understand why we stopped, the result is not null. |
c906108c | 5440 | |
c5aa993b JM |
5441 | Each element of the chain refers to a particular breakpoint or |
5442 | watchpoint at which we have stopped. (We may have stopped for | |
5443 | several reasons concurrently.) | |
c906108c | 5444 | |
c5aa993b JM |
5445 | Each element of the chain has valid next, breakpoint_at, |
5446 | commands, FIXME??? fields. */ | |
c906108c SS |
5447 | |
5448 | bpstat | |
6c95b8df | 5449 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5450 | CORE_ADDR bp_addr, ptid_t ptid, |
5451 | const struct target_waitstatus *ws) | |
c906108c | 5452 | { |
0d381245 | 5453 | struct breakpoint *b = NULL; |
afe38095 | 5454 | struct bp_location *bl; |
20874c92 | 5455 | struct bp_location *loc; |
5760d0ab JK |
5456 | /* First item of allocated bpstat's. */ |
5457 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5458 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5459 | bpstat bs; |
20874c92 | 5460 | int ix; |
429374b8 | 5461 | int need_remove_insert; |
f431efe5 | 5462 | int removed_any; |
c906108c | 5463 | |
f431efe5 PA |
5464 | /* First, build the bpstat chain with locations that explain a |
5465 | target stop, while being careful to not set the target running, | |
5466 | as that may invalidate locations (in particular watchpoint | |
5467 | locations are recreated). Resuming will happen here with | |
5468 | breakpoint conditions or watchpoint expressions that include | |
5469 | inferior function calls. */ | |
c5aa993b | 5470 | |
429374b8 JK |
5471 | ALL_BREAKPOINTS (b) |
5472 | { | |
1a853c52 | 5473 | if (!breakpoint_enabled (b)) |
429374b8 | 5474 | continue; |
a5606eee | 5475 | |
429374b8 JK |
5476 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5477 | { | |
4a64f543 MS |
5478 | /* For hardware watchpoints, we look only at the first |
5479 | location. The watchpoint_check function will work on the | |
5480 | entire expression, not the individual locations. For | |
5481 | read watchpoints, the watchpoints_triggered function has | |
5482 | checked all locations already. */ | |
429374b8 JK |
5483 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5484 | break; | |
18a18393 | 5485 | |
f6592439 | 5486 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5487 | continue; |
c5aa993b | 5488 | |
09ac7c10 | 5489 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5490 | continue; |
c5aa993b | 5491 | |
4a64f543 MS |
5492 | /* Come here if it's a watchpoint, or if the break address |
5493 | matches. */ | |
c5aa993b | 5494 | |
4a64f543 MS |
5495 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5496 | explain stop. */ | |
c5aa993b | 5497 | |
f431efe5 PA |
5498 | /* Assume we stop. Should we find a watchpoint that is not |
5499 | actually triggered, or if the condition of the breakpoint | |
5500 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5501 | bs->stop = 1; |
5502 | bs->print = 1; | |
d983da9c | 5503 | |
f431efe5 PA |
5504 | /* If this is a scope breakpoint, mark the associated |
5505 | watchpoint as triggered so that we will handle the | |
5506 | out-of-scope event. We'll get to the watchpoint next | |
5507 | iteration. */ | |
d0fb5eae | 5508 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5509 | { |
5510 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5511 | ||
5512 | w->watchpoint_triggered = watch_triggered_yes; | |
5513 | } | |
f431efe5 PA |
5514 | } |
5515 | } | |
5516 | ||
7c16b83e | 5517 | /* Check if a moribund breakpoint explains the stop. */ |
f431efe5 PA |
5518 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
5519 | { | |
f1310107 | 5520 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 5521 | { |
5760d0ab | 5522 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
5523 | /* For hits of moribund locations, we should just proceed. */ |
5524 | bs->stop = 0; | |
5525 | bs->print = 0; | |
5526 | bs->print_it = print_it_noop; | |
5527 | } | |
5528 | } | |
5529 | ||
edcc5120 TT |
5530 | /* A bit of special processing for shlib breakpoints. We need to |
5531 | process solib loading here, so that the lists of loaded and | |
5532 | unloaded libraries are correct before we handle "catch load" and | |
5533 | "catch unload". */ | |
5534 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5535 | { | |
5d268276 | 5536 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5537 | { |
5538 | handle_solib_event (); | |
5539 | break; | |
5540 | } | |
5541 | } | |
5542 | ||
f431efe5 PA |
5543 | /* Now go through the locations that caused the target to stop, and |
5544 | check whether we're interested in reporting this stop to higher | |
5545 | layers, or whether we should resume the target transparently. */ | |
5546 | ||
5547 | removed_any = 0; | |
5548 | ||
5760d0ab | 5549 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5550 | { |
5551 | if (!bs->stop) | |
5552 | continue; | |
5553 | ||
f431efe5 | 5554 | b = bs->breakpoint_at; |
348d480f PA |
5555 | b->ops->check_status (bs); |
5556 | if (bs->stop) | |
28010a5d | 5557 | { |
348d480f | 5558 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5559 | |
429374b8 JK |
5560 | if (bs->stop) |
5561 | { | |
5562 | ++(b->hit_count); | |
8d3788bd | 5563 | observer_notify_breakpoint_modified (b); |
c906108c | 5564 | |
4a64f543 | 5565 | /* We will stop here. */ |
429374b8 JK |
5566 | if (b->disposition == disp_disable) |
5567 | { | |
816338b5 | 5568 | --(b->enable_count); |
1a853c52 | 5569 | if (b->enable_count <= 0) |
429374b8 | 5570 | b->enable_state = bp_disabled; |
f431efe5 | 5571 | removed_any = 1; |
429374b8 JK |
5572 | } |
5573 | if (b->silent) | |
5574 | bs->print = 0; | |
5575 | bs->commands = b->commands; | |
9add0f1b | 5576 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5577 | if (command_line_is_silent (bs->commands |
5578 | ? bs->commands->commands : NULL)) | |
5579 | bs->print = 0; | |
9d6e6e84 HZ |
5580 | |
5581 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5582 | } |
5583 | ||
348d480f | 5584 | } |
a9b3a50f PA |
5585 | |
5586 | /* Print nothing for this entry if we don't stop or don't | |
5587 | print. */ | |
5588 | if (!bs->stop || !bs->print) | |
5589 | bs->print_it = print_it_noop; | |
429374b8 | 5590 | } |
876fa593 | 5591 | |
d983da9c DJ |
5592 | /* If we aren't stopping, the value of some hardware watchpoint may |
5593 | not have changed, but the intermediate memory locations we are | |
5594 | watching may have. Don't bother if we're stopping; this will get | |
5595 | done later. */ | |
d832cb68 | 5596 | need_remove_insert = 0; |
5760d0ab JK |
5597 | if (! bpstat_causes_stop (bs_head)) |
5598 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5599 | if (!bs->stop |
f431efe5 PA |
5600 | && bs->breakpoint_at |
5601 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5602 | { |
3a5c3e22 PA |
5603 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5604 | ||
5605 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5606 | need_remove_insert = 1; |
d983da9c DJ |
5607 | } |
5608 | ||
d832cb68 | 5609 | if (need_remove_insert) |
44702360 | 5610 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5611 | else if (removed_any) |
44702360 | 5612 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5613 | |
5760d0ab | 5614 | return bs_head; |
c906108c | 5615 | } |
628fe4e4 JK |
5616 | |
5617 | static void | |
5618 | handle_jit_event (void) | |
5619 | { | |
5620 | struct frame_info *frame; | |
5621 | struct gdbarch *gdbarch; | |
5622 | ||
5623 | /* Switch terminal for any messages produced by | |
5624 | breakpoint_re_set. */ | |
5625 | target_terminal_ours_for_output (); | |
5626 | ||
5627 | frame = get_current_frame (); | |
5628 | gdbarch = get_frame_arch (frame); | |
5629 | ||
5630 | jit_event_handler (gdbarch); | |
5631 | ||
5632 | target_terminal_inferior (); | |
5633 | } | |
5634 | ||
5635 | /* Prepare WHAT final decision for infrun. */ | |
5636 | ||
5637 | /* Decide what infrun needs to do with this bpstat. */ | |
5638 | ||
c906108c | 5639 | struct bpstat_what |
0e30163f | 5640 | bpstat_what (bpstat bs_head) |
c906108c | 5641 | { |
c906108c | 5642 | struct bpstat_what retval; |
628fe4e4 | 5643 | int jit_event = 0; |
0e30163f | 5644 | bpstat bs; |
c906108c | 5645 | |
628fe4e4 | 5646 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5647 | retval.call_dummy = STOP_NONE; |
186c406b | 5648 | retval.is_longjmp = 0; |
628fe4e4 | 5649 | |
0e30163f | 5650 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5651 | { |
628fe4e4 JK |
5652 | /* Extract this BS's action. After processing each BS, we check |
5653 | if its action overrides all we've seem so far. */ | |
5654 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5655 | enum bptype bptype; | |
5656 | ||
c906108c | 5657 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5658 | { |
5659 | /* I suspect this can happen if it was a momentary | |
5660 | breakpoint which has since been deleted. */ | |
5661 | bptype = bp_none; | |
5662 | } | |
20874c92 | 5663 | else |
f431efe5 | 5664 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5665 | |
5666 | switch (bptype) | |
c906108c SS |
5667 | { |
5668 | case bp_none: | |
628fe4e4 | 5669 | break; |
c906108c SS |
5670 | case bp_breakpoint: |
5671 | case bp_hardware_breakpoint: | |
7c16b83e | 5672 | case bp_single_step: |
c906108c SS |
5673 | case bp_until: |
5674 | case bp_finish: | |
a9b3a50f | 5675 | case bp_shlib_event: |
c906108c SS |
5676 | if (bs->stop) |
5677 | { | |
5678 | if (bs->print) | |
628fe4e4 | 5679 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5680 | else |
628fe4e4 | 5681 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5682 | } |
5683 | else | |
628fe4e4 | 5684 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5685 | break; |
5686 | case bp_watchpoint: | |
5687 | case bp_hardware_watchpoint: | |
5688 | case bp_read_watchpoint: | |
5689 | case bp_access_watchpoint: | |
5690 | if (bs->stop) | |
5691 | { | |
5692 | if (bs->print) | |
628fe4e4 | 5693 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5694 | else |
628fe4e4 | 5695 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5696 | } |
5697 | else | |
628fe4e4 JK |
5698 | { |
5699 | /* There was a watchpoint, but we're not stopping. | |
5700 | This requires no further action. */ | |
5701 | } | |
c906108c SS |
5702 | break; |
5703 | case bp_longjmp: | |
e2e4d78b | 5704 | case bp_longjmp_call_dummy: |
186c406b | 5705 | case bp_exception: |
628fe4e4 | 5706 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
e2e4d78b | 5707 | retval.is_longjmp = bptype != bp_exception; |
c906108c SS |
5708 | break; |
5709 | case bp_longjmp_resume: | |
186c406b | 5710 | case bp_exception_resume: |
628fe4e4 | 5711 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 5712 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
5713 | break; |
5714 | case bp_step_resume: | |
5715 | if (bs->stop) | |
628fe4e4 JK |
5716 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5717 | else | |
c906108c | 5718 | { |
628fe4e4 JK |
5719 | /* It is for the wrong frame. */ |
5720 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5721 | } |
c906108c | 5722 | break; |
2c03e5be PA |
5723 | case bp_hp_step_resume: |
5724 | if (bs->stop) | |
5725 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5726 | else | |
5727 | { | |
5728 | /* It is for the wrong frame. */ | |
5729 | this_action = BPSTAT_WHAT_SINGLE; | |
5730 | } | |
5731 | break; | |
c906108c | 5732 | case bp_watchpoint_scope: |
c4093a6a | 5733 | case bp_thread_event: |
1900040c | 5734 | case bp_overlay_event: |
0fd8e87f | 5735 | case bp_longjmp_master: |
aa7d318d | 5736 | case bp_std_terminate_master: |
186c406b | 5737 | case bp_exception_master: |
628fe4e4 | 5738 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5739 | break; |
ce78b96d | 5740 | case bp_catchpoint: |
c5aa993b JM |
5741 | if (bs->stop) |
5742 | { | |
5743 | if (bs->print) | |
628fe4e4 | 5744 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5745 | else |
628fe4e4 | 5746 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5747 | } |
5748 | else | |
628fe4e4 JK |
5749 | { |
5750 | /* There was a catchpoint, but we're not stopping. | |
5751 | This requires no further action. */ | |
5752 | } | |
5753 | break; | |
628fe4e4 JK |
5754 | case bp_jit_event: |
5755 | jit_event = 1; | |
5756 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5757 | break; |
c906108c | 5758 | case bp_call_dummy: |
53a5351d JM |
5759 | /* Make sure the action is stop (silent or noisy), |
5760 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5761 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5762 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5763 | break; |
5764 | case bp_std_terminate: | |
5765 | /* Make sure the action is stop (silent or noisy), | |
5766 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5767 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5768 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5769 | break; |
1042e4c0 | 5770 | case bp_tracepoint: |
7a697b8d | 5771 | case bp_fast_tracepoint: |
0fb4aa4b | 5772 | case bp_static_tracepoint: |
1042e4c0 SS |
5773 | /* Tracepoint hits should not be reported back to GDB, and |
5774 | if one got through somehow, it should have been filtered | |
5775 | out already. */ | |
5776 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5777 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5778 | break; |
5779 | case bp_gnu_ifunc_resolver: | |
5780 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5781 | this_action = BPSTAT_WHAT_SINGLE; | |
5782 | break; | |
5783 | case bp_gnu_ifunc_resolver_return: | |
5784 | /* The breakpoint will be removed, execution will restart from the | |
5785 | PC of the former breakpoint. */ | |
5786 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5787 | break; | |
e7e0cddf SS |
5788 | |
5789 | case bp_dprintf: | |
a11cfd87 HZ |
5790 | if (bs->stop) |
5791 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5792 | else | |
5793 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5794 | break; |
5795 | ||
628fe4e4 JK |
5796 | default: |
5797 | internal_error (__FILE__, __LINE__, | |
5798 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5799 | } |
628fe4e4 JK |
5800 | |
5801 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5802 | } |
628fe4e4 | 5803 | |
0e30163f JK |
5804 | /* These operations may affect the bs->breakpoint_at state so they are |
5805 | delayed after MAIN_ACTION is decided above. */ | |
5806 | ||
628fe4e4 JK |
5807 | if (jit_event) |
5808 | { | |
5809 | if (debug_infrun) | |
5810 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
5811 | ||
5812 | handle_jit_event (); | |
5813 | } | |
5814 | ||
0e30163f JK |
5815 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5816 | { | |
5817 | struct breakpoint *b = bs->breakpoint_at; | |
5818 | ||
5819 | if (b == NULL) | |
5820 | continue; | |
5821 | switch (b->type) | |
5822 | { | |
5823 | case bp_gnu_ifunc_resolver: | |
5824 | gnu_ifunc_resolver_stop (b); | |
5825 | break; | |
5826 | case bp_gnu_ifunc_resolver_return: | |
5827 | gnu_ifunc_resolver_return_stop (b); | |
5828 | break; | |
5829 | } | |
5830 | } | |
5831 | ||
c906108c SS |
5832 | return retval; |
5833 | } | |
5834 | ||
5835 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5836 | without hardware support). This isn't related to a specific bpstat, | |
5837 | just to things like whether watchpoints are set. */ | |
5838 | ||
c5aa993b | 5839 | int |
fba45db2 | 5840 | bpstat_should_step (void) |
c906108c SS |
5841 | { |
5842 | struct breakpoint *b; | |
cc59ec59 | 5843 | |
c906108c | 5844 | ALL_BREAKPOINTS (b) |
717a8278 | 5845 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5846 | return 1; |
c906108c SS |
5847 | return 0; |
5848 | } | |
5849 | ||
67822962 PA |
5850 | int |
5851 | bpstat_causes_stop (bpstat bs) | |
5852 | { | |
5853 | for (; bs != NULL; bs = bs->next) | |
5854 | if (bs->stop) | |
5855 | return 1; | |
5856 | ||
5857 | return 0; | |
5858 | } | |
5859 | ||
c906108c | 5860 | \f |
c5aa993b | 5861 | |
170b53b2 UW |
5862 | /* Compute a string of spaces suitable to indent the next line |
5863 | so it starts at the position corresponding to the table column | |
5864 | named COL_NAME in the currently active table of UIOUT. */ | |
5865 | ||
5866 | static char * | |
5867 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5868 | { | |
5869 | static char wrap_indent[80]; | |
5870 | int i, total_width, width, align; | |
5871 | char *text; | |
5872 | ||
5873 | total_width = 0; | |
5874 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
5875 | { | |
5876 | if (strcmp (text, col_name) == 0) | |
5877 | { | |
5878 | gdb_assert (total_width < sizeof wrap_indent); | |
5879 | memset (wrap_indent, ' ', total_width); | |
5880 | wrap_indent[total_width] = 0; | |
5881 | ||
5882 | return wrap_indent; | |
5883 | } | |
5884 | ||
5885 | total_width += width + 1; | |
5886 | } | |
5887 | ||
5888 | return NULL; | |
5889 | } | |
5890 | ||
b775012e LM |
5891 | /* Determine if the locations of this breakpoint will have their conditions |
5892 | evaluated by the target, host or a mix of both. Returns the following: | |
5893 | ||
5894 | "host": Host evals condition. | |
5895 | "host or target": Host or Target evals condition. | |
5896 | "target": Target evals condition. | |
5897 | */ | |
5898 | ||
5899 | static const char * | |
5900 | bp_condition_evaluator (struct breakpoint *b) | |
5901 | { | |
5902 | struct bp_location *bl; | |
5903 | char host_evals = 0; | |
5904 | char target_evals = 0; | |
5905 | ||
5906 | if (!b) | |
5907 | return NULL; | |
5908 | ||
5909 | if (!is_breakpoint (b)) | |
5910 | return NULL; | |
5911 | ||
5912 | if (gdb_evaluates_breakpoint_condition_p () | |
5913 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5914 | return condition_evaluation_host; | |
5915 | ||
5916 | for (bl = b->loc; bl; bl = bl->next) | |
5917 | { | |
5918 | if (bl->cond_bytecode) | |
5919 | target_evals++; | |
5920 | else | |
5921 | host_evals++; | |
5922 | } | |
5923 | ||
5924 | if (host_evals && target_evals) | |
5925 | return condition_evaluation_both; | |
5926 | else if (target_evals) | |
5927 | return condition_evaluation_target; | |
5928 | else | |
5929 | return condition_evaluation_host; | |
5930 | } | |
5931 | ||
5932 | /* Determine the breakpoint location's condition evaluator. This is | |
5933 | similar to bp_condition_evaluator, but for locations. */ | |
5934 | ||
5935 | static const char * | |
5936 | bp_location_condition_evaluator (struct bp_location *bl) | |
5937 | { | |
5938 | if (bl && !is_breakpoint (bl->owner)) | |
5939 | return NULL; | |
5940 | ||
5941 | if (gdb_evaluates_breakpoint_condition_p () | |
5942 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5943 | return condition_evaluation_host; | |
5944 | ||
5945 | if (bl && bl->cond_bytecode) | |
5946 | return condition_evaluation_target; | |
5947 | else | |
5948 | return condition_evaluation_host; | |
5949 | } | |
5950 | ||
859825b8 JK |
5951 | /* Print the LOC location out of the list of B->LOC locations. */ |
5952 | ||
170b53b2 UW |
5953 | static void |
5954 | print_breakpoint_location (struct breakpoint *b, | |
5955 | struct bp_location *loc) | |
0d381245 | 5956 | { |
79a45e25 | 5957 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
5958 | struct cleanup *old_chain = save_current_program_space (); |
5959 | ||
859825b8 JK |
5960 | if (loc != NULL && loc->shlib_disabled) |
5961 | loc = NULL; | |
5962 | ||
6c95b8df PA |
5963 | if (loc != NULL) |
5964 | set_current_program_space (loc->pspace); | |
5965 | ||
56435ebe TT |
5966 | if (b->display_canonical) |
5967 | ui_out_field_string (uiout, "what", b->addr_string); | |
2f202fde | 5968 | else if (loc && loc->symtab) |
0d381245 VP |
5969 | { |
5970 | struct symbol *sym | |
5971 | = find_pc_sect_function (loc->address, loc->section); | |
5972 | if (sym) | |
5973 | { | |
5974 | ui_out_text (uiout, "in "); | |
5975 | ui_out_field_string (uiout, "func", | |
5976 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
5977 | ui_out_text (uiout, " "); |
5978 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
5979 | ui_out_text (uiout, "at "); | |
0d381245 | 5980 | } |
05cba821 JK |
5981 | ui_out_field_string (uiout, "file", |
5982 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 5983 | ui_out_text (uiout, ":"); |
05cba821 | 5984 | |
0d381245 | 5985 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
5986 | ui_out_field_string (uiout, "fullname", |
5987 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 5988 | |
f8eba3c6 | 5989 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 5990 | } |
859825b8 | 5991 | else if (loc) |
0d381245 | 5992 | { |
f99d8bf4 PA |
5993 | struct ui_file *stb = mem_fileopen (); |
5994 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 5995 | |
f99d8bf4 | 5996 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 5997 | demangle, ""); |
0d381245 | 5998 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
5999 | |
6000 | do_cleanups (stb_chain); | |
0d381245 | 6001 | } |
859825b8 JK |
6002 | else |
6003 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df | 6004 | |
b775012e LM |
6005 | if (loc && is_breakpoint (b) |
6006 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6007 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6008 | { | |
6009 | ui_out_text (uiout, " ("); | |
6010 | ui_out_field_string (uiout, "evaluated-by", | |
6011 | bp_location_condition_evaluator (loc)); | |
6012 | ui_out_text (uiout, ")"); | |
6013 | } | |
6014 | ||
6c95b8df | 6015 | do_cleanups (old_chain); |
0d381245 VP |
6016 | } |
6017 | ||
269b11a2 PA |
6018 | static const char * |
6019 | bptype_string (enum bptype type) | |
c906108c | 6020 | { |
c4093a6a JM |
6021 | struct ep_type_description |
6022 | { | |
6023 | enum bptype type; | |
6024 | char *description; | |
6025 | }; | |
6026 | static struct ep_type_description bptypes[] = | |
c906108c | 6027 | { |
c5aa993b JM |
6028 | {bp_none, "?deleted?"}, |
6029 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6030 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6031 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6032 | {bp_until, "until"}, |
6033 | {bp_finish, "finish"}, | |
6034 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6035 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6036 | {bp_read_watchpoint, "read watchpoint"}, |
6037 | {bp_access_watchpoint, "acc watchpoint"}, | |
6038 | {bp_longjmp, "longjmp"}, | |
6039 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6040 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6041 | {bp_exception, "exception"}, |
6042 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6043 | {bp_step_resume, "step resume"}, |
2c03e5be | 6044 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6045 | {bp_watchpoint_scope, "watchpoint scope"}, |
6046 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6047 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6048 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6049 | {bp_thread_event, "thread events"}, |
1900040c | 6050 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6051 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6052 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6053 | {bp_exception_master, "exception master"}, |
ce78b96d | 6054 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6055 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6056 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6057 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6058 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6059 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6060 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6061 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6062 | }; |
269b11a2 PA |
6063 | |
6064 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6065 | || ((int) type != bptypes[(int) type].type)) | |
6066 | internal_error (__FILE__, __LINE__, | |
6067 | _("bptypes table does not describe type #%d."), | |
6068 | (int) type); | |
6069 | ||
6070 | return bptypes[(int) type].description; | |
6071 | } | |
6072 | ||
998580f1 MK |
6073 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6074 | For CLI, prefix the list with the string 'inf'. */ | |
6075 | ||
6076 | static void | |
6077 | output_thread_groups (struct ui_out *uiout, | |
6078 | const char *field_name, | |
6079 | VEC(int) *inf_num, | |
6080 | int mi_only) | |
6081 | { | |
752eb8b4 | 6082 | struct cleanup *back_to; |
998580f1 MK |
6083 | int is_mi = ui_out_is_mi_like_p (uiout); |
6084 | int inf; | |
6085 | int i; | |
6086 | ||
6087 | /* For backward compatibility, don't display inferiors in CLI unless | |
6088 | there are several. Always display them for MI. */ | |
6089 | if (!is_mi && mi_only) | |
6090 | return; | |
6091 | ||
752eb8b4 TT |
6092 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6093 | ||
998580f1 MK |
6094 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6095 | { | |
6096 | if (is_mi) | |
6097 | { | |
6098 | char mi_group[10]; | |
6099 | ||
6100 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6101 | ui_out_field_string (uiout, NULL, mi_group); | |
6102 | } | |
6103 | else | |
6104 | { | |
6105 | if (i == 0) | |
6106 | ui_out_text (uiout, " inf "); | |
6107 | else | |
6108 | ui_out_text (uiout, ", "); | |
6109 | ||
6110 | ui_out_text (uiout, plongest (inf)); | |
6111 | } | |
6112 | } | |
6113 | ||
6114 | do_cleanups (back_to); | |
6115 | } | |
6116 | ||
269b11a2 PA |
6117 | /* Print B to gdb_stdout. */ |
6118 | ||
6119 | static void | |
6120 | print_one_breakpoint_location (struct breakpoint *b, | |
6121 | struct bp_location *loc, | |
6122 | int loc_number, | |
6123 | struct bp_location **last_loc, | |
269b11a2 PA |
6124 | int allflag) |
6125 | { | |
6126 | struct command_line *l; | |
c2c6d25f | 6127 | static char bpenables[] = "nynny"; |
c906108c | 6128 | |
79a45e25 | 6129 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6130 | int header_of_multiple = 0; |
6131 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6132 | struct value_print_options opts; |
6133 | ||
6134 | get_user_print_options (&opts); | |
0d381245 VP |
6135 | |
6136 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6137 | /* See comment in print_one_breakpoint concerning treatment of |
6138 | breakpoints with single disabled location. */ | |
0d381245 VP |
6139 | if (loc == NULL |
6140 | && (b->loc != NULL | |
6141 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6142 | header_of_multiple = 1; | |
6143 | if (loc == NULL) | |
6144 | loc = b->loc; | |
6145 | ||
c4093a6a JM |
6146 | annotate_record (); |
6147 | ||
6148 | /* 1 */ | |
6149 | annotate_field (0); | |
0d381245 VP |
6150 | if (part_of_multiple) |
6151 | { | |
6152 | char *formatted; | |
0c6773c1 | 6153 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6154 | ui_out_field_string (uiout, "number", formatted); |
6155 | xfree (formatted); | |
6156 | } | |
6157 | else | |
6158 | { | |
6159 | ui_out_field_int (uiout, "number", b->number); | |
6160 | } | |
c4093a6a JM |
6161 | |
6162 | /* 2 */ | |
6163 | annotate_field (1); | |
0d381245 VP |
6164 | if (part_of_multiple) |
6165 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6166 | else |
6167 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6168 | |
6169 | /* 3 */ | |
6170 | annotate_field (2); | |
0d381245 VP |
6171 | if (part_of_multiple) |
6172 | ui_out_field_skip (uiout, "disp"); | |
6173 | else | |
2cec12e5 | 6174 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6175 | |
c4093a6a JM |
6176 | |
6177 | /* 4 */ | |
6178 | annotate_field (3); | |
0d381245 | 6179 | if (part_of_multiple) |
54e52265 | 6180 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6181 | else |
4a64f543 MS |
6182 | ui_out_field_fmt (uiout, "enabled", "%c", |
6183 | bpenables[(int) b->enable_state]); | |
54e52265 | 6184 | ui_out_spaces (uiout, 2); |
0d381245 | 6185 | |
c4093a6a JM |
6186 | |
6187 | /* 5 and 6 */ | |
3086aeae | 6188 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6189 | { |
4a64f543 MS |
6190 | /* Although the print_one can possibly print all locations, |
6191 | calling it here is not likely to get any nice result. So, | |
6192 | make sure there's just one location. */ | |
0d381245 | 6193 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6194 | b->ops->print_one (b, last_loc); |
0d381245 | 6195 | } |
3086aeae DJ |
6196 | else |
6197 | switch (b->type) | |
6198 | { | |
6199 | case bp_none: | |
6200 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6201 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6202 | break; |
c906108c | 6203 | |
3086aeae DJ |
6204 | case bp_watchpoint: |
6205 | case bp_hardware_watchpoint: | |
6206 | case bp_read_watchpoint: | |
6207 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6208 | { |
6209 | struct watchpoint *w = (struct watchpoint *) b; | |
6210 | ||
6211 | /* Field 4, the address, is omitted (which makes the columns | |
6212 | not line up too nicely with the headers, but the effect | |
6213 | is relatively readable). */ | |
6214 | if (opts.addressprint) | |
6215 | ui_out_field_skip (uiout, "addr"); | |
6216 | annotate_field (5); | |
6217 | ui_out_field_string (uiout, "what", w->exp_string); | |
6218 | } | |
3086aeae DJ |
6219 | break; |
6220 | ||
3086aeae DJ |
6221 | case bp_breakpoint: |
6222 | case bp_hardware_breakpoint: | |
7c16b83e | 6223 | case bp_single_step: |
3086aeae DJ |
6224 | case bp_until: |
6225 | case bp_finish: | |
6226 | case bp_longjmp: | |
6227 | case bp_longjmp_resume: | |
e2e4d78b | 6228 | case bp_longjmp_call_dummy: |
186c406b TT |
6229 | case bp_exception: |
6230 | case bp_exception_resume: | |
3086aeae | 6231 | case bp_step_resume: |
2c03e5be | 6232 | case bp_hp_step_resume: |
3086aeae DJ |
6233 | case bp_watchpoint_scope: |
6234 | case bp_call_dummy: | |
aa7d318d | 6235 | case bp_std_terminate: |
3086aeae DJ |
6236 | case bp_shlib_event: |
6237 | case bp_thread_event: | |
6238 | case bp_overlay_event: | |
0fd8e87f | 6239 | case bp_longjmp_master: |
aa7d318d | 6240 | case bp_std_terminate_master: |
186c406b | 6241 | case bp_exception_master: |
1042e4c0 | 6242 | case bp_tracepoint: |
7a697b8d | 6243 | case bp_fast_tracepoint: |
0fb4aa4b | 6244 | case bp_static_tracepoint: |
e7e0cddf | 6245 | case bp_dprintf: |
4efc6507 | 6246 | case bp_jit_event: |
0e30163f JK |
6247 | case bp_gnu_ifunc_resolver: |
6248 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6249 | if (opts.addressprint) |
3086aeae DJ |
6250 | { |
6251 | annotate_field (4); | |
54e52265 | 6252 | if (header_of_multiple) |
0d381245 | 6253 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6254 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6255 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6256 | else |
5af949e3 UW |
6257 | ui_out_field_core_addr (uiout, "addr", |
6258 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6259 | } |
6260 | annotate_field (5); | |
0d381245 | 6261 | if (!header_of_multiple) |
170b53b2 | 6262 | print_breakpoint_location (b, loc); |
0d381245 | 6263 | if (b->loc) |
a6d9a66e | 6264 | *last_loc = b->loc; |
3086aeae DJ |
6265 | break; |
6266 | } | |
c906108c | 6267 | |
6c95b8df | 6268 | |
998580f1 | 6269 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6270 | { |
6271 | struct inferior *inf; | |
998580f1 MK |
6272 | VEC(int) *inf_num = NULL; |
6273 | int mi_only = 1; | |
6c95b8df | 6274 | |
998580f1 | 6275 | ALL_INFERIORS (inf) |
6c95b8df PA |
6276 | { |
6277 | if (inf->pspace == loc->pspace) | |
998580f1 | 6278 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6279 | } |
998580f1 MK |
6280 | |
6281 | /* For backward compatibility, don't display inferiors in CLI unless | |
6282 | there are several. Always display for MI. */ | |
6283 | if (allflag | |
6284 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6285 | && (number_of_program_spaces () > 1 | |
6286 | || number_of_inferiors () > 1) | |
6287 | /* LOC is for existing B, it cannot be in | |
6288 | moribund_locations and thus having NULL OWNER. */ | |
6289 | && loc->owner->type != bp_catchpoint)) | |
6290 | mi_only = 0; | |
6291 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6292 | VEC_free (int, inf_num); | |
6c95b8df PA |
6293 | } |
6294 | ||
4a306c9a | 6295 | if (!part_of_multiple) |
c4093a6a | 6296 | { |
4a306c9a JB |
6297 | if (b->thread != -1) |
6298 | { | |
6299 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6300 | "stop only in" line a little further down. */ |
4a306c9a JB |
6301 | ui_out_text (uiout, " thread "); |
6302 | ui_out_field_int (uiout, "thread", b->thread); | |
6303 | } | |
6304 | else if (b->task != 0) | |
6305 | { | |
6306 | ui_out_text (uiout, " task "); | |
6307 | ui_out_field_int (uiout, "task", b->task); | |
6308 | } | |
c4093a6a | 6309 | } |
f1310107 | 6310 | |
8b93c638 | 6311 | ui_out_text (uiout, "\n"); |
f1310107 | 6312 | |
348d480f | 6313 | if (!part_of_multiple) |
f1310107 TJB |
6314 | b->ops->print_one_detail (b, uiout); |
6315 | ||
0d381245 | 6316 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6317 | { |
6318 | annotate_field (6); | |
8b93c638 | 6319 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6320 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6321 | the frame ID. */ |
5af949e3 UW |
6322 | ui_out_field_core_addr (uiout, "frame", |
6323 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6324 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6325 | } |
6326 | ||
28010a5d | 6327 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6328 | { |
6329 | annotate_field (7); | |
d77f58be | 6330 | if (is_tracepoint (b)) |
1042e4c0 SS |
6331 | ui_out_text (uiout, "\ttrace only if "); |
6332 | else | |
6333 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6334 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6335 | |
6336 | /* Print whether the target is doing the breakpoint's condition | |
6337 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6338 | if (is_breakpoint (b) | |
6339 | && breakpoint_condition_evaluation_mode () | |
6340 | == condition_evaluation_target) | |
6341 | { | |
6342 | ui_out_text (uiout, " ("); | |
6343 | ui_out_field_string (uiout, "evaluated-by", | |
6344 | bp_condition_evaluator (b)); | |
6345 | ui_out_text (uiout, " evals)"); | |
6346 | } | |
0101ce28 JJ |
6347 | ui_out_text (uiout, "\n"); |
6348 | } | |
6349 | ||
0d381245 | 6350 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6351 | { |
4a64f543 | 6352 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
6353 | ui_out_text (uiout, "\tstop only in thread "); |
6354 | ui_out_field_int (uiout, "thread", b->thread); | |
6355 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
6356 | } |
6357 | ||
556ec64d YQ |
6358 | if (!part_of_multiple) |
6359 | { | |
6360 | if (b->hit_count) | |
31f56a27 YQ |
6361 | { |
6362 | /* FIXME should make an annotation for this. */ | |
6363 | if (is_catchpoint (b)) | |
6364 | ui_out_text (uiout, "\tcatchpoint"); | |
6365 | else if (is_tracepoint (b)) | |
6366 | ui_out_text (uiout, "\ttracepoint"); | |
6367 | else | |
6368 | ui_out_text (uiout, "\tbreakpoint"); | |
6369 | ui_out_text (uiout, " already hit "); | |
6370 | ui_out_field_int (uiout, "times", b->hit_count); | |
6371 | if (b->hit_count == 1) | |
6372 | ui_out_text (uiout, " time\n"); | |
6373 | else | |
6374 | ui_out_text (uiout, " times\n"); | |
6375 | } | |
556ec64d YQ |
6376 | else |
6377 | { | |
31f56a27 YQ |
6378 | /* Output the count also if it is zero, but only if this is mi. */ |
6379 | if (ui_out_is_mi_like_p (uiout)) | |
6380 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6381 | } |
6382 | } | |
8b93c638 | 6383 | |
0d381245 | 6384 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6385 | { |
6386 | annotate_field (8); | |
8b93c638 JM |
6387 | ui_out_text (uiout, "\tignore next "); |
6388 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6389 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6390 | } |
059fb39f | 6391 | |
816338b5 SS |
6392 | /* Note that an enable count of 1 corresponds to "enable once" |
6393 | behavior, which is reported by the combination of enablement and | |
6394 | disposition, so we don't need to mention it here. */ | |
6395 | if (!part_of_multiple && b->enable_count > 1) | |
6396 | { | |
6397 | annotate_field (8); | |
6398 | ui_out_text (uiout, "\tdisable after "); | |
6399 | /* Tweak the wording to clarify that ignore and enable counts | |
6400 | are distinct, and have additive effect. */ | |
6401 | if (b->ignore_count) | |
6402 | ui_out_text (uiout, "additional "); | |
6403 | else | |
6404 | ui_out_text (uiout, "next "); | |
6405 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6406 | ui_out_text (uiout, " hits\n"); | |
6407 | } | |
6408 | ||
f196051f SS |
6409 | if (!part_of_multiple && is_tracepoint (b)) |
6410 | { | |
6411 | struct tracepoint *tp = (struct tracepoint *) b; | |
6412 | ||
6413 | if (tp->traceframe_usage) | |
6414 | { | |
6415 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6416 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6417 | ui_out_text (uiout, " bytes\n"); | |
6418 | } | |
6419 | } | |
d3ce09f5 | 6420 | |
9add0f1b | 6421 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6422 | if (!part_of_multiple && l) |
c4093a6a | 6423 | { |
3b31d625 EZ |
6424 | struct cleanup *script_chain; |
6425 | ||
c4093a6a | 6426 | annotate_field (9); |
3b31d625 | 6427 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6428 | print_command_lines (uiout, l, 4); |
3b31d625 | 6429 | do_cleanups (script_chain); |
c4093a6a | 6430 | } |
d24317b4 | 6431 | |
d9b3f62e | 6432 | if (is_tracepoint (b)) |
1042e4c0 | 6433 | { |
d9b3f62e PA |
6434 | struct tracepoint *t = (struct tracepoint *) b; |
6435 | ||
6436 | if (!part_of_multiple && t->pass_count) | |
6437 | { | |
6438 | annotate_field (10); | |
6439 | ui_out_text (uiout, "\tpass count "); | |
6440 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6441 | ui_out_text (uiout, " \n"); | |
6442 | } | |
f2a8bc8a YQ |
6443 | |
6444 | /* Don't display it when tracepoint or tracepoint location is | |
6445 | pending. */ | |
6446 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6447 | { | |
6448 | annotate_field (11); | |
6449 | ||
6450 | if (ui_out_is_mi_like_p (uiout)) | |
6451 | ui_out_field_string (uiout, "installed", | |
6452 | loc->inserted ? "y" : "n"); | |
6453 | else | |
6454 | { | |
6455 | if (loc->inserted) | |
6456 | ui_out_text (uiout, "\t"); | |
6457 | else | |
6458 | ui_out_text (uiout, "\tnot "); | |
6459 | ui_out_text (uiout, "installed on target\n"); | |
6460 | } | |
6461 | } | |
1042e4c0 SS |
6462 | } |
6463 | ||
d24317b4 VP |
6464 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6465 | { | |
3a5c3e22 PA |
6466 | if (is_watchpoint (b)) |
6467 | { | |
6468 | struct watchpoint *w = (struct watchpoint *) b; | |
6469 | ||
6470 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6471 | } | |
6472 | else if (b->addr_string) | |
d24317b4 | 6473 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 6474 | } |
c4093a6a | 6475 | } |
c5aa993b | 6476 | |
0d381245 VP |
6477 | static void |
6478 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6479 | struct bp_location **last_loc, |
6c95b8df | 6480 | int allflag) |
0d381245 | 6481 | { |
8d3788bd | 6482 | struct cleanup *bkpt_chain; |
79a45e25 | 6483 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6484 | |
6485 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6486 | ||
12c5a436 | 6487 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6488 | do_cleanups (bkpt_chain); |
0d381245 VP |
6489 | |
6490 | /* If this breakpoint has custom print function, | |
6491 | it's already printed. Otherwise, print individual | |
6492 | locations, if any. */ | |
6493 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6494 | { | |
4a64f543 MS |
6495 | /* If breakpoint has a single location that is disabled, we |
6496 | print it as if it had several locations, since otherwise it's | |
6497 | hard to represent "breakpoint enabled, location disabled" | |
6498 | situation. | |
6499 | ||
6500 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6501 | internally, that's not a property exposed to user. */ |
0d381245 | 6502 | if (b->loc |
a5606eee | 6503 | && !is_hardware_watchpoint (b) |
8d3788bd | 6504 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6505 | { |
6506 | struct bp_location *loc; | |
6507 | int n = 1; | |
8d3788bd | 6508 | |
0d381245 | 6509 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6510 | { |
6511 | struct cleanup *inner2 = | |
6512 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6513 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6514 | do_cleanups (inner2); | |
6515 | } | |
0d381245 VP |
6516 | } |
6517 | } | |
6518 | } | |
6519 | ||
a6d9a66e UW |
6520 | static int |
6521 | breakpoint_address_bits (struct breakpoint *b) | |
6522 | { | |
6523 | int print_address_bits = 0; | |
6524 | struct bp_location *loc; | |
6525 | ||
6526 | for (loc = b->loc; loc; loc = loc->next) | |
6527 | { | |
c7437ca6 PA |
6528 | int addr_bit; |
6529 | ||
6530 | /* Software watchpoints that aren't watching memory don't have | |
6531 | an address to print. */ | |
6532 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
6533 | continue; | |
6534 | ||
6535 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
6536 | if (addr_bit > print_address_bits) |
6537 | print_address_bits = addr_bit; | |
6538 | } | |
6539 | ||
6540 | return print_address_bits; | |
6541 | } | |
0d381245 | 6542 | |
c4093a6a JM |
6543 | struct captured_breakpoint_query_args |
6544 | { | |
6545 | int bnum; | |
6546 | }; | |
c5aa993b | 6547 | |
c4093a6a | 6548 | static int |
2b65245e | 6549 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
6550 | { |
6551 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 6552 | struct breakpoint *b; |
a6d9a66e | 6553 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6554 | |
c4093a6a JM |
6555 | ALL_BREAKPOINTS (b) |
6556 | { | |
6557 | if (args->bnum == b->number) | |
c5aa993b | 6558 | { |
12c5a436 | 6559 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6560 | return GDB_RC_OK; |
c5aa993b | 6561 | } |
c4093a6a JM |
6562 | } |
6563 | return GDB_RC_NONE; | |
6564 | } | |
c5aa993b | 6565 | |
c4093a6a | 6566 | enum gdb_rc |
4a64f543 MS |
6567 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6568 | char **error_message) | |
c4093a6a JM |
6569 | { |
6570 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6571 | |
c4093a6a JM |
6572 | args.bnum = bnum; |
6573 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6574 | an error. */ |
b0b13bb4 DJ |
6575 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6576 | error_message, RETURN_MASK_ALL) < 0) | |
6577 | return GDB_RC_FAIL; | |
6578 | else | |
6579 | return GDB_RC_OK; | |
c4093a6a | 6580 | } |
c5aa993b | 6581 | |
09d682a4 TT |
6582 | /* Return true if this breakpoint was set by the user, false if it is |
6583 | internal or momentary. */ | |
6584 | ||
6585 | int | |
6586 | user_breakpoint_p (struct breakpoint *b) | |
6587 | { | |
46c6471b | 6588 | return b->number > 0; |
09d682a4 TT |
6589 | } |
6590 | ||
7f3b0473 | 6591 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6592 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6593 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6594 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6595 | ones for which it returns non-zero. Return the total number of | |
6596 | breakpoints listed. */ | |
c906108c | 6597 | |
d77f58be | 6598 | static int |
e5a67952 | 6599 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6600 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6601 | { |
52f0bd74 | 6602 | struct breakpoint *b; |
a6d9a66e | 6603 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6604 | int nr_printable_breakpoints; |
3b31d625 | 6605 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6606 | struct value_print_options opts; |
a6d9a66e | 6607 | int print_address_bits = 0; |
269b11a2 | 6608 | int print_type_col_width = 14; |
79a45e25 | 6609 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6610 | |
79a45b7d TT |
6611 | get_user_print_options (&opts); |
6612 | ||
4a64f543 MS |
6613 | /* Compute the number of rows in the table, as well as the size |
6614 | required for address fields. */ | |
7f3b0473 AC |
6615 | nr_printable_breakpoints = 0; |
6616 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6617 | { |
6618 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6619 | if (filter && !filter (b)) | |
6620 | continue; | |
6621 | ||
6622 | /* If we have an "args" string, it is a list of breakpoints to | |
6623 | accept. Skip the others. */ | |
6624 | if (args != NULL && *args != '\0') | |
6625 | { | |
6626 | if (allflag && parse_and_eval_long (args) != b->number) | |
6627 | continue; | |
6628 | if (!allflag && !number_is_in_list (args, b->number)) | |
6629 | continue; | |
6630 | } | |
269b11a2 | 6631 | |
e5a67952 MS |
6632 | if (allflag || user_breakpoint_p (b)) |
6633 | { | |
6634 | int addr_bit, type_len; | |
a6d9a66e | 6635 | |
e5a67952 MS |
6636 | addr_bit = breakpoint_address_bits (b); |
6637 | if (addr_bit > print_address_bits) | |
6638 | print_address_bits = addr_bit; | |
269b11a2 | 6639 | |
e5a67952 MS |
6640 | type_len = strlen (bptype_string (b->type)); |
6641 | if (type_len > print_type_col_width) | |
6642 | print_type_col_width = type_len; | |
6643 | ||
6644 | nr_printable_breakpoints++; | |
6645 | } | |
6646 | } | |
7f3b0473 | 6647 | |
79a45b7d | 6648 | if (opts.addressprint) |
3b31d625 | 6649 | bkpttbl_chain |
3e43a32a MS |
6650 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6651 | nr_printable_breakpoints, | |
3b31d625 | 6652 | "BreakpointTable"); |
8b93c638 | 6653 | else |
3b31d625 | 6654 | bkpttbl_chain |
3e43a32a MS |
6655 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6656 | nr_printable_breakpoints, | |
3b31d625 | 6657 | "BreakpointTable"); |
8b93c638 | 6658 | |
7f3b0473 | 6659 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6660 | annotate_breakpoints_headers (); |
6661 | if (nr_printable_breakpoints > 0) | |
6662 | annotate_field (0); | |
4a64f543 | 6663 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6664 | if (nr_printable_breakpoints > 0) |
6665 | annotate_field (1); | |
269b11a2 | 6666 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6667 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6668 | if (nr_printable_breakpoints > 0) |
6669 | annotate_field (2); | |
4a64f543 | 6670 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6671 | if (nr_printable_breakpoints > 0) |
6672 | annotate_field (3); | |
54e52265 | 6673 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6674 | if (opts.addressprint) |
e5a67952 MS |
6675 | { |
6676 | if (nr_printable_breakpoints > 0) | |
6677 | annotate_field (4); | |
6678 | if (print_address_bits <= 32) | |
6679 | ui_out_table_header (uiout, 10, ui_left, | |
6680 | "addr", "Address"); /* 5 */ | |
6681 | else | |
6682 | ui_out_table_header (uiout, 18, ui_left, | |
6683 | "addr", "Address"); /* 5 */ | |
6684 | } | |
d7faa9e7 AC |
6685 | if (nr_printable_breakpoints > 0) |
6686 | annotate_field (5); | |
6687 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6688 | ui_out_table_body (uiout); | |
6689 | if (nr_printable_breakpoints > 0) | |
6690 | annotate_breakpoints_table (); | |
7f3b0473 | 6691 | |
c4093a6a | 6692 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6693 | { |
6694 | QUIT; | |
6695 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6696 | if (filter && !filter (b)) | |
6697 | continue; | |
6698 | ||
6699 | /* If we have an "args" string, it is a list of breakpoints to | |
6700 | accept. Skip the others. */ | |
6701 | ||
6702 | if (args != NULL && *args != '\0') | |
6703 | { | |
6704 | if (allflag) /* maintenance info breakpoint */ | |
6705 | { | |
6706 | if (parse_and_eval_long (args) != b->number) | |
6707 | continue; | |
6708 | } | |
6709 | else /* all others */ | |
6710 | { | |
6711 | if (!number_is_in_list (args, b->number)) | |
6712 | continue; | |
6713 | } | |
6714 | } | |
6715 | /* We only print out user settable breakpoints unless the | |
6716 | allflag is set. */ | |
6717 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6718 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6719 | } |
6720 | ||
3b31d625 | 6721 | do_cleanups (bkpttbl_chain); |
698384cd | 6722 | |
7f3b0473 | 6723 | if (nr_printable_breakpoints == 0) |
c906108c | 6724 | { |
4a64f543 MS |
6725 | /* If there's a filter, let the caller decide how to report |
6726 | empty list. */ | |
d77f58be SS |
6727 | if (!filter) |
6728 | { | |
e5a67952 | 6729 | if (args == NULL || *args == '\0') |
d77f58be SS |
6730 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6731 | else | |
4a64f543 | 6732 | ui_out_message (uiout, 0, |
e5a67952 MS |
6733 | "No breakpoint or watchpoint matching '%s'.\n", |
6734 | args); | |
d77f58be | 6735 | } |
c906108c SS |
6736 | } |
6737 | else | |
c4093a6a | 6738 | { |
a6d9a66e UW |
6739 | if (last_loc && !server_command) |
6740 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6741 | } |
c906108c | 6742 | |
4a64f543 | 6743 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6744 | there have been breakpoints? */ |
c906108c | 6745 | annotate_breakpoints_table_end (); |
d77f58be SS |
6746 | |
6747 | return nr_printable_breakpoints; | |
c906108c SS |
6748 | } |
6749 | ||
ad443146 SS |
6750 | /* Display the value of default-collect in a way that is generally |
6751 | compatible with the breakpoint list. */ | |
6752 | ||
6753 | static void | |
6754 | default_collect_info (void) | |
6755 | { | |
79a45e25 PA |
6756 | struct ui_out *uiout = current_uiout; |
6757 | ||
ad443146 SS |
6758 | /* If it has no value (which is frequently the case), say nothing; a |
6759 | message like "No default-collect." gets in user's face when it's | |
6760 | not wanted. */ | |
6761 | if (!*default_collect) | |
6762 | return; | |
6763 | ||
6764 | /* The following phrase lines up nicely with per-tracepoint collect | |
6765 | actions. */ | |
6766 | ui_out_text (uiout, "default collect "); | |
6767 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6768 | ui_out_text (uiout, " \n"); | |
6769 | } | |
6770 | ||
c906108c | 6771 | static void |
e5a67952 | 6772 | breakpoints_info (char *args, int from_tty) |
c906108c | 6773 | { |
e5a67952 | 6774 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6775 | |
6776 | default_collect_info (); | |
d77f58be SS |
6777 | } |
6778 | ||
6779 | static void | |
e5a67952 | 6780 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6781 | { |
e5a67952 | 6782 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6783 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6784 | |
6785 | if (num_printed == 0) | |
6786 | { | |
e5a67952 | 6787 | if (args == NULL || *args == '\0') |
d77f58be SS |
6788 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6789 | else | |
e5a67952 | 6790 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6791 | } |
c906108c SS |
6792 | } |
6793 | ||
7a292a7a | 6794 | static void |
e5a67952 | 6795 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6796 | { |
e5a67952 | 6797 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6798 | |
6799 | default_collect_info (); | |
c906108c SS |
6800 | } |
6801 | ||
0d381245 | 6802 | static int |
714835d5 | 6803 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6804 | struct program_space *pspace, |
714835d5 | 6805 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6806 | { |
6807 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6808 | |
0d381245 VP |
6809 | for (; bl; bl = bl->next) |
6810 | { | |
6c95b8df PA |
6811 | if (bl->pspace == pspace |
6812 | && bl->address == pc | |
0d381245 VP |
6813 | && (!overlay_debugging || bl->section == section)) |
6814 | return 1; | |
6815 | } | |
6816 | return 0; | |
6817 | } | |
6818 | ||
672f9b60 | 6819 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6820 | concerns with logical breakpoints, so we match program spaces, not |
6821 | address spaces. */ | |
c906108c SS |
6822 | |
6823 | static void | |
6c95b8df PA |
6824 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6825 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6826 | struct obj_section *section, int thread) |
c906108c | 6827 | { |
52f0bd74 AC |
6828 | int others = 0; |
6829 | struct breakpoint *b; | |
c906108c SS |
6830 | |
6831 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6832 | others += (user_breakpoint_p (b) |
6833 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6834 | if (others > 0) |
6835 | { | |
a3f17187 AC |
6836 | if (others == 1) |
6837 | printf_filtered (_("Note: breakpoint ")); | |
6838 | else /* if (others == ???) */ | |
6839 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6840 | ALL_BREAKPOINTS (b) |
672f9b60 | 6841 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6842 | { |
6843 | others--; | |
6844 | printf_filtered ("%d", b->number); | |
6845 | if (b->thread == -1 && thread != -1) | |
6846 | printf_filtered (" (all threads)"); | |
6847 | else if (b->thread != -1) | |
6848 | printf_filtered (" (thread %d)", b->thread); | |
6849 | printf_filtered ("%s%s ", | |
059fb39f | 6850 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6851 | || b->enable_state == bp_call_disabled) |
0d381245 | 6852 | ? " (disabled)" |
0d381245 VP |
6853 | : ""), |
6854 | (others > 1) ? "," | |
6855 | : ((others == 1) ? " and" : "")); | |
6856 | } | |
a3f17187 | 6857 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6858 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6859 | printf_filtered (".\n"); |
6860 | } | |
6861 | } | |
6862 | \f | |
c906108c | 6863 | |
e4f237da KB |
6864 | /* Return true iff it is meaningful to use the address member of |
6865 | BPT. For some breakpoint types, the address member is irrelevant | |
6866 | and it makes no sense to attempt to compare it to other addresses | |
6867 | (or use it for any other purpose either). | |
6868 | ||
4a64f543 MS |
6869 | More specifically, each of the following breakpoint types will |
6870 | always have a zero valued address and we don't want to mark | |
6871 | breakpoints of any of these types to be a duplicate of an actual | |
6872 | breakpoint at address zero: | |
e4f237da KB |
6873 | |
6874 | bp_watchpoint | |
2d134ed3 PA |
6875 | bp_catchpoint |
6876 | ||
6877 | */ | |
e4f237da KB |
6878 | |
6879 | static int | |
6880 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6881 | { | |
6882 | enum bptype type = bpt->type; | |
6883 | ||
2d134ed3 PA |
6884 | return (type != bp_watchpoint && type != bp_catchpoint); |
6885 | } | |
6886 | ||
6887 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6888 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6889 | ||
6890 | static int | |
4a64f543 MS |
6891 | watchpoint_locations_match (struct bp_location *loc1, |
6892 | struct bp_location *loc2) | |
2d134ed3 | 6893 | { |
3a5c3e22 PA |
6894 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6895 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6896 | ||
6897 | /* Both of them must exist. */ | |
6898 | gdb_assert (w1 != NULL); | |
6899 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6900 | |
4a64f543 MS |
6901 | /* If the target can evaluate the condition expression in hardware, |
6902 | then we we need to insert both watchpoints even if they are at | |
6903 | the same place. Otherwise the watchpoint will only trigger when | |
6904 | the condition of whichever watchpoint was inserted evaluates to | |
6905 | true, not giving a chance for GDB to check the condition of the | |
6906 | other watchpoint. */ | |
3a5c3e22 | 6907 | if ((w1->cond_exp |
4a64f543 MS |
6908 | && target_can_accel_watchpoint_condition (loc1->address, |
6909 | loc1->length, | |
0cf6dd15 | 6910 | loc1->watchpoint_type, |
3a5c3e22 PA |
6911 | w1->cond_exp)) |
6912 | || (w2->cond_exp | |
4a64f543 MS |
6913 | && target_can_accel_watchpoint_condition (loc2->address, |
6914 | loc2->length, | |
0cf6dd15 | 6915 | loc2->watchpoint_type, |
3a5c3e22 | 6916 | w2->cond_exp))) |
0cf6dd15 TJB |
6917 | return 0; |
6918 | ||
85d721b8 PA |
6919 | /* Note that this checks the owner's type, not the location's. In |
6920 | case the target does not support read watchpoints, but does | |
6921 | support access watchpoints, we'll have bp_read_watchpoint | |
6922 | watchpoints with hw_access locations. Those should be considered | |
6923 | duplicates of hw_read locations. The hw_read locations will | |
6924 | become hw_access locations later. */ | |
2d134ed3 PA |
6925 | return (loc1->owner->type == loc2->owner->type |
6926 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6927 | && loc1->address == loc2->address | |
6928 | && loc1->length == loc2->length); | |
e4f237da KB |
6929 | } |
6930 | ||
31e77af2 | 6931 | /* See breakpoint.h. */ |
6c95b8df | 6932 | |
31e77af2 | 6933 | int |
6c95b8df PA |
6934 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
6935 | struct address_space *aspace2, CORE_ADDR addr2) | |
6936 | { | |
f5656ead | 6937 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6938 | || aspace1 == aspace2) |
6939 | && addr1 == addr2); | |
6940 | } | |
6941 | ||
f1310107 TJB |
6942 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6943 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6944 | matches ASPACE2. On targets that have global breakpoints, the address | |
6945 | space doesn't really matter. */ | |
6946 | ||
6947 | static int | |
6948 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
6949 | int len1, struct address_space *aspace2, | |
6950 | CORE_ADDR addr2) | |
6951 | { | |
f5656ead | 6952 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6953 | || aspace1 == aspace2) |
6954 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6955 | } | |
6956 | ||
6957 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6958 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6959 | matches the breakpoint's address space. On targets that have global | |
6960 | breakpoints, the address space doesn't really matter. */ | |
6961 | ||
6962 | static int | |
6963 | breakpoint_location_address_match (struct bp_location *bl, | |
6964 | struct address_space *aspace, | |
6965 | CORE_ADDR addr) | |
6966 | { | |
6967 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6968 | aspace, addr) | |
6969 | || (bl->length | |
6970 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6971 | bl->address, bl->length, | |
6972 | aspace, addr))); | |
6973 | } | |
6974 | ||
1e4d1764 YQ |
6975 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6976 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6977 | true, otherwise returns false. */ | |
6978 | ||
6979 | static int | |
6980 | tracepoint_locations_match (struct bp_location *loc1, | |
6981 | struct bp_location *loc2) | |
6982 | { | |
6983 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6984 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6985 | locations at the same address of different tracepoints are regarded as | |
6986 | different locations. */ | |
6987 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6988 | else | |
6989 | return 0; | |
6990 | } | |
6991 | ||
2d134ed3 PA |
6992 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
6993 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
6994 | represent the same location. */ | |
6995 | ||
6996 | static int | |
4a64f543 MS |
6997 | breakpoint_locations_match (struct bp_location *loc1, |
6998 | struct bp_location *loc2) | |
2d134ed3 | 6999 | { |
2bdf28a0 JK |
7000 | int hw_point1, hw_point2; |
7001 | ||
7002 | /* Both of them must not be in moribund_locations. */ | |
7003 | gdb_assert (loc1->owner != NULL); | |
7004 | gdb_assert (loc2->owner != NULL); | |
7005 | ||
7006 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7007 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7008 | |
7009 | if (hw_point1 != hw_point2) | |
7010 | return 0; | |
7011 | else if (hw_point1) | |
7012 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7013 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7014 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7015 | else |
f1310107 TJB |
7016 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7017 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7018 | loc2->pspace->aspace, loc2->address) | |
7019 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7020 | } |
7021 | ||
76897487 KB |
7022 | static void |
7023 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7024 | int bnum, int have_bnum) | |
7025 | { | |
f63fbe86 MS |
7026 | /* The longest string possibly returned by hex_string_custom |
7027 | is 50 chars. These must be at least that big for safety. */ | |
7028 | char astr1[64]; | |
7029 | char astr2[64]; | |
76897487 | 7030 | |
bb599908 PH |
7031 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7032 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7033 | if (have_bnum) |
8a3fe4f8 | 7034 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7035 | bnum, astr1, astr2); |
7036 | else | |
8a3fe4f8 | 7037 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7038 | } |
7039 | ||
4a64f543 MS |
7040 | /* Adjust a breakpoint's address to account for architectural |
7041 | constraints on breakpoint placement. Return the adjusted address. | |
7042 | Note: Very few targets require this kind of adjustment. For most | |
7043 | targets, this function is simply the identity function. */ | |
76897487 KB |
7044 | |
7045 | static CORE_ADDR | |
a6d9a66e UW |
7046 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7047 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7048 | { |
a6d9a66e | 7049 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7050 | { |
7051 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7052 | return bpaddr; | |
7053 | } | |
88f7da05 KB |
7054 | else if (bptype == bp_watchpoint |
7055 | || bptype == bp_hardware_watchpoint | |
7056 | || bptype == bp_read_watchpoint | |
7057 | || bptype == bp_access_watchpoint | |
fe798b75 | 7058 | || bptype == bp_catchpoint) |
88f7da05 KB |
7059 | { |
7060 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7061 | have their addresses modified. */ | |
7062 | return bpaddr; | |
7063 | } | |
7c16b83e PA |
7064 | else if (bptype == bp_single_step) |
7065 | { | |
7066 | /* Single-step breakpoints should not have their addresses | |
7067 | modified. If there's any architectural constrain that | |
7068 | applies to this address, then it should have already been | |
7069 | taken into account when the breakpoint was created in the | |
7070 | first place. If we didn't do this, stepping through e.g., | |
7071 | Thumb-2 IT blocks would break. */ | |
7072 | return bpaddr; | |
7073 | } | |
76897487 KB |
7074 | else |
7075 | { | |
7076 | CORE_ADDR adjusted_bpaddr; | |
7077 | ||
7078 | /* Some targets have architectural constraints on the placement | |
7079 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7080 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7081 | |
7082 | /* An adjusted breakpoint address can significantly alter | |
7083 | a user's expectations. Print a warning if an adjustment | |
7084 | is required. */ | |
7085 | if (adjusted_bpaddr != bpaddr) | |
7086 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7087 | ||
7088 | return adjusted_bpaddr; | |
7089 | } | |
7090 | } | |
7091 | ||
28010a5d PA |
7092 | void |
7093 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7094 | struct breakpoint *owner) | |
7cc221ef | 7095 | { |
7cc221ef DJ |
7096 | memset (loc, 0, sizeof (*loc)); |
7097 | ||
348d480f PA |
7098 | gdb_assert (ops != NULL); |
7099 | ||
28010a5d PA |
7100 | loc->ops = ops; |
7101 | loc->owner = owner; | |
511a6cd4 | 7102 | loc->cond = NULL; |
b775012e | 7103 | loc->cond_bytecode = NULL; |
0d381245 VP |
7104 | loc->shlib_disabled = 0; |
7105 | loc->enabled = 1; | |
e049a4b5 | 7106 | |
28010a5d | 7107 | switch (owner->type) |
e049a4b5 DJ |
7108 | { |
7109 | case bp_breakpoint: | |
7c16b83e | 7110 | case bp_single_step: |
e049a4b5 DJ |
7111 | case bp_until: |
7112 | case bp_finish: | |
7113 | case bp_longjmp: | |
7114 | case bp_longjmp_resume: | |
e2e4d78b | 7115 | case bp_longjmp_call_dummy: |
186c406b TT |
7116 | case bp_exception: |
7117 | case bp_exception_resume: | |
e049a4b5 | 7118 | case bp_step_resume: |
2c03e5be | 7119 | case bp_hp_step_resume: |
e049a4b5 DJ |
7120 | case bp_watchpoint_scope: |
7121 | case bp_call_dummy: | |
aa7d318d | 7122 | case bp_std_terminate: |
e049a4b5 DJ |
7123 | case bp_shlib_event: |
7124 | case bp_thread_event: | |
7125 | case bp_overlay_event: | |
4efc6507 | 7126 | case bp_jit_event: |
0fd8e87f | 7127 | case bp_longjmp_master: |
aa7d318d | 7128 | case bp_std_terminate_master: |
186c406b | 7129 | case bp_exception_master: |
0e30163f JK |
7130 | case bp_gnu_ifunc_resolver: |
7131 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7132 | case bp_dprintf: |
e049a4b5 | 7133 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7134 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7135 | break; |
7136 | case bp_hardware_breakpoint: | |
7137 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7138 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7139 | break; |
7140 | case bp_hardware_watchpoint: | |
7141 | case bp_read_watchpoint: | |
7142 | case bp_access_watchpoint: | |
7143 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7144 | break; | |
7145 | case bp_watchpoint: | |
ce78b96d | 7146 | case bp_catchpoint: |
15c3d785 PA |
7147 | case bp_tracepoint: |
7148 | case bp_fast_tracepoint: | |
0fb4aa4b | 7149 | case bp_static_tracepoint: |
e049a4b5 DJ |
7150 | loc->loc_type = bp_loc_other; |
7151 | break; | |
7152 | default: | |
e2e0b3e5 | 7153 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7154 | } |
7155 | ||
f431efe5 | 7156 | loc->refc = 1; |
28010a5d PA |
7157 | } |
7158 | ||
7159 | /* Allocate a struct bp_location. */ | |
7160 | ||
7161 | static struct bp_location * | |
7162 | allocate_bp_location (struct breakpoint *bpt) | |
7163 | { | |
348d480f PA |
7164 | return bpt->ops->allocate_location (bpt); |
7165 | } | |
7cc221ef | 7166 | |
f431efe5 PA |
7167 | static void |
7168 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7169 | { |
348d480f | 7170 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7171 | xfree (loc); |
7172 | } | |
7173 | ||
f431efe5 PA |
7174 | /* Increment reference count. */ |
7175 | ||
7176 | static void | |
7177 | incref_bp_location (struct bp_location *bl) | |
7178 | { | |
7179 | ++bl->refc; | |
7180 | } | |
7181 | ||
7182 | /* Decrement reference count. If the reference count reaches 0, | |
7183 | destroy the bp_location. Sets *BLP to NULL. */ | |
7184 | ||
7185 | static void | |
7186 | decref_bp_location (struct bp_location **blp) | |
7187 | { | |
0807b50c PA |
7188 | gdb_assert ((*blp)->refc > 0); |
7189 | ||
f431efe5 PA |
7190 | if (--(*blp)->refc == 0) |
7191 | free_bp_location (*blp); | |
7192 | *blp = NULL; | |
7193 | } | |
7194 | ||
346774a9 | 7195 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7196 | |
346774a9 PA |
7197 | static void |
7198 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7199 | { |
346774a9 | 7200 | struct breakpoint *b1; |
c906108c | 7201 | |
346774a9 PA |
7202 | /* Add this breakpoint to the end of the chain so that a list of |
7203 | breakpoints will come out in order of increasing numbers. */ | |
7204 | ||
7205 | b1 = breakpoint_chain; | |
7206 | if (b1 == 0) | |
7207 | breakpoint_chain = b; | |
7208 | else | |
7209 | { | |
7210 | while (b1->next) | |
7211 | b1 = b1->next; | |
7212 | b1->next = b; | |
7213 | } | |
7214 | } | |
7215 | ||
7216 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7217 | ||
7218 | static void | |
7219 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7220 | struct gdbarch *gdbarch, | |
28010a5d | 7221 | enum bptype bptype, |
c0a91b2b | 7222 | const struct breakpoint_ops *ops) |
346774a9 | 7223 | { |
c906108c | 7224 | memset (b, 0, sizeof (*b)); |
2219d63c | 7225 | |
348d480f PA |
7226 | gdb_assert (ops != NULL); |
7227 | ||
28010a5d | 7228 | b->ops = ops; |
4d28f7a8 | 7229 | b->type = bptype; |
a6d9a66e | 7230 | b->gdbarch = gdbarch; |
c906108c SS |
7231 | b->language = current_language->la_language; |
7232 | b->input_radix = input_radix; | |
7233 | b->thread = -1; | |
b5de0fa7 | 7234 | b->enable_state = bp_enabled; |
c906108c SS |
7235 | b->next = 0; |
7236 | b->silent = 0; | |
7237 | b->ignore_count = 0; | |
7238 | b->commands = NULL; | |
818dd999 | 7239 | b->frame_id = null_frame_id; |
0d381245 | 7240 | b->condition_not_parsed = 0; |
84f4c1fe | 7241 | b->py_bp_object = NULL; |
d0fb5eae | 7242 | b->related_breakpoint = b; |
346774a9 PA |
7243 | } |
7244 | ||
7245 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7246 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7247 | |
7248 | static struct breakpoint * | |
7249 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7250 | enum bptype bptype, |
c0a91b2b | 7251 | const struct breakpoint_ops *ops) |
346774a9 PA |
7252 | { |
7253 | struct breakpoint *b = XNEW (struct breakpoint); | |
7254 | ||
348d480f | 7255 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7256 | add_to_breakpoint_chain (b); |
0d381245 VP |
7257 | return b; |
7258 | } | |
7259 | ||
0e30163f JK |
7260 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7261 | resolutions should be made as the user specified the location explicitly | |
7262 | enough. */ | |
7263 | ||
0d381245 | 7264 | static void |
0e30163f | 7265 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7266 | { |
2bdf28a0 JK |
7267 | gdb_assert (loc->owner != NULL); |
7268 | ||
0d381245 | 7269 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7270 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7271 | || is_tracepoint (loc->owner)) |
0d381245 | 7272 | { |
0e30163f | 7273 | int is_gnu_ifunc; |
2c02bd72 | 7274 | const char *function_name; |
6a3a010b | 7275 | CORE_ADDR func_addr; |
0e30163f | 7276 | |
2c02bd72 | 7277 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7278 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7279 | |
7280 | if (is_gnu_ifunc && !explicit_loc) | |
7281 | { | |
7282 | struct breakpoint *b = loc->owner; | |
7283 | ||
7284 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7285 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7286 | &loc->requested_address)) |
7287 | { | |
7288 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7289 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7290 | loc->requested_address, | |
7291 | b->type); | |
7292 | } | |
7293 | else if (b->type == bp_breakpoint && b->loc == loc | |
7294 | && loc->next == NULL && b->related_breakpoint == b) | |
7295 | { | |
7296 | /* Create only the whole new breakpoint of this type but do not | |
7297 | mess more complicated breakpoints with multiple locations. */ | |
7298 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7299 | /* Remember the resolver's address for use by the return |
7300 | breakpoint. */ | |
7301 | loc->related_address = func_addr; | |
0e30163f JK |
7302 | } |
7303 | } | |
7304 | ||
2c02bd72 DE |
7305 | if (function_name) |
7306 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7307 | } |
7308 | } | |
7309 | ||
a6d9a66e | 7310 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7311 | struct gdbarch * |
a6d9a66e UW |
7312 | get_sal_arch (struct symtab_and_line sal) |
7313 | { | |
7314 | if (sal.section) | |
7315 | return get_objfile_arch (sal.section->objfile); | |
7316 | if (sal.symtab) | |
eb822aa6 | 7317 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7318 | |
7319 | return NULL; | |
7320 | } | |
7321 | ||
346774a9 PA |
7322 | /* Low level routine for partially initializing a breakpoint of type |
7323 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7324 | file name, and line number are provided by SAL. |
0d381245 VP |
7325 | |
7326 | It is expected that the caller will complete the initialization of | |
7327 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7328 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7329 | |
346774a9 PA |
7330 | static void |
7331 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7332 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7333 | const struct breakpoint_ops *ops) |
0d381245 | 7334 | { |
28010a5d | 7335 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7336 | |
3742cc8b | 7337 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7338 | |
6c95b8df PA |
7339 | if (bptype != bp_catchpoint) |
7340 | gdb_assert (sal.pspace != NULL); | |
7341 | ||
f8eba3c6 TT |
7342 | /* Store the program space that was used to set the breakpoint, |
7343 | except for ordinary breakpoints, which are independent of the | |
7344 | program space. */ | |
7345 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7346 | b->pspace = sal.pspace; | |
346774a9 | 7347 | } |
c906108c | 7348 | |
346774a9 PA |
7349 | /* set_raw_breakpoint is a low level routine for allocating and |
7350 | partially initializing a breakpoint of type BPTYPE. The newly | |
7351 | created breakpoint's address, section, source file name, and line | |
7352 | number are provided by SAL. The newly created and partially | |
7353 | initialized breakpoint is added to the breakpoint chain and | |
7354 | is also returned as the value of this function. | |
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 | |
7358 | information regarding the creation of a new breakpoint. In | |
7359 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7360 | number! Care should be taken to not allow an error to occur | |
7361 | prior to completing the initialization of the breakpoint. If this | |
7362 | should happen, a bogus breakpoint will be left on the chain. */ | |
7363 | ||
7364 | struct breakpoint * | |
7365 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7366 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7367 | const struct breakpoint_ops *ops) |
346774a9 PA |
7368 | { |
7369 | struct breakpoint *b = XNEW (struct breakpoint); | |
7370 | ||
348d480f | 7371 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7372 | add_to_breakpoint_chain (b); |
c906108c SS |
7373 | return b; |
7374 | } | |
7375 | ||
c2c6d25f JM |
7376 | |
7377 | /* Note that the breakpoint object B describes a permanent breakpoint | |
7378 | instruction, hard-wired into the inferior's code. */ | |
7379 | void | |
7380 | make_breakpoint_permanent (struct breakpoint *b) | |
7381 | { | |
0d381245 | 7382 | struct bp_location *bl; |
cc59ec59 | 7383 | |
4a64f543 MS |
7384 | /* By definition, permanent breakpoints are already present in the |
7385 | code. Mark all locations as inserted. For now, | |
7386 | make_breakpoint_permanent is called in just one place, so it's | |
7387 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 7388 | multiple locations or not, but it's easy to implement. */ |
0d381245 | 7389 | for (bl = b->loc; bl; bl = bl->next) |
1a853c52 PA |
7390 | { |
7391 | bl->permanent = 1; | |
7392 | bl->inserted = 1; | |
7393 | } | |
c2c6d25f JM |
7394 | } |
7395 | ||
53a5351d | 7396 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7397 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7398 | initiated the operation. */ | |
c906108c SS |
7399 | |
7400 | void | |
186c406b | 7401 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7402 | { |
35df4500 | 7403 | struct breakpoint *b, *b_tmp; |
186c406b | 7404 | int thread = tp->num; |
0fd8e87f UW |
7405 | |
7406 | /* To avoid having to rescan all objfile symbols at every step, | |
7407 | we maintain a list of continually-inserted but always disabled | |
7408 | longjmp "master" breakpoints. Here, we simply create momentary | |
7409 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7410 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7411 | if (b->pspace == current_program_space |
186c406b TT |
7412 | && (b->type == bp_longjmp_master |
7413 | || b->type == bp_exception_master)) | |
0fd8e87f | 7414 | { |
06edf0c0 PA |
7415 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7416 | struct breakpoint *clone; | |
cc59ec59 | 7417 | |
e2e4d78b JK |
7418 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7419 | after their removal. */ | |
06edf0c0 | 7420 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7421 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7422 | clone->thread = thread; |
7423 | } | |
186c406b TT |
7424 | |
7425 | tp->initiating_frame = frame; | |
c906108c SS |
7426 | } |
7427 | ||
611c83ae | 7428 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7429 | void |
611c83ae | 7430 | delete_longjmp_breakpoint (int thread) |
c906108c | 7431 | { |
35df4500 | 7432 | struct breakpoint *b, *b_tmp; |
c906108c | 7433 | |
35df4500 | 7434 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7435 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7436 | { |
7437 | if (b->thread == thread) | |
7438 | delete_breakpoint (b); | |
7439 | } | |
c906108c SS |
7440 | } |
7441 | ||
f59f708a PA |
7442 | void |
7443 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7444 | { | |
7445 | struct breakpoint *b, *b_tmp; | |
7446 | ||
7447 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7448 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7449 | { | |
7450 | if (b->thread == thread) | |
7451 | b->disposition = disp_del_at_next_stop; | |
7452 | } | |
7453 | } | |
7454 | ||
e2e4d78b JK |
7455 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7456 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7457 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7458 | breakpoints. */ | |
7459 | ||
7460 | struct breakpoint * | |
7461 | set_longjmp_breakpoint_for_call_dummy (void) | |
7462 | { | |
7463 | struct breakpoint *b, *retval = NULL; | |
7464 | ||
7465 | ALL_BREAKPOINTS (b) | |
7466 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7467 | { | |
7468 | struct breakpoint *new_b; | |
7469 | ||
7470 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7471 | &momentary_breakpoint_ops, |
7472 | 1); | |
e2e4d78b JK |
7473 | new_b->thread = pid_to_thread_id (inferior_ptid); |
7474 | ||
7475 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7476 | ||
7477 | gdb_assert (new_b->related_breakpoint == new_b); | |
7478 | if (retval == NULL) | |
7479 | retval = new_b; | |
7480 | new_b->related_breakpoint = retval; | |
7481 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7482 | retval = retval->related_breakpoint; | |
7483 | retval->related_breakpoint = new_b; | |
7484 | } | |
7485 | ||
7486 | return retval; | |
7487 | } | |
7488 | ||
7489 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7490 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7491 | stack. |
7492 | ||
7493 | You should call this function only at places where it is safe to currently | |
7494 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7495 | frames. */ | |
7496 | ||
7497 | void | |
b67a2c6f | 7498 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7499 | { |
7500 | struct breakpoint *b, *b_tmp; | |
7501 | ||
7502 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
b67a2c6f | 7503 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->num) |
e2e4d78b JK |
7504 | { |
7505 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7506 | ||
7507 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7508 | dummy_b = dummy_b->related_breakpoint; | |
7509 | if (dummy_b->type != bp_call_dummy | |
7510 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7511 | continue; | |
7512 | ||
b67a2c6f | 7513 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7514 | |
7515 | while (b->related_breakpoint != b) | |
7516 | { | |
7517 | if (b_tmp == b->related_breakpoint) | |
7518 | b_tmp = b->related_breakpoint->next; | |
7519 | delete_breakpoint (b->related_breakpoint); | |
7520 | } | |
7521 | delete_breakpoint (b); | |
7522 | } | |
7523 | } | |
7524 | ||
1900040c MS |
7525 | void |
7526 | enable_overlay_breakpoints (void) | |
7527 | { | |
52f0bd74 | 7528 | struct breakpoint *b; |
1900040c MS |
7529 | |
7530 | ALL_BREAKPOINTS (b) | |
7531 | if (b->type == bp_overlay_event) | |
7532 | { | |
7533 | b->enable_state = bp_enabled; | |
44702360 | 7534 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7535 | overlay_events_enabled = 1; |
1900040c MS |
7536 | } |
7537 | } | |
7538 | ||
7539 | void | |
7540 | disable_overlay_breakpoints (void) | |
7541 | { | |
52f0bd74 | 7542 | struct breakpoint *b; |
1900040c MS |
7543 | |
7544 | ALL_BREAKPOINTS (b) | |
7545 | if (b->type == bp_overlay_event) | |
7546 | { | |
7547 | b->enable_state = bp_disabled; | |
44702360 | 7548 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7549 | overlay_events_enabled = 0; |
1900040c MS |
7550 | } |
7551 | } | |
7552 | ||
aa7d318d TT |
7553 | /* Set an active std::terminate breakpoint for each std::terminate |
7554 | master breakpoint. */ | |
7555 | void | |
7556 | set_std_terminate_breakpoint (void) | |
7557 | { | |
35df4500 | 7558 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7559 | |
35df4500 | 7560 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7561 | if (b->pspace == current_program_space |
7562 | && b->type == bp_std_terminate_master) | |
7563 | { | |
06edf0c0 | 7564 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7565 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7566 | } |
7567 | } | |
7568 | ||
7569 | /* Delete all the std::terminate breakpoints. */ | |
7570 | void | |
7571 | delete_std_terminate_breakpoint (void) | |
7572 | { | |
35df4500 | 7573 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7574 | |
35df4500 | 7575 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7576 | if (b->type == bp_std_terminate) |
7577 | delete_breakpoint (b); | |
7578 | } | |
7579 | ||
c4093a6a | 7580 | struct breakpoint * |
a6d9a66e | 7581 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7582 | { |
7583 | struct breakpoint *b; | |
c4093a6a | 7584 | |
06edf0c0 PA |
7585 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7586 | &internal_breakpoint_ops); | |
7587 | ||
b5de0fa7 | 7588 | b->enable_state = bp_enabled; |
c4093a6a | 7589 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
7590 | b->addr_string |
7591 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 7592 | |
44702360 | 7593 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7594 | |
c4093a6a JM |
7595 | return b; |
7596 | } | |
7597 | ||
7598 | void | |
7599 | remove_thread_event_breakpoints (void) | |
7600 | { | |
35df4500 | 7601 | struct breakpoint *b, *b_tmp; |
c4093a6a | 7602 | |
35df4500 | 7603 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7604 | if (b->type == bp_thread_event |
7605 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
7606 | delete_breakpoint (b); |
7607 | } | |
7608 | ||
0101ce28 JJ |
7609 | struct lang_and_radix |
7610 | { | |
7611 | enum language lang; | |
7612 | int radix; | |
7613 | }; | |
7614 | ||
4efc6507 DE |
7615 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7616 | ||
7617 | struct breakpoint * | |
7618 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7619 | { | |
7620 | struct breakpoint *b; | |
7621 | ||
06edf0c0 PA |
7622 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7623 | &internal_breakpoint_ops); | |
44702360 | 7624 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
4efc6507 DE |
7625 | return b; |
7626 | } | |
0101ce28 | 7627 | |
03673fc7 PP |
7628 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7629 | ||
7630 | void | |
7631 | remove_jit_event_breakpoints (void) | |
7632 | { | |
7633 | struct breakpoint *b, *b_tmp; | |
7634 | ||
7635 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7636 | if (b->type == bp_jit_event | |
7637 | && b->loc->pspace == current_program_space) | |
7638 | delete_breakpoint (b); | |
7639 | } | |
7640 | ||
cae688ec JJ |
7641 | void |
7642 | remove_solib_event_breakpoints (void) | |
7643 | { | |
35df4500 | 7644 | struct breakpoint *b, *b_tmp; |
cae688ec | 7645 | |
35df4500 | 7646 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7647 | if (b->type == bp_shlib_event |
7648 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7649 | delete_breakpoint (b); |
7650 | } | |
7651 | ||
f37f681c PA |
7652 | /* See breakpoint.h. */ |
7653 | ||
7654 | void | |
7655 | remove_solib_event_breakpoints_at_next_stop (void) | |
7656 | { | |
7657 | struct breakpoint *b, *b_tmp; | |
7658 | ||
7659 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7660 | if (b->type == bp_shlib_event | |
7661 | && b->loc->pspace == current_program_space) | |
7662 | b->disposition = disp_del_at_next_stop; | |
7663 | } | |
7664 | ||
04086b45 PA |
7665 | /* Helper for create_solib_event_breakpoint / |
7666 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7667 | INSERT_MODE to pass through to update_global_location_list. */ | |
7668 | ||
7669 | static struct breakpoint * | |
7670 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7671 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7672 | { |
7673 | struct breakpoint *b; | |
7674 | ||
06edf0c0 PA |
7675 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7676 | &internal_breakpoint_ops); | |
04086b45 | 7677 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7678 | return b; |
7679 | } | |
7680 | ||
04086b45 PA |
7681 | struct breakpoint * |
7682 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7683 | { | |
7684 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7685 | } | |
7686 | ||
f37f681c PA |
7687 | /* See breakpoint.h. */ |
7688 | ||
7689 | struct breakpoint * | |
7690 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7691 | { | |
7692 | struct breakpoint *b; | |
7693 | ||
04086b45 PA |
7694 | /* Explicitly tell update_global_location_list to insert |
7695 | locations. */ | |
7696 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7697 | if (!b->loc->inserted) |
7698 | { | |
7699 | delete_breakpoint (b); | |
7700 | return NULL; | |
7701 | } | |
7702 | return b; | |
7703 | } | |
7704 | ||
cae688ec JJ |
7705 | /* Disable any breakpoints that are on code in shared libraries. Only |
7706 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7707 | ||
7708 | void | |
cb851954 | 7709 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7710 | { |
876fa593 | 7711 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7712 | |
876fa593 | 7713 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7714 | { |
2bdf28a0 | 7715 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7716 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7717 | |
4a64f543 MS |
7718 | /* We apply the check to all breakpoints, including disabled for |
7719 | those with loc->duplicate set. This is so that when breakpoint | |
7720 | becomes enabled, or the duplicate is removed, gdb will try to | |
7721 | insert all breakpoints. If we don't set shlib_disabled here, | |
7722 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7723 | if (((b->type == bp_breakpoint) |
508ccb1f | 7724 | || (b->type == bp_jit_event) |
1042e4c0 | 7725 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7726 | || (is_tracepoint (b))) |
6c95b8df | 7727 | && loc->pspace == current_program_space |
0d381245 | 7728 | && !loc->shlib_disabled |
6c95b8df | 7729 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7730 | ) |
0d381245 VP |
7731 | { |
7732 | loc->shlib_disabled = 1; | |
7733 | } | |
cae688ec JJ |
7734 | } |
7735 | } | |
7736 | ||
63644780 NB |
7737 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7738 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7739 | disabled ones can just stay disabled. */ | |
84acb35a | 7740 | |
75149521 | 7741 | static void |
84acb35a JJ |
7742 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7743 | { | |
876fa593 | 7744 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7745 | int disabled_shlib_breaks = 0; |
7746 | ||
c86cf029 VP |
7747 | /* SunOS a.out shared libraries are always mapped, so do not |
7748 | disable breakpoints; they will only be reported as unloaded | |
7749 | through clear_solib when GDB discards its shared library | |
7750 | list. See clear_solib for more information. */ | |
7751 | if (exec_bfd != NULL | |
7752 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7753 | return; | |
7754 | ||
876fa593 | 7755 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7756 | { |
2bdf28a0 | 7757 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7758 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7759 | |
1e4d1764 | 7760 | if (solib->pspace == loc->pspace |
e2dd7057 | 7761 | && !loc->shlib_disabled |
1e4d1764 YQ |
7762 | && (((b->type == bp_breakpoint |
7763 | || b->type == bp_jit_event | |
7764 | || b->type == bp_hardware_breakpoint) | |
7765 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7766 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7767 | || is_tracepoint (b)) | |
e2dd7057 | 7768 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7769 | { |
e2dd7057 PP |
7770 | loc->shlib_disabled = 1; |
7771 | /* At this point, we cannot rely on remove_breakpoint | |
7772 | succeeding so we must mark the breakpoint as not inserted | |
7773 | to prevent future errors occurring in remove_breakpoints. */ | |
7774 | loc->inserted = 0; | |
8d3788bd VP |
7775 | |
7776 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7777 | observer_notify_breakpoint_modified (b); | |
7778 | ||
e2dd7057 PP |
7779 | if (!disabled_shlib_breaks) |
7780 | { | |
7781 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7782 | warning (_("Temporarily disabling breakpoints " |
7783 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7784 | solib->so_name); |
84acb35a | 7785 | } |
e2dd7057 | 7786 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7787 | } |
7788 | } | |
84acb35a JJ |
7789 | } |
7790 | ||
63644780 NB |
7791 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7792 | notification of free_objfile. Only apply to enabled breakpoints, | |
7793 | disabled ones can just stay disabled. */ | |
7794 | ||
7795 | static void | |
7796 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7797 | { | |
7798 | struct breakpoint *b; | |
7799 | ||
7800 | if (objfile == NULL) | |
7801 | return; | |
7802 | ||
d03de421 PA |
7803 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7804 | managed by the user with add-symbol-file/remove-symbol-file. | |
7805 | Similarly to how breakpoints in shared libraries are handled in | |
7806 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7807 | shlib_disabled so they end up uninserted on the next global |
7808 | location list update. Shared libraries not loaded by the user | |
7809 | aren't handled here -- they're already handled in | |
7810 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7811 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7812 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7813 | main objfile). */ | |
7814 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7815 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7816 | return; |
7817 | ||
7818 | ALL_BREAKPOINTS (b) | |
7819 | { | |
7820 | struct bp_location *loc; | |
7821 | int bp_modified = 0; | |
7822 | ||
7823 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7824 | continue; | |
7825 | ||
7826 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7827 | { | |
7828 | CORE_ADDR loc_addr = loc->address; | |
7829 | ||
7830 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7831 | && loc->loc_type != bp_loc_software_breakpoint) | |
7832 | continue; | |
7833 | ||
7834 | if (loc->shlib_disabled != 0) | |
7835 | continue; | |
7836 | ||
7837 | if (objfile->pspace != loc->pspace) | |
7838 | continue; | |
7839 | ||
7840 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7841 | && loc->loc_type != bp_loc_software_breakpoint) | |
7842 | continue; | |
7843 | ||
7844 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7845 | { | |
7846 | loc->shlib_disabled = 1; | |
08351840 PA |
7847 | /* At this point, we don't know whether the object was |
7848 | unmapped from the inferior or not, so leave the | |
7849 | inserted flag alone. We'll handle failure to | |
7850 | uninsert quietly, in case the object was indeed | |
7851 | unmapped. */ | |
63644780 NB |
7852 | |
7853 | mark_breakpoint_location_modified (loc); | |
7854 | ||
7855 | bp_modified = 1; | |
7856 | } | |
7857 | } | |
7858 | ||
7859 | if (bp_modified) | |
7860 | observer_notify_breakpoint_modified (b); | |
7861 | } | |
7862 | } | |
7863 | ||
ce78b96d JB |
7864 | /* FORK & VFORK catchpoints. */ |
7865 | ||
e29a4733 PA |
7866 | /* An instance of this type is used to represent a fork or vfork |
7867 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
7868 | class; users downcast to "struct breakpoint *" when needed. A | |
7869 | breakpoint is really of this type iff its ops pointer points to | |
7870 | CATCH_FORK_BREAKPOINT_OPS. */ | |
7871 | ||
7872 | struct fork_catchpoint | |
7873 | { | |
7874 | /* The base class. */ | |
7875 | struct breakpoint base; | |
7876 | ||
7877 | /* Process id of a child process whose forking triggered this | |
7878 | catchpoint. This field is only valid immediately after this | |
7879 | catchpoint has triggered. */ | |
7880 | ptid_t forked_inferior_pid; | |
7881 | }; | |
7882 | ||
4a64f543 MS |
7883 | /* Implement the "insert" breakpoint_ops method for fork |
7884 | catchpoints. */ | |
ce78b96d | 7885 | |
77b06cd7 TJB |
7886 | static int |
7887 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7888 | { |
dfd4cc63 | 7889 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7890 | } |
7891 | ||
4a64f543 MS |
7892 | /* Implement the "remove" breakpoint_ops method for fork |
7893 | catchpoints. */ | |
ce78b96d JB |
7894 | |
7895 | static int | |
77b06cd7 | 7896 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 7897 | { |
dfd4cc63 | 7898 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7899 | } |
7900 | ||
7901 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7902 | catchpoints. */ | |
7903 | ||
7904 | static int | |
f1310107 | 7905 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7906 | struct address_space *aspace, CORE_ADDR bp_addr, |
7907 | const struct target_waitstatus *ws) | |
ce78b96d | 7908 | { |
e29a4733 PA |
7909 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7910 | ||
f90263c1 TT |
7911 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7912 | return 0; | |
7913 | ||
7914 | c->forked_inferior_pid = ws->value.related_pid; | |
7915 | return 1; | |
ce78b96d JB |
7916 | } |
7917 | ||
4a64f543 MS |
7918 | /* Implement the "print_it" breakpoint_ops method for fork |
7919 | catchpoints. */ | |
ce78b96d JB |
7920 | |
7921 | static enum print_stop_action | |
348d480f | 7922 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7923 | { |
36dfb11c | 7924 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7925 | struct breakpoint *b = bs->breakpoint_at; |
7926 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7927 | |
ce78b96d | 7928 | annotate_catchpoint (b->number); |
36dfb11c TT |
7929 | if (b->disposition == disp_del) |
7930 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
7931 | else | |
7932 | ui_out_text (uiout, "\nCatchpoint "); | |
7933 | if (ui_out_is_mi_like_p (uiout)) | |
7934 | { | |
7935 | ui_out_field_string (uiout, "reason", | |
7936 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
7937 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7938 | } | |
7939 | ui_out_field_int (uiout, "bkptno", b->number); | |
7940 | ui_out_text (uiout, " (forked process "); | |
7941 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7942 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
7943 | return PRINT_SRC_AND_LOC; |
7944 | } | |
7945 | ||
4a64f543 MS |
7946 | /* Implement the "print_one" breakpoint_ops method for fork |
7947 | catchpoints. */ | |
ce78b96d JB |
7948 | |
7949 | static void | |
a6d9a66e | 7950 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7951 | { |
e29a4733 | 7952 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7953 | struct value_print_options opts; |
79a45e25 | 7954 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7955 | |
7956 | get_user_print_options (&opts); | |
7957 | ||
4a64f543 MS |
7958 | /* Field 4, the address, is omitted (which makes the columns not |
7959 | line up too nicely with the headers, but the effect is relatively | |
7960 | readable). */ | |
79a45b7d | 7961 | if (opts.addressprint) |
ce78b96d JB |
7962 | ui_out_field_skip (uiout, "addr"); |
7963 | annotate_field (5); | |
7964 | ui_out_text (uiout, "fork"); | |
e29a4733 | 7965 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
7966 | { |
7967 | ui_out_text (uiout, ", process "); | |
7968 | ui_out_field_int (uiout, "what", | |
e29a4733 | 7969 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
7970 | ui_out_spaces (uiout, 1); |
7971 | } | |
8ac3646f TT |
7972 | |
7973 | if (ui_out_is_mi_like_p (uiout)) | |
7974 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
7975 | } |
7976 | ||
7977 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7978 | catchpoints. */ | |
7979 | ||
7980 | static void | |
7981 | print_mention_catch_fork (struct breakpoint *b) | |
7982 | { | |
7983 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7984 | } | |
7985 | ||
6149aea9 PA |
7986 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7987 | catchpoints. */ | |
7988 | ||
7989 | static void | |
7990 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7991 | { | |
7992 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7993 | print_recreate_thread (b, fp); |
6149aea9 PA |
7994 | } |
7995 | ||
ce78b96d JB |
7996 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7997 | ||
2060206e | 7998 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7999 | |
4a64f543 MS |
8000 | /* Implement the "insert" breakpoint_ops method for vfork |
8001 | catchpoints. */ | |
ce78b96d | 8002 | |
77b06cd7 TJB |
8003 | static int |
8004 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8005 | { |
dfd4cc63 | 8006 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8007 | } |
8008 | ||
4a64f543 MS |
8009 | /* Implement the "remove" breakpoint_ops method for vfork |
8010 | catchpoints. */ | |
ce78b96d JB |
8011 | |
8012 | static int | |
77b06cd7 | 8013 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 8014 | { |
dfd4cc63 | 8015 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8016 | } |
8017 | ||
8018 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8019 | catchpoints. */ | |
8020 | ||
8021 | static int | |
f1310107 | 8022 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8023 | struct address_space *aspace, CORE_ADDR bp_addr, |
8024 | const struct target_waitstatus *ws) | |
ce78b96d | 8025 | { |
e29a4733 PA |
8026 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8027 | ||
f90263c1 TT |
8028 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8029 | return 0; | |
8030 | ||
8031 | c->forked_inferior_pid = ws->value.related_pid; | |
8032 | return 1; | |
ce78b96d JB |
8033 | } |
8034 | ||
4a64f543 MS |
8035 | /* Implement the "print_it" breakpoint_ops method for vfork |
8036 | catchpoints. */ | |
ce78b96d JB |
8037 | |
8038 | static enum print_stop_action | |
348d480f | 8039 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8040 | { |
36dfb11c | 8041 | struct ui_out *uiout = current_uiout; |
348d480f | 8042 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8043 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8044 | ||
ce78b96d | 8045 | annotate_catchpoint (b->number); |
36dfb11c TT |
8046 | if (b->disposition == disp_del) |
8047 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8048 | else | |
8049 | ui_out_text (uiout, "\nCatchpoint "); | |
8050 | if (ui_out_is_mi_like_p (uiout)) | |
8051 | { | |
8052 | ui_out_field_string (uiout, "reason", | |
8053 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8054 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8055 | } | |
8056 | ui_out_field_int (uiout, "bkptno", b->number); | |
8057 | ui_out_text (uiout, " (vforked process "); | |
8058 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8059 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8060 | return PRINT_SRC_AND_LOC; |
8061 | } | |
8062 | ||
4a64f543 MS |
8063 | /* Implement the "print_one" breakpoint_ops method for vfork |
8064 | catchpoints. */ | |
ce78b96d JB |
8065 | |
8066 | static void | |
a6d9a66e | 8067 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8068 | { |
e29a4733 | 8069 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8070 | struct value_print_options opts; |
79a45e25 | 8071 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8072 | |
8073 | get_user_print_options (&opts); | |
4a64f543 MS |
8074 | /* Field 4, the address, is omitted (which makes the columns not |
8075 | line up too nicely with the headers, but the effect is relatively | |
8076 | readable). */ | |
79a45b7d | 8077 | if (opts.addressprint) |
ce78b96d JB |
8078 | ui_out_field_skip (uiout, "addr"); |
8079 | annotate_field (5); | |
8080 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8081 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8082 | { |
8083 | ui_out_text (uiout, ", process "); | |
8084 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8085 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8086 | ui_out_spaces (uiout, 1); |
8087 | } | |
8ac3646f TT |
8088 | |
8089 | if (ui_out_is_mi_like_p (uiout)) | |
8090 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8091 | } |
8092 | ||
8093 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8094 | catchpoints. */ | |
8095 | ||
8096 | static void | |
8097 | print_mention_catch_vfork (struct breakpoint *b) | |
8098 | { | |
8099 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8100 | } | |
8101 | ||
6149aea9 PA |
8102 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8103 | catchpoints. */ | |
8104 | ||
8105 | static void | |
8106 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8107 | { | |
8108 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8109 | print_recreate_thread (b, fp); |
6149aea9 PA |
8110 | } |
8111 | ||
ce78b96d JB |
8112 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8113 | ||
2060206e | 8114 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8115 | |
edcc5120 TT |
8116 | /* An instance of this type is used to represent an solib catchpoint. |
8117 | It includes a "struct breakpoint" as a kind of base class; users | |
8118 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8119 | really of this type iff its ops pointer points to | |
8120 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8121 | ||
8122 | struct solib_catchpoint | |
8123 | { | |
8124 | /* The base class. */ | |
8125 | struct breakpoint base; | |
8126 | ||
8127 | /* True for "catch load", false for "catch unload". */ | |
8128 | unsigned char is_load; | |
8129 | ||
8130 | /* Regular expression to match, if any. COMPILED is only valid when | |
8131 | REGEX is non-NULL. */ | |
8132 | char *regex; | |
8133 | regex_t compiled; | |
8134 | }; | |
8135 | ||
8136 | static void | |
8137 | dtor_catch_solib (struct breakpoint *b) | |
8138 | { | |
8139 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8140 | ||
8141 | if (self->regex) | |
8142 | regfree (&self->compiled); | |
8143 | xfree (self->regex); | |
8144 | ||
8145 | base_breakpoint_ops.dtor (b); | |
8146 | } | |
8147 | ||
8148 | static int | |
8149 | insert_catch_solib (struct bp_location *ignore) | |
8150 | { | |
8151 | return 0; | |
8152 | } | |
8153 | ||
8154 | static int | |
8155 | remove_catch_solib (struct bp_location *ignore) | |
8156 | { | |
8157 | return 0; | |
8158 | } | |
8159 | ||
8160 | static int | |
8161 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8162 | struct address_space *aspace, | |
8163 | CORE_ADDR bp_addr, | |
8164 | const struct target_waitstatus *ws) | |
8165 | { | |
8166 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8167 | struct breakpoint *other; | |
8168 | ||
8169 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8170 | return 1; | |
8171 | ||
8172 | ALL_BREAKPOINTS (other) | |
8173 | { | |
8174 | struct bp_location *other_bl; | |
8175 | ||
8176 | if (other == bl->owner) | |
8177 | continue; | |
8178 | ||
8179 | if (other->type != bp_shlib_event) | |
8180 | continue; | |
8181 | ||
8182 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8183 | continue; | |
8184 | ||
8185 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8186 | { | |
8187 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8188 | return 1; | |
8189 | } | |
8190 | } | |
8191 | ||
8192 | return 0; | |
8193 | } | |
8194 | ||
8195 | static void | |
8196 | check_status_catch_solib (struct bpstats *bs) | |
8197 | { | |
8198 | struct solib_catchpoint *self | |
8199 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8200 | int ix; | |
8201 | ||
8202 | if (self->is_load) | |
8203 | { | |
8204 | struct so_list *iter; | |
8205 | ||
8206 | for (ix = 0; | |
8207 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8208 | ix, iter); | |
8209 | ++ix) | |
8210 | { | |
8211 | if (!self->regex | |
8212 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8213 | return; | |
8214 | } | |
8215 | } | |
8216 | else | |
8217 | { | |
8218 | char *iter; | |
8219 | ||
8220 | for (ix = 0; | |
8221 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8222 | ix, iter); | |
8223 | ++ix) | |
8224 | { | |
8225 | if (!self->regex | |
8226 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8227 | return; | |
8228 | } | |
8229 | } | |
8230 | ||
8231 | bs->stop = 0; | |
8232 | bs->print_it = print_it_noop; | |
8233 | } | |
8234 | ||
8235 | static enum print_stop_action | |
8236 | print_it_catch_solib (bpstat bs) | |
8237 | { | |
8238 | struct breakpoint *b = bs->breakpoint_at; | |
8239 | struct ui_out *uiout = current_uiout; | |
8240 | ||
8241 | annotate_catchpoint (b->number); | |
8242 | if (b->disposition == disp_del) | |
8243 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8244 | else | |
8245 | ui_out_text (uiout, "\nCatchpoint "); | |
8246 | ui_out_field_int (uiout, "bkptno", b->number); | |
8247 | ui_out_text (uiout, "\n"); | |
8248 | if (ui_out_is_mi_like_p (uiout)) | |
8249 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8250 | print_solib_event (1); | |
8251 | return PRINT_SRC_AND_LOC; | |
8252 | } | |
8253 | ||
8254 | static void | |
8255 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8256 | { | |
8257 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8258 | struct value_print_options opts; | |
8259 | struct ui_out *uiout = current_uiout; | |
8260 | char *msg; | |
8261 | ||
8262 | get_user_print_options (&opts); | |
8263 | /* Field 4, the address, is omitted (which makes the columns not | |
8264 | line up too nicely with the headers, but the effect is relatively | |
8265 | readable). */ | |
8266 | if (opts.addressprint) | |
8267 | { | |
8268 | annotate_field (4); | |
8269 | ui_out_field_skip (uiout, "addr"); | |
8270 | } | |
8271 | ||
8272 | annotate_field (5); | |
8273 | if (self->is_load) | |
8274 | { | |
8275 | if (self->regex) | |
8276 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8277 | else | |
8278 | msg = xstrdup (_("load of library")); | |
8279 | } | |
8280 | else | |
8281 | { | |
8282 | if (self->regex) | |
8283 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8284 | else | |
8285 | msg = xstrdup (_("unload of library")); | |
8286 | } | |
8287 | ui_out_field_string (uiout, "what", msg); | |
8288 | xfree (msg); | |
8ac3646f TT |
8289 | |
8290 | if (ui_out_is_mi_like_p (uiout)) | |
8291 | ui_out_field_string (uiout, "catch-type", | |
8292 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8293 | } |
8294 | ||
8295 | static void | |
8296 | print_mention_catch_solib (struct breakpoint *b) | |
8297 | { | |
8298 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8299 | ||
8300 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8301 | self->is_load ? "load" : "unload"); | |
8302 | } | |
8303 | ||
8304 | static void | |
8305 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8306 | { | |
8307 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8308 | ||
8309 | fprintf_unfiltered (fp, "%s %s", | |
8310 | b->disposition == disp_del ? "tcatch" : "catch", | |
8311 | self->is_load ? "load" : "unload"); | |
8312 | if (self->regex) | |
8313 | fprintf_unfiltered (fp, " %s", self->regex); | |
8314 | fprintf_unfiltered (fp, "\n"); | |
8315 | } | |
8316 | ||
8317 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8318 | ||
91985142 MG |
8319 | /* Shared helper function (MI and CLI) for creating and installing |
8320 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8321 | the events to be caught are load events, otherwise they are | |
8322 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8323 | temporary one. If ENABLED is non-zero the catchpoint is | |
8324 | created in an enabled state. */ | |
edcc5120 | 8325 | |
91985142 MG |
8326 | void |
8327 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8328 | { |
8329 | struct solib_catchpoint *c; | |
8330 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8331 | struct cleanup *cleanup; |
8332 | ||
edcc5120 TT |
8333 | if (!arg) |
8334 | arg = ""; | |
8335 | arg = skip_spaces (arg); | |
8336 | ||
8337 | c = XCNEW (struct solib_catchpoint); | |
8338 | cleanup = make_cleanup (xfree, c); | |
8339 | ||
8340 | if (*arg != '\0') | |
8341 | { | |
8342 | int errcode; | |
8343 | ||
8344 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8345 | if (errcode != 0) | |
8346 | { | |
8347 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8348 | ||
8349 | make_cleanup (xfree, err); | |
8350 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8351 | } | |
8352 | c->regex = xstrdup (arg); | |
8353 | } | |
8354 | ||
8355 | c->is_load = is_load; | |
91985142 | 8356 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8357 | &catch_solib_breakpoint_ops); |
8358 | ||
91985142 MG |
8359 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8360 | ||
edcc5120 TT |
8361 | discard_cleanups (cleanup); |
8362 | install_breakpoint (0, &c->base, 1); | |
8363 | } | |
8364 | ||
91985142 MG |
8365 | /* A helper function that does all the work for "catch load" and |
8366 | "catch unload". */ | |
8367 | ||
8368 | static void | |
8369 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8370 | struct cmd_list_element *command) | |
8371 | { | |
8372 | int tempflag; | |
8373 | const int enabled = 1; | |
8374 | ||
8375 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8376 | ||
8377 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8378 | } | |
8379 | ||
edcc5120 TT |
8380 | static void |
8381 | catch_load_command_1 (char *arg, int from_tty, | |
8382 | struct cmd_list_element *command) | |
8383 | { | |
8384 | catch_load_or_unload (arg, from_tty, 1, command); | |
8385 | } | |
8386 | ||
8387 | static void | |
8388 | catch_unload_command_1 (char *arg, int from_tty, | |
8389 | struct cmd_list_element *command) | |
8390 | { | |
8391 | catch_load_or_unload (arg, from_tty, 0, command); | |
8392 | } | |
8393 | ||
be5c67c1 PA |
8394 | /* An instance of this type is used to represent a syscall catchpoint. |
8395 | It includes a "struct breakpoint" as a kind of base class; users | |
8396 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8397 | really of this type iff its ops pointer points to | |
8398 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
8399 | ||
8400 | struct syscall_catchpoint | |
8401 | { | |
8402 | /* The base class. */ | |
8403 | struct breakpoint base; | |
8404 | ||
8405 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
8406 | syscall has been specified for filtering, its value is NULL. | |
8407 | Otherwise, it holds a list of all syscalls to be caught. The | |
8408 | list elements are allocated with xmalloc. */ | |
8409 | VEC(int) *syscalls_to_be_caught; | |
8410 | }; | |
8411 | ||
8412 | /* Implement the "dtor" breakpoint_ops method for syscall | |
8413 | catchpoints. */ | |
8414 | ||
8415 | static void | |
8416 | dtor_catch_syscall (struct breakpoint *b) | |
8417 | { | |
8418 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
8419 | ||
8420 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 8421 | |
2060206e | 8422 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
8423 | } |
8424 | ||
fa3064dd YQ |
8425 | static const struct inferior_data *catch_syscall_inferior_data = NULL; |
8426 | ||
8427 | struct catch_syscall_inferior_data | |
8428 | { | |
8429 | /* We keep a count of the number of times the user has requested a | |
8430 | particular syscall to be tracked, and pass this information to the | |
8431 | target. This lets capable targets implement filtering directly. */ | |
8432 | ||
8433 | /* Number of times that "any" syscall is requested. */ | |
8434 | int any_syscall_count; | |
8435 | ||
8436 | /* Count of each system call. */ | |
8437 | VEC(int) *syscalls_counts; | |
8438 | ||
8439 | /* This counts all syscall catch requests, so we can readily determine | |
8440 | if any catching is necessary. */ | |
8441 | int total_syscalls_count; | |
8442 | }; | |
8443 | ||
8444 | static struct catch_syscall_inferior_data* | |
8445 | get_catch_syscall_inferior_data (struct inferior *inf) | |
8446 | { | |
8447 | struct catch_syscall_inferior_data *inf_data; | |
8448 | ||
8449 | inf_data = inferior_data (inf, catch_syscall_inferior_data); | |
8450 | if (inf_data == NULL) | |
8451 | { | |
41bf6aca | 8452 | inf_data = XCNEW (struct catch_syscall_inferior_data); |
fa3064dd YQ |
8453 | set_inferior_data (inf, catch_syscall_inferior_data, inf_data); |
8454 | } | |
8455 | ||
8456 | return inf_data; | |
8457 | } | |
8458 | ||
8459 | static void | |
8460 | catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) | |
8461 | { | |
8462 | xfree (arg); | |
8463 | } | |
8464 | ||
8465 | ||
a96d9b2e SDJ |
8466 | /* Implement the "insert" breakpoint_ops method for syscall |
8467 | catchpoints. */ | |
8468 | ||
77b06cd7 TJB |
8469 | static int |
8470 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 8471 | { |
be5c67c1 | 8472 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8473 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8474 | struct catch_syscall_inferior_data *inf_data |
8475 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8476 | |
fa3064dd | 8477 | ++inf_data->total_syscalls_count; |
be5c67c1 | 8478 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8479 | ++inf_data->any_syscall_count; |
a96d9b2e SDJ |
8480 | else |
8481 | { | |
8482 | int i, iter; | |
cc59ec59 | 8483 | |
a96d9b2e | 8484 | for (i = 0; |
be5c67c1 | 8485 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8486 | i++) |
8487 | { | |
8488 | int elem; | |
cc59ec59 | 8489 | |
fa3064dd | 8490 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e | 8491 | { |
fa3064dd | 8492 | int old_size = VEC_length (int, inf_data->syscalls_counts); |
3e43a32a MS |
8493 | uintptr_t vec_addr_offset |
8494 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e | 8495 | uintptr_t vec_addr; |
fa3064dd YQ |
8496 | VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); |
8497 | vec_addr = ((uintptr_t) VEC_address (int, | |
8498 | inf_data->syscalls_counts) | |
8499 | + vec_addr_offset); | |
a96d9b2e SDJ |
8500 | memset ((void *) vec_addr, 0, |
8501 | (iter + 1 - old_size) * sizeof (int)); | |
8502 | } | |
fa3064dd YQ |
8503 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8504 | VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); | |
a96d9b2e SDJ |
8505 | } |
8506 | } | |
8507 | ||
dfd4cc63 | 8508 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8509 | inf_data->total_syscalls_count != 0, |
8510 | inf_data->any_syscall_count, | |
8511 | VEC_length (int, | |
8512 | inf_data->syscalls_counts), | |
8513 | VEC_address (int, | |
8514 | inf_data->syscalls_counts)); | |
a96d9b2e SDJ |
8515 | } |
8516 | ||
8517 | /* Implement the "remove" breakpoint_ops method for syscall | |
8518 | catchpoints. */ | |
8519 | ||
8520 | static int | |
77b06cd7 | 8521 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 8522 | { |
be5c67c1 | 8523 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e | 8524 | struct inferior *inf = current_inferior (); |
fa3064dd YQ |
8525 | struct catch_syscall_inferior_data *inf_data |
8526 | = get_catch_syscall_inferior_data (inf); | |
a96d9b2e | 8527 | |
fa3064dd | 8528 | --inf_data->total_syscalls_count; |
be5c67c1 | 8529 | if (!c->syscalls_to_be_caught) |
fa3064dd | 8530 | --inf_data->any_syscall_count; |
a96d9b2e SDJ |
8531 | else |
8532 | { | |
8533 | int i, iter; | |
cc59ec59 | 8534 | |
a96d9b2e | 8535 | for (i = 0; |
be5c67c1 | 8536 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8537 | i++) |
8538 | { | |
8539 | int elem; | |
fa3064dd | 8540 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
a96d9b2e SDJ |
8541 | /* Shouldn't happen. */ |
8542 | continue; | |
fa3064dd YQ |
8543 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
8544 | VEC_replace (int, inf_data->syscalls_counts, iter, --elem); | |
a96d9b2e SDJ |
8545 | } |
8546 | } | |
8547 | ||
dfd4cc63 | 8548 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
fa3064dd YQ |
8549 | inf_data->total_syscalls_count != 0, |
8550 | inf_data->any_syscall_count, | |
8551 | VEC_length (int, | |
8552 | inf_data->syscalls_counts), | |
3e43a32a | 8553 | VEC_address (int, |
fa3064dd | 8554 | inf_data->syscalls_counts)); |
a96d9b2e SDJ |
8555 | } |
8556 | ||
8557 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
8558 | catchpoints. */ | |
8559 | ||
8560 | static int | |
f1310107 | 8561 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
09ac7c10 TT |
8562 | struct address_space *aspace, CORE_ADDR bp_addr, |
8563 | const struct target_waitstatus *ws) | |
a96d9b2e | 8564 | { |
4a64f543 MS |
8565 | /* We must check if we are catching specific syscalls in this |
8566 | breakpoint. If we are, then we must guarantee that the called | |
8567 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 8568 | int syscall_number = 0; |
be5c67c1 PA |
8569 | const struct syscall_catchpoint *c |
8570 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e | 8571 | |
f90263c1 TT |
8572 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
8573 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
a96d9b2e SDJ |
8574 | return 0; |
8575 | ||
f90263c1 TT |
8576 | syscall_number = ws->value.syscall_number; |
8577 | ||
a96d9b2e | 8578 | /* Now, checking if the syscall is the same. */ |
be5c67c1 | 8579 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8580 | { |
8581 | int i, iter; | |
cc59ec59 | 8582 | |
a96d9b2e | 8583 | for (i = 0; |
be5c67c1 | 8584 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8585 | i++) |
8586 | if (syscall_number == iter) | |
4924df79 GKB |
8587 | return 1; |
8588 | ||
8589 | return 0; | |
a96d9b2e SDJ |
8590 | } |
8591 | ||
8592 | return 1; | |
8593 | } | |
8594 | ||
8595 | /* Implement the "print_it" breakpoint_ops method for syscall | |
8596 | catchpoints. */ | |
8597 | ||
8598 | static enum print_stop_action | |
348d480f | 8599 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 8600 | { |
36dfb11c | 8601 | struct ui_out *uiout = current_uiout; |
348d480f | 8602 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
8603 | /* These are needed because we want to know in which state a |
8604 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
8605 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
8606 | must print "called syscall" or "returned from syscall". */ | |
8607 | ptid_t ptid; | |
8608 | struct target_waitstatus last; | |
8609 | struct syscall s; | |
458c8db8 | 8610 | struct gdbarch *gdbarch = bs->bp_location_at->gdbarch; |
a96d9b2e SDJ |
8611 | |
8612 | get_last_target_status (&ptid, &last); | |
8613 | ||
458c8db8 | 8614 | get_syscall_by_number (gdbarch, last.value.syscall_number, &s); |
a96d9b2e SDJ |
8615 | |
8616 | annotate_catchpoint (b->number); | |
8617 | ||
36dfb11c TT |
8618 | if (b->disposition == disp_del) |
8619 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 8620 | else |
36dfb11c TT |
8621 | ui_out_text (uiout, "\nCatchpoint "); |
8622 | if (ui_out_is_mi_like_p (uiout)) | |
8623 | { | |
8624 | ui_out_field_string (uiout, "reason", | |
8625 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
8626 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
8627 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
8628 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8629 | } | |
8630 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
8631 | |
8632 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
8633 | ui_out_text (uiout, " (call to syscall "); |
8634 | else | |
8635 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 8636 | |
36dfb11c TT |
8637 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
8638 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
8639 | if (s.name != NULL) | |
8640 | ui_out_field_string (uiout, "syscall-name", s.name); | |
8641 | ||
8642 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
8643 | |
8644 | return PRINT_SRC_AND_LOC; | |
8645 | } | |
8646 | ||
8647 | /* Implement the "print_one" breakpoint_ops method for syscall | |
8648 | catchpoints. */ | |
8649 | ||
8650 | static void | |
8651 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 8652 | struct bp_location **last_loc) |
a96d9b2e | 8653 | { |
be5c67c1 | 8654 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 8655 | struct value_print_options opts; |
79a45e25 | 8656 | struct ui_out *uiout = current_uiout; |
458c8db8 | 8657 | struct gdbarch *gdbarch = b->loc->gdbarch; |
a96d9b2e SDJ |
8658 | |
8659 | get_user_print_options (&opts); | |
4a64f543 MS |
8660 | /* Field 4, the address, is omitted (which makes the columns not |
8661 | line up too nicely with the headers, but the effect is relatively | |
8662 | readable). */ | |
a96d9b2e SDJ |
8663 | if (opts.addressprint) |
8664 | ui_out_field_skip (uiout, "addr"); | |
8665 | annotate_field (5); | |
8666 | ||
be5c67c1 PA |
8667 | if (c->syscalls_to_be_caught |
8668 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
8669 | ui_out_text (uiout, "syscalls \""); |
8670 | else | |
8671 | ui_out_text (uiout, "syscall \""); | |
8672 | ||
be5c67c1 | 8673 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
8674 | { |
8675 | int i, iter; | |
8676 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 8677 | |
a96d9b2e | 8678 | for (i = 0; |
be5c67c1 | 8679 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8680 | i++) |
8681 | { | |
8682 | char *x = text; | |
8683 | struct syscall s; | |
458c8db8 | 8684 | get_syscall_by_number (gdbarch, iter, &s); |
a96d9b2e SDJ |
8685 | |
8686 | if (s.name != NULL) | |
8687 | text = xstrprintf ("%s%s, ", text, s.name); | |
8688 | else | |
8689 | text = xstrprintf ("%s%d, ", text, iter); | |
8690 | ||
8691 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 8692 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
8693 | on every call. */ |
8694 | xfree (x); | |
8695 | } | |
8696 | /* Remove the last comma. */ | |
8697 | text[strlen (text) - 2] = '\0'; | |
8698 | ui_out_field_string (uiout, "what", text); | |
8699 | } | |
8700 | else | |
8701 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
8702 | ui_out_text (uiout, "\" "); | |
8ac3646f TT |
8703 | |
8704 | if (ui_out_is_mi_like_p (uiout)) | |
8705 | ui_out_field_string (uiout, "catch-type", "syscall"); | |
a96d9b2e SDJ |
8706 | } |
8707 | ||
8708 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
8709 | catchpoints. */ | |
8710 | ||
8711 | static void | |
8712 | print_mention_catch_syscall (struct breakpoint *b) | |
8713 | { | |
be5c67c1 | 8714 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
458c8db8 | 8715 | struct gdbarch *gdbarch = b->loc->gdbarch; |
be5c67c1 PA |
8716 | |
8717 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
8718 | { |
8719 | int i, iter; | |
8720 | ||
be5c67c1 | 8721 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
8722 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
8723 | else | |
8724 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
8725 | ||
8726 | for (i = 0; | |
be5c67c1 | 8727 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
8728 | i++) |
8729 | { | |
8730 | struct syscall s; | |
458c8db8 | 8731 | get_syscall_by_number (gdbarch, iter, &s); |
a96d9b2e SDJ |
8732 | |
8733 | if (s.name) | |
8734 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
8735 | else | |
8736 | printf_filtered (" %d", s.number); | |
8737 | } | |
8738 | printf_filtered (")"); | |
8739 | } | |
8740 | else | |
8741 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
8742 | b->number); | |
8743 | } | |
8744 | ||
6149aea9 PA |
8745 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
8746 | catchpoints. */ | |
8747 | ||
8748 | static void | |
8749 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
8750 | { | |
be5c67c1 | 8751 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
458c8db8 | 8752 | struct gdbarch *gdbarch = b->loc->gdbarch; |
be5c67c1 | 8753 | |
6149aea9 PA |
8754 | fprintf_unfiltered (fp, "catch syscall"); |
8755 | ||
be5c67c1 | 8756 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
8757 | { |
8758 | int i, iter; | |
8759 | ||
8760 | for (i = 0; | |
be5c67c1 | 8761 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
8762 | i++) |
8763 | { | |
8764 | struct syscall s; | |
8765 | ||
458c8db8 | 8766 | get_syscall_by_number (gdbarch, iter, &s); |
6149aea9 PA |
8767 | if (s.name) |
8768 | fprintf_unfiltered (fp, " %s", s.name); | |
8769 | else | |
8770 | fprintf_unfiltered (fp, " %d", s.number); | |
8771 | } | |
8772 | } | |
d9b3f62e | 8773 | print_recreate_thread (b, fp); |
6149aea9 PA |
8774 | } |
8775 | ||
a96d9b2e SDJ |
8776 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
8777 | ||
2060206e | 8778 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
8779 | |
8780 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
8781 | ||
8782 | static int | |
8783 | syscall_catchpoint_p (struct breakpoint *b) | |
8784 | { | |
8785 | return (b->ops == &catch_syscall_breakpoint_ops); | |
8786 | } | |
8787 | ||
346774a9 PA |
8788 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8789 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8790 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8791 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8792 | |
ab04a2af | 8793 | void |
346774a9 PA |
8794 | init_catchpoint (struct breakpoint *b, |
8795 | struct gdbarch *gdbarch, int tempflag, | |
8796 | char *cond_string, | |
c0a91b2b | 8797 | const struct breakpoint_ops *ops) |
c906108c | 8798 | { |
c5aa993b | 8799 | struct symtab_and_line sal; |
346774a9 | 8800 | |
fe39c653 | 8801 | init_sal (&sal); |
6c95b8df | 8802 | sal.pspace = current_program_space; |
c5aa993b | 8803 | |
28010a5d | 8804 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8805 | |
1b36a34b | 8806 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8807 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8808 | } |
8809 | ||
28010a5d | 8810 | void |
3ea46bff | 8811 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8812 | { |
8813 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8814 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8815 | if (is_tracepoint (b)) |
8816 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8817 | if (!internal) |
8818 | mention (b); | |
c56053d2 | 8819 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8820 | |
8821 | if (update_gll) | |
44702360 | 8822 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8823 | } |
8824 | ||
9b70b993 | 8825 | static void |
a6d9a66e UW |
8826 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8827 | int tempflag, char *cond_string, | |
c0a91b2b | 8828 | const struct breakpoint_ops *ops) |
c906108c | 8829 | { |
e29a4733 | 8830 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8831 | |
e29a4733 PA |
8832 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8833 | ||
8834 | c->forked_inferior_pid = null_ptid; | |
8835 | ||
3ea46bff | 8836 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8837 | } |
8838 | ||
fe798b75 JB |
8839 | /* Exec catchpoints. */ |
8840 | ||
b4d90040 PA |
8841 | /* An instance of this type is used to represent an exec catchpoint. |
8842 | It includes a "struct breakpoint" as a kind of base class; users | |
8843 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8844 | really of this type iff its ops pointer points to | |
8845 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8846 | ||
8847 | struct exec_catchpoint | |
8848 | { | |
8849 | /* The base class. */ | |
8850 | struct breakpoint base; | |
8851 | ||
8852 | /* Filename of a program whose exec triggered this catchpoint. | |
8853 | This field is only valid immediately after this catchpoint has | |
8854 | triggered. */ | |
8855 | char *exec_pathname; | |
8856 | }; | |
8857 | ||
8858 | /* Implement the "dtor" breakpoint_ops method for exec | |
8859 | catchpoints. */ | |
8860 | ||
8861 | static void | |
8862 | dtor_catch_exec (struct breakpoint *b) | |
8863 | { | |
8864 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8865 | ||
8866 | xfree (c->exec_pathname); | |
348d480f | 8867 | |
2060206e | 8868 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8869 | } |
8870 | ||
77b06cd7 TJB |
8871 | static int |
8872 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8873 | { |
dfd4cc63 | 8874 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8875 | } |
c906108c | 8876 | |
fe798b75 | 8877 | static int |
77b06cd7 | 8878 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8879 | { |
dfd4cc63 | 8880 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8881 | } |
c906108c | 8882 | |
fe798b75 | 8883 | static int |
f1310107 | 8884 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8885 | struct address_space *aspace, CORE_ADDR bp_addr, |
8886 | const struct target_waitstatus *ws) | |
fe798b75 | 8887 | { |
b4d90040 PA |
8888 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8889 | ||
f90263c1 TT |
8890 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8891 | return 0; | |
8892 | ||
8893 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8894 | return 1; | |
fe798b75 | 8895 | } |
c906108c | 8896 | |
fe798b75 | 8897 | static enum print_stop_action |
348d480f | 8898 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8899 | { |
36dfb11c | 8900 | struct ui_out *uiout = current_uiout; |
348d480f | 8901 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8902 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8903 | ||
fe798b75 | 8904 | annotate_catchpoint (b->number); |
36dfb11c TT |
8905 | if (b->disposition == disp_del) |
8906 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
8907 | else | |
8908 | ui_out_text (uiout, "\nCatchpoint "); | |
8909 | if (ui_out_is_mi_like_p (uiout)) | |
8910 | { | |
8911 | ui_out_field_string (uiout, "reason", | |
8912 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8913 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8914 | } | |
8915 | ui_out_field_int (uiout, "bkptno", b->number); | |
8916 | ui_out_text (uiout, " (exec'd "); | |
8917 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8918 | ui_out_text (uiout, "), "); | |
8919 | ||
fe798b75 | 8920 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8921 | } |
8922 | ||
fe798b75 | 8923 | static void |
a6d9a66e | 8924 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8925 | { |
b4d90040 | 8926 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8927 | struct value_print_options opts; |
79a45e25 | 8928 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8929 | |
8930 | get_user_print_options (&opts); | |
8931 | ||
8932 | /* Field 4, the address, is omitted (which makes the columns | |
8933 | not line up too nicely with the headers, but the effect | |
8934 | is relatively readable). */ | |
8935 | if (opts.addressprint) | |
8936 | ui_out_field_skip (uiout, "addr"); | |
8937 | annotate_field (5); | |
8938 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8939 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8940 | { |
8941 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8942 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8943 | ui_out_text (uiout, "\" "); |
8944 | } | |
8ac3646f TT |
8945 | |
8946 | if (ui_out_is_mi_like_p (uiout)) | |
8947 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8948 | } |
8949 | ||
8950 | static void | |
8951 | print_mention_catch_exec (struct breakpoint *b) | |
8952 | { | |
8953 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8954 | } | |
8955 | ||
6149aea9 PA |
8956 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8957 | catchpoints. */ | |
8958 | ||
8959 | static void | |
8960 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8961 | { | |
8962 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8963 | print_recreate_thread (b, fp); |
6149aea9 PA |
8964 | } |
8965 | ||
2060206e | 8966 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8967 | |
a96d9b2e SDJ |
8968 | static void |
8969 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 8970 | const struct breakpoint_ops *ops) |
a96d9b2e | 8971 | { |
be5c67c1 | 8972 | struct syscall_catchpoint *c; |
a96d9b2e | 8973 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 8974 | |
be5c67c1 PA |
8975 | c = XNEW (struct syscall_catchpoint); |
8976 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
8977 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 8978 | |
3ea46bff | 8979 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
8980 | } |
8981 | ||
c906108c | 8982 | static int |
fba45db2 | 8983 | hw_breakpoint_used_count (void) |
c906108c | 8984 | { |
c906108c | 8985 | int i = 0; |
f1310107 TJB |
8986 | struct breakpoint *b; |
8987 | struct bp_location *bl; | |
c906108c SS |
8988 | |
8989 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8990 | { |
d6b74ac4 | 8991 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8992 | for (bl = b->loc; bl; bl = bl->next) |
8993 | { | |
8994 | /* Special types of hardware breakpoints may use more than | |
8995 | one register. */ | |
348d480f | 8996 | i += b->ops->resources_needed (bl); |
f1310107 | 8997 | } |
c5aa993b | 8998 | } |
c906108c SS |
8999 | |
9000 | return i; | |
9001 | } | |
9002 | ||
a1398e0c PA |
9003 | /* Returns the resources B would use if it were a hardware |
9004 | watchpoint. */ | |
9005 | ||
c906108c | 9006 | static int |
a1398e0c | 9007 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 9008 | { |
c906108c | 9009 | int i = 0; |
e09342b5 | 9010 | struct bp_location *bl; |
c906108c | 9011 | |
a1398e0c PA |
9012 | if (!breakpoint_enabled (b)) |
9013 | return 0; | |
9014 | ||
9015 | for (bl = b->loc; bl; bl = bl->next) | |
9016 | { | |
9017 | /* Special types of hardware watchpoints may use more than | |
9018 | one register. */ | |
9019 | i += b->ops->resources_needed (bl); | |
9020 | } | |
9021 | ||
9022 | return i; | |
9023 | } | |
9024 | ||
9025 | /* Returns the sum the used resources of all hardware watchpoints of | |
9026 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
9027 | the sum of the used resources of all hardware watchpoints of other | |
9028 | types _not_ TYPE. */ | |
9029 | ||
9030 | static int | |
9031 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
9032 | enum bptype type, int *other_type_used) | |
9033 | { | |
9034 | int i = 0; | |
9035 | struct breakpoint *b; | |
9036 | ||
c906108c SS |
9037 | *other_type_used = 0; |
9038 | ALL_BREAKPOINTS (b) | |
e09342b5 | 9039 | { |
a1398e0c PA |
9040 | if (b == except) |
9041 | continue; | |
e09342b5 TJB |
9042 | if (!breakpoint_enabled (b)) |
9043 | continue; | |
9044 | ||
a1398e0c PA |
9045 | if (b->type == type) |
9046 | i += hw_watchpoint_use_count (b); | |
9047 | else if (is_hardware_watchpoint (b)) | |
9048 | *other_type_used = 1; | |
e09342b5 TJB |
9049 | } |
9050 | ||
c906108c SS |
9051 | return i; |
9052 | } | |
9053 | ||
c906108c | 9054 | void |
fba45db2 | 9055 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 9056 | { |
c5aa993b | 9057 | struct breakpoint *b; |
c906108c SS |
9058 | |
9059 | ALL_BREAKPOINTS (b) | |
c5aa993b | 9060 | { |
cc60f2e3 | 9061 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 9062 | { |
b5de0fa7 | 9063 | b->enable_state = bp_call_disabled; |
44702360 | 9064 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
9065 | } |
9066 | } | |
c906108c SS |
9067 | } |
9068 | ||
9069 | void | |
fba45db2 | 9070 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 9071 | { |
c5aa993b | 9072 | struct breakpoint *b; |
c906108c SS |
9073 | |
9074 | ALL_BREAKPOINTS (b) | |
c5aa993b | 9075 | { |
cc60f2e3 | 9076 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 9077 | { |
b5de0fa7 | 9078 | b->enable_state = bp_enabled; |
44702360 | 9079 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
9080 | } |
9081 | } | |
c906108c SS |
9082 | } |
9083 | ||
8bea4e01 UW |
9084 | void |
9085 | disable_breakpoints_before_startup (void) | |
9086 | { | |
6c95b8df | 9087 | current_program_space->executing_startup = 1; |
44702360 | 9088 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
9089 | } |
9090 | ||
9091 | void | |
9092 | enable_breakpoints_after_startup (void) | |
9093 | { | |
6c95b8df | 9094 | current_program_space->executing_startup = 0; |
f8eba3c6 | 9095 | breakpoint_re_set (); |
8bea4e01 UW |
9096 | } |
9097 | ||
7c16b83e PA |
9098 | /* Create a new single-step breakpoint for thread THREAD, with no |
9099 | locations. */ | |
c906108c | 9100 | |
7c16b83e PA |
9101 | static struct breakpoint * |
9102 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
9103 | { | |
9104 | struct breakpoint *b = XNEW (struct breakpoint); | |
9105 | ||
9106 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
9107 | &momentary_breakpoint_ops); | |
9108 | ||
9109 | b->disposition = disp_donttouch; | |
9110 | b->frame_id = null_frame_id; | |
9111 | ||
9112 | b->thread = thread; | |
9113 | gdb_assert (b->thread != 0); | |
9114 | ||
9115 | add_to_breakpoint_chain (b); | |
9116 | ||
9117 | return b; | |
9118 | } | |
9119 | ||
9120 | /* Set a momentary breakpoint of type TYPE at address specified by | |
9121 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
9122 | frame. */ | |
c906108c SS |
9123 | |
9124 | struct breakpoint * | |
a6d9a66e UW |
9125 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
9126 | struct frame_id frame_id, enum bptype type) | |
c906108c | 9127 | { |
52f0bd74 | 9128 | struct breakpoint *b; |
edb3359d | 9129 | |
193facb3 JK |
9130 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
9131 | tail-called one. */ | |
9132 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 9133 | |
06edf0c0 | 9134 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
9135 | b->enable_state = bp_enabled; |
9136 | b->disposition = disp_donttouch; | |
818dd999 | 9137 | b->frame_id = frame_id; |
c906108c | 9138 | |
4a64f543 MS |
9139 | /* If we're debugging a multi-threaded program, then we want |
9140 | momentary breakpoints to be active in only a single thread of | |
9141 | control. */ | |
39f77062 KB |
9142 | if (in_thread_list (inferior_ptid)) |
9143 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 9144 | |
44702360 | 9145 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 9146 | |
c906108c SS |
9147 | return b; |
9148 | } | |
611c83ae | 9149 | |
06edf0c0 | 9150 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
9151 | The new breakpoint will have type TYPE, use OPS as its |
9152 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 9153 | |
06edf0c0 PA |
9154 | static struct breakpoint * |
9155 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
9156 | enum bptype type, | |
a1aa2221 LM |
9157 | const struct breakpoint_ops *ops, |
9158 | int loc_enabled) | |
e58b0e63 PA |
9159 | { |
9160 | struct breakpoint *copy; | |
9161 | ||
06edf0c0 | 9162 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 9163 | copy->loc = allocate_bp_location (copy); |
0e30163f | 9164 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 9165 | |
a6d9a66e | 9166 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
9167 | copy->loc->requested_address = orig->loc->requested_address; |
9168 | copy->loc->address = orig->loc->address; | |
9169 | copy->loc->section = orig->loc->section; | |
6c95b8df | 9170 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 9171 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 9172 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 9173 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 9174 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
9175 | copy->frame_id = orig->frame_id; |
9176 | copy->thread = orig->thread; | |
6c95b8df | 9177 | copy->pspace = orig->pspace; |
e58b0e63 PA |
9178 | |
9179 | copy->enable_state = bp_enabled; | |
9180 | copy->disposition = disp_donttouch; | |
9181 | copy->number = internal_breakpoint_number--; | |
9182 | ||
44702360 | 9183 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
9184 | return copy; |
9185 | } | |
9186 | ||
06edf0c0 PA |
9187 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
9188 | ORIG is NULL. */ | |
9189 | ||
9190 | struct breakpoint * | |
9191 | clone_momentary_breakpoint (struct breakpoint *orig) | |
9192 | { | |
9193 | /* If there's nothing to clone, then return nothing. */ | |
9194 | if (orig == NULL) | |
9195 | return NULL; | |
9196 | ||
a1aa2221 | 9197 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
9198 | } |
9199 | ||
611c83ae | 9200 | struct breakpoint * |
a6d9a66e UW |
9201 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
9202 | enum bptype type) | |
611c83ae PA |
9203 | { |
9204 | struct symtab_and_line sal; | |
9205 | ||
9206 | sal = find_pc_line (pc, 0); | |
9207 | sal.pc = pc; | |
9208 | sal.section = find_pc_overlay (pc); | |
9209 | sal.explicit_pc = 1; | |
9210 | ||
a6d9a66e | 9211 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 9212 | } |
c906108c | 9213 | \f |
c5aa993b | 9214 | |
c906108c SS |
9215 | /* Tell the user we have just set a breakpoint B. */ |
9216 | ||
9217 | static void | |
fba45db2 | 9218 | mention (struct breakpoint *b) |
c906108c | 9219 | { |
348d480f | 9220 | b->ops->print_mention (b); |
79a45e25 | 9221 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 9222 | return; |
c906108c SS |
9223 | printf_filtered ("\n"); |
9224 | } | |
c906108c | 9225 | \f |
c5aa993b | 9226 | |
1a853c52 PA |
9227 | static int bp_loc_is_permanent (struct bp_location *loc); |
9228 | ||
0d381245 | 9229 | static struct bp_location * |
39d61571 | 9230 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
9231 | const struct symtab_and_line *sal) |
9232 | { | |
9233 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9234 | CORE_ADDR adjusted_address; |
9235 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9236 | ||
9237 | if (loc_gdbarch == NULL) | |
9238 | loc_gdbarch = b->gdbarch; | |
9239 | ||
9240 | /* Adjust the breakpoint's address prior to allocating a location. | |
9241 | Once we call allocate_bp_location(), that mostly uninitialized | |
9242 | location will be placed on the location chain. Adjustment of the | |
9243 | breakpoint may cause target_read_memory() to be called and we do | |
9244 | not want its scan of the location chain to find a breakpoint and | |
9245 | location that's only been partially initialized. */ | |
9246 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9247 | sal->pc, b->type); | |
0d381245 | 9248 | |
d30113d4 | 9249 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9250 | loc = allocate_bp_location (b); |
d30113d4 JK |
9251 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9252 | tmp = &((*tmp)->next)) | |
0d381245 | 9253 | ; |
d30113d4 | 9254 | loc->next = *tmp; |
0d381245 | 9255 | *tmp = loc; |
3742cc8b | 9256 | |
0d381245 | 9257 | loc->requested_address = sal->pc; |
3742cc8b | 9258 | loc->address = adjusted_address; |
6c95b8df | 9259 | loc->pspace = sal->pspace; |
729662a5 TT |
9260 | loc->probe.probe = sal->probe; |
9261 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9262 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9263 | loc->section = sal->section; |
3742cc8b | 9264 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9265 | loc->line_number = sal->line; |
2f202fde | 9266 | loc->symtab = sal->symtab; |
f8eba3c6 | 9267 | |
0e30163f JK |
9268 | set_breakpoint_location_function (loc, |
9269 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 PA |
9270 | |
9271 | if (bp_loc_is_permanent (loc)) | |
9272 | { | |
9273 | loc->inserted = 1; | |
9274 | loc->permanent = 1; | |
9275 | } | |
9276 | ||
0d381245 VP |
9277 | return loc; |
9278 | } | |
514f746b AR |
9279 | \f |
9280 | ||
9281 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9282 | return 0 otherwise. */ | |
9283 | ||
9284 | static int | |
9285 | bp_loc_is_permanent (struct bp_location *loc) | |
9286 | { | |
9287 | int len; | |
9288 | CORE_ADDR addr; | |
1afeeb75 | 9289 | const gdb_byte *bpoint; |
514f746b | 9290 | gdb_byte *target_mem; |
939c61fa JK |
9291 | struct cleanup *cleanup; |
9292 | int retval = 0; | |
514f746b AR |
9293 | |
9294 | gdb_assert (loc != NULL); | |
9295 | ||
9296 | addr = loc->address; | |
1afeeb75 | 9297 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 9298 | |
939c61fa | 9299 | /* Software breakpoints unsupported? */ |
1afeeb75 | 9300 | if (bpoint == NULL) |
939c61fa JK |
9301 | return 0; |
9302 | ||
514f746b AR |
9303 | target_mem = alloca (len); |
9304 | ||
939c61fa JK |
9305 | /* Enable the automatic memory restoration from breakpoints while |
9306 | we read the memory. Otherwise we could say about our temporary | |
9307 | breakpoints they are permanent. */ | |
6c95b8df PA |
9308 | cleanup = save_current_space_and_thread (); |
9309 | ||
9310 | switch_to_program_space_and_thread (loc->pspace); | |
9311 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 9312 | |
514f746b | 9313 | if (target_read_memory (loc->address, target_mem, len) == 0 |
1afeeb75 | 9314 | && memcmp (target_mem, bpoint, len) == 0) |
939c61fa | 9315 | retval = 1; |
514f746b | 9316 | |
939c61fa JK |
9317 | do_cleanups (cleanup); |
9318 | ||
9319 | return retval; | |
514f746b AR |
9320 | } |
9321 | ||
e7e0cddf SS |
9322 | /* Build a command list for the dprintf corresponding to the current |
9323 | settings of the dprintf style options. */ | |
9324 | ||
9325 | static void | |
9326 | update_dprintf_command_list (struct breakpoint *b) | |
9327 | { | |
9328 | char *dprintf_args = b->extra_string; | |
9329 | char *printf_line = NULL; | |
9330 | ||
9331 | if (!dprintf_args) | |
9332 | return; | |
9333 | ||
9334 | dprintf_args = skip_spaces (dprintf_args); | |
9335 | ||
9336 | /* Allow a comma, as it may have terminated a location, but don't | |
9337 | insist on it. */ | |
9338 | if (*dprintf_args == ',') | |
9339 | ++dprintf_args; | |
9340 | dprintf_args = skip_spaces (dprintf_args); | |
9341 | ||
9342 | if (*dprintf_args != '"') | |
9343 | error (_("Bad format string, missing '\"'.")); | |
9344 | ||
d3ce09f5 | 9345 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9346 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9347 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9348 | { |
9349 | if (!dprintf_function) | |
9350 | error (_("No function supplied for dprintf call")); | |
9351 | ||
9352 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9353 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9354 | dprintf_function, | |
9355 | dprintf_channel, | |
9356 | dprintf_args); | |
9357 | else | |
9358 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9359 | dprintf_function, | |
9360 | dprintf_args); | |
9361 | } | |
d3ce09f5 SS |
9362 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9363 | { | |
9364 | if (target_can_run_breakpoint_commands ()) | |
9365 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9366 | else | |
9367 | { | |
9368 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9369 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9370 | } | |
9371 | } | |
e7e0cddf SS |
9372 | else |
9373 | internal_error (__FILE__, __LINE__, | |
9374 | _("Invalid dprintf style.")); | |
9375 | ||
f28045c2 | 9376 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9377 | /* Manufacture a printf sequence. */ |
f28045c2 | 9378 | { |
9d6e6e84 HZ |
9379 | struct command_line *printf_cmd_line |
9380 | = xmalloc (sizeof (struct command_line)); | |
e7e0cddf | 9381 | |
f28045c2 YQ |
9382 | printf_cmd_line = xmalloc (sizeof (struct command_line)); |
9383 | printf_cmd_line->control_type = simple_control; | |
9384 | printf_cmd_line->body_count = 0; | |
9385 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9386 | printf_cmd_line->next = NULL; |
f28045c2 | 9387 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9388 | |
f28045c2 YQ |
9389 | breakpoint_set_commands (b, printf_cmd_line); |
9390 | } | |
e7e0cddf SS |
9391 | } |
9392 | ||
9393 | /* Update all dprintf commands, making their command lists reflect | |
9394 | current style settings. */ | |
9395 | ||
9396 | static void | |
9397 | update_dprintf_commands (char *args, int from_tty, | |
9398 | struct cmd_list_element *c) | |
9399 | { | |
9400 | struct breakpoint *b; | |
9401 | ||
9402 | ALL_BREAKPOINTS (b) | |
9403 | { | |
9404 | if (b->type == bp_dprintf) | |
9405 | update_dprintf_command_list (b); | |
9406 | } | |
9407 | } | |
c3f6f71d | 9408 | |
018d34a4 VP |
9409 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
9410 | as textual description of the location, and COND_STRING | |
db107f19 | 9411 | as condition expression. */ |
018d34a4 VP |
9412 | |
9413 | static void | |
d9b3f62e PA |
9414 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
9415 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9416 | char *filter, char *cond_string, |
e7e0cddf | 9417 | char *extra_string, |
d9b3f62e PA |
9418 | enum bptype type, enum bpdisp disposition, |
9419 | int thread, int task, int ignore_count, | |
c0a91b2b | 9420 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9421 | int enabled, int internal, unsigned flags, |
9422 | int display_canonical) | |
018d34a4 | 9423 | { |
0d381245 | 9424 | int i; |
018d34a4 VP |
9425 | |
9426 | if (type == bp_hardware_breakpoint) | |
9427 | { | |
fbbd034e AS |
9428 | int target_resources_ok; |
9429 | ||
9430 | i = hw_breakpoint_used_count (); | |
9431 | target_resources_ok = | |
9432 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9433 | i + 1, 0); |
9434 | if (target_resources_ok == 0) | |
9435 | error (_("No hardware breakpoint support in the target.")); | |
9436 | else if (target_resources_ok < 0) | |
9437 | error (_("Hardware breakpoints used exceeds limit.")); | |
9438 | } | |
9439 | ||
6c95b8df PA |
9440 | gdb_assert (sals.nelts > 0); |
9441 | ||
0d381245 VP |
9442 | for (i = 0; i < sals.nelts; ++i) |
9443 | { | |
9444 | struct symtab_and_line sal = sals.sals[i]; | |
9445 | struct bp_location *loc; | |
9446 | ||
9447 | if (from_tty) | |
5af949e3 UW |
9448 | { |
9449 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9450 | if (!loc_gdbarch) | |
9451 | loc_gdbarch = gdbarch; | |
9452 | ||
9453 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9454 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9455 | } |
0d381245 VP |
9456 | |
9457 | if (i == 0) | |
9458 | { | |
d9b3f62e | 9459 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9460 | b->thread = thread; |
4a306c9a | 9461 | b->task = task; |
855a6e68 | 9462 | |
0d381245 | 9463 | b->cond_string = cond_string; |
e7e0cddf | 9464 | b->extra_string = extra_string; |
0d381245 | 9465 | b->ignore_count = ignore_count; |
41447f92 | 9466 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9467 | b->disposition = disposition; |
6c95b8df | 9468 | |
44f238bb PA |
9469 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9470 | b->loc->inserted = 1; | |
9471 | ||
0fb4aa4b PA |
9472 | if (type == bp_static_tracepoint) |
9473 | { | |
d9b3f62e | 9474 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9475 | struct static_tracepoint_marker marker; |
9476 | ||
983af33b | 9477 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9478 | { |
9479 | /* We already know the marker exists, otherwise, we | |
9480 | wouldn't see a sal for it. */ | |
9481 | char *p = &addr_string[3]; | |
9482 | char *endp; | |
9483 | char *marker_str; | |
0fb4aa4b | 9484 | |
e9cafbcc | 9485 | p = skip_spaces (p); |
0fb4aa4b | 9486 | |
e9cafbcc | 9487 | endp = skip_to_space (p); |
0fb4aa4b PA |
9488 | |
9489 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9490 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9491 | |
3e43a32a MS |
9492 | printf_filtered (_("Probed static tracepoint " |
9493 | "marker \"%s\"\n"), | |
d9b3f62e | 9494 | t->static_trace_marker_id); |
0fb4aa4b PA |
9495 | } |
9496 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9497 | { | |
d9b3f62e | 9498 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9499 | release_static_tracepoint_marker (&marker); |
9500 | ||
3e43a32a MS |
9501 | printf_filtered (_("Probed static tracepoint " |
9502 | "marker \"%s\"\n"), | |
d9b3f62e | 9503 | t->static_trace_marker_id); |
0fb4aa4b PA |
9504 | } |
9505 | else | |
3e43a32a MS |
9506 | warning (_("Couldn't determine the static " |
9507 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9508 | } |
9509 | ||
0d381245 VP |
9510 | loc = b->loc; |
9511 | } | |
9512 | else | |
018d34a4 | 9513 | { |
39d61571 | 9514 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9515 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9516 | loc->inserted = 1; | |
0d381245 VP |
9517 | } |
9518 | ||
9519 | if (b->cond_string) | |
9520 | { | |
bbc13ae3 KS |
9521 | const char *arg = b->cond_string; |
9522 | ||
1bb9788d TT |
9523 | loc->cond = parse_exp_1 (&arg, loc->address, |
9524 | block_for_pc (loc->address), 0); | |
0d381245 | 9525 | if (*arg) |
588ae58c | 9526 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9527 | } |
e7e0cddf SS |
9528 | |
9529 | /* Dynamic printf requires and uses additional arguments on the | |
9530 | command line, otherwise it's an error. */ | |
9531 | if (type == bp_dprintf) | |
9532 | { | |
9533 | if (b->extra_string) | |
9534 | update_dprintf_command_list (b); | |
9535 | else | |
9536 | error (_("Format string required")); | |
9537 | } | |
9538 | else if (b->extra_string) | |
588ae58c | 9539 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9540 | } |
018d34a4 | 9541 | |
56435ebe | 9542 | b->display_canonical = display_canonical; |
018d34a4 VP |
9543 | if (addr_string) |
9544 | b->addr_string = addr_string; | |
9545 | else | |
9546 | /* addr_string has to be used or breakpoint_re_set will delete | |
9547 | me. */ | |
5af949e3 UW |
9548 | b->addr_string |
9549 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
f8eba3c6 | 9550 | b->filter = filter; |
d9b3f62e | 9551 | } |
018d34a4 | 9552 | |
d9b3f62e PA |
9553 | static void |
9554 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
9555 | struct symtabs_and_lines sals, char *addr_string, | |
f8eba3c6 | 9556 | char *filter, char *cond_string, |
e7e0cddf | 9557 | char *extra_string, |
d9b3f62e PA |
9558 | enum bptype type, enum bpdisp disposition, |
9559 | int thread, int task, int ignore_count, | |
c0a91b2b | 9560 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9561 | int enabled, int internal, unsigned flags, |
9562 | int display_canonical) | |
d9b3f62e PA |
9563 | { |
9564 | struct breakpoint *b; | |
9565 | struct cleanup *old_chain; | |
9566 | ||
9567 | if (is_tracepoint_type (type)) | |
9568 | { | |
9569 | struct tracepoint *t; | |
9570 | ||
9571 | t = XCNEW (struct tracepoint); | |
9572 | b = &t->base; | |
9573 | } | |
9574 | else | |
9575 | b = XNEW (struct breakpoint); | |
9576 | ||
9577 | old_chain = make_cleanup (xfree, b); | |
9578 | ||
9579 | init_breakpoint_sal (b, gdbarch, | |
9580 | sals, addr_string, | |
e7e0cddf | 9581 | filter, cond_string, extra_string, |
d9b3f62e PA |
9582 | type, disposition, |
9583 | thread, task, ignore_count, | |
9584 | ops, from_tty, | |
44f238bb PA |
9585 | enabled, internal, flags, |
9586 | display_canonical); | |
d9b3f62e PA |
9587 | discard_cleanups (old_chain); |
9588 | ||
3ea46bff | 9589 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9590 | } |
9591 | ||
9592 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9593 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9594 | value. COND_STRING, if not NULL, specified the condition to be | |
9595 | used for all breakpoints. Essentially the only case where | |
9596 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9597 | function. In that case, it's still not possible to specify | |
9598 | separate conditions for different overloaded functions, so | |
9599 | we take just a single condition string. | |
9600 | ||
c3f6f71d | 9601 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9602 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9603 | array contents). If the function fails (error() is called), the |
9604 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9605 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9606 | |
9607 | static void | |
8cdf0e15 | 9608 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9609 | struct linespec_result *canonical, |
e7e0cddf | 9610 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9611 | enum bptype type, enum bpdisp disposition, |
9612 | int thread, int task, int ignore_count, | |
c0a91b2b | 9613 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9614 | int enabled, int internal, unsigned flags) |
c906108c | 9615 | { |
018d34a4 | 9616 | int i; |
f8eba3c6 | 9617 | struct linespec_sals *lsal; |
cc59ec59 | 9618 | |
f8eba3c6 TT |
9619 | if (canonical->pre_expanded) |
9620 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9621 | ||
9622 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9623 | { |
f8eba3c6 TT |
9624 | /* Note that 'addr_string' can be NULL in the case of a plain |
9625 | 'break', without arguments. */ | |
9626 | char *addr_string = (canonical->addr_string | |
9627 | ? xstrdup (canonical->addr_string) | |
9628 | : NULL); | |
9629 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; | |
9630 | struct cleanup *inner = make_cleanup (xfree, addr_string); | |
0d381245 | 9631 | |
f8eba3c6 TT |
9632 | make_cleanup (xfree, filter_string); |
9633 | create_breakpoint_sal (gdbarch, lsal->sals, | |
9634 | addr_string, | |
9635 | filter_string, | |
e7e0cddf SS |
9636 | cond_string, extra_string, |
9637 | type, disposition, | |
84f4c1fe | 9638 | thread, task, ignore_count, ops, |
44f238bb | 9639 | from_tty, enabled, internal, flags, |
56435ebe | 9640 | canonical->special_display); |
f8eba3c6 | 9641 | discard_cleanups (inner); |
c3f6f71d | 9642 | } |
c3f6f71d | 9643 | } |
c906108c | 9644 | |
9998af43 | 9645 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 9646 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 9647 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
9648 | address strings. ADDRESS points to the end of the SAL. |
9649 | ||
9650 | The array and the line spec strings are allocated on the heap, it is | |
9651 | the caller's responsibility to free them. */ | |
c906108c | 9652 | |
b9362cc7 | 9653 | static void |
c3f6f71d | 9654 | parse_breakpoint_sals (char **address, |
58438ac1 | 9655 | struct linespec_result *canonical) |
c3f6f71d | 9656 | { |
c3f6f71d | 9657 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 9658 | breakpoint. */ |
c3f6f71d JM |
9659 | if ((*address) == NULL |
9660 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 9661 | { |
1bfeeb0f JL |
9662 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
9663 | address. */ | |
9664 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9665 | { |
f8eba3c6 | 9666 | struct linespec_sals lsal; |
c3f6f71d | 9667 | struct symtab_and_line sal; |
1c8cdcb1 | 9668 | CORE_ADDR pc; |
cc59ec59 | 9669 | |
4a64f543 | 9670 | init_sal (&sal); /* Initialize to zeroes. */ |
f8eba3c6 | 9671 | lsal.sals.sals = (struct symtab_and_line *) |
c906108c | 9672 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
9673 | |
9674 | /* Set sal's pspace, pc, symtab, and line to the values | |
1c8cdcb1 JK |
9675 | corresponding to the last call to print_frame_info. |
9676 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9677 | as the breakpoint line number is inappropriate otherwise. | |
9678 | find_pc_line would adjust PC, re-set it back. */ | |
1bfeeb0f | 9679 | get_last_displayed_sal (&sal); |
1c8cdcb1 JK |
9680 | pc = sal.pc; |
9681 | sal = find_pc_line (pc, 0); | |
00903456 | 9682 | |
4a64f543 | 9683 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
9684 | where PC is the last displayed codepoint's address. So |
9685 | make sure to set sal.explicit_pc to prevent GDB from | |
9686 | trying to expand the list of sals to include all other | |
9687 | instances with the same symtab and line. */ | |
1c8cdcb1 | 9688 | sal.pc = pc; |
00903456 JK |
9689 | sal.explicit_pc = 1; |
9690 | ||
f8eba3c6 TT |
9691 | lsal.sals.sals[0] = sal; |
9692 | lsal.sals.nelts = 1; | |
9693 | lsal.canonical = NULL; | |
9694 | ||
9695 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
c906108c SS |
9696 | } |
9697 | else | |
8a3fe4f8 | 9698 | error (_("No default breakpoint address now.")); |
c906108c SS |
9699 | } |
9700 | else | |
9701 | { | |
cc80f267 JK |
9702 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
9703 | ||
c906108c | 9704 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
9705 | current_source_symtab (which is decode_line_1's default). |
9706 | This should produce the results we want almost all of the | |
cc80f267 JK |
9707 | time while leaving default_breakpoint_* alone. |
9708 | ||
9709 | ObjC: However, don't match an Objective-C method name which | |
9710 | may have a '+' or '-' succeeded by a '['. */ | |
9711 | if (last_displayed_sal_is_valid () | |
9712 | && (!cursal.symtab | |
9713 | || ((strchr ("+-", (*address)[0]) != NULL) | |
9714 | && ((*address)[1] != '[')))) | |
f8eba3c6 TT |
9715 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
9716 | get_last_displayed_symtab (), | |
9717 | get_last_displayed_line (), | |
9718 | canonical, NULL, NULL); | |
c906108c | 9719 | else |
f8eba3c6 | 9720 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
cc80f267 | 9721 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c906108c | 9722 | } |
c3f6f71d | 9723 | } |
c906108c | 9724 | |
c906108c | 9725 | |
c3f6f71d | 9726 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9727 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9728 | |
b9362cc7 | 9729 | static void |
23e7acfb | 9730 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9731 | { |
9732 | int i; | |
cc59ec59 | 9733 | |
c3f6f71d | 9734 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9735 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9736 | } |
9737 | ||
7a697b8d SS |
9738 | /* Fast tracepoints may have restrictions on valid locations. For |
9739 | instance, a fast tracepoint using a jump instead of a trap will | |
9740 | likely have to overwrite more bytes than a trap would, and so can | |
9741 | only be placed where the instruction is longer than the jump, or a | |
9742 | multi-instruction sequence does not have a jump into the middle of | |
9743 | it, etc. */ | |
9744 | ||
9745 | static void | |
9746 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9747 | struct symtabs_and_lines *sals) | |
9748 | { | |
9749 | int i, rslt; | |
9750 | struct symtab_and_line *sal; | |
9751 | char *msg; | |
9752 | struct cleanup *old_chain; | |
9753 | ||
9754 | for (i = 0; i < sals->nelts; i++) | |
9755 | { | |
f8eba3c6 TT |
9756 | struct gdbarch *sarch; |
9757 | ||
7a697b8d SS |
9758 | sal = &sals->sals[i]; |
9759 | ||
f8eba3c6 TT |
9760 | sarch = get_sal_arch (*sal); |
9761 | /* We fall back to GDBARCH if there is no architecture | |
9762 | associated with SAL. */ | |
9763 | if (sarch == NULL) | |
9764 | sarch = gdbarch; | |
9765 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, | |
7a697b8d SS |
9766 | NULL, &msg); |
9767 | old_chain = make_cleanup (xfree, msg); | |
9768 | ||
9769 | if (!rslt) | |
9770 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9771 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9772 | |
9773 | do_cleanups (old_chain); | |
9774 | } | |
9775 | } | |
9776 | ||
af4908ba KS |
9777 | /* Issue an invalid thread ID error. */ |
9778 | ||
9779 | static void ATTRIBUTE_NORETURN | |
9780 | invalid_thread_id_error (int id) | |
9781 | { | |
9782 | error (_("Unknown thread %d."), id); | |
9783 | } | |
9784 | ||
018d34a4 VP |
9785 | /* Given TOK, a string specification of condition and thread, as |
9786 | accepted by the 'break' command, extract the condition | |
9787 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9788 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9789 | If no condition is found, *COND_STRING is set to NULL. |
9790 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9791 | |
9792 | static void | |
bbc13ae3 | 9793 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9794 | char **cond_string, int *thread, int *task, |
9795 | char **rest) | |
018d34a4 VP |
9796 | { |
9797 | *cond_string = NULL; | |
9798 | *thread = -1; | |
ed1d1739 KS |
9799 | *task = 0; |
9800 | *rest = NULL; | |
9801 | ||
018d34a4 VP |
9802 | while (tok && *tok) |
9803 | { | |
bbc13ae3 | 9804 | const char *end_tok; |
018d34a4 | 9805 | int toklen; |
bbc13ae3 KS |
9806 | const char *cond_start = NULL; |
9807 | const char *cond_end = NULL; | |
cc59ec59 | 9808 | |
bbc13ae3 | 9809 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9810 | |
9811 | if ((*tok == '"' || *tok == ',') && rest) | |
9812 | { | |
9813 | *rest = savestring (tok, strlen (tok)); | |
9814 | return; | |
9815 | } | |
9816 | ||
bbc13ae3 | 9817 | end_tok = skip_to_space_const (tok); |
d634f2de | 9818 | |
018d34a4 | 9819 | toklen = end_tok - tok; |
d634f2de | 9820 | |
018d34a4 VP |
9821 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9822 | { | |
f7545552 TT |
9823 | struct expression *expr; |
9824 | ||
018d34a4 | 9825 | tok = cond_start = end_tok + 1; |
1bb9788d | 9826 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9827 | xfree (expr); |
018d34a4 | 9828 | cond_end = tok; |
d634f2de | 9829 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9830 | } |
9831 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9832 | { | |
9833 | char *tmptok; | |
d634f2de | 9834 | |
018d34a4 | 9835 | tok = end_tok + 1; |
bbc13ae3 | 9836 | *thread = strtol (tok, &tmptok, 0); |
018d34a4 VP |
9837 | if (tok == tmptok) |
9838 | error (_("Junk after thread keyword.")); | |
9839 | if (!valid_thread_id (*thread)) | |
af4908ba | 9840 | invalid_thread_id_error (*thread); |
bbc13ae3 | 9841 | tok = tmptok; |
018d34a4 | 9842 | } |
4a306c9a JB |
9843 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9844 | { | |
9845 | char *tmptok; | |
9846 | ||
9847 | tok = end_tok + 1; | |
bbc13ae3 | 9848 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9849 | if (tok == tmptok) |
9850 | error (_("Junk after task keyword.")); | |
9851 | if (!valid_task_id (*task)) | |
b6199126 | 9852 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9853 | tok = tmptok; |
4a306c9a | 9854 | } |
e7e0cddf SS |
9855 | else if (rest) |
9856 | { | |
9857 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9858 | return; |
e7e0cddf | 9859 | } |
018d34a4 VP |
9860 | else |
9861 | error (_("Junk at end of arguments.")); | |
9862 | } | |
9863 | } | |
9864 | ||
0fb4aa4b PA |
9865 | /* Decode a static tracepoint marker spec. */ |
9866 | ||
9867 | static struct symtabs_and_lines | |
9868 | decode_static_tracepoint_spec (char **arg_p) | |
9869 | { | |
9870 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9871 | struct symtabs_and_lines sals; | |
0fb4aa4b PA |
9872 | struct cleanup *old_chain; |
9873 | char *p = &(*arg_p)[3]; | |
9874 | char *endp; | |
9875 | char *marker_str; | |
9876 | int i; | |
9877 | ||
e9cafbcc | 9878 | p = skip_spaces (p); |
0fb4aa4b | 9879 | |
e9cafbcc | 9880 | endp = skip_to_space (p); |
0fb4aa4b PA |
9881 | |
9882 | marker_str = savestring (p, endp - p); | |
9883 | old_chain = make_cleanup (xfree, marker_str); | |
9884 | ||
9885 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9886 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9887 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9888 | ||
9889 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
9890 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
9891 | ||
9892 | for (i = 0; i < sals.nelts; i++) | |
9893 | { | |
9894 | struct static_tracepoint_marker *marker; | |
9895 | ||
9896 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9897 | ||
9898 | init_sal (&sals.sals[i]); | |
9899 | ||
9900 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9901 | sals.sals[i].pc = marker->address; | |
9902 | ||
9903 | release_static_tracepoint_marker (marker); | |
9904 | } | |
9905 | ||
9906 | do_cleanups (old_chain); | |
9907 | ||
9908 | *arg_p = endp; | |
9909 | return sals; | |
9910 | } | |
9911 | ||
fd9b8c24 PA |
9912 | /* Set a breakpoint. This function is shared between CLI and MI |
9913 | functions for setting a breakpoint. This function has two major | |
f6de8ec2 PA |
9914 | modes of operations, selected by the PARSE_ARG parameter. If |
9915 | non-zero, the function will parse ARG, extracting location, | |
9916 | condition, thread and extra string. Otherwise, ARG is just the | |
9917 | breakpoint's location, with condition, thread, and extra string | |
9918 | specified by the COND_STRING, THREAD and EXTRA_STRING parameters. | |
9919 | If INTERNAL is non-zero, the breakpoint number will be allocated | |
9920 | from the internal breakpoint count. Returns true if any breakpoint | |
9921 | was created; false otherwise. */ | |
0101ce28 | 9922 | |
8cdf0e15 VP |
9923 | int |
9924 | create_breakpoint (struct gdbarch *gdbarch, | |
e7e0cddf SS |
9925 | char *arg, char *cond_string, |
9926 | int thread, char *extra_string, | |
f6de8ec2 | 9927 | int parse_arg, |
0fb4aa4b | 9928 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9929 | int ignore_count, |
9930 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9931 | const struct breakpoint_ops *ops, |
44f238bb PA |
9932 | int from_tty, int enabled, int internal, |
9933 | unsigned flags) | |
c3f6f71d | 9934 | { |
b78a6381 | 9935 | volatile struct gdb_exception e; |
f8eba3c6 | 9936 | char *copy_arg = NULL; |
c3f6f71d | 9937 | char *addr_start = arg; |
7efd8fc2 | 9938 | struct linespec_result canonical; |
c3f6f71d | 9939 | struct cleanup *old_chain; |
80c99de1 | 9940 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9941 | int pending = 0; |
4a306c9a | 9942 | int task = 0; |
86b17b60 | 9943 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9944 | |
348d480f PA |
9945 | gdb_assert (ops != NULL); |
9946 | ||
7efd8fc2 | 9947 | init_linespec_result (&canonical); |
c3f6f71d | 9948 | |
b78a6381 TT |
9949 | TRY_CATCH (e, RETURN_MASK_ALL) |
9950 | { | |
983af33b SDJ |
9951 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
9952 | addr_start, ©_arg); | |
b78a6381 | 9953 | } |
0101ce28 JJ |
9954 | |
9955 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 9956 | switch (e.reason) |
0101ce28 | 9957 | { |
983af33b SDJ |
9958 | case GDB_NO_ERROR: |
9959 | if (VEC_empty (linespec_sals, canonical.sals)) | |
9960 | return 0; | |
9961 | break; | |
05ff989b AC |
9962 | case RETURN_ERROR: |
9963 | switch (e.error) | |
0101ce28 | 9964 | { |
05ff989b | 9965 | case NOT_FOUND_ERROR: |
0101ce28 | 9966 | |
05ff989b AC |
9967 | /* If pending breakpoint support is turned off, throw |
9968 | error. */ | |
fa8d40ab JJ |
9969 | |
9970 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9971 | throw_exception (e); |
9972 | ||
9973 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9974 | |
05ff989b AC |
9975 | /* If pending breakpoint support is auto query and the user |
9976 | selects no, then simply return the error code. */ | |
059fb39f | 9977 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9978 | && !nquery (_("Make %s pending on future shared library load? "), |
9979 | bptype_string (type_wanted))) | |
fd9b8c24 | 9980 | return 0; |
fa8d40ab | 9981 | |
05ff989b AC |
9982 | /* At this point, either the user was queried about setting |
9983 | a pending breakpoint and selected yes, or pending | |
9984 | breakpoint behavior is on and thus a pending breakpoint | |
9985 | is defaulted on behalf of the user. */ | |
f8eba3c6 TT |
9986 | { |
9987 | struct linespec_sals lsal; | |
9988 | ||
9989 | copy_arg = xstrdup (addr_start); | |
9990 | lsal.canonical = xstrdup (copy_arg); | |
9991 | lsal.sals.nelts = 1; | |
9992 | lsal.sals.sals = XNEW (struct symtab_and_line); | |
9993 | init_sal (&lsal.sals.sals[0]); | |
9994 | pending = 1; | |
9995 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); | |
9996 | } | |
05ff989b AC |
9997 | break; |
9998 | default: | |
98deb0da | 9999 | throw_exception (e); |
0101ce28 | 10000 | } |
2abae994 | 10001 | break; |
05ff989b | 10002 | default: |
983af33b | 10003 | throw_exception (e); |
0101ce28 | 10004 | } |
c3f6f71d | 10005 | |
4a64f543 | 10006 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 10007 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 10008 | |
c3f6f71d JM |
10009 | /* ----------------------------- SNIP ----------------------------- |
10010 | Anything added to the cleanup chain beyond this point is assumed | |
10011 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
10012 | then the memory is not reclaimed. */ |
10013 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 10014 | |
c3f6f71d JM |
10015 | /* Resolve all line numbers to PC's and verify that the addresses |
10016 | are ok for the target. */ | |
0101ce28 | 10017 | if (!pending) |
f8eba3c6 TT |
10018 | { |
10019 | int ix; | |
10020 | struct linespec_sals *iter; | |
10021 | ||
10022 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
10023 | breakpoint_sals_to_pc (&iter->sals); | |
10024 | } | |
c3f6f71d | 10025 | |
7a697b8d | 10026 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 10027 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
10028 | { |
10029 | int ix; | |
10030 | struct linespec_sals *iter; | |
10031 | ||
10032 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
10033 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
10034 | } | |
7a697b8d | 10035 | |
c3f6f71d JM |
10036 | /* Verify that condition can be parsed, before setting any |
10037 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 10038 | breakpoint. */ |
0101ce28 | 10039 | if (!pending) |
c3f6f71d | 10040 | { |
f6de8ec2 | 10041 | if (parse_arg) |
72b2ff0e | 10042 | { |
0878d0fa | 10043 | char *rest; |
52d361e1 YQ |
10044 | struct linespec_sals *lsal; |
10045 | ||
10046 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
10047 | ||
0878d0fa YQ |
10048 | /* Here we only parse 'arg' to separate condition |
10049 | from thread number, so parsing in context of first | |
10050 | sal is OK. When setting the breakpoint we'll | |
10051 | re-parse it in context of each sal. */ | |
10052 | ||
10053 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, | |
10054 | &thread, &task, &rest); | |
10055 | if (cond_string) | |
10056 | make_cleanup (xfree, cond_string); | |
10057 | if (rest) | |
10058 | make_cleanup (xfree, rest); | |
10059 | if (rest) | |
10060 | extra_string = rest; | |
72b2ff0e | 10061 | } |
2f069f6f | 10062 | else |
72b2ff0e | 10063 | { |
0878d0fa YQ |
10064 | if (*arg != '\0') |
10065 | error (_("Garbage '%s' at end of location"), arg); | |
10066 | ||
10067 | /* Create a private copy of condition string. */ | |
10068 | if (cond_string) | |
10069 | { | |
10070 | cond_string = xstrdup (cond_string); | |
10071 | make_cleanup (xfree, cond_string); | |
10072 | } | |
10073 | /* Create a private copy of any extra string. */ | |
10074 | if (extra_string) | |
10075 | { | |
10076 | extra_string = xstrdup (extra_string); | |
10077 | make_cleanup (xfree, extra_string); | |
10078 | } | |
72b2ff0e | 10079 | } |
0fb4aa4b | 10080 | |
52d361e1 | 10081 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 10082 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
10083 | tempflag ? disp_del : disp_donttouch, |
10084 | thread, task, ignore_count, ops, | |
44f238bb | 10085 | from_tty, enabled, internal, flags); |
c906108c | 10086 | } |
0101ce28 JJ |
10087 | else |
10088 | { | |
0101ce28 JJ |
10089 | struct breakpoint *b; |
10090 | ||
0101ce28 JJ |
10091 | make_cleanup (xfree, copy_arg); |
10092 | ||
bfccc43c YQ |
10093 | if (is_tracepoint_type (type_wanted)) |
10094 | { | |
10095 | struct tracepoint *t; | |
10096 | ||
10097 | t = XCNEW (struct tracepoint); | |
10098 | b = &t->base; | |
10099 | } | |
10100 | else | |
10101 | b = XNEW (struct breakpoint); | |
10102 | ||
10103 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
10104 | ||
f8eba3c6 | 10105 | b->addr_string = copy_arg; |
f6de8ec2 | 10106 | if (parse_arg) |
e12c7713 MK |
10107 | b->cond_string = NULL; |
10108 | else | |
10109 | { | |
10110 | /* Create a private copy of condition string. */ | |
10111 | if (cond_string) | |
10112 | { | |
10113 | cond_string = xstrdup (cond_string); | |
10114 | make_cleanup (xfree, cond_string); | |
10115 | } | |
10116 | b->cond_string = cond_string; | |
10117 | } | |
e7e0cddf | 10118 | b->extra_string = NULL; |
0101ce28 | 10119 | b->ignore_count = ignore_count; |
0101ce28 | 10120 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 10121 | b->condition_not_parsed = 1; |
41447f92 | 10122 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
10123 | if ((type_wanted != bp_breakpoint |
10124 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 10125 | b->pspace = current_program_space; |
8bea4e01 | 10126 | |
bfccc43c | 10127 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
10128 | } |
10129 | ||
f8eba3c6 | 10130 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 10131 | { |
3e43a32a MS |
10132 | warning (_("Multiple breakpoints were set.\nUse the " |
10133 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 10134 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
10135 | } |
10136 | ||
80c99de1 PA |
10137 | /* That's it. Discard the cleanups for data inserted into the |
10138 | breakpoint. */ | |
10139 | discard_cleanups (bkpt_chain); | |
10140 | /* But cleanup everything else. */ | |
c3f6f71d | 10141 | do_cleanups (old_chain); |
217dc9e2 | 10142 | |
80c99de1 | 10143 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 10144 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
10145 | |
10146 | return 1; | |
c3f6f71d | 10147 | } |
c906108c | 10148 | |
348d480f | 10149 | /* Set a breakpoint. |
72b2ff0e VP |
10150 | ARG is a string describing breakpoint address, |
10151 | condition, and thread. | |
10152 | FLAG specifies if a breakpoint is hardware on, | |
10153 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
10154 | and BP_TEMPFLAG. */ | |
348d480f | 10155 | |
98deb0da | 10156 | static void |
72b2ff0e | 10157 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 10158 | { |
72b2ff0e | 10159 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
10160 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
10161 | ? bp_hardware_breakpoint | |
10162 | : bp_breakpoint); | |
55aa24fb SDJ |
10163 | struct breakpoint_ops *ops; |
10164 | const char *arg_cp = arg; | |
10165 | ||
10166 | /* Matching breakpoints on probes. */ | |
10167 | if (arg && probe_linespec_to_ops (&arg_cp) != NULL) | |
10168 | ops = &bkpt_probe_breakpoint_ops; | |
10169 | else | |
10170 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 10171 | |
8cdf0e15 VP |
10172 | create_breakpoint (get_current_arch (), |
10173 | arg, | |
e7e0cddf | 10174 | NULL, 0, NULL, 1 /* parse arg */, |
0fb4aa4b | 10175 | tempflag, type_wanted, |
8cdf0e15 VP |
10176 | 0 /* Ignore count */, |
10177 | pending_break_support, | |
55aa24fb | 10178 | ops, |
8cdf0e15 | 10179 | from_tty, |
84f4c1fe | 10180 | 1 /* enabled */, |
44f238bb PA |
10181 | 0 /* internal */, |
10182 | 0); | |
c906108c SS |
10183 | } |
10184 | ||
c906108c SS |
10185 | /* Helper function for break_command_1 and disassemble_command. */ |
10186 | ||
10187 | void | |
fba45db2 | 10188 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
10189 | { |
10190 | CORE_ADDR pc; | |
10191 | ||
10192 | if (sal->pc == 0 && sal->symtab != NULL) | |
10193 | { | |
10194 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 10195 | error (_("No line %d in file \"%s\"."), |
05cba821 | 10196 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 10197 | sal->pc = pc; |
6a048695 | 10198 | |
4a64f543 MS |
10199 | /* If this SAL corresponds to a breakpoint inserted using a line |
10200 | number, then skip the function prologue if necessary. */ | |
6a048695 | 10201 | if (sal->explicit_line) |
059acae7 | 10202 | skip_prologue_sal (sal); |
c906108c SS |
10203 | } |
10204 | ||
10205 | if (sal->section == 0 && sal->symtab != NULL) | |
10206 | { | |
346d1dfe | 10207 | const struct blockvector *bv; |
3977b71f | 10208 | const struct block *b; |
c5aa993b | 10209 | struct symbol *sym; |
c906108c | 10210 | |
43f3e411 DE |
10211 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
10212 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
10213 | if (bv != NULL) |
10214 | { | |
7f0df278 | 10215 | sym = block_linkage_function (b); |
c906108c SS |
10216 | if (sym != NULL) |
10217 | { | |
eb822aa6 DE |
10218 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
10219 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
10220 | sym); | |
c906108c SS |
10221 | } |
10222 | else | |
10223 | { | |
4a64f543 MS |
10224 | /* It really is worthwhile to have the section, so we'll |
10225 | just have to look harder. This case can be executed | |
10226 | if we have line numbers but no functions (as can | |
10227 | happen in assembly source). */ | |
c906108c | 10228 | |
7cbd4a93 | 10229 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10230 | struct cleanup *old_chain = save_current_space_and_thread (); |
10231 | ||
10232 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10233 | |
10234 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10235 | if (msym.minsym) |
efd66ac6 | 10236 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10237 | |
10238 | do_cleanups (old_chain); | |
c906108c SS |
10239 | } |
10240 | } | |
10241 | } | |
10242 | } | |
10243 | ||
10244 | void | |
fba45db2 | 10245 | break_command (char *arg, int from_tty) |
c906108c | 10246 | { |
db107f19 | 10247 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10248 | } |
10249 | ||
c906108c | 10250 | void |
fba45db2 | 10251 | tbreak_command (char *arg, int from_tty) |
c906108c | 10252 | { |
db107f19 | 10253 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10254 | } |
10255 | ||
c906108c | 10256 | static void |
fba45db2 | 10257 | hbreak_command (char *arg, int from_tty) |
c906108c | 10258 | { |
db107f19 | 10259 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10260 | } |
10261 | ||
10262 | static void | |
fba45db2 | 10263 | thbreak_command (char *arg, int from_tty) |
c906108c | 10264 | { |
db107f19 | 10265 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10266 | } |
10267 | ||
10268 | static void | |
fba45db2 | 10269 | stop_command (char *arg, int from_tty) |
c906108c | 10270 | { |
a3f17187 | 10271 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10272 | Usage: stop in <function | address>\n\ |
a3f17187 | 10273 | stop at <line>\n")); |
c906108c SS |
10274 | } |
10275 | ||
10276 | static void | |
fba45db2 | 10277 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10278 | { |
10279 | int badInput = 0; | |
10280 | ||
c5aa993b | 10281 | if (arg == (char *) NULL) |
c906108c SS |
10282 | badInput = 1; |
10283 | else if (*arg != '*') | |
10284 | { | |
10285 | char *argptr = arg; | |
10286 | int hasColon = 0; | |
10287 | ||
4a64f543 | 10288 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10289 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10290 | function/method name. */ |
c906108c | 10291 | while (*argptr && !hasColon) |
c5aa993b JM |
10292 | { |
10293 | hasColon = (*argptr == ':'); | |
10294 | argptr++; | |
10295 | } | |
c906108c SS |
10296 | |
10297 | if (hasColon) | |
c5aa993b | 10298 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10299 | else |
c5aa993b | 10300 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10301 | } |
10302 | ||
10303 | if (badInput) | |
a3f17187 | 10304 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10305 | else |
db107f19 | 10306 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10307 | } |
10308 | ||
10309 | static void | |
fba45db2 | 10310 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10311 | { |
10312 | int badInput = 0; | |
10313 | ||
c5aa993b | 10314 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10315 | badInput = 1; |
10316 | else | |
10317 | { | |
10318 | char *argptr = arg; | |
10319 | int hasColon = 0; | |
10320 | ||
4a64f543 MS |
10321 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10322 | it is probably a line number. */ | |
c906108c | 10323 | while (*argptr && !hasColon) |
c5aa993b JM |
10324 | { |
10325 | hasColon = (*argptr == ':'); | |
10326 | argptr++; | |
10327 | } | |
c906108c SS |
10328 | |
10329 | if (hasColon) | |
c5aa993b | 10330 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10331 | else |
c5aa993b | 10332 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10333 | } |
10334 | ||
10335 | if (badInput) | |
a3f17187 | 10336 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10337 | else |
db107f19 | 10338 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10339 | } |
10340 | ||
e7e0cddf SS |
10341 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10342 | with a prewired command list consisting of a single output command, | |
10343 | built from extra arguments supplied on the dprintf command | |
10344 | line. */ | |
10345 | ||
da821c7b | 10346 | static void |
e7e0cddf SS |
10347 | dprintf_command (char *arg, int from_tty) |
10348 | { | |
10349 | create_breakpoint (get_current_arch (), | |
10350 | arg, | |
10351 | NULL, 0, NULL, 1 /* parse arg */, | |
10352 | 0, bp_dprintf, | |
10353 | 0 /* Ignore count */, | |
10354 | pending_break_support, | |
10355 | &dprintf_breakpoint_ops, | |
10356 | from_tty, | |
10357 | 1 /* enabled */, | |
10358 | 0 /* internal */, | |
10359 | 0); | |
10360 | } | |
10361 | ||
d3ce09f5 SS |
10362 | static void |
10363 | agent_printf_command (char *arg, int from_tty) | |
10364 | { | |
10365 | error (_("May only run agent-printf on the target")); | |
10366 | } | |
10367 | ||
f1310107 TJB |
10368 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10369 | ranged breakpoints. */ | |
10370 | ||
10371 | static int | |
10372 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10373 | struct address_space *aspace, | |
09ac7c10 TT |
10374 | CORE_ADDR bp_addr, |
10375 | const struct target_waitstatus *ws) | |
f1310107 | 10376 | { |
09ac7c10 | 10377 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10378 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10379 | return 0; |
10380 | ||
f1310107 TJB |
10381 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10382 | bl->length, aspace, bp_addr); | |
10383 | } | |
10384 | ||
10385 | /* Implement the "resources_needed" breakpoint_ops method for | |
10386 | ranged breakpoints. */ | |
10387 | ||
10388 | static int | |
10389 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10390 | { | |
10391 | return target_ranged_break_num_registers (); | |
10392 | } | |
10393 | ||
10394 | /* Implement the "print_it" breakpoint_ops method for | |
10395 | ranged breakpoints. */ | |
10396 | ||
10397 | static enum print_stop_action | |
348d480f | 10398 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10399 | { |
348d480f | 10400 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10401 | struct bp_location *bl = b->loc; |
79a45e25 | 10402 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10403 | |
10404 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10405 | ||
10406 | /* Ranged breakpoints have only one location. */ | |
10407 | gdb_assert (bl && bl->next == NULL); | |
10408 | ||
10409 | annotate_breakpoint (b->number); | |
10410 | if (b->disposition == disp_del) | |
10411 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
10412 | else | |
10413 | ui_out_text (uiout, "\nRanged breakpoint "); | |
10414 | if (ui_out_is_mi_like_p (uiout)) | |
10415 | { | |
10416 | ui_out_field_string (uiout, "reason", | |
10417 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10418 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10419 | } | |
10420 | ui_out_field_int (uiout, "bkptno", b->number); | |
10421 | ui_out_text (uiout, ", "); | |
10422 | ||
10423 | return PRINT_SRC_AND_LOC; | |
10424 | } | |
10425 | ||
10426 | /* Implement the "print_one" breakpoint_ops method for | |
10427 | ranged breakpoints. */ | |
10428 | ||
10429 | static void | |
10430 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10431 | struct bp_location **last_loc) | |
10432 | { | |
10433 | struct bp_location *bl = b->loc; | |
10434 | struct value_print_options opts; | |
79a45e25 | 10435 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10436 | |
10437 | /* Ranged breakpoints have only one location. */ | |
10438 | gdb_assert (bl && bl->next == NULL); | |
10439 | ||
10440 | get_user_print_options (&opts); | |
10441 | ||
10442 | if (opts.addressprint) | |
10443 | /* We don't print the address range here, it will be printed later | |
10444 | by print_one_detail_ranged_breakpoint. */ | |
10445 | ui_out_field_skip (uiout, "addr"); | |
10446 | annotate_field (5); | |
10447 | print_breakpoint_location (b, bl); | |
10448 | *last_loc = bl; | |
10449 | } | |
10450 | ||
10451 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10452 | ranged breakpoints. */ | |
10453 | ||
10454 | static void | |
10455 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10456 | struct ui_out *uiout) | |
10457 | { | |
10458 | CORE_ADDR address_start, address_end; | |
10459 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10460 | struct ui_file *stb = mem_fileopen (); |
10461 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10462 | |
10463 | gdb_assert (bl); | |
10464 | ||
10465 | address_start = bl->address; | |
10466 | address_end = address_start + bl->length - 1; | |
10467 | ||
10468 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10469 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10470 | print_core_address (bl->gdbarch, address_start), |
10471 | print_core_address (bl->gdbarch, address_end)); | |
10472 | ui_out_field_stream (uiout, "addr", stb); | |
10473 | ui_out_text (uiout, "\n"); | |
10474 | ||
10475 | do_cleanups (cleanup); | |
10476 | } | |
10477 | ||
10478 | /* Implement the "print_mention" breakpoint_ops method for | |
10479 | ranged breakpoints. */ | |
10480 | ||
10481 | static void | |
10482 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10483 | { | |
10484 | struct bp_location *bl = b->loc; | |
79a45e25 | 10485 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10486 | |
10487 | gdb_assert (bl); | |
10488 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10489 | ||
10490 | if (ui_out_is_mi_like_p (uiout)) | |
10491 | return; | |
10492 | ||
10493 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10494 | b->number, paddress (bl->gdbarch, bl->address), | |
10495 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10496 | } | |
10497 | ||
10498 | /* Implement the "print_recreate" breakpoint_ops method for | |
10499 | ranged breakpoints. */ | |
10500 | ||
10501 | static void | |
10502 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10503 | { | |
10504 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
10505 | b->addr_string_range_end); | |
d9b3f62e | 10506 | print_recreate_thread (b, fp); |
f1310107 TJB |
10507 | } |
10508 | ||
10509 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10510 | ||
2060206e | 10511 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10512 | |
10513 | /* Find the address where the end of the breakpoint range should be | |
10514 | placed, given the SAL of the end of the range. This is so that if | |
10515 | the user provides a line number, the end of the range is set to the | |
10516 | last instruction of the given line. */ | |
10517 | ||
10518 | static CORE_ADDR | |
10519 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10520 | { | |
10521 | CORE_ADDR end; | |
10522 | ||
10523 | /* If the user provided a PC value, use it. Otherwise, | |
10524 | find the address of the end of the given location. */ | |
10525 | if (sal.explicit_pc) | |
10526 | end = sal.pc; | |
10527 | else | |
10528 | { | |
10529 | int ret; | |
10530 | CORE_ADDR start; | |
10531 | ||
10532 | ret = find_line_pc_range (sal, &start, &end); | |
10533 | if (!ret) | |
10534 | error (_("Could not find location of the end of the range.")); | |
10535 | ||
10536 | /* find_line_pc_range returns the start of the next line. */ | |
10537 | end--; | |
10538 | } | |
10539 | ||
10540 | return end; | |
10541 | } | |
10542 | ||
10543 | /* Implement the "break-range" CLI command. */ | |
10544 | ||
10545 | static void | |
10546 | break_range_command (char *arg, int from_tty) | |
10547 | { | |
10548 | char *arg_start, *addr_string_start, *addr_string_end; | |
10549 | struct linespec_result canonical_start, canonical_end; | |
10550 | int bp_count, can_use_bp, length; | |
10551 | CORE_ADDR end; | |
10552 | struct breakpoint *b; | |
10553 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10554 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10555 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10556 | |
10557 | /* We don't support software ranged breakpoints. */ | |
10558 | if (target_ranged_break_num_registers () < 0) | |
10559 | error (_("This target does not support hardware ranged breakpoints.")); | |
10560 | ||
10561 | bp_count = hw_breakpoint_used_count (); | |
10562 | bp_count += target_ranged_break_num_registers (); | |
10563 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10564 | bp_count, 0); | |
10565 | if (can_use_bp < 0) | |
10566 | error (_("Hardware breakpoints used exceeds limit.")); | |
10567 | ||
f8eba3c6 | 10568 | arg = skip_spaces (arg); |
f1310107 TJB |
10569 | if (arg == NULL || arg[0] == '\0') |
10570 | error(_("No address range specified.")); | |
10571 | ||
f1310107 TJB |
10572 | init_linespec_result (&canonical_start); |
10573 | ||
f8eba3c6 TT |
10574 | arg_start = arg; |
10575 | parse_breakpoint_sals (&arg, &canonical_start); | |
f1310107 | 10576 | |
f8eba3c6 | 10577 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
f1310107 TJB |
10578 | |
10579 | if (arg[0] != ',') | |
10580 | error (_("Too few arguments.")); | |
f8eba3c6 | 10581 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10582 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10583 | |
10584 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10585 | ||
10586 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10587 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10588 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10589 | ||
f8eba3c6 TT |
10590 | sal_start = lsal_start->sals.sals[0]; |
10591 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10592 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10593 | |
10594 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10595 | arg = skip_spaces (arg); |
f1310107 TJB |
10596 | |
10597 | /* Parse the end location. */ | |
10598 | ||
f1310107 TJB |
10599 | init_linespec_result (&canonical_end); |
10600 | arg_start = arg; | |
10601 | ||
f8eba3c6 | 10602 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10603 | parse_breakpoint_sals because we need to specify the start location's |
10604 | symtab and line as the default symtab and line for the end of the | |
10605 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10606 | where +14 means 14 lines from the start location. */ | |
f8eba3c6 TT |
10607 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
10608 | sal_start.symtab, sal_start.line, | |
10609 | &canonical_end, NULL, NULL); | |
10610 | ||
10611 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10612 | |
f8eba3c6 | 10613 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10614 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10615 | |
10616 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10617 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10618 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10619 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10620 | ||
f8eba3c6 TT |
10621 | sal_end = lsal_end->sals.sals[0]; |
10622 | addr_string_end = savestring (arg_start, arg - arg_start); | |
10623 | make_cleanup (xfree, addr_string_end); | |
f1310107 TJB |
10624 | |
10625 | end = find_breakpoint_range_end (sal_end); | |
10626 | if (sal_start.pc > end) | |
177b42fe | 10627 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10628 | |
10629 | length = end - sal_start.pc + 1; | |
10630 | if (length < 0) | |
10631 | /* Length overflowed. */ | |
10632 | error (_("Address range too large.")); | |
10633 | else if (length == 1) | |
10634 | { | |
10635 | /* This range is simple enough to be handled by | |
10636 | the `hbreak' command. */ | |
10637 | hbreak_command (addr_string_start, 1); | |
10638 | ||
10639 | do_cleanups (cleanup_bkpt); | |
10640 | ||
10641 | return; | |
10642 | } | |
10643 | ||
10644 | /* Now set up the breakpoint. */ | |
10645 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10646 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10647 | set_breakpoint_count (breakpoint_count + 1); |
10648 | b->number = breakpoint_count; | |
10649 | b->disposition = disp_donttouch; | |
f8eba3c6 TT |
10650 | b->addr_string = xstrdup (addr_string_start); |
10651 | b->addr_string_range_end = xstrdup (addr_string_end); | |
f1310107 TJB |
10652 | b->loc->length = length; |
10653 | ||
f8eba3c6 | 10654 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10655 | |
10656 | mention (b); | |
8d3788bd | 10657 | observer_notify_breakpoint_created (b); |
44702360 | 10658 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10659 | } |
10660 | ||
4a64f543 MS |
10661 | /* Return non-zero if EXP is verified as constant. Returned zero |
10662 | means EXP is variable. Also the constant detection may fail for | |
10663 | some constant expressions and in such case still falsely return | |
10664 | zero. */ | |
2e6e3d9c | 10665 | |
65d79d4b SDJ |
10666 | static int |
10667 | watchpoint_exp_is_const (const struct expression *exp) | |
10668 | { | |
10669 | int i = exp->nelts; | |
10670 | ||
10671 | while (i > 0) | |
10672 | { | |
10673 | int oplenp, argsp; | |
10674 | ||
10675 | /* We are only interested in the descriptor of each element. */ | |
10676 | operator_length (exp, i, &oplenp, &argsp); | |
10677 | i -= oplenp; | |
10678 | ||
10679 | switch (exp->elts[i].opcode) | |
10680 | { | |
10681 | case BINOP_ADD: | |
10682 | case BINOP_SUB: | |
10683 | case BINOP_MUL: | |
10684 | case BINOP_DIV: | |
10685 | case BINOP_REM: | |
10686 | case BINOP_MOD: | |
10687 | case BINOP_LSH: | |
10688 | case BINOP_RSH: | |
10689 | case BINOP_LOGICAL_AND: | |
10690 | case BINOP_LOGICAL_OR: | |
10691 | case BINOP_BITWISE_AND: | |
10692 | case BINOP_BITWISE_IOR: | |
10693 | case BINOP_BITWISE_XOR: | |
10694 | case BINOP_EQUAL: | |
10695 | case BINOP_NOTEQUAL: | |
10696 | case BINOP_LESS: | |
10697 | case BINOP_GTR: | |
10698 | case BINOP_LEQ: | |
10699 | case BINOP_GEQ: | |
10700 | case BINOP_REPEAT: | |
10701 | case BINOP_COMMA: | |
10702 | case BINOP_EXP: | |
10703 | case BINOP_MIN: | |
10704 | case BINOP_MAX: | |
10705 | case BINOP_INTDIV: | |
10706 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10707 | case TERNOP_COND: |
10708 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10709 | |
10710 | case OP_LONG: | |
10711 | case OP_DOUBLE: | |
10712 | case OP_DECFLOAT: | |
10713 | case OP_LAST: | |
10714 | case OP_COMPLEX: | |
10715 | case OP_STRING: | |
65d79d4b SDJ |
10716 | case OP_ARRAY: |
10717 | case OP_TYPE: | |
608b4967 TT |
10718 | case OP_TYPEOF: |
10719 | case OP_DECLTYPE: | |
6e72ca20 | 10720 | case OP_TYPEID: |
65d79d4b SDJ |
10721 | case OP_NAME: |
10722 | case OP_OBJC_NSSTRING: | |
10723 | ||
10724 | case UNOP_NEG: | |
10725 | case UNOP_LOGICAL_NOT: | |
10726 | case UNOP_COMPLEMENT: | |
10727 | case UNOP_ADDR: | |
10728 | case UNOP_HIGH: | |
aeaa2474 | 10729 | case UNOP_CAST: |
9eaf6705 TT |
10730 | |
10731 | case UNOP_CAST_TYPE: | |
10732 | case UNOP_REINTERPRET_CAST: | |
10733 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10734 | /* Unary, binary and ternary operators: We have to check |
10735 | their operands. If they are constant, then so is the | |
10736 | result of that operation. For instance, if A and B are | |
10737 | determined to be constants, then so is "A + B". | |
10738 | ||
10739 | UNOP_IND is one exception to the rule above, because the | |
10740 | value of *ADDR is not necessarily a constant, even when | |
10741 | ADDR is. */ | |
65d79d4b SDJ |
10742 | break; |
10743 | ||
10744 | case OP_VAR_VALUE: | |
10745 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10746 | |
65d79d4b | 10747 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10748 | possible that a buggy compiler could mark a variable as |
10749 | constant even when it is not, and TYPE_CONST would return | |
10750 | true in this case, while SYMBOL_CLASS wouldn't. | |
10751 | ||
10752 | We also have to check for function symbols because they | |
10753 | are always constant. */ | |
65d79d4b SDJ |
10754 | { |
10755 | struct symbol *s = exp->elts[i + 2].symbol; | |
10756 | ||
10757 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10758 | && SYMBOL_CLASS (s) != LOC_CONST | |
10759 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10760 | return 0; | |
10761 | break; | |
10762 | } | |
10763 | ||
10764 | /* The default action is to return 0 because we are using | |
10765 | the optimistic approach here: If we don't know something, | |
10766 | then it is not a constant. */ | |
10767 | default: | |
10768 | return 0; | |
10769 | } | |
10770 | } | |
10771 | ||
10772 | return 1; | |
10773 | } | |
10774 | ||
3a5c3e22 PA |
10775 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10776 | ||
10777 | static void | |
10778 | dtor_watchpoint (struct breakpoint *self) | |
10779 | { | |
10780 | struct watchpoint *w = (struct watchpoint *) self; | |
10781 | ||
10782 | xfree (w->cond_exp); | |
10783 | xfree (w->exp); | |
10784 | xfree (w->exp_string); | |
10785 | xfree (w->exp_string_reparse); | |
10786 | value_free (w->val); | |
10787 | ||
10788 | base_breakpoint_ops.dtor (self); | |
10789 | } | |
10790 | ||
348d480f PA |
10791 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10792 | ||
10793 | static void | |
10794 | re_set_watchpoint (struct breakpoint *b) | |
10795 | { | |
3a5c3e22 PA |
10796 | struct watchpoint *w = (struct watchpoint *) b; |
10797 | ||
348d480f PA |
10798 | /* Watchpoint can be either on expression using entirely global |
10799 | variables, or it can be on local variables. | |
10800 | ||
10801 | Watchpoints of the first kind are never auto-deleted, and even | |
10802 | persist across program restarts. Since they can use variables | |
10803 | from shared libraries, we need to reparse expression as libraries | |
10804 | are loaded and unloaded. | |
10805 | ||
10806 | Watchpoints on local variables can also change meaning as result | |
10807 | of solib event. For example, if a watchpoint uses both a local | |
10808 | and a global variables in expression, it's a local watchpoint, | |
10809 | but unloading of a shared library will make the expression | |
10810 | invalid. This is not a very common use case, but we still | |
10811 | re-evaluate expression, to avoid surprises to the user. | |
10812 | ||
10813 | Note that for local watchpoints, we re-evaluate it only if | |
10814 | watchpoints frame id is still valid. If it's not, it means the | |
10815 | watchpoint is out of scope and will be deleted soon. In fact, | |
10816 | I'm not sure we'll ever be called in this case. | |
10817 | ||
10818 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10819 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10820 | |
3a5c3e22 PA |
10821 | Don't do anything about disabled watchpoints, since they will be |
10822 | reevaluated again when enabled. */ | |
10823 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10824 | } |
10825 | ||
77b06cd7 TJB |
10826 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10827 | ||
10828 | static int | |
10829 | insert_watchpoint (struct bp_location *bl) | |
10830 | { | |
3a5c3e22 PA |
10831 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10832 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10833 | |
10834 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10835 | w->cond_exp); |
77b06cd7 TJB |
10836 | } |
10837 | ||
10838 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10839 | ||
10840 | static int | |
10841 | remove_watchpoint (struct bp_location *bl) | |
10842 | { | |
3a5c3e22 PA |
10843 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10844 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10845 | |
10846 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10847 | w->cond_exp); |
e09342b5 TJB |
10848 | } |
10849 | ||
e09342b5 | 10850 | static int |
348d480f | 10851 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10852 | struct address_space *aspace, CORE_ADDR bp_addr, |
10853 | const struct target_waitstatus *ws) | |
e09342b5 | 10854 | { |
348d480f | 10855 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10856 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10857 | |
348d480f PA |
10858 | /* Continuable hardware watchpoints are treated as non-existent if the |
10859 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10860 | some data address). Otherwise gdb won't stop on a break instruction | |
10861 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10862 | been defined. Also skip watchpoints which we know did not trigger | |
10863 | (did not match the data address). */ | |
10864 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10865 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10866 | return 0; |
9c06b0b4 | 10867 | |
348d480f | 10868 | return 1; |
9c06b0b4 TJB |
10869 | } |
10870 | ||
348d480f PA |
10871 | static void |
10872 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10873 | { |
348d480f | 10874 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10875 | |
348d480f | 10876 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10877 | } |
10878 | ||
10879 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10880 | hardware watchpoints. */ |
9c06b0b4 TJB |
10881 | |
10882 | static int | |
348d480f | 10883 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10884 | { |
3a5c3e22 PA |
10885 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10886 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10887 | |
10888 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10889 | } |
10890 | ||
10891 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10892 | hardware watchpoints. */ |
9c06b0b4 TJB |
10893 | |
10894 | static int | |
348d480f | 10895 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10896 | { |
efa80663 PA |
10897 | /* Read and access watchpoints only work with hardware support. */ |
10898 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10899 | } |
10900 | ||
9c06b0b4 | 10901 | static enum print_stop_action |
348d480f | 10902 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10903 | { |
348d480f PA |
10904 | struct cleanup *old_chain; |
10905 | struct breakpoint *b; | |
f99d8bf4 | 10906 | struct ui_file *stb; |
348d480f | 10907 | enum print_stop_action result; |
3a5c3e22 | 10908 | struct watchpoint *w; |
79a45e25 | 10909 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10910 | |
10911 | gdb_assert (bs->bp_location_at != NULL); | |
10912 | ||
348d480f | 10913 | b = bs->breakpoint_at; |
3a5c3e22 | 10914 | w = (struct watchpoint *) b; |
348d480f | 10915 | |
f99d8bf4 PA |
10916 | stb = mem_fileopen (); |
10917 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 TJB |
10918 | |
10919 | switch (b->type) | |
10920 | { | |
348d480f | 10921 | case bp_watchpoint: |
9c06b0b4 TJB |
10922 | case bp_hardware_watchpoint: |
10923 | annotate_watchpoint (b->number); | |
10924 | if (ui_out_is_mi_like_p (uiout)) | |
10925 | ui_out_field_string | |
10926 | (uiout, "reason", | |
10927 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10928 | mention (b); |
10929 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10930 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10931 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10932 | ui_out_field_stream (uiout, "old", stb); |
10933 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10934 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10935 | ui_out_field_stream (uiout, "new", stb); |
10936 | ui_out_text (uiout, "\n"); | |
10937 | /* More than one watchpoint may have been triggered. */ | |
10938 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10939 | break; |
10940 | ||
10941 | case bp_read_watchpoint: | |
10942 | if (ui_out_is_mi_like_p (uiout)) | |
10943 | ui_out_field_string | |
10944 | (uiout, "reason", | |
10945 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10946 | mention (b); |
10947 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10948 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10949 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10950 | ui_out_field_stream (uiout, "value", stb); |
10951 | ui_out_text (uiout, "\n"); | |
10952 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10953 | break; |
10954 | ||
10955 | case bp_access_watchpoint: | |
348d480f PA |
10956 | if (bs->old_val != NULL) |
10957 | { | |
10958 | annotate_watchpoint (b->number); | |
10959 | if (ui_out_is_mi_like_p (uiout)) | |
10960 | ui_out_field_string | |
10961 | (uiout, "reason", | |
10962 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10963 | mention (b); | |
10964 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10965 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10966 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10967 | ui_out_field_stream (uiout, "old", stb); |
10968 | ui_out_text (uiout, "\nNew value = "); | |
10969 | } | |
10970 | else | |
10971 | { | |
10972 | mention (b); | |
10973 | if (ui_out_is_mi_like_p (uiout)) | |
10974 | ui_out_field_string | |
10975 | (uiout, "reason", | |
10976 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10977 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10978 | ui_out_text (uiout, "\nValue = "); | |
10979 | } | |
f99d8bf4 | 10980 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10981 | ui_out_field_stream (uiout, "new", stb); |
10982 | ui_out_text (uiout, "\n"); | |
10983 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10984 | break; |
10985 | default: | |
348d480f | 10986 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10987 | } |
10988 | ||
348d480f PA |
10989 | do_cleanups (old_chain); |
10990 | return result; | |
10991 | } | |
10992 | ||
10993 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10994 | watchpoints. */ | |
10995 | ||
10996 | static void | |
10997 | print_mention_watchpoint (struct breakpoint *b) | |
10998 | { | |
10999 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 11000 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11001 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11002 | |
11003 | switch (b->type) | |
11004 | { | |
11005 | case bp_watchpoint: | |
11006 | ui_out_text (uiout, "Watchpoint "); | |
11007 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11008 | break; | |
11009 | case bp_hardware_watchpoint: | |
11010 | ui_out_text (uiout, "Hardware watchpoint "); | |
11011 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11012 | break; | |
11013 | case bp_read_watchpoint: | |
11014 | ui_out_text (uiout, "Hardware read watchpoint "); | |
11015 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11016 | break; | |
11017 | case bp_access_watchpoint: | |
11018 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
11019 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11020 | break; | |
11021 | default: | |
11022 | internal_error (__FILE__, __LINE__, | |
11023 | _("Invalid hardware watchpoint type.")); | |
11024 | } | |
11025 | ||
11026 | ui_out_field_int (uiout, "number", b->number); | |
11027 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11028 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
11029 | do_cleanups (ui_out_chain); |
11030 | } | |
11031 | ||
11032 | /* Implement the "print_recreate" breakpoint_ops method for | |
11033 | watchpoints. */ | |
11034 | ||
11035 | static void | |
11036 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11037 | { | |
3a5c3e22 PA |
11038 | struct watchpoint *w = (struct watchpoint *) b; |
11039 | ||
348d480f PA |
11040 | switch (b->type) |
11041 | { | |
11042 | case bp_watchpoint: | |
11043 | case bp_hardware_watchpoint: | |
11044 | fprintf_unfiltered (fp, "watch"); | |
11045 | break; | |
11046 | case bp_read_watchpoint: | |
11047 | fprintf_unfiltered (fp, "rwatch"); | |
11048 | break; | |
11049 | case bp_access_watchpoint: | |
11050 | fprintf_unfiltered (fp, "awatch"); | |
11051 | break; | |
11052 | default: | |
11053 | internal_error (__FILE__, __LINE__, | |
11054 | _("Invalid watchpoint type.")); | |
11055 | } | |
11056 | ||
3a5c3e22 | 11057 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 11058 | print_recreate_thread (b, fp); |
348d480f PA |
11059 | } |
11060 | ||
427cd150 TT |
11061 | /* Implement the "explains_signal" breakpoint_ops method for |
11062 | watchpoints. */ | |
11063 | ||
47591c29 | 11064 | static int |
427cd150 TT |
11065 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
11066 | { | |
11067 | /* A software watchpoint cannot cause a signal other than | |
11068 | GDB_SIGNAL_TRAP. */ | |
11069 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 11070 | return 0; |
427cd150 | 11071 | |
47591c29 | 11072 | return 1; |
427cd150 TT |
11073 | } |
11074 | ||
348d480f PA |
11075 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
11076 | ||
2060206e | 11077 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
11078 | |
11079 | /* Implement the "insert" breakpoint_ops method for | |
11080 | masked hardware watchpoints. */ | |
11081 | ||
11082 | static int | |
11083 | insert_masked_watchpoint (struct bp_location *bl) | |
11084 | { | |
3a5c3e22 PA |
11085 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
11086 | ||
11087 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
11088 | bl->watchpoint_type); |
11089 | } | |
11090 | ||
11091 | /* Implement the "remove" breakpoint_ops method for | |
11092 | masked hardware watchpoints. */ | |
11093 | ||
11094 | static int | |
11095 | remove_masked_watchpoint (struct bp_location *bl) | |
11096 | { | |
3a5c3e22 PA |
11097 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
11098 | ||
11099 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
11100 | bl->watchpoint_type); |
11101 | } | |
11102 | ||
11103 | /* Implement the "resources_needed" breakpoint_ops method for | |
11104 | masked hardware watchpoints. */ | |
11105 | ||
11106 | static int | |
11107 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
11108 | { | |
3a5c3e22 PA |
11109 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
11110 | ||
11111 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
11112 | } |
11113 | ||
11114 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
11115 | masked hardware watchpoints. */ | |
11116 | ||
11117 | static int | |
11118 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
11119 | { | |
11120 | return 0; | |
11121 | } | |
11122 | ||
11123 | /* Implement the "print_it" breakpoint_ops method for | |
11124 | masked hardware watchpoints. */ | |
11125 | ||
11126 | static enum print_stop_action | |
11127 | print_it_masked_watchpoint (bpstat bs) | |
11128 | { | |
11129 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 11130 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11131 | |
11132 | /* Masked watchpoints have only one location. */ | |
11133 | gdb_assert (b->loc && b->loc->next == NULL); | |
11134 | ||
11135 | switch (b->type) | |
11136 | { | |
11137 | case bp_hardware_watchpoint: | |
11138 | annotate_watchpoint (b->number); | |
11139 | if (ui_out_is_mi_like_p (uiout)) | |
11140 | ui_out_field_string | |
11141 | (uiout, "reason", | |
11142 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
11143 | break; | |
11144 | ||
11145 | case bp_read_watchpoint: | |
11146 | if (ui_out_is_mi_like_p (uiout)) | |
11147 | ui_out_field_string | |
11148 | (uiout, "reason", | |
11149 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
11150 | break; | |
11151 | ||
11152 | case bp_access_watchpoint: | |
11153 | if (ui_out_is_mi_like_p (uiout)) | |
11154 | ui_out_field_string | |
11155 | (uiout, "reason", | |
11156 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11157 | break; | |
11158 | default: | |
11159 | internal_error (__FILE__, __LINE__, | |
11160 | _("Invalid hardware watchpoint type.")); | |
11161 | } | |
11162 | ||
11163 | mention (b); | |
9c06b0b4 TJB |
11164 | ui_out_text (uiout, _("\n\ |
11165 | Check the underlying instruction at PC for the memory\n\ | |
11166 | address and value which triggered this watchpoint.\n")); | |
11167 | ui_out_text (uiout, "\n"); | |
11168 | ||
11169 | /* More than one watchpoint may have been triggered. */ | |
11170 | return PRINT_UNKNOWN; | |
11171 | } | |
11172 | ||
11173 | /* Implement the "print_one_detail" breakpoint_ops method for | |
11174 | masked hardware watchpoints. */ | |
11175 | ||
11176 | static void | |
11177 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
11178 | struct ui_out *uiout) | |
11179 | { | |
3a5c3e22 PA |
11180 | struct watchpoint *w = (struct watchpoint *) b; |
11181 | ||
9c06b0b4 TJB |
11182 | /* Masked watchpoints have only one location. */ |
11183 | gdb_assert (b->loc && b->loc->next == NULL); | |
11184 | ||
11185 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 11186 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
11187 | ui_out_text (uiout, "\n"); |
11188 | } | |
11189 | ||
11190 | /* Implement the "print_mention" breakpoint_ops method for | |
11191 | masked hardware watchpoints. */ | |
11192 | ||
11193 | static void | |
11194 | print_mention_masked_watchpoint (struct breakpoint *b) | |
11195 | { | |
3a5c3e22 | 11196 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11197 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
11198 | struct cleanup *ui_out_chain; |
11199 | ||
11200 | switch (b->type) | |
11201 | { | |
11202 | case bp_hardware_watchpoint: | |
11203 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
11204 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11205 | break; | |
11206 | case bp_read_watchpoint: | |
11207 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
11208 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11209 | break; | |
11210 | case bp_access_watchpoint: | |
11211 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
11212 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11213 | break; | |
11214 | default: | |
11215 | internal_error (__FILE__, __LINE__, | |
11216 | _("Invalid hardware watchpoint type.")); | |
11217 | } | |
11218 | ||
11219 | ui_out_field_int (uiout, "number", b->number); | |
11220 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11221 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
11222 | do_cleanups (ui_out_chain); |
11223 | } | |
11224 | ||
11225 | /* Implement the "print_recreate" breakpoint_ops method for | |
11226 | masked hardware watchpoints. */ | |
11227 | ||
11228 | static void | |
11229 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11230 | { | |
3a5c3e22 | 11231 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11232 | char tmp[40]; |
11233 | ||
11234 | switch (b->type) | |
11235 | { | |
11236 | case bp_hardware_watchpoint: | |
11237 | fprintf_unfiltered (fp, "watch"); | |
11238 | break; | |
11239 | case bp_read_watchpoint: | |
11240 | fprintf_unfiltered (fp, "rwatch"); | |
11241 | break; | |
11242 | case bp_access_watchpoint: | |
11243 | fprintf_unfiltered (fp, "awatch"); | |
11244 | break; | |
11245 | default: | |
11246 | internal_error (__FILE__, __LINE__, | |
11247 | _("Invalid hardware watchpoint type.")); | |
11248 | } | |
11249 | ||
3a5c3e22 PA |
11250 | sprintf_vma (tmp, w->hw_wp_mask); |
11251 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11252 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11253 | } |
11254 | ||
11255 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11256 | ||
2060206e | 11257 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11258 | |
11259 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11260 | ||
11261 | static int | |
11262 | is_masked_watchpoint (const struct breakpoint *b) | |
11263 | { | |
11264 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11265 | } | |
11266 | ||
53a5351d JM |
11267 | /* accessflag: hw_write: watch write, |
11268 | hw_read: watch read, | |
11269 | hw_access: watch access (read or write) */ | |
c906108c | 11270 | static void |
bbc13ae3 | 11271 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11272 | int just_location, int internal) |
c906108c | 11273 | { |
a9634178 | 11274 | volatile struct gdb_exception e; |
d983da9c | 11275 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11276 | struct expression *exp; |
270140bd | 11277 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11278 | struct value *val, *mark, *result; |
bb9d5f81 | 11279 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 11280 | struct frame_info *frame; |
bbc13ae3 KS |
11281 | const char *exp_start = NULL; |
11282 | const char *exp_end = NULL; | |
11283 | const char *tok, *end_tok; | |
9c06b0b4 | 11284 | int toklen = -1; |
bbc13ae3 KS |
11285 | const char *cond_start = NULL; |
11286 | const char *cond_end = NULL; | |
c906108c | 11287 | enum bptype bp_type; |
37e4754d | 11288 | int thread = -1; |
0cf6dd15 | 11289 | int pc = 0; |
9c06b0b4 TJB |
11290 | /* Flag to indicate whether we are going to use masks for |
11291 | the hardware watchpoint. */ | |
11292 | int use_mask = 0; | |
11293 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11294 | struct watchpoint *w; |
bbc13ae3 KS |
11295 | char *expression; |
11296 | struct cleanup *back_to; | |
c906108c | 11297 | |
37e4754d LM |
11298 | /* Make sure that we actually have parameters to parse. */ |
11299 | if (arg != NULL && arg[0] != '\0') | |
11300 | { | |
bbc13ae3 KS |
11301 | const char *value_start; |
11302 | ||
11303 | exp_end = arg + strlen (arg); | |
37e4754d | 11304 | |
9c06b0b4 TJB |
11305 | /* Look for "parameter value" pairs at the end |
11306 | of the arguments string. */ | |
bbc13ae3 | 11307 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11308 | { |
11309 | /* Skip whitespace at the end of the argument list. */ | |
11310 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11311 | tok--; | |
11312 | ||
11313 | /* Find the beginning of the last token. | |
11314 | This is the value of the parameter. */ | |
11315 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11316 | tok--; | |
11317 | value_start = tok + 1; | |
11318 | ||
11319 | /* Skip whitespace. */ | |
11320 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11321 | tok--; | |
11322 | ||
11323 | end_tok = tok; | |
11324 | ||
11325 | /* Find the beginning of the second to last token. | |
11326 | This is the parameter itself. */ | |
11327 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11328 | tok--; | |
11329 | tok++; | |
11330 | toklen = end_tok - tok + 1; | |
11331 | ||
11332 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
11333 | { | |
11334 | /* At this point we've found a "thread" token, which means | |
11335 | the user is trying to set a watchpoint that triggers | |
11336 | only in a specific thread. */ | |
11337 | char *endp; | |
37e4754d | 11338 | |
9c06b0b4 TJB |
11339 | if (thread != -1) |
11340 | error(_("You can specify only one thread.")); | |
37e4754d | 11341 | |
9c06b0b4 TJB |
11342 | /* Extract the thread ID from the next token. */ |
11343 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 11344 | |
9c06b0b4 TJB |
11345 | /* Check if the user provided a valid numeric value for the |
11346 | thread ID. */ | |
11347 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
11348 | error (_("Invalid thread ID specification %s."), value_start); | |
11349 | ||
11350 | /* Check if the thread actually exists. */ | |
11351 | if (!valid_thread_id (thread)) | |
af4908ba | 11352 | invalid_thread_id_error (thread); |
9c06b0b4 TJB |
11353 | } |
11354 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
11355 | { | |
11356 | /* We've found a "mask" token, which means the user wants to | |
11357 | create a hardware watchpoint that is going to have the mask | |
11358 | facility. */ | |
11359 | struct value *mask_value, *mark; | |
37e4754d | 11360 | |
9c06b0b4 TJB |
11361 | if (use_mask) |
11362 | error(_("You can specify only one mask.")); | |
37e4754d | 11363 | |
9c06b0b4 | 11364 | use_mask = just_location = 1; |
37e4754d | 11365 | |
9c06b0b4 TJB |
11366 | mark = value_mark (); |
11367 | mask_value = parse_to_comma_and_eval (&value_start); | |
11368 | mask = value_as_address (mask_value); | |
11369 | value_free_to_mark (mark); | |
11370 | } | |
11371 | else | |
11372 | /* We didn't recognize what we found. We should stop here. */ | |
11373 | break; | |
37e4754d | 11374 | |
9c06b0b4 TJB |
11375 | /* Truncate the string and get rid of the "parameter value" pair before |
11376 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11377 | exp_end = tok; |
9c06b0b4 | 11378 | } |
37e4754d | 11379 | } |
bbc13ae3 KS |
11380 | else |
11381 | exp_end = arg; | |
37e4754d | 11382 | |
bbc13ae3 KS |
11383 | /* Parse the rest of the arguments. From here on out, everything |
11384 | is in terms of a newly allocated string instead of the original | |
11385 | ARG. */ | |
c906108c | 11386 | innermost_block = NULL; |
bbc13ae3 KS |
11387 | expression = savestring (arg, exp_end - arg); |
11388 | back_to = make_cleanup (xfree, expression); | |
11389 | exp_start = arg = expression; | |
1bb9788d | 11390 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11391 | exp_end = arg; |
fa8a61dc TT |
11392 | /* Remove trailing whitespace from the expression before saving it. |
11393 | This makes the eventual display of the expression string a bit | |
11394 | prettier. */ | |
11395 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11396 | --exp_end; | |
11397 | ||
65d79d4b SDJ |
11398 | /* Checking if the expression is not constant. */ |
11399 | if (watchpoint_exp_is_const (exp)) | |
11400 | { | |
11401 | int len; | |
11402 | ||
11403 | len = exp_end - exp_start; | |
11404 | while (len > 0 && isspace (exp_start[len - 1])) | |
11405 | len--; | |
11406 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11407 | } | |
11408 | ||
c906108c SS |
11409 | exp_valid_block = innermost_block; |
11410 | mark = value_mark (); | |
3a1115a0 | 11411 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b | 11412 | |
bb9d5f81 PP |
11413 | if (val != NULL && just_location) |
11414 | { | |
11415 | saved_bitpos = value_bitpos (val); | |
11416 | saved_bitsize = value_bitsize (val); | |
11417 | } | |
11418 | ||
06a64a0b TT |
11419 | if (just_location) |
11420 | { | |
9c06b0b4 TJB |
11421 | int ret; |
11422 | ||
06a64a0b | 11423 | exp_valid_block = NULL; |
a1442452 | 11424 | val = value_addr (result); |
06a64a0b TT |
11425 | release_value (val); |
11426 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11427 | |
11428 | if (use_mask) | |
11429 | { | |
11430 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11431 | mask); | |
11432 | if (ret == -1) | |
11433 | error (_("This target does not support masked watchpoints.")); | |
11434 | else if (ret == -2) | |
11435 | error (_("Invalid mask or memory region.")); | |
11436 | } | |
06a64a0b TT |
11437 | } |
11438 | else if (val != NULL) | |
fa4727a6 | 11439 | release_value (val); |
c906108c | 11440 | |
bbc13ae3 KS |
11441 | tok = skip_spaces_const (arg); |
11442 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11443 | |
11444 | toklen = end_tok - tok; | |
11445 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11446 | { | |
2d134ed3 PA |
11447 | struct expression *cond; |
11448 | ||
60e1c644 | 11449 | innermost_block = NULL; |
c906108c | 11450 | tok = cond_start = end_tok + 1; |
1bb9788d | 11451 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11452 | |
11453 | /* The watchpoint expression may not be local, but the condition | |
11454 | may still be. E.g.: `watch global if local > 0'. */ | |
11455 | cond_exp_valid_block = innermost_block; | |
11456 | ||
2d134ed3 | 11457 | xfree (cond); |
c906108c SS |
11458 | cond_end = tok; |
11459 | } | |
11460 | if (*tok) | |
8a3fe4f8 | 11461 | error (_("Junk at end of command.")); |
c906108c | 11462 | |
d983da9c | 11463 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11464 | |
11465 | /* If the expression is "local", then set up a "watchpoint scope" | |
11466 | breakpoint at the point where we've left the scope of the watchpoint | |
11467 | expression. Create the scope breakpoint before the watchpoint, so | |
11468 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11469 | if (exp_valid_block && frame) |
d983da9c | 11470 | { |
edb3359d DJ |
11471 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11472 | { | |
11473 | scope_breakpoint | |
a6d9a66e UW |
11474 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11475 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11476 | bp_watchpoint_scope, |
11477 | &momentary_breakpoint_ops); | |
d983da9c | 11478 | |
edb3359d | 11479 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11480 | |
edb3359d DJ |
11481 | /* Automatically delete the breakpoint when it hits. */ |
11482 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11483 | |
edb3359d DJ |
11484 | /* Only break in the proper frame (help with recursion). */ |
11485 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11486 | |
edb3359d | 11487 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11488 | scope_breakpoint->loc->gdbarch |
11489 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11490 | scope_breakpoint->loc->requested_address |
11491 | = frame_unwind_caller_pc (frame); | |
11492 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11493 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11494 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11495 | scope_breakpoint->type); |
11496 | } | |
d983da9c DJ |
11497 | } |
11498 | ||
e8369a73 AB |
11499 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11500 | watchpoints here even if hardware watchpoints are turned off, a call | |
11501 | to update_watchpoint later in this function will cause the type to | |
11502 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11503 | ||
11504 | if (accessflag == hw_read) | |
11505 | bp_type = bp_read_watchpoint; | |
11506 | else if (accessflag == hw_access) | |
11507 | bp_type = bp_access_watchpoint; | |
11508 | else | |
11509 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11510 | |
11511 | w = XCNEW (struct watchpoint); | |
11512 | b = &w->base; | |
348d480f | 11513 | if (use_mask) |
3a5c3e22 PA |
11514 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11515 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11516 | else |
3a5c3e22 PA |
11517 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11518 | &watchpoint_breakpoint_ops); | |
37e4754d | 11519 | b->thread = thread; |
b5de0fa7 | 11520 | b->disposition = disp_donttouch; |
348d480f | 11521 | b->pspace = current_program_space; |
3a5c3e22 PA |
11522 | w->exp = exp; |
11523 | w->exp_valid_block = exp_valid_block; | |
11524 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11525 | if (just_location) |
11526 | { | |
11527 | struct type *t = value_type (val); | |
11528 | CORE_ADDR addr = value_as_address (val); | |
11529 | char *name; | |
11530 | ||
11531 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11532 | name = type_to_string (t); | |
11533 | ||
3a5c3e22 | 11534 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11535 | core_addr_to_string (addr)); |
06a64a0b TT |
11536 | xfree (name); |
11537 | ||
3a5c3e22 | 11538 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11539 | (int) (exp_end - exp_start), exp_start); |
11540 | ||
06a64a0b TT |
11541 | /* The above expression is in C. */ |
11542 | b->language = language_c; | |
11543 | } | |
11544 | else | |
3a5c3e22 | 11545 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11546 | |
11547 | if (use_mask) | |
11548 | { | |
3a5c3e22 | 11549 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11550 | } |
11551 | else | |
11552 | { | |
3a5c3e22 | 11553 | w->val = val; |
bb9d5f81 PP |
11554 | w->val_bitpos = saved_bitpos; |
11555 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11556 | w->val_valid = 1; |
9c06b0b4 | 11557 | } |
77b06cd7 | 11558 | |
c906108c SS |
11559 | if (cond_start) |
11560 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11561 | else | |
11562 | b->cond_string = 0; | |
c5aa993b | 11563 | |
c906108c | 11564 | if (frame) |
f6bc2008 | 11565 | { |
3a5c3e22 PA |
11566 | w->watchpoint_frame = get_frame_id (frame); |
11567 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11568 | } |
c906108c | 11569 | else |
f6bc2008 | 11570 | { |
3a5c3e22 PA |
11571 | w->watchpoint_frame = null_frame_id; |
11572 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11573 | } |
c906108c | 11574 | |
d983da9c | 11575 | if (scope_breakpoint != NULL) |
c906108c | 11576 | { |
d983da9c DJ |
11577 | /* The scope breakpoint is related to the watchpoint. We will |
11578 | need to act on them together. */ | |
11579 | b->related_breakpoint = scope_breakpoint; | |
11580 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11581 | } |
d983da9c | 11582 | |
06a64a0b TT |
11583 | if (!just_location) |
11584 | value_free_to_mark (mark); | |
2d134ed3 | 11585 | |
a9634178 TJB |
11586 | TRY_CATCH (e, RETURN_MASK_ALL) |
11587 | { | |
11588 | /* Finally update the new watchpoint. This creates the locations | |
11589 | that should be inserted. */ | |
3a5c3e22 | 11590 | update_watchpoint (w, 1); |
a9634178 TJB |
11591 | } |
11592 | if (e.reason < 0) | |
11593 | { | |
11594 | delete_breakpoint (b); | |
11595 | throw_exception (e); | |
11596 | } | |
11597 | ||
3ea46bff | 11598 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11599 | do_cleanups (back_to); |
c906108c SS |
11600 | } |
11601 | ||
e09342b5 | 11602 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11603 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11604 | |
c906108c | 11605 | static int |
a9634178 | 11606 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11607 | { |
11608 | int found_memory_cnt = 0; | |
2e70b7b9 | 11609 | struct value *head = v; |
c906108c SS |
11610 | |
11611 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11612 | if (!can_use_hw_watchpoints) |
c906108c | 11613 | return 0; |
c5aa993b | 11614 | |
5c44784c JM |
11615 | /* Make sure that the value of the expression depends only upon |
11616 | memory contents, and values computed from them within GDB. If we | |
11617 | find any register references or function calls, we can't use a | |
11618 | hardware watchpoint. | |
11619 | ||
11620 | The idea here is that evaluating an expression generates a series | |
11621 | of values, one holding the value of every subexpression. (The | |
11622 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11623 | a*b+c.) GDB's values hold almost enough information to establish | |
11624 | the criteria given above --- they identify memory lvalues, | |
11625 | register lvalues, computed values, etcetera. So we can evaluate | |
11626 | the expression, and then scan the chain of values that leaves | |
11627 | behind to decide whether we can detect any possible change to the | |
11628 | expression's final value using only hardware watchpoints. | |
11629 | ||
11630 | However, I don't think that the values returned by inferior | |
11631 | function calls are special in any way. So this function may not | |
11632 | notice that an expression involving an inferior function call | |
11633 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11634 | for (; v; v = value_next (v)) |
c906108c | 11635 | { |
5c44784c | 11636 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11637 | { |
8464be76 DJ |
11638 | if (v != head && value_lazy (v)) |
11639 | /* A lazy memory lvalue in the chain is one that GDB never | |
11640 | needed to fetch; we either just used its address (e.g., | |
11641 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11642 | in `a,b'). This doesn't apply to HEAD; if that is | |
11643 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11644 | ; |
53a5351d | 11645 | else |
5c44784c JM |
11646 | { |
11647 | /* Ahh, memory we actually used! Check if we can cover | |
11648 | it with hardware watchpoints. */ | |
df407dfe | 11649 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11650 | |
11651 | /* We only watch structs and arrays if user asked for it | |
11652 | explicitly, never if they just happen to appear in a | |
11653 | middle of some value chain. */ | |
11654 | if (v == head | |
11655 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11656 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11657 | { | |
42ae5230 | 11658 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11659 | int len; |
11660 | int num_regs; | |
11661 | ||
a9634178 | 11662 | len = (target_exact_watchpoints |
e09342b5 TJB |
11663 | && is_scalar_type_recursive (vtype))? |
11664 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11665 | |
e09342b5 TJB |
11666 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11667 | if (!num_regs) | |
2e70b7b9 MS |
11668 | return 0; |
11669 | else | |
e09342b5 | 11670 | found_memory_cnt += num_regs; |
2e70b7b9 | 11671 | } |
5c44784c | 11672 | } |
c5aa993b | 11673 | } |
5086187c AC |
11674 | else if (VALUE_LVAL (v) != not_lval |
11675 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11676 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11677 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11678 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11679 | } |
11680 | ||
11681 | /* The expression itself looks suitable for using a hardware | |
11682 | watchpoint, but give the target machine a chance to reject it. */ | |
11683 | return found_memory_cnt; | |
11684 | } | |
11685 | ||
8b93c638 | 11686 | void |
84f4c1fe | 11687 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11688 | { |
84f4c1fe | 11689 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11690 | } |
11691 | ||
06a64a0b TT |
11692 | /* A helper function that looks for the "-location" argument and then |
11693 | calls watch_command_1. */ | |
11694 | ||
11695 | static void | |
11696 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11697 | { | |
11698 | int just_location = 0; | |
11699 | ||
11700 | if (arg | |
11701 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11702 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11703 | { | |
e9cafbcc | 11704 | arg = skip_spaces (arg); |
06a64a0b TT |
11705 | just_location = 1; |
11706 | } | |
11707 | ||
84f4c1fe | 11708 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11709 | } |
8926118c | 11710 | |
c5aa993b | 11711 | static void |
fba45db2 | 11712 | watch_command (char *arg, int from_tty) |
c906108c | 11713 | { |
06a64a0b | 11714 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11715 | } |
11716 | ||
8b93c638 | 11717 | void |
84f4c1fe | 11718 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11719 | { |
84f4c1fe | 11720 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11721 | } |
8926118c | 11722 | |
c5aa993b | 11723 | static void |
fba45db2 | 11724 | rwatch_command (char *arg, int from_tty) |
c906108c | 11725 | { |
06a64a0b | 11726 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11727 | } |
11728 | ||
8b93c638 | 11729 | void |
84f4c1fe | 11730 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11731 | { |
84f4c1fe | 11732 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11733 | } |
8926118c | 11734 | |
c5aa993b | 11735 | static void |
fba45db2 | 11736 | awatch_command (char *arg, int from_tty) |
c906108c | 11737 | { |
06a64a0b | 11738 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11739 | } |
c906108c | 11740 | \f |
c5aa993b | 11741 | |
43ff13b4 | 11742 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
11743 | because it uses the mechanisms of breakpoints. */ |
11744 | ||
bfec99b2 PA |
11745 | struct until_break_command_continuation_args |
11746 | { | |
11747 | struct breakpoint *breakpoint; | |
11748 | struct breakpoint *breakpoint2; | |
186c406b | 11749 | int thread_num; |
bfec99b2 PA |
11750 | }; |
11751 | ||
43ff13b4 | 11752 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 11753 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 11754 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 11755 | command. */ |
c2c6d25f | 11756 | static void |
fa4cd53f | 11757 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 11758 | { |
bfec99b2 PA |
11759 | struct until_break_command_continuation_args *a = arg; |
11760 | ||
11761 | delete_breakpoint (a->breakpoint); | |
11762 | if (a->breakpoint2) | |
11763 | delete_breakpoint (a->breakpoint2); | |
186c406b | 11764 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
11765 | } |
11766 | ||
c906108c | 11767 | void |
ae66c1fc | 11768 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11769 | { |
11770 | struct symtabs_and_lines sals; | |
11771 | struct symtab_and_line sal; | |
8556afb4 PA |
11772 | struct frame_info *frame; |
11773 | struct gdbarch *frame_gdbarch; | |
11774 | struct frame_id stack_frame_id; | |
11775 | struct frame_id caller_frame_id; | |
c906108c | 11776 | struct breakpoint *breakpoint; |
f107f563 | 11777 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 11778 | struct cleanup *old_chain; |
186c406b TT |
11779 | int thread; |
11780 | struct thread_info *tp; | |
c906108c | 11781 | |
70509625 | 11782 | clear_proceed_status (0); |
c906108c SS |
11783 | |
11784 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11785 | this function. */ |
c5aa993b | 11786 | |
1bfeeb0f | 11787 | if (last_displayed_sal_is_valid ()) |
f8eba3c6 | 11788 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
1bfeeb0f | 11789 | get_last_displayed_symtab (), |
f8eba3c6 | 11790 | get_last_displayed_line ()); |
c906108c | 11791 | else |
f8eba3c6 TT |
11792 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
11793 | (struct symtab *) NULL, 0); | |
c5aa993b | 11794 | |
c906108c | 11795 | if (sals.nelts != 1) |
8a3fe4f8 | 11796 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11797 | |
c906108c | 11798 | sal = sals.sals[0]; |
4a64f543 | 11799 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11800 | |
c906108c | 11801 | if (*arg) |
8a3fe4f8 | 11802 | error (_("Junk at end of arguments.")); |
c5aa993b | 11803 | |
c906108c | 11804 | resolve_sal_pc (&sal); |
c5aa993b | 11805 | |
186c406b TT |
11806 | tp = inferior_thread (); |
11807 | thread = tp->num; | |
11808 | ||
883bc8d1 PA |
11809 | old_chain = make_cleanup (null_cleanup, NULL); |
11810 | ||
8556afb4 PA |
11811 | /* Note linespec handling above invalidates the frame chain. |
11812 | Installing a breakpoint also invalidates the frame chain (as it | |
11813 | may need to switch threads), so do any frame handling before | |
11814 | that. */ | |
11815 | ||
11816 | frame = get_selected_frame (NULL); | |
11817 | frame_gdbarch = get_frame_arch (frame); | |
11818 | stack_frame_id = get_stack_frame_id (frame); | |
11819 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11820 | |
ae66c1fc EZ |
11821 | /* Keep within the current frame, or in frames called by the current |
11822 | one. */ | |
edb3359d | 11823 | |
883bc8d1 | 11824 | if (frame_id_p (caller_frame_id)) |
c906108c | 11825 | { |
883bc8d1 PA |
11826 | struct symtab_and_line sal2; |
11827 | ||
11828 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11829 | sal2.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e | 11830 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
883bc8d1 PA |
11831 | sal2, |
11832 | caller_frame_id, | |
f107f563 VP |
11833 | bp_until); |
11834 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b | 11835 | |
883bc8d1 | 11836 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11837 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11838 | } |
c5aa993b | 11839 | |
c70a6932 JK |
11840 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11841 | frame = NULL; | |
11842 | ||
883bc8d1 PA |
11843 | if (anywhere) |
11844 | /* If the user told us to continue until a specified location, | |
11845 | we don't specify a frame at which we need to stop. */ | |
11846 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11847 | null_frame_id, bp_until); | |
11848 | else | |
11849 | /* Otherwise, specify the selected frame, because we want to stop | |
11850 | only at the very same frame. */ | |
11851 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, | |
11852 | stack_frame_id, bp_until); | |
11853 | make_cleanup_delete_breakpoint (breakpoint); | |
11854 | ||
a493e3e2 | 11855 | proceed (-1, GDB_SIGNAL_DEFAULT, 0); |
f107f563 | 11856 | |
4a64f543 MS |
11857 | /* If we are running asynchronously, and proceed call above has |
11858 | actually managed to start the target, arrange for breakpoints to | |
11859 | be deleted when the target stops. Otherwise, we're already | |
11860 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 11861 | |
8ea051c5 | 11862 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 11863 | { |
bfec99b2 PA |
11864 | struct until_break_command_continuation_args *args; |
11865 | args = xmalloc (sizeof (*args)); | |
f107f563 | 11866 | |
bfec99b2 PA |
11867 | args->breakpoint = breakpoint; |
11868 | args->breakpoint2 = breakpoint2; | |
186c406b | 11869 | args->thread_num = thread; |
f107f563 VP |
11870 | |
11871 | discard_cleanups (old_chain); | |
95e54da7 PA |
11872 | add_continuation (inferior_thread (), |
11873 | until_break_command_continuation, args, | |
604ead4a | 11874 | xfree); |
f107f563 VP |
11875 | } |
11876 | else | |
c5aa993b | 11877 | do_cleanups (old_chain); |
c906108c | 11878 | } |
ae66c1fc | 11879 | |
c906108c SS |
11880 | /* This function attempts to parse an optional "if <cond>" clause |
11881 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11882 | |
c906108c SS |
11883 | Else, it returns a pointer to the condition string. (It does not |
11884 | attempt to evaluate the string against a particular block.) And, | |
11885 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11886 | if clause in the arg string. */ |
53a5351d | 11887 | |
916703c0 | 11888 | char * |
fba45db2 | 11889 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11890 | { |
c5aa993b JM |
11891 | char *cond_string; |
11892 | ||
11893 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11894 | return NULL; |
c5aa993b | 11895 | |
4a64f543 | 11896 | /* Skip the "if" keyword. */ |
c906108c | 11897 | (*arg) += 2; |
c5aa993b | 11898 | |
c906108c | 11899 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11900 | condition string. */ |
e9cafbcc | 11901 | *arg = skip_spaces (*arg); |
c906108c | 11902 | cond_string = *arg; |
c5aa993b | 11903 | |
4a64f543 MS |
11904 | /* Assume that the condition occupies the remainder of the arg |
11905 | string. */ | |
c906108c | 11906 | (*arg) += strlen (cond_string); |
c5aa993b | 11907 | |
c906108c SS |
11908 | return cond_string; |
11909 | } | |
c5aa993b | 11910 | |
c906108c SS |
11911 | /* Commands to deal with catching events, such as signals, exceptions, |
11912 | process start/exit, etc. */ | |
c5aa993b JM |
11913 | |
11914 | typedef enum | |
11915 | { | |
44feb3ce TT |
11916 | catch_fork_temporary, catch_vfork_temporary, |
11917 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11918 | } |
11919 | catch_fork_kind; | |
11920 | ||
c906108c | 11921 | static void |
cc59ec59 MS |
11922 | catch_fork_command_1 (char *arg, int from_tty, |
11923 | struct cmd_list_element *command) | |
c906108c | 11924 | { |
a6d9a66e | 11925 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11926 | char *cond_string = NULL; |
44feb3ce TT |
11927 | catch_fork_kind fork_kind; |
11928 | int tempflag; | |
11929 | ||
11930 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11931 | tempflag = (fork_kind == catch_fork_temporary | |
11932 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11933 | |
44feb3ce TT |
11934 | if (!arg) |
11935 | arg = ""; | |
e9cafbcc | 11936 | arg = skip_spaces (arg); |
c5aa993b | 11937 | |
c906108c | 11938 | /* The allowed syntax is: |
c5aa993b JM |
11939 | catch [v]fork |
11940 | catch [v]fork if <cond> | |
11941 | ||
4a64f543 | 11942 | First, check if there's an if clause. */ |
c906108c | 11943 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11944 | |
c906108c | 11945 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11946 | error (_("Junk at end of arguments.")); |
c5aa993b | 11947 | |
c906108c | 11948 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11949 | and enable reporting of such events. */ |
c5aa993b JM |
11950 | switch (fork_kind) |
11951 | { | |
44feb3ce TT |
11952 | case catch_fork_temporary: |
11953 | case catch_fork_permanent: | |
a6d9a66e | 11954 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11955 | &catch_fork_breakpoint_ops); |
c906108c | 11956 | break; |
44feb3ce TT |
11957 | case catch_vfork_temporary: |
11958 | case catch_vfork_permanent: | |
a6d9a66e | 11959 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11960 | &catch_vfork_breakpoint_ops); |
c906108c | 11961 | break; |
c5aa993b | 11962 | default: |
8a3fe4f8 | 11963 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11964 | break; |
c5aa993b | 11965 | } |
c906108c SS |
11966 | } |
11967 | ||
11968 | static void | |
cc59ec59 MS |
11969 | catch_exec_command_1 (char *arg, int from_tty, |
11970 | struct cmd_list_element *command) | |
c906108c | 11971 | { |
b4d90040 | 11972 | struct exec_catchpoint *c; |
a6d9a66e | 11973 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11974 | int tempflag; |
c5aa993b | 11975 | char *cond_string = NULL; |
c906108c | 11976 | |
44feb3ce TT |
11977 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11978 | ||
11979 | if (!arg) | |
11980 | arg = ""; | |
e9cafbcc | 11981 | arg = skip_spaces (arg); |
c906108c SS |
11982 | |
11983 | /* The allowed syntax is: | |
c5aa993b JM |
11984 | catch exec |
11985 | catch exec if <cond> | |
c906108c | 11986 | |
4a64f543 | 11987 | First, check if there's an if clause. */ |
c906108c SS |
11988 | cond_string = ep_parse_optional_if_clause (&arg); |
11989 | ||
11990 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11991 | error (_("Junk at end of arguments.")); |
c906108c | 11992 | |
b4d90040 PA |
11993 | c = XNEW (struct exec_catchpoint); |
11994 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11995 | &catch_exec_breakpoint_ops); | |
11996 | c->exec_pathname = NULL; | |
11997 | ||
3ea46bff | 11998 | install_breakpoint (0, &c->base, 1); |
c906108c | 11999 | } |
c5aa993b | 12000 | |
9ac4176b | 12001 | void |
28010a5d PA |
12002 | init_ada_exception_breakpoint (struct breakpoint *b, |
12003 | struct gdbarch *gdbarch, | |
12004 | struct symtab_and_line sal, | |
12005 | char *addr_string, | |
c0a91b2b | 12006 | const struct breakpoint_ops *ops, |
28010a5d | 12007 | int tempflag, |
349774ef | 12008 | int enabled, |
28010a5d | 12009 | int from_tty) |
f7f9143b | 12010 | { |
f7f9143b JB |
12011 | if (from_tty) |
12012 | { | |
5af949e3 UW |
12013 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
12014 | if (!loc_gdbarch) | |
12015 | loc_gdbarch = gdbarch; | |
12016 | ||
6c95b8df PA |
12017 | describe_other_breakpoints (loc_gdbarch, |
12018 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
12019 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
12020 | version for exception catchpoints, because two catchpoints | |
12021 | used for different exception names will use the same address. | |
12022 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 12023 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 12024 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
12025 | the user what type of catchpoint it is. The above is good |
12026 | enough for now, though. */ | |
12027 | } | |
12028 | ||
28010a5d | 12029 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 12030 | |
349774ef | 12031 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 12032 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f7f9143b JB |
12033 | b->addr_string = addr_string; |
12034 | b->language = language_ada; | |
f7f9143b JB |
12035 | } |
12036 | ||
a96d9b2e SDJ |
12037 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
12038 | filter list, or NULL if no filtering is required. */ | |
12039 | static VEC(int) * | |
12040 | catch_syscall_split_args (char *arg) | |
12041 | { | |
12042 | VEC(int) *result = NULL; | |
29d0bb3d | 12043 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
458c8db8 | 12044 | struct gdbarch *gdbarch = target_gdbarch (); |
a96d9b2e SDJ |
12045 | |
12046 | while (*arg != '\0') | |
12047 | { | |
12048 | int i, syscall_number; | |
12049 | char *endptr; | |
12050 | char cur_name[128]; | |
12051 | struct syscall s; | |
12052 | ||
12053 | /* Skip whitespace. */ | |
529480d0 | 12054 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
12055 | |
12056 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
12057 | cur_name[i] = arg[i]; | |
12058 | cur_name[i] = '\0'; | |
12059 | arg += i; | |
12060 | ||
12061 | /* Check if the user provided a syscall name or a number. */ | |
12062 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
12063 | if (*endptr == '\0') | |
458c8db8 | 12064 | get_syscall_by_number (gdbarch, syscall_number, &s); |
a96d9b2e SDJ |
12065 | else |
12066 | { | |
12067 | /* We have a name. Let's check if it's valid and convert it | |
12068 | to a number. */ | |
458c8db8 | 12069 | get_syscall_by_name (gdbarch, cur_name, &s); |
a96d9b2e SDJ |
12070 | |
12071 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
12072 | /* Here we have to issue an error instead of a warning, |
12073 | because GDB cannot do anything useful if there's no | |
12074 | syscall number to be caught. */ | |
a96d9b2e SDJ |
12075 | error (_("Unknown syscall name '%s'."), cur_name); |
12076 | } | |
12077 | ||
12078 | /* Ok, it's valid. */ | |
12079 | VEC_safe_push (int, result, s.number); | |
12080 | } | |
12081 | ||
12082 | discard_cleanups (cleanup); | |
12083 | return result; | |
12084 | } | |
12085 | ||
12086 | /* Implement the "catch syscall" command. */ | |
12087 | ||
12088 | static void | |
cc59ec59 MS |
12089 | catch_syscall_command_1 (char *arg, int from_tty, |
12090 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
12091 | { |
12092 | int tempflag; | |
12093 | VEC(int) *filter; | |
12094 | struct syscall s; | |
12095 | struct gdbarch *gdbarch = get_current_arch (); | |
12096 | ||
12097 | /* Checking if the feature if supported. */ | |
12098 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
12099 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 12100 | this architecture yet.")); |
a96d9b2e SDJ |
12101 | |
12102 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
12103 | ||
e9cafbcc | 12104 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
12105 | |
12106 | /* We need to do this first "dummy" translation in order | |
12107 | to get the syscall XML file loaded or, most important, | |
12108 | to display a warning to the user if there's no XML file | |
12109 | for his/her architecture. */ | |
458c8db8 | 12110 | get_syscall_by_number (gdbarch, 0, &s); |
a96d9b2e SDJ |
12111 | |
12112 | /* The allowed syntax is: | |
12113 | catch syscall | |
12114 | catch syscall <name | number> [<name | number> ... <name | number>] | |
12115 | ||
12116 | Let's check if there's a syscall name. */ | |
12117 | ||
12118 | if (arg != NULL) | |
12119 | filter = catch_syscall_split_args (arg); | |
12120 | else | |
12121 | filter = NULL; | |
12122 | ||
12123 | create_syscall_event_catchpoint (tempflag, filter, | |
12124 | &catch_syscall_breakpoint_ops); | |
12125 | } | |
12126 | ||
c906108c | 12127 | static void |
fba45db2 | 12128 | catch_command (char *arg, int from_tty) |
c906108c | 12129 | { |
44feb3ce | 12130 | error (_("Catch requires an event name.")); |
c906108c SS |
12131 | } |
12132 | \f | |
12133 | ||
12134 | static void | |
fba45db2 | 12135 | tcatch_command (char *arg, int from_tty) |
c906108c | 12136 | { |
44feb3ce | 12137 | error (_("Catch requires an event name.")); |
c906108c SS |
12138 | } |
12139 | ||
8a2c437b TT |
12140 | /* A qsort comparison function that sorts breakpoints in order. */ |
12141 | ||
12142 | static int | |
12143 | compare_breakpoints (const void *a, const void *b) | |
12144 | { | |
12145 | const breakpoint_p *ba = a; | |
12146 | uintptr_t ua = (uintptr_t) *ba; | |
12147 | const breakpoint_p *bb = b; | |
12148 | uintptr_t ub = (uintptr_t) *bb; | |
12149 | ||
12150 | if ((*ba)->number < (*bb)->number) | |
12151 | return -1; | |
12152 | else if ((*ba)->number > (*bb)->number) | |
12153 | return 1; | |
12154 | ||
12155 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
12156 | the number 0. */ | |
12157 | if (ua < ub) | |
12158 | return -1; | |
94b0e70d | 12159 | return ua > ub ? 1 : 0; |
8a2c437b TT |
12160 | } |
12161 | ||
80f8a6eb | 12162 | /* Delete breakpoints by address or line. */ |
c906108c SS |
12163 | |
12164 | static void | |
fba45db2 | 12165 | clear_command (char *arg, int from_tty) |
c906108c | 12166 | { |
8a2c437b | 12167 | struct breakpoint *b, *prev; |
d6e956e5 VP |
12168 | VEC(breakpoint_p) *found = 0; |
12169 | int ix; | |
c906108c SS |
12170 | int default_match; |
12171 | struct symtabs_and_lines sals; | |
12172 | struct symtab_and_line sal; | |
c906108c | 12173 | int i; |
8a2c437b | 12174 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
12175 | |
12176 | if (arg) | |
12177 | { | |
39cf75f7 DE |
12178 | sals = decode_line_with_current_source (arg, |
12179 | (DECODE_LINE_FUNFIRSTLINE | |
12180 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 12181 | make_cleanup (xfree, sals.sals); |
c906108c SS |
12182 | default_match = 0; |
12183 | } | |
12184 | else | |
12185 | { | |
c5aa993b | 12186 | sals.sals = (struct symtab_and_line *) |
c906108c | 12187 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 12188 | make_cleanup (xfree, sals.sals); |
4a64f543 | 12189 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
12190 | |
12191 | /* Set sal's line, symtab, pc, and pspace to the values | |
12192 | corresponding to the last call to print_frame_info. If the | |
12193 | codepoint is not valid, this will set all the fields to 0. */ | |
12194 | get_last_displayed_sal (&sal); | |
c906108c | 12195 | if (sal.symtab == 0) |
8a3fe4f8 | 12196 | error (_("No source file specified.")); |
c906108c SS |
12197 | |
12198 | sals.sals[0] = sal; | |
12199 | sals.nelts = 1; | |
12200 | ||
12201 | default_match = 1; | |
12202 | } | |
12203 | ||
4a64f543 MS |
12204 | /* We don't call resolve_sal_pc here. That's not as bad as it |
12205 | seems, because all existing breakpoints typically have both | |
12206 | file/line and pc set. So, if clear is given file/line, we can | |
12207 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
12208 | |
12209 | We only support clearing given the address explicitly | |
12210 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 12211 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 12212 | due to optimization, all in one block. |
4a64f543 MS |
12213 | |
12214 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
12215 | PC corresponding to the same file:line, the breakpoint won't |
12216 | be cleared. We probably can still clear the breakpoint, but | |
12217 | since the other PC value is never presented to user, user | |
12218 | can only find it by guessing, and it does not seem important | |
12219 | to support that. */ | |
12220 | ||
4a64f543 MS |
12221 | /* For each line spec given, delete bps which correspond to it. Do |
12222 | it in two passes, solely to preserve the current behavior that | |
12223 | from_tty is forced true if we delete more than one | |
12224 | breakpoint. */ | |
c906108c | 12225 | |
80f8a6eb | 12226 | found = NULL; |
8a2c437b | 12227 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12228 | for (i = 0; i < sals.nelts; i++) |
12229 | { | |
05cba821 JK |
12230 | const char *sal_fullname; |
12231 | ||
c906108c | 12232 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12233 | If line given (pc == 0), clear all bpts on specified line. |
12234 | If defaulting, clear all bpts on default line | |
c906108c | 12235 | or at default pc. |
c5aa993b JM |
12236 | |
12237 | defaulting sal.pc != 0 tests to do | |
12238 | ||
12239 | 0 1 pc | |
12240 | 1 1 pc _and_ line | |
12241 | 0 0 line | |
12242 | 1 0 <can't happen> */ | |
c906108c SS |
12243 | |
12244 | sal = sals.sals[i]; | |
05cba821 JK |
12245 | sal_fullname = (sal.symtab == NULL |
12246 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12247 | |
4a64f543 | 12248 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12249 | ALL_BREAKPOINTS (b) |
c5aa993b | 12250 | { |
0d381245 | 12251 | int match = 0; |
4a64f543 | 12252 | /* Are we going to delete b? */ |
cc60f2e3 | 12253 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12254 | { |
12255 | struct bp_location *loc = b->loc; | |
12256 | for (; loc; loc = loc->next) | |
12257 | { | |
f8eba3c6 TT |
12258 | /* If the user specified file:line, don't allow a PC |
12259 | match. This matches historical gdb behavior. */ | |
12260 | int pc_match = (!sal.explicit_line | |
12261 | && sal.pc | |
12262 | && (loc->pspace == sal.pspace) | |
12263 | && (loc->address == sal.pc) | |
12264 | && (!section_is_overlay (loc->section) | |
12265 | || loc->section == sal.section)); | |
4aac40c8 TT |
12266 | int line_match = 0; |
12267 | ||
12268 | if ((default_match || sal.explicit_line) | |
2f202fde | 12269 | && loc->symtab != NULL |
05cba821 | 12270 | && sal_fullname != NULL |
4aac40c8 | 12271 | && sal.pspace == loc->pspace |
05cba821 JK |
12272 | && loc->line_number == sal.line |
12273 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12274 | sal_fullname) == 0) | |
12275 | line_match = 1; | |
4aac40c8 | 12276 | |
0d381245 VP |
12277 | if (pc_match || line_match) |
12278 | { | |
12279 | match = 1; | |
12280 | break; | |
12281 | } | |
12282 | } | |
12283 | } | |
12284 | ||
12285 | if (match) | |
d6e956e5 | 12286 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12287 | } |
80f8a6eb | 12288 | } |
8a2c437b | 12289 | |
80f8a6eb | 12290 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12291 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12292 | { |
12293 | if (arg) | |
8a3fe4f8 | 12294 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12295 | else |
8a3fe4f8 | 12296 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12297 | } |
c906108c | 12298 | |
8a2c437b TT |
12299 | /* Remove duplicates from the vec. */ |
12300 | qsort (VEC_address (breakpoint_p, found), | |
12301 | VEC_length (breakpoint_p, found), | |
12302 | sizeof (breakpoint_p), | |
12303 | compare_breakpoints); | |
12304 | prev = VEC_index (breakpoint_p, found, 0); | |
12305 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12306 | { | |
12307 | if (b == prev) | |
12308 | { | |
12309 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12310 | --ix; | |
12311 | } | |
12312 | } | |
12313 | ||
d6e956e5 | 12314 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12315 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12316 | if (from_tty) |
a3f17187 | 12317 | { |
d6e956e5 | 12318 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12319 | printf_unfiltered (_("Deleted breakpoint ")); |
12320 | else | |
12321 | printf_unfiltered (_("Deleted breakpoints ")); | |
12322 | } | |
d6e956e5 VP |
12323 | |
12324 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12325 | { |
c5aa993b | 12326 | if (from_tty) |
d6e956e5 VP |
12327 | printf_unfiltered ("%d ", b->number); |
12328 | delete_breakpoint (b); | |
c906108c | 12329 | } |
80f8a6eb MS |
12330 | if (from_tty) |
12331 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12332 | |
12333 | do_cleanups (cleanups); | |
c906108c SS |
12334 | } |
12335 | \f | |
12336 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12337 | all breakpoints that are marked for deletion, whether hit or not. | |
12338 | This is called after any breakpoint is hit, or after errors. */ | |
12339 | ||
12340 | void | |
fba45db2 | 12341 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12342 | { |
35df4500 | 12343 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12344 | |
12345 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12346 | if (bs->breakpoint_at |
12347 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12348 | && bs->stop) |
f431efe5 | 12349 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12350 | |
35df4500 | 12351 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12352 | { |
b5de0fa7 | 12353 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12354 | delete_breakpoint (b); |
12355 | } | |
c906108c SS |
12356 | } |
12357 | ||
4a64f543 MS |
12358 | /* A comparison function for bp_location AP and BP being interfaced to |
12359 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12360 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 12361 | secondarily by ordering first permanent elements and |
4a64f543 | 12362 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 12363 | qsort being an unstable algorithm. */ |
876fa593 JK |
12364 | |
12365 | static int | |
494cfb0f | 12366 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12367 | { |
494cfb0f JK |
12368 | struct bp_location *a = *(void **) ap; |
12369 | struct bp_location *b = *(void **) bp; | |
876fa593 JK |
12370 | |
12371 | if (a->address != b->address) | |
12372 | return (a->address > b->address) - (a->address < b->address); | |
12373 | ||
dea2aa5f LM |
12374 | /* Sort locations at the same address by their pspace number, keeping |
12375 | locations of the same inferior (in a multi-inferior environment) | |
12376 | grouped. */ | |
12377 | ||
12378 | if (a->pspace->num != b->pspace->num) | |
12379 | return ((a->pspace->num > b->pspace->num) | |
12380 | - (a->pspace->num < b->pspace->num)); | |
12381 | ||
876fa593 | 12382 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
12383 | if (a->permanent != b->permanent) |
12384 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 12385 | |
c56a97f9 JK |
12386 | /* Make the internal GDB representation stable across GDB runs |
12387 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12388 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12389 | |
12390 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12391 | return ((a->owner->number > b->owner->number) |
12392 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12393 | |
12394 | return (a > b) - (a < b); | |
12395 | } | |
12396 | ||
876fa593 | 12397 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12398 | bp_location_shadow_len_after_address_max according to the current |
12399 | content of the bp_location array. */ | |
f7545552 TT |
12400 | |
12401 | static void | |
876fa593 | 12402 | bp_location_target_extensions_update (void) |
f7545552 | 12403 | { |
876fa593 JK |
12404 | struct bp_location *bl, **blp_tmp; |
12405 | ||
12406 | bp_location_placed_address_before_address_max = 0; | |
12407 | bp_location_shadow_len_after_address_max = 0; | |
12408 | ||
12409 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12410 | { | |
12411 | CORE_ADDR start, end, addr; | |
12412 | ||
12413 | if (!bp_location_has_shadow (bl)) | |
12414 | continue; | |
12415 | ||
12416 | start = bl->target_info.placed_address; | |
12417 | end = start + bl->target_info.shadow_len; | |
12418 | ||
12419 | gdb_assert (bl->address >= start); | |
12420 | addr = bl->address - start; | |
12421 | if (addr > bp_location_placed_address_before_address_max) | |
12422 | bp_location_placed_address_before_address_max = addr; | |
12423 | ||
12424 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12425 | ||
12426 | gdb_assert (bl->address < end); | |
12427 | addr = end - bl->address; | |
12428 | if (addr > bp_location_shadow_len_after_address_max) | |
12429 | bp_location_shadow_len_after_address_max = addr; | |
12430 | } | |
f7545552 TT |
12431 | } |
12432 | ||
1e4d1764 YQ |
12433 | /* Download tracepoint locations if they haven't been. */ |
12434 | ||
12435 | static void | |
12436 | download_tracepoint_locations (void) | |
12437 | { | |
7ed2c994 | 12438 | struct breakpoint *b; |
1e4d1764 YQ |
12439 | struct cleanup *old_chain; |
12440 | ||
12441 | if (!target_can_download_tracepoint ()) | |
12442 | return; | |
12443 | ||
12444 | old_chain = save_current_space_and_thread (); | |
12445 | ||
7ed2c994 | 12446 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12447 | { |
7ed2c994 | 12448 | struct bp_location *bl; |
1e4d1764 | 12449 | struct tracepoint *t; |
f2a8bc8a | 12450 | int bp_location_downloaded = 0; |
1e4d1764 | 12451 | |
7ed2c994 | 12452 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12453 | ? !may_insert_fast_tracepoints |
12454 | : !may_insert_tracepoints)) | |
12455 | continue; | |
12456 | ||
7ed2c994 YQ |
12457 | for (bl = b->loc; bl; bl = bl->next) |
12458 | { | |
12459 | /* In tracepoint, locations are _never_ duplicated, so | |
12460 | should_be_inserted is equivalent to | |
12461 | unduplicated_should_be_inserted. */ | |
12462 | if (!should_be_inserted (bl) || bl->inserted) | |
12463 | continue; | |
1e4d1764 | 12464 | |
7ed2c994 | 12465 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12466 | |
7ed2c994 | 12467 | target_download_tracepoint (bl); |
1e4d1764 | 12468 | |
7ed2c994 | 12469 | bl->inserted = 1; |
f2a8bc8a | 12470 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12471 | } |
12472 | t = (struct tracepoint *) b; | |
12473 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12474 | if (bp_location_downloaded) |
12475 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12476 | } |
12477 | ||
12478 | do_cleanups (old_chain); | |
12479 | } | |
12480 | ||
934709f0 PW |
12481 | /* Swap the insertion/duplication state between two locations. */ |
12482 | ||
12483 | static void | |
12484 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12485 | { | |
12486 | const int left_inserted = left->inserted; | |
12487 | const int left_duplicate = left->duplicate; | |
b775012e | 12488 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12489 | const struct bp_target_info left_target_info = left->target_info; |
12490 | ||
1e4d1764 YQ |
12491 | /* Locations of tracepoints can never be duplicated. */ |
12492 | if (is_tracepoint (left->owner)) | |
12493 | gdb_assert (!left->duplicate); | |
12494 | if (is_tracepoint (right->owner)) | |
12495 | gdb_assert (!right->duplicate); | |
12496 | ||
934709f0 PW |
12497 | left->inserted = right->inserted; |
12498 | left->duplicate = right->duplicate; | |
b775012e | 12499 | left->needs_update = right->needs_update; |
934709f0 PW |
12500 | left->target_info = right->target_info; |
12501 | right->inserted = left_inserted; | |
12502 | right->duplicate = left_duplicate; | |
b775012e | 12503 | right->needs_update = left_needs_update; |
934709f0 PW |
12504 | right->target_info = left_target_info; |
12505 | } | |
12506 | ||
b775012e LM |
12507 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12508 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12509 | conditions on the target's side. Such conditions need to be updated on | |
12510 | the target. */ | |
12511 | ||
12512 | static void | |
12513 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12514 | { | |
12515 | struct bp_location **locp = NULL, **loc2p; | |
12516 | struct bp_location *loc; | |
12517 | CORE_ADDR address = 0; | |
12518 | int pspace_num; | |
12519 | ||
12520 | address = bl->address; | |
12521 | pspace_num = bl->pspace->num; | |
12522 | ||
12523 | /* This is only meaningful if the target is | |
12524 | evaluating conditions and if the user has | |
12525 | opted for condition evaluation on the target's | |
12526 | side. */ | |
12527 | if (gdb_evaluates_breakpoint_condition_p () | |
12528 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12529 | return; | |
12530 | ||
12531 | /* Flag all breakpoint locations with this address and | |
12532 | the same program space as the location | |
12533 | as "its condition has changed". We need to | |
12534 | update the conditions on the target's side. */ | |
12535 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12536 | { | |
12537 | loc = *loc2p; | |
12538 | ||
12539 | if (!is_breakpoint (loc->owner) | |
12540 | || pspace_num != loc->pspace->num) | |
12541 | continue; | |
12542 | ||
12543 | /* Flag the location appropriately. We use a different state to | |
12544 | let everyone know that we already updated the set of locations | |
12545 | with addr bl->address and program space bl->pspace. This is so | |
12546 | we don't have to keep calling these functions just to mark locations | |
12547 | that have already been marked. */ | |
12548 | loc->condition_changed = condition_updated; | |
12549 | ||
12550 | /* Free the agent expression bytecode as well. We will compute | |
12551 | it later on. */ | |
12552 | if (loc->cond_bytecode) | |
12553 | { | |
12554 | free_agent_expr (loc->cond_bytecode); | |
12555 | loc->cond_bytecode = NULL; | |
12556 | } | |
12557 | } | |
12558 | } | |
44702360 PA |
12559 | /* Called whether new breakpoints are created, or existing breakpoints |
12560 | deleted, to update the global location list and recompute which | |
12561 | locations are duplicate of which. | |
b775012e | 12562 | |
04086b45 PA |
12563 | The INSERT_MODE flag determines whether locations may not, may, or |
12564 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12565 | info. */ | |
b60e7edf | 12566 | |
0d381245 | 12567 | static void |
44702360 | 12568 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12569 | { |
74960c60 | 12570 | struct breakpoint *b; |
876fa593 | 12571 | struct bp_location **locp, *loc; |
f7545552 | 12572 | struct cleanup *cleanups; |
b775012e LM |
12573 | /* Last breakpoint location address that was marked for update. */ |
12574 | CORE_ADDR last_addr = 0; | |
12575 | /* Last breakpoint location program space that was marked for update. */ | |
12576 | int last_pspace_num = -1; | |
f7545552 | 12577 | |
2d134ed3 PA |
12578 | /* Used in the duplicates detection below. When iterating over all |
12579 | bp_locations, points to the first bp_location of a given address. | |
12580 | Breakpoints and watchpoints of different types are never | |
12581 | duplicates of each other. Keep one pointer for each type of | |
12582 | breakpoint/watchpoint, so we only need to loop over all locations | |
12583 | once. */ | |
12584 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12585 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12586 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12587 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12588 | |
4a64f543 MS |
12589 | /* Saved former bp_location array which we compare against the newly |
12590 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12591 | struct bp_location **old_location, **old_locp; |
12592 | unsigned old_location_count; | |
12593 | ||
12594 | old_location = bp_location; | |
12595 | old_location_count = bp_location_count; | |
12596 | bp_location = NULL; | |
12597 | bp_location_count = 0; | |
12598 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12599 | |
74960c60 | 12600 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12601 | for (loc = b->loc; loc; loc = loc->next) |
12602 | bp_location_count++; | |
12603 | ||
12604 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
12605 | locp = bp_location; | |
12606 | ALL_BREAKPOINTS (b) | |
12607 | for (loc = b->loc; loc; loc = loc->next) | |
12608 | *locp++ = loc; | |
12609 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12610 | bp_location_compare); |
876fa593 JK |
12611 | |
12612 | bp_location_target_extensions_update (); | |
74960c60 | 12613 | |
4a64f543 MS |
12614 | /* Identify bp_location instances that are no longer present in the |
12615 | new list, and therefore should be freed. Note that it's not | |
12616 | necessary that those locations should be removed from inferior -- | |
12617 | if there's another location at the same address (previously | |
12618 | marked as duplicate), we don't need to remove/insert the | |
12619 | location. | |
876fa593 | 12620 | |
4a64f543 MS |
12621 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12622 | and former bp_location array state respectively. */ | |
876fa593 JK |
12623 | |
12624 | locp = bp_location; | |
12625 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12626 | old_locp++) | |
74960c60 | 12627 | { |
876fa593 | 12628 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12629 | struct bp_location **loc2p; |
876fa593 | 12630 | |
e5dd4106 | 12631 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12632 | not, we have to free it. */ |
c7d46a38 | 12633 | int found_object = 0; |
20874c92 VP |
12634 | /* Tells if the location should remain inserted in the target. */ |
12635 | int keep_in_target = 0; | |
12636 | int removed = 0; | |
876fa593 | 12637 | |
4a64f543 MS |
12638 | /* Skip LOCP entries which will definitely never be needed. |
12639 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12640 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12641 | && (*locp)->address < old_loc->address) |
876fa593 | 12642 | locp++; |
c7d46a38 PA |
12643 | |
12644 | for (loc2p = locp; | |
12645 | (loc2p < bp_location + bp_location_count | |
12646 | && (*loc2p)->address == old_loc->address); | |
12647 | loc2p++) | |
12648 | { | |
b775012e LM |
12649 | /* Check if this is a new/duplicated location or a duplicated |
12650 | location that had its condition modified. If so, we want to send | |
12651 | its condition to the target if evaluation of conditions is taking | |
12652 | place there. */ | |
12653 | if ((*loc2p)->condition_changed == condition_modified | |
12654 | && (last_addr != old_loc->address | |
12655 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12656 | { |
b775012e LM |
12657 | force_breakpoint_reinsertion (*loc2p); |
12658 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12659 | } |
b775012e LM |
12660 | |
12661 | if (*loc2p == old_loc) | |
12662 | found_object = 1; | |
c7d46a38 | 12663 | } |
74960c60 | 12664 | |
b775012e LM |
12665 | /* We have already handled this address, update it so that we don't |
12666 | have to go through updates again. */ | |
12667 | last_addr = old_loc->address; | |
12668 | ||
12669 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12670 | if (!found_object) | |
12671 | force_breakpoint_reinsertion (old_loc); | |
12672 | ||
4a64f543 MS |
12673 | /* If this location is no longer present, and inserted, look if |
12674 | there's maybe a new location at the same address. If so, | |
12675 | mark that one inserted, and don't remove this one. This is | |
12676 | needed so that we don't have a time window where a breakpoint | |
12677 | at certain location is not inserted. */ | |
74960c60 | 12678 | |
876fa593 | 12679 | if (old_loc->inserted) |
0d381245 | 12680 | { |
4a64f543 MS |
12681 | /* If the location is inserted now, we might have to remove |
12682 | it. */ | |
74960c60 | 12683 | |
876fa593 | 12684 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12685 | { |
4a64f543 MS |
12686 | /* The location is still present in the location list, |
12687 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12688 | keep_in_target = 1; |
74960c60 VP |
12689 | } |
12690 | else | |
12691 | { | |
b775012e LM |
12692 | /* This location still exists, but it won't be kept in the |
12693 | target since it may have been disabled. We proceed to | |
12694 | remove its target-side condition. */ | |
12695 | ||
4a64f543 MS |
12696 | /* The location is either no longer present, or got |
12697 | disabled. See if there's another location at the | |
12698 | same address, in which case we don't need to remove | |
12699 | this one from the target. */ | |
876fa593 | 12700 | |
2bdf28a0 | 12701 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12702 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12703 | { | |
876fa593 | 12704 | for (loc2p = locp; |
c7d46a38 PA |
12705 | (loc2p < bp_location + bp_location_count |
12706 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12707 | loc2p++) |
12708 | { | |
12709 | struct bp_location *loc2 = *loc2p; | |
12710 | ||
2d134ed3 | 12711 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12712 | { |
85d721b8 PA |
12713 | /* Read watchpoint locations are switched to |
12714 | access watchpoints, if the former are not | |
12715 | supported, but the latter are. */ | |
12716 | if (is_hardware_watchpoint (old_loc->owner)) | |
12717 | { | |
12718 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12719 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12720 | } | |
12721 | ||
934709f0 PW |
12722 | /* loc2 is a duplicated location. We need to check |
12723 | if it should be inserted in case it will be | |
12724 | unduplicated. */ | |
12725 | if (loc2 != old_loc | |
12726 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12727 | { |
934709f0 | 12728 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12729 | keep_in_target = 1; |
12730 | break; | |
12731 | } | |
876fa593 JK |
12732 | } |
12733 | } | |
12734 | } | |
74960c60 VP |
12735 | } |
12736 | ||
20874c92 VP |
12737 | if (!keep_in_target) |
12738 | { | |
876fa593 | 12739 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12740 | { |
4a64f543 MS |
12741 | /* This is just about all we can do. We could keep |
12742 | this location on the global list, and try to | |
12743 | remove it next time, but there's no particular | |
12744 | reason why we will succeed next time. | |
20874c92 | 12745 | |
4a64f543 MS |
12746 | Note that at this point, old_loc->owner is still |
12747 | valid, as delete_breakpoint frees the breakpoint | |
12748 | only after calling us. */ | |
3e43a32a MS |
12749 | printf_filtered (_("warning: Error removing " |
12750 | "breakpoint %d\n"), | |
876fa593 | 12751 | old_loc->owner->number); |
20874c92 VP |
12752 | } |
12753 | removed = 1; | |
12754 | } | |
0d381245 | 12755 | } |
74960c60 VP |
12756 | |
12757 | if (!found_object) | |
1c5cfe86 | 12758 | { |
db82e815 PA |
12759 | if (removed && non_stop |
12760 | && breakpoint_address_is_meaningful (old_loc->owner) | |
12761 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 12762 | { |
db82e815 PA |
12763 | /* This location was removed from the target. In |
12764 | non-stop mode, a race condition is possible where | |
12765 | we've removed a breakpoint, but stop events for that | |
12766 | breakpoint are already queued and will arrive later. | |
12767 | We apply an heuristic to be able to distinguish such | |
12768 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12769 | breakpoint location for a bit, and will retire it | |
12770 | after we see some number of events. The theory here | |
12771 | is that reporting of events should, "on the average", | |
12772 | be fair, so after a while we'll see events from all | |
12773 | threads that have anything of interest, and no longer | |
12774 | need to keep this breakpoint location around. We | |
12775 | don't hold locations forever so to reduce chances of | |
12776 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12777 | SIGTRAP. | |
12778 | ||
12779 | The heuristic failing can be disastrous on | |
12780 | decr_pc_after_break targets. | |
12781 | ||
12782 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12783 | if we fail to recognize a late breakpoint SIGTRAP, | |
12784 | because events_till_retirement has reached 0 too | |
12785 | soon, we'll fail to do the PC adjustment, and report | |
12786 | a random SIGTRAP to the user. When the user resumes | |
12787 | the inferior, it will most likely immediately crash | |
2dec564e | 12788 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12789 | corrupted, because of being resumed e.g., in the |
12790 | middle of a multi-byte instruction, or skipped a | |
12791 | one-byte instruction. This was actually seen happen | |
12792 | on native x86-linux, and should be less rare on | |
12793 | targets that do not support new thread events, like | |
12794 | remote, due to the heuristic depending on | |
12795 | thread_count. | |
12796 | ||
12797 | Mistaking a random SIGTRAP for a breakpoint trap | |
12798 | causes similar symptoms (PC adjustment applied when | |
12799 | it shouldn't), but then again, playing with SIGTRAPs | |
12800 | behind the debugger's back is asking for trouble. | |
12801 | ||
12802 | Since hardware watchpoint traps are always | |
12803 | distinguishable from other traps, so we don't need to | |
12804 | apply keep hardware watchpoint moribund locations | |
12805 | around. We simply always ignore hardware watchpoint | |
12806 | traps we can no longer explain. */ | |
12807 | ||
876fa593 JK |
12808 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12809 | old_loc->owner = NULL; | |
20874c92 | 12810 | |
876fa593 | 12811 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12812 | } |
12813 | else | |
f431efe5 PA |
12814 | { |
12815 | old_loc->owner = NULL; | |
12816 | decref_bp_location (&old_loc); | |
12817 | } | |
20874c92 | 12818 | } |
74960c60 | 12819 | } |
1c5cfe86 | 12820 | |
348d480f PA |
12821 | /* Rescan breakpoints at the same address and section, marking the |
12822 | first one as "first" and any others as "duplicates". This is so | |
12823 | that the bpt instruction is only inserted once. If we have a | |
12824 | permanent breakpoint at the same place as BPT, make that one the | |
12825 | official one, and the rest as duplicates. Permanent breakpoints | |
12826 | are sorted first for the same address. | |
12827 | ||
12828 | Do the same for hardware watchpoints, but also considering the | |
12829 | watchpoint's type (regular/access/read) and length. */ | |
12830 | ||
12831 | bp_loc_first = NULL; | |
12832 | wp_loc_first = NULL; | |
12833 | awp_loc_first = NULL; | |
12834 | rwp_loc_first = NULL; | |
12835 | ALL_BP_LOCATIONS (loc, locp) | |
12836 | { | |
12837 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12838 | non-NULL. */ | |
348d480f | 12839 | struct bp_location **loc_first_p; |
d3fbdd86 | 12840 | b = loc->owner; |
348d480f | 12841 | |
6f380991 | 12842 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12843 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12844 | /* Don't detect duplicate for tracepoint locations because they are |
12845 | never duplicated. See the comments in field `duplicate' of | |
12846 | `struct bp_location'. */ | |
348d480f | 12847 | || is_tracepoint (b)) |
b775012e LM |
12848 | { |
12849 | /* Clear the condition modification flag. */ | |
12850 | loc->condition_changed = condition_unchanged; | |
12851 | continue; | |
12852 | } | |
348d480f PA |
12853 | |
12854 | /* Permanent breakpoint should always be inserted. */ | |
1a853c52 | 12855 | if (loc->permanent && ! loc->inserted) |
348d480f PA |
12856 | internal_error (__FILE__, __LINE__, |
12857 | _("allegedly permanent breakpoint is not " | |
12858 | "actually inserted")); | |
12859 | ||
12860 | if (b->type == bp_hardware_watchpoint) | |
12861 | loc_first_p = &wp_loc_first; | |
12862 | else if (b->type == bp_read_watchpoint) | |
12863 | loc_first_p = &rwp_loc_first; | |
12864 | else if (b->type == bp_access_watchpoint) | |
12865 | loc_first_p = &awp_loc_first; | |
12866 | else | |
12867 | loc_first_p = &bp_loc_first; | |
12868 | ||
12869 | if (*loc_first_p == NULL | |
12870 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12871 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12872 | { | |
12873 | *loc_first_p = loc; | |
12874 | loc->duplicate = 0; | |
b775012e LM |
12875 | |
12876 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12877 | { | |
12878 | loc->needs_update = 1; | |
12879 | /* Clear the condition modification flag. */ | |
12880 | loc->condition_changed = condition_unchanged; | |
12881 | } | |
348d480f PA |
12882 | continue; |
12883 | } | |
12884 | ||
934709f0 PW |
12885 | |
12886 | /* This and the above ensure the invariant that the first location | |
12887 | is not duplicated, and is the inserted one. | |
12888 | All following are marked as duplicated, and are not inserted. */ | |
12889 | if (loc->inserted) | |
12890 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12891 | loc->duplicate = 1; |
12892 | ||
b775012e LM |
12893 | /* Clear the condition modification flag. */ |
12894 | loc->condition_changed = condition_unchanged; | |
12895 | ||
1a853c52 PA |
12896 | if (loc->inserted && !loc->permanent |
12897 | && (*loc_first_p)->permanent) | |
348d480f PA |
12898 | internal_error (__FILE__, __LINE__, |
12899 | _("another breakpoint was inserted on top of " | |
12900 | "a permanent breakpoint")); | |
12901 | } | |
12902 | ||
a25a5a45 | 12903 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12904 | { |
04086b45 | 12905 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12906 | insert_breakpoint_locations (); |
12907 | else | |
12908 | { | |
44702360 PA |
12909 | /* Even though the caller told us to not insert new |
12910 | locations, we may still need to update conditions on the | |
12911 | target's side of breakpoints that were already inserted | |
12912 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12913 | only update conditions for locations that are marked |
12914 | "needs_update". */ | |
12915 | update_inserted_breakpoint_locations (); | |
12916 | } | |
12917 | } | |
348d480f | 12918 | |
04086b45 | 12919 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12920 | download_tracepoint_locations (); |
12921 | ||
348d480f PA |
12922 | do_cleanups (cleanups); |
12923 | } | |
12924 | ||
12925 | void | |
12926 | breakpoint_retire_moribund (void) | |
12927 | { | |
12928 | struct bp_location *loc; | |
12929 | int ix; | |
12930 | ||
12931 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12932 | if (--(loc->events_till_retirement) == 0) | |
12933 | { | |
12934 | decref_bp_location (&loc); | |
12935 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12936 | --ix; | |
12937 | } | |
12938 | } | |
12939 | ||
12940 | static void | |
44702360 | 12941 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12942 | { |
bfd189b1 | 12943 | volatile struct gdb_exception e; |
348d480f PA |
12944 | |
12945 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
44702360 | 12946 | update_global_location_list (insert_mode); |
348d480f PA |
12947 | } |
12948 | ||
12949 | /* Clear BKP from a BPS. */ | |
12950 | ||
12951 | static void | |
12952 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12953 | { | |
12954 | bpstat bs; | |
12955 | ||
12956 | for (bs = bps; bs; bs = bs->next) | |
12957 | if (bs->breakpoint_at == bpt) | |
12958 | { | |
12959 | bs->breakpoint_at = NULL; | |
12960 | bs->old_val = NULL; | |
12961 | /* bs->commands will be freed later. */ | |
12962 | } | |
12963 | } | |
12964 | ||
12965 | /* Callback for iterate_over_threads. */ | |
12966 | static int | |
12967 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12968 | { | |
12969 | struct breakpoint *bpt = data; | |
12970 | ||
12971 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12972 | return 0; | |
12973 | } | |
12974 | ||
12975 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12976 | callbacks. */ | |
12977 | ||
12978 | static void | |
12979 | say_where (struct breakpoint *b) | |
12980 | { | |
12981 | struct value_print_options opts; | |
12982 | ||
12983 | get_user_print_options (&opts); | |
12984 | ||
12985 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12986 | single string. */ | |
12987 | if (b->loc == NULL) | |
12988 | { | |
12989 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
12990 | } | |
12991 | else | |
12992 | { | |
2f202fde | 12993 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12994 | { |
12995 | printf_filtered (" at "); | |
12996 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12997 | gdb_stdout); | |
12998 | } | |
2f202fde | 12999 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
13000 | { |
13001 | /* If there is a single location, we can print the location | |
13002 | more nicely. */ | |
13003 | if (b->loc->next == NULL) | |
13004 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
13005 | symtab_to_filename_for_display (b->loc->symtab), |
13006 | b->loc->line_number); | |
f8eba3c6 TT |
13007 | else |
13008 | /* This is not ideal, but each location may have a | |
13009 | different file name, and this at least reflects the | |
13010 | real situation somewhat. */ | |
13011 | printf_filtered (": %s.", b->addr_string); | |
13012 | } | |
348d480f PA |
13013 | |
13014 | if (b->loc->next) | |
13015 | { | |
13016 | struct bp_location *loc = b->loc; | |
13017 | int n = 0; | |
13018 | for (; loc; loc = loc->next) | |
13019 | ++n; | |
13020 | printf_filtered (" (%d locations)", n); | |
13021 | } | |
13022 | } | |
13023 | } | |
13024 | ||
348d480f PA |
13025 | /* Default bp_location_ops methods. */ |
13026 | ||
13027 | static void | |
13028 | bp_location_dtor (struct bp_location *self) | |
13029 | { | |
13030 | xfree (self->cond); | |
b775012e LM |
13031 | if (self->cond_bytecode) |
13032 | free_agent_expr (self->cond_bytecode); | |
348d480f | 13033 | xfree (self->function_name); |
8b4f3082 PA |
13034 | |
13035 | VEC_free (agent_expr_p, self->target_info.conditions); | |
13036 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
13037 | } |
13038 | ||
13039 | static const struct bp_location_ops bp_location_ops = | |
13040 | { | |
13041 | bp_location_dtor | |
13042 | }; | |
13043 | ||
2060206e PA |
13044 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
13045 | inherit from. */ | |
348d480f | 13046 | |
2060206e PA |
13047 | static void |
13048 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
13049 | { |
13050 | decref_counted_command_line (&self->commands); | |
13051 | xfree (self->cond_string); | |
fb81d016 | 13052 | xfree (self->extra_string); |
348d480f | 13053 | xfree (self->addr_string); |
f8eba3c6 | 13054 | xfree (self->filter); |
348d480f | 13055 | xfree (self->addr_string_range_end); |
348d480f PA |
13056 | } |
13057 | ||
2060206e PA |
13058 | static struct bp_location * |
13059 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
13060 | { |
13061 | struct bp_location *loc; | |
13062 | ||
13063 | loc = XNEW (struct bp_location); | |
13064 | init_bp_location (loc, &bp_location_ops, self); | |
13065 | return loc; | |
13066 | } | |
13067 | ||
2060206e PA |
13068 | static void |
13069 | base_breakpoint_re_set (struct breakpoint *b) | |
13070 | { | |
13071 | /* Nothing to re-set. */ | |
13072 | } | |
13073 | ||
13074 | #define internal_error_pure_virtual_called() \ | |
13075 | gdb_assert_not_reached ("pure virtual function called") | |
13076 | ||
13077 | static int | |
13078 | base_breakpoint_insert_location (struct bp_location *bl) | |
13079 | { | |
13080 | internal_error_pure_virtual_called (); | |
13081 | } | |
13082 | ||
13083 | static int | |
13084 | base_breakpoint_remove_location (struct bp_location *bl) | |
13085 | { | |
13086 | internal_error_pure_virtual_called (); | |
13087 | } | |
13088 | ||
13089 | static int | |
13090 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
13091 | struct address_space *aspace, | |
09ac7c10 TT |
13092 | CORE_ADDR bp_addr, |
13093 | const struct target_waitstatus *ws) | |
2060206e PA |
13094 | { |
13095 | internal_error_pure_virtual_called (); | |
13096 | } | |
13097 | ||
13098 | static void | |
13099 | base_breakpoint_check_status (bpstat bs) | |
13100 | { | |
13101 | /* Always stop. */ | |
13102 | } | |
13103 | ||
13104 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
13105 | errors. */ | |
13106 | ||
13107 | static int | |
13108 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
13109 | { | |
13110 | internal_error_pure_virtual_called (); | |
13111 | } | |
13112 | ||
13113 | /* A "resources_needed" breakpoint_ops method that just internal | |
13114 | errors. */ | |
13115 | ||
13116 | static int | |
13117 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
13118 | { | |
13119 | internal_error_pure_virtual_called (); | |
13120 | } | |
13121 | ||
13122 | static enum print_stop_action | |
13123 | base_breakpoint_print_it (bpstat bs) | |
13124 | { | |
13125 | internal_error_pure_virtual_called (); | |
13126 | } | |
13127 | ||
13128 | static void | |
13129 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
13130 | struct ui_out *uiout) | |
13131 | { | |
13132 | /* nothing */ | |
13133 | } | |
13134 | ||
13135 | static void | |
13136 | base_breakpoint_print_mention (struct breakpoint *b) | |
13137 | { | |
13138 | internal_error_pure_virtual_called (); | |
13139 | } | |
13140 | ||
13141 | static void | |
13142 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
13143 | { | |
13144 | internal_error_pure_virtual_called (); | |
13145 | } | |
13146 | ||
983af33b SDJ |
13147 | static void |
13148 | base_breakpoint_create_sals_from_address (char **arg, | |
13149 | struct linespec_result *canonical, | |
13150 | enum bptype type_wanted, | |
13151 | char *addr_start, | |
13152 | char **copy_arg) | |
13153 | { | |
13154 | internal_error_pure_virtual_called (); | |
13155 | } | |
13156 | ||
13157 | static void | |
13158 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13159 | struct linespec_result *c, | |
983af33b | 13160 | char *cond_string, |
e7e0cddf | 13161 | char *extra_string, |
983af33b SDJ |
13162 | enum bptype type_wanted, |
13163 | enum bpdisp disposition, | |
13164 | int thread, | |
13165 | int task, int ignore_count, | |
13166 | const struct breakpoint_ops *o, | |
13167 | int from_tty, int enabled, | |
44f238bb | 13168 | int internal, unsigned flags) |
983af33b SDJ |
13169 | { |
13170 | internal_error_pure_virtual_called (); | |
13171 | } | |
13172 | ||
13173 | static void | |
13174 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, | |
13175 | struct symtabs_and_lines *sals) | |
13176 | { | |
13177 | internal_error_pure_virtual_called (); | |
13178 | } | |
13179 | ||
ab04a2af TT |
13180 | /* The default 'explains_signal' method. */ |
13181 | ||
47591c29 | 13182 | static int |
427cd150 | 13183 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 13184 | { |
47591c29 | 13185 | return 1; |
ab04a2af TT |
13186 | } |
13187 | ||
9d6e6e84 HZ |
13188 | /* The default "after_condition_true" method. */ |
13189 | ||
13190 | static void | |
13191 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
13192 | { | |
13193 | /* Nothing to do. */ | |
13194 | } | |
13195 | ||
ab04a2af | 13196 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
13197 | { |
13198 | base_breakpoint_dtor, | |
13199 | base_breakpoint_allocate_location, | |
13200 | base_breakpoint_re_set, | |
13201 | base_breakpoint_insert_location, | |
13202 | base_breakpoint_remove_location, | |
13203 | base_breakpoint_breakpoint_hit, | |
13204 | base_breakpoint_check_status, | |
13205 | base_breakpoint_resources_needed, | |
13206 | base_breakpoint_works_in_software_mode, | |
13207 | base_breakpoint_print_it, | |
13208 | NULL, | |
13209 | base_breakpoint_print_one_detail, | |
13210 | base_breakpoint_print_mention, | |
983af33b SDJ |
13211 | base_breakpoint_print_recreate, |
13212 | base_breakpoint_create_sals_from_address, | |
13213 | base_breakpoint_create_breakpoints_sal, | |
13214 | base_breakpoint_decode_linespec, | |
9d6e6e84 HZ |
13215 | base_breakpoint_explains_signal, |
13216 | base_breakpoint_after_condition_true, | |
2060206e PA |
13217 | }; |
13218 | ||
13219 | /* Default breakpoint_ops methods. */ | |
13220 | ||
13221 | static void | |
348d480f PA |
13222 | bkpt_re_set (struct breakpoint *b) |
13223 | { | |
06edf0c0 PA |
13224 | /* FIXME: is this still reachable? */ |
13225 | if (b->addr_string == NULL) | |
13226 | { | |
13227 | /* Anything without a string can't be re-set. */ | |
348d480f | 13228 | delete_breakpoint (b); |
06edf0c0 | 13229 | return; |
348d480f | 13230 | } |
06edf0c0 PA |
13231 | |
13232 | breakpoint_re_set_default (b); | |
348d480f PA |
13233 | } |
13234 | ||
2060206e | 13235 | static int |
348d480f PA |
13236 | bkpt_insert_location (struct bp_location *bl) |
13237 | { | |
13238 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
7c16b83e | 13239 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 13240 | else |
7c16b83e | 13241 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13242 | } |
13243 | ||
2060206e | 13244 | static int |
348d480f PA |
13245 | bkpt_remove_location (struct bp_location *bl) |
13246 | { | |
13247 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13248 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13249 | else | |
7c16b83e | 13250 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13251 | } |
13252 | ||
2060206e | 13253 | static int |
348d480f | 13254 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13255 | struct address_space *aspace, CORE_ADDR bp_addr, |
13256 | const struct target_waitstatus *ws) | |
348d480f | 13257 | { |
09ac7c10 | 13258 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13259 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13260 | return 0; |
13261 | ||
348d480f PA |
13262 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13263 | aspace, bp_addr)) | |
13264 | return 0; | |
13265 | ||
13266 | if (overlay_debugging /* unmapped overlay section */ | |
13267 | && section_is_overlay (bl->section) | |
13268 | && !section_is_mapped (bl->section)) | |
13269 | return 0; | |
13270 | ||
13271 | return 1; | |
13272 | } | |
13273 | ||
cd1608cc PA |
13274 | static int |
13275 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
13276 | struct address_space *aspace, CORE_ADDR bp_addr, | |
13277 | const struct target_waitstatus *ws) | |
13278 | { | |
13279 | if (dprintf_style == dprintf_style_agent | |
13280 | && target_can_run_breakpoint_commands ()) | |
13281 | { | |
13282 | /* An agent-style dprintf never causes a stop. If we see a trap | |
13283 | for this address it must be for a breakpoint that happens to | |
13284 | be set at the same address. */ | |
13285 | return 0; | |
13286 | } | |
13287 | ||
13288 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
13289 | } | |
13290 | ||
2060206e | 13291 | static int |
348d480f PA |
13292 | bkpt_resources_needed (const struct bp_location *bl) |
13293 | { | |
13294 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13295 | ||
13296 | return 1; | |
13297 | } | |
13298 | ||
2060206e | 13299 | static enum print_stop_action |
348d480f PA |
13300 | bkpt_print_it (bpstat bs) |
13301 | { | |
348d480f PA |
13302 | struct breakpoint *b; |
13303 | const struct bp_location *bl; | |
001c8c33 | 13304 | int bp_temp; |
79a45e25 | 13305 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13306 | |
13307 | gdb_assert (bs->bp_location_at != NULL); | |
13308 | ||
13309 | bl = bs->bp_location_at; | |
13310 | b = bs->breakpoint_at; | |
13311 | ||
001c8c33 PA |
13312 | bp_temp = b->disposition == disp_del; |
13313 | if (bl->address != bl->requested_address) | |
13314 | breakpoint_adjustment_warning (bl->requested_address, | |
13315 | bl->address, | |
13316 | b->number, 1); | |
13317 | annotate_breakpoint (b->number); | |
13318 | if (bp_temp) | |
13319 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
13320 | else | |
13321 | ui_out_text (uiout, "\nBreakpoint "); | |
13322 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 13323 | { |
001c8c33 PA |
13324 | ui_out_field_string (uiout, "reason", |
13325 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13326 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13327 | } |
001c8c33 PA |
13328 | ui_out_field_int (uiout, "bkptno", b->number); |
13329 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13330 | |
001c8c33 | 13331 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13332 | } |
13333 | ||
2060206e | 13334 | static void |
06edf0c0 PA |
13335 | bkpt_print_mention (struct breakpoint *b) |
13336 | { | |
79a45e25 | 13337 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13338 | return; |
13339 | ||
13340 | switch (b->type) | |
13341 | { | |
13342 | case bp_breakpoint: | |
13343 | case bp_gnu_ifunc_resolver: | |
13344 | if (b->disposition == disp_del) | |
13345 | printf_filtered (_("Temporary breakpoint")); | |
13346 | else | |
13347 | printf_filtered (_("Breakpoint")); | |
13348 | printf_filtered (_(" %d"), b->number); | |
13349 | if (b->type == bp_gnu_ifunc_resolver) | |
13350 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13351 | break; | |
13352 | case bp_hardware_breakpoint: | |
13353 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13354 | break; | |
e7e0cddf SS |
13355 | case bp_dprintf: |
13356 | printf_filtered (_("Dprintf %d"), b->number); | |
13357 | break; | |
06edf0c0 PA |
13358 | } |
13359 | ||
13360 | say_where (b); | |
13361 | } | |
13362 | ||
2060206e | 13363 | static void |
06edf0c0 PA |
13364 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13365 | { | |
13366 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13367 | fprintf_unfiltered (fp, "tbreak"); | |
13368 | else if (tp->type == bp_breakpoint) | |
13369 | fprintf_unfiltered (fp, "break"); | |
13370 | else if (tp->type == bp_hardware_breakpoint | |
13371 | && tp->disposition == disp_del) | |
13372 | fprintf_unfiltered (fp, "thbreak"); | |
13373 | else if (tp->type == bp_hardware_breakpoint) | |
13374 | fprintf_unfiltered (fp, "hbreak"); | |
13375 | else | |
13376 | internal_error (__FILE__, __LINE__, | |
13377 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13378 | ||
2060206e | 13379 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 13380 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13381 | } |
13382 | ||
983af33b SDJ |
13383 | static void |
13384 | bkpt_create_sals_from_address (char **arg, | |
13385 | struct linespec_result *canonical, | |
13386 | enum bptype type_wanted, | |
13387 | char *addr_start, char **copy_arg) | |
13388 | { | |
13389 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13390 | addr_start, copy_arg); | |
13391 | } | |
13392 | ||
13393 | static void | |
13394 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13395 | struct linespec_result *canonical, | |
983af33b | 13396 | char *cond_string, |
e7e0cddf | 13397 | char *extra_string, |
983af33b SDJ |
13398 | enum bptype type_wanted, |
13399 | enum bpdisp disposition, | |
13400 | int thread, | |
13401 | int task, int ignore_count, | |
13402 | const struct breakpoint_ops *ops, | |
13403 | int from_tty, int enabled, | |
44f238bb | 13404 | int internal, unsigned flags) |
983af33b | 13405 | { |
023fa29b | 13406 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13407 | cond_string, extra_string, |
13408 | type_wanted, | |
983af33b SDJ |
13409 | disposition, thread, task, |
13410 | ignore_count, ops, from_tty, | |
44f238bb | 13411 | enabled, internal, flags); |
983af33b SDJ |
13412 | } |
13413 | ||
13414 | static void | |
13415 | bkpt_decode_linespec (struct breakpoint *b, char **s, | |
13416 | struct symtabs_and_lines *sals) | |
13417 | { | |
13418 | decode_linespec_default (b, s, sals); | |
13419 | } | |
13420 | ||
06edf0c0 PA |
13421 | /* Virtual table for internal breakpoints. */ |
13422 | ||
13423 | static void | |
13424 | internal_bkpt_re_set (struct breakpoint *b) | |
13425 | { | |
13426 | switch (b->type) | |
13427 | { | |
13428 | /* Delete overlay event and longjmp master breakpoints; they | |
13429 | will be reset later by breakpoint_re_set. */ | |
13430 | case bp_overlay_event: | |
13431 | case bp_longjmp_master: | |
13432 | case bp_std_terminate_master: | |
13433 | case bp_exception_master: | |
13434 | delete_breakpoint (b); | |
13435 | break; | |
13436 | ||
13437 | /* This breakpoint is special, it's set up when the inferior | |
13438 | starts and we really don't want to touch it. */ | |
13439 | case bp_shlib_event: | |
13440 | ||
13441 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13442 | it is set up, we do not want to touch it. */ | |
13443 | case bp_thread_event: | |
13444 | break; | |
13445 | } | |
13446 | } | |
13447 | ||
13448 | static void | |
13449 | internal_bkpt_check_status (bpstat bs) | |
13450 | { | |
a9b3a50f PA |
13451 | if (bs->breakpoint_at->type == bp_shlib_event) |
13452 | { | |
13453 | /* If requested, stop when the dynamic linker notifies GDB of | |
13454 | events. This allows the user to get control and place | |
13455 | breakpoints in initializer routines for dynamically loaded | |
13456 | objects (among other things). */ | |
13457 | bs->stop = stop_on_solib_events; | |
13458 | bs->print = stop_on_solib_events; | |
13459 | } | |
13460 | else | |
13461 | bs->stop = 0; | |
06edf0c0 PA |
13462 | } |
13463 | ||
13464 | static enum print_stop_action | |
13465 | internal_bkpt_print_it (bpstat bs) | |
13466 | { | |
06edf0c0 | 13467 | struct breakpoint *b; |
06edf0c0 | 13468 | |
06edf0c0 PA |
13469 | b = bs->breakpoint_at; |
13470 | ||
06edf0c0 PA |
13471 | switch (b->type) |
13472 | { | |
348d480f PA |
13473 | case bp_shlib_event: |
13474 | /* Did we stop because the user set the stop_on_solib_events | |
13475 | variable? (If so, we report this as a generic, "Stopped due | |
13476 | to shlib event" message.) */ | |
edcc5120 | 13477 | print_solib_event (0); |
348d480f PA |
13478 | break; |
13479 | ||
13480 | case bp_thread_event: | |
13481 | /* Not sure how we will get here. | |
13482 | GDB should not stop for these breakpoints. */ | |
13483 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13484 | break; |
13485 | ||
13486 | case bp_overlay_event: | |
13487 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13488 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13489 | break; |
13490 | ||
13491 | case bp_longjmp_master: | |
13492 | /* These should never be enabled. */ | |
13493 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13494 | break; |
13495 | ||
13496 | case bp_std_terminate_master: | |
13497 | /* These should never be enabled. */ | |
13498 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13499 | "gdb should not stop!\n")); | |
348d480f PA |
13500 | break; |
13501 | ||
13502 | case bp_exception_master: | |
13503 | /* These should never be enabled. */ | |
13504 | printf_filtered (_("Exception Master Breakpoint: " | |
13505 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13506 | break; |
13507 | } | |
13508 | ||
001c8c33 | 13509 | return PRINT_NOTHING; |
06edf0c0 PA |
13510 | } |
13511 | ||
13512 | static void | |
13513 | internal_bkpt_print_mention (struct breakpoint *b) | |
13514 | { | |
13515 | /* Nothing to mention. These breakpoints are internal. */ | |
13516 | } | |
13517 | ||
06edf0c0 PA |
13518 | /* Virtual table for momentary breakpoints */ |
13519 | ||
13520 | static void | |
13521 | momentary_bkpt_re_set (struct breakpoint *b) | |
13522 | { | |
13523 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13524 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13525 | Otherwise these should have been blown away via the cleanup chain |
13526 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13527 | } | |
13528 | ||
13529 | static void | |
13530 | momentary_bkpt_check_status (bpstat bs) | |
13531 | { | |
13532 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13533 | } | |
13534 | ||
13535 | static enum print_stop_action | |
13536 | momentary_bkpt_print_it (bpstat bs) | |
13537 | { | |
79a45e25 PA |
13538 | struct ui_out *uiout = current_uiout; |
13539 | ||
001c8c33 | 13540 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 13541 | { |
001c8c33 | 13542 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 13543 | |
001c8c33 PA |
13544 | switch (b->type) |
13545 | { | |
13546 | case bp_finish: | |
13547 | ui_out_field_string | |
13548 | (uiout, "reason", | |
13549 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
13550 | break; | |
348d480f | 13551 | |
001c8c33 PA |
13552 | case bp_until: |
13553 | ui_out_field_string | |
13554 | (uiout, "reason", | |
13555 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
13556 | break; | |
13557 | } | |
348d480f PA |
13558 | } |
13559 | ||
001c8c33 | 13560 | return PRINT_UNKNOWN; |
348d480f PA |
13561 | } |
13562 | ||
06edf0c0 PA |
13563 | static void |
13564 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13565 | { |
06edf0c0 | 13566 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13567 | } |
13568 | ||
e2e4d78b JK |
13569 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13570 | ||
13571 | It gets cleared already on the removal of the first one of such placed | |
13572 | breakpoints. This is OK as they get all removed altogether. */ | |
13573 | ||
13574 | static void | |
13575 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13576 | { | |
13577 | struct thread_info *tp = find_thread_id (self->thread); | |
13578 | ||
13579 | if (tp) | |
13580 | tp->initiating_frame = null_frame_id; | |
13581 | ||
13582 | momentary_breakpoint_ops.dtor (self); | |
13583 | } | |
13584 | ||
55aa24fb SDJ |
13585 | /* Specific methods for probe breakpoints. */ |
13586 | ||
13587 | static int | |
13588 | bkpt_probe_insert_location (struct bp_location *bl) | |
13589 | { | |
13590 | int v = bkpt_insert_location (bl); | |
13591 | ||
13592 | if (v == 0) | |
13593 | { | |
13594 | /* The insertion was successful, now let's set the probe's semaphore | |
13595 | if needed. */ | |
0ea5cda8 SDJ |
13596 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13597 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13598 | bl->probe.objfile, | |
13599 | bl->gdbarch); | |
55aa24fb SDJ |
13600 | } |
13601 | ||
13602 | return v; | |
13603 | } | |
13604 | ||
13605 | static int | |
13606 | bkpt_probe_remove_location (struct bp_location *bl) | |
13607 | { | |
13608 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13609 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13610 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13611 | bl->probe.objfile, | |
13612 | bl->gdbarch); | |
55aa24fb SDJ |
13613 | |
13614 | return bkpt_remove_location (bl); | |
13615 | } | |
13616 | ||
13617 | static void | |
13618 | bkpt_probe_create_sals_from_address (char **arg, | |
13619 | struct linespec_result *canonical, | |
13620 | enum bptype type_wanted, | |
13621 | char *addr_start, char **copy_arg) | |
13622 | { | |
13623 | struct linespec_sals lsal; | |
13624 | ||
13625 | lsal.sals = parse_probes (arg, canonical); | |
13626 | ||
13627 | *copy_arg = xstrdup (canonical->addr_string); | |
13628 | lsal.canonical = xstrdup (*copy_arg); | |
13629 | ||
13630 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13631 | } | |
13632 | ||
13633 | static void | |
13634 | bkpt_probe_decode_linespec (struct breakpoint *b, char **s, | |
13635 | struct symtabs_and_lines *sals) | |
13636 | { | |
13637 | *sals = parse_probes (s, NULL); | |
13638 | if (!sals->sals) | |
13639 | error (_("probe not found")); | |
13640 | } | |
13641 | ||
348d480f | 13642 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13643 | |
348d480f PA |
13644 | static void |
13645 | tracepoint_re_set (struct breakpoint *b) | |
13646 | { | |
13647 | breakpoint_re_set_default (b); | |
13648 | } | |
876fa593 | 13649 | |
348d480f PA |
13650 | static int |
13651 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13652 | struct address_space *aspace, CORE_ADDR bp_addr, |
13653 | const struct target_waitstatus *ws) | |
348d480f PA |
13654 | { |
13655 | /* By definition, the inferior does not report stops at | |
13656 | tracepoints. */ | |
13657 | return 0; | |
74960c60 VP |
13658 | } |
13659 | ||
13660 | static void | |
348d480f PA |
13661 | tracepoint_print_one_detail (const struct breakpoint *self, |
13662 | struct ui_out *uiout) | |
74960c60 | 13663 | { |
d9b3f62e PA |
13664 | struct tracepoint *tp = (struct tracepoint *) self; |
13665 | if (tp->static_trace_marker_id) | |
348d480f PA |
13666 | { |
13667 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13668 | |
348d480f PA |
13669 | ui_out_text (uiout, "\tmarker id is "); |
13670 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13671 | tp->static_trace_marker_id); |
348d480f PA |
13672 | ui_out_text (uiout, "\n"); |
13673 | } | |
0d381245 VP |
13674 | } |
13675 | ||
a474d7c2 | 13676 | static void |
348d480f | 13677 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13678 | { |
79a45e25 | 13679 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13680 | return; |
cc59ec59 | 13681 | |
348d480f PA |
13682 | switch (b->type) |
13683 | { | |
13684 | case bp_tracepoint: | |
13685 | printf_filtered (_("Tracepoint")); | |
13686 | printf_filtered (_(" %d"), b->number); | |
13687 | break; | |
13688 | case bp_fast_tracepoint: | |
13689 | printf_filtered (_("Fast tracepoint")); | |
13690 | printf_filtered (_(" %d"), b->number); | |
13691 | break; | |
13692 | case bp_static_tracepoint: | |
13693 | printf_filtered (_("Static tracepoint")); | |
13694 | printf_filtered (_(" %d"), b->number); | |
13695 | break; | |
13696 | default: | |
13697 | internal_error (__FILE__, __LINE__, | |
13698 | _("unhandled tracepoint type %d"), (int) b->type); | |
13699 | } | |
13700 | ||
13701 | say_where (b); | |
a474d7c2 PA |
13702 | } |
13703 | ||
348d480f | 13704 | static void |
d9b3f62e | 13705 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13706 | { |
d9b3f62e PA |
13707 | struct tracepoint *tp = (struct tracepoint *) self; |
13708 | ||
13709 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13710 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 13711 | if (self->type == bp_static_tracepoint) |
348d480f | 13712 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13713 | else if (self->type == bp_tracepoint) |
348d480f PA |
13714 | fprintf_unfiltered (fp, "trace"); |
13715 | else | |
13716 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13717 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13718 | |
d9b3f62e PA |
13719 | fprintf_unfiltered (fp, " %s", self->addr_string); |
13720 | print_recreate_thread (self, fp); | |
13721 | ||
13722 | if (tp->pass_count) | |
13723 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13724 | } |
13725 | ||
983af33b SDJ |
13726 | static void |
13727 | tracepoint_create_sals_from_address (char **arg, | |
13728 | struct linespec_result *canonical, | |
13729 | enum bptype type_wanted, | |
13730 | char *addr_start, char **copy_arg) | |
13731 | { | |
13732 | create_sals_from_address_default (arg, canonical, type_wanted, | |
13733 | addr_start, copy_arg); | |
13734 | } | |
13735 | ||
13736 | static void | |
13737 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13738 | struct linespec_result *canonical, | |
983af33b | 13739 | char *cond_string, |
e7e0cddf | 13740 | char *extra_string, |
983af33b SDJ |
13741 | enum bptype type_wanted, |
13742 | enum bpdisp disposition, | |
13743 | int thread, | |
13744 | int task, int ignore_count, | |
13745 | const struct breakpoint_ops *ops, | |
13746 | int from_tty, int enabled, | |
44f238bb | 13747 | int internal, unsigned flags) |
983af33b | 13748 | { |
023fa29b | 13749 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13750 | cond_string, extra_string, |
13751 | type_wanted, | |
983af33b SDJ |
13752 | disposition, thread, task, |
13753 | ignore_count, ops, from_tty, | |
44f238bb | 13754 | enabled, internal, flags); |
983af33b SDJ |
13755 | } |
13756 | ||
13757 | static void | |
13758 | tracepoint_decode_linespec (struct breakpoint *b, char **s, | |
13759 | struct symtabs_and_lines *sals) | |
13760 | { | |
13761 | decode_linespec_default (b, s, sals); | |
13762 | } | |
13763 | ||
2060206e | 13764 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13765 | |
55aa24fb SDJ |
13766 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13767 | static probe. */ | |
13768 | ||
13769 | static void | |
13770 | tracepoint_probe_create_sals_from_address (char **arg, | |
13771 | struct linespec_result *canonical, | |
13772 | enum bptype type_wanted, | |
13773 | char *addr_start, char **copy_arg) | |
13774 | { | |
13775 | /* We use the same method for breakpoint on probes. */ | |
13776 | bkpt_probe_create_sals_from_address (arg, canonical, type_wanted, | |
13777 | addr_start, copy_arg); | |
13778 | } | |
13779 | ||
13780 | static void | |
13781 | tracepoint_probe_decode_linespec (struct breakpoint *b, char **s, | |
13782 | struct symtabs_and_lines *sals) | |
13783 | { | |
13784 | /* We use the same method for breakpoint on probes. */ | |
13785 | bkpt_probe_decode_linespec (b, s, sals); | |
13786 | } | |
13787 | ||
13788 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13789 | ||
5c2b4418 HZ |
13790 | /* Dprintf breakpoint_ops methods. */ |
13791 | ||
13792 | static void | |
13793 | dprintf_re_set (struct breakpoint *b) | |
13794 | { | |
13795 | breakpoint_re_set_default (b); | |
13796 | ||
13797 | /* This breakpoint could have been pending, and be resolved now, and | |
13798 | if so, we should now have the extra string. If we don't, the | |
13799 | dprintf was malformed when created, but we couldn't tell because | |
13800 | we can't extract the extra string until the location is | |
13801 | resolved. */ | |
13802 | if (b->loc != NULL && b->extra_string == NULL) | |
13803 | error (_("Format string required")); | |
13804 | ||
13805 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13806 | 2 - create a dprintf, which resolves fine. | |
13807 | 3 - disconnect from target 1 | |
13808 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13809 | ||
13810 | After steps #3/#4, you'll want the dprintf command list to | |
13811 | be updated, because target 1 and 2 may well return different | |
13812 | answers for target_can_run_breakpoint_commands(). | |
13813 | Given absence of finer grained resetting, we get to do | |
13814 | it all the time. */ | |
13815 | if (b->extra_string != NULL) | |
13816 | update_dprintf_command_list (b); | |
13817 | } | |
13818 | ||
2d9442cc HZ |
13819 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13820 | ||
13821 | static void | |
13822 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13823 | { | |
13824 | fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string, | |
13825 | tp->extra_string); | |
13826 | print_recreate_thread (tp, fp); | |
13827 | } | |
13828 | ||
9d6e6e84 HZ |
13829 | /* Implement the "after_condition_true" breakpoint_ops method for |
13830 | dprintf. | |
13831 | ||
13832 | dprintf's are implemented with regular commands in their command | |
13833 | list, but we run the commands here instead of before presenting the | |
13834 | stop to the user, as dprintf's don't actually cause a stop. This | |
13835 | also makes it so that the commands of multiple dprintfs at the same | |
13836 | address are all handled. */ | |
13837 | ||
13838 | static void | |
13839 | dprintf_after_condition_true (struct bpstats *bs) | |
13840 | { | |
13841 | struct cleanup *old_chain; | |
13842 | struct bpstats tmp_bs = { NULL }; | |
13843 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13844 | ||
13845 | /* dprintf's never cause a stop. This wasn't set in the | |
13846 | check_status hook instead because that would make the dprintf's | |
13847 | condition not be evaluated. */ | |
13848 | bs->stop = 0; | |
13849 | ||
13850 | /* Run the command list here. Take ownership of it instead of | |
13851 | copying. We never want these commands to run later in | |
13852 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13853 | be set at same address as this dprintf, or even if running the | |
13854 | commands here throws. */ | |
13855 | tmp_bs.commands = bs->commands; | |
13856 | bs->commands = NULL; | |
13857 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13858 | ||
13859 | bpstat_do_actions_1 (&tmp_bs_p); | |
13860 | ||
13861 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13862 | bpstat_do_actions_1 may return early without processing the whole | |
13863 | list. */ | |
13864 | do_cleanups (old_chain); | |
13865 | } | |
13866 | ||
983af33b SDJ |
13867 | /* The breakpoint_ops structure to be used on static tracepoints with |
13868 | markers (`-m'). */ | |
13869 | ||
13870 | static void | |
13871 | strace_marker_create_sals_from_address (char **arg, | |
13872 | struct linespec_result *canonical, | |
13873 | enum bptype type_wanted, | |
13874 | char *addr_start, char **copy_arg) | |
13875 | { | |
13876 | struct linespec_sals lsal; | |
13877 | ||
13878 | lsal.sals = decode_static_tracepoint_spec (arg); | |
13879 | ||
13880 | *copy_arg = savestring (addr_start, *arg - addr_start); | |
13881 | ||
13882 | canonical->addr_string = xstrdup (*copy_arg); | |
13883 | lsal.canonical = xstrdup (*copy_arg); | |
13884 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
13885 | } | |
13886 | ||
13887 | static void | |
13888 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13889 | struct linespec_result *canonical, | |
983af33b | 13890 | char *cond_string, |
e7e0cddf | 13891 | char *extra_string, |
983af33b SDJ |
13892 | enum bptype type_wanted, |
13893 | enum bpdisp disposition, | |
13894 | int thread, | |
13895 | int task, int ignore_count, | |
13896 | const struct breakpoint_ops *ops, | |
13897 | int from_tty, int enabled, | |
44f238bb | 13898 | int internal, unsigned flags) |
983af33b SDJ |
13899 | { |
13900 | int i; | |
52d361e1 YQ |
13901 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13902 | canonical->sals, 0); | |
983af33b SDJ |
13903 | |
13904 | /* If the user is creating a static tracepoint by marker id | |
13905 | (strace -m MARKER_ID), then store the sals index, so that | |
13906 | breakpoint_re_set can try to match up which of the newly | |
13907 | found markers corresponds to this one, and, don't try to | |
13908 | expand multiple locations for each sal, given than SALS | |
13909 | already should contain all sals for MARKER_ID. */ | |
13910 | ||
13911 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13912 | { | |
13913 | struct symtabs_and_lines expanded; | |
13914 | struct tracepoint *tp; | |
13915 | struct cleanup *old_chain; | |
13916 | char *addr_string; | |
13917 | ||
13918 | expanded.nelts = 1; | |
13919 | expanded.sals = &lsal->sals.sals[i]; | |
13920 | ||
13921 | addr_string = xstrdup (canonical->addr_string); | |
13922 | old_chain = make_cleanup (xfree, addr_string); | |
13923 | ||
13924 | tp = XCNEW (struct tracepoint); | |
13925 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
13926 | addr_string, NULL, | |
e7e0cddf SS |
13927 | cond_string, extra_string, |
13928 | type_wanted, disposition, | |
983af33b | 13929 | thread, task, ignore_count, ops, |
44f238bb | 13930 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13931 | canonical->special_display); |
13932 | /* Given that its possible to have multiple markers with | |
13933 | the same string id, if the user is creating a static | |
13934 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13935 | store the sals index, so that breakpoint_re_set can | |
13936 | try to match up which of the newly found markers | |
13937 | corresponds to this one */ | |
13938 | tp->static_trace_marker_id_idx = i; | |
13939 | ||
13940 | install_breakpoint (internal, &tp->base, 0); | |
13941 | ||
13942 | discard_cleanups (old_chain); | |
13943 | } | |
13944 | } | |
13945 | ||
13946 | static void | |
13947 | strace_marker_decode_linespec (struct breakpoint *b, char **s, | |
13948 | struct symtabs_and_lines *sals) | |
13949 | { | |
13950 | struct tracepoint *tp = (struct tracepoint *) b; | |
13951 | ||
13952 | *sals = decode_static_tracepoint_spec (s); | |
13953 | if (sals->nelts > tp->static_trace_marker_id_idx) | |
13954 | { | |
13955 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13956 | sals->nelts = 1; | |
13957 | } | |
13958 | else | |
13959 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13960 | } | |
13961 | ||
13962 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13963 | ||
13964 | static int | |
13965 | strace_marker_p (struct breakpoint *b) | |
13966 | { | |
13967 | return b->ops == &strace_marker_breakpoint_ops; | |
13968 | } | |
13969 | ||
53a5351d | 13970 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13971 | structures. */ |
c906108c SS |
13972 | |
13973 | void | |
fba45db2 | 13974 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13975 | { |
52f0bd74 | 13976 | struct breakpoint *b; |
c906108c | 13977 | |
8a3fe4f8 | 13978 | gdb_assert (bpt != NULL); |
c906108c | 13979 | |
4a64f543 MS |
13980 | /* Has this bp already been deleted? This can happen because |
13981 | multiple lists can hold pointers to bp's. bpstat lists are | |
13982 | especial culprits. | |
13983 | ||
13984 | One example of this happening is a watchpoint's scope bp. When | |
13985 | the scope bp triggers, we notice that the watchpoint is out of | |
13986 | scope, and delete it. We also delete its scope bp. But the | |
13987 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13988 | That bpstat is then checked for auto-deleting bp's, which are | |
13989 | deleted. | |
13990 | ||
13991 | A real solution to this problem might involve reference counts in | |
13992 | bp's, and/or giving them pointers back to their referencing | |
13993 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13994 | storage when no more references were extent. A cheaper bandaid | |
13995 | was chosen. */ | |
c906108c SS |
13996 | if (bpt->type == bp_none) |
13997 | return; | |
13998 | ||
4a64f543 MS |
13999 | /* At least avoid this stale reference until the reference counting |
14000 | of breakpoints gets resolved. */ | |
d0fb5eae | 14001 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 14002 | { |
d0fb5eae | 14003 | struct breakpoint *related; |
3a5c3e22 | 14004 | struct watchpoint *w; |
d0fb5eae JK |
14005 | |
14006 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 14007 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 14008 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
14009 | w = (struct watchpoint *) bpt; |
14010 | else | |
14011 | w = NULL; | |
14012 | if (w != NULL) | |
14013 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
14014 | |
14015 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
14016 | for (related = bpt; related->related_breakpoint != bpt; | |
14017 | related = related->related_breakpoint); | |
14018 | related->related_breakpoint = bpt->related_breakpoint; | |
14019 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
14020 | } |
14021 | ||
a9634178 TJB |
14022 | /* watch_command_1 creates a watchpoint but only sets its number if |
14023 | update_watchpoint succeeds in creating its bp_locations. If there's | |
14024 | a problem in that process, we'll be asked to delete the half-created | |
14025 | watchpoint. In that case, don't announce the deletion. */ | |
14026 | if (bpt->number) | |
14027 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 14028 | |
c906108c SS |
14029 | if (breakpoint_chain == bpt) |
14030 | breakpoint_chain = bpt->next; | |
14031 | ||
c906108c SS |
14032 | ALL_BREAKPOINTS (b) |
14033 | if (b->next == bpt) | |
c5aa993b JM |
14034 | { |
14035 | b->next = bpt->next; | |
14036 | break; | |
14037 | } | |
c906108c | 14038 | |
f431efe5 PA |
14039 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
14040 | been freed. */ | |
14041 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 14042 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
14043 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
14044 | commands are associated with the bpstat; if we remove it here, | |
14045 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
14046 | event-top.c won't do anything, and temporary breakpoints with | |
14047 | commands won't work. */ | |
14048 | ||
14049 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
14050 | ||
4a64f543 MS |
14051 | /* Now that breakpoint is removed from breakpoint list, update the |
14052 | global location list. This will remove locations that used to | |
14053 | belong to this breakpoint. Do this before freeing the breakpoint | |
14054 | itself, since remove_breakpoint looks at location's owner. It | |
14055 | might be better design to have location completely | |
14056 | self-contained, but it's not the case now. */ | |
44702360 | 14057 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 14058 | |
348d480f | 14059 | bpt->ops->dtor (bpt); |
4a64f543 MS |
14060 | /* On the chance that someone will soon try again to delete this |
14061 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 14062 | bpt->type = bp_none; |
b8c9b27d | 14063 | xfree (bpt); |
c906108c SS |
14064 | } |
14065 | ||
4d6140d9 AC |
14066 | static void |
14067 | do_delete_breakpoint_cleanup (void *b) | |
14068 | { | |
14069 | delete_breakpoint (b); | |
14070 | } | |
14071 | ||
14072 | struct cleanup * | |
14073 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
14074 | { | |
14075 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
14076 | } | |
14077 | ||
51be5b68 PA |
14078 | /* Iterator function to call a user-provided callback function once |
14079 | for each of B and its related breakpoints. */ | |
14080 | ||
14081 | static void | |
14082 | iterate_over_related_breakpoints (struct breakpoint *b, | |
14083 | void (*function) (struct breakpoint *, | |
14084 | void *), | |
14085 | void *data) | |
14086 | { | |
14087 | struct breakpoint *related; | |
14088 | ||
14089 | related = b; | |
14090 | do | |
14091 | { | |
14092 | struct breakpoint *next; | |
14093 | ||
14094 | /* FUNCTION may delete RELATED. */ | |
14095 | next = related->related_breakpoint; | |
14096 | ||
14097 | if (next == related) | |
14098 | { | |
14099 | /* RELATED is the last ring entry. */ | |
14100 | function (related, data); | |
14101 | ||
14102 | /* FUNCTION may have deleted it, so we'd never reach back to | |
14103 | B. There's nothing left to do anyway, so just break | |
14104 | out. */ | |
14105 | break; | |
14106 | } | |
14107 | else | |
14108 | function (related, data); | |
14109 | ||
14110 | related = next; | |
14111 | } | |
14112 | while (related != b); | |
14113 | } | |
95a42b64 TT |
14114 | |
14115 | static void | |
14116 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
14117 | { | |
14118 | delete_breakpoint (b); | |
14119 | } | |
14120 | ||
51be5b68 PA |
14121 | /* A callback for map_breakpoint_numbers that calls |
14122 | delete_breakpoint. */ | |
14123 | ||
14124 | static void | |
14125 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
14126 | { | |
14127 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
14128 | } | |
14129 | ||
c906108c | 14130 | void |
fba45db2 | 14131 | delete_command (char *arg, int from_tty) |
c906108c | 14132 | { |
35df4500 | 14133 | struct breakpoint *b, *b_tmp; |
c906108c | 14134 | |
ea9365bb TT |
14135 | dont_repeat (); |
14136 | ||
c906108c SS |
14137 | if (arg == 0) |
14138 | { | |
14139 | int breaks_to_delete = 0; | |
14140 | ||
46c6471b PA |
14141 | /* Delete all breakpoints if no argument. Do not delete |
14142 | internal breakpoints, these have to be deleted with an | |
14143 | explicit breakpoint number argument. */ | |
c5aa993b | 14144 | ALL_BREAKPOINTS (b) |
46c6471b | 14145 | if (user_breakpoint_p (b)) |
973d738b DJ |
14146 | { |
14147 | breaks_to_delete = 1; | |
14148 | break; | |
14149 | } | |
c906108c SS |
14150 | |
14151 | /* Ask user only if there are some breakpoints to delete. */ | |
14152 | if (!from_tty | |
e2e0b3e5 | 14153 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 14154 | { |
35df4500 | 14155 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14156 | if (user_breakpoint_p (b)) |
c5aa993b | 14157 | delete_breakpoint (b); |
c906108c SS |
14158 | } |
14159 | } | |
14160 | else | |
51be5b68 | 14161 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
14162 | } |
14163 | ||
0d381245 VP |
14164 | static int |
14165 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 14166 | { |
0d381245 | 14167 | for (; loc; loc = loc->next) |
8645ff69 UW |
14168 | if (!loc->shlib_disabled |
14169 | && !loc->pspace->executing_startup) | |
0d381245 VP |
14170 | return 0; |
14171 | return 1; | |
fe3f5fa8 VP |
14172 | } |
14173 | ||
776592bf DE |
14174 | /* Subroutine of update_breakpoint_locations to simplify it. |
14175 | Return non-zero if multiple fns in list LOC have the same name. | |
14176 | Null names are ignored. */ | |
14177 | ||
14178 | static int | |
14179 | ambiguous_names_p (struct bp_location *loc) | |
14180 | { | |
14181 | struct bp_location *l; | |
14182 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
14183 | (int (*) (const void *, |
14184 | const void *)) streq, | |
776592bf DE |
14185 | NULL, xcalloc, xfree); |
14186 | ||
14187 | for (l = loc; l != NULL; l = l->next) | |
14188 | { | |
14189 | const char **slot; | |
14190 | const char *name = l->function_name; | |
14191 | ||
14192 | /* Allow for some names to be NULL, ignore them. */ | |
14193 | if (name == NULL) | |
14194 | continue; | |
14195 | ||
14196 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
14197 | INSERT); | |
4a64f543 MS |
14198 | /* NOTE: We can assume slot != NULL here because xcalloc never |
14199 | returns NULL. */ | |
776592bf DE |
14200 | if (*slot != NULL) |
14201 | { | |
14202 | htab_delete (htab); | |
14203 | return 1; | |
14204 | } | |
14205 | *slot = name; | |
14206 | } | |
14207 | ||
14208 | htab_delete (htab); | |
14209 | return 0; | |
14210 | } | |
14211 | ||
0fb4aa4b PA |
14212 | /* When symbols change, it probably means the sources changed as well, |
14213 | and it might mean the static tracepoint markers are no longer at | |
14214 | the same address or line numbers they used to be at last we | |
14215 | checked. Losing your static tracepoints whenever you rebuild is | |
14216 | undesirable. This function tries to resync/rematch gdb static | |
14217 | tracepoints with the markers on the target, for static tracepoints | |
14218 | that have not been set by marker id. Static tracepoint that have | |
14219 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14220 | The heuristic is: | |
14221 | ||
14222 | 1) For a tracepoint set at a specific address, look for a marker at | |
14223 | the old PC. If one is found there, assume to be the same marker. | |
14224 | If the name / string id of the marker found is different from the | |
14225 | previous known name, assume that means the user renamed the marker | |
14226 | in the sources, and output a warning. | |
14227 | ||
14228 | 2) For a tracepoint set at a given line number, look for a marker | |
14229 | at the new address of the old line number. If one is found there, | |
14230 | assume to be the same marker. If the name / string id of the | |
14231 | marker found is different from the previous known name, assume that | |
14232 | means the user renamed the marker in the sources, and output a | |
14233 | warning. | |
14234 | ||
14235 | 3) If a marker is no longer found at the same address or line, it | |
14236 | may mean the marker no longer exists. But it may also just mean | |
14237 | the code changed a bit. Maybe the user added a few lines of code | |
14238 | that made the marker move up or down (in line number terms). Ask | |
14239 | the target for info about the marker with the string id as we knew | |
14240 | it. If found, update line number and address in the matching | |
14241 | static tracepoint. This will get confused if there's more than one | |
14242 | marker with the same ID (possible in UST, although unadvised | |
14243 | precisely because it confuses tools). */ | |
14244 | ||
14245 | static struct symtab_and_line | |
14246 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14247 | { | |
d9b3f62e | 14248 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14249 | struct static_tracepoint_marker marker; |
14250 | CORE_ADDR pc; | |
0fb4aa4b PA |
14251 | |
14252 | pc = sal.pc; | |
14253 | if (sal.line) | |
14254 | find_line_pc (sal.symtab, sal.line, &pc); | |
14255 | ||
14256 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14257 | { | |
d9b3f62e | 14258 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14259 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14260 | b->number, | |
d9b3f62e | 14261 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14262 | |
d9b3f62e PA |
14263 | xfree (tp->static_trace_marker_id); |
14264 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14265 | release_static_tracepoint_marker (&marker); |
14266 | ||
14267 | return sal; | |
14268 | } | |
14269 | ||
14270 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14271 | by string ID. */ | |
14272 | if (!sal.explicit_pc | |
14273 | && sal.line != 0 | |
14274 | && sal.symtab != NULL | |
d9b3f62e | 14275 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14276 | { |
14277 | VEC(static_tracepoint_marker_p) *markers; | |
14278 | ||
14279 | markers | |
d9b3f62e | 14280 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14281 | |
14282 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14283 | { | |
80e1d417 | 14284 | struct symtab_and_line sal2; |
0fb4aa4b | 14285 | struct symbol *sym; |
80e1d417 | 14286 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14287 | struct ui_out *uiout = current_uiout; |
0fb4aa4b | 14288 | |
80e1d417 | 14289 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14290 | |
d9b3f62e | 14291 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14292 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14293 | |
14294 | warning (_("marker for static tracepoint %d (%s) not " | |
14295 | "found at previous line number"), | |
d9b3f62e | 14296 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14297 | |
80e1d417 | 14298 | init_sal (&sal2); |
0fb4aa4b | 14299 | |
80e1d417 | 14300 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14301 | |
80e1d417 AS |
14302 | sal2 = find_pc_line (tpmarker->address, 0); |
14303 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14304 | ui_out_text (uiout, "Now in "); |
14305 | if (sym) | |
14306 | { | |
14307 | ui_out_field_string (uiout, "func", | |
14308 | SYMBOL_PRINT_NAME (sym)); | |
14309 | ui_out_text (uiout, " at "); | |
14310 | } | |
05cba821 JK |
14311 | ui_out_field_string (uiout, "file", |
14312 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14313 | ui_out_text (uiout, ":"); |
14314 | ||
14315 | if (ui_out_is_mi_like_p (uiout)) | |
14316 | { | |
0b0865da | 14317 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14318 | |
f35a17b5 | 14319 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14320 | } |
14321 | ||
80e1d417 | 14322 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14323 | ui_out_text (uiout, "\n"); |
14324 | ||
80e1d417 | 14325 | b->loc->line_number = sal2.line; |
2f202fde | 14326 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b PA |
14327 | |
14328 | xfree (b->addr_string); | |
14329 | b->addr_string = xstrprintf ("%s:%d", | |
05cba821 | 14330 | symtab_to_filename_for_display (sal2.symtab), |
f8eba3c6 | 14331 | b->loc->line_number); |
0fb4aa4b PA |
14332 | |
14333 | /* Might be nice to check if function changed, and warn if | |
14334 | so. */ | |
14335 | ||
80e1d417 | 14336 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14337 | } |
14338 | } | |
14339 | return sal; | |
14340 | } | |
14341 | ||
8d3788bd VP |
14342 | /* Returns 1 iff locations A and B are sufficiently same that |
14343 | we don't need to report breakpoint as changed. */ | |
14344 | ||
14345 | static int | |
14346 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14347 | { | |
14348 | while (a && b) | |
14349 | { | |
14350 | if (a->address != b->address) | |
14351 | return 0; | |
14352 | ||
14353 | if (a->shlib_disabled != b->shlib_disabled) | |
14354 | return 0; | |
14355 | ||
14356 | if (a->enabled != b->enabled) | |
14357 | return 0; | |
14358 | ||
14359 | a = a->next; | |
14360 | b = b->next; | |
14361 | } | |
14362 | ||
14363 | if ((a == NULL) != (b == NULL)) | |
14364 | return 0; | |
14365 | ||
14366 | return 1; | |
14367 | } | |
14368 | ||
f1310107 TJB |
14369 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
14370 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
14371 | a ranged breakpoint. */ | |
14372 | ||
0e30163f | 14373 | void |
0d381245 | 14374 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
14375 | struct symtabs_and_lines sals, |
14376 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14377 | { |
14378 | int i; | |
0d381245 VP |
14379 | struct bp_location *existing_locations = b->loc; |
14380 | ||
f8eba3c6 TT |
14381 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14382 | { | |
14383 | /* Ranged breakpoints have only one start location and one end | |
14384 | location. */ | |
14385 | b->enable_state = bp_disabled; | |
44702360 | 14386 | update_global_location_list (UGLL_MAY_INSERT); |
f8eba3c6 TT |
14387 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14388 | "multiple locations found\n"), | |
14389 | b->number); | |
14390 | return; | |
14391 | } | |
f1310107 | 14392 | |
4a64f543 MS |
14393 | /* If there's no new locations, and all existing locations are |
14394 | pending, don't do anything. This optimizes the common case where | |
14395 | all locations are in the same shared library, that was unloaded. | |
14396 | We'd like to retain the location, so that when the library is | |
14397 | loaded again, we don't loose the enabled/disabled status of the | |
14398 | individual locations. */ | |
0d381245 | 14399 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
14400 | return; |
14401 | ||
fe3f5fa8 VP |
14402 | b->loc = NULL; |
14403 | ||
0d381245 | 14404 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14405 | { |
f8eba3c6 TT |
14406 | struct bp_location *new_loc; |
14407 | ||
14408 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14409 | ||
14410 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14411 | |
0d381245 VP |
14412 | /* Reparse conditions, they might contain references to the |
14413 | old symtab. */ | |
14414 | if (b->cond_string != NULL) | |
14415 | { | |
bbc13ae3 | 14416 | const char *s; |
bfd189b1 | 14417 | volatile struct gdb_exception e; |
fe3f5fa8 | 14418 | |
0d381245 VP |
14419 | s = b->cond_string; |
14420 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14421 | { | |
1bb9788d TT |
14422 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14423 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14424 | 0); |
14425 | } | |
14426 | if (e.reason < 0) | |
14427 | { | |
3e43a32a MS |
14428 | warning (_("failed to reevaluate condition " |
14429 | "for breakpoint %d: %s"), | |
0d381245 VP |
14430 | b->number, e.message); |
14431 | new_loc->enabled = 0; | |
14432 | } | |
14433 | } | |
fe3f5fa8 | 14434 | |
f1310107 TJB |
14435 | if (sals_end.nelts) |
14436 | { | |
14437 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14438 | ||
14439 | new_loc->length = end - sals.sals[0].pc + 1; | |
14440 | } | |
0d381245 | 14441 | } |
fe3f5fa8 | 14442 | |
4a64f543 MS |
14443 | /* If possible, carry over 'disable' status from existing |
14444 | breakpoints. */ | |
0d381245 VP |
14445 | { |
14446 | struct bp_location *e = existing_locations; | |
776592bf DE |
14447 | /* If there are multiple breakpoints with the same function name, |
14448 | e.g. for inline functions, comparing function names won't work. | |
14449 | Instead compare pc addresses; this is just a heuristic as things | |
14450 | may have moved, but in practice it gives the correct answer | |
14451 | often enough until a better solution is found. */ | |
14452 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14453 | ||
0d381245 VP |
14454 | for (; e; e = e->next) |
14455 | { | |
14456 | if (!e->enabled && e->function_name) | |
14457 | { | |
14458 | struct bp_location *l = b->loc; | |
776592bf DE |
14459 | if (have_ambiguous_names) |
14460 | { | |
14461 | for (; l; l = l->next) | |
f1310107 | 14462 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14463 | { |
14464 | l->enabled = 0; | |
14465 | break; | |
14466 | } | |
14467 | } | |
14468 | else | |
14469 | { | |
14470 | for (; l; l = l->next) | |
14471 | if (l->function_name | |
14472 | && strcmp (e->function_name, l->function_name) == 0) | |
14473 | { | |
14474 | l->enabled = 0; | |
14475 | break; | |
14476 | } | |
14477 | } | |
0d381245 VP |
14478 | } |
14479 | } | |
14480 | } | |
fe3f5fa8 | 14481 | |
8d3788bd VP |
14482 | if (!locations_are_equal (existing_locations, b->loc)) |
14483 | observer_notify_breakpoint_modified (b); | |
14484 | ||
44702360 | 14485 | update_global_location_list (UGLL_MAY_INSERT); |
fe3f5fa8 VP |
14486 | } |
14487 | ||
ef23e705 TJB |
14488 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
14489 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
14490 | ||
14491 | static struct symtabs_and_lines | |
14492 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
14493 | { | |
14494 | char *s; | |
02d20e4a | 14495 | struct symtabs_and_lines sals = {0}; |
f8eba3c6 | 14496 | volatile struct gdb_exception e; |
ef23e705 | 14497 | |
983af33b | 14498 | gdb_assert (b->ops != NULL); |
ef23e705 | 14499 | s = addr_string; |
ef23e705 TJB |
14500 | |
14501 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
14502 | { | |
983af33b | 14503 | b->ops->decode_linespec (b, &s, &sals); |
ef23e705 TJB |
14504 | } |
14505 | if (e.reason < 0) | |
14506 | { | |
14507 | int not_found_and_ok = 0; | |
14508 | /* For pending breakpoints, it's expected that parsing will | |
14509 | fail until the right shared library is loaded. User has | |
14510 | already told to create pending breakpoints and don't need | |
14511 | extra messages. If breakpoint is in bp_shlib_disabled | |
14512 | state, then user already saw the message about that | |
14513 | breakpoint being disabled, and don't want to see more | |
14514 | errors. */ | |
58438ac1 | 14515 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
14516 | && (b->condition_not_parsed |
14517 | || (b->loc && b->loc->shlib_disabled) | |
f8eba3c6 | 14518 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14519 | || b->enable_state == bp_disabled)) |
14520 | not_found_and_ok = 1; | |
14521 | ||
14522 | if (!not_found_and_ok) | |
14523 | { | |
14524 | /* We surely don't want to warn about the same breakpoint | |
14525 | 10 times. One solution, implemented here, is disable | |
14526 | the breakpoint on error. Another solution would be to | |
14527 | have separate 'warning emitted' flag. Since this | |
14528 | happens only when a binary has changed, I don't know | |
14529 | which approach is better. */ | |
14530 | b->enable_state = bp_disabled; | |
14531 | throw_exception (e); | |
14532 | } | |
14533 | } | |
14534 | ||
58438ac1 | 14535 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 | 14536 | { |
f8eba3c6 | 14537 | int i; |
ef23e705 | 14538 | |
f8eba3c6 TT |
14539 | for (i = 0; i < sals.nelts; ++i) |
14540 | resolve_sal_pc (&sals.sals[i]); | |
ef23e705 TJB |
14541 | if (b->condition_not_parsed && s && s[0]) |
14542 | { | |
ed1d1739 KS |
14543 | char *cond_string, *extra_string; |
14544 | int thread, task; | |
ef23e705 TJB |
14545 | |
14546 | find_condition_and_thread (s, sals.sals[0].pc, | |
e7e0cddf SS |
14547 | &cond_string, &thread, &task, |
14548 | &extra_string); | |
ef23e705 TJB |
14549 | if (cond_string) |
14550 | b->cond_string = cond_string; | |
14551 | b->thread = thread; | |
14552 | b->task = task; | |
e7e0cddf SS |
14553 | if (extra_string) |
14554 | b->extra_string = extra_string; | |
ef23e705 TJB |
14555 | b->condition_not_parsed = 0; |
14556 | } | |
14557 | ||
983af33b | 14558 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14559 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14560 | |
58438ac1 TT |
14561 | *found = 1; |
14562 | } | |
14563 | else | |
14564 | *found = 0; | |
ef23e705 TJB |
14565 | |
14566 | return sals; | |
14567 | } | |
14568 | ||
348d480f PA |
14569 | /* The default re_set method, for typical hardware or software |
14570 | breakpoints. Reevaluate the breakpoint and recreate its | |
14571 | locations. */ | |
14572 | ||
14573 | static void | |
28010a5d | 14574 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14575 | { |
14576 | int found; | |
f1310107 | 14577 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14578 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14579 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
14580 | |
14581 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
14582 | if (found) | |
14583 | { | |
14584 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14585 | expanded = sals; |
ef23e705 TJB |
14586 | } |
14587 | ||
f1310107 TJB |
14588 | if (b->addr_string_range_end) |
14589 | { | |
14590 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
14591 | if (found) | |
14592 | { | |
14593 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14594 | expanded_end = sals_end; |
f1310107 TJB |
14595 | } |
14596 | } | |
14597 | ||
14598 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
14599 | } |
14600 | ||
983af33b SDJ |
14601 | /* Default method for creating SALs from an address string. It basically |
14602 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14603 | ||
14604 | static void | |
14605 | create_sals_from_address_default (char **arg, | |
14606 | struct linespec_result *canonical, | |
14607 | enum bptype type_wanted, | |
14608 | char *addr_start, char **copy_arg) | |
14609 | { | |
14610 | parse_breakpoint_sals (arg, canonical); | |
14611 | } | |
14612 | ||
14613 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14614 | function for the `create_breakpoints_sal' method of | |
14615 | breakpoint_ops. */ | |
14616 | ||
14617 | static void | |
14618 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14619 | struct linespec_result *canonical, | |
983af33b | 14620 | char *cond_string, |
e7e0cddf | 14621 | char *extra_string, |
983af33b SDJ |
14622 | enum bptype type_wanted, |
14623 | enum bpdisp disposition, | |
14624 | int thread, | |
14625 | int task, int ignore_count, | |
14626 | const struct breakpoint_ops *ops, | |
14627 | int from_tty, int enabled, | |
44f238bb | 14628 | int internal, unsigned flags) |
983af33b SDJ |
14629 | { |
14630 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14631 | extra_string, |
983af33b SDJ |
14632 | type_wanted, disposition, |
14633 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14634 | enabled, internal, flags); |
983af33b SDJ |
14635 | } |
14636 | ||
14637 | /* Decode the line represented by S by calling decode_line_full. This is the | |
14638 | default function for the `decode_linespec' method of breakpoint_ops. */ | |
14639 | ||
14640 | static void | |
14641 | decode_linespec_default (struct breakpoint *b, char **s, | |
14642 | struct symtabs_and_lines *sals) | |
14643 | { | |
14644 | struct linespec_result canonical; | |
14645 | ||
14646 | init_linespec_result (&canonical); | |
14647 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, | |
14648 | (struct symtab *) NULL, 0, | |
14649 | &canonical, multiple_symbols_all, | |
14650 | b->filter); | |
14651 | ||
14652 | /* We should get 0 or 1 resulting SALs. */ | |
14653 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14654 | ||
14655 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14656 | { | |
14657 | struct linespec_sals *lsal; | |
14658 | ||
14659 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14660 | *sals = lsal->sals; | |
14661 | /* Arrange it so the destructor does not free the | |
14662 | contents. */ | |
14663 | lsal->sals.sals = NULL; | |
14664 | } | |
14665 | ||
14666 | destroy_linespec_result (&canonical); | |
14667 | } | |
14668 | ||
28010a5d PA |
14669 | /* Prepare the global context for a re-set of breakpoint B. */ |
14670 | ||
14671 | static struct cleanup * | |
14672 | prepare_re_set_context (struct breakpoint *b) | |
14673 | { | |
14674 | struct cleanup *cleanups; | |
14675 | ||
14676 | input_radix = b->input_radix; | |
14677 | cleanups = save_current_space_and_thread (); | |
f8eba3c6 TT |
14678 | if (b->pspace != NULL) |
14679 | switch_to_program_space_and_thread (b->pspace); | |
28010a5d PA |
14680 | set_language (b->language); |
14681 | ||
14682 | return cleanups; | |
ef23e705 TJB |
14683 | } |
14684 | ||
c906108c SS |
14685 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14686 | The value we return ends up being the return value from catch_errors. | |
14687 | Unused in this case. */ | |
14688 | ||
14689 | static int | |
4efb68b1 | 14690 | breakpoint_re_set_one (void *bint) |
c906108c | 14691 | { |
4a64f543 | 14692 | /* Get past catch_errs. */ |
53a5351d | 14693 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14694 | struct cleanup *cleanups; |
c906108c | 14695 | |
348d480f PA |
14696 | cleanups = prepare_re_set_context (b); |
14697 | b->ops->re_set (b); | |
14698 | do_cleanups (cleanups); | |
c906108c SS |
14699 | return 0; |
14700 | } | |
14701 | ||
69de3c6a | 14702 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 14703 | void |
69de3c6a | 14704 | breakpoint_re_set (void) |
c906108c | 14705 | { |
35df4500 | 14706 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14707 | enum language save_language; |
14708 | int save_input_radix; | |
6c95b8df | 14709 | struct cleanup *old_chain; |
c5aa993b | 14710 | |
c906108c SS |
14711 | save_language = current_language->la_language; |
14712 | save_input_radix = input_radix; | |
6c95b8df PA |
14713 | old_chain = save_current_program_space (); |
14714 | ||
35df4500 | 14715 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14716 | { |
4a64f543 | 14717 | /* Format possible error msg. */ |
fe3f5fa8 | 14718 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14719 | b->number); |
14720 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14721 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14722 | do_cleanups (cleanups); |
c5aa993b | 14723 | } |
c906108c SS |
14724 | set_language (save_language); |
14725 | input_radix = save_input_radix; | |
e62c965a | 14726 | |
0756c555 | 14727 | jit_breakpoint_re_set (); |
4efc6507 | 14728 | |
6c95b8df PA |
14729 | do_cleanups (old_chain); |
14730 | ||
af02033e PP |
14731 | create_overlay_event_breakpoint (); |
14732 | create_longjmp_master_breakpoint (); | |
14733 | create_std_terminate_master_breakpoint (); | |
186c406b | 14734 | create_exception_master_breakpoint (); |
c906108c SS |
14735 | } |
14736 | \f | |
c906108c SS |
14737 | /* Reset the thread number of this breakpoint: |
14738 | ||
14739 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14740 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14741 | void |
fba45db2 | 14742 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14743 | { |
14744 | if (b->thread != -1) | |
14745 | { | |
39f77062 KB |
14746 | if (in_thread_list (inferior_ptid)) |
14747 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
14748 | |
14749 | /* We're being called after following a fork. The new fork is | |
14750 | selected as current, and unless this was a vfork will have a | |
14751 | different program space from the original thread. Reset that | |
14752 | as well. */ | |
14753 | b->loc->pspace = current_program_space; | |
c906108c SS |
14754 | } |
14755 | } | |
14756 | ||
03ac34d5 MS |
14757 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14758 | If from_tty is nonzero, it prints a message to that effect, | |
14759 | which ends with a period (no newline). */ | |
14760 | ||
c906108c | 14761 | void |
fba45db2 | 14762 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14763 | { |
52f0bd74 | 14764 | struct breakpoint *b; |
c906108c SS |
14765 | |
14766 | if (count < 0) | |
14767 | count = 0; | |
14768 | ||
14769 | ALL_BREAKPOINTS (b) | |
14770 | if (b->number == bptnum) | |
c5aa993b | 14771 | { |
d77f58be SS |
14772 | if (is_tracepoint (b)) |
14773 | { | |
14774 | if (from_tty && count != 0) | |
14775 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14776 | bptnum); | |
14777 | return; | |
14778 | } | |
14779 | ||
c5aa993b | 14780 | b->ignore_count = count; |
221ea385 KS |
14781 | if (from_tty) |
14782 | { | |
14783 | if (count == 0) | |
3e43a32a MS |
14784 | printf_filtered (_("Will stop next time " |
14785 | "breakpoint %d is reached."), | |
221ea385 KS |
14786 | bptnum); |
14787 | else if (count == 1) | |
a3f17187 | 14788 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14789 | bptnum); |
14790 | else | |
3e43a32a MS |
14791 | printf_filtered (_("Will ignore next %d " |
14792 | "crossings of breakpoint %d."), | |
221ea385 KS |
14793 | count, bptnum); |
14794 | } | |
8d3788bd | 14795 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14796 | return; |
14797 | } | |
c906108c | 14798 | |
8a3fe4f8 | 14799 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14800 | } |
14801 | ||
c906108c SS |
14802 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14803 | ||
14804 | static void | |
fba45db2 | 14805 | ignore_command (char *args, int from_tty) |
c906108c SS |
14806 | { |
14807 | char *p = args; | |
52f0bd74 | 14808 | int num; |
c906108c SS |
14809 | |
14810 | if (p == 0) | |
e2e0b3e5 | 14811 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14812 | |
c906108c | 14813 | num = get_number (&p); |
5c44784c | 14814 | if (num == 0) |
8a3fe4f8 | 14815 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14816 | if (*p == 0) |
8a3fe4f8 | 14817 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14818 | |
14819 | set_ignore_count (num, | |
14820 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14821 | from_tty); | |
221ea385 KS |
14822 | if (from_tty) |
14823 | printf_filtered ("\n"); | |
c906108c SS |
14824 | } |
14825 | \f | |
14826 | /* Call FUNCTION on each of the breakpoints | |
14827 | whose numbers are given in ARGS. */ | |
14828 | ||
14829 | static void | |
95a42b64 TT |
14830 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14831 | void *), | |
14832 | void *data) | |
c906108c | 14833 | { |
52f0bd74 AC |
14834 | int num; |
14835 | struct breakpoint *b, *tmp; | |
11cf8741 | 14836 | int match; |
197f0a60 | 14837 | struct get_number_or_range_state state; |
c906108c | 14838 | |
197f0a60 | 14839 | if (args == 0) |
e2e0b3e5 | 14840 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14841 | |
197f0a60 TT |
14842 | init_number_or_range (&state, args); |
14843 | ||
14844 | while (!state.finished) | |
c906108c | 14845 | { |
e799154c | 14846 | const char *p = state.string; |
197f0a60 | 14847 | |
11cf8741 | 14848 | match = 0; |
c5aa993b | 14849 | |
197f0a60 | 14850 | num = get_number_or_range (&state); |
5c44784c | 14851 | if (num == 0) |
c5aa993b | 14852 | { |
8a3fe4f8 | 14853 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14854 | } |
14855 | else | |
14856 | { | |
14857 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14858 | if (b->number == num) | |
14859 | { | |
11cf8741 | 14860 | match = 1; |
cdac0397 | 14861 | function (b, data); |
11cf8741 | 14862 | break; |
5c44784c | 14863 | } |
11cf8741 | 14864 | if (match == 0) |
a3f17187 | 14865 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14866 | } |
c906108c SS |
14867 | } |
14868 | } | |
14869 | ||
0d381245 VP |
14870 | static struct bp_location * |
14871 | find_location_by_number (char *number) | |
14872 | { | |
14873 | char *dot = strchr (number, '.'); | |
14874 | char *p1; | |
14875 | int bp_num; | |
14876 | int loc_num; | |
14877 | struct breakpoint *b; | |
14878 | struct bp_location *loc; | |
14879 | ||
14880 | *dot = '\0'; | |
14881 | ||
14882 | p1 = number; | |
197f0a60 | 14883 | bp_num = get_number (&p1); |
0d381245 VP |
14884 | if (bp_num == 0) |
14885 | error (_("Bad breakpoint number '%s'"), number); | |
14886 | ||
14887 | ALL_BREAKPOINTS (b) | |
14888 | if (b->number == bp_num) | |
14889 | { | |
14890 | break; | |
14891 | } | |
14892 | ||
14893 | if (!b || b->number != bp_num) | |
14894 | error (_("Bad breakpoint number '%s'"), number); | |
14895 | ||
14896 | p1 = dot+1; | |
197f0a60 | 14897 | loc_num = get_number (&p1); |
0d381245 VP |
14898 | if (loc_num == 0) |
14899 | error (_("Bad breakpoint location number '%s'"), number); | |
14900 | ||
14901 | --loc_num; | |
14902 | loc = b->loc; | |
14903 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14904 | ; | |
14905 | if (!loc) | |
14906 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14907 | ||
14908 | return loc; | |
14909 | } | |
14910 | ||
14911 | ||
1900040c MS |
14912 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14913 | If from_tty is nonzero, it prints a message to that effect, | |
14914 | which ends with a period (no newline). */ | |
14915 | ||
c906108c | 14916 | void |
fba45db2 | 14917 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14918 | { |
14919 | /* Never disable a watchpoint scope breakpoint; we want to | |
14920 | hit them when we leave scope so we can delete both the | |
14921 | watchpoint and its scope breakpoint at that time. */ | |
14922 | if (bpt->type == bp_watchpoint_scope) | |
14923 | return; | |
14924 | ||
b5de0fa7 | 14925 | bpt->enable_state = bp_disabled; |
c906108c | 14926 | |
b775012e LM |
14927 | /* Mark breakpoint locations modified. */ |
14928 | mark_breakpoint_modified (bpt); | |
14929 | ||
d248b706 KY |
14930 | if (target_supports_enable_disable_tracepoint () |
14931 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14932 | { | |
14933 | struct bp_location *location; | |
14934 | ||
14935 | for (location = bpt->loc; location; location = location->next) | |
14936 | target_disable_tracepoint (location); | |
14937 | } | |
14938 | ||
44702360 | 14939 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14940 | |
8d3788bd | 14941 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14942 | } |
14943 | ||
51be5b68 PA |
14944 | /* A callback for iterate_over_related_breakpoints. */ |
14945 | ||
14946 | static void | |
14947 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14948 | { | |
14949 | disable_breakpoint (b); | |
14950 | } | |
14951 | ||
95a42b64 TT |
14952 | /* A callback for map_breakpoint_numbers that calls |
14953 | disable_breakpoint. */ | |
14954 | ||
14955 | static void | |
14956 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14957 | { | |
51be5b68 | 14958 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14959 | } |
14960 | ||
c906108c | 14961 | static void |
fba45db2 | 14962 | disable_command (char *args, int from_tty) |
c906108c | 14963 | { |
c906108c | 14964 | if (args == 0) |
46c6471b PA |
14965 | { |
14966 | struct breakpoint *bpt; | |
14967 | ||
14968 | ALL_BREAKPOINTS (bpt) | |
14969 | if (user_breakpoint_p (bpt)) | |
14970 | disable_breakpoint (bpt); | |
14971 | } | |
9eaabc75 | 14972 | else |
0d381245 | 14973 | { |
9eaabc75 MW |
14974 | char *num = extract_arg (&args); |
14975 | ||
14976 | while (num) | |
d248b706 | 14977 | { |
9eaabc75 | 14978 | if (strchr (num, '.')) |
b775012e | 14979 | { |
9eaabc75 MW |
14980 | struct bp_location *loc = find_location_by_number (num); |
14981 | ||
14982 | if (loc) | |
14983 | { | |
14984 | if (loc->enabled) | |
14985 | { | |
14986 | loc->enabled = 0; | |
14987 | mark_breakpoint_location_modified (loc); | |
14988 | } | |
14989 | if (target_supports_enable_disable_tracepoint () | |
14990 | && current_trace_status ()->running && loc->owner | |
14991 | && is_tracepoint (loc->owner)) | |
14992 | target_disable_tracepoint (loc); | |
14993 | } | |
44702360 | 14994 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14995 | } |
9eaabc75 MW |
14996 | else |
14997 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14998 | num = extract_arg (&args); | |
d248b706 | 14999 | } |
0d381245 | 15000 | } |
c906108c SS |
15001 | } |
15002 | ||
15003 | static void | |
816338b5 SS |
15004 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
15005 | int count) | |
c906108c | 15006 | { |
afe38095 | 15007 | int target_resources_ok; |
c906108c SS |
15008 | |
15009 | if (bpt->type == bp_hardware_breakpoint) | |
15010 | { | |
15011 | int i; | |
c5aa993b | 15012 | i = hw_breakpoint_used_count (); |
53a5351d | 15013 | target_resources_ok = |
d92524f1 | 15014 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 15015 | i + 1, 0); |
c906108c | 15016 | if (target_resources_ok == 0) |
8a3fe4f8 | 15017 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 15018 | else if (target_resources_ok < 0) |
8a3fe4f8 | 15019 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
15020 | } |
15021 | ||
cc60f2e3 | 15022 | if (is_watchpoint (bpt)) |
c906108c | 15023 | { |
d07205c2 JK |
15024 | /* Initialize it just to avoid a GCC false warning. */ |
15025 | enum enable_state orig_enable_state = 0; | |
bfd189b1 | 15026 | volatile struct gdb_exception e; |
dde02812 ES |
15027 | |
15028 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 15029 | { |
3a5c3e22 PA |
15030 | struct watchpoint *w = (struct watchpoint *) bpt; |
15031 | ||
1e718ff1 TJB |
15032 | orig_enable_state = bpt->enable_state; |
15033 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 15034 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 15035 | } |
dde02812 | 15036 | if (e.reason < 0) |
c5aa993b | 15037 | { |
1e718ff1 | 15038 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
15039 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
15040 | bpt->number); | |
15041 | return; | |
c5aa993b | 15042 | } |
c906108c | 15043 | } |
0101ce28 | 15044 | |
b775012e LM |
15045 | bpt->enable_state = bp_enabled; |
15046 | ||
15047 | /* Mark breakpoint locations modified. */ | |
15048 | mark_breakpoint_modified (bpt); | |
15049 | ||
d248b706 KY |
15050 | if (target_supports_enable_disable_tracepoint () |
15051 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
15052 | { | |
15053 | struct bp_location *location; | |
15054 | ||
15055 | for (location = bpt->loc; location; location = location->next) | |
15056 | target_enable_tracepoint (location); | |
15057 | } | |
15058 | ||
b4c291bb | 15059 | bpt->disposition = disposition; |
816338b5 | 15060 | bpt->enable_count = count; |
44702360 | 15061 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 15062 | |
8d3788bd | 15063 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
15064 | } |
15065 | ||
fe3f5fa8 | 15066 | |
c906108c | 15067 | void |
fba45db2 | 15068 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 15069 | { |
816338b5 | 15070 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
15071 | } |
15072 | ||
15073 | static void | |
15074 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
15075 | { | |
15076 | enable_breakpoint (bpt); | |
c906108c SS |
15077 | } |
15078 | ||
95a42b64 TT |
15079 | /* A callback for map_breakpoint_numbers that calls |
15080 | enable_breakpoint. */ | |
15081 | ||
15082 | static void | |
15083 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
15084 | { | |
51be5b68 | 15085 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
15086 | } |
15087 | ||
c906108c SS |
15088 | /* The enable command enables the specified breakpoints (or all defined |
15089 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 15090 | in stopping the inferior. */ |
c906108c | 15091 | |
c906108c | 15092 | static void |
fba45db2 | 15093 | enable_command (char *args, int from_tty) |
c906108c | 15094 | { |
c906108c | 15095 | if (args == 0) |
46c6471b PA |
15096 | { |
15097 | struct breakpoint *bpt; | |
15098 | ||
15099 | ALL_BREAKPOINTS (bpt) | |
15100 | if (user_breakpoint_p (bpt)) | |
15101 | enable_breakpoint (bpt); | |
15102 | } | |
9eaabc75 | 15103 | else |
0d381245 | 15104 | { |
9eaabc75 MW |
15105 | char *num = extract_arg (&args); |
15106 | ||
15107 | while (num) | |
d248b706 | 15108 | { |
9eaabc75 | 15109 | if (strchr (num, '.')) |
b775012e | 15110 | { |
9eaabc75 MW |
15111 | struct bp_location *loc = find_location_by_number (num); |
15112 | ||
15113 | if (loc) | |
15114 | { | |
15115 | if (!loc->enabled) | |
15116 | { | |
15117 | loc->enabled = 1; | |
15118 | mark_breakpoint_location_modified (loc); | |
15119 | } | |
15120 | if (target_supports_enable_disable_tracepoint () | |
15121 | && current_trace_status ()->running && loc->owner | |
15122 | && is_tracepoint (loc->owner)) | |
15123 | target_enable_tracepoint (loc); | |
15124 | } | |
44702360 | 15125 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 15126 | } |
9eaabc75 MW |
15127 | else |
15128 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
15129 | num = extract_arg (&args); | |
d248b706 | 15130 | } |
0d381245 | 15131 | } |
c906108c SS |
15132 | } |
15133 | ||
816338b5 SS |
15134 | /* This struct packages up disposition data for application to multiple |
15135 | breakpoints. */ | |
15136 | ||
15137 | struct disp_data | |
15138 | { | |
15139 | enum bpdisp disp; | |
15140 | int count; | |
15141 | }; | |
15142 | ||
c906108c | 15143 | static void |
51be5b68 PA |
15144 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
15145 | { | |
816338b5 | 15146 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 15147 | |
816338b5 | 15148 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
15149 | } |
15150 | ||
15151 | static void | |
15152 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 15153 | { |
816338b5 | 15154 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
15155 | |
15156 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15157 | } |
15158 | ||
c906108c | 15159 | static void |
fba45db2 | 15160 | enable_once_command (char *args, int from_tty) |
c906108c | 15161 | { |
51be5b68 | 15162 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
15163 | } |
15164 | ||
816338b5 SS |
15165 | static void |
15166 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
15167 | { | |
15168 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
15169 | ||
15170 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
15171 | } | |
15172 | ||
15173 | static void | |
15174 | enable_count_command (char *args, int from_tty) | |
15175 | { | |
15176 | int count = get_number (&args); | |
15177 | ||
15178 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
15179 | } | |
15180 | ||
c906108c | 15181 | static void |
51be5b68 | 15182 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 15183 | { |
816338b5 | 15184 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
15185 | |
15186 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15187 | } |
15188 | ||
c906108c | 15189 | static void |
fba45db2 | 15190 | enable_delete_command (char *args, int from_tty) |
c906108c | 15191 | { |
51be5b68 | 15192 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15193 | } |
15194 | \f | |
fa8d40ab JJ |
15195 | static void |
15196 | set_breakpoint_cmd (char *args, int from_tty) | |
15197 | { | |
15198 | } | |
15199 | ||
15200 | static void | |
15201 | show_breakpoint_cmd (char *args, int from_tty) | |
15202 | { | |
15203 | } | |
15204 | ||
1f3b5d1b PP |
15205 | /* Invalidate last known value of any hardware watchpoint if |
15206 | the memory which that value represents has been written to by | |
15207 | GDB itself. */ | |
15208 | ||
15209 | static void | |
8de0566d YQ |
15210 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15211 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15212 | const bfd_byte *data) |
15213 | { | |
15214 | struct breakpoint *bp; | |
15215 | ||
15216 | ALL_BREAKPOINTS (bp) | |
15217 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15218 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15219 | { |
3a5c3e22 | 15220 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15221 | |
3a5c3e22 PA |
15222 | if (wp->val_valid && wp->val) |
15223 | { | |
15224 | struct bp_location *loc; | |
15225 | ||
15226 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15227 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15228 | && loc->address + loc->length > addr | |
15229 | && addr + len > loc->address) | |
15230 | { | |
15231 | value_free (wp->val); | |
15232 | wp->val = NULL; | |
15233 | wp->val_valid = 0; | |
15234 | } | |
15235 | } | |
1f3b5d1b PP |
15236 | } |
15237 | } | |
15238 | ||
8181d85f DJ |
15239 | /* Create and insert a breakpoint for software single step. */ |
15240 | ||
15241 | void | |
6c95b8df | 15242 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15243 | struct address_space *aspace, |
15244 | CORE_ADDR next_pc) | |
8181d85f | 15245 | { |
7c16b83e PA |
15246 | struct thread_info *tp = inferior_thread (); |
15247 | struct symtab_and_line sal; | |
15248 | CORE_ADDR pc = next_pc; | |
8181d85f | 15249 | |
34b7e8a6 PA |
15250 | if (tp->control.single_step_breakpoints == NULL) |
15251 | { | |
15252 | tp->control.single_step_breakpoints | |
15253 | = new_single_step_breakpoint (tp->num, gdbarch); | |
15254 | } | |
8181d85f | 15255 | |
7c16b83e PA |
15256 | sal = find_pc_line (pc, 0); |
15257 | sal.pc = pc; | |
15258 | sal.section = find_pc_overlay (pc); | |
15259 | sal.explicit_pc = 1; | |
34b7e8a6 | 15260 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 15261 | |
7c16b83e | 15262 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
15263 | } |
15264 | ||
34b7e8a6 | 15265 | /* See breakpoint.h. */ |
f02253f1 HZ |
15266 | |
15267 | int | |
7c16b83e PA |
15268 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
15269 | struct address_space *aspace, | |
15270 | CORE_ADDR pc) | |
1aafd4da | 15271 | { |
7c16b83e | 15272 | struct bp_location *loc; |
1aafd4da | 15273 | |
7c16b83e PA |
15274 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
15275 | if (loc->inserted | |
15276 | && breakpoint_location_address_match (loc, aspace, pc)) | |
15277 | return 1; | |
1aafd4da | 15278 | |
7c16b83e | 15279 | return 0; |
ef370185 JB |
15280 | } |
15281 | ||
15282 | /* Check whether a software single-step breakpoint is inserted at | |
15283 | PC. */ | |
15284 | ||
15285 | int | |
15286 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15287 | CORE_ADDR pc) | |
15288 | { | |
34b7e8a6 PA |
15289 | struct breakpoint *bpt; |
15290 | ||
15291 | ALL_BREAKPOINTS (bpt) | |
15292 | { | |
15293 | if (bpt->type == bp_single_step | |
15294 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
15295 | return 1; | |
15296 | } | |
15297 | return 0; | |
1aafd4da UW |
15298 | } |
15299 | ||
a96d9b2e SDJ |
15300 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
15301 | non-zero otherwise. */ | |
15302 | static int | |
15303 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
15304 | { | |
15305 | if (syscall_catchpoint_p (bp) | |
15306 | && bp->enable_state != bp_disabled | |
15307 | && bp->enable_state != bp_call_disabled) | |
15308 | return 1; | |
15309 | else | |
15310 | return 0; | |
15311 | } | |
15312 | ||
15313 | int | |
15314 | catch_syscall_enabled (void) | |
15315 | { | |
fa3064dd YQ |
15316 | struct catch_syscall_inferior_data *inf_data |
15317 | = get_catch_syscall_inferior_data (current_inferior ()); | |
a96d9b2e | 15318 | |
fa3064dd | 15319 | return inf_data->total_syscalls_count != 0; |
a96d9b2e SDJ |
15320 | } |
15321 | ||
15322 | int | |
15323 | catching_syscall_number (int syscall_number) | |
15324 | { | |
15325 | struct breakpoint *bp; | |
15326 | ||
15327 | ALL_BREAKPOINTS (bp) | |
15328 | if (is_syscall_catchpoint_enabled (bp)) | |
15329 | { | |
be5c67c1 PA |
15330 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
15331 | ||
15332 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
15333 | { |
15334 | int i, iter; | |
15335 | for (i = 0; | |
be5c67c1 | 15336 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
15337 | i++) |
15338 | if (syscall_number == iter) | |
15339 | return 1; | |
15340 | } | |
15341 | else | |
15342 | return 1; | |
15343 | } | |
15344 | ||
15345 | return 0; | |
15346 | } | |
15347 | ||
15348 | /* Complete syscall names. Used by "catch syscall". */ | |
49c4e619 | 15349 | static VEC (char_ptr) * |
a96d9b2e | 15350 | catch_syscall_completer (struct cmd_list_element *cmd, |
6f937416 | 15351 | const char *text, const char *word) |
a96d9b2e | 15352 | { |
458c8db8 | 15353 | const char **list = get_syscall_names (get_current_arch ()); |
49c4e619 | 15354 | VEC (char_ptr) *retlist |
b45627a0 | 15355 | = (list == NULL) ? NULL : complete_on_enum (list, word, word); |
cc59ec59 | 15356 | |
c38eea1a MS |
15357 | xfree (list); |
15358 | return retlist; | |
a96d9b2e SDJ |
15359 | } |
15360 | ||
1042e4c0 SS |
15361 | /* Tracepoint-specific operations. */ |
15362 | ||
15363 | /* Set tracepoint count to NUM. */ | |
15364 | static void | |
15365 | set_tracepoint_count (int num) | |
15366 | { | |
15367 | tracepoint_count = num; | |
4fa62494 | 15368 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15369 | } |
15370 | ||
70221824 | 15371 | static void |
1042e4c0 SS |
15372 | trace_command (char *arg, int from_tty) |
15373 | { | |
55aa24fb SDJ |
15374 | struct breakpoint_ops *ops; |
15375 | const char *arg_cp = arg; | |
15376 | ||
15377 | if (arg && probe_linespec_to_ops (&arg_cp)) | |
15378 | ops = &tracepoint_probe_breakpoint_ops; | |
15379 | else | |
15380 | ops = &tracepoint_breakpoint_ops; | |
15381 | ||
558a9d82 YQ |
15382 | create_breakpoint (get_current_arch (), |
15383 | arg, | |
15384 | NULL, 0, NULL, 1 /* parse arg */, | |
15385 | 0 /* tempflag */, | |
15386 | bp_tracepoint /* type_wanted */, | |
15387 | 0 /* Ignore count */, | |
15388 | pending_break_support, | |
15389 | ops, | |
15390 | from_tty, | |
15391 | 1 /* enabled */, | |
15392 | 0 /* internal */, 0); | |
1042e4c0 SS |
15393 | } |
15394 | ||
70221824 | 15395 | static void |
7a697b8d SS |
15396 | ftrace_command (char *arg, int from_tty) |
15397 | { | |
558a9d82 YQ |
15398 | create_breakpoint (get_current_arch (), |
15399 | arg, | |
15400 | NULL, 0, NULL, 1 /* parse arg */, | |
15401 | 0 /* tempflag */, | |
15402 | bp_fast_tracepoint /* type_wanted */, | |
15403 | 0 /* Ignore count */, | |
15404 | pending_break_support, | |
15405 | &tracepoint_breakpoint_ops, | |
15406 | from_tty, | |
15407 | 1 /* enabled */, | |
15408 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15409 | } |
15410 | ||
15411 | /* strace command implementation. Creates a static tracepoint. */ | |
15412 | ||
70221824 | 15413 | static void |
0fb4aa4b PA |
15414 | strace_command (char *arg, int from_tty) |
15415 | { | |
983af33b SDJ |
15416 | struct breakpoint_ops *ops; |
15417 | ||
15418 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15419 | or with a normal static tracepoint. */ | |
15420 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) | |
15421 | ops = &strace_marker_breakpoint_ops; | |
15422 | else | |
15423 | ops = &tracepoint_breakpoint_ops; | |
15424 | ||
558a9d82 YQ |
15425 | create_breakpoint (get_current_arch (), |
15426 | arg, | |
15427 | NULL, 0, NULL, 1 /* parse arg */, | |
15428 | 0 /* tempflag */, | |
15429 | bp_static_tracepoint /* type_wanted */, | |
15430 | 0 /* Ignore count */, | |
15431 | pending_break_support, | |
15432 | ops, | |
15433 | from_tty, | |
15434 | 1 /* enabled */, | |
15435 | 0 /* internal */, 0); | |
7a697b8d SS |
15436 | } |
15437 | ||
409873ef SS |
15438 | /* Set up a fake reader function that gets command lines from a linked |
15439 | list that was acquired during tracepoint uploading. */ | |
15440 | ||
15441 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15442 | static int next_cmd; |
409873ef SS |
15443 | |
15444 | static char * | |
15445 | read_uploaded_action (void) | |
15446 | { | |
15447 | char *rslt; | |
15448 | ||
3149d8c1 | 15449 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15450 | |
3149d8c1 | 15451 | next_cmd++; |
409873ef SS |
15452 | |
15453 | return rslt; | |
15454 | } | |
15455 | ||
00bf0b85 SS |
15456 | /* Given information about a tracepoint as recorded on a target (which |
15457 | can be either a live system or a trace file), attempt to create an | |
15458 | equivalent GDB tracepoint. This is not a reliable process, since | |
15459 | the target does not necessarily have all the information used when | |
15460 | the tracepoint was originally defined. */ | |
15461 | ||
d9b3f62e | 15462 | struct tracepoint * |
00bf0b85 | 15463 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15464 | { |
409873ef | 15465 | char *addr_str, small_buf[100]; |
d9b3f62e | 15466 | struct tracepoint *tp; |
fd9b8c24 | 15467 | |
409873ef SS |
15468 | if (utp->at_string) |
15469 | addr_str = utp->at_string; | |
15470 | else | |
15471 | { | |
15472 | /* In the absence of a source location, fall back to raw | |
15473 | address. Since there is no way to confirm that the address | |
15474 | means the same thing as when the trace was started, warn the | |
15475 | user. */ | |
3e43a32a MS |
15476 | warning (_("Uploaded tracepoint %d has no " |
15477 | "source location, using raw address"), | |
409873ef | 15478 | utp->number); |
8c042590 | 15479 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15480 | addr_str = small_buf; |
15481 | } | |
15482 | ||
15483 | /* There's not much we can do with a sequence of bytecodes. */ | |
15484 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15485 | warning (_("Uploaded tracepoint %d condition " |
15486 | "has no source form, ignoring it"), | |
409873ef | 15487 | utp->number); |
d5551862 | 15488 | |
8cdf0e15 | 15489 | if (!create_breakpoint (get_current_arch (), |
409873ef | 15490 | addr_str, |
e7e0cddf SS |
15491 | utp->cond_string, -1, NULL, |
15492 | 0 /* parse cond/thread */, | |
8cdf0e15 | 15493 | 0 /* tempflag */, |
0fb4aa4b | 15494 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15495 | 0 /* Ignore count */, |
15496 | pending_break_support, | |
348d480f | 15497 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15498 | 0 /* from_tty */, |
84f4c1fe | 15499 | utp->enabled /* enabled */, |
44f238bb PA |
15500 | 0 /* internal */, |
15501 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
fd9b8c24 PA |
15502 | return NULL; |
15503 | ||
409873ef | 15504 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15505 | tp = get_tracepoint (tracepoint_count); |
15506 | gdb_assert (tp != NULL); | |
d5551862 | 15507 | |
00bf0b85 SS |
15508 | if (utp->pass > 0) |
15509 | { | |
8c042590 PM |
15510 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15511 | tp->base.number); | |
00bf0b85 | 15512 | |
409873ef | 15513 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15514 | } |
15515 | ||
409873ef SS |
15516 | /* If we have uploaded versions of the original commands, set up a |
15517 | special-purpose "reader" function and call the usual command line | |
15518 | reader, then pass the result to the breakpoint command-setting | |
15519 | function. */ | |
3149d8c1 | 15520 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15521 | { |
409873ef | 15522 | struct command_line *cmd_list; |
00bf0b85 | 15523 | |
409873ef | 15524 | this_utp = utp; |
3149d8c1 | 15525 | next_cmd = 0; |
d5551862 | 15526 | |
409873ef SS |
15527 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15528 | ||
d9b3f62e | 15529 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15530 | } |
3149d8c1 SS |
15531 | else if (!VEC_empty (char_ptr, utp->actions) |
15532 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15533 | warning (_("Uploaded tracepoint %d actions " |
15534 | "have no source form, ignoring them"), | |
409873ef | 15535 | utp->number); |
00bf0b85 | 15536 | |
f196051f SS |
15537 | /* Copy any status information that might be available. */ |
15538 | tp->base.hit_count = utp->hit_count; | |
15539 | tp->traceframe_usage = utp->traceframe_usage; | |
15540 | ||
00bf0b85 | 15541 | return tp; |
d9b3f62e | 15542 | } |
00bf0b85 | 15543 | |
1042e4c0 SS |
15544 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15545 | omitted. */ | |
15546 | ||
15547 | static void | |
e5a67952 | 15548 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15549 | { |
79a45e25 | 15550 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15551 | int num_printed; |
1042e4c0 | 15552 | |
e5a67952 | 15553 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15554 | |
15555 | if (num_printed == 0) | |
1042e4c0 | 15556 | { |
e5a67952 | 15557 | if (args == NULL || *args == '\0') |
d77f58be SS |
15558 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15559 | else | |
e5a67952 | 15560 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15561 | } |
ad443146 SS |
15562 | |
15563 | default_collect_info (); | |
1042e4c0 SS |
15564 | } |
15565 | ||
4a64f543 | 15566 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15567 | Not supported by all targets. */ |
15568 | static void | |
15569 | enable_trace_command (char *args, int from_tty) | |
15570 | { | |
15571 | enable_command (args, from_tty); | |
15572 | } | |
15573 | ||
4a64f543 | 15574 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15575 | Not supported by all targets. */ |
15576 | static void | |
15577 | disable_trace_command (char *args, int from_tty) | |
15578 | { | |
15579 | disable_command (args, from_tty); | |
15580 | } | |
15581 | ||
4a64f543 | 15582 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15583 | static void |
15584 | delete_trace_command (char *arg, int from_tty) | |
15585 | { | |
35df4500 | 15586 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15587 | |
15588 | dont_repeat (); | |
15589 | ||
15590 | if (arg == 0) | |
15591 | { | |
15592 | int breaks_to_delete = 0; | |
15593 | ||
15594 | /* Delete all breakpoints if no argument. | |
15595 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15596 | have to be deleted with an explicit breakpoint number |
15597 | argument. */ | |
1042e4c0 | 15598 | ALL_TRACEPOINTS (b) |
46c6471b | 15599 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15600 | { |
15601 | breaks_to_delete = 1; | |
15602 | break; | |
15603 | } | |
1042e4c0 SS |
15604 | |
15605 | /* Ask user only if there are some breakpoints to delete. */ | |
15606 | if (!from_tty | |
15607 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15608 | { | |
35df4500 | 15609 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15610 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15611 | delete_breakpoint (b); |
1042e4c0 SS |
15612 | } |
15613 | } | |
15614 | else | |
51be5b68 | 15615 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15616 | } |
15617 | ||
197f0a60 TT |
15618 | /* Helper function for trace_pass_command. */ |
15619 | ||
15620 | static void | |
d9b3f62e | 15621 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15622 | { |
d9b3f62e | 15623 | tp->pass_count = count; |
6f6484cd | 15624 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15625 | if (from_tty) |
15626 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15627 | tp->base.number, count); |
197f0a60 TT |
15628 | } |
15629 | ||
1042e4c0 SS |
15630 | /* Set passcount for tracepoint. |
15631 | ||
15632 | First command argument is passcount, second is tracepoint number. | |
15633 | If tracepoint number omitted, apply to most recently defined. | |
15634 | Also accepts special argument "all". */ | |
15635 | ||
15636 | static void | |
15637 | trace_pass_command (char *args, int from_tty) | |
15638 | { | |
d9b3f62e | 15639 | struct tracepoint *t1; |
1042e4c0 | 15640 | unsigned int count; |
1042e4c0 SS |
15641 | |
15642 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15643 | error (_("passcount command requires an " |
15644 | "argument (count + optional TP num)")); | |
1042e4c0 | 15645 | |
4a64f543 | 15646 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15647 | |
529480d0 | 15648 | args = skip_spaces (args); |
1042e4c0 SS |
15649 | if (*args && strncasecmp (args, "all", 3) == 0) |
15650 | { | |
d9b3f62e PA |
15651 | struct breakpoint *b; |
15652 | ||
1042e4c0 | 15653 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15654 | if (*args) |
15655 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15656 | |
d9b3f62e | 15657 | ALL_TRACEPOINTS (b) |
197f0a60 | 15658 | { |
d9b3f62e | 15659 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15660 | trace_pass_set_count (t1, count, from_tty); |
15661 | } | |
15662 | } | |
15663 | else if (*args == '\0') | |
1042e4c0 | 15664 | { |
5fa1d40e | 15665 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15666 | if (t1) |
197f0a60 TT |
15667 | trace_pass_set_count (t1, count, from_tty); |
15668 | } | |
15669 | else | |
15670 | { | |
15671 | struct get_number_or_range_state state; | |
15672 | ||
15673 | init_number_or_range (&state, args); | |
15674 | while (!state.finished) | |
1042e4c0 | 15675 | { |
5fa1d40e | 15676 | t1 = get_tracepoint_by_number (&args, &state); |
197f0a60 TT |
15677 | if (t1) |
15678 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15679 | } |
15680 | } | |
1042e4c0 SS |
15681 | } |
15682 | ||
d9b3f62e | 15683 | struct tracepoint * |
1042e4c0 SS |
15684 | get_tracepoint (int num) |
15685 | { | |
15686 | struct breakpoint *t; | |
15687 | ||
15688 | ALL_TRACEPOINTS (t) | |
15689 | if (t->number == num) | |
d9b3f62e | 15690 | return (struct tracepoint *) t; |
1042e4c0 SS |
15691 | |
15692 | return NULL; | |
15693 | } | |
15694 | ||
d5551862 SS |
15695 | /* Find the tracepoint with the given target-side number (which may be |
15696 | different from the tracepoint number after disconnecting and | |
15697 | reconnecting). */ | |
15698 | ||
d9b3f62e | 15699 | struct tracepoint * |
d5551862 SS |
15700 | get_tracepoint_by_number_on_target (int num) |
15701 | { | |
d9b3f62e | 15702 | struct breakpoint *b; |
d5551862 | 15703 | |
d9b3f62e PA |
15704 | ALL_TRACEPOINTS (b) |
15705 | { | |
15706 | struct tracepoint *t = (struct tracepoint *) b; | |
15707 | ||
15708 | if (t->number_on_target == num) | |
15709 | return t; | |
15710 | } | |
d5551862 SS |
15711 | |
15712 | return NULL; | |
15713 | } | |
15714 | ||
1042e4c0 | 15715 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15716 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15717 | If the argument is missing, the most recent tracepoint |
15718 | (tracepoint_count) is returned. */ | |
15719 | ||
d9b3f62e | 15720 | struct tracepoint * |
197f0a60 | 15721 | get_tracepoint_by_number (char **arg, |
5fa1d40e | 15722 | struct get_number_or_range_state *state) |
1042e4c0 | 15723 | { |
1042e4c0 SS |
15724 | struct breakpoint *t; |
15725 | int tpnum; | |
15726 | char *instring = arg == NULL ? NULL : *arg; | |
15727 | ||
197f0a60 TT |
15728 | if (state) |
15729 | { | |
15730 | gdb_assert (!state->finished); | |
15731 | tpnum = get_number_or_range (state); | |
15732 | } | |
15733 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15734 | tpnum = tracepoint_count; |
1042e4c0 | 15735 | else |
197f0a60 | 15736 | tpnum = get_number (arg); |
1042e4c0 SS |
15737 | |
15738 | if (tpnum <= 0) | |
15739 | { | |
15740 | if (instring && *instring) | |
15741 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15742 | instring); | |
15743 | else | |
5fa1d40e | 15744 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15745 | return NULL; |
15746 | } | |
15747 | ||
15748 | ALL_TRACEPOINTS (t) | |
15749 | if (t->number == tpnum) | |
15750 | { | |
d9b3f62e | 15751 | return (struct tracepoint *) t; |
1042e4c0 SS |
15752 | } |
15753 | ||
1042e4c0 SS |
15754 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15755 | return NULL; | |
15756 | } | |
15757 | ||
d9b3f62e PA |
15758 | void |
15759 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15760 | { | |
15761 | if (b->thread != -1) | |
15762 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15763 | ||
15764 | if (b->task != 0) | |
15765 | fprintf_unfiltered (fp, " task %d", b->task); | |
15766 | ||
15767 | fprintf_unfiltered (fp, "\n"); | |
15768 | } | |
15769 | ||
6149aea9 PA |
15770 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15771 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15772 | on each breakpoint and only include the ones for which it returns | |
15773 | non-zero. */ | |
15774 | ||
1042e4c0 | 15775 | static void |
6149aea9 PA |
15776 | save_breakpoints (char *filename, int from_tty, |
15777 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15778 | { |
15779 | struct breakpoint *tp; | |
6149aea9 | 15780 | int any = 0; |
1042e4c0 | 15781 | struct cleanup *cleanup; |
a7bdde9e | 15782 | struct ui_file *fp; |
6149aea9 | 15783 | int extra_trace_bits = 0; |
1042e4c0 | 15784 | |
6149aea9 PA |
15785 | if (filename == 0 || *filename == 0) |
15786 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15787 | |
15788 | /* See if we have anything to save. */ | |
6149aea9 | 15789 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15790 | { |
6149aea9 | 15791 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15792 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15793 | continue; |
15794 | ||
15795 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15796 | if (filter && !filter (tp)) | |
15797 | continue; | |
15798 | ||
15799 | any = 1; | |
15800 | ||
15801 | if (is_tracepoint (tp)) | |
15802 | { | |
15803 | extra_trace_bits = 1; | |
15804 | ||
15805 | /* We can stop searching. */ | |
15806 | break; | |
15807 | } | |
1042e4c0 | 15808 | } |
6149aea9 PA |
15809 | |
15810 | if (!any) | |
1042e4c0 | 15811 | { |
6149aea9 | 15812 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15813 | return; |
15814 | } | |
15815 | ||
c718be47 PA |
15816 | filename = tilde_expand (filename); |
15817 | cleanup = make_cleanup (xfree, filename); | |
15818 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15819 | if (!fp) |
6149aea9 PA |
15820 | error (_("Unable to open file '%s' for saving (%s)"), |
15821 | filename, safe_strerror (errno)); | |
a7bdde9e | 15822 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15823 | |
6149aea9 PA |
15824 | if (extra_trace_bits) |
15825 | save_trace_state_variables (fp); | |
8bf6485c | 15826 | |
6149aea9 | 15827 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15828 | { |
6149aea9 | 15829 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15830 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15831 | continue; |
8bf6485c | 15832 | |
6149aea9 PA |
15833 | /* If we have a filter, only save the breakpoints it accepts. */ |
15834 | if (filter && !filter (tp)) | |
15835 | continue; | |
15836 | ||
348d480f | 15837 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15838 | |
6149aea9 PA |
15839 | /* Note, we can't rely on tp->number for anything, as we can't |
15840 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15841 | instead. */ | |
15842 | ||
15843 | if (tp->cond_string) | |
15844 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15845 | ||
15846 | if (tp->ignore_count) | |
15847 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15848 | ||
2d9442cc | 15849 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15850 | { |
a7bdde9e VP |
15851 | volatile struct gdb_exception ex; |
15852 | ||
6149aea9 | 15853 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15854 | |
79a45e25 | 15855 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 15856 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 15857 | { |
79a45e25 | 15858 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15859 | } |
79a45e25 | 15860 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 15861 | |
a7bdde9e VP |
15862 | if (ex.reason < 0) |
15863 | throw_exception (ex); | |
1042e4c0 | 15864 | |
a7bdde9e | 15865 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15866 | } |
6149aea9 PA |
15867 | |
15868 | if (tp->enable_state == bp_disabled) | |
99894e11 | 15869 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
6149aea9 PA |
15870 | |
15871 | /* If this is a multi-location breakpoint, check if the locations | |
15872 | should be individually disabled. Watchpoint locations are | |
15873 | special, and not user visible. */ | |
15874 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15875 | { | |
15876 | struct bp_location *loc; | |
15877 | int n = 1; | |
15878 | ||
15879 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15880 | if (!loc->enabled) | |
15881 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15882 | } | |
1042e4c0 | 15883 | } |
8bf6485c | 15884 | |
6149aea9 | 15885 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15886 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15887 | ||
1042e4c0 | 15888 | if (from_tty) |
6149aea9 | 15889 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15890 | do_cleanups (cleanup); |
6149aea9 PA |
15891 | } |
15892 | ||
15893 | /* The `save breakpoints' command. */ | |
15894 | ||
15895 | static void | |
15896 | save_breakpoints_command (char *args, int from_tty) | |
15897 | { | |
15898 | save_breakpoints (args, from_tty, NULL); | |
15899 | } | |
15900 | ||
15901 | /* The `save tracepoints' command. */ | |
15902 | ||
15903 | static void | |
15904 | save_tracepoints_command (char *args, int from_tty) | |
15905 | { | |
15906 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15907 | } |
15908 | ||
15909 | /* Create a vector of all tracepoints. */ | |
15910 | ||
15911 | VEC(breakpoint_p) * | |
eeae04df | 15912 | all_tracepoints (void) |
1042e4c0 SS |
15913 | { |
15914 | VEC(breakpoint_p) *tp_vec = 0; | |
15915 | struct breakpoint *tp; | |
15916 | ||
15917 | ALL_TRACEPOINTS (tp) | |
15918 | { | |
15919 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15920 | } | |
15921 | ||
15922 | return tp_vec; | |
15923 | } | |
15924 | ||
c906108c | 15925 | \f |
4a64f543 MS |
15926 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15927 | commands. It is defined as a macro to prevent duplication. | |
15928 | COMMAND should be a string constant containing the name of the | |
15929 | command. */ | |
31e2b00f | 15930 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15931 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15932 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15933 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
15934 | guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\ | |
31e2b00f AS |
15935 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
15936 | If a line number is specified, break at start of code for that line.\n\ | |
15937 | If a function is specified, break at start of code for that function.\n\ | |
15938 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
15939 | With no LOCATION, uses current execution address of the selected\n\ |
15940 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15941 | \n\ |
15942 | THREADNUM is the number from \"info threads\".\n\ | |
15943 | CONDITION is a boolean expression.\n\ | |
15944 | \n\ | |
d41c0fc8 PA |
15945 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15946 | conditions are different.\n\ | |
31e2b00f AS |
15947 | \n\ |
15948 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15949 | ||
44feb3ce TT |
15950 | /* List of subcommands for "catch". */ |
15951 | static struct cmd_list_element *catch_cmdlist; | |
15952 | ||
15953 | /* List of subcommands for "tcatch". */ | |
15954 | static struct cmd_list_element *tcatch_cmdlist; | |
15955 | ||
9ac4176b | 15956 | void |
44feb3ce | 15957 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 15958 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15959 | completer_ftype *completer, |
44feb3ce TT |
15960 | void *user_data_catch, |
15961 | void *user_data_tcatch) | |
15962 | { | |
15963 | struct cmd_list_element *command; | |
15964 | ||
15965 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15966 | &catch_cmdlist); | |
15967 | set_cmd_sfunc (command, sfunc); | |
15968 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15969 | set_cmd_completer (command, completer); |
44feb3ce TT |
15970 | |
15971 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15972 | &tcatch_cmdlist); | |
15973 | set_cmd_sfunc (command, sfunc); | |
15974 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15975 | set_cmd_completer (command, completer); |
44feb3ce TT |
15976 | } |
15977 | ||
6c95b8df | 15978 | static void |
a79b8f6e | 15979 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 15980 | { |
fa3064dd YQ |
15981 | struct catch_syscall_inferior_data *inf_data |
15982 | = get_catch_syscall_inferior_data (inf); | |
15983 | ||
15984 | inf_data->total_syscalls_count = 0; | |
15985 | inf_data->any_syscall_count = 0; | |
15986 | VEC_free (int, inf_data->syscalls_counts); | |
6c95b8df PA |
15987 | } |
15988 | ||
6149aea9 PA |
15989 | static void |
15990 | save_command (char *arg, int from_tty) | |
15991 | { | |
3e43a32a MS |
15992 | printf_unfiltered (_("\"save\" must be followed by " |
15993 | "the name of a save subcommand.\n")); | |
635c7e8a | 15994 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15995 | } |
15996 | ||
84f4c1fe PM |
15997 | struct breakpoint * |
15998 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15999 | void *data) | |
16000 | { | |
35df4500 | 16001 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 16002 | |
35df4500 | 16003 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
16004 | { |
16005 | if ((*callback) (b, data)) | |
16006 | return b; | |
16007 | } | |
16008 | ||
16009 | return NULL; | |
16010 | } | |
16011 | ||
0574c78f GB |
16012 | /* Zero if any of the breakpoint's locations could be a location where |
16013 | functions have been inlined, nonzero otherwise. */ | |
16014 | ||
16015 | static int | |
16016 | is_non_inline_function (struct breakpoint *b) | |
16017 | { | |
16018 | /* The shared library event breakpoint is set on the address of a | |
16019 | non-inline function. */ | |
16020 | if (b->type == bp_shlib_event) | |
16021 | return 1; | |
16022 | ||
16023 | return 0; | |
16024 | } | |
16025 | ||
16026 | /* Nonzero if the specified PC cannot be a location where functions | |
16027 | have been inlined. */ | |
16028 | ||
16029 | int | |
09ac7c10 TT |
16030 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
16031 | const struct target_waitstatus *ws) | |
0574c78f GB |
16032 | { |
16033 | struct breakpoint *b; | |
16034 | struct bp_location *bl; | |
16035 | ||
16036 | ALL_BREAKPOINTS (b) | |
16037 | { | |
16038 | if (!is_non_inline_function (b)) | |
16039 | continue; | |
16040 | ||
16041 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
16042 | { | |
16043 | if (!bl->shlib_disabled | |
09ac7c10 | 16044 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
16045 | return 1; |
16046 | } | |
16047 | } | |
16048 | ||
16049 | return 0; | |
16050 | } | |
16051 | ||
2f202fde JK |
16052 | /* Remove any references to OBJFILE which is going to be freed. */ |
16053 | ||
16054 | void | |
16055 | breakpoint_free_objfile (struct objfile *objfile) | |
16056 | { | |
16057 | struct bp_location **locp, *loc; | |
16058 | ||
16059 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 16060 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
16061 | loc->symtab = NULL; |
16062 | } | |
16063 | ||
2060206e PA |
16064 | void |
16065 | initialize_breakpoint_ops (void) | |
16066 | { | |
16067 | static int initialized = 0; | |
16068 | ||
16069 | struct breakpoint_ops *ops; | |
16070 | ||
16071 | if (initialized) | |
16072 | return; | |
16073 | initialized = 1; | |
16074 | ||
16075 | /* The breakpoint_ops structure to be inherit by all kinds of | |
16076 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
16077 | internal and momentary breakpoints, etc.). */ | |
16078 | ops = &bkpt_base_breakpoint_ops; | |
16079 | *ops = base_breakpoint_ops; | |
16080 | ops->re_set = bkpt_re_set; | |
16081 | ops->insert_location = bkpt_insert_location; | |
16082 | ops->remove_location = bkpt_remove_location; | |
16083 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
983af33b SDJ |
16084 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
16085 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; | |
16086 | ops->decode_linespec = bkpt_decode_linespec; | |
2060206e PA |
16087 | |
16088 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
16089 | ops = &bkpt_breakpoint_ops; | |
16090 | *ops = bkpt_base_breakpoint_ops; | |
16091 | ops->re_set = bkpt_re_set; | |
16092 | ops->resources_needed = bkpt_resources_needed; | |
16093 | ops->print_it = bkpt_print_it; | |
16094 | ops->print_mention = bkpt_print_mention; | |
16095 | ops->print_recreate = bkpt_print_recreate; | |
16096 | ||
16097 | /* Ranged breakpoints. */ | |
16098 | ops = &ranged_breakpoint_ops; | |
16099 | *ops = bkpt_breakpoint_ops; | |
16100 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
16101 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
16102 | ops->print_it = print_it_ranged_breakpoint; | |
16103 | ops->print_one = print_one_ranged_breakpoint; | |
16104 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
16105 | ops->print_mention = print_mention_ranged_breakpoint; | |
16106 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
16107 | ||
16108 | /* Internal breakpoints. */ | |
16109 | ops = &internal_breakpoint_ops; | |
16110 | *ops = bkpt_base_breakpoint_ops; | |
16111 | ops->re_set = internal_bkpt_re_set; | |
16112 | ops->check_status = internal_bkpt_check_status; | |
16113 | ops->print_it = internal_bkpt_print_it; | |
16114 | ops->print_mention = internal_bkpt_print_mention; | |
16115 | ||
16116 | /* Momentary breakpoints. */ | |
16117 | ops = &momentary_breakpoint_ops; | |
16118 | *ops = bkpt_base_breakpoint_ops; | |
16119 | ops->re_set = momentary_bkpt_re_set; | |
16120 | ops->check_status = momentary_bkpt_check_status; | |
16121 | ops->print_it = momentary_bkpt_print_it; | |
16122 | ops->print_mention = momentary_bkpt_print_mention; | |
16123 | ||
e2e4d78b JK |
16124 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
16125 | ops = &longjmp_breakpoint_ops; | |
16126 | *ops = momentary_breakpoint_ops; | |
16127 | ops->dtor = longjmp_bkpt_dtor; | |
16128 | ||
55aa24fb SDJ |
16129 | /* Probe breakpoints. */ |
16130 | ops = &bkpt_probe_breakpoint_ops; | |
16131 | *ops = bkpt_breakpoint_ops; | |
16132 | ops->insert_location = bkpt_probe_insert_location; | |
16133 | ops->remove_location = bkpt_probe_remove_location; | |
16134 | ops->create_sals_from_address = bkpt_probe_create_sals_from_address; | |
16135 | ops->decode_linespec = bkpt_probe_decode_linespec; | |
16136 | ||
2060206e PA |
16137 | /* Watchpoints. */ |
16138 | ops = &watchpoint_breakpoint_ops; | |
16139 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 16140 | ops->dtor = dtor_watchpoint; |
2060206e PA |
16141 | ops->re_set = re_set_watchpoint; |
16142 | ops->insert_location = insert_watchpoint; | |
16143 | ops->remove_location = remove_watchpoint; | |
16144 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
16145 | ops->check_status = check_status_watchpoint; | |
16146 | ops->resources_needed = resources_needed_watchpoint; | |
16147 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
16148 | ops->print_it = print_it_watchpoint; | |
16149 | ops->print_mention = print_mention_watchpoint; | |
16150 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 16151 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
16152 | |
16153 | /* Masked watchpoints. */ | |
16154 | ops = &masked_watchpoint_breakpoint_ops; | |
16155 | *ops = watchpoint_breakpoint_ops; | |
16156 | ops->insert_location = insert_masked_watchpoint; | |
16157 | ops->remove_location = remove_masked_watchpoint; | |
16158 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16159 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16160 | ops->print_it = print_it_masked_watchpoint; | |
16161 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16162 | ops->print_mention = print_mention_masked_watchpoint; | |
16163 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16164 | ||
16165 | /* Tracepoints. */ | |
16166 | ops = &tracepoint_breakpoint_ops; | |
16167 | *ops = base_breakpoint_ops; | |
16168 | ops->re_set = tracepoint_re_set; | |
16169 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16170 | ops->print_one_detail = tracepoint_print_one_detail; | |
16171 | ops->print_mention = tracepoint_print_mention; | |
16172 | ops->print_recreate = tracepoint_print_recreate; | |
983af33b SDJ |
16173 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
16174 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; | |
16175 | ops->decode_linespec = tracepoint_decode_linespec; | |
16176 | ||
55aa24fb SDJ |
16177 | /* Probe tracepoints. */ |
16178 | ops = &tracepoint_probe_breakpoint_ops; | |
16179 | *ops = tracepoint_breakpoint_ops; | |
16180 | ops->create_sals_from_address = tracepoint_probe_create_sals_from_address; | |
16181 | ops->decode_linespec = tracepoint_probe_decode_linespec; | |
16182 | ||
983af33b SDJ |
16183 | /* Static tracepoints with marker (`-m'). */ |
16184 | ops = &strace_marker_breakpoint_ops; | |
16185 | *ops = tracepoint_breakpoint_ops; | |
16186 | ops->create_sals_from_address = strace_marker_create_sals_from_address; | |
16187 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; | |
16188 | ops->decode_linespec = strace_marker_decode_linespec; | |
2060206e PA |
16189 | |
16190 | /* Fork catchpoints. */ | |
16191 | ops = &catch_fork_breakpoint_ops; | |
16192 | *ops = base_breakpoint_ops; | |
16193 | ops->insert_location = insert_catch_fork; | |
16194 | ops->remove_location = remove_catch_fork; | |
16195 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16196 | ops->print_it = print_it_catch_fork; | |
16197 | ops->print_one = print_one_catch_fork; | |
16198 | ops->print_mention = print_mention_catch_fork; | |
16199 | ops->print_recreate = print_recreate_catch_fork; | |
16200 | ||
16201 | /* Vfork catchpoints. */ | |
16202 | ops = &catch_vfork_breakpoint_ops; | |
16203 | *ops = base_breakpoint_ops; | |
16204 | ops->insert_location = insert_catch_vfork; | |
16205 | ops->remove_location = remove_catch_vfork; | |
16206 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16207 | ops->print_it = print_it_catch_vfork; | |
16208 | ops->print_one = print_one_catch_vfork; | |
16209 | ops->print_mention = print_mention_catch_vfork; | |
16210 | ops->print_recreate = print_recreate_catch_vfork; | |
16211 | ||
16212 | /* Exec catchpoints. */ | |
16213 | ops = &catch_exec_breakpoint_ops; | |
16214 | *ops = base_breakpoint_ops; | |
16215 | ops->dtor = dtor_catch_exec; | |
16216 | ops->insert_location = insert_catch_exec; | |
16217 | ops->remove_location = remove_catch_exec; | |
16218 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16219 | ops->print_it = print_it_catch_exec; | |
16220 | ops->print_one = print_one_catch_exec; | |
16221 | ops->print_mention = print_mention_catch_exec; | |
16222 | ops->print_recreate = print_recreate_catch_exec; | |
16223 | ||
16224 | /* Syscall catchpoints. */ | |
16225 | ops = &catch_syscall_breakpoint_ops; | |
16226 | *ops = base_breakpoint_ops; | |
16227 | ops->dtor = dtor_catch_syscall; | |
16228 | ops->insert_location = insert_catch_syscall; | |
16229 | ops->remove_location = remove_catch_syscall; | |
16230 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
16231 | ops->print_it = print_it_catch_syscall; | |
16232 | ops->print_one = print_one_catch_syscall; | |
16233 | ops->print_mention = print_mention_catch_syscall; | |
16234 | ops->print_recreate = print_recreate_catch_syscall; | |
edcc5120 TT |
16235 | |
16236 | /* Solib-related catchpoints. */ | |
16237 | ops = &catch_solib_breakpoint_ops; | |
16238 | *ops = base_breakpoint_ops; | |
16239 | ops->dtor = dtor_catch_solib; | |
16240 | ops->insert_location = insert_catch_solib; | |
16241 | ops->remove_location = remove_catch_solib; | |
16242 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16243 | ops->check_status = check_status_catch_solib; | |
16244 | ops->print_it = print_it_catch_solib; | |
16245 | ops->print_one = print_one_catch_solib; | |
16246 | ops->print_mention = print_mention_catch_solib; | |
16247 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16248 | |
16249 | ops = &dprintf_breakpoint_ops; | |
16250 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16251 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16252 | ops->resources_needed = bkpt_resources_needed; |
16253 | ops->print_it = bkpt_print_it; | |
16254 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16255 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16256 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 16257 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
16258 | } |
16259 | ||
8bfd80db YQ |
16260 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16261 | ||
16262 | static struct cmd_list_element *enablebreaklist = NULL; | |
16263 | ||
c906108c | 16264 | void |
fba45db2 | 16265 | _initialize_breakpoint (void) |
c906108c SS |
16266 | { |
16267 | struct cmd_list_element *c; | |
16268 | ||
2060206e PA |
16269 | initialize_breakpoint_ops (); |
16270 | ||
84acb35a | 16271 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16272 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
6c95b8df | 16273 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 16274 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16275 | |
55aa24fb SDJ |
16276 | breakpoint_objfile_key |
16277 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16278 | |
fa3064dd | 16279 | catch_syscall_inferior_data |
8e260fc0 TT |
16280 | = register_inferior_data_with_cleanup (NULL, |
16281 | catch_syscall_inferior_data_cleanup); | |
fa3064dd | 16282 | |
c906108c SS |
16283 | breakpoint_chain = 0; |
16284 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16285 | before a breakpoint is set. */ | |
16286 | breakpoint_count = 0; | |
16287 | ||
1042e4c0 SS |
16288 | tracepoint_count = 0; |
16289 | ||
1bedd215 AC |
16290 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16291 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16292 | Usage is `ignore N COUNT'.")); | |
c906108c | 16293 | if (xdb_commands) |
c5aa993b | 16294 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 16295 | |
1bedd215 AC |
16296 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16297 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16298 | Give breakpoint number as argument after \"commands\".\n\ |
16299 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16300 | The commands themselves follow starting on the next line.\n\ | |
16301 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16302 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16303 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16304 | |
d55637df | 16305 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16306 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16307 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16308 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16309 | set_cmd_completer (c, condition_completer); |
c906108c | 16310 | |
1bedd215 | 16311 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16312 | Set a temporary breakpoint.\n\ |
c906108c SS |
16313 | Like \"break\" except the breakpoint is only temporary,\n\ |
16314 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16315 | by using \"enable delete\" on the breakpoint number.\n\ |
16316 | \n" | |
16317 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16318 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16319 | |
1bedd215 | 16320 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16321 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16322 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16323 | some target hardware may not have this support.\n\ |
16324 | \n" | |
16325 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16326 | set_cmd_completer (c, location_completer); |
c906108c | 16327 | |
1bedd215 | 16328 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16329 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16330 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16331 | so it will be deleted when hit.\n\ |
16332 | \n" | |
16333 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16334 | set_cmd_completer (c, location_completer); |
c906108c | 16335 | |
1bedd215 AC |
16336 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16337 | Enable some breakpoints.\n\ | |
c906108c SS |
16338 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16339 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16340 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16341 | With a subcommand you can enable temporarily."), |
c906108c SS |
16342 | &enablelist, "enable ", 1, &cmdlist); |
16343 | if (xdb_commands) | |
1bedd215 AC |
16344 | add_com ("ab", class_breakpoint, enable_command, _("\ |
16345 | Enable some breakpoints.\n\ | |
c906108c SS |
16346 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16347 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16348 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16349 | With a subcommand you can enable temporarily.")); |
c906108c SS |
16350 | |
16351 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16352 | ||
84951ab5 | 16353 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16354 | Enable some breakpoints.\n\ |
c906108c SS |
16355 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16356 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16357 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16358 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16359 | |
1a966eab AC |
16360 | add_cmd ("once", no_class, enable_once_command, _("\ |
16361 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16362 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16363 | &enablebreaklist); |
16364 | ||
1a966eab AC |
16365 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16366 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16367 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16368 | &enablebreaklist); |
16369 | ||
816338b5 SS |
16370 | add_cmd ("count", no_class, enable_count_command, _("\ |
16371 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16372 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16373 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16374 | &enablebreaklist); | |
16375 | ||
1a966eab AC |
16376 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16377 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16378 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16379 | &enablelist); |
16380 | ||
1a966eab AC |
16381 | add_cmd ("once", no_class, enable_once_command, _("\ |
16382 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16383 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16384 | &enablelist); |
16385 | ||
16386 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16387 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16388 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16389 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16390 | &enablelist); |
16391 | ||
1bedd215 AC |
16392 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16393 | Disable some breakpoints.\n\ | |
c906108c SS |
16394 | Arguments are breakpoint numbers with spaces in between.\n\ |
16395 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16396 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16397 | &disablelist, "disable ", 1, &cmdlist); |
16398 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16399 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
16400 | if (xdb_commands) | |
1bedd215 AC |
16401 | add_com ("sb", class_breakpoint, disable_command, _("\ |
16402 | Disable some breakpoints.\n\ | |
c906108c SS |
16403 | Arguments are breakpoint numbers with spaces in between.\n\ |
16404 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16405 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 16406 | |
1a966eab AC |
16407 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16408 | Disable some breakpoints.\n\ | |
c906108c SS |
16409 | Arguments are breakpoint numbers with spaces in between.\n\ |
16410 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16411 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16412 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16413 | &disablelist); |
16414 | ||
1bedd215 AC |
16415 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16416 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16417 | Arguments are breakpoint numbers with spaces in between.\n\ |
16418 | To delete all breakpoints, give no argument.\n\ | |
16419 | \n\ | |
16420 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16421 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16422 | &deletelist, "delete ", 1, &cmdlist); |
16423 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16424 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16425 | if (xdb_commands) |
1bedd215 AC |
16426 | add_com ("db", class_breakpoint, delete_command, _("\ |
16427 | Delete some breakpoints.\n\ | |
c906108c | 16428 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 16429 | To delete all breakpoints, give no argument.\n")); |
c906108c | 16430 | |
1a966eab AC |
16431 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16432 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16433 | Arguments are breakpoint numbers with spaces in between.\n\ |
16434 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16435 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16436 | &deletelist); |
16437 | ||
1bedd215 AC |
16438 | add_com ("clear", class_breakpoint, clear_command, _("\ |
16439 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
16440 | Argument may be line number, function name, or \"*\" and an address.\n\ |
16441 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
16442 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
16443 | If an address is specified, breakpoints at that address are cleared.\n\ |
16444 | \n\ | |
16445 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
16446 | is executing in.\n\ |
16447 | \n\ | |
1bedd215 | 16448 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16449 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16450 | |
1bedd215 | 16451 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
16452 | Set breakpoint at specified line or function.\n" |
16453 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 16454 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16455 | |
c906108c SS |
16456 | add_com_alias ("b", "break", class_run, 1); |
16457 | add_com_alias ("br", "break", class_run, 1); | |
16458 | add_com_alias ("bre", "break", class_run, 1); | |
16459 | add_com_alias ("brea", "break", class_run, 1); | |
16460 | ||
7681d515 PM |
16461 | if (xdb_commands) |
16462 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
16463 | |
16464 | if (dbx_commands) | |
16465 | { | |
1bedd215 AC |
16466 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16467 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16468 | &stoplist, "stop ", 1, &cmdlist); |
16469 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16470 | _("Break in function or address."), &stoplist); |
c5aa993b | 16471 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16472 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16473 | add_com ("status", class_info, breakpoints_info, _("\ |
16474 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16475 | The \"Type\" column indicates one of:\n\ |
16476 | \tbreakpoint - normal breakpoint\n\ | |
16477 | \twatchpoint - watchpoint\n\ | |
16478 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16479 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16480 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16481 | address and file/line number respectively.\n\ |
16482 | \n\ | |
16483 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16484 | are set to the address of the last breakpoint listed unless the command\n\ |
16485 | is prefixed with \"server \".\n\n\ | |
c906108c | 16486 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16487 | breakpoint set.")); |
c906108c SS |
16488 | } |
16489 | ||
1bedd215 | 16490 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16491 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16492 | The \"Type\" column indicates one of:\n\ |
16493 | \tbreakpoint - normal breakpoint\n\ | |
16494 | \twatchpoint - watchpoint\n\ | |
16495 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16496 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16497 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16498 | address and file/line number respectively.\n\ |
16499 | \n\ | |
16500 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16501 | are set to the address of the last breakpoint listed unless the command\n\ |
16502 | is prefixed with \"server \".\n\n\ | |
c906108c | 16503 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16504 | breakpoint set.")); |
c906108c | 16505 | |
6b04bdb7 MS |
16506 | add_info_alias ("b", "breakpoints", 1); |
16507 | ||
c906108c | 16508 | if (xdb_commands) |
1bedd215 AC |
16509 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
16510 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16511 | The \"Type\" column indicates one of:\n\ |
16512 | \tbreakpoint - normal breakpoint\n\ | |
16513 | \twatchpoint - watchpoint\n\ | |
16514 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16515 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16516 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16517 | address and file/line number respectively.\n\ |
16518 | \n\ | |
16519 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16520 | are set to the address of the last breakpoint listed unless the command\n\ |
16521 | is prefixed with \"server \".\n\n\ | |
c906108c | 16522 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16523 | breakpoint set.")); |
c906108c | 16524 | |
1a966eab AC |
16525 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16526 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16527 | The \"Type\" column indicates one of:\n\ |
16528 | \tbreakpoint - normal breakpoint\n\ | |
16529 | \twatchpoint - watchpoint\n\ | |
16530 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16531 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16532 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16533 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16534 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16535 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16536 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16537 | address and file/line number respectively.\n\ |
16538 | \n\ | |
16539 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16540 | are set to the address of the last breakpoint listed unless the command\n\ |
16541 | is prefixed with \"server \".\n\n\ | |
c906108c | 16542 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16543 | breakpoint set."), |
c906108c SS |
16544 | &maintenanceinfolist); |
16545 | ||
44feb3ce TT |
16546 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16547 | Set catchpoints to catch events."), | |
16548 | &catch_cmdlist, "catch ", | |
16549 | 0/*allow-unknown*/, &cmdlist); | |
16550 | ||
16551 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16552 | Set temporary catchpoints to catch events."), | |
16553 | &tcatch_cmdlist, "tcatch ", | |
16554 | 0/*allow-unknown*/, &cmdlist); | |
16555 | ||
44feb3ce TT |
16556 | add_catch_command ("fork", _("Catch calls to fork."), |
16557 | catch_fork_command_1, | |
a96d9b2e | 16558 | NULL, |
44feb3ce TT |
16559 | (void *) (uintptr_t) catch_fork_permanent, |
16560 | (void *) (uintptr_t) catch_fork_temporary); | |
16561 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16562 | catch_fork_command_1, | |
a96d9b2e | 16563 | NULL, |
44feb3ce TT |
16564 | (void *) (uintptr_t) catch_vfork_permanent, |
16565 | (void *) (uintptr_t) catch_vfork_temporary); | |
16566 | add_catch_command ("exec", _("Catch calls to exec."), | |
16567 | catch_exec_command_1, | |
a96d9b2e SDJ |
16568 | NULL, |
16569 | CATCH_PERMANENT, | |
16570 | CATCH_TEMPORARY); | |
edcc5120 TT |
16571 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16572 | Usage: catch load [REGEX]\n\ | |
16573 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16574 | catch_load_command_1, | |
16575 | NULL, | |
16576 | CATCH_PERMANENT, | |
16577 | CATCH_TEMPORARY); | |
16578 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16579 | Usage: catch unload [REGEX]\n\ | |
16580 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16581 | catch_unload_command_1, | |
16582 | NULL, | |
16583 | CATCH_PERMANENT, | |
16584 | CATCH_TEMPORARY); | |
a96d9b2e SDJ |
16585 | add_catch_command ("syscall", _("\ |
16586 | Catch system calls by their names and/or numbers.\n\ | |
16587 | Arguments say which system calls to catch. If no arguments\n\ | |
16588 | are given, every system call will be caught.\n\ | |
16589 | Arguments, if given, should be one or more system call names\n\ | |
16590 | (if your system supports that), or system call numbers."), | |
16591 | catch_syscall_command_1, | |
16592 | catch_syscall_completer, | |
44feb3ce TT |
16593 | CATCH_PERMANENT, |
16594 | CATCH_TEMPORARY); | |
c5aa993b | 16595 | |
1bedd215 AC |
16596 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16597 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16598 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16599 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16600 | an expression changes.\n\ |
16601 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16602 | the memory to which it refers.")); | |
65d12d83 | 16603 | set_cmd_completer (c, expression_completer); |
c906108c | 16604 | |
1bedd215 AC |
16605 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16606 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16607 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16608 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16609 | an expression is read.\n\ |
16610 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16611 | the memory to which it refers.")); | |
65d12d83 | 16612 | set_cmd_completer (c, expression_completer); |
c906108c | 16613 | |
1bedd215 AC |
16614 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16615 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16616 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16617 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16618 | an expression is either read or written.\n\ |
16619 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16620 | the memory to which it refers.")); | |
65d12d83 | 16621 | set_cmd_completer (c, expression_completer); |
c906108c | 16622 | |
d77f58be | 16623 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16624 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16625 | |
920d2a44 AC |
16626 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16627 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16628 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16629 | &can_use_hw_watchpoints, _("\ | |
16630 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16631 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16632 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16633 | such is available. (However, any hardware watchpoints that were\n\ | |
16634 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16635 | hardware.)"), |
16636 | NULL, | |
920d2a44 | 16637 | show_can_use_hw_watchpoints, |
85c07804 | 16638 | &setlist, &showlist); |
c906108c SS |
16639 | |
16640 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16641 | |
1042e4c0 SS |
16642 | /* Tracepoint manipulation commands. */ |
16643 | ||
16644 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
16645 | Set a tracepoint at specified line or function.\n\ | |
16646 | \n" | |
16647 | BREAK_ARGS_HELP ("trace") "\n\ | |
16648 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16649 | set_cmd_completer (c, location_completer); | |
16650 | ||
16651 | add_com_alias ("tp", "trace", class_alias, 0); | |
16652 | add_com_alias ("tr", "trace", class_alias, 1); | |
16653 | add_com_alias ("tra", "trace", class_alias, 1); | |
16654 | add_com_alias ("trac", "trace", class_alias, 1); | |
16655 | ||
7a697b8d SS |
16656 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
16657 | Set a fast tracepoint at specified line or function.\n\ | |
16658 | \n" | |
16659 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16660 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16661 | set_cmd_completer (c, location_completer); | |
16662 | ||
0fb4aa4b PA |
16663 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
16664 | Set a static tracepoint at specified line, function or marker.\n\ | |
16665 | \n\ | |
16666 | strace [LOCATION] [if CONDITION]\n\ | |
16667 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
16668 | or -m MARKER_ID.\n\ | |
16669 | If a line number is specified, probe the marker at start of code\n\ | |
16670 | for that line. If a function is specified, probe the marker at start\n\ | |
16671 | of code for that function. If an address is specified, probe the marker\n\ | |
16672 | at that exact address. If a marker id is specified, probe the marker\n\ | |
16673 | with that name. With no LOCATION, uses current execution address of\n\ | |
16674 | the selected stack frame.\n\ | |
16675 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
16676 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16677 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16678 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16679 | \n\ | |
16680 | CONDITION is a boolean expression.\n\ | |
16681 | \n\ | |
d41c0fc8 PA |
16682 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16683 | conditions are different.\n\ | |
0fb4aa4b PA |
16684 | \n\ |
16685 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16686 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16687 | set_cmd_completer (c, location_completer); | |
16688 | ||
1042e4c0 | 16689 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16690 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16691 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16692 | last tracepoint set.")); | |
16693 | ||
16694 | add_info_alias ("tp", "tracepoints", 1); | |
16695 | ||
16696 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16697 | Delete specified tracepoints.\n\ | |
16698 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16699 | No argument means delete all tracepoints."), | |
16700 | &deletelist); | |
7e20dfcd | 16701 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16702 | |
16703 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16704 | Disable specified tracepoints.\n\ | |
16705 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16706 | No argument means disable all tracepoints."), | |
16707 | &disablelist); | |
16708 | deprecate_cmd (c, "disable"); | |
16709 | ||
16710 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16711 | Enable specified tracepoints.\n\ | |
16712 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16713 | No argument means enable all tracepoints."), | |
16714 | &enablelist); | |
16715 | deprecate_cmd (c, "enable"); | |
16716 | ||
16717 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16718 | Set the passcount for a tracepoint.\n\ | |
16719 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16720 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16721 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16722 | ||
6149aea9 PA |
16723 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16724 | _("Save breakpoint definitions as a script."), | |
16725 | &save_cmdlist, "save ", | |
16726 | 0/*allow-unknown*/, &cmdlist); | |
16727 | ||
16728 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16729 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16730 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16731 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16732 | session to restore them."), | |
16733 | &save_cmdlist); | |
16734 | set_cmd_completer (c, filename_completer); | |
16735 | ||
16736 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16737 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16738 | Use the 'source' command in another debug session to restore them."), |
16739 | &save_cmdlist); | |
1042e4c0 SS |
16740 | set_cmd_completer (c, filename_completer); |
16741 | ||
6149aea9 PA |
16742 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16743 | deprecate_cmd (c, "save tracepoints"); | |
16744 | ||
1bedd215 | 16745 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16746 | Breakpoint specific settings\n\ |
16747 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16748 | pending breakpoint behavior"), |
fa8d40ab JJ |
16749 | &breakpoint_set_cmdlist, "set breakpoint ", |
16750 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16751 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16752 | Breakpoint specific settings\n\ |
16753 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16754 | pending breakpoint behavior"), |
fa8d40ab JJ |
16755 | &breakpoint_show_cmdlist, "show breakpoint ", |
16756 | 0/*allow-unknown*/, &showlist); | |
16757 | ||
7915a72c AC |
16758 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16759 | &pending_break_support, _("\ | |
16760 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16761 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16762 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16763 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16764 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16765 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16766 | NULL, |
920d2a44 | 16767 | show_pending_break_support, |
6e1d7d6c AC |
16768 | &breakpoint_set_cmdlist, |
16769 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16770 | |
16771 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16772 | |
16773 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16774 | &automatic_hardware_breakpoints, _("\ | |
16775 | Set automatic usage of hardware breakpoints."), _("\ | |
16776 | Show automatic usage of hardware breakpoints."), _("\ | |
16777 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16778 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16779 | a warning will be emitted for such breakpoints."), | |
16780 | NULL, | |
16781 | show_automatic_hardware_breakpoints, | |
16782 | &breakpoint_set_cmdlist, | |
16783 | &breakpoint_show_cmdlist); | |
74960c60 | 16784 | |
a25a5a45 PA |
16785 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16786 | &always_inserted_mode, _("\ | |
74960c60 VP |
16787 | Set mode for inserting breakpoints."), _("\ |
16788 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16789 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16790 | they're created, kept inserted even when execution stops, and removed\n\ | |
16791 | only when the user deletes them. When this mode is off (the default),\n\ | |
16792 | breakpoints are inserted only when execution continues, and removed\n\ | |
16793 | when execution stops."), | |
72d0e2c5 YQ |
16794 | NULL, |
16795 | &show_always_inserted_mode, | |
16796 | &breakpoint_set_cmdlist, | |
16797 | &breakpoint_show_cmdlist); | |
f1310107 | 16798 | |
b775012e LM |
16799 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16800 | condition_evaluation_enums, | |
16801 | &condition_evaluation_mode_1, _("\ | |
16802 | Set mode of breakpoint condition evaluation."), _("\ | |
16803 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16804 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16805 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16806 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16807 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16808 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16809 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16810 | be set to \"gdb\""), | |
16811 | &set_condition_evaluation_mode, | |
16812 | &show_condition_evaluation_mode, | |
16813 | &breakpoint_set_cmdlist, | |
16814 | &breakpoint_show_cmdlist); | |
16815 | ||
f1310107 TJB |
16816 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16817 | Set a breakpoint for an address range.\n\ | |
16818 | break-range START-LOCATION, END-LOCATION\n\ | |
16819 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16820 | LINENUM, for that line in the current file,\n\ | |
16821 | FILE:LINENUM, for that line in that file,\n\ | |
16822 | +OFFSET, for that number of lines after the current line\n\ | |
16823 | or the start of the range\n\ | |
16824 | FUNCTION, for the first line in that function,\n\ | |
16825 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16826 | *ADDRESS, for the instruction at that address.\n\ | |
16827 | \n\ | |
16828 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16829 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16830 | range (including START-LOCATION and END-LOCATION).")); | |
16831 | ||
e7e0cddf SS |
16832 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
16833 | Set a dynamic printf at specified line or function.\n\ | |
16834 | dprintf location,format string,arg1,arg2,...\n\ | |
16835 | location may be a line number, function name, or \"*\" and an address.\n\ | |
16836 | If a line number is specified, break at start of code for that line.\n\ | |
0e4777df | 16837 | If a function is specified, break at start of code for that function.")); |
e7e0cddf SS |
16838 | set_cmd_completer (c, location_completer); |
16839 | ||
16840 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16841 | dprintf_style_enums, &dprintf_style, _("\ | |
16842 | Set the style of usage for dynamic printf."), _("\ | |
16843 | Show the style of usage for dynamic printf."), _("\ | |
16844 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16845 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16846 | console, as with the \"printf\" command.\n\ | |
16847 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16848 | program; by default printf(), but you can choose a different function or\n\ | |
16849 | output stream by setting dprintf-function and dprintf-channel."), | |
16850 | update_dprintf_commands, NULL, | |
16851 | &setlist, &showlist); | |
16852 | ||
16853 | dprintf_function = xstrdup ("printf"); | |
16854 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16855 | &dprintf_function, _("\ | |
16856 | Set the function to use for dynamic printf"), _("\ | |
16857 | Show the function to use for dynamic printf"), NULL, | |
16858 | update_dprintf_commands, NULL, | |
16859 | &setlist, &showlist); | |
16860 | ||
16861 | dprintf_channel = xstrdup (""); | |
16862 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16863 | &dprintf_channel, _("\ | |
16864 | Set the channel to use for dynamic printf"), _("\ | |
16865 | Show the channel to use for dynamic printf"), NULL, | |
16866 | update_dprintf_commands, NULL, | |
16867 | &setlist, &showlist); | |
16868 | ||
d3ce09f5 SS |
16869 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16870 | &disconnected_dprintf, _("\ | |
16871 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16872 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16873 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16874 | even if GDB disconnects or detaches from the target."), | |
16875 | NULL, | |
16876 | NULL, | |
16877 | &setlist, &showlist); | |
16878 | ||
16879 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16880 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16881 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16882 | ||
765dc015 | 16883 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16884 | |
16885 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16886 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16887 | } |