Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 | 4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
7b6bb8da | 5 | 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
a6d9a66e | 23 | #include "arch-utils.h" |
c906108c | 24 | #include <ctype.h> |
776592bf | 25 | #include "hashtab.h" |
c906108c SS |
26 | #include "symtab.h" |
27 | #include "frame.h" | |
28 | #include "breakpoint.h" | |
1042e4c0 | 29 | #include "tracepoint.h" |
c906108c SS |
30 | #include "gdbtypes.h" |
31 | #include "expression.h" | |
32 | #include "gdbcore.h" | |
33 | #include "gdbcmd.h" | |
34 | #include "value.h" | |
35 | #include "command.h" | |
36 | #include "inferior.h" | |
37 | #include "gdbthread.h" | |
38 | #include "target.h" | |
39 | #include "language.h" | |
40 | #include "gdb_string.h" | |
50f182aa | 41 | #include "gdb-demangle.h" |
0ba1096a | 42 | #include "filenames.h" |
c906108c SS |
43 | #include "annotate.h" |
44 | #include "symfile.h" | |
45 | #include "objfiles.h" | |
0378c332 | 46 | #include "source.h" |
c5f0f3d0 | 47 | #include "linespec.h" |
c94fdfd0 | 48 | #include "completer.h" |
5b7f31a4 | 49 | #include "gdb.h" |
8b93c638 | 50 | #include "ui-out.h" |
e1507482 | 51 | #include "cli/cli-script.h" |
0225421b | 52 | #include "gdb_assert.h" |
fe898f56 | 53 | #include "block.h" |
a77053c2 | 54 | #include "solib.h" |
84acb35a JJ |
55 | #include "solist.h" |
56 | #include "observer.h" | |
60250e8b | 57 | #include "exceptions.h" |
765dc015 | 58 | #include "memattr.h" |
f7f9143b | 59 | #include "ada-lang.h" |
d1aa2f50 | 60 | #include "top.h" |
fa4727a6 | 61 | #include "wrapper.h" |
79a45b7d | 62 | #include "valprint.h" |
4efc6507 | 63 | #include "jit.h" |
a96d9b2e | 64 | #include "xml-syscall.h" |
65d79d4b | 65 | #include "parser-defs.h" |
e9cafbcc | 66 | #include "cli/cli-utils.h" |
be34f849 | 67 | #include "continuations.h" |
1bfeeb0f JL |
68 | #include "stack.h" |
69 | #include "skip.h" | |
c906108c | 70 | |
1042e4c0 SS |
71 | /* readline include files */ |
72 | #include "readline/readline.h" | |
73 | #include "readline/history.h" | |
74 | ||
75 | /* readline defines this. */ | |
76 | #undef savestring | |
77 | ||
034dad6f | 78 | #include "mi/mi-common.h" |
7371cf6d | 79 | #include "python/python.h" |
104c1213 | 80 | |
4a64f543 | 81 | /* Prototypes for local functions. */ |
c906108c | 82 | |
a14ed312 | 83 | static void enable_delete_command (char *, int); |
c906108c | 84 | |
a14ed312 | 85 | static void enable_once_command (char *, int); |
c906108c | 86 | |
a14ed312 | 87 | static void disable_command (char *, int); |
c906108c | 88 | |
a14ed312 | 89 | static void enable_command (char *, int); |
c906108c | 90 | |
95a42b64 TT |
91 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
92 | void *), | |
93 | void *); | |
c906108c | 94 | |
a14ed312 | 95 | static void ignore_command (char *, int); |
c906108c | 96 | |
4efb68b1 | 97 | static int breakpoint_re_set_one (void *); |
c906108c | 98 | |
348d480f PA |
99 | static void breakpoint_re_set_default (struct breakpoint *); |
100 | ||
a14ed312 | 101 | static void clear_command (char *, int); |
c906108c | 102 | |
a14ed312 | 103 | static void catch_command (char *, int); |
c906108c | 104 | |
a9634178 | 105 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 106 | |
98deb0da | 107 | static void break_command_1 (char *, int, int); |
c906108c | 108 | |
a14ed312 | 109 | static void mention (struct breakpoint *); |
c906108c | 110 | |
348d480f PA |
111 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
112 | enum bptype, | |
c0a91b2b | 113 | const struct breakpoint_ops *); |
3742cc8b YQ |
114 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
115 | const struct symtab_and_line *); | |
116 | ||
4a64f543 MS |
117 | /* This function is used in gdbtk sources and thus can not be made |
118 | static. */ | |
63c252f8 | 119 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 120 | struct symtab_and_line, |
c0a91b2b TT |
121 | enum bptype, |
122 | const struct breakpoint_ops *); | |
c906108c | 123 | |
06edf0c0 PA |
124 | static struct breakpoint * |
125 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
126 | enum bptype type, | |
c0a91b2b | 127 | const struct breakpoint_ops *ops); |
06edf0c0 | 128 | |
76897487 KB |
129 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
130 | ||
a6d9a66e UW |
131 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
132 | CORE_ADDR bpaddr, | |
88f7da05 | 133 | enum bptype bptype); |
76897487 | 134 | |
6c95b8df PA |
135 | static void describe_other_breakpoints (struct gdbarch *, |
136 | struct program_space *, CORE_ADDR, | |
5af949e3 | 137 | struct obj_section *, int); |
c906108c | 138 | |
6c95b8df PA |
139 | static int breakpoint_address_match (struct address_space *aspace1, |
140 | CORE_ADDR addr1, | |
141 | struct address_space *aspace2, | |
142 | CORE_ADDR addr2); | |
143 | ||
85d721b8 PA |
144 | static int watchpoint_locations_match (struct bp_location *loc1, |
145 | struct bp_location *loc2); | |
146 | ||
f1310107 TJB |
147 | static int breakpoint_location_address_match (struct bp_location *bl, |
148 | struct address_space *aspace, | |
149 | CORE_ADDR addr); | |
150 | ||
a14ed312 | 151 | static void breakpoints_info (char *, int); |
c906108c | 152 | |
d77f58be SS |
153 | static void watchpoints_info (char *, int); |
154 | ||
e5a67952 MS |
155 | static int breakpoint_1 (char *, int, |
156 | int (*) (const struct breakpoint *)); | |
c906108c | 157 | |
4efb68b1 | 158 | static int breakpoint_cond_eval (void *); |
c906108c | 159 | |
4efb68b1 | 160 | static void cleanup_executing_breakpoints (void *); |
c906108c | 161 | |
a14ed312 | 162 | static void commands_command (char *, int); |
c906108c | 163 | |
a14ed312 | 164 | static void condition_command (char *, int); |
c906108c | 165 | |
c5aa993b JM |
166 | typedef enum |
167 | { | |
168 | mark_inserted, | |
169 | mark_uninserted | |
170 | } | |
171 | insertion_state_t; | |
c906108c | 172 | |
0bde7532 | 173 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 174 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 175 | |
e514a9d6 | 176 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 177 | |
4efb68b1 | 178 | static int watchpoint_check (void *); |
c906108c | 179 | |
a14ed312 | 180 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 181 | |
a14ed312 | 182 | static int hw_breakpoint_used_count (void); |
c906108c | 183 | |
a1398e0c PA |
184 | static int hw_watchpoint_use_count (struct breakpoint *); |
185 | ||
186 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
187 | enum bptype type, | |
188 | int *other_type_used); | |
c906108c | 189 | |
a14ed312 | 190 | static void hbreak_command (char *, int); |
c906108c | 191 | |
a14ed312 | 192 | static void thbreak_command (char *, int); |
c906108c | 193 | |
51be5b68 | 194 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp); |
c906108c | 195 | |
a14ed312 | 196 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 197 | |
a14ed312 | 198 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 199 | |
a14ed312 | 200 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 201 | |
a14ed312 | 202 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 203 | |
d85310f7 MS |
204 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
205 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 206 | |
a14ed312 | 207 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 208 | |
d03285ec UW |
209 | static void detach_single_step_breakpoints (void); |
210 | ||
6c95b8df PA |
211 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
212 | CORE_ADDR pc); | |
1aafd4da | 213 | |
fe3f5fa8 | 214 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
215 | static void incref_bp_location (struct bp_location *loc); |
216 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 217 | |
39d61571 | 218 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 219 | |
b60e7edf | 220 | static void update_global_location_list (int); |
a5606eee | 221 | |
b60e7edf | 222 | static void update_global_location_list_nothrow (int); |
74960c60 | 223 | |
d77f58be | 224 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
225 | |
226 | static void insert_breakpoint_locations (void); | |
a5606eee | 227 | |
a96d9b2e SDJ |
228 | static int syscall_catchpoint_p (struct breakpoint *b); |
229 | ||
1042e4c0 SS |
230 | static void tracepoints_info (char *, int); |
231 | ||
232 | static void delete_trace_command (char *, int); | |
233 | ||
234 | static void enable_trace_command (char *, int); | |
235 | ||
236 | static void disable_trace_command (char *, int); | |
237 | ||
238 | static void trace_pass_command (char *, int); | |
239 | ||
9c06b0b4 TJB |
240 | static int is_masked_watchpoint (const struct breakpoint *b); |
241 | ||
0fb4aa4b PA |
242 | /* Assuming we're creating a static tracepoint, does S look like a |
243 | static tracepoint marker spec ("-m MARKER_ID")? */ | |
244 | #define is_marker_spec(s) \ | |
f5a8e22b | 245 | (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t')) |
0fb4aa4b | 246 | |
2060206e PA |
247 | /* The abstract base class all breakpoint_ops structures inherit |
248 | from. */ | |
249 | static struct breakpoint_ops base_breakpoint_ops; | |
250 | ||
251 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
252 | that are implemented on top of software or hardware breakpoints | |
253 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
254 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
255 | ||
256 | /* Internal breakpoints class type. */ | |
06edf0c0 | 257 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
258 | |
259 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
260 | static struct breakpoint_ops momentary_breakpoint_ops; |
261 | ||
2060206e PA |
262 | /* The breakpoint_ops structure to be used in regular user created |
263 | breakpoints. */ | |
264 | struct breakpoint_ops bkpt_breakpoint_ops; | |
265 | ||
5cea2a26 PA |
266 | /* A reference-counted struct command_line. This lets multiple |
267 | breakpoints share a single command list. */ | |
268 | struct counted_command_line | |
269 | { | |
270 | /* The reference count. */ | |
271 | int refc; | |
272 | ||
273 | /* The command list. */ | |
274 | struct command_line *commands; | |
275 | }; | |
276 | ||
277 | struct command_line * | |
278 | breakpoint_commands (struct breakpoint *b) | |
279 | { | |
280 | return b->commands ? b->commands->commands : NULL; | |
281 | } | |
3daf8fe5 | 282 | |
f3b1572e PA |
283 | /* Flag indicating that a command has proceeded the inferior past the |
284 | current breakpoint. */ | |
285 | ||
286 | static int breakpoint_proceeded; | |
287 | ||
956a9fb9 | 288 | const char * |
2cec12e5 AR |
289 | bpdisp_text (enum bpdisp disp) |
290 | { | |
4a64f543 MS |
291 | /* NOTE: the following values are a part of MI protocol and |
292 | represent values of 'disp' field returned when inferior stops at | |
293 | a breakpoint. */ | |
bc043ef3 | 294 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 295 | |
2cec12e5 AR |
296 | return bpdisps[(int) disp]; |
297 | } | |
c906108c | 298 | |
4a64f543 | 299 | /* Prototypes for exported functions. */ |
c906108c | 300 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 301 | if such is available. */ |
c906108c SS |
302 | static int can_use_hw_watchpoints; |
303 | ||
920d2a44 AC |
304 | static void |
305 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
306 | struct cmd_list_element *c, | |
307 | const char *value) | |
308 | { | |
3e43a32a MS |
309 | fprintf_filtered (file, |
310 | _("Debugger's willingness to use " | |
311 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
312 | value); |
313 | } | |
314 | ||
fa8d40ab JJ |
315 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
316 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 317 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
318 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
319 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
320 | static void |
321 | show_pending_break_support (struct ui_file *file, int from_tty, | |
322 | struct cmd_list_element *c, | |
323 | const char *value) | |
324 | { | |
3e43a32a MS |
325 | fprintf_filtered (file, |
326 | _("Debugger's behavior regarding " | |
327 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
328 | value); |
329 | } | |
fa8d40ab | 330 | |
765dc015 | 331 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 332 | set with "break" but falling in read-only memory. |
765dc015 VP |
333 | If 0, gdb will warn about such breakpoints, but won't automatically |
334 | use hardware breakpoints. */ | |
335 | static int automatic_hardware_breakpoints; | |
336 | static void | |
337 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
338 | struct cmd_list_element *c, | |
339 | const char *value) | |
340 | { | |
3e43a32a MS |
341 | fprintf_filtered (file, |
342 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
343 | value); |
344 | } | |
345 | ||
33e5cbd6 PA |
346 | /* If on, gdb will keep breakpoints inserted even as inferior is |
347 | stopped, and immediately insert any new breakpoints. If off, gdb | |
348 | will insert breakpoints into inferior only when resuming it, and | |
349 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
350 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
351 | ||
352 | static const char always_inserted_auto[] = "auto"; | |
353 | static const char always_inserted_on[] = "on"; | |
354 | static const char always_inserted_off[] = "off"; | |
355 | static const char *always_inserted_enums[] = { | |
356 | always_inserted_auto, | |
357 | always_inserted_off, | |
358 | always_inserted_on, | |
359 | NULL | |
360 | }; | |
361 | static const char *always_inserted_mode = always_inserted_auto; | |
362 | static void | |
74960c60 | 363 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 364 | struct cmd_list_element *c, const char *value) |
74960c60 | 365 | { |
33e5cbd6 | 366 | if (always_inserted_mode == always_inserted_auto) |
3e43a32a MS |
367 | fprintf_filtered (file, |
368 | _("Always inserted breakpoint " | |
369 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
370 | value, |
371 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
372 | else | |
3e43a32a MS |
373 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
374 | value); | |
74960c60 VP |
375 | } |
376 | ||
33e5cbd6 PA |
377 | int |
378 | breakpoints_always_inserted_mode (void) | |
379 | { | |
380 | return (always_inserted_mode == always_inserted_on | |
381 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
382 | } | |
765dc015 | 383 | |
a14ed312 | 384 | void _initialize_breakpoint (void); |
c906108c | 385 | |
c906108c SS |
386 | /* Are we executing breakpoint commands? */ |
387 | static int executing_breakpoint_commands; | |
388 | ||
c02f5703 MS |
389 | /* Are overlay event breakpoints enabled? */ |
390 | static int overlay_events_enabled; | |
391 | ||
e09342b5 TJB |
392 | /* See description in breakpoint.h. */ |
393 | int target_exact_watchpoints = 0; | |
394 | ||
c906108c | 395 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 396 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 397 | current breakpoint. */ |
c906108c | 398 | |
5c44784c | 399 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 400 | |
5c44784c JM |
401 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
402 | for (B = breakpoint_chain; \ | |
403 | B ? (TMP=B->next, 1): 0; \ | |
404 | B = TMP) | |
c906108c | 405 | |
4a64f543 MS |
406 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
407 | not provided so update_global_location_list must not be called | |
408 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 409 | |
876fa593 JK |
410 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
411 | for (BP_TMP = bp_location; \ | |
412 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
413 | BP_TMP++) | |
7cc221ef | 414 | |
1042e4c0 SS |
415 | /* Iterator for tracepoints only. */ |
416 | ||
417 | #define ALL_TRACEPOINTS(B) \ | |
418 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 419 | if (is_tracepoint (B)) |
1042e4c0 | 420 | |
7cc221ef | 421 | /* Chains of all breakpoints defined. */ |
c906108c SS |
422 | |
423 | struct breakpoint *breakpoint_chain; | |
424 | ||
876fa593 JK |
425 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
426 | ||
427 | static struct bp_location **bp_location; | |
428 | ||
429 | /* Number of elements of BP_LOCATION. */ | |
430 | ||
431 | static unsigned bp_location_count; | |
432 | ||
4a64f543 MS |
433 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
434 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
435 | result from bp_location_has_shadow. You can use it for roughly | |
436 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
437 | an address you need to read. */ | |
876fa593 JK |
438 | |
439 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
440 | ||
4a64f543 MS |
441 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
442 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
443 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
444 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
445 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
446 | |
447 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 448 | |
4a64f543 MS |
449 | /* The locations that no longer correspond to any breakpoint, unlinked |
450 | from bp_location array, but for which a hit may still be reported | |
451 | by a target. */ | |
20874c92 VP |
452 | VEC(bp_location_p) *moribund_locations = NULL; |
453 | ||
c906108c SS |
454 | /* Number of last breakpoint made. */ |
455 | ||
95a42b64 TT |
456 | static int breakpoint_count; |
457 | ||
86b17b60 PA |
458 | /* The value of `breakpoint_count' before the last command that |
459 | created breakpoints. If the last (break-like) command created more | |
460 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
461 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
462 | static int prev_breakpoint_count; | |
c906108c | 463 | |
1042e4c0 SS |
464 | /* Number of last tracepoint made. */ |
465 | ||
95a42b64 | 466 | static int tracepoint_count; |
1042e4c0 | 467 | |
6149aea9 PA |
468 | static struct cmd_list_element *breakpoint_set_cmdlist; |
469 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 470 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 471 | |
468d015d JJ |
472 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
473 | static int | |
474 | breakpoint_enabled (struct breakpoint *b) | |
475 | { | |
0d381245 | 476 | return (b->enable_state == bp_enabled); |
468d015d JJ |
477 | } |
478 | ||
c906108c SS |
479 | /* Set breakpoint count to NUM. */ |
480 | ||
95a42b64 | 481 | static void |
fba45db2 | 482 | set_breakpoint_count (int num) |
c906108c | 483 | { |
86b17b60 | 484 | prev_breakpoint_count = breakpoint_count; |
c906108c | 485 | breakpoint_count = num; |
4fa62494 | 486 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
487 | } |
488 | ||
86b17b60 PA |
489 | /* Used by `start_rbreak_breakpoints' below, to record the current |
490 | breakpoint count before "rbreak" creates any breakpoint. */ | |
491 | static int rbreak_start_breakpoint_count; | |
492 | ||
95a42b64 TT |
493 | /* Called at the start an "rbreak" command to record the first |
494 | breakpoint made. */ | |
86b17b60 | 495 | |
95a42b64 TT |
496 | void |
497 | start_rbreak_breakpoints (void) | |
498 | { | |
86b17b60 | 499 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
500 | } |
501 | ||
502 | /* Called at the end of an "rbreak" command to record the last | |
503 | breakpoint made. */ | |
86b17b60 | 504 | |
95a42b64 TT |
505 | void |
506 | end_rbreak_breakpoints (void) | |
507 | { | |
86b17b60 | 508 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
509 | } |
510 | ||
4a64f543 | 511 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
512 | |
513 | void | |
fba45db2 | 514 | clear_breakpoint_hit_counts (void) |
c906108c SS |
515 | { |
516 | struct breakpoint *b; | |
517 | ||
518 | ALL_BREAKPOINTS (b) | |
519 | b->hit_count = 0; | |
520 | } | |
521 | ||
9add0f1b TT |
522 | /* Allocate a new counted_command_line with reference count of 1. |
523 | The new structure owns COMMANDS. */ | |
524 | ||
525 | static struct counted_command_line * | |
526 | alloc_counted_command_line (struct command_line *commands) | |
527 | { | |
528 | struct counted_command_line *result | |
529 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 530 | |
9add0f1b TT |
531 | result->refc = 1; |
532 | result->commands = commands; | |
533 | return result; | |
534 | } | |
535 | ||
536 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
537 | ||
538 | static void | |
539 | incref_counted_command_line (struct counted_command_line *cmd) | |
540 | { | |
541 | if (cmd) | |
542 | ++cmd->refc; | |
543 | } | |
544 | ||
545 | /* Decrement reference count. If the reference count reaches 0, | |
546 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
547 | nothing if *CMDP is NULL. */ | |
548 | ||
549 | static void | |
550 | decref_counted_command_line (struct counted_command_line **cmdp) | |
551 | { | |
552 | if (*cmdp) | |
553 | { | |
554 | if (--(*cmdp)->refc == 0) | |
555 | { | |
556 | free_command_lines (&(*cmdp)->commands); | |
557 | xfree (*cmdp); | |
558 | } | |
559 | *cmdp = NULL; | |
560 | } | |
561 | } | |
562 | ||
563 | /* A cleanup function that calls decref_counted_command_line. */ | |
564 | ||
565 | static void | |
566 | do_cleanup_counted_command_line (void *arg) | |
567 | { | |
568 | decref_counted_command_line (arg); | |
569 | } | |
570 | ||
571 | /* Create a cleanup that calls decref_counted_command_line on the | |
572 | argument. */ | |
573 | ||
574 | static struct cleanup * | |
575 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
576 | { | |
577 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
578 | } | |
579 | ||
c906108c | 580 | \f |
48cb2d85 VP |
581 | /* Return the breakpoint with the specified number, or NULL |
582 | if the number does not refer to an existing breakpoint. */ | |
583 | ||
584 | struct breakpoint * | |
585 | get_breakpoint (int num) | |
586 | { | |
587 | struct breakpoint *b; | |
588 | ||
589 | ALL_BREAKPOINTS (b) | |
590 | if (b->number == num) | |
591 | return b; | |
592 | ||
593 | return NULL; | |
594 | } | |
5c44784c | 595 | |
c906108c | 596 | \f |
adc36818 PM |
597 | |
598 | void | |
599 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
600 | int from_tty) | |
601 | { | |
3a5c3e22 PA |
602 | xfree (b->cond_string); |
603 | b->cond_string = NULL; | |
adc36818 | 604 | |
3a5c3e22 | 605 | if (is_watchpoint (b)) |
adc36818 | 606 | { |
3a5c3e22 PA |
607 | struct watchpoint *w = (struct watchpoint *) b; |
608 | ||
609 | xfree (w->cond_exp); | |
610 | w->cond_exp = NULL; | |
611 | } | |
612 | else | |
613 | { | |
614 | struct bp_location *loc; | |
615 | ||
616 | for (loc = b->loc; loc; loc = loc->next) | |
617 | { | |
618 | xfree (loc->cond); | |
619 | loc->cond = NULL; | |
620 | } | |
adc36818 | 621 | } |
adc36818 PM |
622 | |
623 | if (*exp == 0) | |
624 | { | |
625 | if (from_tty) | |
626 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
627 | } | |
628 | else | |
629 | { | |
630 | char *arg = exp; | |
cc59ec59 | 631 | |
adc36818 PM |
632 | /* I don't know if it matters whether this is the string the user |
633 | typed in or the decompiled expression. */ | |
634 | b->cond_string = xstrdup (arg); | |
635 | b->condition_not_parsed = 0; | |
636 | ||
637 | if (is_watchpoint (b)) | |
638 | { | |
3a5c3e22 PA |
639 | struct watchpoint *w = (struct watchpoint *) b; |
640 | ||
adc36818 PM |
641 | innermost_block = NULL; |
642 | arg = exp; | |
3a5c3e22 | 643 | w->cond_exp = parse_exp_1 (&arg, 0, 0); |
adc36818 PM |
644 | if (*arg) |
645 | error (_("Junk at end of expression")); | |
3a5c3e22 | 646 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
647 | } |
648 | else | |
649 | { | |
3a5c3e22 PA |
650 | struct bp_location *loc; |
651 | ||
adc36818 PM |
652 | for (loc = b->loc; loc; loc = loc->next) |
653 | { | |
654 | arg = exp; | |
655 | loc->cond = | |
656 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
657 | if (*arg) | |
658 | error (_("Junk at end of expression")); | |
659 | } | |
660 | } | |
661 | } | |
662 | breakpoints_changed (); | |
8d3788bd | 663 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
664 | } |
665 | ||
c906108c SS |
666 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
667 | ||
668 | static void | |
fba45db2 | 669 | condition_command (char *arg, int from_tty) |
c906108c | 670 | { |
52f0bd74 | 671 | struct breakpoint *b; |
c906108c | 672 | char *p; |
52f0bd74 | 673 | int bnum; |
c906108c SS |
674 | |
675 | if (arg == 0) | |
e2e0b3e5 | 676 | error_no_arg (_("breakpoint number")); |
c906108c SS |
677 | |
678 | p = arg; | |
679 | bnum = get_number (&p); | |
5c44784c | 680 | if (bnum == 0) |
8a3fe4f8 | 681 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
682 | |
683 | ALL_BREAKPOINTS (b) | |
684 | if (b->number == bnum) | |
2f069f6f | 685 | { |
7371cf6d PM |
686 | /* Check if this breakpoint has a Python object assigned to |
687 | it, and if it has a definition of the "stop" | |
688 | method. This method and conditions entered into GDB from | |
689 | the CLI are mutually exclusive. */ | |
690 | if (b->py_bp_object | |
691 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
692 | error (_("Cannot set a condition where a Python 'stop' " | |
693 | "method has been defined in the breakpoint.")); | |
2566ad2d | 694 | set_breakpoint_condition (b, p, from_tty); |
2f069f6f JB |
695 | return; |
696 | } | |
c906108c | 697 | |
8a3fe4f8 | 698 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
699 | } |
700 | ||
a7bdde9e VP |
701 | /* Check that COMMAND do not contain commands that are suitable |
702 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
703 | Throw if any such commands is found. */ |
704 | ||
a7bdde9e VP |
705 | static void |
706 | check_no_tracepoint_commands (struct command_line *commands) | |
707 | { | |
708 | struct command_line *c; | |
cc59ec59 | 709 | |
a7bdde9e VP |
710 | for (c = commands; c; c = c->next) |
711 | { | |
712 | int i; | |
713 | ||
714 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
715 | error (_("The 'while-stepping' command can " |
716 | "only be used for tracepoints")); | |
a7bdde9e VP |
717 | |
718 | for (i = 0; i < c->body_count; ++i) | |
719 | check_no_tracepoint_commands ((c->body_list)[i]); | |
720 | ||
721 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 722 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
723 | command directly. */ |
724 | if (strstr (c->line, "collect ") == c->line) | |
725 | error (_("The 'collect' command can only be used for tracepoints")); | |
726 | ||
51661e93 VP |
727 | if (strstr (c->line, "teval ") == c->line) |
728 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
729 | } |
730 | } | |
731 | ||
d77f58be SS |
732 | /* Encapsulate tests for different types of tracepoints. */ |
733 | ||
d9b3f62e PA |
734 | static int |
735 | is_tracepoint_type (enum bptype type) | |
736 | { | |
737 | return (type == bp_tracepoint | |
738 | || type == bp_fast_tracepoint | |
739 | || type == bp_static_tracepoint); | |
740 | } | |
741 | ||
a7bdde9e | 742 | int |
d77f58be | 743 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 744 | { |
d9b3f62e | 745 | return is_tracepoint_type (b->type); |
a7bdde9e | 746 | } |
d9b3f62e | 747 | |
e5dd4106 | 748 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
749 | breakpoint. This function will throw an exception if a problem is |
750 | found. */ | |
48cb2d85 | 751 | |
95a42b64 TT |
752 | static void |
753 | validate_commands_for_breakpoint (struct breakpoint *b, | |
754 | struct command_line *commands) | |
48cb2d85 | 755 | { |
d77f58be | 756 | if (is_tracepoint (b)) |
a7bdde9e | 757 | { |
4a64f543 MS |
758 | /* We need to verify that each top-level element of commands is |
759 | valid for tracepoints, that there's at most one | |
760 | while-stepping element, and that while-stepping's body has | |
761 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
762 | struct command_line *c; |
763 | struct command_line *while_stepping = 0; | |
764 | for (c = commands; c; c = c->next) | |
765 | { | |
a7bdde9e VP |
766 | if (c->control_type == while_stepping_control) |
767 | { | |
768 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
769 | error (_("The 'while-stepping' command " |
770 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 771 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
772 | error (_("The 'while-stepping' command " |
773 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
774 | |
775 | if (while_stepping) | |
3e43a32a MS |
776 | error (_("The 'while-stepping' command " |
777 | "can be used only once")); | |
a7bdde9e VP |
778 | else |
779 | while_stepping = c; | |
780 | } | |
781 | } | |
782 | if (while_stepping) | |
783 | { | |
784 | struct command_line *c2; | |
785 | ||
786 | gdb_assert (while_stepping->body_count == 1); | |
787 | c2 = while_stepping->body_list[0]; | |
788 | for (; c2; c2 = c2->next) | |
789 | { | |
a7bdde9e VP |
790 | if (c2->control_type == while_stepping_control) |
791 | error (_("The 'while-stepping' command cannot be nested")); | |
792 | } | |
793 | } | |
794 | } | |
795 | else | |
796 | { | |
797 | check_no_tracepoint_commands (commands); | |
798 | } | |
95a42b64 TT |
799 | } |
800 | ||
0fb4aa4b PA |
801 | /* Return a vector of all the static tracepoints set at ADDR. The |
802 | caller is responsible for releasing the vector. */ | |
803 | ||
804 | VEC(breakpoint_p) * | |
805 | static_tracepoints_here (CORE_ADDR addr) | |
806 | { | |
807 | struct breakpoint *b; | |
808 | VEC(breakpoint_p) *found = 0; | |
809 | struct bp_location *loc; | |
810 | ||
811 | ALL_BREAKPOINTS (b) | |
812 | if (b->type == bp_static_tracepoint) | |
813 | { | |
814 | for (loc = b->loc; loc; loc = loc->next) | |
815 | if (loc->address == addr) | |
816 | VEC_safe_push(breakpoint_p, found, b); | |
817 | } | |
818 | ||
819 | return found; | |
820 | } | |
821 | ||
95a42b64 | 822 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 823 | validate that only allowed commands are included. */ |
95a42b64 TT |
824 | |
825 | void | |
4a64f543 MS |
826 | breakpoint_set_commands (struct breakpoint *b, |
827 | struct command_line *commands) | |
95a42b64 TT |
828 | { |
829 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 830 | |
9add0f1b TT |
831 | decref_counted_command_line (&b->commands); |
832 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 | 833 | breakpoints_changed (); |
8d3788bd | 834 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
835 | } |
836 | ||
45a43567 TT |
837 | /* Set the internal `silent' flag on the breakpoint. Note that this |
838 | is not the same as the "silent" that may appear in the breakpoint's | |
839 | commands. */ | |
840 | ||
841 | void | |
842 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
843 | { | |
844 | int old_silent = b->silent; | |
845 | ||
846 | b->silent = silent; | |
847 | if (old_silent != silent) | |
8d3788bd | 848 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
849 | } |
850 | ||
851 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
852 | breakpoint work for any thread. */ | |
853 | ||
854 | void | |
855 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
856 | { | |
857 | int old_thread = b->thread; | |
858 | ||
859 | b->thread = thread; | |
860 | if (old_thread != thread) | |
8d3788bd | 861 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
862 | } |
863 | ||
864 | /* Set the task for this breakpoint. If TASK is 0, make the | |
865 | breakpoint work for any task. */ | |
866 | ||
867 | void | |
868 | breakpoint_set_task (struct breakpoint *b, int task) | |
869 | { | |
870 | int old_task = b->task; | |
871 | ||
872 | b->task = task; | |
873 | if (old_task != task) | |
8d3788bd | 874 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
875 | } |
876 | ||
95a42b64 TT |
877 | void |
878 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
879 | { |
880 | struct breakpoint *b = closure; | |
cc59ec59 | 881 | |
a7bdde9e VP |
882 | validate_actionline (&line, b); |
883 | } | |
884 | ||
95a42b64 TT |
885 | /* A structure used to pass information through |
886 | map_breakpoint_numbers. */ | |
887 | ||
888 | struct commands_info | |
889 | { | |
890 | /* True if the command was typed at a tty. */ | |
891 | int from_tty; | |
86b17b60 PA |
892 | |
893 | /* The breakpoint range spec. */ | |
894 | char *arg; | |
895 | ||
95a42b64 TT |
896 | /* Non-NULL if the body of the commands are being read from this |
897 | already-parsed command. */ | |
898 | struct command_line *control; | |
86b17b60 | 899 | |
95a42b64 TT |
900 | /* The command lines read from the user, or NULL if they have not |
901 | yet been read. */ | |
902 | struct counted_command_line *cmd; | |
903 | }; | |
904 | ||
905 | /* A callback for map_breakpoint_numbers that sets the commands for | |
906 | commands_command. */ | |
907 | ||
c906108c | 908 | static void |
95a42b64 | 909 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 910 | { |
95a42b64 | 911 | struct commands_info *info = data; |
c906108c | 912 | |
95a42b64 TT |
913 | if (info->cmd == NULL) |
914 | { | |
915 | struct command_line *l; | |
5c44784c | 916 | |
95a42b64 TT |
917 | if (info->control != NULL) |
918 | l = copy_command_lines (info->control->body_list[0]); | |
919 | else | |
86b17b60 PA |
920 | { |
921 | struct cleanup *old_chain; | |
922 | char *str; | |
c5aa993b | 923 | |
3e43a32a MS |
924 | str = xstrprintf (_("Type commands for breakpoint(s) " |
925 | "%s, one per line."), | |
86b17b60 PA |
926 | info->arg); |
927 | ||
928 | old_chain = make_cleanup (xfree, str); | |
929 | ||
930 | l = read_command_lines (str, | |
931 | info->from_tty, 1, | |
d77f58be | 932 | (is_tracepoint (b) |
86b17b60 PA |
933 | ? check_tracepoint_command : 0), |
934 | b); | |
935 | ||
936 | do_cleanups (old_chain); | |
937 | } | |
a7bdde9e | 938 | |
95a42b64 TT |
939 | info->cmd = alloc_counted_command_line (l); |
940 | } | |
941 | ||
942 | /* If a breakpoint was on the list more than once, we don't need to | |
943 | do anything. */ | |
944 | if (b->commands != info->cmd) | |
945 | { | |
946 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
947 | incref_counted_command_line (info->cmd); | |
948 | decref_counted_command_line (&b->commands); | |
949 | b->commands = info->cmd; | |
950 | breakpoints_changed (); | |
8d3788bd | 951 | observer_notify_breakpoint_modified (b); |
c5aa993b | 952 | } |
95a42b64 TT |
953 | } |
954 | ||
955 | static void | |
4a64f543 MS |
956 | commands_command_1 (char *arg, int from_tty, |
957 | struct command_line *control) | |
95a42b64 TT |
958 | { |
959 | struct cleanup *cleanups; | |
960 | struct commands_info info; | |
961 | ||
962 | info.from_tty = from_tty; | |
963 | info.control = control; | |
964 | info.cmd = NULL; | |
965 | /* If we read command lines from the user, then `info' will hold an | |
966 | extra reference to the commands that we must clean up. */ | |
967 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
968 | ||
969 | if (arg == NULL || !*arg) | |
970 | { | |
86b17b60 | 971 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
972 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
973 | breakpoint_count); | |
95a42b64 TT |
974 | else if (breakpoint_count > 0) |
975 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
976 | else |
977 | { | |
978 | /* So that we don't try to free the incoming non-NULL | |
979 | argument in the cleanup below. Mapping breakpoint | |
980 | numbers will fail in this case. */ | |
981 | arg = NULL; | |
982 | } | |
95a42b64 | 983 | } |
9766ced4 SS |
984 | else |
985 | /* The command loop has some static state, so we need to preserve | |
986 | our argument. */ | |
987 | arg = xstrdup (arg); | |
86b17b60 PA |
988 | |
989 | if (arg != NULL) | |
990 | make_cleanup (xfree, arg); | |
991 | ||
992 | info.arg = arg; | |
95a42b64 TT |
993 | |
994 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
995 | ||
996 | if (info.cmd == NULL) | |
997 | error (_("No breakpoints specified.")); | |
998 | ||
999 | do_cleanups (cleanups); | |
1000 | } | |
1001 | ||
1002 | static void | |
1003 | commands_command (char *arg, int from_tty) | |
1004 | { | |
1005 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1006 | } |
40c03ae8 EZ |
1007 | |
1008 | /* Like commands_command, but instead of reading the commands from | |
1009 | input stream, takes them from an already parsed command structure. | |
1010 | ||
1011 | This is used by cli-script.c to DTRT with breakpoint commands | |
1012 | that are part of if and while bodies. */ | |
1013 | enum command_control_type | |
1014 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1015 | { | |
95a42b64 TT |
1016 | commands_command_1 (arg, 0, cmd); |
1017 | return simple_control; | |
40c03ae8 | 1018 | } |
876fa593 JK |
1019 | |
1020 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1021 | ||
1022 | static int | |
1023 | bp_location_has_shadow (struct bp_location *bl) | |
1024 | { | |
1025 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1026 | return 0; | |
1027 | if (!bl->inserted) | |
1028 | return 0; | |
1029 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1030 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1031 | return 0; |
1032 | return 1; | |
1033 | } | |
1034 | ||
8defab1a | 1035 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1036 | by replacing any memory breakpoints with their shadowed contents. |
1037 | ||
1038 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
1039 | bl->address - bp_location_placed_address_before_address_max |
1040 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1041 | The range we were requested to resolve shadows for is: |
1042 | memaddr ... memaddr + len | |
1043 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1044 | memaddr + len <= (bl->address |
1045 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1046 | and: |
35df4500 | 1047 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1048 | |
8defab1a DJ |
1049 | void |
1050 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1051 | { |
4a64f543 MS |
1052 | /* Left boundary, right boundary and median element of our binary |
1053 | search. */ | |
876fa593 JK |
1054 | unsigned bc_l, bc_r, bc; |
1055 | ||
4a64f543 MS |
1056 | /* Find BC_L which is a leftmost element which may affect BUF |
1057 | content. It is safe to report lower value but a failure to | |
1058 | report higher one. */ | |
876fa593 JK |
1059 | |
1060 | bc_l = 0; | |
1061 | bc_r = bp_location_count; | |
1062 | while (bc_l + 1 < bc_r) | |
1063 | { | |
35df4500 | 1064 | struct bp_location *bl; |
876fa593 JK |
1065 | |
1066 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1067 | bl = bp_location[bc]; |
876fa593 | 1068 | |
4a64f543 MS |
1069 | /* Check first BL->ADDRESS will not overflow due to the added |
1070 | constant. Then advance the left boundary only if we are sure | |
1071 | the BC element can in no way affect the BUF content (MEMADDR | |
1072 | to MEMADDR + LEN range). | |
876fa593 | 1073 | |
4a64f543 MS |
1074 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1075 | offset so that we cannot miss a breakpoint with its shadow | |
1076 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1077 | |
35df4500 TJB |
1078 | if ((bl->address + bp_location_shadow_len_after_address_max |
1079 | >= bl->address) | |
1080 | && (bl->address + bp_location_shadow_len_after_address_max | |
1081 | <= memaddr)) | |
876fa593 JK |
1082 | bc_l = bc; |
1083 | else | |
1084 | bc_r = bc; | |
1085 | } | |
1086 | ||
128070bb PA |
1087 | /* Due to the binary search above, we need to make sure we pick the |
1088 | first location that's at BC_L's address. E.g., if there are | |
1089 | multiple locations at the same address, BC_L may end up pointing | |
1090 | at a duplicate location, and miss the "master"/"inserted" | |
1091 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1092 | B: | |
1093 | ||
1094 | L1@A, L2@A, L3@B, ... | |
1095 | ||
1096 | BC_L could end up pointing at location L2, while the "master" | |
1097 | location could be L1. Since the `loc->inserted' flag is only set | |
1098 | on "master" locations, we'd forget to restore the shadow of L1 | |
1099 | and L2. */ | |
1100 | while (bc_l > 0 | |
1101 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1102 | bc_l--; | |
1103 | ||
876fa593 JK |
1104 | /* Now do full processing of the found relevant range of elements. */ |
1105 | ||
1106 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1107 | { |
35df4500 | 1108 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1109 | CORE_ADDR bp_addr = 0; |
1110 | int bp_size = 0; | |
1111 | int bptoffset = 0; | |
1112 | ||
35df4500 TJB |
1113 | /* bp_location array has BL->OWNER always non-NULL. */ |
1114 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1115 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1116 | bl->owner->number); |
ffce0d52 | 1117 | |
e5dd4106 | 1118 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1119 | content. */ |
1120 | ||
35df4500 TJB |
1121 | if (bl->address >= bp_location_placed_address_before_address_max |
1122 | && memaddr + len <= (bl->address | |
1123 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1124 | break; |
1125 | ||
35df4500 | 1126 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1127 | continue; |
35df4500 | 1128 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1129 | current_program_space->aspace, 0)) |
1130 | continue; | |
1131 | ||
c5aa993b JM |
1132 | /* Addresses and length of the part of the breakpoint that |
1133 | we need to copy. */ | |
35df4500 TJB |
1134 | bp_addr = bl->target_info.placed_address; |
1135 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1136 | |
c5aa993b JM |
1137 | if (bp_addr + bp_size <= memaddr) |
1138 | /* The breakpoint is entirely before the chunk of memory we | |
1139 | are reading. */ | |
1140 | continue; | |
8defab1a | 1141 | |
c5aa993b JM |
1142 | if (bp_addr >= memaddr + len) |
1143 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1144 | reading. */ |
c5aa993b | 1145 | continue; |
c5aa993b | 1146 | |
8defab1a DJ |
1147 | /* Offset within shadow_contents. */ |
1148 | if (bp_addr < memaddr) | |
1149 | { | |
1150 | /* Only copy the second part of the breakpoint. */ | |
1151 | bp_size -= memaddr - bp_addr; | |
1152 | bptoffset = memaddr - bp_addr; | |
1153 | bp_addr = memaddr; | |
1154 | } | |
c5aa993b | 1155 | |
8defab1a DJ |
1156 | if (bp_addr + bp_size > memaddr + len) |
1157 | { | |
1158 | /* Only copy the first part of the breakpoint. */ | |
1159 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1160 | } | |
c5aa993b | 1161 | |
8defab1a | 1162 | memcpy (buf + bp_addr - memaddr, |
35df4500 | 1163 | bl->target_info.shadow_contents + bptoffset, bp_size); |
c5aa993b | 1164 | } |
c906108c | 1165 | } |
c906108c | 1166 | \f |
c5aa993b | 1167 | |
60e1c644 PA |
1168 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1169 | ||
a5606eee | 1170 | static int |
d77f58be | 1171 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1172 | { |
1173 | return (bpt->type == bp_hardware_watchpoint | |
1174 | || bpt->type == bp_read_watchpoint | |
1175 | || bpt->type == bp_access_watchpoint); | |
1176 | } | |
7270d8f2 | 1177 | |
60e1c644 PA |
1178 | /* Return true if BPT is of any watchpoint kind, hardware or |
1179 | software. */ | |
1180 | ||
3a5c3e22 | 1181 | int |
d77f58be | 1182 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1183 | { |
1184 | return (is_hardware_watchpoint (bpt) | |
1185 | || bpt->type == bp_watchpoint); | |
1186 | } | |
1187 | ||
3a5c3e22 PA |
1188 | /* Returns true if the current thread and its running state are safe |
1189 | to evaluate or update watchpoint B. Watchpoints on local | |
1190 | expressions need to be evaluated in the context of the thread that | |
1191 | was current when the watchpoint was created, and, that thread needs | |
1192 | to be stopped to be able to select the correct frame context. | |
1193 | Watchpoints on global expressions can be evaluated on any thread, | |
1194 | and in any state. It is presently left to the target allowing | |
1195 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1196 | |
1197 | static int | |
3a5c3e22 | 1198 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 PA |
1199 | { |
1200 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1201 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1202 | && !is_executing (inferior_ptid))); | |
1203 | } | |
1204 | ||
d0fb5eae JK |
1205 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1206 | associated bp_watchpoint_scope breakpoint. */ | |
1207 | ||
1208 | static void | |
3a5c3e22 | 1209 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1210 | { |
3a5c3e22 | 1211 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1212 | |
1213 | if (b->related_breakpoint != b) | |
1214 | { | |
1215 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1216 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1217 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1218 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1219 | b->related_breakpoint = b; | |
1220 | } | |
1221 | b->disposition = disp_del_at_next_stop; | |
1222 | } | |
1223 | ||
567e1b4e JB |
1224 | /* Assuming that B is a watchpoint: |
1225 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1226 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1227 | - Evaluate the condition if there is one, and store the result |
1228 | in b->loc->cond. | |
a5606eee VP |
1229 | - Update the list of values that must be watched in B->loc. |
1230 | ||
4a64f543 MS |
1231 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1232 | nothing. If this is local watchpoint that is out of scope, delete | |
1233 | it. | |
1234 | ||
1235 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1236 | removed + inserted on each stop here. Normal breakpoints must | |
1237 | never be removed because they might be missed by a running thread | |
1238 | when debugging in non-stop mode. On the other hand, hardware | |
1239 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1240 | to each LWP since they are stored in each LWP's hardware debug | |
1241 | registers. Therefore, such LWP must be stopped first in order to | |
1242 | be able to modify its hardware watchpoints. | |
1243 | ||
1244 | Hardware watchpoints must be reset exactly once after being | |
1245 | presented to the user. It cannot be done sooner, because it would | |
1246 | reset the data used to present the watchpoint hit to the user. And | |
1247 | it must not be done later because it could display the same single | |
1248 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1249 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1250 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1251 | not user-visible - its hit is suppressed if the memory content has | |
1252 | not changed. | |
1253 | ||
1254 | The following constraints influence the location where we can reset | |
1255 | hardware watchpoints: | |
1256 | ||
1257 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1258 | called several times when GDB stops. | |
1259 | ||
1260 | [linux] | |
1261 | * Multiple hardware watchpoints can be hit at the same time, | |
1262 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1263 | hit at a time as the reason for stopping, and all the other hits | |
1264 | are presented later, one after the other, each time the user | |
1265 | requests the execution to be resumed. Execution is not resumed | |
1266 | for the threads still having pending hit event stored in | |
1267 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1268 | the inferior on the first stop the thread hit event is kept being | |
1269 | reported from its cached value by linux_nat_stopped_data_address | |
1270 | until the real thread resume happens after the watchpoint gets | |
1271 | presented and thus its LWP_INFO->STATUS gets reset. | |
1272 | ||
1273 | Therefore the hardware watchpoint hit can get safely reset on the | |
1274 | watchpoint removal from inferior. */ | |
a79d3c27 | 1275 | |
b40ce68a | 1276 | static void |
3a5c3e22 | 1277 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1278 | { |
a5606eee | 1279 | int within_current_scope; |
a5606eee | 1280 | struct frame_id saved_frame_id; |
66076460 | 1281 | int frame_saved; |
a5606eee | 1282 | |
f6bc2008 PA |
1283 | /* If this is a local watchpoint, we only want to check if the |
1284 | watchpoint frame is in scope if the current thread is the thread | |
1285 | that was used to create the watchpoint. */ | |
1286 | if (!watchpoint_in_thread_scope (b)) | |
1287 | return; | |
1288 | ||
3a5c3e22 | 1289 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1290 | return; |
1291 | ||
66076460 | 1292 | frame_saved = 0; |
a5606eee VP |
1293 | |
1294 | /* Determine if the watchpoint is within scope. */ | |
1295 | if (b->exp_valid_block == NULL) | |
1296 | within_current_scope = 1; | |
1297 | else | |
1298 | { | |
b5db5dfc UW |
1299 | struct frame_info *fi = get_current_frame (); |
1300 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1301 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1302 | ||
1303 | /* If we're in a function epilogue, unwinding may not work | |
1304 | properly, so do not attempt to recreate locations at this | |
1305 | point. See similar comments in watchpoint_check. */ | |
1306 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1307 | return; | |
66076460 DJ |
1308 | |
1309 | /* Save the current frame's ID so we can restore it after | |
1310 | evaluating the watchpoint expression on its own frame. */ | |
1311 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1312 | took a frame parameter, so that we didn't have to change the | |
1313 | selected frame. */ | |
1314 | frame_saved = 1; | |
1315 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1316 | ||
a5606eee VP |
1317 | fi = frame_find_by_id (b->watchpoint_frame); |
1318 | within_current_scope = (fi != NULL); | |
1319 | if (within_current_scope) | |
1320 | select_frame (fi); | |
1321 | } | |
1322 | ||
b5db5dfc UW |
1323 | /* We don't free locations. They are stored in the bp_location array |
1324 | and update_global_location_list will eventually delete them and | |
1325 | remove breakpoints if needed. */ | |
3a5c3e22 | 1326 | b->base.loc = NULL; |
b5db5dfc | 1327 | |
a5606eee VP |
1328 | if (within_current_scope && reparse) |
1329 | { | |
1330 | char *s; | |
d63d0675 | 1331 | |
a5606eee VP |
1332 | if (b->exp) |
1333 | { | |
1334 | xfree (b->exp); | |
1335 | b->exp = NULL; | |
1336 | } | |
d63d0675 | 1337 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1338 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1339 | /* If the meaning of expression itself changed, the old value is | |
1340 | no longer relevant. We don't want to report a watchpoint hit | |
1341 | to the user when the old value and the new value may actually | |
1342 | be completely different objects. */ | |
1343 | value_free (b->val); | |
fa4727a6 DJ |
1344 | b->val = NULL; |
1345 | b->val_valid = 0; | |
60e1c644 PA |
1346 | |
1347 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1348 | expression is stored in the breakpoint object, not in the | |
1349 | locations (re)created below. */ | |
3a5c3e22 | 1350 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1351 | { |
1352 | if (b->cond_exp != NULL) | |
1353 | { | |
1354 | xfree (b->cond_exp); | |
1355 | b->cond_exp = NULL; | |
1356 | } | |
1357 | ||
3a5c3e22 | 1358 | s = b->base.cond_string; |
60e1c644 PA |
1359 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); |
1360 | } | |
a5606eee | 1361 | } |
a5606eee VP |
1362 | |
1363 | /* If we failed to parse the expression, for example because | |
1364 | it refers to a global variable in a not-yet-loaded shared library, | |
1365 | don't try to insert watchpoint. We don't automatically delete | |
1366 | such watchpoint, though, since failure to parse expression | |
1367 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1368 | if ( !target_has_execution) |
1369 | { | |
1370 | /* Without execution, memory can't change. No use to try and | |
1371 | set watchpoint locations. The watchpoint will be reset when | |
1372 | the target gains execution, through breakpoint_re_set. */ | |
1373 | } | |
1374 | else if (within_current_scope && b->exp) | |
a5606eee | 1375 | { |
0cf6dd15 | 1376 | int pc = 0; |
fa4727a6 | 1377 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1378 | struct program_space *frame_pspace; |
a5606eee | 1379 | |
0cf6dd15 | 1380 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1381 | |
a5606eee VP |
1382 | /* Avoid setting b->val if it's already set. The meaning of |
1383 | b->val is 'the last value' user saw, and we should update | |
1384 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1385 | happens, the code that reports it updates b->val directly. |
1386 | We don't keep track of the memory value for masked | |
1387 | watchpoints. */ | |
3a5c3e22 | 1388 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1389 | { |
1390 | b->val = v; | |
1391 | b->val_valid = 1; | |
1392 | } | |
a5606eee | 1393 | |
2d134ed3 PA |
1394 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1395 | ||
a5606eee | 1396 | /* Look at each value on the value chain. */ |
9fa40276 | 1397 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1398 | { |
1399 | /* If it's a memory location, and GDB actually needed | |
1400 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1401 | must watch it. If the first value returned is |
1402 | still lazy, that means an error occurred reading it; | |
1403 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1404 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1405 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1406 | { |
1407 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1408 | |
a5606eee VP |
1409 | /* We only watch structs and arrays if user asked |
1410 | for it explicitly, never if they just happen to | |
1411 | appear in the middle of some value chain. */ | |
fa4727a6 | 1412 | if (v == result |
a5606eee VP |
1413 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1414 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1415 | { | |
1416 | CORE_ADDR addr; | |
1417 | int len, type; | |
1418 | struct bp_location *loc, **tmp; | |
1419 | ||
42ae5230 | 1420 | addr = value_address (v); |
a5606eee VP |
1421 | len = TYPE_LENGTH (value_type (v)); |
1422 | type = hw_write; | |
3a5c3e22 | 1423 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1424 | type = hw_read; |
3a5c3e22 | 1425 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1426 | type = hw_access; |
3a5c3e22 PA |
1427 | |
1428 | loc = allocate_bp_location (&b->base); | |
1429 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1430 | ; |
1431 | *tmp = loc; | |
a6d9a66e | 1432 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1433 | |
1434 | loc->pspace = frame_pspace; | |
a5606eee VP |
1435 | loc->address = addr; |
1436 | loc->length = len; | |
1437 | loc->watchpoint_type = type; | |
1438 | } | |
1439 | } | |
9fa40276 TJB |
1440 | } |
1441 | ||
1442 | /* Change the type of breakpoint between hardware assisted or | |
1443 | an ordinary watchpoint depending on the hardware support | |
1444 | and free hardware slots. REPARSE is set when the inferior | |
1445 | is started. */ | |
a9634178 | 1446 | if (reparse) |
9fa40276 | 1447 | { |
e09342b5 | 1448 | int reg_cnt; |
9fa40276 TJB |
1449 | enum bp_loc_type loc_type; |
1450 | struct bp_location *bl; | |
a5606eee | 1451 | |
a9634178 | 1452 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1453 | |
1454 | if (reg_cnt) | |
9fa40276 TJB |
1455 | { |
1456 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1457 | enum bptype type; |
9fa40276 | 1458 | |
a9634178 TJB |
1459 | /* Use an exact watchpoint when there's only one memory region to be |
1460 | watched, and only one debug register is needed to watch it. */ | |
1461 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1462 | ||
9fa40276 | 1463 | /* We need to determine how many resources are already |
e09342b5 TJB |
1464 | used for all other hardware watchpoints plus this one |
1465 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1466 | this watchpoint in as well. */ |
1467 | ||
1468 | /* If this is a software watchpoint, we try to turn it | |
1469 | to a hardware one -- count resources as if B was of | |
1470 | hardware watchpoint type. */ | |
1471 | type = b->base.type; | |
1472 | if (type == bp_watchpoint) | |
1473 | type = bp_hardware_watchpoint; | |
1474 | ||
1475 | /* This watchpoint may or may not have been placed on | |
1476 | the list yet at this point (it won't be in the list | |
1477 | if we're trying to create it for the first time, | |
1478 | through watch_command), so always account for it | |
1479 | manually. */ | |
1480 | ||
1481 | /* Count resources used by all watchpoints except B. */ | |
1482 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1483 | ||
1484 | /* Add in the resources needed for B. */ | |
1485 | i += hw_watchpoint_use_count (&b->base); | |
1486 | ||
1487 | target_resources_ok | |
1488 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1489 | if (target_resources_ok <= 0) |
a9634178 | 1490 | { |
3a5c3e22 | 1491 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1492 | |
1493 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1494 | error (_("Target does not support this type of " |
1495 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1496 | else if (target_resources_ok < 0 && !sw_mode) |
1497 | error (_("There are not enough available hardware " | |
1498 | "resources for this watchpoint.")); | |
a1398e0c PA |
1499 | |
1500 | /* Downgrade to software watchpoint. */ | |
1501 | b->base.type = bp_watchpoint; | |
1502 | } | |
1503 | else | |
1504 | { | |
1505 | /* If this was a software watchpoint, we've just | |
1506 | found we have enough resources to turn it to a | |
1507 | hardware watchpoint. Otherwise, this is a | |
1508 | nop. */ | |
1509 | b->base.type = type; | |
a9634178 | 1510 | } |
9fa40276 | 1511 | } |
3a5c3e22 | 1512 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
a9634178 TJB |
1513 | error (_("Expression cannot be implemented with " |
1514 | "read/access watchpoint.")); | |
9fa40276 | 1515 | else |
3a5c3e22 | 1516 | b->base.type = bp_watchpoint; |
9fa40276 | 1517 | |
3a5c3e22 | 1518 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1519 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1520 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1521 | bl->loc_type = loc_type; |
1522 | } | |
1523 | ||
1524 | for (v = val_chain; v; v = next) | |
1525 | { | |
a5606eee VP |
1526 | next = value_next (v); |
1527 | if (v != b->val) | |
1528 | value_free (v); | |
1529 | } | |
1530 | ||
c7437ca6 PA |
1531 | /* If a software watchpoint is not watching any memory, then the |
1532 | above left it without any location set up. But, | |
1533 | bpstat_stop_status requires a location to be able to report | |
1534 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1535 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1536 | { |
3a5c3e22 PA |
1537 | struct breakpoint *base = &b->base; |
1538 | base->loc = allocate_bp_location (base); | |
1539 | base->loc->pspace = frame_pspace; | |
1540 | base->loc->address = -1; | |
1541 | base->loc->length = -1; | |
1542 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1543 | } |
a5606eee VP |
1544 | } |
1545 | else if (!within_current_scope) | |
7270d8f2 | 1546 | { |
ac74f770 MS |
1547 | printf_filtered (_("\ |
1548 | Watchpoint %d deleted because the program has left the block\n\ | |
1549 | in which its expression is valid.\n"), | |
3a5c3e22 | 1550 | b->base.number); |
d0fb5eae | 1551 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1552 | } |
a5606eee VP |
1553 | |
1554 | /* Restore the selected frame. */ | |
66076460 DJ |
1555 | if (frame_saved) |
1556 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1557 | } |
1558 | ||
a5606eee | 1559 | |
74960c60 | 1560 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
1561 | inserted in the inferior. We don't differentiate the type of BL's owner |
1562 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
1563 | breakpoint_ops is not defined, because in insert_bp_location, | |
1564 | tracepoint's insert_location will not be called. */ | |
74960c60 | 1565 | static int |
35df4500 | 1566 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1567 | { |
35df4500 | 1568 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1569 | return 0; |
1570 | ||
35df4500 | 1571 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1572 | return 0; |
1573 | ||
35df4500 | 1574 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1575 | return 0; |
1576 | ||
56710373 PA |
1577 | /* This is set for example, when we're attached to the parent of a |
1578 | vfork, and have detached from the child. The child is running | |
1579 | free, and we expect it to do an exec or exit, at which point the | |
1580 | OS makes the parent schedulable again (and the target reports | |
1581 | that the vfork is done). Until the child is done with the shared | |
1582 | memory region, do not insert breakpoints in the parent, otherwise | |
1583 | the child could still trip on the parent's breakpoints. Since | |
1584 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1585 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1586 | return 0; |
1587 | ||
74960c60 VP |
1588 | return 1; |
1589 | } | |
1590 | ||
934709f0 PW |
1591 | /* Same as should_be_inserted but does the check assuming |
1592 | that the location is not duplicated. */ | |
1593 | ||
1594 | static int | |
1595 | unduplicated_should_be_inserted (struct bp_location *bl) | |
1596 | { | |
1597 | int result; | |
1598 | const int save_duplicate = bl->duplicate; | |
1599 | ||
1600 | bl->duplicate = 0; | |
1601 | result = should_be_inserted (bl); | |
1602 | bl->duplicate = save_duplicate; | |
1603 | return result; | |
1604 | } | |
1605 | ||
35df4500 TJB |
1606 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
1607 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 1608 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
1609 | Returns 0 for success, 1 if the bp_location type is not supported or |
1610 | -1 for failure. | |
879bfdc2 | 1611 | |
4a64f543 MS |
1612 | NOTE drow/2003-09-09: This routine could be broken down to an |
1613 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1614 | static int |
35df4500 | 1615 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 1616 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 1617 | int *disabled_breaks, |
26bb91f3 | 1618 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1619 | { |
1620 | int val = 0; | |
1621 | ||
35df4500 | 1622 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1623 | return 0; |
1624 | ||
8181d85f | 1625 | /* Initialize the target-specific information. */ |
35df4500 TJB |
1626 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
1627 | bl->target_info.placed_address = bl->address; | |
1628 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 1629 | bl->target_info.length = bl->length; |
8181d85f | 1630 | |
35df4500 TJB |
1631 | if (bl->loc_type == bp_loc_software_breakpoint |
1632 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 1633 | { |
35df4500 | 1634 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
1635 | { |
1636 | /* If the explicitly specified breakpoint type | |
1637 | is not hardware breakpoint, check the memory map to see | |
1638 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 1639 | |
765dc015 VP |
1640 | Two important cases are: |
1641 | - location type is not hardware breakpoint, memory | |
1642 | is readonly. We change the type of the location to | |
1643 | hardware breakpoint. | |
4a64f543 MS |
1644 | - location type is hardware breakpoint, memory is |
1645 | read-write. This means we've previously made the | |
1646 | location hardware one, but then the memory map changed, | |
1647 | so we undo. | |
765dc015 | 1648 | |
4a64f543 MS |
1649 | When breakpoints are removed, remove_breakpoints will use |
1650 | location types we've just set here, the only possible | |
1651 | problem is that memory map has changed during running | |
1652 | program, but it's not going to work anyway with current | |
1653 | gdb. */ | |
765dc015 | 1654 | struct mem_region *mr |
35df4500 | 1655 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
1656 | |
1657 | if (mr) | |
1658 | { | |
1659 | if (automatic_hardware_breakpoints) | |
1660 | { | |
765dc015 VP |
1661 | enum bp_loc_type new_type; |
1662 | ||
1663 | if (mr->attrib.mode != MEM_RW) | |
1664 | new_type = bp_loc_hardware_breakpoint; | |
1665 | else | |
1666 | new_type = bp_loc_software_breakpoint; | |
1667 | ||
35df4500 | 1668 | if (new_type != bl->loc_type) |
765dc015 VP |
1669 | { |
1670 | static int said = 0; | |
cc59ec59 | 1671 | |
35df4500 | 1672 | bl->loc_type = new_type; |
765dc015 VP |
1673 | if (!said) |
1674 | { | |
3e43a32a MS |
1675 | fprintf_filtered (gdb_stdout, |
1676 | _("Note: automatically using " | |
1677 | "hardware breakpoints for " | |
1678 | "read-only addresses.\n")); | |
765dc015 VP |
1679 | said = 1; |
1680 | } | |
1681 | } | |
1682 | } | |
35df4500 | 1683 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 1684 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
1685 | warning (_("cannot set software breakpoint " |
1686 | "at readonly address %s"), | |
35df4500 | 1687 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
1688 | } |
1689 | } | |
1690 | ||
879bfdc2 DJ |
1691 | /* First check to see if we have to handle an overlay. */ |
1692 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
1693 | || bl->section == NULL |
1694 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
1695 | { |
1696 | /* No overlay handling: just set the breakpoint. */ | |
1697 | ||
348d480f | 1698 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
1699 | } |
1700 | else | |
1701 | { | |
4a64f543 | 1702 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
1703 | Shall we set a breakpoint at the LMA? */ |
1704 | if (!overlay_events_enabled) | |
1705 | { | |
1706 | /* Yes -- overlay event support is not active, | |
1707 | so we must try to set a breakpoint at the LMA. | |
1708 | This will not work for a hardware breakpoint. */ | |
35df4500 | 1709 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 1710 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 1711 | bl->owner->number); |
879bfdc2 DJ |
1712 | else |
1713 | { | |
35df4500 TJB |
1714 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
1715 | bl->section); | |
879bfdc2 | 1716 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
1717 | bl->overlay_target_info = bl->target_info; |
1718 | bl->overlay_target_info.placed_address = addr; | |
1719 | val = target_insert_breakpoint (bl->gdbarch, | |
1720 | &bl->overlay_target_info); | |
879bfdc2 | 1721 | if (val != 0) |
99361f52 | 1722 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1723 | "Overlay breakpoint %d " |
1724 | "failed: in ROM?\n", | |
35df4500 | 1725 | bl->owner->number); |
879bfdc2 DJ |
1726 | } |
1727 | } | |
1728 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 1729 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
1730 | { |
1731 | /* Yes. This overlay section is mapped into memory. */ | |
348d480f | 1732 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
1733 | } |
1734 | else | |
1735 | { | |
1736 | /* No. This breakpoint will not be inserted. | |
1737 | No error, but do not mark the bp as 'inserted'. */ | |
1738 | return 0; | |
1739 | } | |
1740 | } | |
1741 | ||
1742 | if (val) | |
1743 | { | |
1744 | /* Can't set the breakpoint. */ | |
35df4500 | 1745 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 1746 | { |
4a64f543 | 1747 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 1748 | val = 0; |
35df4500 | 1749 | bl->shlib_disabled = 1; |
8d3788bd | 1750 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
1751 | if (!*disabled_breaks) |
1752 | { | |
1753 | fprintf_unfiltered (tmp_error_stream, | |
1754 | "Cannot insert breakpoint %d.\n", | |
1755 | bl->owner->number); | |
1756 | fprintf_unfiltered (tmp_error_stream, | |
1757 | "Temporarily disabling shared " | |
1758 | "library breakpoints:\n"); | |
1759 | } | |
1760 | *disabled_breaks = 1; | |
879bfdc2 | 1761 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 1762 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
1763 | } |
1764 | else | |
879bfdc2 | 1765 | { |
35df4500 | 1766 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
1767 | { |
1768 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
1769 | fprintf_unfiltered (tmp_error_stream, |
1770 | "Cannot insert hardware " | |
1771 | "breakpoint %d.\n", | |
35df4500 | 1772 | bl->owner->number); |
879bfdc2 DJ |
1773 | } |
1774 | else | |
1775 | { | |
1776 | fprintf_unfiltered (tmp_error_stream, | |
1777 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1778 | bl->owner->number); |
879bfdc2 DJ |
1779 | fprintf_filtered (tmp_error_stream, |
1780 | "Error accessing memory address "); | |
35df4500 | 1781 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 1782 | tmp_error_stream); |
879bfdc2 DJ |
1783 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1784 | safe_strerror (val)); | |
1785 | } | |
1786 | ||
1787 | } | |
1788 | } | |
1789 | else | |
35df4500 | 1790 | bl->inserted = 1; |
879bfdc2 DJ |
1791 | |
1792 | return val; | |
1793 | } | |
1794 | ||
35df4500 | 1795 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 1796 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 1797 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 1798 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 1799 | { |
77b06cd7 TJB |
1800 | gdb_assert (bl->owner->ops != NULL |
1801 | && bl->owner->ops->insert_location != NULL); | |
1802 | ||
1803 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
1804 | |
1805 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1806 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 1807 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
1808 | { |
1809 | struct bp_location *loc, **loc_temp; | |
1810 | ||
1811 | /* But don't try to insert it, if there's already another | |
1812 | hw_access location that would be considered a duplicate | |
1813 | of this one. */ | |
1814 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 1815 | if (loc != bl |
85d721b8 | 1816 | && loc->watchpoint_type == hw_access |
35df4500 | 1817 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 1818 | { |
35df4500 TJB |
1819 | bl->duplicate = 1; |
1820 | bl->inserted = 1; | |
1821 | bl->target_info = loc->target_info; | |
1822 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
1823 | val = 0; |
1824 | break; | |
1825 | } | |
1826 | ||
1827 | if (val == 1) | |
1828 | { | |
77b06cd7 TJB |
1829 | bl->watchpoint_type = hw_access; |
1830 | val = bl->owner->ops->insert_location (bl); | |
1831 | ||
1832 | if (val) | |
1833 | /* Back to the original value. */ | |
1834 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
1835 | } |
1836 | } | |
1837 | ||
35df4500 | 1838 | bl->inserted = (val == 0); |
879bfdc2 DJ |
1839 | } |
1840 | ||
35df4500 | 1841 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 1842 | { |
77b06cd7 TJB |
1843 | gdb_assert (bl->owner->ops != NULL |
1844 | && bl->owner->ops->insert_location != NULL); | |
1845 | ||
1846 | val = bl->owner->ops->insert_location (bl); | |
1847 | if (val) | |
1848 | { | |
1849 | bl->owner->enable_state = bp_disabled; | |
1850 | ||
1851 | if (val == 1) | |
1852 | warning (_("\ | |
1853 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
1854 | of catchpoint."), bl->owner->number); | |
1855 | else | |
1856 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
1857 | } | |
1858 | ||
1859 | bl->inserted = (val == 0); | |
1640b821 DJ |
1860 | |
1861 | /* We've already printed an error message if there was a problem | |
1862 | inserting this catchpoint, and we've disabled the catchpoint, | |
1863 | so just return success. */ | |
1864 | return 0; | |
879bfdc2 DJ |
1865 | } |
1866 | ||
1867 | return 0; | |
1868 | } | |
1869 | ||
6c95b8df PA |
1870 | /* This function is called when program space PSPACE is about to be |
1871 | deleted. It takes care of updating breakpoints to not reference | |
1872 | PSPACE anymore. */ | |
1873 | ||
1874 | void | |
1875 | breakpoint_program_space_exit (struct program_space *pspace) | |
1876 | { | |
1877 | struct breakpoint *b, *b_temp; | |
876fa593 | 1878 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1879 | |
1880 | /* Remove any breakpoint that was set through this program space. */ | |
1881 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1882 | { | |
1883 | if (b->pspace == pspace) | |
1884 | delete_breakpoint (b); | |
1885 | } | |
1886 | ||
1887 | /* Breakpoints set through other program spaces could have locations | |
1888 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1889 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1890 | { |
1891 | struct bp_location *tmp; | |
1892 | ||
1893 | if (loc->pspace == pspace) | |
1894 | { | |
2bdf28a0 | 1895 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1896 | if (loc->owner->loc == loc) |
1897 | loc->owner->loc = loc->next; | |
1898 | else | |
1899 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1900 | if (tmp->next == loc) | |
1901 | { | |
1902 | tmp->next = loc->next; | |
1903 | break; | |
1904 | } | |
1905 | } | |
1906 | } | |
1907 | ||
1908 | /* Now update the global location list to permanently delete the | |
1909 | removed locations above. */ | |
1910 | update_global_location_list (0); | |
1911 | } | |
1912 | ||
74960c60 VP |
1913 | /* Make sure all breakpoints are inserted in inferior. |
1914 | Throws exception on any error. | |
1915 | A breakpoint that is already inserted won't be inserted | |
1916 | again, so calling this function twice is safe. */ | |
1917 | void | |
1918 | insert_breakpoints (void) | |
1919 | { | |
1920 | struct breakpoint *bpt; | |
1921 | ||
1922 | ALL_BREAKPOINTS (bpt) | |
1923 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
1924 | { |
1925 | struct watchpoint *w = (struct watchpoint *) bpt; | |
1926 | ||
1927 | update_watchpoint (w, 0 /* don't reparse. */); | |
1928 | } | |
74960c60 | 1929 | |
b60e7edf | 1930 | update_global_location_list (1); |
74960c60 | 1931 | |
c35b1492 PA |
1932 | /* update_global_location_list does not insert breakpoints when |
1933 | always_inserted_mode is not enabled. Explicitly insert them | |
1934 | now. */ | |
1935 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1936 | insert_breakpoint_locations (); |
1937 | } | |
1938 | ||
c30eee59 | 1939 | /* Used when starting or continuing the program. */ |
c906108c | 1940 | |
74960c60 VP |
1941 | static void |
1942 | insert_breakpoint_locations (void) | |
c906108c | 1943 | { |
a5606eee | 1944 | struct breakpoint *bpt; |
35df4500 | 1945 | struct bp_location *bl, **blp_tmp; |
e236ba44 | 1946 | int error = 0; |
c906108c | 1947 | int val = 0; |
3fbb6ffa | 1948 | int disabled_breaks = 0; |
81d0cc19 | 1949 | int hw_breakpoint_error = 0; |
c906108c | 1950 | |
81d0cc19 | 1951 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1952 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1953 | |
81d0cc19 GS |
1954 | /* Explicitly mark the warning -- this will only be printed if |
1955 | there was an error. */ | |
1956 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1957 | |
1958 | save_current_space_and_thread (); | |
1959 | ||
35df4500 | 1960 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 1961 | { |
35df4500 | 1962 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1963 | continue; |
1964 | ||
4a64f543 MS |
1965 | /* There is no point inserting thread-specific breakpoints if |
1966 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
1967 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
1968 | if (bl->owner->thread != -1 |
1969 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
1970 | continue; |
1971 | ||
35df4500 | 1972 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
1973 | |
1974 | /* For targets that support global breakpoints, there's no need | |
1975 | to select an inferior to insert breakpoint to. In fact, even | |
1976 | if we aren't attached to any process yet, we should still | |
1977 | insert breakpoints. */ | |
1978 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1979 | && ptid_equal (inferior_ptid, null_ptid)) | |
1980 | continue; | |
1981 | ||
3fbb6ffa TJB |
1982 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
1983 | &hw_breakpoint_error); | |
879bfdc2 | 1984 | if (val) |
e236ba44 | 1985 | error = val; |
879bfdc2 | 1986 | } |
c906108c | 1987 | |
4a64f543 MS |
1988 | /* If we failed to insert all locations of a watchpoint, remove |
1989 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
1990 | ALL_BREAKPOINTS (bpt) |
1991 | { | |
1992 | int some_failed = 0; | |
1993 | struct bp_location *loc; | |
1994 | ||
1995 | if (!is_hardware_watchpoint (bpt)) | |
1996 | continue; | |
1997 | ||
d6b74ac4 | 1998 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1999 | continue; |
74960c60 VP |
2000 | |
2001 | if (bpt->disposition == disp_del_at_next_stop) | |
2002 | continue; | |
a5606eee VP |
2003 | |
2004 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2005 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2006 | { |
2007 | some_failed = 1; | |
2008 | break; | |
2009 | } | |
2010 | if (some_failed) | |
2011 | { | |
2012 | for (loc = bpt->loc; loc; loc = loc->next) | |
2013 | if (loc->inserted) | |
2014 | remove_breakpoint (loc, mark_uninserted); | |
2015 | ||
2016 | hw_breakpoint_error = 1; | |
2017 | fprintf_unfiltered (tmp_error_stream, | |
2018 | "Could not insert hardware watchpoint %d.\n", | |
2019 | bpt->number); | |
2020 | error = -1; | |
2021 | } | |
2022 | } | |
2023 | ||
e236ba44 | 2024 | if (error) |
81d0cc19 GS |
2025 | { |
2026 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2027 | message about possibly exhausted resources. */ | |
879bfdc2 | 2028 | if (hw_breakpoint_error) |
81d0cc19 | 2029 | { |
c6510018 MS |
2030 | fprintf_unfiltered (tmp_error_stream, |
2031 | "Could not insert hardware breakpoints:\n\ | |
2032 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2033 | } |
81d0cc19 GS |
2034 | target_terminal_ours_for_output (); |
2035 | error_stream (tmp_error_stream); | |
2036 | } | |
f7545552 TT |
2037 | |
2038 | do_cleanups (cleanups); | |
c906108c SS |
2039 | } |
2040 | ||
c30eee59 TJB |
2041 | /* Used when the program stops. |
2042 | Returns zero if successful, or non-zero if there was a problem | |
2043 | removing a breakpoint location. */ | |
2044 | ||
c906108c | 2045 | int |
fba45db2 | 2046 | remove_breakpoints (void) |
c906108c | 2047 | { |
35df4500 | 2048 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2049 | int val = 0; |
c906108c | 2050 | |
35df4500 | 2051 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2052 | { |
1e4d1764 | 2053 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 2054 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 2055 | } |
3a1bae8e | 2056 | return val; |
c906108c SS |
2057 | } |
2058 | ||
6c95b8df PA |
2059 | /* Remove breakpoints of process PID. */ |
2060 | ||
2061 | int | |
2062 | remove_breakpoints_pid (int pid) | |
2063 | { | |
35df4500 | 2064 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2065 | int val; |
2066 | struct inferior *inf = find_inferior_pid (pid); | |
2067 | ||
35df4500 | 2068 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2069 | { |
35df4500 | 2070 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2071 | continue; |
2072 | ||
35df4500 | 2073 | if (bl->inserted) |
6c95b8df | 2074 | { |
35df4500 | 2075 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2076 | if (val != 0) |
2077 | return val; | |
2078 | } | |
2079 | } | |
2080 | return 0; | |
2081 | } | |
2082 | ||
c906108c | 2083 | int |
fba45db2 | 2084 | reattach_breakpoints (int pid) |
c906108c | 2085 | { |
6c95b8df | 2086 | struct cleanup *old_chain; |
35df4500 | 2087 | struct bp_location *bl, **blp_tmp; |
c906108c | 2088 | int val; |
86b887df | 2089 | struct ui_file *tmp_error_stream; |
3fbb6ffa | 2090 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2091 | struct inferior *inf; |
2092 | struct thread_info *tp; | |
2093 | ||
2094 | tp = any_live_thread_of_process (pid); | |
2095 | if (tp == NULL) | |
2096 | return 1; | |
2097 | ||
2098 | inf = find_inferior_pid (pid); | |
2099 | old_chain = save_inferior_ptid (); | |
2100 | ||
2101 | inferior_ptid = tp->ptid; | |
a4954f26 | 2102 | |
86b887df | 2103 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2104 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2105 | |
35df4500 | 2106 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2107 | { |
35df4500 | 2108 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2109 | continue; |
2110 | ||
35df4500 | 2111 | if (bl->inserted) |
c5aa993b | 2112 | { |
35df4500 | 2113 | bl->inserted = 0; |
3fbb6ffa | 2114 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); |
c5aa993b JM |
2115 | if (val != 0) |
2116 | { | |
ce696e05 | 2117 | do_cleanups (old_chain); |
c5aa993b JM |
2118 | return val; |
2119 | } | |
2120 | } | |
2121 | } | |
ce696e05 | 2122 | do_cleanups (old_chain); |
c906108c SS |
2123 | return 0; |
2124 | } | |
2125 | ||
e58b0e63 PA |
2126 | static int internal_breakpoint_number = -1; |
2127 | ||
84f4c1fe PM |
2128 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2129 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2130 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 2131 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
2132 | breakpoint_count and that value incremented. Internal breakpoints |
2133 | do not set the internal var bpnum. */ | |
2134 | static void | |
2135 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2136 | { | |
2137 | if (internal) | |
2138 | b->number = internal_breakpoint_number--; | |
2139 | else | |
2140 | { | |
2141 | set_breakpoint_count (breakpoint_count + 1); | |
2142 | b->number = breakpoint_count; | |
2143 | } | |
2144 | } | |
2145 | ||
e62c965a | 2146 | static struct breakpoint * |
a6d9a66e | 2147 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 2148 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 2149 | const struct breakpoint_ops *ops) |
e62c965a | 2150 | { |
e62c965a PP |
2151 | struct symtab_and_line sal; |
2152 | struct breakpoint *b; | |
2153 | ||
4a64f543 | 2154 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2155 | |
2156 | sal.pc = address; | |
2157 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2158 | sal.pspace = current_program_space; |
e62c965a | 2159 | |
06edf0c0 | 2160 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
2161 | b->number = internal_breakpoint_number--; |
2162 | b->disposition = disp_donttouch; | |
2163 | ||
2164 | return b; | |
2165 | } | |
2166 | ||
17450429 PP |
2167 | static const char *const longjmp_names[] = |
2168 | { | |
2169 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2170 | }; | |
2171 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2172 | ||
2173 | /* Per-objfile data private to breakpoint.c. */ | |
2174 | struct breakpoint_objfile_data | |
2175 | { | |
2176 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2177 | struct minimal_symbol *overlay_msym; | |
2178 | ||
2179 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2180 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2181 | ||
2182 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2183 | struct minimal_symbol *terminate_msym; | |
2184 | ||
2185 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2186 | struct minimal_symbol *exception_msym; | |
2187 | }; | |
2188 | ||
2189 | static const struct objfile_data *breakpoint_objfile_key; | |
2190 | ||
2191 | /* Minimal symbol not found sentinel. */ | |
2192 | static struct minimal_symbol msym_not_found; | |
2193 | ||
2194 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2195 | ||
2196 | static int | |
2197 | msym_not_found_p (const struct minimal_symbol *msym) | |
2198 | { | |
2199 | return msym == &msym_not_found; | |
2200 | } | |
2201 | ||
2202 | /* Return per-objfile data needed by breakpoint.c. | |
2203 | Allocate the data if necessary. */ | |
2204 | ||
2205 | static struct breakpoint_objfile_data * | |
2206 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2207 | { | |
2208 | struct breakpoint_objfile_data *bp_objfile_data; | |
2209 | ||
2210 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2211 | if (bp_objfile_data == NULL) | |
2212 | { | |
2213 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2214 | sizeof (*bp_objfile_data)); | |
2215 | ||
2216 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2217 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2218 | } | |
2219 | return bp_objfile_data; | |
2220 | } | |
2221 | ||
e62c965a | 2222 | static void |
af02033e | 2223 | create_overlay_event_breakpoint (void) |
e62c965a | 2224 | { |
69de3c6a | 2225 | struct objfile *objfile; |
af02033e | 2226 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2227 | |
69de3c6a PP |
2228 | ALL_OBJFILES (objfile) |
2229 | { | |
2230 | struct breakpoint *b; | |
17450429 PP |
2231 | struct breakpoint_objfile_data *bp_objfile_data; |
2232 | CORE_ADDR addr; | |
69de3c6a | 2233 | |
17450429 PP |
2234 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2235 | ||
2236 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2237 | continue; | |
2238 | ||
2239 | if (bp_objfile_data->overlay_msym == NULL) | |
2240 | { | |
2241 | struct minimal_symbol *m; | |
2242 | ||
2243 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2244 | if (m == NULL) | |
2245 | { | |
2246 | /* Avoid future lookups in this objfile. */ | |
2247 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2248 | continue; | |
2249 | } | |
2250 | bp_objfile_data->overlay_msym = m; | |
2251 | } | |
e62c965a | 2252 | |
17450429 PP |
2253 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2254 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2255 | bp_overlay_event, |
2256 | &internal_breakpoint_ops); | |
69de3c6a | 2257 | b->addr_string = xstrdup (func_name); |
e62c965a | 2258 | |
69de3c6a PP |
2259 | if (overlay_debugging == ovly_auto) |
2260 | { | |
2261 | b->enable_state = bp_enabled; | |
2262 | overlay_events_enabled = 1; | |
2263 | } | |
2264 | else | |
2265 | { | |
2266 | b->enable_state = bp_disabled; | |
2267 | overlay_events_enabled = 0; | |
2268 | } | |
e62c965a PP |
2269 | } |
2270 | update_global_location_list (1); | |
2271 | } | |
2272 | ||
0fd8e87f | 2273 | static void |
af02033e | 2274 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2275 | { |
6c95b8df | 2276 | struct program_space *pspace; |
6c95b8df PA |
2277 | struct cleanup *old_chain; |
2278 | ||
2279 | old_chain = save_current_program_space (); | |
0fd8e87f | 2280 | |
6c95b8df | 2281 | ALL_PSPACES (pspace) |
af02033e PP |
2282 | { |
2283 | struct objfile *objfile; | |
2284 | ||
2285 | set_current_program_space (pspace); | |
2286 | ||
2287 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2288 | { |
af02033e PP |
2289 | int i; |
2290 | struct gdbarch *gdbarch; | |
17450429 | 2291 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2292 | |
af02033e PP |
2293 | gdbarch = get_objfile_arch (objfile); |
2294 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2295 | continue; |
2296 | ||
17450429 PP |
2297 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2298 | ||
2299 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2300 | { |
2301 | struct breakpoint *b; | |
af02033e | 2302 | const char *func_name; |
17450429 | 2303 | CORE_ADDR addr; |
6c95b8df | 2304 | |
17450429 | 2305 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2306 | continue; |
0fd8e87f | 2307 | |
17450429 PP |
2308 | func_name = longjmp_names[i]; |
2309 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2310 | { | |
2311 | struct minimal_symbol *m; | |
2312 | ||
2313 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2314 | if (m == NULL) | |
2315 | { | |
2316 | /* Prevent future lookups in this objfile. */ | |
2317 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2318 | continue; | |
2319 | } | |
2320 | bp_objfile_data->longjmp_msym[i] = m; | |
2321 | } | |
2322 | ||
2323 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
06edf0c0 PA |
2324 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
2325 | &internal_breakpoint_ops); | |
af02033e PP |
2326 | b->addr_string = xstrdup (func_name); |
2327 | b->enable_state = bp_disabled; | |
2328 | } | |
0fd8e87f | 2329 | } |
af02033e | 2330 | } |
0fd8e87f | 2331 | update_global_location_list (1); |
6c95b8df PA |
2332 | |
2333 | do_cleanups (old_chain); | |
0fd8e87f UW |
2334 | } |
2335 | ||
af02033e | 2336 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2337 | static void |
af02033e | 2338 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2339 | { |
2340 | struct program_space *pspace; | |
aa7d318d | 2341 | struct cleanup *old_chain; |
af02033e | 2342 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2343 | |
2344 | old_chain = save_current_program_space (); | |
2345 | ||
2346 | ALL_PSPACES (pspace) | |
17450429 PP |
2347 | { |
2348 | struct objfile *objfile; | |
2349 | CORE_ADDR addr; | |
2350 | ||
2351 | set_current_program_space (pspace); | |
2352 | ||
aa7d318d TT |
2353 | ALL_OBJFILES (objfile) |
2354 | { | |
2355 | struct breakpoint *b; | |
17450429 | 2356 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2357 | |
17450429 | 2358 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2359 | |
17450429 PP |
2360 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2361 | continue; | |
2362 | ||
2363 | if (bp_objfile_data->terminate_msym == NULL) | |
2364 | { | |
2365 | struct minimal_symbol *m; | |
2366 | ||
2367 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2368 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2369 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2370 | { | |
2371 | /* Prevent future lookups in this objfile. */ | |
2372 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2373 | continue; | |
2374 | } | |
2375 | bp_objfile_data->terminate_msym = m; | |
2376 | } | |
aa7d318d | 2377 | |
17450429 PP |
2378 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2379 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2380 | bp_std_terminate_master, |
2381 | &internal_breakpoint_ops); | |
aa7d318d TT |
2382 | b->addr_string = xstrdup (func_name); |
2383 | b->enable_state = bp_disabled; | |
2384 | } | |
17450429 PP |
2385 | } |
2386 | ||
aa7d318d TT |
2387 | update_global_location_list (1); |
2388 | ||
2389 | do_cleanups (old_chain); | |
2390 | } | |
2391 | ||
186c406b TT |
2392 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2393 | ||
2394 | void | |
2395 | create_exception_master_breakpoint (void) | |
2396 | { | |
2397 | struct objfile *objfile; | |
17450429 | 2398 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2399 | |
2400 | ALL_OBJFILES (objfile) | |
2401 | { | |
17450429 PP |
2402 | struct breakpoint *b; |
2403 | struct gdbarch *gdbarch; | |
2404 | struct breakpoint_objfile_data *bp_objfile_data; | |
2405 | CORE_ADDR addr; | |
2406 | ||
2407 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2408 | ||
2409 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2410 | continue; | |
2411 | ||
2412 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2413 | |
17450429 | 2414 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2415 | { |
17450429 | 2416 | struct minimal_symbol *debug_hook; |
186c406b | 2417 | |
17450429 PP |
2418 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2419 | if (debug_hook == NULL) | |
2420 | { | |
2421 | bp_objfile_data->exception_msym = &msym_not_found; | |
2422 | continue; | |
2423 | } | |
2424 | ||
2425 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2426 | } |
17450429 PP |
2427 | |
2428 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2429 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2430 | ¤t_target); | |
06edf0c0 PA |
2431 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
2432 | &internal_breakpoint_ops); | |
17450429 PP |
2433 | b->addr_string = xstrdup (func_name); |
2434 | b->enable_state = bp_disabled; | |
186c406b TT |
2435 | } |
2436 | ||
2437 | update_global_location_list (1); | |
2438 | } | |
2439 | ||
c906108c | 2440 | void |
fba45db2 | 2441 | update_breakpoints_after_exec (void) |
c906108c | 2442 | { |
35df4500 | 2443 | struct breakpoint *b, *b_tmp; |
876fa593 | 2444 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2445 | |
25b22b0a PA |
2446 | /* We're about to delete breakpoints from GDB's lists. If the |
2447 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2448 | writing the breakpoints' "shadow contents" back into memory. The | |
2449 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2450 | do that. Instead, the target is responsible from marking | |
2451 | breakpoints out as soon as it detects an exec. We don't do that | |
2452 | here instead, because there may be other attempts to delete | |
2453 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2454 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2455 | if (bploc->pspace == current_program_space) |
2456 | gdb_assert (!bploc->inserted); | |
c906108c | 2457 | |
35df4500 | 2458 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2459 | { |
6c95b8df PA |
2460 | if (b->pspace != current_program_space) |
2461 | continue; | |
2462 | ||
4a64f543 | 2463 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2464 | if (b->type == bp_shlib_event) |
2465 | { | |
2466 | delete_breakpoint (b); | |
2467 | continue; | |
2468 | } | |
c906108c | 2469 | |
4a64f543 | 2470 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2471 | if (b->type == bp_jit_event) |
2472 | { | |
2473 | delete_breakpoint (b); | |
2474 | continue; | |
2475 | } | |
2476 | ||
1900040c | 2477 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2478 | as must overlay event and longjmp master breakpoints. */ |
2479 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2480 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2481 | || b->type == bp_exception_master) | |
c4093a6a JM |
2482 | { |
2483 | delete_breakpoint (b); | |
2484 | continue; | |
2485 | } | |
2486 | ||
4a64f543 | 2487 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 2488 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
2489 | { |
2490 | delete_breakpoint (b); | |
2491 | continue; | |
2492 | } | |
2493 | ||
611c83ae PA |
2494 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2495 | after an exec. */ | |
186c406b TT |
2496 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2497 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2498 | { |
2499 | delete_breakpoint (b); | |
2500 | continue; | |
2501 | } | |
2502 | ||
ce78b96d JB |
2503 | if (b->type == bp_catchpoint) |
2504 | { | |
2505 | /* For now, none of the bp_catchpoint breakpoints need to | |
2506 | do anything at this point. In the future, if some of | |
2507 | the catchpoints need to something, we will need to add | |
2508 | a new method, and call this method from here. */ | |
2509 | continue; | |
2510 | } | |
2511 | ||
c5aa993b JM |
2512 | /* bp_finish is a special case. The only way we ought to be able |
2513 | to see one of these when an exec() has happened, is if the user | |
2514 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2515 | carries them to the call-site of the current callee, by setting | |
2516 | a temporary bp there and resuming. But in this case, the finish | |
2517 | will carry them entirely through the vfork & exec. | |
2518 | ||
2519 | We don't want to allow a bp_finish to remain inserted now. But | |
2520 | we can't safely delete it, 'cause finish_command has a handle to | |
2521 | the bp on a bpstat, and will later want to delete it. There's a | |
2522 | chance (and I've seen it happen) that if we delete the bp_finish | |
2523 | here, that its storage will get reused by the time finish_command | |
2524 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2525 | We really must allow finish_command to delete a bp_finish. | |
2526 | ||
e5dd4106 | 2527 | In the absence of a general solution for the "how do we know |
53a5351d JM |
2528 | it's safe to delete something others may have handles to?" |
2529 | problem, what we'll do here is just uninsert the bp_finish, and | |
2530 | let finish_command delete it. | |
2531 | ||
2532 | (We know the bp_finish is "doomed" in the sense that it's | |
2533 | momentary, and will be deleted as soon as finish_command sees | |
2534 | the inferior stopped. So it doesn't matter that the bp's | |
2535 | address is probably bogus in the new a.out, unlike e.g., the | |
2536 | solib breakpoints.) */ | |
c5aa993b | 2537 | |
c5aa993b JM |
2538 | if (b->type == bp_finish) |
2539 | { | |
2540 | continue; | |
2541 | } | |
2542 | ||
2543 | /* Without a symbolic address, we have little hope of the | |
2544 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2545 | a.out. */ |
c5aa993b JM |
2546 | if (b->addr_string == NULL) |
2547 | { | |
2548 | delete_breakpoint (b); | |
2549 | continue; | |
2550 | } | |
c5aa993b | 2551 | } |
1900040c | 2552 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
2553 | create_overlay_event_breakpoint (); |
2554 | create_longjmp_master_breakpoint (); | |
2555 | create_std_terminate_master_breakpoint (); | |
186c406b | 2556 | create_exception_master_breakpoint (); |
c906108c SS |
2557 | } |
2558 | ||
2559 | int | |
fba45db2 | 2560 | detach_breakpoints (int pid) |
c906108c | 2561 | { |
35df4500 | 2562 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2563 | int val = 0; |
ce696e05 | 2564 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2565 | struct inferior *inf = current_inferior (); |
c5aa993b | 2566 | |
39f77062 | 2567 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2568 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2569 | |
6c95b8df | 2570 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2571 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2572 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2573 | { |
35df4500 | 2574 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2575 | continue; |
2576 | ||
35df4500 TJB |
2577 | if (bl->inserted) |
2578 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2579 | } |
d03285ec UW |
2580 | |
2581 | /* Detach single-step breakpoints as well. */ | |
2582 | detach_single_step_breakpoints (); | |
2583 | ||
ce696e05 | 2584 | do_cleanups (old_chain); |
3a1bae8e | 2585 | return val; |
c906108c SS |
2586 | } |
2587 | ||
35df4500 | 2588 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2589 | Note that this is used to detach breakpoints from a child fork. |
2590 | When we get here, the child isn't in the inferior list, and neither | |
2591 | do we have objects to represent its address space --- we should | |
35df4500 | 2592 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2593 | |
c906108c | 2594 | static int |
35df4500 | 2595 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2596 | { |
2597 | int val; | |
c5aa993b | 2598 | |
35df4500 TJB |
2599 | /* BL is never in moribund_locations by our callers. */ |
2600 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2601 | |
35df4500 | 2602 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2603 | /* Permanent breakpoints cannot be inserted or removed. */ |
2604 | return 0; | |
2605 | ||
74960c60 VP |
2606 | /* The type of none suggests that owner is actually deleted. |
2607 | This should not ever happen. */ | |
35df4500 | 2608 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2609 | |
35df4500 TJB |
2610 | if (bl->loc_type == bp_loc_software_breakpoint |
2611 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2612 | { |
c02f5703 MS |
2613 | /* "Normal" instruction breakpoint: either the standard |
2614 | trap-instruction bp (bp_breakpoint), or a | |
2615 | bp_hardware_breakpoint. */ | |
2616 | ||
2617 | /* First check to see if we have to handle an overlay. */ | |
2618 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2619 | || bl->section == NULL |
2620 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2621 | { |
2622 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 2623 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 2624 | } |
c906108c SS |
2625 | else |
2626 | { | |
4a64f543 | 2627 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2628 | Did we set a breakpoint at the LMA? */ |
2629 | if (!overlay_events_enabled) | |
2630 | { | |
2631 | /* Yes -- overlay event support is not active, so we | |
2632 | should have set a breakpoint at the LMA. Remove it. | |
2633 | */ | |
c02f5703 MS |
2634 | /* Ignore any failures: if the LMA is in ROM, we will |
2635 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2636 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2637 | target_remove_hw_breakpoint (bl->gdbarch, | |
2638 | &bl->overlay_target_info); | |
c02f5703 | 2639 | else |
35df4500 TJB |
2640 | target_remove_breakpoint (bl->gdbarch, |
2641 | &bl->overlay_target_info); | |
c02f5703 MS |
2642 | } |
2643 | /* Did we set a breakpoint at the VMA? | |
2644 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2645 | if (bl->inserted) |
c906108c | 2646 | { |
c02f5703 MS |
2647 | /* Yes -- remove it. Previously we did not bother to |
2648 | remove the breakpoint if the section had been | |
2649 | unmapped, but let's not rely on that being safe. We | |
2650 | don't know what the overlay manager might do. */ | |
aa67235e UW |
2651 | |
2652 | /* However, we should remove *software* breakpoints only | |
2653 | if the section is still mapped, or else we overwrite | |
2654 | wrong code with the saved shadow contents. */ | |
348d480f PA |
2655 | if (bl->loc_type == bp_loc_hardware_breakpoint |
2656 | || section_is_mapped (bl->section)) | |
2657 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
2658 | else |
2659 | val = 0; | |
c906108c | 2660 | } |
c02f5703 MS |
2661 | else |
2662 | { | |
2663 | /* No -- not inserted, so no need to remove. No error. */ | |
2664 | val = 0; | |
2665 | } | |
c906108c | 2666 | } |
879d1e6b UW |
2667 | |
2668 | /* In some cases, we might not be able to remove a breakpoint | |
2669 | in a shared library that has already been removed, but we | |
2670 | have not yet processed the shlib unload event. */ | |
35df4500 | 2671 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2672 | val = 0; |
2673 | ||
c906108c SS |
2674 | if (val) |
2675 | return val; | |
35df4500 | 2676 | bl->inserted = (is == mark_inserted); |
c906108c | 2677 | } |
35df4500 | 2678 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2679 | { |
77b06cd7 TJB |
2680 | gdb_assert (bl->owner->ops != NULL |
2681 | && bl->owner->ops->remove_location != NULL); | |
2682 | ||
35df4500 | 2683 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2684 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2685 | |
c906108c | 2686 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2687 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2688 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2689 | bl->owner->number); |
c906108c | 2690 | } |
35df4500 TJB |
2691 | else if (bl->owner->type == bp_catchpoint |
2692 | && breakpoint_enabled (bl->owner) | |
2693 | && !bl->duplicate) | |
ce78b96d | 2694 | { |
77b06cd7 TJB |
2695 | gdb_assert (bl->owner->ops != NULL |
2696 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2697 | |
77b06cd7 | 2698 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2699 | if (val) |
2700 | return val; | |
77b06cd7 | 2701 | |
35df4500 | 2702 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2703 | } |
c906108c SS |
2704 | |
2705 | return 0; | |
2706 | } | |
2707 | ||
6c95b8df | 2708 | static int |
35df4500 | 2709 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2710 | { |
2711 | int ret; | |
2712 | struct cleanup *old_chain; | |
2713 | ||
35df4500 TJB |
2714 | /* BL is never in moribund_locations by our callers. */ |
2715 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2716 | |
35df4500 | 2717 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2718 | /* Permanent breakpoints cannot be inserted or removed. */ |
2719 | return 0; | |
2720 | ||
2721 | /* The type of none suggests that owner is actually deleted. | |
2722 | This should not ever happen. */ | |
35df4500 | 2723 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2724 | |
2725 | old_chain = save_current_space_and_thread (); | |
2726 | ||
35df4500 | 2727 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2728 | |
35df4500 | 2729 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2730 | |
2731 | do_cleanups (old_chain); | |
2732 | return ret; | |
2733 | } | |
2734 | ||
c906108c SS |
2735 | /* Clear the "inserted" flag in all breakpoints. */ |
2736 | ||
25b22b0a | 2737 | void |
fba45db2 | 2738 | mark_breakpoints_out (void) |
c906108c | 2739 | { |
35df4500 | 2740 | struct bp_location *bl, **blp_tmp; |
c906108c | 2741 | |
35df4500 TJB |
2742 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2743 | if (bl->pspace == current_program_space) | |
2744 | bl->inserted = 0; | |
c906108c SS |
2745 | } |
2746 | ||
53a5351d JM |
2747 | /* Clear the "inserted" flag in all breakpoints and delete any |
2748 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2749 | |
2750 | Plus other such housekeeping that has to be done for breakpoints | |
2751 | between runs. | |
2752 | ||
53a5351d JM |
2753 | Note: this function gets called at the end of a run (by |
2754 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2755 | init_wait_for_inferior). */ |
c906108c SS |
2756 | |
2757 | ||
2758 | ||
2759 | void | |
fba45db2 | 2760 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2761 | { |
35df4500 TJB |
2762 | struct breakpoint *b, *b_tmp; |
2763 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2764 | int ix; |
6c95b8df | 2765 | struct program_space *pspace = current_program_space; |
c906108c | 2766 | |
50c71eaf PA |
2767 | /* If breakpoint locations are shared across processes, then there's |
2768 | nothing to do. */ | |
2567c7d9 | 2769 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2770 | return; |
2771 | ||
35df4500 | 2772 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2773 | { |
35df4500 TJB |
2774 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2775 | if (bl->pspace == pspace | |
2776 | && bl->owner->enable_state != bp_permanent) | |
2777 | bl->inserted = 0; | |
6c95b8df | 2778 | } |
075f6582 | 2779 | |
35df4500 | 2780 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2781 | { |
6c95b8df PA |
2782 | if (b->loc && b->loc->pspace != pspace) |
2783 | continue; | |
2784 | ||
c5aa993b JM |
2785 | switch (b->type) |
2786 | { | |
2787 | case bp_call_dummy: | |
c906108c | 2788 | |
c5aa993b | 2789 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2790 | cause problems when the inferior is rerun, so we better get |
2791 | rid of it. */ | |
2792 | ||
2793 | case bp_watchpoint_scope: | |
2794 | ||
2795 | /* Also get rid of scope breakpoints. */ | |
2796 | ||
2797 | case bp_shlib_event: | |
2798 | ||
2799 | /* Also remove solib event breakpoints. Their addresses may | |
2800 | have changed since the last time we ran the program. | |
2801 | Actually we may now be debugging against different target; | |
2802 | and so the solib backend that installed this breakpoint may | |
2803 | not be used in by the target. E.g., | |
2804 | ||
2805 | (gdb) file prog-linux | |
2806 | (gdb) run # native linux target | |
2807 | ... | |
2808 | (gdb) kill | |
2809 | (gdb) file prog-win.exe | |
2810 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2811 | */ | |
c906108c | 2812 | |
c5aa993b JM |
2813 | delete_breakpoint (b); |
2814 | break; | |
c906108c | 2815 | |
c5aa993b JM |
2816 | case bp_watchpoint: |
2817 | case bp_hardware_watchpoint: | |
2818 | case bp_read_watchpoint: | |
2819 | case bp_access_watchpoint: | |
3a5c3e22 PA |
2820 | { |
2821 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 2822 | |
3a5c3e22 PA |
2823 | /* Likewise for watchpoints on local expressions. */ |
2824 | if (w->exp_valid_block != NULL) | |
2825 | delete_breakpoint (b); | |
2826 | else if (context == inf_starting) | |
2827 | { | |
2828 | /* Reset val field to force reread of starting value in | |
2829 | insert_breakpoints. */ | |
2830 | if (w->val) | |
2831 | value_free (w->val); | |
2832 | w->val = NULL; | |
2833 | w->val_valid = 0; | |
c860120c | 2834 | } |
3a5c3e22 | 2835 | } |
c5aa993b JM |
2836 | break; |
2837 | default: | |
c5aa993b JM |
2838 | break; |
2839 | } | |
2840 | } | |
1c5cfe86 PA |
2841 | |
2842 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2843 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2844 | decref_bp_location (&bl); | |
1c5cfe86 | 2845 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2846 | } |
2847 | ||
6c95b8df PA |
2848 | /* These functions concern about actual breakpoints inserted in the |
2849 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2850 | we need to hop over the bkpt --- so we check for address space | |
2851 | match, not program space. */ | |
2852 | ||
c2c6d25f JM |
2853 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2854 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2855 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2856 | permanent breakpoint. | |
2857 | - When continuing from a location with an ordinary breakpoint, we | |
2858 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 2859 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
2860 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
2861 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2862 | |
c2c6d25f | 2863 | enum breakpoint_here |
6c95b8df | 2864 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2865 | { |
35df4500 | 2866 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2867 | int any_breakpoint_here = 0; |
c906108c | 2868 | |
35df4500 | 2869 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2870 | { |
35df4500 TJB |
2871 | if (bl->loc_type != bp_loc_software_breakpoint |
2872 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2873 | continue; |
2874 | ||
f1310107 | 2875 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
2876 | if ((breakpoint_enabled (bl->owner) |
2877 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 2878 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2879 | { |
2880 | if (overlay_debugging | |
35df4500 TJB |
2881 | && section_is_overlay (bl->section) |
2882 | && !section_is_mapped (bl->section)) | |
075f6582 | 2883 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2884 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2885 | return permanent_breakpoint_here; |
2886 | else | |
2887 | any_breakpoint_here = 1; | |
2888 | } | |
2889 | } | |
c906108c | 2890 | |
c2c6d25f | 2891 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2892 | } |
2893 | ||
1c5cfe86 PA |
2894 | /* Return true if there's a moribund breakpoint at PC. */ |
2895 | ||
2896 | int | |
6c95b8df | 2897 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2898 | { |
2899 | struct bp_location *loc; | |
2900 | int ix; | |
2901 | ||
2902 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 2903 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
2904 | return 1; |
2905 | ||
2906 | return 0; | |
2907 | } | |
c2c6d25f | 2908 | |
c36b740a | 2909 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2910 | inserted using regular breakpoint_chain / bp_location array |
2911 | mechanism. This does not check for single-step breakpoints, which | |
2912 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2913 | |
2914 | int | |
4a64f543 MS |
2915 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2916 | CORE_ADDR pc) | |
c906108c | 2917 | { |
35df4500 | 2918 | struct bp_location *bl, **blp_tmp; |
c906108c | 2919 | |
35df4500 | 2920 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2921 | { |
35df4500 TJB |
2922 | if (bl->loc_type != bp_loc_software_breakpoint |
2923 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2924 | continue; |
2925 | ||
35df4500 | 2926 | if (bl->inserted |
f1310107 | 2927 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2928 | { |
2929 | if (overlay_debugging | |
35df4500 TJB |
2930 | && section_is_overlay (bl->section) |
2931 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2932 | continue; /* unmapped overlay -- can't be a match */ |
2933 | else | |
2934 | return 1; | |
2935 | } | |
c5aa993b | 2936 | } |
c36b740a VP |
2937 | return 0; |
2938 | } | |
2939 | ||
2940 | /* Returns non-zero iff there's either regular breakpoint | |
2941 | or a single step breakpoint inserted at PC. */ | |
2942 | ||
2943 | int | |
6c95b8df | 2944 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2945 | { |
6c95b8df | 2946 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2947 | return 1; |
c906108c | 2948 | |
6c95b8df | 2949 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2950 | return 1; |
2951 | ||
c906108c SS |
2952 | return 0; |
2953 | } | |
2954 | ||
4fa8626c DJ |
2955 | /* This function returns non-zero iff there is a software breakpoint |
2956 | inserted at PC. */ | |
2957 | ||
2958 | int | |
3e43a32a MS |
2959 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
2960 | CORE_ADDR pc) | |
4fa8626c | 2961 | { |
35df4500 | 2962 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 2963 | |
35df4500 | 2964 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 2965 | { |
35df4500 | 2966 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
2967 | continue; |
2968 | ||
35df4500 TJB |
2969 | if (bl->inserted |
2970 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2971 | aspace, pc)) |
4fa8626c DJ |
2972 | { |
2973 | if (overlay_debugging | |
35df4500 TJB |
2974 | && section_is_overlay (bl->section) |
2975 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
2976 | continue; /* unmapped overlay -- can't be a match */ |
2977 | else | |
2978 | return 1; | |
2979 | } | |
2980 | } | |
2981 | ||
1aafd4da | 2982 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2983 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2984 | return 1; |
2985 | ||
4fa8626c DJ |
2986 | return 0; |
2987 | } | |
2988 | ||
9093389c PA |
2989 | int |
2990 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2991 | CORE_ADDR addr, ULONGEST len) | |
2992 | { | |
2993 | struct breakpoint *bpt; | |
2994 | ||
2995 | ALL_BREAKPOINTS (bpt) | |
2996 | { | |
2997 | struct bp_location *loc; | |
2998 | ||
2999 | if (bpt->type != bp_hardware_watchpoint | |
3000 | && bpt->type != bp_access_watchpoint) | |
3001 | continue; | |
3002 | ||
3003 | if (!breakpoint_enabled (bpt)) | |
3004 | continue; | |
3005 | ||
3006 | for (loc = bpt->loc; loc; loc = loc->next) | |
3007 | if (loc->pspace->aspace == aspace && loc->inserted) | |
3008 | { | |
3009 | CORE_ADDR l, h; | |
3010 | ||
3011 | /* Check for intersection. */ | |
3012 | l = max (loc->address, addr); | |
3013 | h = min (loc->address + loc->length, addr + len); | |
3014 | if (l < h) | |
3015 | return 1; | |
3016 | } | |
3017 | } | |
3018 | return 0; | |
3019 | } | |
3020 | ||
075f6582 DJ |
3021 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
3022 | PC is valid for process/thread PTID. */ | |
c906108c SS |
3023 | |
3024 | int | |
6c95b8df PA |
3025 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
3026 | ptid_t ptid) | |
c906108c | 3027 | { |
35df4500 | 3028 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 3029 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 3030 | int thread = -1; |
4a306c9a | 3031 | int task = 0; |
a6f1cd96 | 3032 | |
35df4500 | 3033 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3034 | { |
35df4500 TJB |
3035 | if (bl->loc_type != bp_loc_software_breakpoint |
3036 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3037 | continue; |
3038 | ||
35df4500 TJB |
3039 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
3040 | if (!breakpoint_enabled (bl->owner) | |
3041 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
3042 | continue; |
3043 | ||
f1310107 | 3044 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
3045 | continue; |
3046 | ||
35df4500 | 3047 | if (bl->owner->thread != -1) |
075f6582 | 3048 | { |
a6f1cd96 JB |
3049 | /* This is a thread-specific breakpoint. Check that ptid |
3050 | matches that thread. If thread hasn't been computed yet, | |
3051 | it is now time to do so. */ | |
3052 | if (thread == -1) | |
3053 | thread = pid_to_thread_id (ptid); | |
35df4500 | 3054 | if (bl->owner->thread != thread) |
a6f1cd96 | 3055 | continue; |
075f6582 | 3056 | } |
a6f1cd96 | 3057 | |
35df4500 | 3058 | if (bl->owner->task != 0) |
4a306c9a JB |
3059 | { |
3060 | /* This is a task-specific breakpoint. Check that ptid | |
3061 | matches that task. If task hasn't been computed yet, | |
3062 | it is now time to do so. */ | |
3063 | if (task == 0) | |
3064 | task = ada_get_task_number (ptid); | |
35df4500 | 3065 | if (bl->owner->task != task) |
4a306c9a JB |
3066 | continue; |
3067 | } | |
3068 | ||
a6f1cd96 | 3069 | if (overlay_debugging |
35df4500 TJB |
3070 | && section_is_overlay (bl->section) |
3071 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
3072 | continue; /* unmapped overlay -- can't be a match */ |
3073 | ||
3074 | return 1; | |
c5aa993b | 3075 | } |
c906108c SS |
3076 | |
3077 | return 0; | |
3078 | } | |
c906108c | 3079 | \f |
c5aa993b | 3080 | |
c906108c SS |
3081 | /* bpstat stuff. External routines' interfaces are documented |
3082 | in breakpoint.h. */ | |
3083 | ||
3084 | int | |
fba45db2 | 3085 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3086 | { |
533be4dd | 3087 | return (ep->type == bp_catchpoint); |
c906108c SS |
3088 | } |
3089 | ||
f431efe5 PA |
3090 | /* Frees any storage that is part of a bpstat. Does not walk the |
3091 | 'next' chain. */ | |
3092 | ||
3093 | static void | |
198757a8 VP |
3094 | bpstat_free (bpstat bs) |
3095 | { | |
3096 | if (bs->old_val != NULL) | |
3097 | value_free (bs->old_val); | |
9add0f1b | 3098 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3099 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3100 | xfree (bs); |
3101 | } | |
3102 | ||
c906108c SS |
3103 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3104 | Also free any storage that is part of a bpstat. */ | |
3105 | ||
3106 | void | |
fba45db2 | 3107 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3108 | { |
3109 | bpstat p; | |
3110 | bpstat q; | |
3111 | ||
3112 | if (bsp == 0) | |
3113 | return; | |
3114 | p = *bsp; | |
3115 | while (p != NULL) | |
3116 | { | |
3117 | q = p->next; | |
198757a8 | 3118 | bpstat_free (p); |
c906108c SS |
3119 | p = q; |
3120 | } | |
3121 | *bsp = NULL; | |
3122 | } | |
3123 | ||
3124 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3125 | is part of the bpstat is copied as well. */ | |
3126 | ||
3127 | bpstat | |
fba45db2 | 3128 | bpstat_copy (bpstat bs) |
c906108c SS |
3129 | { |
3130 | bpstat p = NULL; | |
3131 | bpstat tmp; | |
3132 | bpstat retval = NULL; | |
3133 | ||
3134 | if (bs == NULL) | |
3135 | return bs; | |
3136 | ||
3137 | for (; bs != NULL; bs = bs->next) | |
3138 | { | |
3139 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3140 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3141 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3142 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3143 | if (bs->old_val != NULL) |
3c3185ac JK |
3144 | { |
3145 | tmp->old_val = value_copy (bs->old_val); | |
3146 | release_value (tmp->old_val); | |
3147 | } | |
31cc81e9 | 3148 | |
c906108c SS |
3149 | if (p == NULL) |
3150 | /* This is the first thing in the chain. */ | |
3151 | retval = tmp; | |
3152 | else | |
3153 | p->next = tmp; | |
3154 | p = tmp; | |
3155 | } | |
3156 | p->next = NULL; | |
3157 | return retval; | |
3158 | } | |
3159 | ||
4a64f543 | 3160 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3161 | |
3162 | bpstat | |
fba45db2 | 3163 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3164 | { |
c5aa993b JM |
3165 | if (bsp == NULL) |
3166 | return NULL; | |
c906108c | 3167 | |
c5aa993b JM |
3168 | for (; bsp != NULL; bsp = bsp->next) |
3169 | { | |
f431efe5 | 3170 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3171 | return bsp; |
3172 | } | |
c906108c SS |
3173 | return NULL; |
3174 | } | |
3175 | ||
4a64f543 MS |
3176 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3177 | stopped at. *BSP upon return is a bpstat which points to the | |
3178 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3179 | good for anything but further calls to bpstat_num). | |
3180 | ||
8671a17b PA |
3181 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3182 | Return -1 if stopped at a breakpoint that has been deleted since | |
3183 | we set it. | |
3184 | Return 1 otherwise. */ | |
c906108c SS |
3185 | |
3186 | int | |
8671a17b | 3187 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3188 | { |
3189 | struct breakpoint *b; | |
3190 | ||
3191 | if ((*bsp) == NULL) | |
3192 | return 0; /* No more breakpoint values */ | |
8671a17b | 3193 | |
4a64f543 MS |
3194 | /* We assume we'll never have several bpstats that correspond to a |
3195 | single breakpoint -- otherwise, this function might return the | |
3196 | same number more than once and this will look ugly. */ | |
f431efe5 | 3197 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3198 | *bsp = (*bsp)->next; |
3199 | if (b == NULL) | |
3200 | return -1; /* breakpoint that's been deleted since */ | |
3201 | ||
3202 | *num = b->number; /* We have its number */ | |
3203 | return 1; | |
c906108c SS |
3204 | } |
3205 | ||
e93ca019 | 3206 | /* See breakpoint.h. */ |
c906108c SS |
3207 | |
3208 | void | |
e93ca019 | 3209 | bpstat_clear_actions (void) |
c906108c | 3210 | { |
e93ca019 JK |
3211 | struct thread_info *tp; |
3212 | bpstat bs; | |
3213 | ||
3214 | if (ptid_equal (inferior_ptid, null_ptid)) | |
3215 | return; | |
3216 | ||
3217 | tp = find_thread_ptid (inferior_ptid); | |
3218 | if (tp == NULL) | |
3219 | return; | |
3220 | ||
3221 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 3222 | { |
9add0f1b | 3223 | decref_counted_command_line (&bs->commands); |
abf85f46 | 3224 | |
c906108c SS |
3225 | if (bs->old_val != NULL) |
3226 | { | |
3227 | value_free (bs->old_val); | |
3228 | bs->old_val = NULL; | |
3229 | } | |
3230 | } | |
3231 | } | |
3232 | ||
f3b1572e PA |
3233 | /* Called when a command is about to proceed the inferior. */ |
3234 | ||
3235 | static void | |
3236 | breakpoint_about_to_proceed (void) | |
3237 | { | |
3238 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3239 | { | |
3240 | struct thread_info *tp = inferior_thread (); | |
3241 | ||
3242 | /* Allow inferior function calls in breakpoint commands to not | |
3243 | interrupt the command list. When the call finishes | |
3244 | successfully, the inferior will be standing at the same | |
3245 | breakpoint as if nothing happened. */ | |
16c381f0 | 3246 | if (tp->control.in_infcall) |
f3b1572e PA |
3247 | return; |
3248 | } | |
3249 | ||
3250 | breakpoint_proceeded = 1; | |
3251 | } | |
3252 | ||
4a64f543 MS |
3253 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3254 | command. */ | |
c906108c | 3255 | static void |
4efb68b1 | 3256 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3257 | { |
3258 | executing_breakpoint_commands = 0; | |
3259 | } | |
3260 | ||
abf85f46 JK |
3261 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
3262 | or its equivalent. */ | |
3263 | ||
3264 | static int | |
3265 | command_line_is_silent (struct command_line *cmd) | |
3266 | { | |
3267 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
3268 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
3269 | } | |
3270 | ||
4a64f543 MS |
3271 | /* Execute all the commands associated with all the breakpoints at |
3272 | this location. Any of these commands could cause the process to | |
3273 | proceed beyond this point, etc. We look out for such changes by | |
3274 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3275 | |
347bddb7 PA |
3276 | Returns true if a breakpoint command resumed the inferior. In that |
3277 | case, it is the caller's responsibility to recall it again with the | |
3278 | bpstat of the current thread. */ | |
3279 | ||
3280 | static int | |
3281 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3282 | { |
3283 | bpstat bs; | |
3284 | struct cleanup *old_chain; | |
347bddb7 | 3285 | int again = 0; |
c906108c SS |
3286 | |
3287 | /* Avoid endless recursion if a `source' command is contained | |
3288 | in bs->commands. */ | |
3289 | if (executing_breakpoint_commands) | |
347bddb7 | 3290 | return 0; |
c906108c SS |
3291 | |
3292 | executing_breakpoint_commands = 1; | |
3293 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3294 | ||
cf6c5ffb TT |
3295 | prevent_dont_repeat (); |
3296 | ||
4a64f543 | 3297 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3298 | bs = *bsp; |
3299 | ||
3300 | breakpoint_proceeded = 0; | |
3301 | for (; bs != NULL; bs = bs->next) | |
3302 | { | |
9add0f1b | 3303 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3304 | struct command_line *cmd; |
3305 | struct cleanup *this_cmd_tree_chain; | |
3306 | ||
3307 | /* Take ownership of the BSP's command tree, if it has one. | |
3308 | ||
3309 | The command tree could legitimately contain commands like | |
3310 | 'step' and 'next', which call clear_proceed_status, which | |
3311 | frees stop_bpstat's command tree. To make sure this doesn't | |
3312 | free the tree we're executing out from under us, we need to | |
3313 | take ownership of the tree ourselves. Since a given bpstat's | |
3314 | commands are only executed once, we don't need to copy it; we | |
3315 | can clear the pointer in the bpstat, and make sure we free | |
3316 | the tree when we're done. */ | |
9add0f1b TT |
3317 | ccmd = bs->commands; |
3318 | bs->commands = NULL; | |
abf85f46 JK |
3319 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
3320 | cmd = ccmd ? ccmd->commands : NULL; | |
3321 | if (command_line_is_silent (cmd)) | |
3322 | { | |
3323 | /* The action has been already done by bpstat_stop_status. */ | |
3324 | cmd = cmd->next; | |
3325 | } | |
6c50ab1c | 3326 | |
c906108c SS |
3327 | while (cmd != NULL) |
3328 | { | |
3329 | execute_control_command (cmd); | |
3330 | ||
3331 | if (breakpoint_proceeded) | |
3332 | break; | |
3333 | else | |
3334 | cmd = cmd->next; | |
3335 | } | |
6c50ab1c JB |
3336 | |
3337 | /* We can free this command tree now. */ | |
3338 | do_cleanups (this_cmd_tree_chain); | |
3339 | ||
c906108c | 3340 | if (breakpoint_proceeded) |
32c1e744 VP |
3341 | { |
3342 | if (target_can_async_p ()) | |
347bddb7 PA |
3343 | /* If we are in async mode, then the target might be still |
3344 | running, not stopped at any breakpoint, so nothing for | |
3345 | us to do here -- just return to the event loop. */ | |
3346 | ; | |
32c1e744 VP |
3347 | else |
3348 | /* In sync mode, when execute_control_command returns | |
3349 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3350 | Breakpoint commands for that stop were not run, since |
3351 | execute_command does not run breakpoint commands -- | |
3352 | only command_line_handler does, but that one is not | |
3353 | involved in execution of breakpoint commands. So, we | |
3354 | can now execute breakpoint commands. It should be | |
3355 | noted that making execute_command do bpstat actions is | |
3356 | not an option -- in this case we'll have recursive | |
3357 | invocation of bpstat for each breakpoint with a | |
3358 | command, and can easily blow up GDB stack. Instead, we | |
3359 | return true, which will trigger the caller to recall us | |
3360 | with the new stop_bpstat. */ | |
3361 | again = 1; | |
3362 | break; | |
32c1e744 | 3363 | } |
c906108c | 3364 | } |
c2b8ed2c | 3365 | do_cleanups (old_chain); |
347bddb7 PA |
3366 | return again; |
3367 | } | |
3368 | ||
3369 | void | |
3370 | bpstat_do_actions (void) | |
3371 | { | |
353d1d73 JK |
3372 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
3373 | ||
347bddb7 PA |
3374 | /* Do any commands attached to breakpoint we are stopped at. */ |
3375 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3376 | && target_has_execution | |
3377 | && !is_exited (inferior_ptid) | |
3378 | && !is_executing (inferior_ptid)) | |
3379 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3380 | and only return when it is stopped at the next breakpoint, we | |
3381 | keep doing breakpoint actions until it returns false to | |
3382 | indicate the inferior was not resumed. */ | |
16c381f0 | 3383 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3384 | break; |
353d1d73 JK |
3385 | |
3386 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
3387 | } |
3388 | ||
fa4727a6 DJ |
3389 | /* Print out the (old or new) value associated with a watchpoint. */ |
3390 | ||
3391 | static void | |
3392 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3393 | { | |
3394 | if (val == NULL) | |
3395 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3396 | else | |
79a45b7d TT |
3397 | { |
3398 | struct value_print_options opts; | |
3399 | get_user_print_options (&opts); | |
3400 | value_print (val, stream, &opts); | |
3401 | } | |
fa4727a6 DJ |
3402 | } |
3403 | ||
e514a9d6 | 3404 | /* Generic routine for printing messages indicating why we |
4a64f543 | 3405 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3406 | 'print_it' in the bpstat structure. Under some circumstances we |
3407 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3408 | normal_stop(). */ |
e514a9d6 JM |
3409 | |
3410 | static enum print_stop_action | |
3411 | print_bp_stop_message (bpstat bs) | |
3412 | { | |
3413 | switch (bs->print_it) | |
3414 | { | |
3415 | case print_it_noop: | |
4a64f543 | 3416 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3417 | return PRINT_UNKNOWN; |
3418 | break; | |
3419 | ||
3420 | case print_it_done: | |
3421 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3422 | relevant messages. */ |
e514a9d6 JM |
3423 | return PRINT_SRC_AND_LOC; |
3424 | break; | |
3425 | ||
3426 | case print_it_normal: | |
4f8d1dc6 | 3427 | { |
f431efe5 PA |
3428 | struct breakpoint *b = bs->breakpoint_at; |
3429 | ||
1a6a67de TJB |
3430 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3431 | which has since been deleted. */ | |
3432 | if (b == NULL) | |
3433 | return PRINT_UNKNOWN; | |
3434 | ||
348d480f PA |
3435 | /* Normal case. Call the breakpoint's print_it method. */ |
3436 | return b->ops->print_it (bs); | |
4f8d1dc6 | 3437 | } |
348d480f | 3438 | break; |
3086aeae | 3439 | |
e514a9d6 | 3440 | default: |
8e65ff28 | 3441 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3442 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3443 | break; |
c906108c | 3444 | } |
c906108c SS |
3445 | } |
3446 | ||
e514a9d6 JM |
3447 | /* Print a message indicating what happened. This is called from |
3448 | normal_stop(). The input to this routine is the head of the bpstat | |
3449 | list - a list of the eventpoints that caused this stop. This | |
3450 | routine calls the generic print routine for printing a message | |
3451 | about reasons for stopping. This will print (for example) the | |
3452 | "Breakpoint n," part of the output. The return value of this | |
3453 | routine is one of: | |
c906108c | 3454 | |
4a64f543 | 3455 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3456 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3457 | code to print the location. An example is |
c5aa993b JM |
3458 | "Breakpoint 1, " which should be followed by |
3459 | the location. | |
917317f4 | 3460 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3461 | to also print the location part of the message. |
3462 | An example is the catch/throw messages, which | |
4a64f543 | 3463 | don't require a location appended to the end. |
917317f4 | 3464 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3465 | further info to be printed. */ |
c906108c | 3466 | |
917317f4 | 3467 | enum print_stop_action |
fba45db2 | 3468 | bpstat_print (bpstat bs) |
c906108c SS |
3469 | { |
3470 | int val; | |
c5aa993b | 3471 | |
c906108c | 3472 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3473 | (Currently all watchpoints go on the bpstat whether hit or not. |
3474 | That probably could (should) be changed, provided care is taken | |
c906108c | 3475 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3476 | for (; bs; bs = bs->next) |
3477 | { | |
3478 | val = print_bp_stop_message (bs); | |
3479 | if (val == PRINT_SRC_ONLY | |
3480 | || val == PRINT_SRC_AND_LOC | |
3481 | || val == PRINT_NOTHING) | |
3482 | return val; | |
3483 | } | |
c906108c | 3484 | |
e514a9d6 | 3485 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3486 | with and nothing was printed. */ |
917317f4 | 3487 | return PRINT_UNKNOWN; |
c906108c SS |
3488 | } |
3489 | ||
4a64f543 MS |
3490 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3491 | used inside a catch_errors to evaluate the breakpoint condition. | |
3492 | The argument is a "struct expression *" that has been cast to a | |
3493 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3494 | |
3495 | static int | |
4efb68b1 | 3496 | breakpoint_cond_eval (void *exp) |
c906108c | 3497 | { |
278cd55f | 3498 | struct value *mark = value_mark (); |
c5aa993b | 3499 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3500 | |
c906108c SS |
3501 | value_free_to_mark (mark); |
3502 | return i; | |
3503 | } | |
3504 | ||
5760d0ab | 3505 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3506 | |
3507 | static bpstat | |
5760d0ab | 3508 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3509 | { |
3510 | bpstat bs; | |
3511 | ||
3512 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3513 | bs->next = NULL; |
3514 | **bs_link_pointer = bs; | |
3515 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3516 | bs->breakpoint_at = bl->owner; |
3517 | bs->bp_location_at = bl; | |
3518 | incref_bp_location (bl); | |
c906108c SS |
3519 | /* If the condition is false, etc., don't do the commands. */ |
3520 | bs->commands = NULL; | |
3521 | bs->old_val = NULL; | |
3522 | bs->print_it = print_it_normal; | |
3523 | return bs; | |
3524 | } | |
3525 | \f | |
d983da9c DJ |
3526 | /* The target has stopped with waitstatus WS. Check if any hardware |
3527 | watchpoints have triggered, according to the target. */ | |
3528 | ||
3529 | int | |
3530 | watchpoints_triggered (struct target_waitstatus *ws) | |
3531 | { | |
d92524f1 | 3532 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3533 | CORE_ADDR addr; |
3534 | struct breakpoint *b; | |
3535 | ||
3536 | if (!stopped_by_watchpoint) | |
3537 | { | |
3538 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3539 | as not triggered. */ | |
3540 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3541 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3542 | { |
3543 | struct watchpoint *w = (struct watchpoint *) b; | |
3544 | ||
3545 | w->watchpoint_triggered = watch_triggered_no; | |
3546 | } | |
d983da9c DJ |
3547 | |
3548 | return 0; | |
3549 | } | |
3550 | ||
3551 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3552 | { | |
3553 | /* We were stopped by a watchpoint, but we don't know where. | |
3554 | Mark all watchpoints as unknown. */ | |
3555 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3556 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3557 | { |
3558 | struct watchpoint *w = (struct watchpoint *) b; | |
3559 | ||
3560 | w->watchpoint_triggered = watch_triggered_unknown; | |
3561 | } | |
d983da9c DJ |
3562 | |
3563 | return stopped_by_watchpoint; | |
3564 | } | |
3565 | ||
3566 | /* The target could report the data address. Mark watchpoints | |
3567 | affected by this data address as triggered, and all others as not | |
3568 | triggered. */ | |
3569 | ||
3570 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3571 | if (is_hardware_watchpoint (b)) |
d983da9c | 3572 | { |
3a5c3e22 | 3573 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 3574 | struct bp_location *loc; |
d983da9c | 3575 | |
3a5c3e22 | 3576 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 3577 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 3578 | { |
3a5c3e22 | 3579 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 3580 | { |
3a5c3e22 PA |
3581 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
3582 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
3583 | |
3584 | if (newaddr == start) | |
3585 | { | |
3a5c3e22 | 3586 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3587 | break; |
3588 | } | |
3589 | } | |
3590 | /* Exact match not required. Within range is sufficient. */ | |
3591 | else if (target_watchpoint_addr_within_range (¤t_target, | |
3592 | addr, loc->address, | |
3593 | loc->length)) | |
3594 | { | |
3a5c3e22 | 3595 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3596 | break; |
3597 | } | |
3598 | } | |
d983da9c DJ |
3599 | } |
3600 | ||
3601 | return 1; | |
3602 | } | |
3603 | ||
c906108c SS |
3604 | /* Possible return values for watchpoint_check (this can't be an enum |
3605 | because of check_errors). */ | |
3606 | /* The watchpoint has been deleted. */ | |
3607 | #define WP_DELETED 1 | |
3608 | /* The value has changed. */ | |
3609 | #define WP_VALUE_CHANGED 2 | |
3610 | /* The value has not changed. */ | |
3611 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3612 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3613 | #define WP_IGNORE 4 | |
c906108c SS |
3614 | |
3615 | #define BP_TEMPFLAG 1 | |
3616 | #define BP_HARDWAREFLAG 2 | |
3617 | ||
4a64f543 MS |
3618 | /* Evaluate watchpoint condition expression and check if its value |
3619 | changed. | |
553e4c11 JB |
3620 | |
3621 | P should be a pointer to struct bpstat, but is defined as a void * | |
3622 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3623 | |
3624 | static int | |
4efb68b1 | 3625 | watchpoint_check (void *p) |
c906108c SS |
3626 | { |
3627 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 3628 | struct watchpoint *b; |
c906108c SS |
3629 | struct frame_info *fr; |
3630 | int within_current_scope; | |
3631 | ||
f431efe5 | 3632 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3633 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 3634 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 3635 | |
f6bc2008 PA |
3636 | /* If this is a local watchpoint, we only want to check if the |
3637 | watchpoint frame is in scope if the current thread is the thread | |
3638 | that was used to create the watchpoint. */ | |
3639 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3640 | return WP_IGNORE; |
f6bc2008 | 3641 | |
c906108c SS |
3642 | if (b->exp_valid_block == NULL) |
3643 | within_current_scope = 1; | |
3644 | else | |
3645 | { | |
edb3359d DJ |
3646 | struct frame_info *frame = get_current_frame (); |
3647 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3648 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3649 | ||
4a64f543 MS |
3650 | /* in_function_epilogue_p() returns a non-zero value if we're |
3651 | still in the function but the stack frame has already been | |
3652 | invalidated. Since we can't rely on the values of local | |
3653 | variables after the stack has been destroyed, we are treating | |
3654 | the watchpoint in that state as `not changed' without further | |
3655 | checking. Don't mark watchpoints as changed if the current | |
3656 | frame is in an epilogue - even if they are in some other | |
3657 | frame, our view of the stack is likely to be wrong and | |
3658 | frame_find_by_id could error out. */ | |
a0f49112 | 3659 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3660 | return WP_IGNORE; |
a0f49112 | 3661 | |
101dcfbe | 3662 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3663 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3664 | |
3665 | /* If we've gotten confused in the unwinder, we might have | |
3666 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3667 | if (within_current_scope) |
3668 | { | |
3669 | struct symbol *function; | |
3670 | ||
3671 | function = get_frame_function (fr); | |
3672 | if (function == NULL | |
3673 | || !contained_in (b->exp_valid_block, | |
3674 | SYMBOL_BLOCK_VALUE (function))) | |
3675 | within_current_scope = 0; | |
3676 | } | |
69fbadd5 | 3677 | |
edb3359d | 3678 | if (within_current_scope) |
c906108c SS |
3679 | /* If we end up stopping, the current frame will get selected |
3680 | in normal_stop. So this call to select_frame won't affect | |
3681 | the user. */ | |
0f7d239c | 3682 | select_frame (fr); |
c906108c | 3683 | } |
c5aa993b | 3684 | |
c906108c SS |
3685 | if (within_current_scope) |
3686 | { | |
4a64f543 MS |
3687 | /* We use value_{,free_to_}mark because it could be a *long* |
3688 | time before we return to the command level and call | |
3689 | free_all_values. We can't call free_all_values because we | |
3690 | might be in the middle of evaluating a function call. */ | |
c906108c | 3691 | |
0cf6dd15 | 3692 | int pc = 0; |
9c06b0b4 | 3693 | struct value *mark; |
fa4727a6 DJ |
3694 | struct value *new_val; |
3695 | ||
3a5c3e22 | 3696 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
3697 | /* Since we don't know the exact trigger address (from |
3698 | stopped_data_address), just tell the user we've triggered | |
3699 | a mask watchpoint. */ | |
3700 | return WP_VALUE_CHANGED; | |
3701 | ||
3702 | mark = value_mark (); | |
0cf6dd15 | 3703 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3704 | |
4a64f543 MS |
3705 | /* We use value_equal_contents instead of value_equal because |
3706 | the latter coerces an array to a pointer, thus comparing just | |
3707 | the address of the array instead of its contents. This is | |
3708 | not what we want. */ | |
fa4727a6 | 3709 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3710 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3711 | { |
fa4727a6 DJ |
3712 | if (new_val != NULL) |
3713 | { | |
3714 | release_value (new_val); | |
3715 | value_free_to_mark (mark); | |
3716 | } | |
c906108c SS |
3717 | bs->old_val = b->val; |
3718 | b->val = new_val; | |
fa4727a6 | 3719 | b->val_valid = 1; |
c906108c SS |
3720 | return WP_VALUE_CHANGED; |
3721 | } | |
3722 | else | |
3723 | { | |
60e1c644 | 3724 | /* Nothing changed. */ |
c906108c | 3725 | value_free_to_mark (mark); |
c906108c SS |
3726 | return WP_VALUE_NOT_CHANGED; |
3727 | } | |
3728 | } | |
3729 | else | |
3730 | { | |
79a45e25 PA |
3731 | struct ui_out *uiout = current_uiout; |
3732 | ||
c906108c | 3733 | /* This seems like the only logical thing to do because |
c5aa993b JM |
3734 | if we temporarily ignored the watchpoint, then when |
3735 | we reenter the block in which it is valid it contains | |
3736 | garbage (in the case of a function, it may have two | |
3737 | garbage values, one before and one after the prologue). | |
3738 | So we can't even detect the first assignment to it and | |
3739 | watch after that (since the garbage may or may not equal | |
3740 | the first value assigned). */ | |
348d480f PA |
3741 | /* We print all the stop information in |
3742 | breakpoint_ops->print_it, but in this case, by the time we | |
3743 | call breakpoint_ops->print_it this bp will be deleted | |
3744 | already. So we have no choice but print the information | |
3745 | here. */ | |
9dc5e2a9 | 3746 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3747 | ui_out_field_string |
3748 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3749 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 3750 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
3751 | ui_out_text (uiout, |
3752 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3753 | which its expression is valid.\n"); |
4ce44c66 | 3754 | |
cdac0397 | 3755 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 3756 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 3757 | watchpoint_del_at_next_stop (b); |
c906108c SS |
3758 | |
3759 | return WP_DELETED; | |
3760 | } | |
3761 | } | |
3762 | ||
18a18393 | 3763 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
3764 | breakpoint location BL. This function does not check if we should |
3765 | stop, only if BL explains the stop. */ | |
3766 | ||
18a18393 | 3767 | static int |
6c95b8df PA |
3768 | bpstat_check_location (const struct bp_location *bl, |
3769 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3770 | { |
3771 | struct breakpoint *b = bl->owner; | |
3772 | ||
348d480f | 3773 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
3774 | gdb_assert (b != NULL); |
3775 | ||
348d480f | 3776 | return b->ops->breakpoint_hit (bl, aspace, bp_addr); |
18a18393 VP |
3777 | } |
3778 | ||
3a5c3e22 PA |
3779 | /* Determine if the watched values have actually changed, and we |
3780 | should stop. If not, set BS->stop to 0. */ | |
3781 | ||
18a18393 VP |
3782 | static void |
3783 | bpstat_check_watchpoint (bpstat bs) | |
3784 | { | |
2bdf28a0 | 3785 | const struct bp_location *bl; |
3a5c3e22 | 3786 | struct watchpoint *b; |
2bdf28a0 JK |
3787 | |
3788 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3789 | bl = bs->bp_location_at; |
2bdf28a0 | 3790 | gdb_assert (bl != NULL); |
3a5c3e22 | 3791 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 3792 | gdb_assert (b != NULL); |
18a18393 | 3793 | |
18a18393 | 3794 | { |
18a18393 VP |
3795 | int must_check_value = 0; |
3796 | ||
3a5c3e22 | 3797 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
3798 | /* For a software watchpoint, we must always check the |
3799 | watched value. */ | |
3800 | must_check_value = 1; | |
3801 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3802 | /* We have a hardware watchpoint (read, write, or access) | |
3803 | and the target earlier reported an address watched by | |
3804 | this watchpoint. */ | |
3805 | must_check_value = 1; | |
3806 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 3807 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
3808 | /* We were stopped by a hardware watchpoint, but the target could |
3809 | not report the data address. We must check the watchpoint's | |
3810 | value. Access and read watchpoints are out of luck; without | |
3811 | a data address, we can't figure it out. */ | |
3812 | must_check_value = 1; | |
3a5c3e22 | 3813 | |
18a18393 VP |
3814 | if (must_check_value) |
3815 | { | |
3e43a32a MS |
3816 | char *message |
3817 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 3818 | b->base.number); |
18a18393 VP |
3819 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3820 | int e = catch_errors (watchpoint_check, bs, message, | |
3821 | RETURN_MASK_ALL); | |
3822 | do_cleanups (cleanups); | |
3823 | switch (e) | |
3824 | { | |
3825 | case WP_DELETED: | |
3826 | /* We've already printed what needs to be printed. */ | |
3827 | bs->print_it = print_it_done; | |
3828 | /* Stop. */ | |
3829 | break; | |
60e1c644 PA |
3830 | case WP_IGNORE: |
3831 | bs->print_it = print_it_noop; | |
3832 | bs->stop = 0; | |
3833 | break; | |
18a18393 | 3834 | case WP_VALUE_CHANGED: |
3a5c3e22 | 3835 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 3836 | { |
85d721b8 PA |
3837 | /* There are two cases to consider here: |
3838 | ||
4a64f543 | 3839 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3840 | In that case, trust the target, and always report |
3841 | the watchpoint hit to the user. Even though | |
3842 | reads don't cause value changes, the value may | |
3843 | have changed since the last time it was read, and | |
3844 | since we're not trapping writes, we will not see | |
3845 | those, and as such we should ignore our notion of | |
3846 | old value. | |
3847 | ||
4a64f543 | 3848 | 2. We're watching the triggered memory for both |
85d721b8 PA |
3849 | reads and writes. There are two ways this may |
3850 | happen: | |
3851 | ||
4a64f543 | 3852 | 2.1. This is a target that can't break on data |
85d721b8 PA |
3853 | reads only, but can break on accesses (reads or |
3854 | writes), such as e.g., x86. We detect this case | |
3855 | at the time we try to insert read watchpoints. | |
3856 | ||
4a64f543 | 3857 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
3858 | watchpoints, but, the user set an access or write |
3859 | watchpoint watching the same memory as this read | |
3860 | watchpoint. | |
3861 | ||
3862 | If we're watching memory writes as well as reads, | |
3863 | ignore watchpoint hits when we find that the | |
3864 | value hasn't changed, as reads don't cause | |
3865 | changes. This still gives false positives when | |
3866 | the program writes the same value to memory as | |
3867 | what there was already in memory (we will confuse | |
3868 | it for a read), but it's much better than | |
3869 | nothing. */ | |
3870 | ||
3871 | int other_write_watchpoint = 0; | |
3872 | ||
3873 | if (bl->watchpoint_type == hw_read) | |
3874 | { | |
3875 | struct breakpoint *other_b; | |
3876 | ||
3877 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
3878 | if (other_b->type == bp_hardware_watchpoint |
3879 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 3880 | { |
3a5c3e22 PA |
3881 | struct watchpoint *other_w = |
3882 | (struct watchpoint *) other_b; | |
3883 | ||
3884 | if (other_w->watchpoint_triggered | |
3885 | == watch_triggered_yes) | |
3886 | { | |
3887 | other_write_watchpoint = 1; | |
3888 | break; | |
3889 | } | |
85d721b8 PA |
3890 | } |
3891 | } | |
3892 | ||
3893 | if (other_write_watchpoint | |
3894 | || bl->watchpoint_type == hw_access) | |
3895 | { | |
3896 | /* We're watching the same memory for writes, | |
3897 | and the value changed since the last time we | |
3898 | updated it, so this trap must be for a write. | |
3899 | Ignore it. */ | |
3900 | bs->print_it = print_it_noop; | |
3901 | bs->stop = 0; | |
3902 | } | |
18a18393 VP |
3903 | } |
3904 | break; | |
3905 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
3906 | if (b->base.type == bp_hardware_watchpoint |
3907 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
3908 | { |
3909 | /* Don't stop: write watchpoints shouldn't fire if | |
3910 | the value hasn't changed. */ | |
3911 | bs->print_it = print_it_noop; | |
3912 | bs->stop = 0; | |
3913 | } | |
3914 | /* Stop. */ | |
3915 | break; | |
3916 | default: | |
3917 | /* Can't happen. */ | |
3918 | case 0: | |
3919 | /* Error from catch_errors. */ | |
3a5c3e22 | 3920 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 3921 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
3922 | /* We've already printed what needs to be printed. */ |
3923 | bs->print_it = print_it_done; | |
3924 | break; | |
3925 | } | |
3926 | } | |
3927 | else /* must_check_value == 0 */ | |
3928 | { | |
3929 | /* This is a case where some watchpoint(s) triggered, but | |
3930 | not at the address of this watchpoint, or else no | |
3931 | watchpoint triggered after all. So don't print | |
3932 | anything for this watchpoint. */ | |
3933 | bs->print_it = print_it_noop; | |
3934 | bs->stop = 0; | |
3935 | } | |
3936 | } | |
3937 | } | |
3938 | ||
3939 | ||
3940 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3941 | of breakpoint referred to by BS. If we should not stop for this | |
3942 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 3943 | |
18a18393 VP |
3944 | static void |
3945 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3946 | { | |
3947 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
3948 | const struct bp_location *bl; |
3949 | struct breakpoint *b; | |
3950 | ||
3951 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3952 | bl = bs->bp_location_at; |
2bdf28a0 | 3953 | gdb_assert (bl != NULL); |
f431efe5 | 3954 | b = bs->breakpoint_at; |
2bdf28a0 | 3955 | gdb_assert (b != NULL); |
18a18393 VP |
3956 | |
3957 | if (frame_id_p (b->frame_id) | |
edb3359d | 3958 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3959 | bs->stop = 0; |
3960 | else if (bs->stop) | |
3961 | { | |
3962 | int value_is_zero = 0; | |
60e1c644 PA |
3963 | struct expression *cond; |
3964 | ||
7371cf6d PM |
3965 | /* Evaluate Python breakpoints that have a "stop" |
3966 | method implemented. */ | |
3967 | if (b->py_bp_object) | |
3968 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
3969 | ||
60e1c644 | 3970 | if (is_watchpoint (b)) |
3a5c3e22 PA |
3971 | { |
3972 | struct watchpoint *w = (struct watchpoint *) b; | |
3973 | ||
3974 | cond = w->cond_exp; | |
3975 | } | |
60e1c644 PA |
3976 | else |
3977 | cond = bl->cond; | |
3978 | ||
f431efe5 | 3979 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 3980 | { |
60e1c644 | 3981 | int within_current_scope = 1; |
3a5c3e22 | 3982 | struct watchpoint * w; |
60e1c644 | 3983 | |
c5bc3a77 DJ |
3984 | /* We use value_mark and value_free_to_mark because it could |
3985 | be a long time before we return to the command level and | |
3986 | call free_all_values. We can't call free_all_values | |
3987 | because we might be in the middle of evaluating a | |
3988 | function call. */ | |
3989 | struct value *mark = value_mark (); | |
3990 | ||
3a5c3e22 PA |
3991 | if (is_watchpoint (b)) |
3992 | w = (struct watchpoint *) b; | |
3993 | else | |
3994 | w = NULL; | |
3995 | ||
edb3359d DJ |
3996 | /* Need to select the frame, with all that implies so that |
3997 | the conditions will have the right context. Because we | |
3998 | use the frame, we will not see an inlined function's | |
3999 | variables when we arrive at a breakpoint at the start | |
4000 | of the inlined function; the current frame will be the | |
4001 | call site. */ | |
3a5c3e22 | 4002 | if (w == NULL || w->cond_exp_valid_block == NULL) |
60e1c644 PA |
4003 | select_frame (get_current_frame ()); |
4004 | else | |
4005 | { | |
4006 | struct frame_info *frame; | |
4007 | ||
4008 | /* For local watchpoint expressions, which particular | |
4009 | instance of a local is being watched matters, so we | |
4010 | keep track of the frame to evaluate the expression | |
4011 | in. To evaluate the condition however, it doesn't | |
4012 | really matter which instantiation of the function | |
4013 | where the condition makes sense triggers the | |
4014 | watchpoint. This allows an expression like "watch | |
4015 | global if q > 10" set in `func', catch writes to | |
4016 | global on all threads that call `func', or catch | |
4017 | writes on all recursive calls of `func' by a single | |
4018 | thread. We simply always evaluate the condition in | |
4019 | the innermost frame that's executing where it makes | |
4020 | sense to evaluate the condition. It seems | |
4021 | intuitive. */ | |
3a5c3e22 | 4022 | frame = block_innermost_frame (w->cond_exp_valid_block); |
60e1c644 PA |
4023 | if (frame != NULL) |
4024 | select_frame (frame); | |
4025 | else | |
4026 | within_current_scope = 0; | |
4027 | } | |
4028 | if (within_current_scope) | |
4029 | value_is_zero | |
4030 | = catch_errors (breakpoint_cond_eval, cond, | |
4031 | "Error in testing breakpoint condition:\n", | |
4032 | RETURN_MASK_ALL); | |
4033 | else | |
4034 | { | |
4035 | warning (_("Watchpoint condition cannot be tested " | |
4036 | "in the current scope")); | |
4037 | /* If we failed to set the right context for this | |
4038 | watchpoint, unconditionally report it. */ | |
4039 | value_is_zero = 0; | |
4040 | } | |
4a64f543 | 4041 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4042 | value_free_to_mark (mark); |
18a18393 | 4043 | } |
60e1c644 PA |
4044 | |
4045 | if (cond && value_is_zero) | |
18a18393 VP |
4046 | { |
4047 | bs->stop = 0; | |
4048 | } | |
4049 | else if (b->thread != -1 && b->thread != thread_id) | |
4050 | { | |
4051 | bs->stop = 0; | |
4052 | } | |
4053 | else if (b->ignore_count > 0) | |
4054 | { | |
4055 | b->ignore_count--; | |
4056 | annotate_ignore_count_change (); | |
4057 | bs->stop = 0; | |
4a64f543 | 4058 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 4059 | ++(b->hit_count); |
8d3788bd | 4060 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
4061 | } |
4062 | } | |
4063 | } | |
4064 | ||
4065 | ||
9709f61c | 4066 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4067 | BP_ADDR in thread PTID. |
c906108c | 4068 | |
d983da9c | 4069 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4070 | don't understand this stop. Result is a chain of bpstat's such |
4071 | that: | |
c906108c | 4072 | |
c5aa993b | 4073 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4074 | |
c5aa993b | 4075 | if we understand why we stopped, the result is not null. |
c906108c | 4076 | |
c5aa993b JM |
4077 | Each element of the chain refers to a particular breakpoint or |
4078 | watchpoint at which we have stopped. (We may have stopped for | |
4079 | several reasons concurrently.) | |
c906108c | 4080 | |
c5aa993b JM |
4081 | Each element of the chain has valid next, breakpoint_at, |
4082 | commands, FIXME??? fields. */ | |
c906108c SS |
4083 | |
4084 | bpstat | |
6c95b8df PA |
4085 | bpstat_stop_status (struct address_space *aspace, |
4086 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4087 | { |
0d381245 | 4088 | struct breakpoint *b = NULL; |
afe38095 | 4089 | struct bp_location *bl; |
20874c92 | 4090 | struct bp_location *loc; |
5760d0ab JK |
4091 | /* First item of allocated bpstat's. */ |
4092 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4093 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4094 | bpstat bs; |
20874c92 | 4095 | int ix; |
429374b8 | 4096 | int need_remove_insert; |
f431efe5 | 4097 | int removed_any; |
c906108c | 4098 | |
f431efe5 PA |
4099 | /* First, build the bpstat chain with locations that explain a |
4100 | target stop, while being careful to not set the target running, | |
4101 | as that may invalidate locations (in particular watchpoint | |
4102 | locations are recreated). Resuming will happen here with | |
4103 | breakpoint conditions or watchpoint expressions that include | |
4104 | inferior function calls. */ | |
c5aa993b | 4105 | |
429374b8 JK |
4106 | ALL_BREAKPOINTS (b) |
4107 | { | |
4108 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4109 | continue; | |
a5606eee | 4110 | |
429374b8 JK |
4111 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4112 | { | |
4a64f543 MS |
4113 | /* For hardware watchpoints, we look only at the first |
4114 | location. The watchpoint_check function will work on the | |
4115 | entire expression, not the individual locations. For | |
4116 | read watchpoints, the watchpoints_triggered function has | |
4117 | checked all locations already. */ | |
429374b8 JK |
4118 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4119 | break; | |
18a18393 | 4120 | |
429374b8 JK |
4121 | if (bl->shlib_disabled) |
4122 | continue; | |
c5aa993b | 4123 | |
429374b8 JK |
4124 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4125 | continue; | |
c5aa993b | 4126 | |
4a64f543 MS |
4127 | /* Come here if it's a watchpoint, or if the break address |
4128 | matches. */ | |
c5aa993b | 4129 | |
4a64f543 MS |
4130 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4131 | explain stop. */ | |
c5aa993b | 4132 | |
f431efe5 PA |
4133 | /* Assume we stop. Should we find a watchpoint that is not |
4134 | actually triggered, or if the condition of the breakpoint | |
4135 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4136 | bs->stop = 1; |
4137 | bs->print = 1; | |
d983da9c | 4138 | |
f431efe5 PA |
4139 | /* If this is a scope breakpoint, mark the associated |
4140 | watchpoint as triggered so that we will handle the | |
4141 | out-of-scope event. We'll get to the watchpoint next | |
4142 | iteration. */ | |
d0fb5eae | 4143 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
4144 | { |
4145 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
4146 | ||
4147 | w->watchpoint_triggered = watch_triggered_yes; | |
4148 | } | |
f431efe5 PA |
4149 | } |
4150 | } | |
4151 | ||
4152 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4153 | { | |
f1310107 | 4154 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 4155 | { |
5760d0ab | 4156 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4157 | /* For hits of moribund locations, we should just proceed. */ |
4158 | bs->stop = 0; | |
4159 | bs->print = 0; | |
4160 | bs->print_it = print_it_noop; | |
4161 | } | |
4162 | } | |
4163 | ||
f431efe5 PA |
4164 | /* Now go through the locations that caused the target to stop, and |
4165 | check whether we're interested in reporting this stop to higher | |
4166 | layers, or whether we should resume the target transparently. */ | |
4167 | ||
4168 | removed_any = 0; | |
4169 | ||
5760d0ab | 4170 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4171 | { |
4172 | if (!bs->stop) | |
4173 | continue; | |
4174 | ||
f431efe5 | 4175 | b = bs->breakpoint_at; |
348d480f PA |
4176 | b->ops->check_status (bs); |
4177 | if (bs->stop) | |
28010a5d | 4178 | { |
348d480f | 4179 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 4180 | |
429374b8 JK |
4181 | if (bs->stop) |
4182 | { | |
4183 | ++(b->hit_count); | |
8d3788bd | 4184 | observer_notify_breakpoint_modified (b); |
c906108c | 4185 | |
4a64f543 | 4186 | /* We will stop here. */ |
429374b8 JK |
4187 | if (b->disposition == disp_disable) |
4188 | { | |
4189 | if (b->enable_state != bp_permanent) | |
4190 | b->enable_state = bp_disabled; | |
f431efe5 | 4191 | removed_any = 1; |
429374b8 JK |
4192 | } |
4193 | if (b->silent) | |
4194 | bs->print = 0; | |
4195 | bs->commands = b->commands; | |
9add0f1b | 4196 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
4197 | if (command_line_is_silent (bs->commands |
4198 | ? bs->commands->commands : NULL)) | |
4199 | bs->print = 0; | |
429374b8 JK |
4200 | } |
4201 | ||
e5dd4106 | 4202 | /* Print nothing for this entry if we don't stop or don't print. */ |
429374b8 JK |
4203 | if (bs->stop == 0 || bs->print == 0) |
4204 | bs->print_it = print_it_noop; | |
348d480f | 4205 | } |
429374b8 | 4206 | } |
876fa593 | 4207 | |
d983da9c DJ |
4208 | /* If we aren't stopping, the value of some hardware watchpoint may |
4209 | not have changed, but the intermediate memory locations we are | |
4210 | watching may have. Don't bother if we're stopping; this will get | |
4211 | done later. */ | |
d832cb68 | 4212 | need_remove_insert = 0; |
5760d0ab JK |
4213 | if (! bpstat_causes_stop (bs_head)) |
4214 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4215 | if (!bs->stop |
f431efe5 PA |
4216 | && bs->breakpoint_at |
4217 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4218 | { |
3a5c3e22 PA |
4219 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
4220 | ||
4221 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 4222 | need_remove_insert = 1; |
d983da9c DJ |
4223 | } |
4224 | ||
d832cb68 | 4225 | if (need_remove_insert) |
2d134ed3 | 4226 | update_global_location_list (1); |
f431efe5 PA |
4227 | else if (removed_any) |
4228 | update_global_location_list (0); | |
d832cb68 | 4229 | |
5760d0ab | 4230 | return bs_head; |
c906108c | 4231 | } |
628fe4e4 JK |
4232 | |
4233 | static void | |
4234 | handle_jit_event (void) | |
4235 | { | |
4236 | struct frame_info *frame; | |
4237 | struct gdbarch *gdbarch; | |
4238 | ||
4239 | /* Switch terminal for any messages produced by | |
4240 | breakpoint_re_set. */ | |
4241 | target_terminal_ours_for_output (); | |
4242 | ||
4243 | frame = get_current_frame (); | |
4244 | gdbarch = get_frame_arch (frame); | |
4245 | ||
4246 | jit_event_handler (gdbarch); | |
4247 | ||
4248 | target_terminal_inferior (); | |
4249 | } | |
4250 | ||
4251 | /* Prepare WHAT final decision for infrun. */ | |
4252 | ||
4253 | /* Decide what infrun needs to do with this bpstat. */ | |
4254 | ||
c906108c | 4255 | struct bpstat_what |
0e30163f | 4256 | bpstat_what (bpstat bs_head) |
c906108c | 4257 | { |
c906108c | 4258 | struct bpstat_what retval; |
628fe4e4 JK |
4259 | /* We need to defer calling `solib_add', as adding new symbols |
4260 | resets breakpoints, which in turn deletes breakpoint locations, | |
4261 | and hence may clear unprocessed entries in the BS chain. */ | |
4262 | int shlib_event = 0; | |
4263 | int jit_event = 0; | |
0e30163f | 4264 | bpstat bs; |
c906108c | 4265 | |
628fe4e4 | 4266 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4267 | retval.call_dummy = STOP_NONE; |
186c406b | 4268 | retval.is_longjmp = 0; |
628fe4e4 | 4269 | |
0e30163f | 4270 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 4271 | { |
628fe4e4 JK |
4272 | /* Extract this BS's action. After processing each BS, we check |
4273 | if its action overrides all we've seem so far. */ | |
4274 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4275 | enum bptype bptype; | |
4276 | ||
c906108c | 4277 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4278 | { |
4279 | /* I suspect this can happen if it was a momentary | |
4280 | breakpoint which has since been deleted. */ | |
4281 | bptype = bp_none; | |
4282 | } | |
20874c92 | 4283 | else |
f431efe5 | 4284 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4285 | |
4286 | switch (bptype) | |
c906108c SS |
4287 | { |
4288 | case bp_none: | |
628fe4e4 | 4289 | break; |
c906108c SS |
4290 | case bp_breakpoint: |
4291 | case bp_hardware_breakpoint: | |
4292 | case bp_until: | |
4293 | case bp_finish: | |
4294 | if (bs->stop) | |
4295 | { | |
4296 | if (bs->print) | |
628fe4e4 | 4297 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4298 | else |
628fe4e4 | 4299 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4300 | } |
4301 | else | |
628fe4e4 | 4302 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4303 | break; |
4304 | case bp_watchpoint: | |
4305 | case bp_hardware_watchpoint: | |
4306 | case bp_read_watchpoint: | |
4307 | case bp_access_watchpoint: | |
4308 | if (bs->stop) | |
4309 | { | |
4310 | if (bs->print) | |
628fe4e4 | 4311 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4312 | else |
628fe4e4 | 4313 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4314 | } |
4315 | else | |
628fe4e4 JK |
4316 | { |
4317 | /* There was a watchpoint, but we're not stopping. | |
4318 | This requires no further action. */ | |
4319 | } | |
c906108c SS |
4320 | break; |
4321 | case bp_longjmp: | |
186c406b | 4322 | case bp_exception: |
628fe4e4 | 4323 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4324 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4325 | break; |
4326 | case bp_longjmp_resume: | |
186c406b | 4327 | case bp_exception_resume: |
628fe4e4 | 4328 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4329 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4330 | break; |
4331 | case bp_step_resume: | |
4332 | if (bs->stop) | |
628fe4e4 JK |
4333 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4334 | else | |
c906108c | 4335 | { |
628fe4e4 JK |
4336 | /* It is for the wrong frame. */ |
4337 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4338 | } |
c906108c | 4339 | break; |
2c03e5be PA |
4340 | case bp_hp_step_resume: |
4341 | if (bs->stop) | |
4342 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
4343 | else | |
4344 | { | |
4345 | /* It is for the wrong frame. */ | |
4346 | this_action = BPSTAT_WHAT_SINGLE; | |
4347 | } | |
4348 | break; | |
c906108c | 4349 | case bp_watchpoint_scope: |
c4093a6a | 4350 | case bp_thread_event: |
1900040c | 4351 | case bp_overlay_event: |
0fd8e87f | 4352 | case bp_longjmp_master: |
aa7d318d | 4353 | case bp_std_terminate_master: |
186c406b | 4354 | case bp_exception_master: |
628fe4e4 | 4355 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4356 | break; |
ce78b96d | 4357 | case bp_catchpoint: |
c5aa993b JM |
4358 | if (bs->stop) |
4359 | { | |
4360 | if (bs->print) | |
628fe4e4 | 4361 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4362 | else |
628fe4e4 | 4363 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4364 | } |
4365 | else | |
628fe4e4 JK |
4366 | { |
4367 | /* There was a catchpoint, but we're not stopping. | |
4368 | This requires no further action. */ | |
4369 | } | |
4370 | break; | |
4371 | case bp_shlib_event: | |
4372 | shlib_event = 1; | |
4373 | ||
4374 | /* If requested, stop when the dynamic linker notifies GDB | |
4375 | of events. This allows the user to get control and place | |
4376 | breakpoints in initializer routines for dynamically | |
4377 | loaded objects (among other things). */ | |
4378 | if (stop_on_solib_events) | |
4379 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4380 | else | |
4381 | this_action = BPSTAT_WHAT_SINGLE; | |
4382 | break; | |
4383 | case bp_jit_event: | |
4384 | jit_event = 1; | |
4385 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4386 | break; |
c906108c | 4387 | case bp_call_dummy: |
53a5351d JM |
4388 | /* Make sure the action is stop (silent or noisy), |
4389 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4390 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4391 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4392 | break; |
4393 | case bp_std_terminate: | |
4394 | /* Make sure the action is stop (silent or noisy), | |
4395 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4396 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4397 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4398 | break; |
1042e4c0 | 4399 | case bp_tracepoint: |
7a697b8d | 4400 | case bp_fast_tracepoint: |
0fb4aa4b | 4401 | case bp_static_tracepoint: |
1042e4c0 SS |
4402 | /* Tracepoint hits should not be reported back to GDB, and |
4403 | if one got through somehow, it should have been filtered | |
4404 | out already. */ | |
4405 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4406 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
4407 | break; |
4408 | case bp_gnu_ifunc_resolver: | |
4409 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
4410 | this_action = BPSTAT_WHAT_SINGLE; | |
4411 | break; | |
4412 | case bp_gnu_ifunc_resolver_return: | |
4413 | /* The breakpoint will be removed, execution will restart from the | |
4414 | PC of the former breakpoint. */ | |
4415 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4416 | break; | |
628fe4e4 JK |
4417 | default: |
4418 | internal_error (__FILE__, __LINE__, | |
4419 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4420 | } |
628fe4e4 JK |
4421 | |
4422 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4423 | } |
628fe4e4 | 4424 | |
0e30163f JK |
4425 | /* These operations may affect the bs->breakpoint_at state so they are |
4426 | delayed after MAIN_ACTION is decided above. */ | |
4427 | ||
628fe4e4 JK |
4428 | if (shlib_event) |
4429 | { | |
4430 | if (debug_infrun) | |
4431 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4432 | ||
4433 | /* Check for any newly added shared libraries if we're supposed | |
4434 | to be adding them automatically. */ | |
4435 | ||
4436 | /* Switch terminal for any messages produced by | |
4437 | breakpoint_re_set. */ | |
4438 | target_terminal_ours_for_output (); | |
4439 | ||
4440 | #ifdef SOLIB_ADD | |
4441 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4442 | #else | |
4443 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4444 | #endif | |
4445 | ||
4446 | target_terminal_inferior (); | |
4447 | } | |
4448 | ||
4449 | if (jit_event) | |
4450 | { | |
4451 | if (debug_infrun) | |
4452 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4453 | ||
4454 | handle_jit_event (); | |
4455 | } | |
4456 | ||
0e30163f JK |
4457 | for (bs = bs_head; bs != NULL; bs = bs->next) |
4458 | { | |
4459 | struct breakpoint *b = bs->breakpoint_at; | |
4460 | ||
4461 | if (b == NULL) | |
4462 | continue; | |
4463 | switch (b->type) | |
4464 | { | |
4465 | case bp_gnu_ifunc_resolver: | |
4466 | gnu_ifunc_resolver_stop (b); | |
4467 | break; | |
4468 | case bp_gnu_ifunc_resolver_return: | |
4469 | gnu_ifunc_resolver_return_stop (b); | |
4470 | break; | |
4471 | } | |
4472 | } | |
4473 | ||
c906108c SS |
4474 | return retval; |
4475 | } | |
4476 | ||
4477 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4478 | without hardware support). This isn't related to a specific bpstat, | |
4479 | just to things like whether watchpoints are set. */ | |
4480 | ||
c5aa993b | 4481 | int |
fba45db2 | 4482 | bpstat_should_step (void) |
c906108c SS |
4483 | { |
4484 | struct breakpoint *b; | |
cc59ec59 | 4485 | |
c906108c | 4486 | ALL_BREAKPOINTS (b) |
717a8278 | 4487 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4488 | return 1; |
c906108c SS |
4489 | return 0; |
4490 | } | |
4491 | ||
67822962 PA |
4492 | int |
4493 | bpstat_causes_stop (bpstat bs) | |
4494 | { | |
4495 | for (; bs != NULL; bs = bs->next) | |
4496 | if (bs->stop) | |
4497 | return 1; | |
4498 | ||
4499 | return 0; | |
4500 | } | |
4501 | ||
c906108c | 4502 | \f |
c5aa993b | 4503 | |
170b53b2 UW |
4504 | /* Compute a string of spaces suitable to indent the next line |
4505 | so it starts at the position corresponding to the table column | |
4506 | named COL_NAME in the currently active table of UIOUT. */ | |
4507 | ||
4508 | static char * | |
4509 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
4510 | { | |
4511 | static char wrap_indent[80]; | |
4512 | int i, total_width, width, align; | |
4513 | char *text; | |
4514 | ||
4515 | total_width = 0; | |
4516 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
4517 | { | |
4518 | if (strcmp (text, col_name) == 0) | |
4519 | { | |
4520 | gdb_assert (total_width < sizeof wrap_indent); | |
4521 | memset (wrap_indent, ' ', total_width); | |
4522 | wrap_indent[total_width] = 0; | |
4523 | ||
4524 | return wrap_indent; | |
4525 | } | |
4526 | ||
4527 | total_width += width + 1; | |
4528 | } | |
4529 | ||
4530 | return NULL; | |
4531 | } | |
4532 | ||
859825b8 JK |
4533 | /* Print the LOC location out of the list of B->LOC locations. */ |
4534 | ||
170b53b2 UW |
4535 | static void |
4536 | print_breakpoint_location (struct breakpoint *b, | |
4537 | struct bp_location *loc) | |
0d381245 | 4538 | { |
79a45e25 | 4539 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
4540 | struct cleanup *old_chain = save_current_program_space (); |
4541 | ||
859825b8 JK |
4542 | if (loc != NULL && loc->shlib_disabled) |
4543 | loc = NULL; | |
4544 | ||
6c95b8df PA |
4545 | if (loc != NULL) |
4546 | set_current_program_space (loc->pspace); | |
4547 | ||
56435ebe TT |
4548 | if (b->display_canonical) |
4549 | ui_out_field_string (uiout, "what", b->addr_string); | |
4550 | else if (b->source_file && loc) | |
0d381245 VP |
4551 | { |
4552 | struct symbol *sym | |
4553 | = find_pc_sect_function (loc->address, loc->section); | |
4554 | if (sym) | |
4555 | { | |
4556 | ui_out_text (uiout, "in "); | |
4557 | ui_out_field_string (uiout, "func", | |
4558 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
4559 | ui_out_text (uiout, " "); |
4560 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
4561 | ui_out_text (uiout, "at "); | |
0d381245 VP |
4562 | } |
4563 | ui_out_field_string (uiout, "file", b->source_file); | |
4564 | ui_out_text (uiout, ":"); | |
4565 | ||
4566 | if (ui_out_is_mi_like_p (uiout)) | |
4567 | { | |
4568 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4569 | char *fullname = symtab_to_fullname (sal.symtab); | |
4570 | ||
4571 | if (fullname) | |
4572 | ui_out_field_string (uiout, "fullname", fullname); | |
4573 | } | |
4574 | ||
4575 | ui_out_field_int (uiout, "line", b->line_number); | |
4576 | } | |
859825b8 | 4577 | else if (loc) |
0d381245 | 4578 | { |
170b53b2 UW |
4579 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4580 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
4581 | ||
22e722e1 DJ |
4582 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4583 | demangle, ""); | |
0d381245 | 4584 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
4585 | |
4586 | do_cleanups (stb_chain); | |
0d381245 | 4587 | } |
859825b8 JK |
4588 | else |
4589 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4590 | |
4591 | do_cleanups (old_chain); | |
0d381245 VP |
4592 | } |
4593 | ||
269b11a2 PA |
4594 | static const char * |
4595 | bptype_string (enum bptype type) | |
c906108c | 4596 | { |
c4093a6a JM |
4597 | struct ep_type_description |
4598 | { | |
4599 | enum bptype type; | |
4600 | char *description; | |
4601 | }; | |
4602 | static struct ep_type_description bptypes[] = | |
c906108c | 4603 | { |
c5aa993b JM |
4604 | {bp_none, "?deleted?"}, |
4605 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4606 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4607 | {bp_until, "until"}, |
4608 | {bp_finish, "finish"}, | |
4609 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4610 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4611 | {bp_read_watchpoint, "read watchpoint"}, |
4612 | {bp_access_watchpoint, "acc watchpoint"}, | |
4613 | {bp_longjmp, "longjmp"}, | |
4614 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4615 | {bp_exception, "exception"}, |
4616 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4617 | {bp_step_resume, "step resume"}, |
2c03e5be | 4618 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
4619 | {bp_watchpoint_scope, "watchpoint scope"}, |
4620 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4621 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4622 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4623 | {bp_thread_event, "thread events"}, |
1900040c | 4624 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4625 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4626 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4627 | {bp_exception_master, "exception master"}, |
ce78b96d | 4628 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4629 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4630 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4631 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4632 | {bp_jit_event, "jit events"}, |
0e30163f JK |
4633 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
4634 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 4635 | }; |
269b11a2 PA |
4636 | |
4637 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4638 | || ((int) type != bptypes[(int) type].type)) | |
4639 | internal_error (__FILE__, __LINE__, | |
4640 | _("bptypes table does not describe type #%d."), | |
4641 | (int) type); | |
4642 | ||
4643 | return bptypes[(int) type].description; | |
4644 | } | |
4645 | ||
4646 | /* Print B to gdb_stdout. */ | |
4647 | ||
4648 | static void | |
4649 | print_one_breakpoint_location (struct breakpoint *b, | |
4650 | struct bp_location *loc, | |
4651 | int loc_number, | |
4652 | struct bp_location **last_loc, | |
269b11a2 PA |
4653 | int allflag) |
4654 | { | |
4655 | struct command_line *l; | |
c2c6d25f | 4656 | static char bpenables[] = "nynny"; |
c906108c | 4657 | |
79a45e25 | 4658 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
4659 | int header_of_multiple = 0; |
4660 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4661 | struct value_print_options opts; |
4662 | ||
4663 | get_user_print_options (&opts); | |
0d381245 VP |
4664 | |
4665 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4666 | /* See comment in print_one_breakpoint concerning treatment of |
4667 | breakpoints with single disabled location. */ | |
0d381245 VP |
4668 | if (loc == NULL |
4669 | && (b->loc != NULL | |
4670 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4671 | header_of_multiple = 1; | |
4672 | if (loc == NULL) | |
4673 | loc = b->loc; | |
4674 | ||
c4093a6a JM |
4675 | annotate_record (); |
4676 | ||
4677 | /* 1 */ | |
4678 | annotate_field (0); | |
0d381245 VP |
4679 | if (part_of_multiple) |
4680 | { | |
4681 | char *formatted; | |
0c6773c1 | 4682 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4683 | ui_out_field_string (uiout, "number", formatted); |
4684 | xfree (formatted); | |
4685 | } | |
4686 | else | |
4687 | { | |
4688 | ui_out_field_int (uiout, "number", b->number); | |
4689 | } | |
c4093a6a JM |
4690 | |
4691 | /* 2 */ | |
4692 | annotate_field (1); | |
0d381245 VP |
4693 | if (part_of_multiple) |
4694 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4695 | else |
4696 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4697 | |
4698 | /* 3 */ | |
4699 | annotate_field (2); | |
0d381245 VP |
4700 | if (part_of_multiple) |
4701 | ui_out_field_skip (uiout, "disp"); | |
4702 | else | |
2cec12e5 | 4703 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4704 | |
c4093a6a JM |
4705 | |
4706 | /* 4 */ | |
4707 | annotate_field (3); | |
0d381245 | 4708 | if (part_of_multiple) |
54e52265 | 4709 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4710 | else |
4a64f543 MS |
4711 | ui_out_field_fmt (uiout, "enabled", "%c", |
4712 | bpenables[(int) b->enable_state]); | |
54e52265 | 4713 | ui_out_spaces (uiout, 2); |
0d381245 | 4714 | |
c4093a6a JM |
4715 | |
4716 | /* 5 and 6 */ | |
3086aeae | 4717 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4718 | { |
4a64f543 MS |
4719 | /* Although the print_one can possibly print all locations, |
4720 | calling it here is not likely to get any nice result. So, | |
4721 | make sure there's just one location. */ | |
0d381245 | 4722 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4723 | b->ops->print_one (b, last_loc); |
0d381245 | 4724 | } |
3086aeae DJ |
4725 | else |
4726 | switch (b->type) | |
4727 | { | |
4728 | case bp_none: | |
4729 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4730 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4731 | break; |
c906108c | 4732 | |
3086aeae DJ |
4733 | case bp_watchpoint: |
4734 | case bp_hardware_watchpoint: | |
4735 | case bp_read_watchpoint: | |
4736 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4737 | { |
4738 | struct watchpoint *w = (struct watchpoint *) b; | |
4739 | ||
4740 | /* Field 4, the address, is omitted (which makes the columns | |
4741 | not line up too nicely with the headers, but the effect | |
4742 | is relatively readable). */ | |
4743 | if (opts.addressprint) | |
4744 | ui_out_field_skip (uiout, "addr"); | |
4745 | annotate_field (5); | |
4746 | ui_out_field_string (uiout, "what", w->exp_string); | |
4747 | } | |
3086aeae DJ |
4748 | break; |
4749 | ||
3086aeae DJ |
4750 | case bp_breakpoint: |
4751 | case bp_hardware_breakpoint: | |
4752 | case bp_until: | |
4753 | case bp_finish: | |
4754 | case bp_longjmp: | |
4755 | case bp_longjmp_resume: | |
186c406b TT |
4756 | case bp_exception: |
4757 | case bp_exception_resume: | |
3086aeae | 4758 | case bp_step_resume: |
2c03e5be | 4759 | case bp_hp_step_resume: |
3086aeae DJ |
4760 | case bp_watchpoint_scope: |
4761 | case bp_call_dummy: | |
aa7d318d | 4762 | case bp_std_terminate: |
3086aeae DJ |
4763 | case bp_shlib_event: |
4764 | case bp_thread_event: | |
4765 | case bp_overlay_event: | |
0fd8e87f | 4766 | case bp_longjmp_master: |
aa7d318d | 4767 | case bp_std_terminate_master: |
186c406b | 4768 | case bp_exception_master: |
1042e4c0 | 4769 | case bp_tracepoint: |
7a697b8d | 4770 | case bp_fast_tracepoint: |
0fb4aa4b | 4771 | case bp_static_tracepoint: |
4efc6507 | 4772 | case bp_jit_event: |
0e30163f JK |
4773 | case bp_gnu_ifunc_resolver: |
4774 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 4775 | if (opts.addressprint) |
3086aeae DJ |
4776 | { |
4777 | annotate_field (4); | |
54e52265 | 4778 | if (header_of_multiple) |
0d381245 | 4779 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4780 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4781 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4782 | else |
5af949e3 UW |
4783 | ui_out_field_core_addr (uiout, "addr", |
4784 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4785 | } |
4786 | annotate_field (5); | |
0d381245 | 4787 | if (!header_of_multiple) |
170b53b2 | 4788 | print_breakpoint_location (b, loc); |
0d381245 | 4789 | if (b->loc) |
a6d9a66e | 4790 | *last_loc = b->loc; |
3086aeae DJ |
4791 | break; |
4792 | } | |
c906108c | 4793 | |
6c95b8df PA |
4794 | |
4795 | /* For backward compatibility, don't display inferiors unless there | |
4796 | are several. */ | |
4797 | if (loc != NULL | |
4798 | && !header_of_multiple | |
4799 | && (allflag | |
4800 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4801 | && (number_of_program_spaces () > 1 | |
4802 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4803 | /* LOC is for existing B, it cannot be in |
4804 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4805 | && loc->owner->type != bp_catchpoint))) |
4806 | { | |
4807 | struct inferior *inf; | |
4808 | int first = 1; | |
4809 | ||
4810 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4811 | { | |
4812 | if (inf->pspace == loc->pspace) | |
4813 | { | |
4814 | if (first) | |
4815 | { | |
4816 | first = 0; | |
4817 | ui_out_text (uiout, " inf "); | |
4818 | } | |
4819 | else | |
4820 | ui_out_text (uiout, ", "); | |
4821 | ui_out_text (uiout, plongest (inf->num)); | |
4822 | } | |
4823 | } | |
4824 | } | |
4825 | ||
4a306c9a | 4826 | if (!part_of_multiple) |
c4093a6a | 4827 | { |
4a306c9a JB |
4828 | if (b->thread != -1) |
4829 | { | |
4830 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4831 | "stop only in" line a little further down. */ |
4a306c9a JB |
4832 | ui_out_text (uiout, " thread "); |
4833 | ui_out_field_int (uiout, "thread", b->thread); | |
4834 | } | |
4835 | else if (b->task != 0) | |
4836 | { | |
4837 | ui_out_text (uiout, " task "); | |
4838 | ui_out_field_int (uiout, "task", b->task); | |
4839 | } | |
c4093a6a | 4840 | } |
f1310107 | 4841 | |
8b93c638 | 4842 | ui_out_text (uiout, "\n"); |
f1310107 | 4843 | |
348d480f | 4844 | if (!part_of_multiple) |
f1310107 TJB |
4845 | b->ops->print_one_detail (b, uiout); |
4846 | ||
0d381245 | 4847 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4848 | { |
4849 | annotate_field (6); | |
8b93c638 | 4850 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 4851 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 4852 | the frame ID. */ |
5af949e3 UW |
4853 | ui_out_field_core_addr (uiout, "frame", |
4854 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4855 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4856 | } |
4857 | ||
28010a5d | 4858 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
4859 | { |
4860 | annotate_field (7); | |
d77f58be | 4861 | if (is_tracepoint (b)) |
1042e4c0 SS |
4862 | ui_out_text (uiout, "\ttrace only if "); |
4863 | else | |
4864 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4865 | ui_out_field_string (uiout, "cond", b->cond_string); |
4866 | ui_out_text (uiout, "\n"); | |
4867 | } | |
4868 | ||
0d381245 | 4869 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 4870 | { |
4a64f543 | 4871 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4872 | ui_out_text (uiout, "\tstop only in thread "); |
4873 | ui_out_field_int (uiout, "thread", b->thread); | |
4874 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4875 | } |
4876 | ||
63c715c6 | 4877 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 4878 | { |
4a64f543 | 4879 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4880 | if (ep_is_catchpoint (b)) |
4881 | ui_out_text (uiout, "\tcatchpoint"); | |
4882 | else | |
4883 | ui_out_text (uiout, "\tbreakpoint"); | |
4884 | ui_out_text (uiout, " already hit "); | |
4885 | ui_out_field_int (uiout, "times", b->hit_count); | |
4886 | if (b->hit_count == 1) | |
4887 | ui_out_text (uiout, " time\n"); | |
4888 | else | |
4889 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4890 | } |
4891 | ||
4a64f543 MS |
4892 | /* Output the count also if it is zero, but only if this is mi. |
4893 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4894 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4895 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4896 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4897 | |
0d381245 | 4898 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4899 | { |
4900 | annotate_field (8); | |
8b93c638 JM |
4901 | ui_out_text (uiout, "\tignore next "); |
4902 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4903 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4904 | } |
059fb39f | 4905 | |
9add0f1b | 4906 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4907 | if (!part_of_multiple && l) |
c4093a6a | 4908 | { |
3b31d625 EZ |
4909 | struct cleanup *script_chain; |
4910 | ||
c4093a6a | 4911 | annotate_field (9); |
3b31d625 | 4912 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4913 | print_command_lines (uiout, l, 4); |
3b31d625 | 4914 | do_cleanups (script_chain); |
c4093a6a | 4915 | } |
d24317b4 | 4916 | |
d9b3f62e | 4917 | if (is_tracepoint (b)) |
1042e4c0 | 4918 | { |
d9b3f62e PA |
4919 | struct tracepoint *t = (struct tracepoint *) b; |
4920 | ||
4921 | if (!part_of_multiple && t->pass_count) | |
4922 | { | |
4923 | annotate_field (10); | |
4924 | ui_out_text (uiout, "\tpass count "); | |
4925 | ui_out_field_int (uiout, "pass", t->pass_count); | |
4926 | ui_out_text (uiout, " \n"); | |
4927 | } | |
1042e4c0 SS |
4928 | } |
4929 | ||
d24317b4 VP |
4930 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4931 | { | |
3a5c3e22 PA |
4932 | if (is_watchpoint (b)) |
4933 | { | |
4934 | struct watchpoint *w = (struct watchpoint *) b; | |
4935 | ||
4936 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
4937 | } | |
4938 | else if (b->addr_string) | |
d24317b4 | 4939 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 4940 | } |
c4093a6a | 4941 | } |
c5aa993b | 4942 | |
0d381245 VP |
4943 | static void |
4944 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 4945 | struct bp_location **last_loc, |
6c95b8df | 4946 | int allflag) |
0d381245 | 4947 | { |
8d3788bd | 4948 | struct cleanup *bkpt_chain; |
79a45e25 | 4949 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
4950 | |
4951 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
4952 | ||
12c5a436 | 4953 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 4954 | do_cleanups (bkpt_chain); |
0d381245 VP |
4955 | |
4956 | /* If this breakpoint has custom print function, | |
4957 | it's already printed. Otherwise, print individual | |
4958 | locations, if any. */ | |
4959 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4960 | { | |
4a64f543 MS |
4961 | /* If breakpoint has a single location that is disabled, we |
4962 | print it as if it had several locations, since otherwise it's | |
4963 | hard to represent "breakpoint enabled, location disabled" | |
4964 | situation. | |
4965 | ||
4966 | Note that while hardware watchpoints have several locations | |
a3be7890 | 4967 | internally, that's not a property exposed to user. */ |
0d381245 | 4968 | if (b->loc |
a5606eee | 4969 | && !is_hardware_watchpoint (b) |
8d3788bd | 4970 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
4971 | { |
4972 | struct bp_location *loc; | |
4973 | int n = 1; | |
8d3788bd | 4974 | |
0d381245 | 4975 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
4976 | { |
4977 | struct cleanup *inner2 = | |
4978 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
4979 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
4980 | do_cleanups (inner2); | |
4981 | } | |
0d381245 VP |
4982 | } |
4983 | } | |
4984 | } | |
4985 | ||
a6d9a66e UW |
4986 | static int |
4987 | breakpoint_address_bits (struct breakpoint *b) | |
4988 | { | |
4989 | int print_address_bits = 0; | |
4990 | struct bp_location *loc; | |
4991 | ||
4992 | for (loc = b->loc; loc; loc = loc->next) | |
4993 | { | |
c7437ca6 PA |
4994 | int addr_bit; |
4995 | ||
4996 | /* Software watchpoints that aren't watching memory don't have | |
4997 | an address to print. */ | |
4998 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
4999 | continue; | |
5000 | ||
5001 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5002 | if (addr_bit > print_address_bits) |
5003 | print_address_bits = addr_bit; | |
5004 | } | |
5005 | ||
5006 | return print_address_bits; | |
5007 | } | |
0d381245 | 5008 | |
c4093a6a JM |
5009 | struct captured_breakpoint_query_args |
5010 | { | |
5011 | int bnum; | |
5012 | }; | |
c5aa993b | 5013 | |
c4093a6a | 5014 | static int |
2b65245e | 5015 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5016 | { |
5017 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5018 | struct breakpoint *b; |
a6d9a66e | 5019 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5020 | |
c4093a6a JM |
5021 | ALL_BREAKPOINTS (b) |
5022 | { | |
5023 | if (args->bnum == b->number) | |
c5aa993b | 5024 | { |
12c5a436 | 5025 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5026 | return GDB_RC_OK; |
c5aa993b | 5027 | } |
c4093a6a JM |
5028 | } |
5029 | return GDB_RC_NONE; | |
5030 | } | |
c5aa993b | 5031 | |
c4093a6a | 5032 | enum gdb_rc |
4a64f543 MS |
5033 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5034 | char **error_message) | |
c4093a6a JM |
5035 | { |
5036 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5037 | |
c4093a6a JM |
5038 | args.bnum = bnum; |
5039 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5040 | an error. */ |
b0b13bb4 DJ |
5041 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5042 | error_message, RETURN_MASK_ALL) < 0) | |
5043 | return GDB_RC_FAIL; | |
5044 | else | |
5045 | return GDB_RC_OK; | |
c4093a6a | 5046 | } |
c5aa993b | 5047 | |
09d682a4 TT |
5048 | /* Return true if this breakpoint was set by the user, false if it is |
5049 | internal or momentary. */ | |
5050 | ||
5051 | int | |
5052 | user_breakpoint_p (struct breakpoint *b) | |
5053 | { | |
46c6471b | 5054 | return b->number > 0; |
09d682a4 TT |
5055 | } |
5056 | ||
7f3b0473 | 5057 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5058 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5059 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5060 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5061 | ones for which it returns non-zero. Return the total number of | |
5062 | breakpoints listed. */ | |
c906108c | 5063 | |
d77f58be | 5064 | static int |
e5a67952 | 5065 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5066 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5067 | { |
52f0bd74 | 5068 | struct breakpoint *b; |
a6d9a66e | 5069 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5070 | int nr_printable_breakpoints; |
3b31d625 | 5071 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5072 | struct value_print_options opts; |
a6d9a66e | 5073 | int print_address_bits = 0; |
269b11a2 | 5074 | int print_type_col_width = 14; |
79a45e25 | 5075 | struct ui_out *uiout = current_uiout; |
269b11a2 | 5076 | |
79a45b7d TT |
5077 | get_user_print_options (&opts); |
5078 | ||
4a64f543 MS |
5079 | /* Compute the number of rows in the table, as well as the size |
5080 | required for address fields. */ | |
7f3b0473 AC |
5081 | nr_printable_breakpoints = 0; |
5082 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5083 | { |
5084 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5085 | if (filter && !filter (b)) | |
5086 | continue; | |
5087 | ||
5088 | /* If we have an "args" string, it is a list of breakpoints to | |
5089 | accept. Skip the others. */ | |
5090 | if (args != NULL && *args != '\0') | |
5091 | { | |
5092 | if (allflag && parse_and_eval_long (args) != b->number) | |
5093 | continue; | |
5094 | if (!allflag && !number_is_in_list (args, b->number)) | |
5095 | continue; | |
5096 | } | |
269b11a2 | 5097 | |
e5a67952 MS |
5098 | if (allflag || user_breakpoint_p (b)) |
5099 | { | |
5100 | int addr_bit, type_len; | |
a6d9a66e | 5101 | |
e5a67952 MS |
5102 | addr_bit = breakpoint_address_bits (b); |
5103 | if (addr_bit > print_address_bits) | |
5104 | print_address_bits = addr_bit; | |
269b11a2 | 5105 | |
e5a67952 MS |
5106 | type_len = strlen (bptype_string (b->type)); |
5107 | if (type_len > print_type_col_width) | |
5108 | print_type_col_width = type_len; | |
5109 | ||
5110 | nr_printable_breakpoints++; | |
5111 | } | |
5112 | } | |
7f3b0473 | 5113 | |
79a45b7d | 5114 | if (opts.addressprint) |
3b31d625 | 5115 | bkpttbl_chain |
3e43a32a MS |
5116 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5117 | nr_printable_breakpoints, | |
3b31d625 | 5118 | "BreakpointTable"); |
8b93c638 | 5119 | else |
3b31d625 | 5120 | bkpttbl_chain |
3e43a32a MS |
5121 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5122 | nr_printable_breakpoints, | |
3b31d625 | 5123 | "BreakpointTable"); |
8b93c638 | 5124 | |
7f3b0473 | 5125 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5126 | annotate_breakpoints_headers (); |
5127 | if (nr_printable_breakpoints > 0) | |
5128 | annotate_field (0); | |
4a64f543 | 5129 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5130 | if (nr_printable_breakpoints > 0) |
5131 | annotate_field (1); | |
269b11a2 | 5132 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5133 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5134 | if (nr_printable_breakpoints > 0) |
5135 | annotate_field (2); | |
4a64f543 | 5136 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5137 | if (nr_printable_breakpoints > 0) |
5138 | annotate_field (3); | |
54e52265 | 5139 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5140 | if (opts.addressprint) |
e5a67952 MS |
5141 | { |
5142 | if (nr_printable_breakpoints > 0) | |
5143 | annotate_field (4); | |
5144 | if (print_address_bits <= 32) | |
5145 | ui_out_table_header (uiout, 10, ui_left, | |
5146 | "addr", "Address"); /* 5 */ | |
5147 | else | |
5148 | ui_out_table_header (uiout, 18, ui_left, | |
5149 | "addr", "Address"); /* 5 */ | |
5150 | } | |
d7faa9e7 AC |
5151 | if (nr_printable_breakpoints > 0) |
5152 | annotate_field (5); | |
5153 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5154 | ui_out_table_body (uiout); | |
5155 | if (nr_printable_breakpoints > 0) | |
5156 | annotate_breakpoints_table (); | |
7f3b0473 | 5157 | |
c4093a6a | 5158 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5159 | { |
5160 | QUIT; | |
5161 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5162 | if (filter && !filter (b)) | |
5163 | continue; | |
5164 | ||
5165 | /* If we have an "args" string, it is a list of breakpoints to | |
5166 | accept. Skip the others. */ | |
5167 | ||
5168 | if (args != NULL && *args != '\0') | |
5169 | { | |
5170 | if (allflag) /* maintenance info breakpoint */ | |
5171 | { | |
5172 | if (parse_and_eval_long (args) != b->number) | |
5173 | continue; | |
5174 | } | |
5175 | else /* all others */ | |
5176 | { | |
5177 | if (!number_is_in_list (args, b->number)) | |
5178 | continue; | |
5179 | } | |
5180 | } | |
5181 | /* We only print out user settable breakpoints unless the | |
5182 | allflag is set. */ | |
5183 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5184 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5185 | } |
5186 | ||
3b31d625 | 5187 | do_cleanups (bkpttbl_chain); |
698384cd | 5188 | |
7f3b0473 | 5189 | if (nr_printable_breakpoints == 0) |
c906108c | 5190 | { |
4a64f543 MS |
5191 | /* If there's a filter, let the caller decide how to report |
5192 | empty list. */ | |
d77f58be SS |
5193 | if (!filter) |
5194 | { | |
e5a67952 | 5195 | if (args == NULL || *args == '\0') |
d77f58be SS |
5196 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5197 | else | |
4a64f543 | 5198 | ui_out_message (uiout, 0, |
e5a67952 MS |
5199 | "No breakpoint or watchpoint matching '%s'.\n", |
5200 | args); | |
d77f58be | 5201 | } |
c906108c SS |
5202 | } |
5203 | else | |
c4093a6a | 5204 | { |
a6d9a66e UW |
5205 | if (last_loc && !server_command) |
5206 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5207 | } |
c906108c | 5208 | |
4a64f543 | 5209 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5210 | there have been breakpoints? */ |
c906108c | 5211 | annotate_breakpoints_table_end (); |
d77f58be SS |
5212 | |
5213 | return nr_printable_breakpoints; | |
c906108c SS |
5214 | } |
5215 | ||
ad443146 SS |
5216 | /* Display the value of default-collect in a way that is generally |
5217 | compatible with the breakpoint list. */ | |
5218 | ||
5219 | static void | |
5220 | default_collect_info (void) | |
5221 | { | |
79a45e25 PA |
5222 | struct ui_out *uiout = current_uiout; |
5223 | ||
ad443146 SS |
5224 | /* If it has no value (which is frequently the case), say nothing; a |
5225 | message like "No default-collect." gets in user's face when it's | |
5226 | not wanted. */ | |
5227 | if (!*default_collect) | |
5228 | return; | |
5229 | ||
5230 | /* The following phrase lines up nicely with per-tracepoint collect | |
5231 | actions. */ | |
5232 | ui_out_text (uiout, "default collect "); | |
5233 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5234 | ui_out_text (uiout, " \n"); | |
5235 | } | |
5236 | ||
c906108c | 5237 | static void |
e5a67952 | 5238 | breakpoints_info (char *args, int from_tty) |
c906108c | 5239 | { |
e5a67952 | 5240 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5241 | |
5242 | default_collect_info (); | |
d77f58be SS |
5243 | } |
5244 | ||
5245 | static void | |
e5a67952 | 5246 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5247 | { |
e5a67952 | 5248 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 5249 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
5250 | |
5251 | if (num_printed == 0) | |
5252 | { | |
e5a67952 | 5253 | if (args == NULL || *args == '\0') |
d77f58be SS |
5254 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5255 | else | |
e5a67952 | 5256 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5257 | } |
c906108c SS |
5258 | } |
5259 | ||
7a292a7a | 5260 | static void |
e5a67952 | 5261 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5262 | { |
e5a67952 | 5263 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5264 | |
5265 | default_collect_info (); | |
c906108c SS |
5266 | } |
5267 | ||
0d381245 | 5268 | static int |
714835d5 | 5269 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5270 | struct program_space *pspace, |
714835d5 | 5271 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5272 | { |
5273 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5274 | |
0d381245 VP |
5275 | for (; bl; bl = bl->next) |
5276 | { | |
6c95b8df PA |
5277 | if (bl->pspace == pspace |
5278 | && bl->address == pc | |
0d381245 VP |
5279 | && (!overlay_debugging || bl->section == section)) |
5280 | return 1; | |
5281 | } | |
5282 | return 0; | |
5283 | } | |
5284 | ||
672f9b60 | 5285 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
5286 | concerns with logical breakpoints, so we match program spaces, not |
5287 | address spaces. */ | |
c906108c SS |
5288 | |
5289 | static void | |
6c95b8df PA |
5290 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5291 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5292 | struct obj_section *section, int thread) |
c906108c | 5293 | { |
52f0bd74 AC |
5294 | int others = 0; |
5295 | struct breakpoint *b; | |
c906108c SS |
5296 | |
5297 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
5298 | others += (user_breakpoint_p (b) |
5299 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
5300 | if (others > 0) |
5301 | { | |
a3f17187 AC |
5302 | if (others == 1) |
5303 | printf_filtered (_("Note: breakpoint ")); | |
5304 | else /* if (others == ???) */ | |
5305 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5306 | ALL_BREAKPOINTS (b) |
672f9b60 | 5307 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5308 | { |
5309 | others--; | |
5310 | printf_filtered ("%d", b->number); | |
5311 | if (b->thread == -1 && thread != -1) | |
5312 | printf_filtered (" (all threads)"); | |
5313 | else if (b->thread != -1) | |
5314 | printf_filtered (" (thread %d)", b->thread); | |
5315 | printf_filtered ("%s%s ", | |
059fb39f | 5316 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5317 | || b->enable_state == bp_call_disabled |
5318 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5319 | ? " (disabled)" |
5320 | : b->enable_state == bp_permanent | |
5321 | ? " (permanent)" | |
5322 | : ""), | |
5323 | (others > 1) ? "," | |
5324 | : ((others == 1) ? " and" : "")); | |
5325 | } | |
a3f17187 | 5326 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5327 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5328 | printf_filtered (".\n"); |
5329 | } | |
5330 | } | |
5331 | \f | |
c906108c | 5332 | |
e4f237da KB |
5333 | /* Return true iff it is meaningful to use the address member of |
5334 | BPT. For some breakpoint types, the address member is irrelevant | |
5335 | and it makes no sense to attempt to compare it to other addresses | |
5336 | (or use it for any other purpose either). | |
5337 | ||
4a64f543 MS |
5338 | More specifically, each of the following breakpoint types will |
5339 | always have a zero valued address and we don't want to mark | |
5340 | breakpoints of any of these types to be a duplicate of an actual | |
5341 | breakpoint at address zero: | |
e4f237da KB |
5342 | |
5343 | bp_watchpoint | |
2d134ed3 PA |
5344 | bp_catchpoint |
5345 | ||
5346 | */ | |
e4f237da KB |
5347 | |
5348 | static int | |
5349 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5350 | { | |
5351 | enum bptype type = bpt->type; | |
5352 | ||
2d134ed3 PA |
5353 | return (type != bp_watchpoint && type != bp_catchpoint); |
5354 | } | |
5355 | ||
5356 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5357 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5358 | ||
5359 | static int | |
4a64f543 MS |
5360 | watchpoint_locations_match (struct bp_location *loc1, |
5361 | struct bp_location *loc2) | |
2d134ed3 | 5362 | { |
3a5c3e22 PA |
5363 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
5364 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
5365 | ||
5366 | /* Both of them must exist. */ | |
5367 | gdb_assert (w1 != NULL); | |
5368 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 5369 | |
4a64f543 MS |
5370 | /* If the target can evaluate the condition expression in hardware, |
5371 | then we we need to insert both watchpoints even if they are at | |
5372 | the same place. Otherwise the watchpoint will only trigger when | |
5373 | the condition of whichever watchpoint was inserted evaluates to | |
5374 | true, not giving a chance for GDB to check the condition of the | |
5375 | other watchpoint. */ | |
3a5c3e22 | 5376 | if ((w1->cond_exp |
4a64f543 MS |
5377 | && target_can_accel_watchpoint_condition (loc1->address, |
5378 | loc1->length, | |
0cf6dd15 | 5379 | loc1->watchpoint_type, |
3a5c3e22 PA |
5380 | w1->cond_exp)) |
5381 | || (w2->cond_exp | |
4a64f543 MS |
5382 | && target_can_accel_watchpoint_condition (loc2->address, |
5383 | loc2->length, | |
0cf6dd15 | 5384 | loc2->watchpoint_type, |
3a5c3e22 | 5385 | w2->cond_exp))) |
0cf6dd15 TJB |
5386 | return 0; |
5387 | ||
85d721b8 PA |
5388 | /* Note that this checks the owner's type, not the location's. In |
5389 | case the target does not support read watchpoints, but does | |
5390 | support access watchpoints, we'll have bp_read_watchpoint | |
5391 | watchpoints with hw_access locations. Those should be considered | |
5392 | duplicates of hw_read locations. The hw_read locations will | |
5393 | become hw_access locations later. */ | |
2d134ed3 PA |
5394 | return (loc1->owner->type == loc2->owner->type |
5395 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5396 | && loc1->address == loc2->address | |
5397 | && loc1->length == loc2->length); | |
e4f237da KB |
5398 | } |
5399 | ||
6c95b8df PA |
5400 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5401 | same breakpoint location. In most targets, this can only be true | |
5402 | if ASPACE1 matches ASPACE2. On targets that have global | |
5403 | breakpoints, the address space doesn't really matter. */ | |
5404 | ||
5405 | static int | |
5406 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5407 | struct address_space *aspace2, CORE_ADDR addr2) | |
5408 | { | |
5409 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5410 | || aspace1 == aspace2) | |
5411 | && addr1 == addr2); | |
5412 | } | |
5413 | ||
f1310107 TJB |
5414 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
5415 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
5416 | matches ASPACE2. On targets that have global breakpoints, the address | |
5417 | space doesn't really matter. */ | |
5418 | ||
5419 | static int | |
5420 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
5421 | int len1, struct address_space *aspace2, | |
5422 | CORE_ADDR addr2) | |
5423 | { | |
5424 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5425 | || aspace1 == aspace2) | |
5426 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
5427 | } | |
5428 | ||
5429 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
5430 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
5431 | matches the breakpoint's address space. On targets that have global | |
5432 | breakpoints, the address space doesn't really matter. */ | |
5433 | ||
5434 | static int | |
5435 | breakpoint_location_address_match (struct bp_location *bl, | |
5436 | struct address_space *aspace, | |
5437 | CORE_ADDR addr) | |
5438 | { | |
5439 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
5440 | aspace, addr) | |
5441 | || (bl->length | |
5442 | && breakpoint_address_match_range (bl->pspace->aspace, | |
5443 | bl->address, bl->length, | |
5444 | aspace, addr))); | |
5445 | } | |
5446 | ||
1e4d1764 YQ |
5447 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
5448 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
5449 | true, otherwise returns false. */ | |
5450 | ||
5451 | static int | |
5452 | tracepoint_locations_match (struct bp_location *loc1, | |
5453 | struct bp_location *loc2) | |
5454 | { | |
5455 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
5456 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
5457 | locations at the same address of different tracepoints are regarded as | |
5458 | different locations. */ | |
5459 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
5460 | else | |
5461 | return 0; | |
5462 | } | |
5463 | ||
2d134ed3 PA |
5464 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5465 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5466 | represent the same location. */ | |
5467 | ||
5468 | static int | |
4a64f543 MS |
5469 | breakpoint_locations_match (struct bp_location *loc1, |
5470 | struct bp_location *loc2) | |
2d134ed3 | 5471 | { |
2bdf28a0 JK |
5472 | int hw_point1, hw_point2; |
5473 | ||
5474 | /* Both of them must not be in moribund_locations. */ | |
5475 | gdb_assert (loc1->owner != NULL); | |
5476 | gdb_assert (loc2->owner != NULL); | |
5477 | ||
5478 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5479 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5480 | |
5481 | if (hw_point1 != hw_point2) | |
5482 | return 0; | |
5483 | else if (hw_point1) | |
5484 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
5485 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
5486 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 5487 | else |
f1310107 TJB |
5488 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
5489 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5490 | loc2->pspace->aspace, loc2->address) | |
5491 | && loc1->length == loc2->length); | |
2d134ed3 PA |
5492 | } |
5493 | ||
76897487 KB |
5494 | static void |
5495 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5496 | int bnum, int have_bnum) | |
5497 | { | |
f63fbe86 MS |
5498 | /* The longest string possibly returned by hex_string_custom |
5499 | is 50 chars. These must be at least that big for safety. */ | |
5500 | char astr1[64]; | |
5501 | char astr2[64]; | |
76897487 | 5502 | |
bb599908 PH |
5503 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5504 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5505 | if (have_bnum) |
8a3fe4f8 | 5506 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5507 | bnum, astr1, astr2); |
5508 | else | |
8a3fe4f8 | 5509 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5510 | } |
5511 | ||
4a64f543 MS |
5512 | /* Adjust a breakpoint's address to account for architectural |
5513 | constraints on breakpoint placement. Return the adjusted address. | |
5514 | Note: Very few targets require this kind of adjustment. For most | |
5515 | targets, this function is simply the identity function. */ | |
76897487 KB |
5516 | |
5517 | static CORE_ADDR | |
a6d9a66e UW |
5518 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5519 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5520 | { |
a6d9a66e | 5521 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5522 | { |
5523 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5524 | return bpaddr; | |
5525 | } | |
88f7da05 KB |
5526 | else if (bptype == bp_watchpoint |
5527 | || bptype == bp_hardware_watchpoint | |
5528 | || bptype == bp_read_watchpoint | |
5529 | || bptype == bp_access_watchpoint | |
fe798b75 | 5530 | || bptype == bp_catchpoint) |
88f7da05 KB |
5531 | { |
5532 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5533 | have their addresses modified. */ | |
5534 | return bpaddr; | |
5535 | } | |
76897487 KB |
5536 | else |
5537 | { | |
5538 | CORE_ADDR adjusted_bpaddr; | |
5539 | ||
5540 | /* Some targets have architectural constraints on the placement | |
5541 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5542 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5543 | |
5544 | /* An adjusted breakpoint address can significantly alter | |
5545 | a user's expectations. Print a warning if an adjustment | |
5546 | is required. */ | |
5547 | if (adjusted_bpaddr != bpaddr) | |
5548 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5549 | ||
5550 | return adjusted_bpaddr; | |
5551 | } | |
5552 | } | |
5553 | ||
28010a5d PA |
5554 | void |
5555 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
5556 | struct breakpoint *owner) | |
7cc221ef | 5557 | { |
7cc221ef DJ |
5558 | memset (loc, 0, sizeof (*loc)); |
5559 | ||
348d480f PA |
5560 | gdb_assert (ops != NULL); |
5561 | ||
28010a5d PA |
5562 | loc->ops = ops; |
5563 | loc->owner = owner; | |
511a6cd4 | 5564 | loc->cond = NULL; |
0d381245 VP |
5565 | loc->shlib_disabled = 0; |
5566 | loc->enabled = 1; | |
e049a4b5 | 5567 | |
28010a5d | 5568 | switch (owner->type) |
e049a4b5 DJ |
5569 | { |
5570 | case bp_breakpoint: | |
5571 | case bp_until: | |
5572 | case bp_finish: | |
5573 | case bp_longjmp: | |
5574 | case bp_longjmp_resume: | |
186c406b TT |
5575 | case bp_exception: |
5576 | case bp_exception_resume: | |
e049a4b5 | 5577 | case bp_step_resume: |
2c03e5be | 5578 | case bp_hp_step_resume: |
e049a4b5 DJ |
5579 | case bp_watchpoint_scope: |
5580 | case bp_call_dummy: | |
aa7d318d | 5581 | case bp_std_terminate: |
e049a4b5 DJ |
5582 | case bp_shlib_event: |
5583 | case bp_thread_event: | |
5584 | case bp_overlay_event: | |
4efc6507 | 5585 | case bp_jit_event: |
0fd8e87f | 5586 | case bp_longjmp_master: |
aa7d318d | 5587 | case bp_std_terminate_master: |
186c406b | 5588 | case bp_exception_master: |
0e30163f JK |
5589 | case bp_gnu_ifunc_resolver: |
5590 | case bp_gnu_ifunc_resolver_return: | |
e049a4b5 DJ |
5591 | loc->loc_type = bp_loc_software_breakpoint; |
5592 | break; | |
5593 | case bp_hardware_breakpoint: | |
5594 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5595 | break; | |
5596 | case bp_hardware_watchpoint: | |
5597 | case bp_read_watchpoint: | |
5598 | case bp_access_watchpoint: | |
5599 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5600 | break; | |
5601 | case bp_watchpoint: | |
ce78b96d | 5602 | case bp_catchpoint: |
15c3d785 PA |
5603 | case bp_tracepoint: |
5604 | case bp_fast_tracepoint: | |
0fb4aa4b | 5605 | case bp_static_tracepoint: |
e049a4b5 DJ |
5606 | loc->loc_type = bp_loc_other; |
5607 | break; | |
5608 | default: | |
e2e0b3e5 | 5609 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5610 | } |
5611 | ||
f431efe5 | 5612 | loc->refc = 1; |
28010a5d PA |
5613 | } |
5614 | ||
5615 | /* Allocate a struct bp_location. */ | |
5616 | ||
5617 | static struct bp_location * | |
5618 | allocate_bp_location (struct breakpoint *bpt) | |
5619 | { | |
348d480f PA |
5620 | return bpt->ops->allocate_location (bpt); |
5621 | } | |
7cc221ef | 5622 | |
f431efe5 PA |
5623 | static void |
5624 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 5625 | { |
348d480f | 5626 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
5627 | xfree (loc); |
5628 | } | |
5629 | ||
f431efe5 PA |
5630 | /* Increment reference count. */ |
5631 | ||
5632 | static void | |
5633 | incref_bp_location (struct bp_location *bl) | |
5634 | { | |
5635 | ++bl->refc; | |
5636 | } | |
5637 | ||
5638 | /* Decrement reference count. If the reference count reaches 0, | |
5639 | destroy the bp_location. Sets *BLP to NULL. */ | |
5640 | ||
5641 | static void | |
5642 | decref_bp_location (struct bp_location **blp) | |
5643 | { | |
0807b50c PA |
5644 | gdb_assert ((*blp)->refc > 0); |
5645 | ||
f431efe5 PA |
5646 | if (--(*blp)->refc == 0) |
5647 | free_bp_location (*blp); | |
5648 | *blp = NULL; | |
5649 | } | |
5650 | ||
346774a9 | 5651 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 5652 | |
346774a9 PA |
5653 | static void |
5654 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 5655 | { |
346774a9 | 5656 | struct breakpoint *b1; |
c906108c | 5657 | |
346774a9 PA |
5658 | /* Add this breakpoint to the end of the chain so that a list of |
5659 | breakpoints will come out in order of increasing numbers. */ | |
5660 | ||
5661 | b1 = breakpoint_chain; | |
5662 | if (b1 == 0) | |
5663 | breakpoint_chain = b; | |
5664 | else | |
5665 | { | |
5666 | while (b1->next) | |
5667 | b1 = b1->next; | |
5668 | b1->next = b; | |
5669 | } | |
5670 | } | |
5671 | ||
5672 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
5673 | ||
5674 | static void | |
5675 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
5676 | struct gdbarch *gdbarch, | |
28010a5d | 5677 | enum bptype bptype, |
c0a91b2b | 5678 | const struct breakpoint_ops *ops) |
346774a9 | 5679 | { |
c906108c | 5680 | memset (b, 0, sizeof (*b)); |
2219d63c | 5681 | |
348d480f PA |
5682 | gdb_assert (ops != NULL); |
5683 | ||
28010a5d | 5684 | b->ops = ops; |
4d28f7a8 | 5685 | b->type = bptype; |
a6d9a66e | 5686 | b->gdbarch = gdbarch; |
c906108c SS |
5687 | b->language = current_language->la_language; |
5688 | b->input_radix = input_radix; | |
5689 | b->thread = -1; | |
b5de0fa7 | 5690 | b->enable_state = bp_enabled; |
c906108c SS |
5691 | b->next = 0; |
5692 | b->silent = 0; | |
5693 | b->ignore_count = 0; | |
5694 | b->commands = NULL; | |
818dd999 | 5695 | b->frame_id = null_frame_id; |
0d381245 | 5696 | b->condition_not_parsed = 0; |
84f4c1fe | 5697 | b->py_bp_object = NULL; |
d0fb5eae | 5698 | b->related_breakpoint = b; |
346774a9 PA |
5699 | } |
5700 | ||
5701 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
5702 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
5703 | |
5704 | static struct breakpoint * | |
5705 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 5706 | enum bptype bptype, |
c0a91b2b | 5707 | const struct breakpoint_ops *ops) |
346774a9 PA |
5708 | { |
5709 | struct breakpoint *b = XNEW (struct breakpoint); | |
5710 | ||
348d480f | 5711 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 5712 | add_to_breakpoint_chain (b); |
0d381245 VP |
5713 | return b; |
5714 | } | |
5715 | ||
0e30163f JK |
5716 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
5717 | resolutions should be made as the user specified the location explicitly | |
5718 | enough. */ | |
5719 | ||
0d381245 | 5720 | static void |
0e30163f | 5721 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 5722 | { |
2bdf28a0 JK |
5723 | gdb_assert (loc->owner != NULL); |
5724 | ||
0d381245 | 5725 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5726 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5727 | || is_tracepoint (loc->owner)) |
0d381245 | 5728 | { |
0e30163f JK |
5729 | int is_gnu_ifunc; |
5730 | ||
5731 | find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name, | |
5732 | NULL, NULL, &is_gnu_ifunc); | |
5733 | ||
5734 | if (is_gnu_ifunc && !explicit_loc) | |
5735 | { | |
5736 | struct breakpoint *b = loc->owner; | |
5737 | ||
5738 | gdb_assert (loc->pspace == current_program_space); | |
5739 | if (gnu_ifunc_resolve_name (loc->function_name, | |
5740 | &loc->requested_address)) | |
5741 | { | |
5742 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
5743 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
5744 | loc->requested_address, | |
5745 | b->type); | |
5746 | } | |
5747 | else if (b->type == bp_breakpoint && b->loc == loc | |
5748 | && loc->next == NULL && b->related_breakpoint == b) | |
5749 | { | |
5750 | /* Create only the whole new breakpoint of this type but do not | |
5751 | mess more complicated breakpoints with multiple locations. */ | |
5752 | b->type = bp_gnu_ifunc_resolver; | |
5753 | } | |
5754 | } | |
5755 | ||
0d381245 VP |
5756 | if (loc->function_name) |
5757 | loc->function_name = xstrdup (loc->function_name); | |
5758 | } | |
5759 | } | |
5760 | ||
a6d9a66e | 5761 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 5762 | struct gdbarch * |
a6d9a66e UW |
5763 | get_sal_arch (struct symtab_and_line sal) |
5764 | { | |
5765 | if (sal.section) | |
5766 | return get_objfile_arch (sal.section->objfile); | |
5767 | if (sal.symtab) | |
5768 | return get_objfile_arch (sal.symtab->objfile); | |
5769 | ||
5770 | return NULL; | |
5771 | } | |
5772 | ||
346774a9 PA |
5773 | /* Low level routine for partially initializing a breakpoint of type |
5774 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 5775 | file name, and line number are provided by SAL. |
0d381245 VP |
5776 | |
5777 | It is expected that the caller will complete the initialization of | |
5778 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 5779 | information regarding the creation of a new breakpoint. */ |
0d381245 | 5780 | |
346774a9 PA |
5781 | static void |
5782 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 5783 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5784 | const struct breakpoint_ops *ops) |
0d381245 | 5785 | { |
28010a5d | 5786 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 5787 | |
3742cc8b | 5788 | add_location_to_breakpoint (b, &sal); |
0d381245 | 5789 | |
6c95b8df PA |
5790 | if (bptype != bp_catchpoint) |
5791 | gdb_assert (sal.pspace != NULL); | |
5792 | ||
6c95b8df PA |
5793 | /* Store the program space that was used to set the breakpoint, for |
5794 | breakpoint resetting. */ | |
5795 | b->pspace = sal.pspace; | |
0d381245 VP |
5796 | |
5797 | if (sal.symtab == NULL) | |
5798 | b->source_file = NULL; | |
5799 | else | |
1b36a34b | 5800 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5801 | b->line_number = sal.line; |
5802 | ||
c906108c | 5803 | breakpoints_changed (); |
346774a9 | 5804 | } |
c906108c | 5805 | |
346774a9 PA |
5806 | /* set_raw_breakpoint is a low level routine for allocating and |
5807 | partially initializing a breakpoint of type BPTYPE. The newly | |
5808 | created breakpoint's address, section, source file name, and line | |
5809 | number are provided by SAL. The newly created and partially | |
5810 | initialized breakpoint is added to the breakpoint chain and | |
5811 | is also returned as the value of this function. | |
5812 | ||
5813 | It is expected that the caller will complete the initialization of | |
5814 | the newly created breakpoint struct as well as output any status | |
5815 | information regarding the creation of a new breakpoint. In | |
5816 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5817 | number! Care should be taken to not allow an error to occur | |
5818 | prior to completing the initialization of the breakpoint. If this | |
5819 | should happen, a bogus breakpoint will be left on the chain. */ | |
5820 | ||
5821 | struct breakpoint * | |
5822 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 5823 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5824 | const struct breakpoint_ops *ops) |
346774a9 PA |
5825 | { |
5826 | struct breakpoint *b = XNEW (struct breakpoint); | |
5827 | ||
348d480f | 5828 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 5829 | add_to_breakpoint_chain (b); |
c906108c SS |
5830 | return b; |
5831 | } | |
5832 | ||
c2c6d25f JM |
5833 | |
5834 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5835 | instruction, hard-wired into the inferior's code. */ | |
5836 | void | |
5837 | make_breakpoint_permanent (struct breakpoint *b) | |
5838 | { | |
0d381245 | 5839 | struct bp_location *bl; |
cc59ec59 | 5840 | |
b5de0fa7 | 5841 | b->enable_state = bp_permanent; |
c2c6d25f | 5842 | |
4a64f543 MS |
5843 | /* By definition, permanent breakpoints are already present in the |
5844 | code. Mark all locations as inserted. For now, | |
5845 | make_breakpoint_permanent is called in just one place, so it's | |
5846 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 5847 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
5848 | for (bl = b->loc; bl; bl = bl->next) |
5849 | bl->inserted = 1; | |
c2c6d25f JM |
5850 | } |
5851 | ||
53a5351d | 5852 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5853 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5854 | initiated the operation. */ | |
c906108c SS |
5855 | |
5856 | void | |
186c406b | 5857 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5858 | { |
35df4500 | 5859 | struct breakpoint *b, *b_tmp; |
186c406b | 5860 | int thread = tp->num; |
0fd8e87f UW |
5861 | |
5862 | /* To avoid having to rescan all objfile symbols at every step, | |
5863 | we maintain a list of continually-inserted but always disabled | |
5864 | longjmp "master" breakpoints. Here, we simply create momentary | |
5865 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5866 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5867 | if (b->pspace == current_program_space |
186c406b TT |
5868 | && (b->type == bp_longjmp_master |
5869 | || b->type == bp_exception_master)) | |
0fd8e87f | 5870 | { |
06edf0c0 PA |
5871 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
5872 | struct breakpoint *clone; | |
cc59ec59 | 5873 | |
06edf0c0 PA |
5874 | clone = momentary_breakpoint_from_master (b, type, |
5875 | &momentary_breakpoint_ops); | |
0fd8e87f UW |
5876 | clone->thread = thread; |
5877 | } | |
186c406b TT |
5878 | |
5879 | tp->initiating_frame = frame; | |
c906108c SS |
5880 | } |
5881 | ||
611c83ae | 5882 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5883 | void |
611c83ae | 5884 | delete_longjmp_breakpoint (int thread) |
c906108c | 5885 | { |
35df4500 | 5886 | struct breakpoint *b, *b_tmp; |
c906108c | 5887 | |
35df4500 | 5888 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 5889 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
5890 | { |
5891 | if (b->thread == thread) | |
5892 | delete_breakpoint (b); | |
5893 | } | |
c906108c SS |
5894 | } |
5895 | ||
1900040c MS |
5896 | void |
5897 | enable_overlay_breakpoints (void) | |
5898 | { | |
52f0bd74 | 5899 | struct breakpoint *b; |
1900040c MS |
5900 | |
5901 | ALL_BREAKPOINTS (b) | |
5902 | if (b->type == bp_overlay_event) | |
5903 | { | |
5904 | b->enable_state = bp_enabled; | |
b60e7edf | 5905 | update_global_location_list (1); |
c02f5703 | 5906 | overlay_events_enabled = 1; |
1900040c MS |
5907 | } |
5908 | } | |
5909 | ||
5910 | void | |
5911 | disable_overlay_breakpoints (void) | |
5912 | { | |
52f0bd74 | 5913 | struct breakpoint *b; |
1900040c MS |
5914 | |
5915 | ALL_BREAKPOINTS (b) | |
5916 | if (b->type == bp_overlay_event) | |
5917 | { | |
5918 | b->enable_state = bp_disabled; | |
b60e7edf | 5919 | update_global_location_list (0); |
c02f5703 | 5920 | overlay_events_enabled = 0; |
1900040c MS |
5921 | } |
5922 | } | |
5923 | ||
aa7d318d TT |
5924 | /* Set an active std::terminate breakpoint for each std::terminate |
5925 | master breakpoint. */ | |
5926 | void | |
5927 | set_std_terminate_breakpoint (void) | |
5928 | { | |
35df4500 | 5929 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5930 | |
35df4500 | 5931 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5932 | if (b->pspace == current_program_space |
5933 | && b->type == bp_std_terminate_master) | |
5934 | { | |
06edf0c0 PA |
5935 | momentary_breakpoint_from_master (b, bp_std_terminate, |
5936 | &momentary_breakpoint_ops); | |
aa7d318d TT |
5937 | } |
5938 | } | |
5939 | ||
5940 | /* Delete all the std::terminate breakpoints. */ | |
5941 | void | |
5942 | delete_std_terminate_breakpoint (void) | |
5943 | { | |
35df4500 | 5944 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5945 | |
35df4500 | 5946 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5947 | if (b->type == bp_std_terminate) |
5948 | delete_breakpoint (b); | |
5949 | } | |
5950 | ||
c4093a6a | 5951 | struct breakpoint * |
a6d9a66e | 5952 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5953 | { |
5954 | struct breakpoint *b; | |
c4093a6a | 5955 | |
06edf0c0 PA |
5956 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
5957 | &internal_breakpoint_ops); | |
5958 | ||
b5de0fa7 | 5959 | b->enable_state = bp_enabled; |
c4093a6a | 5960 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5961 | b->addr_string |
5962 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5963 | |
b60e7edf | 5964 | update_global_location_list_nothrow (1); |
74960c60 | 5965 | |
c4093a6a JM |
5966 | return b; |
5967 | } | |
5968 | ||
5969 | void | |
5970 | remove_thread_event_breakpoints (void) | |
5971 | { | |
35df4500 | 5972 | struct breakpoint *b, *b_tmp; |
c4093a6a | 5973 | |
35df4500 | 5974 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5975 | if (b->type == bp_thread_event |
5976 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5977 | delete_breakpoint (b); |
5978 | } | |
5979 | ||
0101ce28 JJ |
5980 | struct lang_and_radix |
5981 | { | |
5982 | enum language lang; | |
5983 | int radix; | |
5984 | }; | |
5985 | ||
4efc6507 DE |
5986 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5987 | ||
5988 | struct breakpoint * | |
5989 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5990 | { | |
5991 | struct breakpoint *b; | |
5992 | ||
06edf0c0 PA |
5993 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
5994 | &internal_breakpoint_ops); | |
4efc6507 DE |
5995 | update_global_location_list_nothrow (1); |
5996 | return b; | |
5997 | } | |
0101ce28 | 5998 | |
03673fc7 PP |
5999 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
6000 | ||
6001 | void | |
6002 | remove_jit_event_breakpoints (void) | |
6003 | { | |
6004 | struct breakpoint *b, *b_tmp; | |
6005 | ||
6006 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6007 | if (b->type == bp_jit_event | |
6008 | && b->loc->pspace == current_program_space) | |
6009 | delete_breakpoint (b); | |
6010 | } | |
6011 | ||
cae688ec JJ |
6012 | void |
6013 | remove_solib_event_breakpoints (void) | |
6014 | { | |
35df4500 | 6015 | struct breakpoint *b, *b_tmp; |
cae688ec | 6016 | |
35df4500 | 6017 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6018 | if (b->type == bp_shlib_event |
6019 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6020 | delete_breakpoint (b); |
6021 | } | |
6022 | ||
6023 | struct breakpoint * | |
a6d9a66e | 6024 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6025 | { |
6026 | struct breakpoint *b; | |
6027 | ||
06edf0c0 PA |
6028 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
6029 | &internal_breakpoint_ops); | |
b60e7edf | 6030 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6031 | return b; |
6032 | } | |
6033 | ||
6034 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6035 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6036 | ||
6037 | void | |
cb851954 | 6038 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6039 | { |
876fa593 | 6040 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6041 | |
876fa593 | 6042 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6043 | { |
2bdf28a0 | 6044 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6045 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6046 | |
4a64f543 MS |
6047 | /* We apply the check to all breakpoints, including disabled for |
6048 | those with loc->duplicate set. This is so that when breakpoint | |
6049 | becomes enabled, or the duplicate is removed, gdb will try to | |
6050 | insert all breakpoints. If we don't set shlib_disabled here, | |
6051 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6052 | if (((b->type == bp_breakpoint) |
508ccb1f | 6053 | || (b->type == bp_jit_event) |
1042e4c0 | 6054 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6055 | || (is_tracepoint (b))) |
6c95b8df | 6056 | && loc->pspace == current_program_space |
0d381245 | 6057 | && !loc->shlib_disabled |
a77053c2 | 6058 | #ifdef PC_SOLIB |
0d381245 | 6059 | && PC_SOLIB (loc->address) |
a77053c2 | 6060 | #else |
6c95b8df | 6061 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6062 | #endif |
6063 | ) | |
0d381245 VP |
6064 | { |
6065 | loc->shlib_disabled = 1; | |
6066 | } | |
cae688ec JJ |
6067 | } |
6068 | } | |
6069 | ||
1e4d1764 YQ |
6070 | /* Disable any breakpoints and tracepoints that are in an unloaded shared |
6071 | library. Only apply to enabled breakpoints, disabled ones can just stay | |
4a64f543 | 6072 | disabled. */ |
84acb35a | 6073 | |
75149521 | 6074 | static void |
84acb35a JJ |
6075 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6076 | { | |
876fa593 | 6077 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6078 | int disabled_shlib_breaks = 0; |
6079 | ||
c86cf029 VP |
6080 | /* SunOS a.out shared libraries are always mapped, so do not |
6081 | disable breakpoints; they will only be reported as unloaded | |
6082 | through clear_solib when GDB discards its shared library | |
6083 | list. See clear_solib for more information. */ | |
6084 | if (exec_bfd != NULL | |
6085 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6086 | return; | |
6087 | ||
876fa593 | 6088 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6089 | { |
2bdf28a0 | 6090 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6091 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6092 | |
1e4d1764 | 6093 | if (solib->pspace == loc->pspace |
e2dd7057 | 6094 | && !loc->shlib_disabled |
1e4d1764 YQ |
6095 | && (((b->type == bp_breakpoint |
6096 | || b->type == bp_jit_event | |
6097 | || b->type == bp_hardware_breakpoint) | |
6098 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
6099 | || loc->loc_type == bp_loc_software_breakpoint)) | |
6100 | || is_tracepoint (b)) | |
e2dd7057 | 6101 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6102 | { |
e2dd7057 PP |
6103 | loc->shlib_disabled = 1; |
6104 | /* At this point, we cannot rely on remove_breakpoint | |
6105 | succeeding so we must mark the breakpoint as not inserted | |
6106 | to prevent future errors occurring in remove_breakpoints. */ | |
6107 | loc->inserted = 0; | |
8d3788bd VP |
6108 | |
6109 | /* This may cause duplicate notifications for the same breakpoint. */ | |
6110 | observer_notify_breakpoint_modified (b); | |
6111 | ||
e2dd7057 PP |
6112 | if (!disabled_shlib_breaks) |
6113 | { | |
6114 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6115 | warning (_("Temporarily disabling breakpoints " |
6116 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6117 | solib->so_name); |
84acb35a | 6118 | } |
e2dd7057 | 6119 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6120 | } |
6121 | } | |
84acb35a JJ |
6122 | } |
6123 | ||
ce78b96d JB |
6124 | /* FORK & VFORK catchpoints. */ |
6125 | ||
e29a4733 PA |
6126 | /* An instance of this type is used to represent a fork or vfork |
6127 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
6128 | class; users downcast to "struct breakpoint *" when needed. A | |
6129 | breakpoint is really of this type iff its ops pointer points to | |
6130 | CATCH_FORK_BREAKPOINT_OPS. */ | |
6131 | ||
6132 | struct fork_catchpoint | |
6133 | { | |
6134 | /* The base class. */ | |
6135 | struct breakpoint base; | |
6136 | ||
6137 | /* Process id of a child process whose forking triggered this | |
6138 | catchpoint. This field is only valid immediately after this | |
6139 | catchpoint has triggered. */ | |
6140 | ptid_t forked_inferior_pid; | |
6141 | }; | |
6142 | ||
4a64f543 MS |
6143 | /* Implement the "insert" breakpoint_ops method for fork |
6144 | catchpoints. */ | |
ce78b96d | 6145 | |
77b06cd7 TJB |
6146 | static int |
6147 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6148 | { |
77b06cd7 | 6149 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6150 | } |
6151 | ||
4a64f543 MS |
6152 | /* Implement the "remove" breakpoint_ops method for fork |
6153 | catchpoints. */ | |
ce78b96d JB |
6154 | |
6155 | static int | |
77b06cd7 | 6156 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6157 | { |
6158 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6159 | } | |
6160 | ||
6161 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6162 | catchpoints. */ | |
6163 | ||
6164 | static int | |
f1310107 TJB |
6165 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
6166 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6167 | { |
e29a4733 PA |
6168 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6169 | ||
6170 | return inferior_has_forked (inferior_ptid, &c->forked_inferior_pid); | |
ce78b96d JB |
6171 | } |
6172 | ||
4a64f543 MS |
6173 | /* Implement the "print_it" breakpoint_ops method for fork |
6174 | catchpoints. */ | |
ce78b96d JB |
6175 | |
6176 | static enum print_stop_action | |
348d480f | 6177 | print_it_catch_fork (bpstat bs) |
ce78b96d | 6178 | { |
348d480f PA |
6179 | struct breakpoint *b = bs->breakpoint_at; |
6180 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 6181 | |
ce78b96d JB |
6182 | annotate_catchpoint (b->number); |
6183 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
e29a4733 | 6184 | b->number, ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6185 | return PRINT_SRC_AND_LOC; |
6186 | } | |
6187 | ||
4a64f543 MS |
6188 | /* Implement the "print_one" breakpoint_ops method for fork |
6189 | catchpoints. */ | |
ce78b96d JB |
6190 | |
6191 | static void | |
a6d9a66e | 6192 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6193 | { |
e29a4733 | 6194 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6195 | struct value_print_options opts; |
79a45e25 | 6196 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6197 | |
6198 | get_user_print_options (&opts); | |
6199 | ||
4a64f543 MS |
6200 | /* Field 4, the address, is omitted (which makes the columns not |
6201 | line up too nicely with the headers, but the effect is relatively | |
6202 | readable). */ | |
79a45b7d | 6203 | if (opts.addressprint) |
ce78b96d JB |
6204 | ui_out_field_skip (uiout, "addr"); |
6205 | annotate_field (5); | |
6206 | ui_out_text (uiout, "fork"); | |
e29a4733 | 6207 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6208 | { |
6209 | ui_out_text (uiout, ", process "); | |
6210 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6211 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6212 | ui_out_spaces (uiout, 1); |
6213 | } | |
6214 | } | |
6215 | ||
6216 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6217 | catchpoints. */ | |
6218 | ||
6219 | static void | |
6220 | print_mention_catch_fork (struct breakpoint *b) | |
6221 | { | |
6222 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6223 | } | |
6224 | ||
6149aea9 PA |
6225 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6226 | catchpoints. */ | |
6227 | ||
6228 | static void | |
6229 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6230 | { | |
6231 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 6232 | print_recreate_thread (b, fp); |
6149aea9 PA |
6233 | } |
6234 | ||
ce78b96d JB |
6235 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6236 | ||
2060206e | 6237 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 6238 | |
4a64f543 MS |
6239 | /* Implement the "insert" breakpoint_ops method for vfork |
6240 | catchpoints. */ | |
ce78b96d | 6241 | |
77b06cd7 TJB |
6242 | static int |
6243 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6244 | { |
77b06cd7 | 6245 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6246 | } |
6247 | ||
4a64f543 MS |
6248 | /* Implement the "remove" breakpoint_ops method for vfork |
6249 | catchpoints. */ | |
ce78b96d JB |
6250 | |
6251 | static int | |
77b06cd7 | 6252 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6253 | { |
6254 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6255 | } | |
6256 | ||
6257 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6258 | catchpoints. */ | |
6259 | ||
6260 | static int | |
f1310107 TJB |
6261 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
6262 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6263 | { |
e29a4733 PA |
6264 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6265 | ||
6266 | return inferior_has_vforked (inferior_ptid, &c->forked_inferior_pid); | |
ce78b96d JB |
6267 | } |
6268 | ||
4a64f543 MS |
6269 | /* Implement the "print_it" breakpoint_ops method for vfork |
6270 | catchpoints. */ | |
ce78b96d JB |
6271 | |
6272 | static enum print_stop_action | |
348d480f | 6273 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 6274 | { |
348d480f | 6275 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
6276 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
6277 | ||
ce78b96d JB |
6278 | annotate_catchpoint (b->number); |
6279 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
e29a4733 | 6280 | b->number, ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6281 | return PRINT_SRC_AND_LOC; |
6282 | } | |
6283 | ||
4a64f543 MS |
6284 | /* Implement the "print_one" breakpoint_ops method for vfork |
6285 | catchpoints. */ | |
ce78b96d JB |
6286 | |
6287 | static void | |
a6d9a66e | 6288 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6289 | { |
e29a4733 | 6290 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6291 | struct value_print_options opts; |
79a45e25 | 6292 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6293 | |
6294 | get_user_print_options (&opts); | |
4a64f543 MS |
6295 | /* Field 4, the address, is omitted (which makes the columns not |
6296 | line up too nicely with the headers, but the effect is relatively | |
6297 | readable). */ | |
79a45b7d | 6298 | if (opts.addressprint) |
ce78b96d JB |
6299 | ui_out_field_skip (uiout, "addr"); |
6300 | annotate_field (5); | |
6301 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 6302 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6303 | { |
6304 | ui_out_text (uiout, ", process "); | |
6305 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6306 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6307 | ui_out_spaces (uiout, 1); |
6308 | } | |
6309 | } | |
6310 | ||
6311 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6312 | catchpoints. */ | |
6313 | ||
6314 | static void | |
6315 | print_mention_catch_vfork (struct breakpoint *b) | |
6316 | { | |
6317 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6318 | } | |
6319 | ||
6149aea9 PA |
6320 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6321 | catchpoints. */ | |
6322 | ||
6323 | static void | |
6324 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6325 | { | |
6326 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 6327 | print_recreate_thread (b, fp); |
6149aea9 PA |
6328 | } |
6329 | ||
ce78b96d JB |
6330 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6331 | ||
2060206e | 6332 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 6333 | |
be5c67c1 PA |
6334 | /* An instance of this type is used to represent a syscall catchpoint. |
6335 | It includes a "struct breakpoint" as a kind of base class; users | |
6336 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6337 | really of this type iff its ops pointer points to | |
6338 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
6339 | ||
6340 | struct syscall_catchpoint | |
6341 | { | |
6342 | /* The base class. */ | |
6343 | struct breakpoint base; | |
6344 | ||
6345 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
6346 | syscall has been specified for filtering, its value is NULL. | |
6347 | Otherwise, it holds a list of all syscalls to be caught. The | |
6348 | list elements are allocated with xmalloc. */ | |
6349 | VEC(int) *syscalls_to_be_caught; | |
6350 | }; | |
6351 | ||
6352 | /* Implement the "dtor" breakpoint_ops method for syscall | |
6353 | catchpoints. */ | |
6354 | ||
6355 | static void | |
6356 | dtor_catch_syscall (struct breakpoint *b) | |
6357 | { | |
6358 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
6359 | ||
6360 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 6361 | |
2060206e | 6362 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
6363 | } |
6364 | ||
a96d9b2e SDJ |
6365 | /* Implement the "insert" breakpoint_ops method for syscall |
6366 | catchpoints. */ | |
6367 | ||
77b06cd7 TJB |
6368 | static int |
6369 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 6370 | { |
be5c67c1 | 6371 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6372 | struct inferior *inf = current_inferior (); |
6373 | ||
6374 | ++inf->total_syscalls_count; | |
be5c67c1 | 6375 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6376 | ++inf->any_syscall_count; |
6377 | else | |
6378 | { | |
6379 | int i, iter; | |
cc59ec59 | 6380 | |
a96d9b2e | 6381 | for (i = 0; |
be5c67c1 | 6382 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6383 | i++) |
6384 | { | |
6385 | int elem; | |
cc59ec59 | 6386 | |
a96d9b2e SDJ |
6387 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6388 | { | |
6389 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6390 | uintptr_t vec_addr_offset |
6391 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6392 | uintptr_t vec_addr; |
6393 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6394 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6395 | vec_addr_offset; | |
6396 | memset ((void *) vec_addr, 0, | |
6397 | (iter + 1 - old_size) * sizeof (int)); | |
6398 | } | |
6399 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6400 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6401 | } | |
6402 | } | |
6403 | ||
77b06cd7 TJB |
6404 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6405 | inf->total_syscalls_count != 0, | |
6406 | inf->any_syscall_count, | |
6407 | VEC_length (int, inf->syscalls_counts), | |
6408 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6409 | } |
6410 | ||
6411 | /* Implement the "remove" breakpoint_ops method for syscall | |
6412 | catchpoints. */ | |
6413 | ||
6414 | static int | |
77b06cd7 | 6415 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 6416 | { |
be5c67c1 | 6417 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6418 | struct inferior *inf = current_inferior (); |
6419 | ||
6420 | --inf->total_syscalls_count; | |
be5c67c1 | 6421 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6422 | --inf->any_syscall_count; |
6423 | else | |
6424 | { | |
6425 | int i, iter; | |
cc59ec59 | 6426 | |
a96d9b2e | 6427 | for (i = 0; |
be5c67c1 | 6428 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6429 | i++) |
6430 | { | |
6431 | int elem; | |
6432 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6433 | /* Shouldn't happen. */ | |
6434 | continue; | |
6435 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6436 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6437 | } | |
6438 | } | |
6439 | ||
6440 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6441 | inf->total_syscalls_count != 0, | |
6442 | inf->any_syscall_count, | |
6443 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6444 | VEC_address (int, |
6445 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6446 | } |
6447 | ||
6448 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6449 | catchpoints. */ | |
6450 | ||
6451 | static int | |
f1310107 TJB |
6452 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
6453 | struct address_space *aspace, CORE_ADDR bp_addr) | |
a96d9b2e | 6454 | { |
4a64f543 MS |
6455 | /* We must check if we are catching specific syscalls in this |
6456 | breakpoint. If we are, then we must guarantee that the called | |
6457 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 6458 | int syscall_number = 0; |
be5c67c1 PA |
6459 | const struct syscall_catchpoint *c |
6460 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e SDJ |
6461 | |
6462 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6463 | return 0; | |
6464 | ||
6465 | /* Now, checking if the syscall is the same. */ | |
be5c67c1 | 6466 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6467 | { |
6468 | int i, iter; | |
cc59ec59 | 6469 | |
a96d9b2e | 6470 | for (i = 0; |
be5c67c1 | 6471 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6472 | i++) |
6473 | if (syscall_number == iter) | |
6474 | break; | |
6475 | /* Not the same. */ | |
6476 | if (!iter) | |
6477 | return 0; | |
6478 | } | |
6479 | ||
6480 | return 1; | |
6481 | } | |
6482 | ||
6483 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6484 | catchpoints. */ | |
6485 | ||
6486 | static enum print_stop_action | |
348d480f | 6487 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 6488 | { |
348d480f | 6489 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
6490 | /* These are needed because we want to know in which state a |
6491 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6492 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6493 | must print "called syscall" or "returned from syscall". */ | |
6494 | ptid_t ptid; | |
6495 | struct target_waitstatus last; | |
6496 | struct syscall s; | |
6497 | struct cleanup *old_chain; | |
6498 | char *syscall_id; | |
6499 | ||
6500 | get_last_target_status (&ptid, &last); | |
6501 | ||
6502 | get_syscall_by_number (last.value.syscall_number, &s); | |
6503 | ||
6504 | annotate_catchpoint (b->number); | |
6505 | ||
6506 | if (s.name == NULL) | |
6507 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6508 | else | |
6509 | syscall_id = xstrprintf ("'%s'", s.name); | |
6510 | ||
6511 | old_chain = make_cleanup (xfree, syscall_id); | |
6512 | ||
6513 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6514 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6515 | b->number, syscall_id); | |
6516 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6517 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6518 | b->number, syscall_id); | |
6519 | ||
6520 | do_cleanups (old_chain); | |
6521 | ||
6522 | return PRINT_SRC_AND_LOC; | |
6523 | } | |
6524 | ||
6525 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6526 | catchpoints. */ | |
6527 | ||
6528 | static void | |
6529 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 6530 | struct bp_location **last_loc) |
a96d9b2e | 6531 | { |
be5c67c1 | 6532 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 6533 | struct value_print_options opts; |
79a45e25 | 6534 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
6535 | |
6536 | get_user_print_options (&opts); | |
4a64f543 MS |
6537 | /* Field 4, the address, is omitted (which makes the columns not |
6538 | line up too nicely with the headers, but the effect is relatively | |
6539 | readable). */ | |
a96d9b2e SDJ |
6540 | if (opts.addressprint) |
6541 | ui_out_field_skip (uiout, "addr"); | |
6542 | annotate_field (5); | |
6543 | ||
be5c67c1 PA |
6544 | if (c->syscalls_to_be_caught |
6545 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
6546 | ui_out_text (uiout, "syscalls \""); |
6547 | else | |
6548 | ui_out_text (uiout, "syscall \""); | |
6549 | ||
be5c67c1 | 6550 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6551 | { |
6552 | int i, iter; | |
6553 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6554 | |
a96d9b2e | 6555 | for (i = 0; |
be5c67c1 | 6556 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6557 | i++) |
6558 | { | |
6559 | char *x = text; | |
6560 | struct syscall s; | |
6561 | get_syscall_by_number (iter, &s); | |
6562 | ||
6563 | if (s.name != NULL) | |
6564 | text = xstrprintf ("%s%s, ", text, s.name); | |
6565 | else | |
6566 | text = xstrprintf ("%s%d, ", text, iter); | |
6567 | ||
6568 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 6569 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
6570 | on every call. */ |
6571 | xfree (x); | |
6572 | } | |
6573 | /* Remove the last comma. */ | |
6574 | text[strlen (text) - 2] = '\0'; | |
6575 | ui_out_field_string (uiout, "what", text); | |
6576 | } | |
6577 | else | |
6578 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6579 | ui_out_text (uiout, "\" "); | |
6580 | } | |
6581 | ||
6582 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6583 | catchpoints. */ | |
6584 | ||
6585 | static void | |
6586 | print_mention_catch_syscall (struct breakpoint *b) | |
6587 | { | |
be5c67c1 PA |
6588 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6589 | ||
6590 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
6591 | { |
6592 | int i, iter; | |
6593 | ||
be5c67c1 | 6594 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
6595 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
6596 | else | |
6597 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6598 | ||
6599 | for (i = 0; | |
be5c67c1 | 6600 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6601 | i++) |
6602 | { | |
6603 | struct syscall s; | |
6604 | get_syscall_by_number (iter, &s); | |
6605 | ||
6606 | if (s.name) | |
6607 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6608 | else | |
6609 | printf_filtered (" %d", s.number); | |
6610 | } | |
6611 | printf_filtered (")"); | |
6612 | } | |
6613 | else | |
6614 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6615 | b->number); | |
6616 | } | |
6617 | ||
6149aea9 PA |
6618 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6619 | catchpoints. */ | |
6620 | ||
6621 | static void | |
6622 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6623 | { | |
be5c67c1 PA |
6624 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6625 | ||
6149aea9 PA |
6626 | fprintf_unfiltered (fp, "catch syscall"); |
6627 | ||
be5c67c1 | 6628 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
6629 | { |
6630 | int i, iter; | |
6631 | ||
6632 | for (i = 0; | |
be5c67c1 | 6633 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
6634 | i++) |
6635 | { | |
6636 | struct syscall s; | |
6637 | ||
6638 | get_syscall_by_number (iter, &s); | |
6639 | if (s.name) | |
6640 | fprintf_unfiltered (fp, " %s", s.name); | |
6641 | else | |
6642 | fprintf_unfiltered (fp, " %d", s.number); | |
6643 | } | |
6644 | } | |
d9b3f62e | 6645 | print_recreate_thread (b, fp); |
6149aea9 PA |
6646 | } |
6647 | ||
a96d9b2e SDJ |
6648 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6649 | ||
2060206e | 6650 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
6651 | |
6652 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6653 | ||
6654 | static int | |
6655 | syscall_catchpoint_p (struct breakpoint *b) | |
6656 | { | |
6657 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6658 | } | |
6659 | ||
346774a9 PA |
6660 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
6661 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
6662 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
6663 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 6664 | |
346774a9 PA |
6665 | static void |
6666 | init_catchpoint (struct breakpoint *b, | |
6667 | struct gdbarch *gdbarch, int tempflag, | |
6668 | char *cond_string, | |
c0a91b2b | 6669 | const struct breakpoint_ops *ops) |
c906108c | 6670 | { |
c5aa993b | 6671 | struct symtab_and_line sal; |
346774a9 | 6672 | |
fe39c653 | 6673 | init_sal (&sal); |
6c95b8df | 6674 | sal.pspace = current_program_space; |
c5aa993b | 6675 | |
28010a5d | 6676 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 6677 | |
1b36a34b | 6678 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 6679 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
6680 | } |
6681 | ||
28010a5d | 6682 | void |
3ea46bff | 6683 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
6684 | { |
6685 | add_to_breakpoint_chain (b); | |
3a5c3e22 PA |
6686 | set_breakpoint_number (internal, b); |
6687 | if (!internal) | |
6688 | mention (b); | |
c56053d2 | 6689 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
6690 | |
6691 | if (update_gll) | |
6692 | update_global_location_list (1); | |
c56053d2 PA |
6693 | } |
6694 | ||
9b70b993 | 6695 | static void |
a6d9a66e UW |
6696 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6697 | int tempflag, char *cond_string, | |
c0a91b2b | 6698 | const struct breakpoint_ops *ops) |
c906108c | 6699 | { |
e29a4733 | 6700 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 6701 | |
e29a4733 PA |
6702 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
6703 | ||
6704 | c->forked_inferior_pid = null_ptid; | |
6705 | ||
3ea46bff | 6706 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
6707 | } |
6708 | ||
fe798b75 JB |
6709 | /* Exec catchpoints. */ |
6710 | ||
b4d90040 PA |
6711 | /* An instance of this type is used to represent an exec catchpoint. |
6712 | It includes a "struct breakpoint" as a kind of base class; users | |
6713 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6714 | really of this type iff its ops pointer points to | |
6715 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
6716 | ||
6717 | struct exec_catchpoint | |
6718 | { | |
6719 | /* The base class. */ | |
6720 | struct breakpoint base; | |
6721 | ||
6722 | /* Filename of a program whose exec triggered this catchpoint. | |
6723 | This field is only valid immediately after this catchpoint has | |
6724 | triggered. */ | |
6725 | char *exec_pathname; | |
6726 | }; | |
6727 | ||
6728 | /* Implement the "dtor" breakpoint_ops method for exec | |
6729 | catchpoints. */ | |
6730 | ||
6731 | static void | |
6732 | dtor_catch_exec (struct breakpoint *b) | |
6733 | { | |
6734 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
6735 | ||
6736 | xfree (c->exec_pathname); | |
348d480f | 6737 | |
2060206e | 6738 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
6739 | } |
6740 | ||
77b06cd7 TJB |
6741 | static int |
6742 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6743 | { |
77b06cd7 | 6744 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6745 | } |
c906108c | 6746 | |
fe798b75 | 6747 | static int |
77b06cd7 | 6748 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6749 | { |
6750 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6751 | } | |
c906108c | 6752 | |
fe798b75 | 6753 | static int |
f1310107 TJB |
6754 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
6755 | struct address_space *aspace, CORE_ADDR bp_addr) | |
fe798b75 | 6756 | { |
b4d90040 PA |
6757 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
6758 | ||
6759 | return inferior_has_execd (inferior_ptid, &c->exec_pathname); | |
fe798b75 | 6760 | } |
c906108c | 6761 | |
fe798b75 | 6762 | static enum print_stop_action |
348d480f | 6763 | print_it_catch_exec (bpstat bs) |
fe798b75 | 6764 | { |
348d480f | 6765 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
6766 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
6767 | ||
fe798b75 JB |
6768 | annotate_catchpoint (b->number); |
6769 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
b4d90040 | 6770 | c->exec_pathname); |
fe798b75 | 6771 | return PRINT_SRC_AND_LOC; |
c906108c SS |
6772 | } |
6773 | ||
fe798b75 | 6774 | static void |
a6d9a66e | 6775 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 6776 | { |
b4d90040 | 6777 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 6778 | struct value_print_options opts; |
79a45e25 | 6779 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
6780 | |
6781 | get_user_print_options (&opts); | |
6782 | ||
6783 | /* Field 4, the address, is omitted (which makes the columns | |
6784 | not line up too nicely with the headers, but the effect | |
6785 | is relatively readable). */ | |
6786 | if (opts.addressprint) | |
6787 | ui_out_field_skip (uiout, "addr"); | |
6788 | annotate_field (5); | |
6789 | ui_out_text (uiout, "exec"); | |
b4d90040 | 6790 | if (c->exec_pathname != NULL) |
fe798b75 JB |
6791 | { |
6792 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 6793 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
6794 | ui_out_text (uiout, "\" "); |
6795 | } | |
6796 | } | |
6797 | ||
6798 | static void | |
6799 | print_mention_catch_exec (struct breakpoint *b) | |
6800 | { | |
6801 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6802 | } | |
6803 | ||
6149aea9 PA |
6804 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6805 | catchpoints. */ | |
6806 | ||
6807 | static void | |
6808 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6809 | { | |
6810 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 6811 | print_recreate_thread (b, fp); |
6149aea9 PA |
6812 | } |
6813 | ||
2060206e | 6814 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 6815 | |
a96d9b2e SDJ |
6816 | static void |
6817 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 6818 | const struct breakpoint_ops *ops) |
a96d9b2e | 6819 | { |
be5c67c1 | 6820 | struct syscall_catchpoint *c; |
a96d9b2e | 6821 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 6822 | |
be5c67c1 PA |
6823 | c = XNEW (struct syscall_catchpoint); |
6824 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
6825 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 6826 | |
3ea46bff | 6827 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
6828 | } |
6829 | ||
c906108c | 6830 | static int |
fba45db2 | 6831 | hw_breakpoint_used_count (void) |
c906108c | 6832 | { |
c906108c | 6833 | int i = 0; |
f1310107 TJB |
6834 | struct breakpoint *b; |
6835 | struct bp_location *bl; | |
c906108c SS |
6836 | |
6837 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6838 | { |
d6b74ac4 | 6839 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
6840 | for (bl = b->loc; bl; bl = bl->next) |
6841 | { | |
6842 | /* Special types of hardware breakpoints may use more than | |
6843 | one register. */ | |
348d480f | 6844 | i += b->ops->resources_needed (bl); |
f1310107 | 6845 | } |
c5aa993b | 6846 | } |
c906108c SS |
6847 | |
6848 | return i; | |
6849 | } | |
6850 | ||
a1398e0c PA |
6851 | /* Returns the resources B would use if it were a hardware |
6852 | watchpoint. */ | |
6853 | ||
c906108c | 6854 | static int |
a1398e0c | 6855 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 6856 | { |
c906108c | 6857 | int i = 0; |
e09342b5 | 6858 | struct bp_location *bl; |
c906108c | 6859 | |
a1398e0c PA |
6860 | if (!breakpoint_enabled (b)) |
6861 | return 0; | |
6862 | ||
6863 | for (bl = b->loc; bl; bl = bl->next) | |
6864 | { | |
6865 | /* Special types of hardware watchpoints may use more than | |
6866 | one register. */ | |
6867 | i += b->ops->resources_needed (bl); | |
6868 | } | |
6869 | ||
6870 | return i; | |
6871 | } | |
6872 | ||
6873 | /* Returns the sum the used resources of all hardware watchpoints of | |
6874 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
6875 | the sum of the used resources of all hardware watchpoints of other | |
6876 | types _not_ TYPE. */ | |
6877 | ||
6878 | static int | |
6879 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
6880 | enum bptype type, int *other_type_used) | |
6881 | { | |
6882 | int i = 0; | |
6883 | struct breakpoint *b; | |
6884 | ||
c906108c SS |
6885 | *other_type_used = 0; |
6886 | ALL_BREAKPOINTS (b) | |
e09342b5 | 6887 | { |
a1398e0c PA |
6888 | if (b == except) |
6889 | continue; | |
e09342b5 TJB |
6890 | if (!breakpoint_enabled (b)) |
6891 | continue; | |
6892 | ||
a1398e0c PA |
6893 | if (b->type == type) |
6894 | i += hw_watchpoint_use_count (b); | |
6895 | else if (is_hardware_watchpoint (b)) | |
6896 | *other_type_used = 1; | |
e09342b5 TJB |
6897 | } |
6898 | ||
c906108c SS |
6899 | return i; |
6900 | } | |
6901 | ||
c906108c | 6902 | void |
fba45db2 | 6903 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6904 | { |
c5aa993b | 6905 | struct breakpoint *b; |
c906108c SS |
6906 | |
6907 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6908 | { |
cc60f2e3 | 6909 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6910 | { |
b5de0fa7 | 6911 | b->enable_state = bp_call_disabled; |
b60e7edf | 6912 | update_global_location_list (0); |
c5aa993b JM |
6913 | } |
6914 | } | |
c906108c SS |
6915 | } |
6916 | ||
6917 | void | |
fba45db2 | 6918 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6919 | { |
c5aa993b | 6920 | struct breakpoint *b; |
c906108c SS |
6921 | |
6922 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6923 | { |
cc60f2e3 | 6924 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6925 | { |
b5de0fa7 | 6926 | b->enable_state = bp_enabled; |
b60e7edf | 6927 | update_global_location_list (1); |
c5aa993b JM |
6928 | } |
6929 | } | |
c906108c SS |
6930 | } |
6931 | ||
8bea4e01 UW |
6932 | void |
6933 | disable_breakpoints_before_startup (void) | |
6934 | { | |
6935 | struct breakpoint *b; | |
6936 | int found = 0; | |
6937 | ||
6938 | ALL_BREAKPOINTS (b) | |
6939 | { | |
6c95b8df PA |
6940 | if (b->pspace != current_program_space) |
6941 | continue; | |
6942 | ||
8bea4e01 UW |
6943 | if ((b->type == bp_breakpoint |
6944 | || b->type == bp_hardware_breakpoint) | |
6945 | && breakpoint_enabled (b)) | |
6946 | { | |
6947 | b->enable_state = bp_startup_disabled; | |
6948 | found = 1; | |
6949 | } | |
6950 | } | |
6951 | ||
6952 | if (found) | |
6953 | update_global_location_list (0); | |
6954 | ||
6c95b8df | 6955 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6956 | } |
6957 | ||
6958 | void | |
6959 | enable_breakpoints_after_startup (void) | |
6960 | { | |
6961 | struct breakpoint *b; | |
6962 | int found = 0; | |
6963 | ||
6c95b8df | 6964 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6965 | |
6966 | ALL_BREAKPOINTS (b) | |
6967 | { | |
6c95b8df PA |
6968 | if (b->pspace != current_program_space) |
6969 | continue; | |
6970 | ||
8bea4e01 UW |
6971 | if ((b->type == bp_breakpoint |
6972 | || b->type == bp_hardware_breakpoint) | |
6973 | && b->enable_state == bp_startup_disabled) | |
6974 | { | |
6975 | b->enable_state = bp_enabled; | |
6976 | found = 1; | |
6977 | } | |
6978 | } | |
6979 | ||
6980 | if (found) | |
6981 | breakpoint_re_set (); | |
6982 | } | |
6983 | ||
c906108c SS |
6984 | |
6985 | /* Set a breakpoint that will evaporate an end of command | |
6986 | at address specified by SAL. | |
6987 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6988 | ||
6989 | struct breakpoint * | |
a6d9a66e UW |
6990 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6991 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6992 | { |
52f0bd74 | 6993 | struct breakpoint *b; |
edb3359d DJ |
6994 | |
6995 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6996 | one. */ | |
6997 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6998 | ||
06edf0c0 | 6999 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
7000 | b->enable_state = bp_enabled; |
7001 | b->disposition = disp_donttouch; | |
818dd999 | 7002 | b->frame_id = frame_id; |
c906108c | 7003 | |
4a64f543 MS |
7004 | /* If we're debugging a multi-threaded program, then we want |
7005 | momentary breakpoints to be active in only a single thread of | |
7006 | control. */ | |
39f77062 KB |
7007 | if (in_thread_list (inferior_ptid)) |
7008 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 7009 | |
b60e7edf | 7010 | update_global_location_list_nothrow (1); |
74960c60 | 7011 | |
c906108c SS |
7012 | return b; |
7013 | } | |
611c83ae | 7014 | |
06edf0c0 PA |
7015 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
7016 | The new breakpoint will have type TYPE, and use OPS as it | |
7017 | breakpoint_ops. */ | |
e58b0e63 | 7018 | |
06edf0c0 PA |
7019 | static struct breakpoint * |
7020 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
7021 | enum bptype type, | |
c0a91b2b | 7022 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
7023 | { |
7024 | struct breakpoint *copy; | |
7025 | ||
06edf0c0 | 7026 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 7027 | copy->loc = allocate_bp_location (copy); |
0e30163f | 7028 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 7029 | |
a6d9a66e | 7030 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
7031 | copy->loc->requested_address = orig->loc->requested_address; |
7032 | copy->loc->address = orig->loc->address; | |
7033 | copy->loc->section = orig->loc->section; | |
6c95b8df | 7034 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
7035 | |
7036 | if (orig->source_file == NULL) | |
7037 | copy->source_file = NULL; | |
7038 | else | |
7039 | copy->source_file = xstrdup (orig->source_file); | |
7040 | ||
7041 | copy->line_number = orig->line_number; | |
7042 | copy->frame_id = orig->frame_id; | |
7043 | copy->thread = orig->thread; | |
6c95b8df | 7044 | copy->pspace = orig->pspace; |
e58b0e63 PA |
7045 | |
7046 | copy->enable_state = bp_enabled; | |
7047 | copy->disposition = disp_donttouch; | |
7048 | copy->number = internal_breakpoint_number--; | |
7049 | ||
7050 | update_global_location_list_nothrow (0); | |
7051 | return copy; | |
7052 | } | |
7053 | ||
06edf0c0 PA |
7054 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
7055 | ORIG is NULL. */ | |
7056 | ||
7057 | struct breakpoint * | |
7058 | clone_momentary_breakpoint (struct breakpoint *orig) | |
7059 | { | |
7060 | /* If there's nothing to clone, then return nothing. */ | |
7061 | if (orig == NULL) | |
7062 | return NULL; | |
7063 | ||
7064 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
7065 | } | |
7066 | ||
611c83ae | 7067 | struct breakpoint * |
a6d9a66e UW |
7068 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
7069 | enum bptype type) | |
611c83ae PA |
7070 | { |
7071 | struct symtab_and_line sal; | |
7072 | ||
7073 | sal = find_pc_line (pc, 0); | |
7074 | sal.pc = pc; | |
7075 | sal.section = find_pc_overlay (pc); | |
7076 | sal.explicit_pc = 1; | |
7077 | ||
a6d9a66e | 7078 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 7079 | } |
c906108c | 7080 | \f |
c5aa993b | 7081 | |
c906108c SS |
7082 | /* Tell the user we have just set a breakpoint B. */ |
7083 | ||
7084 | static void | |
fba45db2 | 7085 | mention (struct breakpoint *b) |
c906108c | 7086 | { |
348d480f | 7087 | b->ops->print_mention (b); |
79a45e25 | 7088 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 7089 | return; |
c906108c SS |
7090 | printf_filtered ("\n"); |
7091 | } | |
c906108c | 7092 | \f |
c5aa993b | 7093 | |
0d381245 | 7094 | static struct bp_location * |
39d61571 | 7095 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7096 | const struct symtab_and_line *sal) |
7097 | { | |
7098 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
7099 | CORE_ADDR adjusted_address; |
7100 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
7101 | ||
7102 | if (loc_gdbarch == NULL) | |
7103 | loc_gdbarch = b->gdbarch; | |
7104 | ||
7105 | /* Adjust the breakpoint's address prior to allocating a location. | |
7106 | Once we call allocate_bp_location(), that mostly uninitialized | |
7107 | location will be placed on the location chain. Adjustment of the | |
7108 | breakpoint may cause target_read_memory() to be called and we do | |
7109 | not want its scan of the location chain to find a breakpoint and | |
7110 | location that's only been partially initialized. */ | |
7111 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
7112 | sal->pc, b->type); | |
0d381245 | 7113 | |
39d61571 | 7114 | loc = allocate_bp_location (b); |
0d381245 VP |
7115 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7116 | ; | |
7117 | *tmp = loc; | |
3742cc8b | 7118 | |
0d381245 | 7119 | loc->requested_address = sal->pc; |
3742cc8b | 7120 | loc->address = adjusted_address; |
6c95b8df PA |
7121 | loc->pspace = sal->pspace; |
7122 | gdb_assert (loc->pspace != NULL); | |
0d381245 | 7123 | loc->section = sal->section; |
3742cc8b | 7124 | loc->gdbarch = loc_gdbarch; |
0e30163f JK |
7125 | set_breakpoint_location_function (loc, |
7126 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
7127 | return loc; |
7128 | } | |
514f746b AR |
7129 | \f |
7130 | ||
7131 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7132 | return 0 otherwise. */ | |
7133 | ||
7134 | static int | |
7135 | bp_loc_is_permanent (struct bp_location *loc) | |
7136 | { | |
7137 | int len; | |
7138 | CORE_ADDR addr; | |
7139 | const gdb_byte *brk; | |
7140 | gdb_byte *target_mem; | |
939c61fa JK |
7141 | struct cleanup *cleanup; |
7142 | int retval = 0; | |
514f746b AR |
7143 | |
7144 | gdb_assert (loc != NULL); | |
7145 | ||
7146 | addr = loc->address; | |
a6d9a66e | 7147 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7148 | |
939c61fa JK |
7149 | /* Software breakpoints unsupported? */ |
7150 | if (brk == NULL) | |
7151 | return 0; | |
7152 | ||
514f746b AR |
7153 | target_mem = alloca (len); |
7154 | ||
939c61fa JK |
7155 | /* Enable the automatic memory restoration from breakpoints while |
7156 | we read the memory. Otherwise we could say about our temporary | |
7157 | breakpoints they are permanent. */ | |
6c95b8df PA |
7158 | cleanup = save_current_space_and_thread (); |
7159 | ||
7160 | switch_to_program_space_and_thread (loc->pspace); | |
7161 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7162 | |
514f746b AR |
7163 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7164 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7165 | retval = 1; |
514f746b | 7166 | |
939c61fa JK |
7167 | do_cleanups (cleanup); |
7168 | ||
7169 | return retval; | |
514f746b AR |
7170 | } |
7171 | ||
7172 | ||
c3f6f71d | 7173 | |
018d34a4 VP |
7174 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7175 | as textual description of the location, and COND_STRING | |
db107f19 | 7176 | as condition expression. */ |
018d34a4 VP |
7177 | |
7178 | static void | |
d9b3f62e PA |
7179 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
7180 | struct symtabs_and_lines sals, char *addr_string, | |
7181 | char *cond_string, | |
7182 | enum bptype type, enum bpdisp disposition, | |
7183 | int thread, int task, int ignore_count, | |
c0a91b2b | 7184 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e | 7185 | int enabled, int internal, int display_canonical) |
018d34a4 | 7186 | { |
0d381245 | 7187 | int i; |
018d34a4 VP |
7188 | |
7189 | if (type == bp_hardware_breakpoint) | |
7190 | { | |
7191 | int i = hw_breakpoint_used_count (); | |
7192 | int target_resources_ok = | |
d92524f1 | 7193 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
7194 | i + 1, 0); |
7195 | if (target_resources_ok == 0) | |
7196 | error (_("No hardware breakpoint support in the target.")); | |
7197 | else if (target_resources_ok < 0) | |
7198 | error (_("Hardware breakpoints used exceeds limit.")); | |
7199 | } | |
7200 | ||
6c95b8df PA |
7201 | gdb_assert (sals.nelts > 0); |
7202 | ||
0d381245 VP |
7203 | for (i = 0; i < sals.nelts; ++i) |
7204 | { | |
7205 | struct symtab_and_line sal = sals.sals[i]; | |
7206 | struct bp_location *loc; | |
7207 | ||
7208 | if (from_tty) | |
5af949e3 UW |
7209 | { |
7210 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7211 | if (!loc_gdbarch) | |
7212 | loc_gdbarch = gdbarch; | |
7213 | ||
7214 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7215 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7216 | } |
0d381245 VP |
7217 | |
7218 | if (i == 0) | |
7219 | { | |
d9b3f62e | 7220 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 7221 | b->thread = thread; |
4a306c9a | 7222 | b->task = task; |
018d34a4 | 7223 | |
0d381245 VP |
7224 | b->cond_string = cond_string; |
7225 | b->ignore_count = ignore_count; | |
41447f92 | 7226 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7227 | b->disposition = disposition; |
6c95b8df PA |
7228 | b->pspace = sals.sals[0].pspace; |
7229 | ||
0fb4aa4b PA |
7230 | if (type == bp_static_tracepoint) |
7231 | { | |
d9b3f62e | 7232 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
7233 | struct static_tracepoint_marker marker; |
7234 | ||
7235 | if (is_marker_spec (addr_string)) | |
7236 | { | |
7237 | /* We already know the marker exists, otherwise, we | |
7238 | wouldn't see a sal for it. */ | |
7239 | char *p = &addr_string[3]; | |
7240 | char *endp; | |
7241 | char *marker_str; | |
7242 | int i; | |
7243 | ||
e9cafbcc | 7244 | p = skip_spaces (p); |
0fb4aa4b | 7245 | |
e9cafbcc | 7246 | endp = skip_to_space (p); |
0fb4aa4b PA |
7247 | |
7248 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 7249 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 7250 | |
3e43a32a MS |
7251 | printf_filtered (_("Probed static tracepoint " |
7252 | "marker \"%s\"\n"), | |
d9b3f62e | 7253 | t->static_trace_marker_id); |
0fb4aa4b PA |
7254 | } |
7255 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7256 | { | |
d9b3f62e | 7257 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
7258 | release_static_tracepoint_marker (&marker); |
7259 | ||
3e43a32a MS |
7260 | printf_filtered (_("Probed static tracepoint " |
7261 | "marker \"%s\"\n"), | |
d9b3f62e | 7262 | t->static_trace_marker_id); |
0fb4aa4b PA |
7263 | } |
7264 | else | |
3e43a32a MS |
7265 | warning (_("Couldn't determine the static " |
7266 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7267 | } |
7268 | ||
6c95b8df | 7269 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7270 | && (b->type == bp_breakpoint |
7271 | || b->type == bp_hardware_breakpoint)) | |
7272 | b->enable_state = bp_startup_disabled; | |
7273 | ||
0d381245 VP |
7274 | loc = b->loc; |
7275 | } | |
7276 | else | |
018d34a4 | 7277 | { |
39d61571 | 7278 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7279 | } |
7280 | ||
514f746b AR |
7281 | if (bp_loc_is_permanent (loc)) |
7282 | make_breakpoint_permanent (b); | |
7283 | ||
0d381245 VP |
7284 | if (b->cond_string) |
7285 | { | |
7286 | char *arg = b->cond_string; | |
d32a6982 | 7287 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7288 | if (*arg) |
db107f19 | 7289 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7290 | } |
0d381245 | 7291 | } |
018d34a4 | 7292 | |
56435ebe | 7293 | b->display_canonical = display_canonical; |
018d34a4 VP |
7294 | if (addr_string) |
7295 | b->addr_string = addr_string; | |
7296 | else | |
7297 | /* addr_string has to be used or breakpoint_re_set will delete | |
7298 | me. */ | |
5af949e3 UW |
7299 | b->addr_string |
7300 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
d9b3f62e | 7301 | } |
018d34a4 | 7302 | |
d9b3f62e PA |
7303 | static void |
7304 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
7305 | struct symtabs_and_lines sals, char *addr_string, | |
7306 | char *cond_string, | |
7307 | enum bptype type, enum bpdisp disposition, | |
7308 | int thread, int task, int ignore_count, | |
c0a91b2b | 7309 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e PA |
7310 | int enabled, int internal, int display_canonical) |
7311 | { | |
7312 | struct breakpoint *b; | |
7313 | struct cleanup *old_chain; | |
7314 | ||
7315 | if (is_tracepoint_type (type)) | |
7316 | { | |
7317 | struct tracepoint *t; | |
7318 | ||
7319 | t = XCNEW (struct tracepoint); | |
7320 | b = &t->base; | |
7321 | } | |
7322 | else | |
7323 | b = XNEW (struct breakpoint); | |
7324 | ||
7325 | old_chain = make_cleanup (xfree, b); | |
7326 | ||
7327 | init_breakpoint_sal (b, gdbarch, | |
7328 | sals, addr_string, | |
7329 | cond_string, | |
7330 | type, disposition, | |
7331 | thread, task, ignore_count, | |
7332 | ops, from_tty, | |
7333 | enabled, internal, display_canonical); | |
7334 | discard_cleanups (old_chain); | |
7335 | ||
3ea46bff | 7336 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
7337 | } |
7338 | ||
ed0616c6 VP |
7339 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7340 | elements to fill the void space. */ | |
2c0b251b PA |
7341 | static void |
7342 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7343 | { |
7344 | int i = index_to_remove+1; | |
7345 | int last_index = sal->nelts-1; | |
7346 | ||
7347 | for (;i <= last_index; ++i) | |
7348 | sal->sals[i-1] = sal->sals[i]; | |
7349 | ||
7350 | --(sal->nelts); | |
7351 | } | |
7352 | ||
6c95b8df PA |
7353 | /* If appropriate, obtains all sals that correspond to the same file |
7354 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7355 | will want to set a breakpoint at foo.c:line, and not really care | |
7356 | about program spaces. This is done only if SAL does not have | |
7357 | explicit PC and has line and file information. If we got just a | |
7358 | single expanded sal, return the original. | |
ed0616c6 | 7359 | |
6c95b8df PA |
7360 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7361 | which the name of enclosing function is different from SAL. This | |
7362 | makes sure that if we have breakpoint originally set in template | |
7363 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7364 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7365 | |
2c0b251b | 7366 | static struct symtabs_and_lines |
ed0616c6 VP |
7367 | expand_line_sal_maybe (struct symtab_and_line sal) |
7368 | { | |
7369 | struct symtabs_and_lines expanded; | |
7370 | CORE_ADDR original_pc = sal.pc; | |
7371 | char *original_function = NULL; | |
7372 | int found; | |
7373 | int i; | |
6c95b8df | 7374 | struct cleanup *old_chain; |
ed0616c6 VP |
7375 | |
7376 | /* If we have explicit pc, don't expand. | |
7377 | If we have no line number, we can't expand. */ | |
7378 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7379 | { | |
7380 | expanded.nelts = 1; | |
7381 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7382 | expanded.sals[0] = sal; | |
7383 | return expanded; | |
7384 | } | |
7385 | ||
7386 | sal.pc = 0; | |
6c95b8df PA |
7387 | |
7388 | old_chain = save_current_space_and_thread (); | |
7389 | ||
7390 | switch_to_program_space_and_thread (sal.pspace); | |
7391 | ||
ed0616c6 | 7392 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7393 | |
7394 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7395 | expanded = expand_line_sal (sal); |
6c95b8df | 7396 | |
ed0616c6 VP |
7397 | if (expanded.nelts == 1) |
7398 | { | |
3dba1c98 JB |
7399 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7400 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7401 | xfree (expanded.sals); |
7402 | expanded.nelts = 1; | |
7403 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7404 | sal.pc = original_pc; | |
7405 | expanded.sals[0] = sal; | |
3dba1c98 | 7406 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7407 | do_cleanups (old_chain); |
ed0616c6 VP |
7408 | return expanded; |
7409 | } | |
7410 | ||
7411 | if (!sal.explicit_line) | |
7412 | { | |
7413 | CORE_ADDR func_addr, func_end; | |
7414 | for (i = 0; i < expanded.nelts; ++i) | |
7415 | { | |
7416 | CORE_ADDR pc = expanded.sals[i].pc; | |
7417 | char *this_function; | |
6c95b8df PA |
7418 | |
7419 | /* We need to switch threads as well since we're about to | |
7420 | read memory. */ | |
7421 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7422 | ||
ed0616c6 VP |
7423 | if (find_pc_partial_function (pc, &this_function, |
7424 | &func_addr, &func_end)) | |
7425 | { | |
059fb39f PM |
7426 | if (this_function |
7427 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7428 | { |
7429 | remove_sal (&expanded, i); | |
7430 | --i; | |
7431 | } | |
ed0616c6 VP |
7432 | } |
7433 | } | |
7434 | } | |
059acae7 UW |
7435 | |
7436 | /* Skip the function prologue if necessary. */ | |
7437 | for (i = 0; i < expanded.nelts; ++i) | |
7438 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7439 | |
6c95b8df PA |
7440 | do_cleanups (old_chain); |
7441 | ||
ed0616c6 VP |
7442 | if (expanded.nelts <= 1) |
7443 | { | |
e5dd4106 | 7444 | /* This is an ugly workaround. If we get zero expanded sals |
4a64f543 MS |
7445 | then something is really wrong. Fix that by returning the |
7446 | original sal. */ | |
7447 | ||
ed0616c6 VP |
7448 | xfree (expanded.sals); |
7449 | expanded.nelts = 1; | |
7450 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7451 | sal.pc = original_pc; | |
7452 | expanded.sals[0] = sal; | |
7453 | return expanded; | |
7454 | } | |
7455 | ||
7456 | if (original_pc) | |
7457 | { | |
7458 | found = 0; | |
7459 | for (i = 0; i < expanded.nelts; ++i) | |
7460 | if (expanded.sals[i].pc == original_pc) | |
7461 | { | |
7462 | found = 1; | |
7463 | break; | |
7464 | } | |
7465 | gdb_assert (found); | |
7466 | } | |
7467 | ||
7468 | return expanded; | |
7469 | } | |
7470 | ||
018d34a4 VP |
7471 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7472 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7473 | value. COND_STRING, if not NULL, specified the condition to be | |
7474 | used for all breakpoints. Essentially the only case where | |
7475 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7476 | function. In that case, it's still not possible to specify | |
7477 | separate conditions for different overloaded functions, so | |
7478 | we take just a single condition string. | |
7479 | ||
c3f6f71d | 7480 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7481 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7482 | array contents). If the function fails (error() is called), the |
7483 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7484 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7485 | |
7486 | static void | |
8cdf0e15 | 7487 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 TT |
7488 | struct symtabs_and_lines sals, |
7489 | struct linespec_result *canonical, | |
8cdf0e15 VP |
7490 | char *cond_string, |
7491 | enum bptype type, enum bpdisp disposition, | |
7492 | int thread, int task, int ignore_count, | |
c0a91b2b | 7493 | const struct breakpoint_ops *ops, int from_tty, |
84f4c1fe | 7494 | int enabled, int internal) |
c906108c | 7495 | { |
018d34a4 | 7496 | int i; |
cc59ec59 | 7497 | |
018d34a4 | 7498 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7499 | { |
ed0616c6 VP |
7500 | struct symtabs_and_lines expanded = |
7501 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7502 | |
7efd8fc2 | 7503 | create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i], |
8cdf0e15 | 7504 | cond_string, type, disposition, |
84f4c1fe | 7505 | thread, task, ignore_count, ops, |
56435ebe TT |
7506 | from_tty, enabled, internal, |
7507 | canonical->special_display); | |
c3f6f71d | 7508 | } |
c3f6f71d | 7509 | } |
c906108c | 7510 | |
9998af43 | 7511 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7512 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7513 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7514 | address strings. ADDRESS points to the end of the SAL. |
7515 | ||
7516 | The array and the line spec strings are allocated on the heap, it is | |
7517 | the caller's responsibility to free them. */ | |
c906108c | 7518 | |
b9362cc7 | 7519 | static void |
c3f6f71d JM |
7520 | parse_breakpoint_sals (char **address, |
7521 | struct symtabs_and_lines *sals, | |
58438ac1 | 7522 | struct linespec_result *canonical) |
c3f6f71d JM |
7523 | { |
7524 | char *addr_start = *address; | |
cc59ec59 | 7525 | |
c3f6f71d | 7526 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 7527 | breakpoint. */ |
c3f6f71d JM |
7528 | if ((*address) == NULL |
7529 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 7530 | { |
1bfeeb0f JL |
7531 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
7532 | address. */ | |
7533 | if (last_displayed_sal_is_valid ()) | |
c906108c | 7534 | { |
c3f6f71d | 7535 | struct symtab_and_line sal; |
cc59ec59 | 7536 | |
4a64f543 | 7537 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7538 | sals->sals = (struct symtab_and_line *) |
c906108c | 7539 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
7540 | |
7541 | /* Set sal's pspace, pc, symtab, and line to the values | |
7542 | corresponding to the last call to print_frame_info. */ | |
7543 | get_last_displayed_sal (&sal); | |
7544 | sal.section = find_pc_overlay (sal.pc); | |
00903456 | 7545 | |
4a64f543 | 7546 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
7547 | where PC is the last displayed codepoint's address. So |
7548 | make sure to set sal.explicit_pc to prevent GDB from | |
7549 | trying to expand the list of sals to include all other | |
7550 | instances with the same symtab and line. */ | |
00903456 JK |
7551 | sal.explicit_pc = 1; |
7552 | ||
c3f6f71d JM |
7553 | sals->sals[0] = sal; |
7554 | sals->nelts = 1; | |
c906108c SS |
7555 | } |
7556 | else | |
8a3fe4f8 | 7557 | error (_("No default breakpoint address now.")); |
c906108c SS |
7558 | } |
7559 | else | |
7560 | { | |
c906108c | 7561 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7562 | current_source_symtab (which is decode_line_1's default). |
7563 | This should produce the results we want almost all of the | |
1bfeeb0f JL |
7564 | time while leaving the last displayed codepoint pointers |
7565 | alone. | |
4a64f543 | 7566 | |
1aeae86e AF |
7567 | ObjC: However, don't match an Objective-C method name which |
7568 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7569 | |
c214a6fd | 7570 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7571 | |
1bfeeb0f | 7572 | if (last_displayed_sal_is_valid () |
0378c332 | 7573 | && (!cursal.symtab |
1aeae86e AF |
7574 | || ((strchr ("+-", (*address)[0]) != NULL) |
7575 | && ((*address)[1] != '[')))) | |
1bfeeb0f JL |
7576 | *sals = decode_line_1 (address, 1, |
7577 | get_last_displayed_symtab (), | |
7578 | get_last_displayed_line (), | |
7579 | canonical); | |
c906108c | 7580 | else |
0101ce28 | 7581 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
58438ac1 | 7582 | canonical); |
c906108c | 7583 | } |
4a64f543 | 7584 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7efd8fc2 | 7585 | if (sals->nelts > 0 && canonical->canonical == NULL) |
38a714bb | 7586 | canonical->canonical = xcalloc (sals->nelts, sizeof (char *)); |
c3f6f71d | 7587 | if (addr_start != (*address)) |
c906108c | 7588 | { |
c3f6f71d | 7589 | int i; |
cc59ec59 | 7590 | |
c3f6f71d | 7591 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7592 | { |
4a64f543 | 7593 | /* Add the string if not present. */ |
7efd8fc2 TT |
7594 | if (canonical->canonical[i] == NULL) |
7595 | canonical->canonical[i] = savestring (addr_start, | |
7596 | (*address) - addr_start); | |
c906108c SS |
7597 | } |
7598 | } | |
c3f6f71d | 7599 | } |
c906108c | 7600 | |
c906108c | 7601 | |
c3f6f71d | 7602 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7603 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7604 | |
b9362cc7 | 7605 | static void |
23e7acfb | 7606 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7607 | { |
7608 | int i; | |
cc59ec59 | 7609 | |
c3f6f71d | 7610 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7611 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7612 | } |
7613 | ||
7a697b8d SS |
7614 | /* Fast tracepoints may have restrictions on valid locations. For |
7615 | instance, a fast tracepoint using a jump instead of a trap will | |
7616 | likely have to overwrite more bytes than a trap would, and so can | |
7617 | only be placed where the instruction is longer than the jump, or a | |
7618 | multi-instruction sequence does not have a jump into the middle of | |
7619 | it, etc. */ | |
7620 | ||
7621 | static void | |
7622 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7623 | struct symtabs_and_lines *sals) | |
7624 | { | |
7625 | int i, rslt; | |
7626 | struct symtab_and_line *sal; | |
7627 | char *msg; | |
7628 | struct cleanup *old_chain; | |
7629 | ||
7630 | for (i = 0; i < sals->nelts; i++) | |
7631 | { | |
7632 | sal = &sals->sals[i]; | |
7633 | ||
7634 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7635 | NULL, &msg); | |
7636 | old_chain = make_cleanup (xfree, msg); | |
7637 | ||
7638 | if (!rslt) | |
7639 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7640 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7641 | ||
7642 | do_cleanups (old_chain); | |
7643 | } | |
7644 | } | |
7645 | ||
018d34a4 VP |
7646 | /* Given TOK, a string specification of condition and thread, as |
7647 | accepted by the 'break' command, extract the condition | |
7648 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7649 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7650 | If no condition is found, *COND_STRING is set to NULL. |
7651 | If no thread is found, *THREAD is set to -1. */ | |
7652 | static void | |
7653 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7654 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7655 | { |
7656 | *cond_string = NULL; | |
7657 | *thread = -1; | |
7658 | while (tok && *tok) | |
7659 | { | |
7660 | char *end_tok; | |
7661 | int toklen; | |
7662 | char *cond_start = NULL; | |
7663 | char *cond_end = NULL; | |
cc59ec59 | 7664 | |
e9cafbcc | 7665 | tok = skip_spaces (tok); |
018d34a4 | 7666 | |
e9cafbcc | 7667 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7668 | |
7669 | toklen = end_tok - tok; | |
7670 | ||
7671 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7672 | { | |
f7545552 TT |
7673 | struct expression *expr; |
7674 | ||
018d34a4 | 7675 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7676 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7677 | xfree (expr); | |
018d34a4 VP |
7678 | cond_end = tok; |
7679 | *cond_string = savestring (cond_start, | |
7680 | cond_end - cond_start); | |
7681 | } | |
7682 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7683 | { | |
7684 | char *tmptok; | |
7685 | ||
7686 | tok = end_tok + 1; | |
7687 | tmptok = tok; | |
7688 | *thread = strtol (tok, &tok, 0); | |
7689 | if (tok == tmptok) | |
7690 | error (_("Junk after thread keyword.")); | |
7691 | if (!valid_thread_id (*thread)) | |
7692 | error (_("Unknown thread %d."), *thread); | |
7693 | } | |
4a306c9a JB |
7694 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7695 | { | |
7696 | char *tmptok; | |
7697 | ||
7698 | tok = end_tok + 1; | |
7699 | tmptok = tok; | |
7700 | *task = strtol (tok, &tok, 0); | |
7701 | if (tok == tmptok) | |
7702 | error (_("Junk after task keyword.")); | |
7703 | if (!valid_task_id (*task)) | |
b6199126 | 7704 | error (_("Unknown task %d."), *task); |
4a306c9a | 7705 | } |
018d34a4 VP |
7706 | else |
7707 | error (_("Junk at end of arguments.")); | |
7708 | } | |
7709 | } | |
7710 | ||
0fb4aa4b PA |
7711 | /* Decode a static tracepoint marker spec. */ |
7712 | ||
7713 | static struct symtabs_and_lines | |
7714 | decode_static_tracepoint_spec (char **arg_p) | |
7715 | { | |
7716 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7717 | struct symtabs_and_lines sals; | |
7718 | struct symtab_and_line sal; | |
7719 | struct symbol *sym; | |
7720 | struct cleanup *old_chain; | |
7721 | char *p = &(*arg_p)[3]; | |
7722 | char *endp; | |
7723 | char *marker_str; | |
7724 | int i; | |
7725 | ||
e9cafbcc | 7726 | p = skip_spaces (p); |
0fb4aa4b | 7727 | |
e9cafbcc | 7728 | endp = skip_to_space (p); |
0fb4aa4b PA |
7729 | |
7730 | marker_str = savestring (p, endp - p); | |
7731 | old_chain = make_cleanup (xfree, marker_str); | |
7732 | ||
7733 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7734 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7735 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7736 | ||
7737 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7738 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7739 | ||
7740 | for (i = 0; i < sals.nelts; i++) | |
7741 | { | |
7742 | struct static_tracepoint_marker *marker; | |
7743 | ||
7744 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7745 | ||
7746 | init_sal (&sals.sals[i]); | |
7747 | ||
7748 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7749 | sals.sals[i].pc = marker->address; | |
7750 | ||
7751 | release_static_tracepoint_marker (marker); | |
7752 | } | |
7753 | ||
7754 | do_cleanups (old_chain); | |
7755 | ||
7756 | *arg_p = endp; | |
7757 | return sals; | |
7758 | } | |
7759 | ||
fd9b8c24 PA |
7760 | /* Set a breakpoint. This function is shared between CLI and MI |
7761 | functions for setting a breakpoint. This function has two major | |
7762 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7763 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7764 | breakpoint location, address and thread. Otherwise, ARG is just |
7765 | the location of breakpoint, with condition and thread specified by | |
7766 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7767 | the breakpoint number will be allocated from the internal | |
7768 | breakpoint count. Returns true if any breakpoint was created; | |
7769 | false otherwise. */ | |
0101ce28 | 7770 | |
8cdf0e15 VP |
7771 | int |
7772 | create_breakpoint (struct gdbarch *gdbarch, | |
7773 | char *arg, char *cond_string, int thread, | |
7774 | int parse_condition_and_thread, | |
0fb4aa4b | 7775 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7776 | int ignore_count, |
7777 | enum auto_boolean pending_break_support, | |
c0a91b2b | 7778 | const struct breakpoint_ops *ops, |
84f4c1fe | 7779 | int from_tty, int enabled, int internal) |
c3f6f71d | 7780 | { |
b78a6381 | 7781 | volatile struct gdb_exception e; |
c3f6f71d | 7782 | struct symtabs_and_lines sals; |
0101ce28 | 7783 | struct symtab_and_line pending_sal; |
0101ce28 | 7784 | char *copy_arg; |
c3f6f71d | 7785 | char *addr_start = arg; |
7efd8fc2 | 7786 | struct linespec_result canonical; |
c3f6f71d | 7787 | struct cleanup *old_chain; |
80c99de1 | 7788 | struct cleanup *bkpt_chain = NULL; |
05ff989b | 7789 | int i; |
0101ce28 | 7790 | int pending = 0; |
4a306c9a | 7791 | int task = 0; |
86b17b60 | 7792 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7793 | |
348d480f PA |
7794 | gdb_assert (ops != NULL); |
7795 | ||
c3f6f71d JM |
7796 | sals.sals = NULL; |
7797 | sals.nelts = 0; | |
7efd8fc2 | 7798 | init_linespec_result (&canonical); |
c3f6f71d | 7799 | |
0fb4aa4b PA |
7800 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7801 | { | |
7802 | int i; | |
7803 | ||
7804 | sals = decode_static_tracepoint_spec (&arg); | |
7805 | ||
7806 | copy_arg = savestring (addr_start, arg - addr_start); | |
38a714bb | 7807 | canonical.canonical = xcalloc (sals.nelts, sizeof (char *)); |
0fb4aa4b | 7808 | for (i = 0; i < sals.nelts; i++) |
7efd8fc2 | 7809 | canonical.canonical[i] = xstrdup (copy_arg); |
0fb4aa4b PA |
7810 | goto done; |
7811 | } | |
7812 | ||
b78a6381 TT |
7813 | TRY_CATCH (e, RETURN_MASK_ALL) |
7814 | { | |
58438ac1 | 7815 | parse_breakpoint_sals (&arg, &sals, &canonical); |
b78a6381 | 7816 | } |
0101ce28 JJ |
7817 | |
7818 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7819 | switch (e.reason) |
0101ce28 | 7820 | { |
05ff989b | 7821 | case RETURN_QUIT: |
98deb0da | 7822 | throw_exception (e); |
05ff989b AC |
7823 | case RETURN_ERROR: |
7824 | switch (e.error) | |
0101ce28 | 7825 | { |
05ff989b | 7826 | case NOT_FOUND_ERROR: |
0101ce28 | 7827 | |
05ff989b AC |
7828 | /* If pending breakpoint support is turned off, throw |
7829 | error. */ | |
fa8d40ab JJ |
7830 | |
7831 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7832 | throw_exception (e); |
7833 | ||
7834 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7835 | |
05ff989b AC |
7836 | /* If pending breakpoint support is auto query and the user |
7837 | selects no, then simply return the error code. */ | |
059fb39f | 7838 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
7839 | && !nquery (_("Make %s pending on future shared library load? "), |
7840 | bptype_string (type_wanted))) | |
fd9b8c24 | 7841 | return 0; |
fa8d40ab | 7842 | |
05ff989b AC |
7843 | /* At this point, either the user was queried about setting |
7844 | a pending breakpoint and selected yes, or pending | |
7845 | breakpoint behavior is on and thus a pending breakpoint | |
7846 | is defaulted on behalf of the user. */ | |
0101ce28 | 7847 | copy_arg = xstrdup (addr_start); |
7efd8fc2 | 7848 | canonical.canonical = ©_arg; |
0101ce28 JJ |
7849 | sals.nelts = 1; |
7850 | sals.sals = &pending_sal; | |
7851 | pending_sal.pc = 0; | |
7852 | pending = 1; | |
05ff989b AC |
7853 | break; |
7854 | default: | |
98deb0da | 7855 | throw_exception (e); |
0101ce28 | 7856 | } |
2abae994 | 7857 | break; |
05ff989b AC |
7858 | default: |
7859 | if (!sals.nelts) | |
fd9b8c24 | 7860 | return 0; |
0101ce28 | 7861 | } |
c3f6f71d | 7862 | |
0fb4aa4b PA |
7863 | done: |
7864 | ||
4a64f543 | 7865 | /* Create a chain of things that always need to be cleaned up. */ |
c3f6f71d JM |
7866 | old_chain = make_cleanup (null_cleanup, 0); |
7867 | ||
0101ce28 JJ |
7868 | if (!pending) |
7869 | { | |
7870 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7871 | make_cleanup (xfree, sals.sals); | |
7872 | ||
7efd8fc2 TT |
7873 | /* Cleanup the canonical array but not its contents. */ |
7874 | make_cleanup (xfree, canonical.canonical); | |
0101ce28 | 7875 | } |
c3f6f71d | 7876 | |
c3f6f71d JM |
7877 | /* ----------------------------- SNIP ----------------------------- |
7878 | Anything added to the cleanup chain beyond this point is assumed | |
7879 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7880 | then the memory is not reclaimed. */ |
7881 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 7882 | |
7efd8fc2 | 7883 | /* Mark the contents of the canonical for cleanup. These go on |
80c99de1 | 7884 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7885 | for (i = 0; i < sals.nelts; i++) |
7886 | { | |
7efd8fc2 TT |
7887 | if (canonical.canonical[i] != NULL) |
7888 | make_cleanup (xfree, canonical.canonical[i]); | |
c3f6f71d JM |
7889 | } |
7890 | ||
7891 | /* Resolve all line numbers to PC's and verify that the addresses | |
7892 | are ok for the target. */ | |
0101ce28 | 7893 | if (!pending) |
23e7acfb | 7894 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 7895 | |
7a697b8d | 7896 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 7897 | if (!pending && type_wanted == bp_fast_tracepoint) |
7a697b8d SS |
7898 | check_fast_tracepoint_sals (gdbarch, &sals); |
7899 | ||
c3f6f71d JM |
7900 | /* Verify that condition can be parsed, before setting any |
7901 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 7902 | breakpoint. */ |
0101ce28 | 7903 | if (!pending) |
c3f6f71d | 7904 | { |
2f069f6f | 7905 | if (parse_condition_and_thread) |
72b2ff0e VP |
7906 | { |
7907 | /* Here we only parse 'arg' to separate condition | |
7908 | from thread number, so parsing in context of first | |
7909 | sal is OK. When setting the breakpoint we'll | |
7910 | re-parse it in context of each sal. */ | |
7911 | cond_string = NULL; | |
7912 | thread = -1; | |
4a306c9a JB |
7913 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7914 | &thread, &task); | |
72b2ff0e VP |
7915 | if (cond_string) |
7916 | make_cleanup (xfree, cond_string); | |
7917 | } | |
2f069f6f | 7918 | else |
72b2ff0e VP |
7919 | { |
7920 | /* Create a private copy of condition string. */ | |
7921 | if (cond_string) | |
7922 | { | |
7923 | cond_string = xstrdup (cond_string); | |
7924 | make_cleanup (xfree, cond_string); | |
7925 | } | |
7926 | } | |
0fb4aa4b PA |
7927 | |
7928 | /* If the user is creating a static tracepoint by marker id | |
7929 | (strace -m MARKER_ID), then store the sals index, so that | |
7930 | breakpoint_re_set can try to match up which of the newly | |
7931 | found markers corresponds to this one, and, don't try to | |
7932 | expand multiple locations for each sal, given than SALS | |
7933 | already should contain all sals for MARKER_ID. */ | |
7934 | if (type_wanted == bp_static_tracepoint | |
7efd8fc2 | 7935 | && is_marker_spec (canonical.canonical[0])) |
0fb4aa4b PA |
7936 | { |
7937 | int i; | |
7938 | ||
7939 | for (i = 0; i < sals.nelts; ++i) | |
7940 | { | |
7941 | struct symtabs_and_lines expanded; | |
d9b3f62e | 7942 | struct tracepoint *tp; |
0fb4aa4b PA |
7943 | struct cleanup *old_chain; |
7944 | ||
7945 | expanded.nelts = 1; | |
7946 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7947 | expanded.sals[0] = sals.sals[i]; | |
7948 | old_chain = make_cleanup (xfree, expanded.sals); | |
7949 | ||
d9b3f62e PA |
7950 | tp = XCNEW (struct tracepoint); |
7951 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
7952 | canonical.canonical[i], | |
7953 | cond_string, type_wanted, | |
7954 | tempflag ? disp_del : disp_donttouch, | |
7955 | thread, task, ignore_count, ops, | |
7956 | from_tty, enabled, internal, | |
7957 | canonical.special_display); | |
0fb4aa4b PA |
7958 | /* Given that its possible to have multiple markers with |
7959 | the same string id, if the user is creating a static | |
7960 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
7961 | store the sals index, so that breakpoint_re_set can | |
7962 | try to match up which of the newly found markers | |
7963 | corresponds to this one */ | |
7964 | tp->static_trace_marker_id_idx = i; | |
d9b3f62e | 7965 | |
3ea46bff | 7966 | install_breakpoint (internal, &tp->base, 0); |
d9b3f62e PA |
7967 | |
7968 | do_cleanups (old_chain); | |
0fb4aa4b PA |
7969 | } |
7970 | } | |
7971 | else | |
7efd8fc2 | 7972 | create_breakpoints_sal (gdbarch, sals, &canonical, cond_string, |
3e43a32a MS |
7973 | type_wanted, |
7974 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 7975 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 7976 | enabled, internal); |
c906108c | 7977 | } |
0101ce28 JJ |
7978 | else |
7979 | { | |
0101ce28 JJ |
7980 | struct breakpoint *b; |
7981 | ||
0101ce28 JJ |
7982 | make_cleanup (xfree, copy_arg); |
7983 | ||
bfccc43c YQ |
7984 | if (is_tracepoint_type (type_wanted)) |
7985 | { | |
7986 | struct tracepoint *t; | |
7987 | ||
7988 | t = XCNEW (struct tracepoint); | |
7989 | b = &t->base; | |
7990 | } | |
7991 | else | |
7992 | b = XNEW (struct breakpoint); | |
7993 | ||
7994 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
7995 | ||
7efd8fc2 | 7996 | b->addr_string = canonical.canonical[0]; |
72b2ff0e | 7997 | b->cond_string = NULL; |
0101ce28 | 7998 | b->ignore_count = ignore_count; |
0101ce28 | 7999 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 8000 | b->condition_not_parsed = 1; |
41447f92 | 8001 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 8002 | b->pspace = current_program_space; |
74960c60 | 8003 | |
6c95b8df | 8004 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
8005 | && (b->type == bp_breakpoint |
8006 | || b->type == bp_hardware_breakpoint)) | |
8007 | b->enable_state = bp_startup_disabled; | |
8008 | ||
bfccc43c | 8009 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
8010 | } |
8011 | ||
c3f6f71d | 8012 | if (sals.nelts > 1) |
95a42b64 | 8013 | { |
3e43a32a MS |
8014 | warning (_("Multiple breakpoints were set.\nUse the " |
8015 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 8016 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
8017 | } |
8018 | ||
80c99de1 PA |
8019 | /* That's it. Discard the cleanups for data inserted into the |
8020 | breakpoint. */ | |
8021 | discard_cleanups (bkpt_chain); | |
8022 | /* But cleanup everything else. */ | |
c3f6f71d | 8023 | do_cleanups (old_chain); |
217dc9e2 | 8024 | |
80c99de1 | 8025 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 8026 | update_global_location_list (1); |
fd9b8c24 PA |
8027 | |
8028 | return 1; | |
c3f6f71d | 8029 | } |
c906108c | 8030 | |
348d480f | 8031 | /* Set a breakpoint. |
72b2ff0e VP |
8032 | ARG is a string describing breakpoint address, |
8033 | condition, and thread. | |
8034 | FLAG specifies if a breakpoint is hardware on, | |
8035 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8036 | and BP_TEMPFLAG. */ | |
348d480f | 8037 | |
98deb0da | 8038 | static void |
72b2ff0e | 8039 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8040 | { |
72b2ff0e | 8041 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8042 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8043 | ? bp_hardware_breakpoint | |
8044 | : bp_breakpoint); | |
c3f6f71d | 8045 | |
8cdf0e15 VP |
8046 | create_breakpoint (get_current_arch (), |
8047 | arg, | |
8048 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8049 | tempflag, type_wanted, |
8cdf0e15 VP |
8050 | 0 /* Ignore count */, |
8051 | pending_break_support, | |
348d480f | 8052 | &bkpt_breakpoint_ops, |
8cdf0e15 | 8053 | from_tty, |
84f4c1fe PM |
8054 | 1 /* enabled */, |
8055 | 0 /* internal */); | |
c906108c SS |
8056 | } |
8057 | ||
c906108c SS |
8058 | /* Helper function for break_command_1 and disassemble_command. */ |
8059 | ||
8060 | void | |
fba45db2 | 8061 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8062 | { |
8063 | CORE_ADDR pc; | |
8064 | ||
8065 | if (sal->pc == 0 && sal->symtab != NULL) | |
8066 | { | |
8067 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8068 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8069 | sal->line, sal->symtab->filename); |
8070 | sal->pc = pc; | |
6a048695 | 8071 | |
4a64f543 MS |
8072 | /* If this SAL corresponds to a breakpoint inserted using a line |
8073 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8074 | if (sal->explicit_line) |
059acae7 | 8075 | skip_prologue_sal (sal); |
c906108c SS |
8076 | } |
8077 | ||
8078 | if (sal->section == 0 && sal->symtab != NULL) | |
8079 | { | |
8080 | struct blockvector *bv; | |
c5aa993b JM |
8081 | struct block *b; |
8082 | struct symbol *sym; | |
c906108c | 8083 | |
801e3a5b | 8084 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8085 | if (bv != NULL) |
8086 | { | |
7f0df278 | 8087 | sym = block_linkage_function (b); |
c906108c SS |
8088 | if (sym != NULL) |
8089 | { | |
8090 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8091 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8092 | } |
8093 | else | |
8094 | { | |
4a64f543 MS |
8095 | /* It really is worthwhile to have the section, so we'll |
8096 | just have to look harder. This case can be executed | |
8097 | if we have line numbers but no functions (as can | |
8098 | happen in assembly source). */ | |
c906108c | 8099 | |
c5aa993b | 8100 | struct minimal_symbol *msym; |
6c95b8df PA |
8101 | struct cleanup *old_chain = save_current_space_and_thread (); |
8102 | ||
8103 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8104 | |
8105 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8106 | if (msym) | |
714835d5 | 8107 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8108 | |
8109 | do_cleanups (old_chain); | |
c906108c SS |
8110 | } |
8111 | } | |
8112 | } | |
8113 | } | |
8114 | ||
8115 | void | |
fba45db2 | 8116 | break_command (char *arg, int from_tty) |
c906108c | 8117 | { |
db107f19 | 8118 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8119 | } |
8120 | ||
c906108c | 8121 | void |
fba45db2 | 8122 | tbreak_command (char *arg, int from_tty) |
c906108c | 8123 | { |
db107f19 | 8124 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8125 | } |
8126 | ||
c906108c | 8127 | static void |
fba45db2 | 8128 | hbreak_command (char *arg, int from_tty) |
c906108c | 8129 | { |
db107f19 | 8130 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8131 | } |
8132 | ||
8133 | static void | |
fba45db2 | 8134 | thbreak_command (char *arg, int from_tty) |
c906108c | 8135 | { |
db107f19 | 8136 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8137 | } |
8138 | ||
8139 | static void | |
fba45db2 | 8140 | stop_command (char *arg, int from_tty) |
c906108c | 8141 | { |
a3f17187 | 8142 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8143 | Usage: stop in <function | address>\n\ |
a3f17187 | 8144 | stop at <line>\n")); |
c906108c SS |
8145 | } |
8146 | ||
8147 | static void | |
fba45db2 | 8148 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8149 | { |
8150 | int badInput = 0; | |
8151 | ||
c5aa993b | 8152 | if (arg == (char *) NULL) |
c906108c SS |
8153 | badInput = 1; |
8154 | else if (*arg != '*') | |
8155 | { | |
8156 | char *argptr = arg; | |
8157 | int hasColon = 0; | |
8158 | ||
4a64f543 | 8159 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8160 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8161 | function/method name. */ |
c906108c | 8162 | while (*argptr && !hasColon) |
c5aa993b JM |
8163 | { |
8164 | hasColon = (*argptr == ':'); | |
8165 | argptr++; | |
8166 | } | |
c906108c SS |
8167 | |
8168 | if (hasColon) | |
c5aa993b | 8169 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8170 | else |
c5aa993b | 8171 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8172 | } |
8173 | ||
8174 | if (badInput) | |
a3f17187 | 8175 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8176 | else |
db107f19 | 8177 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8178 | } |
8179 | ||
8180 | static void | |
fba45db2 | 8181 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8182 | { |
8183 | int badInput = 0; | |
8184 | ||
c5aa993b | 8185 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8186 | badInput = 1; |
8187 | else | |
8188 | { | |
8189 | char *argptr = arg; | |
8190 | int hasColon = 0; | |
8191 | ||
4a64f543 MS |
8192 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8193 | it is probably a line number. */ | |
c906108c | 8194 | while (*argptr && !hasColon) |
c5aa993b JM |
8195 | { |
8196 | hasColon = (*argptr == ':'); | |
8197 | argptr++; | |
8198 | } | |
c906108c SS |
8199 | |
8200 | if (hasColon) | |
c5aa993b | 8201 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8202 | else |
c5aa993b | 8203 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8204 | } |
8205 | ||
8206 | if (badInput) | |
a3f17187 | 8207 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8208 | else |
db107f19 | 8209 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8210 | } |
8211 | ||
f1310107 TJB |
8212 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
8213 | ranged breakpoints. */ | |
8214 | ||
8215 | static int | |
8216 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
8217 | struct address_space *aspace, | |
8218 | CORE_ADDR bp_addr) | |
8219 | { | |
8220 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, | |
8221 | bl->length, aspace, bp_addr); | |
8222 | } | |
8223 | ||
8224 | /* Implement the "resources_needed" breakpoint_ops method for | |
8225 | ranged breakpoints. */ | |
8226 | ||
8227 | static int | |
8228 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
8229 | { | |
8230 | return target_ranged_break_num_registers (); | |
8231 | } | |
8232 | ||
8233 | /* Implement the "print_it" breakpoint_ops method for | |
8234 | ranged breakpoints. */ | |
8235 | ||
8236 | static enum print_stop_action | |
348d480f | 8237 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 8238 | { |
348d480f | 8239 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 8240 | struct bp_location *bl = b->loc; |
79a45e25 | 8241 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8242 | |
8243 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8244 | ||
8245 | /* Ranged breakpoints have only one location. */ | |
8246 | gdb_assert (bl && bl->next == NULL); | |
8247 | ||
8248 | annotate_breakpoint (b->number); | |
8249 | if (b->disposition == disp_del) | |
8250 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
8251 | else | |
8252 | ui_out_text (uiout, "\nRanged breakpoint "); | |
8253 | if (ui_out_is_mi_like_p (uiout)) | |
8254 | { | |
8255 | ui_out_field_string (uiout, "reason", | |
8256 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8257 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8258 | } | |
8259 | ui_out_field_int (uiout, "bkptno", b->number); | |
8260 | ui_out_text (uiout, ", "); | |
8261 | ||
8262 | return PRINT_SRC_AND_LOC; | |
8263 | } | |
8264 | ||
8265 | /* Implement the "print_one" breakpoint_ops method for | |
8266 | ranged breakpoints. */ | |
8267 | ||
8268 | static void | |
8269 | print_one_ranged_breakpoint (struct breakpoint *b, | |
8270 | struct bp_location **last_loc) | |
8271 | { | |
8272 | struct bp_location *bl = b->loc; | |
8273 | struct value_print_options opts; | |
79a45e25 | 8274 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8275 | |
8276 | /* Ranged breakpoints have only one location. */ | |
8277 | gdb_assert (bl && bl->next == NULL); | |
8278 | ||
8279 | get_user_print_options (&opts); | |
8280 | ||
8281 | if (opts.addressprint) | |
8282 | /* We don't print the address range here, it will be printed later | |
8283 | by print_one_detail_ranged_breakpoint. */ | |
8284 | ui_out_field_skip (uiout, "addr"); | |
8285 | annotate_field (5); | |
8286 | print_breakpoint_location (b, bl); | |
8287 | *last_loc = bl; | |
8288 | } | |
8289 | ||
8290 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8291 | ranged breakpoints. */ | |
8292 | ||
8293 | static void | |
8294 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
8295 | struct ui_out *uiout) | |
8296 | { | |
8297 | CORE_ADDR address_start, address_end; | |
8298 | struct bp_location *bl = b->loc; | |
8299 | struct ui_stream *stb = ui_out_stream_new (uiout); | |
8300 | struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb); | |
8301 | ||
8302 | gdb_assert (bl); | |
8303 | ||
8304 | address_start = bl->address; | |
8305 | address_end = address_start + bl->length - 1; | |
8306 | ||
8307 | ui_out_text (uiout, "\taddress range: "); | |
8308 | fprintf_unfiltered (stb->stream, "[%s, %s]", | |
8309 | print_core_address (bl->gdbarch, address_start), | |
8310 | print_core_address (bl->gdbarch, address_end)); | |
8311 | ui_out_field_stream (uiout, "addr", stb); | |
8312 | ui_out_text (uiout, "\n"); | |
8313 | ||
8314 | do_cleanups (cleanup); | |
8315 | } | |
8316 | ||
8317 | /* Implement the "print_mention" breakpoint_ops method for | |
8318 | ranged breakpoints. */ | |
8319 | ||
8320 | static void | |
8321 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
8322 | { | |
8323 | struct bp_location *bl = b->loc; | |
79a45e25 | 8324 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8325 | |
8326 | gdb_assert (bl); | |
8327 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8328 | ||
8329 | if (ui_out_is_mi_like_p (uiout)) | |
8330 | return; | |
8331 | ||
8332 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
8333 | b->number, paddress (bl->gdbarch, bl->address), | |
8334 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
8335 | } | |
8336 | ||
8337 | /* Implement the "print_recreate" breakpoint_ops method for | |
8338 | ranged breakpoints. */ | |
8339 | ||
8340 | static void | |
8341 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
8342 | { | |
8343 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
8344 | b->addr_string_range_end); | |
d9b3f62e | 8345 | print_recreate_thread (b, fp); |
f1310107 TJB |
8346 | } |
8347 | ||
8348 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
8349 | ||
2060206e | 8350 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
8351 | |
8352 | /* Find the address where the end of the breakpoint range should be | |
8353 | placed, given the SAL of the end of the range. This is so that if | |
8354 | the user provides a line number, the end of the range is set to the | |
8355 | last instruction of the given line. */ | |
8356 | ||
8357 | static CORE_ADDR | |
8358 | find_breakpoint_range_end (struct symtab_and_line sal) | |
8359 | { | |
8360 | CORE_ADDR end; | |
8361 | ||
8362 | /* If the user provided a PC value, use it. Otherwise, | |
8363 | find the address of the end of the given location. */ | |
8364 | if (sal.explicit_pc) | |
8365 | end = sal.pc; | |
8366 | else | |
8367 | { | |
8368 | int ret; | |
8369 | CORE_ADDR start; | |
8370 | ||
8371 | ret = find_line_pc_range (sal, &start, &end); | |
8372 | if (!ret) | |
8373 | error (_("Could not find location of the end of the range.")); | |
8374 | ||
8375 | /* find_line_pc_range returns the start of the next line. */ | |
8376 | end--; | |
8377 | } | |
8378 | ||
8379 | return end; | |
8380 | } | |
8381 | ||
8382 | /* Implement the "break-range" CLI command. */ | |
8383 | ||
8384 | static void | |
8385 | break_range_command (char *arg, int from_tty) | |
8386 | { | |
8387 | char *arg_start, *addr_string_start, *addr_string_end; | |
8388 | struct linespec_result canonical_start, canonical_end; | |
8389 | int bp_count, can_use_bp, length; | |
8390 | CORE_ADDR end; | |
8391 | struct breakpoint *b; | |
8392 | struct symtab_and_line sal_start, sal_end; | |
8393 | struct symtabs_and_lines sals_start, sals_end; | |
8394 | struct cleanup *cleanup_bkpt; | |
8395 | ||
8396 | /* We don't support software ranged breakpoints. */ | |
8397 | if (target_ranged_break_num_registers () < 0) | |
8398 | error (_("This target does not support hardware ranged breakpoints.")); | |
8399 | ||
8400 | bp_count = hw_breakpoint_used_count (); | |
8401 | bp_count += target_ranged_break_num_registers (); | |
8402 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
8403 | bp_count, 0); | |
8404 | if (can_use_bp < 0) | |
8405 | error (_("Hardware breakpoints used exceeds limit.")); | |
8406 | ||
8407 | if (arg == NULL || arg[0] == '\0') | |
8408 | error(_("No address range specified.")); | |
8409 | ||
8410 | sals_start.sals = NULL; | |
8411 | sals_start.nelts = 0; | |
8412 | init_linespec_result (&canonical_start); | |
8413 | ||
8414 | while (*arg == ' ' || *arg == '\t') | |
8415 | arg++; | |
8416 | ||
58438ac1 | 8417 | parse_breakpoint_sals (&arg, &sals_start, &canonical_start); |
f1310107 TJB |
8418 | |
8419 | sal_start = sals_start.sals[0]; | |
8420 | addr_string_start = canonical_start.canonical[0]; | |
8421 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); | |
8422 | xfree (sals_start.sals); | |
8423 | xfree (canonical_start.canonical); | |
8424 | ||
8425 | if (arg[0] != ',') | |
8426 | error (_("Too few arguments.")); | |
8427 | else if (sals_start.nelts == 0) | |
8428 | error (_("Could not find location of the beginning of the range.")); | |
8429 | else if (sals_start.nelts != 1) | |
8430 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8431 | ||
8432 | resolve_sal_pc (&sal_start); | |
8433 | ||
8434 | arg++; /* Skip the comma. */ | |
8435 | while (*arg == ' ' || *arg == '\t') | |
8436 | arg++; | |
8437 | ||
8438 | /* Parse the end location. */ | |
8439 | ||
8440 | sals_end.sals = NULL; | |
8441 | sals_end.nelts = 0; | |
8442 | init_linespec_result (&canonical_end); | |
8443 | arg_start = arg; | |
8444 | ||
423f41a5 | 8445 | /* We call decode_line_1 directly here instead of using |
f1310107 TJB |
8446 | parse_breakpoint_sals because we need to specify the start location's |
8447 | symtab and line as the default symtab and line for the end of the | |
8448 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
8449 | where +14 means 14 lines from the start location. */ | |
8450 | sals_end = decode_line_1 (&arg, 1, sal_start.symtab, sal_start.line, | |
58438ac1 | 8451 | &canonical_end); |
f1310107 TJB |
8452 | |
8453 | /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */ | |
8454 | if (canonical_end.canonical == NULL) | |
38a714bb | 8455 | canonical_end.canonical = xcalloc (1, sizeof (char *)); |
f1310107 TJB |
8456 | /* Add the string if not present. */ |
8457 | if (arg_start != arg && canonical_end.canonical[0] == NULL) | |
8458 | canonical_end.canonical[0] = savestring (arg_start, arg - arg_start); | |
8459 | ||
8460 | sal_end = sals_end.sals[0]; | |
8461 | addr_string_end = canonical_end.canonical[0]; | |
8462 | make_cleanup (xfree, addr_string_end); | |
8463 | xfree (sals_end.sals); | |
8464 | xfree (canonical_end.canonical); | |
8465 | ||
8466 | if (sals_end.nelts == 0) | |
8467 | error (_("Could not find location of the end of the range.")); | |
8468 | else if (sals_end.nelts != 1) | |
8469 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8470 | ||
8471 | resolve_sal_pc (&sal_end); | |
8472 | ||
8473 | end = find_breakpoint_range_end (sal_end); | |
8474 | if (sal_start.pc > end) | |
177b42fe | 8475 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
8476 | |
8477 | length = end - sal_start.pc + 1; | |
8478 | if (length < 0) | |
8479 | /* Length overflowed. */ | |
8480 | error (_("Address range too large.")); | |
8481 | else if (length == 1) | |
8482 | { | |
8483 | /* This range is simple enough to be handled by | |
8484 | the `hbreak' command. */ | |
8485 | hbreak_command (addr_string_start, 1); | |
8486 | ||
8487 | do_cleanups (cleanup_bkpt); | |
8488 | ||
8489 | return; | |
8490 | } | |
8491 | ||
8492 | /* Now set up the breakpoint. */ | |
8493 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 8494 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
8495 | set_breakpoint_count (breakpoint_count + 1); |
8496 | b->number = breakpoint_count; | |
8497 | b->disposition = disp_donttouch; | |
8498 | b->addr_string = addr_string_start; | |
8499 | b->addr_string_range_end = addr_string_end; | |
f1310107 TJB |
8500 | b->loc->length = length; |
8501 | ||
8502 | discard_cleanups (cleanup_bkpt); | |
8503 | ||
8504 | mention (b); | |
8d3788bd | 8505 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
8506 | update_global_location_list (1); |
8507 | } | |
8508 | ||
4a64f543 MS |
8509 | /* Return non-zero if EXP is verified as constant. Returned zero |
8510 | means EXP is variable. Also the constant detection may fail for | |
8511 | some constant expressions and in such case still falsely return | |
8512 | zero. */ | |
65d79d4b SDJ |
8513 | static int |
8514 | watchpoint_exp_is_const (const struct expression *exp) | |
8515 | { | |
8516 | int i = exp->nelts; | |
8517 | ||
8518 | while (i > 0) | |
8519 | { | |
8520 | int oplenp, argsp; | |
8521 | ||
8522 | /* We are only interested in the descriptor of each element. */ | |
8523 | operator_length (exp, i, &oplenp, &argsp); | |
8524 | i -= oplenp; | |
8525 | ||
8526 | switch (exp->elts[i].opcode) | |
8527 | { | |
8528 | case BINOP_ADD: | |
8529 | case BINOP_SUB: | |
8530 | case BINOP_MUL: | |
8531 | case BINOP_DIV: | |
8532 | case BINOP_REM: | |
8533 | case BINOP_MOD: | |
8534 | case BINOP_LSH: | |
8535 | case BINOP_RSH: | |
8536 | case BINOP_LOGICAL_AND: | |
8537 | case BINOP_LOGICAL_OR: | |
8538 | case BINOP_BITWISE_AND: | |
8539 | case BINOP_BITWISE_IOR: | |
8540 | case BINOP_BITWISE_XOR: | |
8541 | case BINOP_EQUAL: | |
8542 | case BINOP_NOTEQUAL: | |
8543 | case BINOP_LESS: | |
8544 | case BINOP_GTR: | |
8545 | case BINOP_LEQ: | |
8546 | case BINOP_GEQ: | |
8547 | case BINOP_REPEAT: | |
8548 | case BINOP_COMMA: | |
8549 | case BINOP_EXP: | |
8550 | case BINOP_MIN: | |
8551 | case BINOP_MAX: | |
8552 | case BINOP_INTDIV: | |
8553 | case BINOP_CONCAT: | |
8554 | case BINOP_IN: | |
8555 | case BINOP_RANGE: | |
8556 | case TERNOP_COND: | |
8557 | case TERNOP_SLICE: | |
8558 | case TERNOP_SLICE_COUNT: | |
8559 | ||
8560 | case OP_LONG: | |
8561 | case OP_DOUBLE: | |
8562 | case OP_DECFLOAT: | |
8563 | case OP_LAST: | |
8564 | case OP_COMPLEX: | |
8565 | case OP_STRING: | |
8566 | case OP_BITSTRING: | |
8567 | case OP_ARRAY: | |
8568 | case OP_TYPE: | |
8569 | case OP_NAME: | |
8570 | case OP_OBJC_NSSTRING: | |
8571 | ||
8572 | case UNOP_NEG: | |
8573 | case UNOP_LOGICAL_NOT: | |
8574 | case UNOP_COMPLEMENT: | |
8575 | case UNOP_ADDR: | |
8576 | case UNOP_HIGH: | |
4a64f543 MS |
8577 | /* Unary, binary and ternary operators: We have to check |
8578 | their operands. If they are constant, then so is the | |
8579 | result of that operation. For instance, if A and B are | |
8580 | determined to be constants, then so is "A + B". | |
8581 | ||
8582 | UNOP_IND is one exception to the rule above, because the | |
8583 | value of *ADDR is not necessarily a constant, even when | |
8584 | ADDR is. */ | |
65d79d4b SDJ |
8585 | break; |
8586 | ||
8587 | case OP_VAR_VALUE: | |
8588 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8589 | |
65d79d4b | 8590 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8591 | possible that a buggy compiler could mark a variable as |
8592 | constant even when it is not, and TYPE_CONST would return | |
8593 | true in this case, while SYMBOL_CLASS wouldn't. | |
8594 | ||
8595 | We also have to check for function symbols because they | |
8596 | are always constant. */ | |
65d79d4b SDJ |
8597 | { |
8598 | struct symbol *s = exp->elts[i + 2].symbol; | |
8599 | ||
8600 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8601 | && SYMBOL_CLASS (s) != LOC_CONST | |
8602 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8603 | return 0; | |
8604 | break; | |
8605 | } | |
8606 | ||
8607 | /* The default action is to return 0 because we are using | |
8608 | the optimistic approach here: If we don't know something, | |
8609 | then it is not a constant. */ | |
8610 | default: | |
8611 | return 0; | |
8612 | } | |
8613 | } | |
8614 | ||
8615 | return 1; | |
8616 | } | |
8617 | ||
3a5c3e22 PA |
8618 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
8619 | ||
8620 | static void | |
8621 | dtor_watchpoint (struct breakpoint *self) | |
8622 | { | |
8623 | struct watchpoint *w = (struct watchpoint *) self; | |
8624 | ||
8625 | xfree (w->cond_exp); | |
8626 | xfree (w->exp); | |
8627 | xfree (w->exp_string); | |
8628 | xfree (w->exp_string_reparse); | |
8629 | value_free (w->val); | |
8630 | ||
8631 | base_breakpoint_ops.dtor (self); | |
8632 | } | |
8633 | ||
348d480f PA |
8634 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
8635 | ||
8636 | static void | |
8637 | re_set_watchpoint (struct breakpoint *b) | |
8638 | { | |
3a5c3e22 PA |
8639 | struct watchpoint *w = (struct watchpoint *) b; |
8640 | ||
348d480f PA |
8641 | /* Watchpoint can be either on expression using entirely global |
8642 | variables, or it can be on local variables. | |
8643 | ||
8644 | Watchpoints of the first kind are never auto-deleted, and even | |
8645 | persist across program restarts. Since they can use variables | |
8646 | from shared libraries, we need to reparse expression as libraries | |
8647 | are loaded and unloaded. | |
8648 | ||
8649 | Watchpoints on local variables can also change meaning as result | |
8650 | of solib event. For example, if a watchpoint uses both a local | |
8651 | and a global variables in expression, it's a local watchpoint, | |
8652 | but unloading of a shared library will make the expression | |
8653 | invalid. This is not a very common use case, but we still | |
8654 | re-evaluate expression, to avoid surprises to the user. | |
8655 | ||
8656 | Note that for local watchpoints, we re-evaluate it only if | |
8657 | watchpoints frame id is still valid. If it's not, it means the | |
8658 | watchpoint is out of scope and will be deleted soon. In fact, | |
8659 | I'm not sure we'll ever be called in this case. | |
8660 | ||
8661 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 8662 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 8663 | |
3a5c3e22 PA |
8664 | Don't do anything about disabled watchpoints, since they will be |
8665 | reevaluated again when enabled. */ | |
8666 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
8667 | } |
8668 | ||
77b06cd7 TJB |
8669 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8670 | ||
8671 | static int | |
8672 | insert_watchpoint (struct bp_location *bl) | |
8673 | { | |
3a5c3e22 PA |
8674 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8675 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8676 | |
8677 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8678 | w->cond_exp); |
77b06cd7 TJB |
8679 | } |
8680 | ||
8681 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8682 | ||
8683 | static int | |
8684 | remove_watchpoint (struct bp_location *bl) | |
8685 | { | |
3a5c3e22 PA |
8686 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8687 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8688 | |
8689 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8690 | w->cond_exp); |
e09342b5 TJB |
8691 | } |
8692 | ||
e09342b5 | 8693 | static int |
348d480f PA |
8694 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
8695 | struct address_space *aspace, CORE_ADDR bp_addr) | |
e09342b5 | 8696 | { |
348d480f | 8697 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 8698 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 8699 | |
348d480f PA |
8700 | /* Continuable hardware watchpoints are treated as non-existent if the |
8701 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
8702 | some data address). Otherwise gdb won't stop on a break instruction | |
8703 | in the code (not from a breakpoint) when a hardware watchpoint has | |
8704 | been defined. Also skip watchpoints which we know did not trigger | |
8705 | (did not match the data address). */ | |
8706 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 8707 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 8708 | return 0; |
9c06b0b4 | 8709 | |
348d480f | 8710 | return 1; |
9c06b0b4 TJB |
8711 | } |
8712 | ||
348d480f PA |
8713 | static void |
8714 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 8715 | { |
348d480f | 8716 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 8717 | |
348d480f | 8718 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
8719 | } |
8720 | ||
8721 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 8722 | hardware watchpoints. */ |
9c06b0b4 TJB |
8723 | |
8724 | static int | |
348d480f | 8725 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 8726 | { |
3a5c3e22 PA |
8727 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8728 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
8729 | |
8730 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
8731 | } |
8732 | ||
8733 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 8734 | hardware watchpoints. */ |
9c06b0b4 TJB |
8735 | |
8736 | static int | |
348d480f | 8737 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 8738 | { |
efa80663 PA |
8739 | /* Read and access watchpoints only work with hardware support. */ |
8740 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
8741 | } |
8742 | ||
9c06b0b4 | 8743 | static enum print_stop_action |
348d480f | 8744 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 8745 | { |
348d480f PA |
8746 | struct cleanup *old_chain; |
8747 | struct breakpoint *b; | |
8748 | const struct bp_location *bl; | |
8749 | struct ui_stream *stb; | |
8750 | enum print_stop_action result; | |
3a5c3e22 | 8751 | struct watchpoint *w; |
79a45e25 | 8752 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8753 | |
8754 | gdb_assert (bs->bp_location_at != NULL); | |
8755 | ||
8756 | bl = bs->bp_location_at; | |
8757 | b = bs->breakpoint_at; | |
3a5c3e22 | 8758 | w = (struct watchpoint *) b; |
348d480f PA |
8759 | |
8760 | stb = ui_out_stream_new (uiout); | |
8761 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
9c06b0b4 TJB |
8762 | |
8763 | switch (b->type) | |
8764 | { | |
348d480f | 8765 | case bp_watchpoint: |
9c06b0b4 TJB |
8766 | case bp_hardware_watchpoint: |
8767 | annotate_watchpoint (b->number); | |
8768 | if (ui_out_is_mi_like_p (uiout)) | |
8769 | ui_out_field_string | |
8770 | (uiout, "reason", | |
8771 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
8772 | mention (b); |
8773 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8774 | ui_out_text (uiout, "\nOld value = "); | |
8775 | watchpoint_value_print (bs->old_val, stb->stream); | |
8776 | ui_out_field_stream (uiout, "old", stb); | |
8777 | ui_out_text (uiout, "\nNew value = "); | |
3a5c3e22 | 8778 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8779 | ui_out_field_stream (uiout, "new", stb); |
8780 | ui_out_text (uiout, "\n"); | |
8781 | /* More than one watchpoint may have been triggered. */ | |
8782 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8783 | break; |
8784 | ||
8785 | case bp_read_watchpoint: | |
8786 | if (ui_out_is_mi_like_p (uiout)) | |
8787 | ui_out_field_string | |
8788 | (uiout, "reason", | |
8789 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
8790 | mention (b); |
8791 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8792 | ui_out_text (uiout, "\nValue = "); | |
3a5c3e22 | 8793 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8794 | ui_out_field_stream (uiout, "value", stb); |
8795 | ui_out_text (uiout, "\n"); | |
8796 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8797 | break; |
8798 | ||
8799 | case bp_access_watchpoint: | |
348d480f PA |
8800 | if (bs->old_val != NULL) |
8801 | { | |
8802 | annotate_watchpoint (b->number); | |
8803 | if (ui_out_is_mi_like_p (uiout)) | |
8804 | ui_out_field_string | |
8805 | (uiout, "reason", | |
8806 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8807 | mention (b); | |
8808 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8809 | ui_out_text (uiout, "\nOld value = "); | |
8810 | watchpoint_value_print (bs->old_val, stb->stream); | |
8811 | ui_out_field_stream (uiout, "old", stb); | |
8812 | ui_out_text (uiout, "\nNew value = "); | |
8813 | } | |
8814 | else | |
8815 | { | |
8816 | mention (b); | |
8817 | if (ui_out_is_mi_like_p (uiout)) | |
8818 | ui_out_field_string | |
8819 | (uiout, "reason", | |
8820 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8821 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8822 | ui_out_text (uiout, "\nValue = "); | |
8823 | } | |
3a5c3e22 | 8824 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8825 | ui_out_field_stream (uiout, "new", stb); |
8826 | ui_out_text (uiout, "\n"); | |
8827 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8828 | break; |
8829 | default: | |
348d480f | 8830 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
8831 | } |
8832 | ||
348d480f PA |
8833 | do_cleanups (old_chain); |
8834 | return result; | |
8835 | } | |
8836 | ||
8837 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
8838 | watchpoints. */ | |
8839 | ||
8840 | static void | |
8841 | print_mention_watchpoint (struct breakpoint *b) | |
8842 | { | |
8843 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 8844 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 8845 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8846 | |
8847 | switch (b->type) | |
8848 | { | |
8849 | case bp_watchpoint: | |
8850 | ui_out_text (uiout, "Watchpoint "); | |
8851 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8852 | break; | |
8853 | case bp_hardware_watchpoint: | |
8854 | ui_out_text (uiout, "Hardware watchpoint "); | |
8855 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8856 | break; | |
8857 | case bp_read_watchpoint: | |
8858 | ui_out_text (uiout, "Hardware read watchpoint "); | |
8859 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
8860 | break; | |
8861 | case bp_access_watchpoint: | |
8862 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
8863 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
8864 | break; | |
8865 | default: | |
8866 | internal_error (__FILE__, __LINE__, | |
8867 | _("Invalid hardware watchpoint type.")); | |
8868 | } | |
8869 | ||
8870 | ui_out_field_int (uiout, "number", b->number); | |
8871 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 8872 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
8873 | do_cleanups (ui_out_chain); |
8874 | } | |
8875 | ||
8876 | /* Implement the "print_recreate" breakpoint_ops method for | |
8877 | watchpoints. */ | |
8878 | ||
8879 | static void | |
8880 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
8881 | { | |
3a5c3e22 PA |
8882 | struct watchpoint *w = (struct watchpoint *) b; |
8883 | ||
348d480f PA |
8884 | switch (b->type) |
8885 | { | |
8886 | case bp_watchpoint: | |
8887 | case bp_hardware_watchpoint: | |
8888 | fprintf_unfiltered (fp, "watch"); | |
8889 | break; | |
8890 | case bp_read_watchpoint: | |
8891 | fprintf_unfiltered (fp, "rwatch"); | |
8892 | break; | |
8893 | case bp_access_watchpoint: | |
8894 | fprintf_unfiltered (fp, "awatch"); | |
8895 | break; | |
8896 | default: | |
8897 | internal_error (__FILE__, __LINE__, | |
8898 | _("Invalid watchpoint type.")); | |
8899 | } | |
8900 | ||
3a5c3e22 | 8901 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 8902 | print_recreate_thread (b, fp); |
348d480f PA |
8903 | } |
8904 | ||
8905 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
8906 | ||
2060206e | 8907 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
8908 | |
8909 | /* Implement the "insert" breakpoint_ops method for | |
8910 | masked hardware watchpoints. */ | |
8911 | ||
8912 | static int | |
8913 | insert_masked_watchpoint (struct bp_location *bl) | |
8914 | { | |
3a5c3e22 PA |
8915 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8916 | ||
8917 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
8918 | bl->watchpoint_type); |
8919 | } | |
8920 | ||
8921 | /* Implement the "remove" breakpoint_ops method for | |
8922 | masked hardware watchpoints. */ | |
8923 | ||
8924 | static int | |
8925 | remove_masked_watchpoint (struct bp_location *bl) | |
8926 | { | |
3a5c3e22 PA |
8927 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8928 | ||
8929 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
8930 | bl->watchpoint_type); |
8931 | } | |
8932 | ||
8933 | /* Implement the "resources_needed" breakpoint_ops method for | |
8934 | masked hardware watchpoints. */ | |
8935 | ||
8936 | static int | |
8937 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
8938 | { | |
3a5c3e22 PA |
8939 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8940 | ||
8941 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
8942 | } |
8943 | ||
8944 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
8945 | masked hardware watchpoints. */ | |
8946 | ||
8947 | static int | |
8948 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
8949 | { | |
8950 | return 0; | |
8951 | } | |
8952 | ||
8953 | /* Implement the "print_it" breakpoint_ops method for | |
8954 | masked hardware watchpoints. */ | |
8955 | ||
8956 | static enum print_stop_action | |
8957 | print_it_masked_watchpoint (bpstat bs) | |
8958 | { | |
8959 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 8960 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8961 | |
8962 | /* Masked watchpoints have only one location. */ | |
8963 | gdb_assert (b->loc && b->loc->next == NULL); | |
8964 | ||
8965 | switch (b->type) | |
8966 | { | |
8967 | case bp_hardware_watchpoint: | |
8968 | annotate_watchpoint (b->number); | |
8969 | if (ui_out_is_mi_like_p (uiout)) | |
8970 | ui_out_field_string | |
8971 | (uiout, "reason", | |
8972 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
8973 | break; | |
8974 | ||
8975 | case bp_read_watchpoint: | |
8976 | if (ui_out_is_mi_like_p (uiout)) | |
8977 | ui_out_field_string | |
8978 | (uiout, "reason", | |
8979 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
8980 | break; | |
8981 | ||
8982 | case bp_access_watchpoint: | |
8983 | if (ui_out_is_mi_like_p (uiout)) | |
8984 | ui_out_field_string | |
8985 | (uiout, "reason", | |
8986 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8987 | break; | |
8988 | default: | |
8989 | internal_error (__FILE__, __LINE__, | |
8990 | _("Invalid hardware watchpoint type.")); | |
8991 | } | |
8992 | ||
8993 | mention (b); | |
9c06b0b4 TJB |
8994 | ui_out_text (uiout, _("\n\ |
8995 | Check the underlying instruction at PC for the memory\n\ | |
8996 | address and value which triggered this watchpoint.\n")); | |
8997 | ui_out_text (uiout, "\n"); | |
8998 | ||
8999 | /* More than one watchpoint may have been triggered. */ | |
9000 | return PRINT_UNKNOWN; | |
9001 | } | |
9002 | ||
9003 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9004 | masked hardware watchpoints. */ | |
9005 | ||
9006 | static void | |
9007 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
9008 | struct ui_out *uiout) | |
9009 | { | |
3a5c3e22 PA |
9010 | struct watchpoint *w = (struct watchpoint *) b; |
9011 | ||
9c06b0b4 TJB |
9012 | /* Masked watchpoints have only one location. */ |
9013 | gdb_assert (b->loc && b->loc->next == NULL); | |
9014 | ||
9015 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 9016 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
9017 | ui_out_text (uiout, "\n"); |
9018 | } | |
9019 | ||
9020 | /* Implement the "print_mention" breakpoint_ops method for | |
9021 | masked hardware watchpoints. */ | |
9022 | ||
9023 | static void | |
9024 | print_mention_masked_watchpoint (struct breakpoint *b) | |
9025 | { | |
3a5c3e22 | 9026 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 9027 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
9028 | struct cleanup *ui_out_chain; |
9029 | ||
9030 | switch (b->type) | |
9031 | { | |
9032 | case bp_hardware_watchpoint: | |
9033 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
9034 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9035 | break; | |
9036 | case bp_read_watchpoint: | |
9037 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
9038 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
9039 | break; | |
9040 | case bp_access_watchpoint: | |
9041 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
9042 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
9043 | break; | |
9044 | default: | |
9045 | internal_error (__FILE__, __LINE__, | |
9046 | _("Invalid hardware watchpoint type.")); | |
9047 | } | |
9048 | ||
9049 | ui_out_field_int (uiout, "number", b->number); | |
9050 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 9051 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
9052 | do_cleanups (ui_out_chain); |
9053 | } | |
9054 | ||
9055 | /* Implement the "print_recreate" breakpoint_ops method for | |
9056 | masked hardware watchpoints. */ | |
9057 | ||
9058 | static void | |
9059 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
9060 | { | |
3a5c3e22 | 9061 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
9062 | char tmp[40]; |
9063 | ||
9064 | switch (b->type) | |
9065 | { | |
9066 | case bp_hardware_watchpoint: | |
9067 | fprintf_unfiltered (fp, "watch"); | |
9068 | break; | |
9069 | case bp_read_watchpoint: | |
9070 | fprintf_unfiltered (fp, "rwatch"); | |
9071 | break; | |
9072 | case bp_access_watchpoint: | |
9073 | fprintf_unfiltered (fp, "awatch"); | |
9074 | break; | |
9075 | default: | |
9076 | internal_error (__FILE__, __LINE__, | |
9077 | _("Invalid hardware watchpoint type.")); | |
9078 | } | |
9079 | ||
3a5c3e22 PA |
9080 | sprintf_vma (tmp, w->hw_wp_mask); |
9081 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 9082 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
9083 | } |
9084 | ||
9085 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
9086 | ||
2060206e | 9087 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
9088 | |
9089 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
9090 | ||
9091 | static int | |
9092 | is_masked_watchpoint (const struct breakpoint *b) | |
9093 | { | |
9094 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
9095 | } | |
9096 | ||
53a5351d JM |
9097 | /* accessflag: hw_write: watch write, |
9098 | hw_read: watch read, | |
9099 | hw_access: watch access (read or write) */ | |
c906108c | 9100 | static void |
84f4c1fe PM |
9101 | watch_command_1 (char *arg, int accessflag, int from_tty, |
9102 | int just_location, int internal) | |
c906108c | 9103 | { |
a9634178 | 9104 | volatile struct gdb_exception e; |
d983da9c | 9105 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 9106 | struct expression *exp; |
60e1c644 | 9107 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 9108 | struct value *val, *mark, *result; |
c906108c | 9109 | struct frame_info *frame; |
c906108c SS |
9110 | char *exp_start = NULL; |
9111 | char *exp_end = NULL; | |
9c06b0b4 TJB |
9112 | char *tok, *end_tok; |
9113 | int toklen = -1; | |
c906108c SS |
9114 | char *cond_start = NULL; |
9115 | char *cond_end = NULL; | |
c906108c | 9116 | enum bptype bp_type; |
37e4754d | 9117 | int thread = -1; |
0cf6dd15 | 9118 | int pc = 0; |
9c06b0b4 TJB |
9119 | /* Flag to indicate whether we are going to use masks for |
9120 | the hardware watchpoint. */ | |
9121 | int use_mask = 0; | |
9122 | CORE_ADDR mask = 0; | |
3a5c3e22 | 9123 | struct watchpoint *w; |
c906108c | 9124 | |
37e4754d LM |
9125 | /* Make sure that we actually have parameters to parse. */ |
9126 | if (arg != NULL && arg[0] != '\0') | |
9127 | { | |
9c06b0b4 | 9128 | char *value_start; |
37e4754d | 9129 | |
9c06b0b4 TJB |
9130 | /* Look for "parameter value" pairs at the end |
9131 | of the arguments string. */ | |
9132 | for (tok = arg + strlen (arg) - 1; tok > arg; tok--) | |
9133 | { | |
9134 | /* Skip whitespace at the end of the argument list. */ | |
9135 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9136 | tok--; | |
9137 | ||
9138 | /* Find the beginning of the last token. | |
9139 | This is the value of the parameter. */ | |
9140 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9141 | tok--; | |
9142 | value_start = tok + 1; | |
9143 | ||
9144 | /* Skip whitespace. */ | |
9145 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9146 | tok--; | |
9147 | ||
9148 | end_tok = tok; | |
9149 | ||
9150 | /* Find the beginning of the second to last token. | |
9151 | This is the parameter itself. */ | |
9152 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9153 | tok--; | |
9154 | tok++; | |
9155 | toklen = end_tok - tok + 1; | |
9156 | ||
9157 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
9158 | { | |
9159 | /* At this point we've found a "thread" token, which means | |
9160 | the user is trying to set a watchpoint that triggers | |
9161 | only in a specific thread. */ | |
9162 | char *endp; | |
37e4754d | 9163 | |
9c06b0b4 TJB |
9164 | if (thread != -1) |
9165 | error(_("You can specify only one thread.")); | |
37e4754d | 9166 | |
9c06b0b4 TJB |
9167 | /* Extract the thread ID from the next token. */ |
9168 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 9169 | |
9c06b0b4 TJB |
9170 | /* Check if the user provided a valid numeric value for the |
9171 | thread ID. */ | |
9172 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
9173 | error (_("Invalid thread ID specification %s."), value_start); | |
9174 | ||
9175 | /* Check if the thread actually exists. */ | |
9176 | if (!valid_thread_id (thread)) | |
9177 | error (_("Unknown thread %d."), thread); | |
9178 | } | |
9179 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
9180 | { | |
9181 | /* We've found a "mask" token, which means the user wants to | |
9182 | create a hardware watchpoint that is going to have the mask | |
9183 | facility. */ | |
9184 | struct value *mask_value, *mark; | |
37e4754d | 9185 | |
9c06b0b4 TJB |
9186 | if (use_mask) |
9187 | error(_("You can specify only one mask.")); | |
37e4754d | 9188 | |
9c06b0b4 | 9189 | use_mask = just_location = 1; |
37e4754d | 9190 | |
9c06b0b4 TJB |
9191 | mark = value_mark (); |
9192 | mask_value = parse_to_comma_and_eval (&value_start); | |
9193 | mask = value_as_address (mask_value); | |
9194 | value_free_to_mark (mark); | |
9195 | } | |
9196 | else | |
9197 | /* We didn't recognize what we found. We should stop here. */ | |
9198 | break; | |
37e4754d | 9199 | |
9c06b0b4 TJB |
9200 | /* Truncate the string and get rid of the "parameter value" pair before |
9201 | the arguments string is parsed by the parse_exp_1 function. */ | |
9202 | *tok = '\0'; | |
9203 | } | |
37e4754d LM |
9204 | } |
9205 | ||
9206 | /* Parse the rest of the arguments. */ | |
c906108c SS |
9207 | innermost_block = NULL; |
9208 | exp_start = arg; | |
9209 | exp = parse_exp_1 (&arg, 0, 0); | |
9210 | exp_end = arg; | |
fa8a61dc TT |
9211 | /* Remove trailing whitespace from the expression before saving it. |
9212 | This makes the eventual display of the expression string a bit | |
9213 | prettier. */ | |
9214 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
9215 | --exp_end; | |
9216 | ||
65d79d4b SDJ |
9217 | /* Checking if the expression is not constant. */ |
9218 | if (watchpoint_exp_is_const (exp)) | |
9219 | { | |
9220 | int len; | |
9221 | ||
9222 | len = exp_end - exp_start; | |
9223 | while (len > 0 && isspace (exp_start[len - 1])) | |
9224 | len--; | |
9225 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
9226 | } | |
9227 | ||
c906108c SS |
9228 | exp_valid_block = innermost_block; |
9229 | mark = value_mark (); | |
a1442452 | 9230 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
9231 | |
9232 | if (just_location) | |
9233 | { | |
9c06b0b4 TJB |
9234 | int ret; |
9235 | ||
06a64a0b | 9236 | exp_valid_block = NULL; |
a1442452 | 9237 | val = value_addr (result); |
06a64a0b TT |
9238 | release_value (val); |
9239 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
9240 | |
9241 | if (use_mask) | |
9242 | { | |
9243 | ret = target_masked_watch_num_registers (value_as_address (val), | |
9244 | mask); | |
9245 | if (ret == -1) | |
9246 | error (_("This target does not support masked watchpoints.")); | |
9247 | else if (ret == -2) | |
9248 | error (_("Invalid mask or memory region.")); | |
9249 | } | |
06a64a0b TT |
9250 | } |
9251 | else if (val != NULL) | |
fa4727a6 | 9252 | release_value (val); |
c906108c | 9253 | |
e9cafbcc TT |
9254 | tok = skip_spaces (arg); |
9255 | end_tok = skip_to_space (tok); | |
c906108c SS |
9256 | |
9257 | toklen = end_tok - tok; | |
9258 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
9259 | { | |
2d134ed3 PA |
9260 | struct expression *cond; |
9261 | ||
60e1c644 | 9262 | innermost_block = NULL; |
c906108c SS |
9263 | tok = cond_start = end_tok + 1; |
9264 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
9265 | |
9266 | /* The watchpoint expression may not be local, but the condition | |
9267 | may still be. E.g.: `watch global if local > 0'. */ | |
9268 | cond_exp_valid_block = innermost_block; | |
9269 | ||
2d134ed3 | 9270 | xfree (cond); |
c906108c SS |
9271 | cond_end = tok; |
9272 | } | |
9273 | if (*tok) | |
8a3fe4f8 | 9274 | error (_("Junk at end of command.")); |
c906108c | 9275 | |
53a5351d | 9276 | if (accessflag == hw_read) |
c5aa993b | 9277 | bp_type = bp_read_watchpoint; |
53a5351d | 9278 | else if (accessflag == hw_access) |
c5aa993b JM |
9279 | bp_type = bp_access_watchpoint; |
9280 | else | |
9281 | bp_type = bp_hardware_watchpoint; | |
c906108c | 9282 | |
d983da9c | 9283 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
9284 | |
9285 | /* If the expression is "local", then set up a "watchpoint scope" | |
9286 | breakpoint at the point where we've left the scope of the watchpoint | |
9287 | expression. Create the scope breakpoint before the watchpoint, so | |
9288 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 9289 | if (exp_valid_block && frame) |
d983da9c | 9290 | { |
edb3359d DJ |
9291 | if (frame_id_p (frame_unwind_caller_id (frame))) |
9292 | { | |
9293 | scope_breakpoint | |
a6d9a66e UW |
9294 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
9295 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
9296 | bp_watchpoint_scope, |
9297 | &momentary_breakpoint_ops); | |
d983da9c | 9298 | |
edb3359d | 9299 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 9300 | |
edb3359d DJ |
9301 | /* Automatically delete the breakpoint when it hits. */ |
9302 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 9303 | |
edb3359d DJ |
9304 | /* Only break in the proper frame (help with recursion). */ |
9305 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 9306 | |
edb3359d | 9307 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
9308 | scope_breakpoint->loc->gdbarch |
9309 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
9310 | scope_breakpoint->loc->requested_address |
9311 | = frame_unwind_caller_pc (frame); | |
9312 | scope_breakpoint->loc->address | |
a6d9a66e UW |
9313 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
9314 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
9315 | scope_breakpoint->type); |
9316 | } | |
d983da9c DJ |
9317 | } |
9318 | ||
c906108c | 9319 | /* Now set up the breakpoint. */ |
3a5c3e22 PA |
9320 | |
9321 | w = XCNEW (struct watchpoint); | |
9322 | b = &w->base; | |
348d480f | 9323 | if (use_mask) |
3a5c3e22 PA |
9324 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9325 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 9326 | else |
3a5c3e22 PA |
9327 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9328 | &watchpoint_breakpoint_ops); | |
37e4754d | 9329 | b->thread = thread; |
b5de0fa7 | 9330 | b->disposition = disp_donttouch; |
348d480f | 9331 | b->pspace = current_program_space; |
3a5c3e22 PA |
9332 | w->exp = exp; |
9333 | w->exp_valid_block = exp_valid_block; | |
9334 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
9335 | if (just_location) |
9336 | { | |
9337 | struct type *t = value_type (val); | |
9338 | CORE_ADDR addr = value_as_address (val); | |
9339 | char *name; | |
9340 | ||
9341 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
9342 | name = type_to_string (t); | |
9343 | ||
3a5c3e22 | 9344 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 9345 | core_addr_to_string (addr)); |
06a64a0b TT |
9346 | xfree (name); |
9347 | ||
3a5c3e22 | 9348 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
9349 | (int) (exp_end - exp_start), exp_start); |
9350 | ||
06a64a0b TT |
9351 | /* The above expression is in C. */ |
9352 | b->language = language_c; | |
9353 | } | |
9354 | else | |
3a5c3e22 | 9355 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
9356 | |
9357 | if (use_mask) | |
9358 | { | |
3a5c3e22 | 9359 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
9360 | } |
9361 | else | |
9362 | { | |
3a5c3e22 PA |
9363 | w->val = val; |
9364 | w->val_valid = 1; | |
9c06b0b4 | 9365 | } |
77b06cd7 | 9366 | |
c906108c SS |
9367 | if (cond_start) |
9368 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
9369 | else | |
9370 | b->cond_string = 0; | |
c5aa993b | 9371 | |
c906108c | 9372 | if (frame) |
f6bc2008 | 9373 | { |
3a5c3e22 PA |
9374 | w->watchpoint_frame = get_frame_id (frame); |
9375 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 9376 | } |
c906108c | 9377 | else |
f6bc2008 | 9378 | { |
3a5c3e22 PA |
9379 | w->watchpoint_frame = null_frame_id; |
9380 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 9381 | } |
c906108c | 9382 | |
d983da9c | 9383 | if (scope_breakpoint != NULL) |
c906108c | 9384 | { |
d983da9c DJ |
9385 | /* The scope breakpoint is related to the watchpoint. We will |
9386 | need to act on them together. */ | |
9387 | b->related_breakpoint = scope_breakpoint; | |
9388 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 9389 | } |
d983da9c | 9390 | |
06a64a0b TT |
9391 | if (!just_location) |
9392 | value_free_to_mark (mark); | |
2d134ed3 | 9393 | |
a9634178 TJB |
9394 | TRY_CATCH (e, RETURN_MASK_ALL) |
9395 | { | |
9396 | /* Finally update the new watchpoint. This creates the locations | |
9397 | that should be inserted. */ | |
3a5c3e22 | 9398 | update_watchpoint (w, 1); |
a9634178 TJB |
9399 | } |
9400 | if (e.reason < 0) | |
9401 | { | |
9402 | delete_breakpoint (b); | |
9403 | throw_exception (e); | |
9404 | } | |
9405 | ||
3ea46bff | 9406 | install_breakpoint (internal, b, 1); |
c906108c SS |
9407 | } |
9408 | ||
e09342b5 | 9409 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 9410 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 9411 | |
c906108c | 9412 | static int |
a9634178 | 9413 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
9414 | { |
9415 | int found_memory_cnt = 0; | |
2e70b7b9 | 9416 | struct value *head = v; |
c906108c SS |
9417 | |
9418 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 9419 | if (!can_use_hw_watchpoints) |
c906108c | 9420 | return 0; |
c5aa993b | 9421 | |
5c44784c JM |
9422 | /* Make sure that the value of the expression depends only upon |
9423 | memory contents, and values computed from them within GDB. If we | |
9424 | find any register references or function calls, we can't use a | |
9425 | hardware watchpoint. | |
9426 | ||
9427 | The idea here is that evaluating an expression generates a series | |
9428 | of values, one holding the value of every subexpression. (The | |
9429 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
9430 | a*b+c.) GDB's values hold almost enough information to establish | |
9431 | the criteria given above --- they identify memory lvalues, | |
9432 | register lvalues, computed values, etcetera. So we can evaluate | |
9433 | the expression, and then scan the chain of values that leaves | |
9434 | behind to decide whether we can detect any possible change to the | |
9435 | expression's final value using only hardware watchpoints. | |
9436 | ||
9437 | However, I don't think that the values returned by inferior | |
9438 | function calls are special in any way. So this function may not | |
9439 | notice that an expression involving an inferior function call | |
9440 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 9441 | for (; v; v = value_next (v)) |
c906108c | 9442 | { |
5c44784c | 9443 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 9444 | { |
8464be76 DJ |
9445 | if (v != head && value_lazy (v)) |
9446 | /* A lazy memory lvalue in the chain is one that GDB never | |
9447 | needed to fetch; we either just used its address (e.g., | |
9448 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
9449 | in `a,b'). This doesn't apply to HEAD; if that is | |
9450 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 9451 | ; |
53a5351d | 9452 | else |
5c44784c JM |
9453 | { |
9454 | /* Ahh, memory we actually used! Check if we can cover | |
9455 | it with hardware watchpoints. */ | |
df407dfe | 9456 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
9457 | |
9458 | /* We only watch structs and arrays if user asked for it | |
9459 | explicitly, never if they just happen to appear in a | |
9460 | middle of some value chain. */ | |
9461 | if (v == head | |
9462 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
9463 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
9464 | { | |
42ae5230 | 9465 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
9466 | int len; |
9467 | int num_regs; | |
9468 | ||
a9634178 | 9469 | len = (target_exact_watchpoints |
e09342b5 TJB |
9470 | && is_scalar_type_recursive (vtype))? |
9471 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 9472 | |
e09342b5 TJB |
9473 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
9474 | if (!num_regs) | |
2e70b7b9 MS |
9475 | return 0; |
9476 | else | |
e09342b5 | 9477 | found_memory_cnt += num_regs; |
2e70b7b9 | 9478 | } |
5c44784c | 9479 | } |
c5aa993b | 9480 | } |
5086187c AC |
9481 | else if (VALUE_LVAL (v) != not_lval |
9482 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 9483 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 9484 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 9485 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
9486 | } |
9487 | ||
9488 | /* The expression itself looks suitable for using a hardware | |
9489 | watchpoint, but give the target machine a chance to reject it. */ | |
9490 | return found_memory_cnt; | |
9491 | } | |
9492 | ||
8b93c638 | 9493 | void |
84f4c1fe | 9494 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9495 | { |
84f4c1fe | 9496 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
9497 | } |
9498 | ||
9499 | /* A helper function that looks for an argument at the start of a | |
9500 | string. The argument must also either be at the end of the string, | |
9501 | or be followed by whitespace. Returns 1 if it finds the argument, | |
9502 | 0 otherwise. If the argument is found, it updates *STR. */ | |
9503 | ||
9504 | static int | |
9505 | check_for_argument (char **str, char *arg, int arg_len) | |
9506 | { | |
9507 | if (strncmp (*str, arg, arg_len) == 0 | |
9508 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
9509 | { | |
9510 | *str += arg_len; | |
9511 | return 1; | |
9512 | } | |
9513 | return 0; | |
9514 | } | |
9515 | ||
9516 | /* A helper function that looks for the "-location" argument and then | |
9517 | calls watch_command_1. */ | |
9518 | ||
9519 | static void | |
9520 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
9521 | { | |
9522 | int just_location = 0; | |
9523 | ||
9524 | if (arg | |
9525 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
9526 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
9527 | { | |
e9cafbcc | 9528 | arg = skip_spaces (arg); |
06a64a0b TT |
9529 | just_location = 1; |
9530 | } | |
9531 | ||
84f4c1fe | 9532 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 9533 | } |
8926118c | 9534 | |
c5aa993b | 9535 | static void |
fba45db2 | 9536 | watch_command (char *arg, int from_tty) |
c906108c | 9537 | { |
06a64a0b | 9538 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
9539 | } |
9540 | ||
8b93c638 | 9541 | void |
84f4c1fe | 9542 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9543 | { |
84f4c1fe | 9544 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 9545 | } |
8926118c | 9546 | |
c5aa993b | 9547 | static void |
fba45db2 | 9548 | rwatch_command (char *arg, int from_tty) |
c906108c | 9549 | { |
06a64a0b | 9550 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
9551 | } |
9552 | ||
8b93c638 | 9553 | void |
84f4c1fe | 9554 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9555 | { |
84f4c1fe | 9556 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 9557 | } |
8926118c | 9558 | |
c5aa993b | 9559 | static void |
fba45db2 | 9560 | awatch_command (char *arg, int from_tty) |
c906108c | 9561 | { |
06a64a0b | 9562 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 9563 | } |
c906108c | 9564 | \f |
c5aa993b | 9565 | |
43ff13b4 | 9566 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
9567 | because it uses the mechanisms of breakpoints. */ |
9568 | ||
bfec99b2 PA |
9569 | struct until_break_command_continuation_args |
9570 | { | |
9571 | struct breakpoint *breakpoint; | |
9572 | struct breakpoint *breakpoint2; | |
186c406b | 9573 | int thread_num; |
bfec99b2 PA |
9574 | }; |
9575 | ||
43ff13b4 | 9576 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 9577 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 9578 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 9579 | command. */ |
c2c6d25f | 9580 | static void |
fa4cd53f | 9581 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 9582 | { |
bfec99b2 PA |
9583 | struct until_break_command_continuation_args *a = arg; |
9584 | ||
9585 | delete_breakpoint (a->breakpoint); | |
9586 | if (a->breakpoint2) | |
9587 | delete_breakpoint (a->breakpoint2); | |
186c406b | 9588 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
9589 | } |
9590 | ||
c906108c | 9591 | void |
ae66c1fc | 9592 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
9593 | { |
9594 | struct symtabs_and_lines sals; | |
9595 | struct symtab_and_line sal; | |
206415a3 | 9596 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 9597 | struct breakpoint *breakpoint; |
f107f563 | 9598 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 9599 | struct cleanup *old_chain; |
186c406b TT |
9600 | int thread; |
9601 | struct thread_info *tp; | |
c906108c SS |
9602 | |
9603 | clear_proceed_status (); | |
9604 | ||
9605 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 9606 | this function. */ |
c5aa993b | 9607 | |
1bfeeb0f JL |
9608 | if (last_displayed_sal_is_valid ()) |
9609 | sals = decode_line_1 (&arg, 1, | |
9610 | get_last_displayed_symtab (), | |
9611 | get_last_displayed_line (), | |
9612 | NULL); | |
c906108c | 9613 | else |
58438ac1 | 9614 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL); |
c5aa993b | 9615 | |
c906108c | 9616 | if (sals.nelts != 1) |
8a3fe4f8 | 9617 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 9618 | |
c906108c | 9619 | sal = sals.sals[0]; |
4a64f543 | 9620 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 9621 | |
c906108c | 9622 | if (*arg) |
8a3fe4f8 | 9623 | error (_("Junk at end of arguments.")); |
c5aa993b | 9624 | |
c906108c | 9625 | resolve_sal_pc (&sal); |
c5aa993b | 9626 | |
ae66c1fc EZ |
9627 | if (anywhere) |
9628 | /* If the user told us to continue until a specified location, | |
9629 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
9630 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9631 | null_frame_id, bp_until); | |
ae66c1fc | 9632 | else |
4a64f543 MS |
9633 | /* Otherwise, specify the selected frame, because we want to stop |
9634 | only at the very same frame. */ | |
a6d9a66e UW |
9635 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9636 | get_stack_frame_id (frame), | |
ae66c1fc | 9637 | bp_until); |
c5aa993b | 9638 | |
f107f563 | 9639 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 9640 | |
186c406b TT |
9641 | tp = inferior_thread (); |
9642 | thread = tp->num; | |
9643 | ||
ae66c1fc EZ |
9644 | /* Keep within the current frame, or in frames called by the current |
9645 | one. */ | |
edb3359d DJ |
9646 | |
9647 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 9648 | { |
edb3359d DJ |
9649 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
9650 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
9651 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
9652 | sal, | |
edb3359d | 9653 | frame_unwind_caller_id (frame), |
f107f563 VP |
9654 | bp_until); |
9655 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
9656 | |
9657 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
9658 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 9659 | } |
c5aa993b | 9660 | |
c906108c | 9661 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 9662 | |
4a64f543 MS |
9663 | /* If we are running asynchronously, and proceed call above has |
9664 | actually managed to start the target, arrange for breakpoints to | |
9665 | be deleted when the target stops. Otherwise, we're already | |
9666 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 9667 | |
8ea051c5 | 9668 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 9669 | { |
bfec99b2 PA |
9670 | struct until_break_command_continuation_args *args; |
9671 | args = xmalloc (sizeof (*args)); | |
f107f563 | 9672 | |
bfec99b2 PA |
9673 | args->breakpoint = breakpoint; |
9674 | args->breakpoint2 = breakpoint2; | |
186c406b | 9675 | args->thread_num = thread; |
f107f563 VP |
9676 | |
9677 | discard_cleanups (old_chain); | |
95e54da7 PA |
9678 | add_continuation (inferior_thread (), |
9679 | until_break_command_continuation, args, | |
604ead4a | 9680 | xfree); |
f107f563 VP |
9681 | } |
9682 | else | |
c5aa993b | 9683 | do_cleanups (old_chain); |
c906108c | 9684 | } |
ae66c1fc | 9685 | |
c906108c SS |
9686 | /* This function attempts to parse an optional "if <cond>" clause |
9687 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 9688 | |
c906108c SS |
9689 | Else, it returns a pointer to the condition string. (It does not |
9690 | attempt to evaluate the string against a particular block.) And, | |
9691 | it updates arg to point to the first character following the parsed | |
4a64f543 | 9692 | if clause in the arg string. */ |
53a5351d | 9693 | |
c906108c | 9694 | static char * |
fba45db2 | 9695 | ep_parse_optional_if_clause (char **arg) |
c906108c | 9696 | { |
c5aa993b JM |
9697 | char *cond_string; |
9698 | ||
9699 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 9700 | return NULL; |
c5aa993b | 9701 | |
4a64f543 | 9702 | /* Skip the "if" keyword. */ |
c906108c | 9703 | (*arg) += 2; |
c5aa993b | 9704 | |
c906108c | 9705 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 9706 | condition string. */ |
e9cafbcc | 9707 | *arg = skip_spaces (*arg); |
c906108c | 9708 | cond_string = *arg; |
c5aa993b | 9709 | |
4a64f543 MS |
9710 | /* Assume that the condition occupies the remainder of the arg |
9711 | string. */ | |
c906108c | 9712 | (*arg) += strlen (cond_string); |
c5aa993b | 9713 | |
c906108c SS |
9714 | return cond_string; |
9715 | } | |
c5aa993b | 9716 | |
c906108c SS |
9717 | /* Commands to deal with catching events, such as signals, exceptions, |
9718 | process start/exit, etc. */ | |
c5aa993b JM |
9719 | |
9720 | typedef enum | |
9721 | { | |
44feb3ce TT |
9722 | catch_fork_temporary, catch_vfork_temporary, |
9723 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
9724 | } |
9725 | catch_fork_kind; | |
9726 | ||
c906108c | 9727 | static void |
cc59ec59 MS |
9728 | catch_fork_command_1 (char *arg, int from_tty, |
9729 | struct cmd_list_element *command) | |
c906108c | 9730 | { |
a6d9a66e | 9731 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 9732 | char *cond_string = NULL; |
44feb3ce TT |
9733 | catch_fork_kind fork_kind; |
9734 | int tempflag; | |
9735 | ||
9736 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
9737 | tempflag = (fork_kind == catch_fork_temporary | |
9738 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 9739 | |
44feb3ce TT |
9740 | if (!arg) |
9741 | arg = ""; | |
e9cafbcc | 9742 | arg = skip_spaces (arg); |
c5aa993b | 9743 | |
c906108c | 9744 | /* The allowed syntax is: |
c5aa993b JM |
9745 | catch [v]fork |
9746 | catch [v]fork if <cond> | |
9747 | ||
4a64f543 | 9748 | First, check if there's an if clause. */ |
c906108c | 9749 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 9750 | |
c906108c | 9751 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9752 | error (_("Junk at end of arguments.")); |
c5aa993b | 9753 | |
c906108c | 9754 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9755 | and enable reporting of such events. */ |
c5aa993b JM |
9756 | switch (fork_kind) |
9757 | { | |
44feb3ce TT |
9758 | case catch_fork_temporary: |
9759 | case catch_fork_permanent: | |
a6d9a66e | 9760 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9761 | &catch_fork_breakpoint_ops); |
c906108c | 9762 | break; |
44feb3ce TT |
9763 | case catch_vfork_temporary: |
9764 | case catch_vfork_permanent: | |
a6d9a66e | 9765 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9766 | &catch_vfork_breakpoint_ops); |
c906108c | 9767 | break; |
c5aa993b | 9768 | default: |
8a3fe4f8 | 9769 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 9770 | break; |
c5aa993b | 9771 | } |
c906108c SS |
9772 | } |
9773 | ||
9774 | static void | |
cc59ec59 MS |
9775 | catch_exec_command_1 (char *arg, int from_tty, |
9776 | struct cmd_list_element *command) | |
c906108c | 9777 | { |
b4d90040 | 9778 | struct exec_catchpoint *c; |
a6d9a66e | 9779 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9780 | int tempflag; |
c5aa993b | 9781 | char *cond_string = NULL; |
c906108c | 9782 | |
44feb3ce TT |
9783 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9784 | ||
9785 | if (!arg) | |
9786 | arg = ""; | |
e9cafbcc | 9787 | arg = skip_spaces (arg); |
c906108c SS |
9788 | |
9789 | /* The allowed syntax is: | |
c5aa993b JM |
9790 | catch exec |
9791 | catch exec if <cond> | |
c906108c | 9792 | |
4a64f543 | 9793 | First, check if there's an if clause. */ |
c906108c SS |
9794 | cond_string = ep_parse_optional_if_clause (&arg); |
9795 | ||
9796 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9797 | error (_("Junk at end of arguments.")); |
c906108c | 9798 | |
b4d90040 PA |
9799 | c = XNEW (struct exec_catchpoint); |
9800 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
9801 | &catch_exec_breakpoint_ops); | |
9802 | c->exec_pathname = NULL; | |
9803 | ||
3ea46bff | 9804 | install_breakpoint (0, &c->base, 1); |
c906108c | 9805 | } |
c5aa993b | 9806 | |
3086aeae | 9807 | static enum print_stop_action |
348d480f | 9808 | print_it_exception_catchpoint (bpstat bs) |
3086aeae | 9809 | { |
79a45e25 | 9810 | struct ui_out *uiout = current_uiout; |
348d480f | 9811 | struct breakpoint *b = bs->breakpoint_at; |
ade92717 | 9812 | int bp_temp, bp_throw; |
3086aeae | 9813 | |
ade92717 | 9814 | annotate_catchpoint (b->number); |
3086aeae | 9815 | |
ade92717 AR |
9816 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9817 | if (b->loc->address != b->loc->requested_address) | |
9818 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9819 | b->loc->address, | |
9820 | b->number, 1); | |
df2b6d2d | 9821 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9822 | ui_out_text (uiout, |
9823 | bp_temp ? "Temporary catchpoint " | |
9824 | : "Catchpoint "); | |
9825 | if (!ui_out_is_mi_like_p (uiout)) | |
9826 | ui_out_field_int (uiout, "bkptno", b->number); | |
9827 | ui_out_text (uiout, | |
c0b37c48 AR |
9828 | bp_throw ? " (exception thrown), " |
9829 | : " (exception caught), "); | |
ade92717 AR |
9830 | if (ui_out_is_mi_like_p (uiout)) |
9831 | { | |
9832 | ui_out_field_string (uiout, "reason", | |
9833 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9834 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9835 | ui_out_field_int (uiout, "bkptno", b->number); | |
9836 | } | |
3086aeae DJ |
9837 | return PRINT_SRC_AND_LOC; |
9838 | } | |
9839 | ||
9840 | static void | |
cc59ec59 MS |
9841 | print_one_exception_catchpoint (struct breakpoint *b, |
9842 | struct bp_location **last_loc) | |
3086aeae | 9843 | { |
79a45b7d | 9844 | struct value_print_options opts; |
79a45e25 | 9845 | struct ui_out *uiout = current_uiout; |
cc59ec59 | 9846 | |
79a45b7d TT |
9847 | get_user_print_options (&opts); |
9848 | if (opts.addressprint) | |
3086aeae DJ |
9849 | { |
9850 | annotate_field (4); | |
604133b5 AR |
9851 | if (b->loc == NULL || b->loc->shlib_disabled) |
9852 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9853 | else | |
5af949e3 UW |
9854 | ui_out_field_core_addr (uiout, "addr", |
9855 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9856 | } |
9857 | annotate_field (5); | |
604133b5 | 9858 | if (b->loc) |
a6d9a66e | 9859 | *last_loc = b->loc; |
3086aeae DJ |
9860 | if (strstr (b->addr_string, "throw") != NULL) |
9861 | ui_out_field_string (uiout, "what", "exception throw"); | |
9862 | else | |
9863 | ui_out_field_string (uiout, "what", "exception catch"); | |
9864 | } | |
9865 | ||
9866 | static void | |
9867 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9868 | { | |
79a45e25 | 9869 | struct ui_out *uiout = current_uiout; |
ade92717 AR |
9870 | int bp_temp; |
9871 | int bp_throw; | |
9872 | ||
df2b6d2d | 9873 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9874 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9875 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9876 | : _("Catchpoint ")); | |
9877 | ui_out_field_int (uiout, "bkptno", b->number); | |
9878 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9879 | : _(" (catch)")); | |
3086aeae DJ |
9880 | } |
9881 | ||
6149aea9 PA |
9882 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9883 | catch catchpoints. */ | |
9884 | ||
9885 | static void | |
4a64f543 MS |
9886 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9887 | struct ui_file *fp) | |
6149aea9 PA |
9888 | { |
9889 | int bp_temp; | |
9890 | int bp_throw; | |
9891 | ||
9892 | bp_temp = b->disposition == disp_del; | |
9893 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9894 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9895 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
d9b3f62e | 9896 | print_recreate_thread (b, fp); |
6149aea9 PA |
9897 | } |
9898 | ||
2060206e | 9899 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; |
3086aeae DJ |
9900 | |
9901 | static int | |
9902 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9903 | enum exception_event_kind ex_event, int from_tty) | |
9904 | { | |
604133b5 AR |
9905 | char *trigger_func_name; |
9906 | ||
3086aeae | 9907 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9908 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9909 | else |
604133b5 | 9910 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9911 | |
8cdf0e15 VP |
9912 | create_breakpoint (get_current_arch (), |
9913 | trigger_func_name, cond_string, -1, | |
9914 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9915 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9916 | 0, |
9917 | AUTO_BOOLEAN_TRUE /* pending */, | |
9918 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9919 | 1 /* enabled */, |
9920 | 0 /* internal */); | |
3086aeae | 9921 | |
3086aeae DJ |
9922 | return 1; |
9923 | } | |
9924 | ||
4a64f543 | 9925 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9926 | |
9927 | static void | |
fba45db2 KB |
9928 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9929 | int tempflag, int from_tty) | |
c906108c | 9930 | { |
c5aa993b | 9931 | char *cond_string = NULL; |
c5aa993b | 9932 | |
44feb3ce TT |
9933 | if (!arg) |
9934 | arg = ""; | |
e9cafbcc | 9935 | arg = skip_spaces (arg); |
c5aa993b | 9936 | |
c906108c SS |
9937 | cond_string = ep_parse_optional_if_clause (&arg); |
9938 | ||
9939 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9940 | error (_("Junk at end of arguments.")); |
c906108c | 9941 | |
059fb39f PM |
9942 | if (ex_event != EX_EVENT_THROW |
9943 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 9944 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 9945 | |
3086aeae DJ |
9946 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
9947 | return; | |
9948 | ||
8a3fe4f8 | 9949 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
9950 | } |
9951 | ||
44feb3ce TT |
9952 | /* Implementation of "catch catch" command. */ |
9953 | ||
9954 | static void | |
9955 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9956 | { | |
9957 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9958 | |
44feb3ce TT |
9959 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
9960 | } | |
9961 | ||
9962 | /* Implementation of "catch throw" command. */ | |
9963 | ||
9964 | static void | |
9965 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9966 | { | |
9967 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9968 | |
44feb3ce TT |
9969 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
9970 | } | |
9971 | ||
9ac4176b | 9972 | void |
28010a5d PA |
9973 | init_ada_exception_breakpoint (struct breakpoint *b, |
9974 | struct gdbarch *gdbarch, | |
9975 | struct symtab_and_line sal, | |
9976 | char *addr_string, | |
c0a91b2b | 9977 | const struct breakpoint_ops *ops, |
28010a5d PA |
9978 | int tempflag, |
9979 | int from_tty) | |
f7f9143b | 9980 | { |
f7f9143b JB |
9981 | if (from_tty) |
9982 | { | |
5af949e3 UW |
9983 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
9984 | if (!loc_gdbarch) | |
9985 | loc_gdbarch = gdbarch; | |
9986 | ||
6c95b8df PA |
9987 | describe_other_breakpoints (loc_gdbarch, |
9988 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
9989 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
9990 | version for exception catchpoints, because two catchpoints | |
9991 | used for different exception names will use the same address. | |
9992 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 9993 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 9994 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
9995 | the user what type of catchpoint it is. The above is good |
9996 | enough for now, though. */ | |
9997 | } | |
9998 | ||
28010a5d | 9999 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b JB |
10000 | |
10001 | b->enable_state = bp_enabled; | |
10002 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
f7f9143b JB |
10003 | b->addr_string = addr_string; |
10004 | b->language = language_ada; | |
f7f9143b JB |
10005 | } |
10006 | ||
a96d9b2e SDJ |
10007 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
10008 | filter list, or NULL if no filtering is required. */ | |
10009 | static VEC(int) * | |
10010 | catch_syscall_split_args (char *arg) | |
10011 | { | |
10012 | VEC(int) *result = NULL; | |
29d0bb3d | 10013 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
10014 | |
10015 | while (*arg != '\0') | |
10016 | { | |
10017 | int i, syscall_number; | |
10018 | char *endptr; | |
10019 | char cur_name[128]; | |
10020 | struct syscall s; | |
10021 | ||
10022 | /* Skip whitespace. */ | |
10023 | while (isspace (*arg)) | |
10024 | arg++; | |
10025 | ||
10026 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
10027 | cur_name[i] = arg[i]; | |
10028 | cur_name[i] = '\0'; | |
10029 | arg += i; | |
10030 | ||
10031 | /* Check if the user provided a syscall name or a number. */ | |
10032 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
10033 | if (*endptr == '\0') | |
bccd0dd2 | 10034 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
10035 | else |
10036 | { | |
10037 | /* We have a name. Let's check if it's valid and convert it | |
10038 | to a number. */ | |
10039 | get_syscall_by_name (cur_name, &s); | |
10040 | ||
10041 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
10042 | /* Here we have to issue an error instead of a warning, |
10043 | because GDB cannot do anything useful if there's no | |
10044 | syscall number to be caught. */ | |
a96d9b2e SDJ |
10045 | error (_("Unknown syscall name '%s'."), cur_name); |
10046 | } | |
10047 | ||
10048 | /* Ok, it's valid. */ | |
10049 | VEC_safe_push (int, result, s.number); | |
10050 | } | |
10051 | ||
10052 | discard_cleanups (cleanup); | |
10053 | return result; | |
10054 | } | |
10055 | ||
10056 | /* Implement the "catch syscall" command. */ | |
10057 | ||
10058 | static void | |
cc59ec59 MS |
10059 | catch_syscall_command_1 (char *arg, int from_tty, |
10060 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
10061 | { |
10062 | int tempflag; | |
10063 | VEC(int) *filter; | |
10064 | struct syscall s; | |
10065 | struct gdbarch *gdbarch = get_current_arch (); | |
10066 | ||
10067 | /* Checking if the feature if supported. */ | |
10068 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
10069 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 10070 | this architecture yet.")); |
a96d9b2e SDJ |
10071 | |
10072 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
10073 | ||
e9cafbcc | 10074 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
10075 | |
10076 | /* We need to do this first "dummy" translation in order | |
10077 | to get the syscall XML file loaded or, most important, | |
10078 | to display a warning to the user if there's no XML file | |
10079 | for his/her architecture. */ | |
10080 | get_syscall_by_number (0, &s); | |
10081 | ||
10082 | /* The allowed syntax is: | |
10083 | catch syscall | |
10084 | catch syscall <name | number> [<name | number> ... <name | number>] | |
10085 | ||
10086 | Let's check if there's a syscall name. */ | |
10087 | ||
10088 | if (arg != NULL) | |
10089 | filter = catch_syscall_split_args (arg); | |
10090 | else | |
10091 | filter = NULL; | |
10092 | ||
10093 | create_syscall_event_catchpoint (tempflag, filter, | |
10094 | &catch_syscall_breakpoint_ops); | |
10095 | } | |
10096 | ||
c906108c | 10097 | static void |
fba45db2 | 10098 | catch_command (char *arg, int from_tty) |
c906108c | 10099 | { |
44feb3ce | 10100 | error (_("Catch requires an event name.")); |
c906108c SS |
10101 | } |
10102 | \f | |
10103 | ||
10104 | static void | |
fba45db2 | 10105 | tcatch_command (char *arg, int from_tty) |
c906108c | 10106 | { |
44feb3ce | 10107 | error (_("Catch requires an event name.")); |
c906108c SS |
10108 | } |
10109 | ||
80f8a6eb | 10110 | /* Delete breakpoints by address or line. */ |
c906108c SS |
10111 | |
10112 | static void | |
fba45db2 | 10113 | clear_command (char *arg, int from_tty) |
c906108c | 10114 | { |
d6e956e5 VP |
10115 | struct breakpoint *b; |
10116 | VEC(breakpoint_p) *found = 0; | |
10117 | int ix; | |
c906108c SS |
10118 | int default_match; |
10119 | struct symtabs_and_lines sals; | |
10120 | struct symtab_and_line sal; | |
c906108c SS |
10121 | int i; |
10122 | ||
10123 | if (arg) | |
10124 | { | |
10125 | sals = decode_line_spec (arg, 1); | |
10126 | default_match = 0; | |
10127 | } | |
10128 | else | |
10129 | { | |
c5aa993b | 10130 | sals.sals = (struct symtab_and_line *) |
c906108c | 10131 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 10132 | make_cleanup (xfree, sals.sals); |
4a64f543 | 10133 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
10134 | |
10135 | /* Set sal's line, symtab, pc, and pspace to the values | |
10136 | corresponding to the last call to print_frame_info. If the | |
10137 | codepoint is not valid, this will set all the fields to 0. */ | |
10138 | get_last_displayed_sal (&sal); | |
c906108c | 10139 | if (sal.symtab == 0) |
8a3fe4f8 | 10140 | error (_("No source file specified.")); |
c906108c SS |
10141 | |
10142 | sals.sals[0] = sal; | |
10143 | sals.nelts = 1; | |
10144 | ||
10145 | default_match = 1; | |
10146 | } | |
10147 | ||
4a64f543 MS |
10148 | /* We don't call resolve_sal_pc here. That's not as bad as it |
10149 | seems, because all existing breakpoints typically have both | |
10150 | file/line and pc set. So, if clear is given file/line, we can | |
10151 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
10152 | |
10153 | We only support clearing given the address explicitly | |
10154 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 10155 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 10156 | due to optimization, all in one block. |
4a64f543 MS |
10157 | |
10158 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
10159 | PC corresponding to the same file:line, the breakpoint won't |
10160 | be cleared. We probably can still clear the breakpoint, but | |
10161 | since the other PC value is never presented to user, user | |
10162 | can only find it by guessing, and it does not seem important | |
10163 | to support that. */ | |
10164 | ||
4a64f543 MS |
10165 | /* For each line spec given, delete bps which correspond to it. Do |
10166 | it in two passes, solely to preserve the current behavior that | |
10167 | from_tty is forced true if we delete more than one | |
10168 | breakpoint. */ | |
c906108c | 10169 | |
80f8a6eb | 10170 | found = NULL; |
c906108c SS |
10171 | for (i = 0; i < sals.nelts; i++) |
10172 | { | |
10173 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
10174 | If line given (pc == 0), clear all bpts on specified line. |
10175 | If defaulting, clear all bpts on default line | |
c906108c | 10176 | or at default pc. |
c5aa993b JM |
10177 | |
10178 | defaulting sal.pc != 0 tests to do | |
10179 | ||
10180 | 0 1 pc | |
10181 | 1 1 pc _and_ line | |
10182 | 0 0 line | |
10183 | 1 0 <can't happen> */ | |
c906108c SS |
10184 | |
10185 | sal = sals.sals[i]; | |
c906108c | 10186 | |
4a64f543 | 10187 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 10188 | ALL_BREAKPOINTS (b) |
c5aa993b | 10189 | { |
0d381245 | 10190 | int match = 0; |
4a64f543 | 10191 | /* Are we going to delete b? */ |
cc60f2e3 | 10192 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
10193 | { |
10194 | struct bp_location *loc = b->loc; | |
10195 | for (; loc; loc = loc->next) | |
10196 | { | |
6c95b8df PA |
10197 | int pc_match = sal.pc |
10198 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
10199 | && (loc->address == sal.pc) |
10200 | && (!section_is_overlay (loc->section) | |
10201 | || loc->section == sal.section); | |
10202 | int line_match = ((default_match || (0 == sal.pc)) | |
10203 | && b->source_file != NULL | |
10204 | && sal.symtab != NULL | |
6c95b8df | 10205 | && sal.pspace == loc->pspace |
0ba1096a KT |
10206 | && filename_cmp (b->source_file, |
10207 | sal.symtab->filename) == 0 | |
0d381245 VP |
10208 | && b->line_number == sal.line); |
10209 | if (pc_match || line_match) | |
10210 | { | |
10211 | match = 1; | |
10212 | break; | |
10213 | } | |
10214 | } | |
10215 | } | |
10216 | ||
10217 | if (match) | |
d6e956e5 | 10218 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 10219 | } |
80f8a6eb MS |
10220 | } |
10221 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 10222 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
10223 | { |
10224 | if (arg) | |
8a3fe4f8 | 10225 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 10226 | else |
8a3fe4f8 | 10227 | error (_("No breakpoint at this line.")); |
80f8a6eb | 10228 | } |
c906108c | 10229 | |
d6e956e5 | 10230 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 10231 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 10232 | if (from_tty) |
a3f17187 | 10233 | { |
d6e956e5 | 10234 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
10235 | printf_unfiltered (_("Deleted breakpoint ")); |
10236 | else | |
10237 | printf_unfiltered (_("Deleted breakpoints ")); | |
10238 | } | |
80f8a6eb | 10239 | breakpoints_changed (); |
d6e956e5 VP |
10240 | |
10241 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 10242 | { |
c5aa993b | 10243 | if (from_tty) |
d6e956e5 VP |
10244 | printf_unfiltered ("%d ", b->number); |
10245 | delete_breakpoint (b); | |
c906108c | 10246 | } |
80f8a6eb MS |
10247 | if (from_tty) |
10248 | putchar_unfiltered ('\n'); | |
c906108c SS |
10249 | } |
10250 | \f | |
10251 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
10252 | all breakpoints that are marked for deletion, whether hit or not. | |
10253 | This is called after any breakpoint is hit, or after errors. */ | |
10254 | ||
10255 | void | |
fba45db2 | 10256 | breakpoint_auto_delete (bpstat bs) |
c906108c | 10257 | { |
35df4500 | 10258 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10259 | |
10260 | for (; bs; bs = bs->next) | |
f431efe5 PA |
10261 | if (bs->breakpoint_at |
10262 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 10263 | && bs->stop) |
f431efe5 | 10264 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 10265 | |
35df4500 | 10266 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10267 | { |
b5de0fa7 | 10268 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
10269 | delete_breakpoint (b); |
10270 | } | |
c906108c SS |
10271 | } |
10272 | ||
4a64f543 MS |
10273 | /* A comparison function for bp_location AP and BP being interfaced to |
10274 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
10275 | does breakpoint_address_is_meaningful say for its OWNER), | |
10276 | secondarily by ordering first bp_permanent OWNERed elements and | |
10277 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 10278 | qsort being an unstable algorithm. */ |
876fa593 JK |
10279 | |
10280 | static int | |
494cfb0f | 10281 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 10282 | { |
494cfb0f JK |
10283 | struct bp_location *a = *(void **) ap; |
10284 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 10285 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
10286 | int a_perm = a->owner->enable_state == bp_permanent; |
10287 | int b_perm = b->owner->enable_state == bp_permanent; | |
10288 | ||
10289 | if (a->address != b->address) | |
10290 | return (a->address > b->address) - (a->address < b->address); | |
10291 | ||
10292 | /* Sort permanent breakpoints first. */ | |
10293 | if (a_perm != b_perm) | |
10294 | return (a_perm < b_perm) - (a_perm > b_perm); | |
10295 | ||
4a64f543 MS |
10296 | /* Make the user-visible order stable across GDB runs. Locations of |
10297 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
10298 | |
10299 | if (a->owner->number != b->owner->number) | |
10300 | return (a->owner->number > b->owner->number) | |
10301 | - (a->owner->number < b->owner->number); | |
10302 | ||
10303 | return (a > b) - (a < b); | |
10304 | } | |
10305 | ||
876fa593 | 10306 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
10307 | bp_location_shadow_len_after_address_max according to the current |
10308 | content of the bp_location array. */ | |
f7545552 TT |
10309 | |
10310 | static void | |
876fa593 | 10311 | bp_location_target_extensions_update (void) |
f7545552 | 10312 | { |
876fa593 JK |
10313 | struct bp_location *bl, **blp_tmp; |
10314 | ||
10315 | bp_location_placed_address_before_address_max = 0; | |
10316 | bp_location_shadow_len_after_address_max = 0; | |
10317 | ||
10318 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10319 | { | |
10320 | CORE_ADDR start, end, addr; | |
10321 | ||
10322 | if (!bp_location_has_shadow (bl)) | |
10323 | continue; | |
10324 | ||
10325 | start = bl->target_info.placed_address; | |
10326 | end = start + bl->target_info.shadow_len; | |
10327 | ||
10328 | gdb_assert (bl->address >= start); | |
10329 | addr = bl->address - start; | |
10330 | if (addr > bp_location_placed_address_before_address_max) | |
10331 | bp_location_placed_address_before_address_max = addr; | |
10332 | ||
10333 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
10334 | ||
10335 | gdb_assert (bl->address < end); | |
10336 | addr = end - bl->address; | |
10337 | if (addr > bp_location_shadow_len_after_address_max) | |
10338 | bp_location_shadow_len_after_address_max = addr; | |
10339 | } | |
f7545552 TT |
10340 | } |
10341 | ||
1e4d1764 YQ |
10342 | /* Download tracepoint locations if they haven't been. */ |
10343 | ||
10344 | static void | |
10345 | download_tracepoint_locations (void) | |
10346 | { | |
10347 | struct bp_location *bl, **blp_tmp; | |
10348 | struct cleanup *old_chain; | |
10349 | ||
10350 | if (!target_can_download_tracepoint ()) | |
10351 | return; | |
10352 | ||
10353 | old_chain = save_current_space_and_thread (); | |
10354 | ||
10355 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10356 | { | |
10357 | struct tracepoint *t; | |
10358 | ||
10359 | if (!is_tracepoint (bl->owner)) | |
10360 | continue; | |
10361 | ||
10362 | if ((bl->owner->type == bp_fast_tracepoint | |
10363 | ? !may_insert_fast_tracepoints | |
10364 | : !may_insert_tracepoints)) | |
10365 | continue; | |
10366 | ||
10367 | /* In tracepoint, locations are _never_ duplicated, so | |
10368 | should_be_inserted is equivalent to | |
10369 | unduplicated_should_be_inserted. */ | |
10370 | if (!should_be_inserted (bl) || bl->inserted) | |
10371 | continue; | |
10372 | ||
10373 | switch_to_program_space_and_thread (bl->pspace); | |
10374 | ||
10375 | target_download_tracepoint (bl); | |
10376 | ||
10377 | bl->inserted = 1; | |
10378 | t = (struct tracepoint *) bl->owner; | |
10379 | t->number_on_target = bl->owner->number; | |
10380 | } | |
10381 | ||
10382 | do_cleanups (old_chain); | |
10383 | } | |
10384 | ||
934709f0 PW |
10385 | /* Swap the insertion/duplication state between two locations. */ |
10386 | ||
10387 | static void | |
10388 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
10389 | { | |
10390 | const int left_inserted = left->inserted; | |
10391 | const int left_duplicate = left->duplicate; | |
10392 | const struct bp_target_info left_target_info = left->target_info; | |
10393 | ||
1e4d1764 YQ |
10394 | /* Locations of tracepoints can never be duplicated. */ |
10395 | if (is_tracepoint (left->owner)) | |
10396 | gdb_assert (!left->duplicate); | |
10397 | if (is_tracepoint (right->owner)) | |
10398 | gdb_assert (!right->duplicate); | |
10399 | ||
934709f0 PW |
10400 | left->inserted = right->inserted; |
10401 | left->duplicate = right->duplicate; | |
10402 | left->target_info = right->target_info; | |
10403 | right->inserted = left_inserted; | |
10404 | right->duplicate = left_duplicate; | |
10405 | right->target_info = left_target_info; | |
10406 | } | |
10407 | ||
4cd9bd08 | 10408 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
10409 | into the inferior, only remove already-inserted locations that no |
10410 | longer should be inserted. Functions that delete a breakpoint or | |
10411 | breakpoints should pass false, so that deleting a breakpoint | |
10412 | doesn't have the side effect of inserting the locations of other | |
10413 | breakpoints that are marked not-inserted, but should_be_inserted | |
10414 | returns true on them. | |
10415 | ||
10416 | This behaviour is useful is situations close to tear-down -- e.g., | |
10417 | after an exec, while the target still has execution, but breakpoint | |
10418 | shadows of the previous executable image should *NOT* be restored | |
10419 | to the new image; or before detaching, where the target still has | |
10420 | execution and wants to delete breakpoints from GDB's lists, and all | |
10421 | breakpoints had already been removed from the inferior. */ | |
10422 | ||
0d381245 | 10423 | static void |
b60e7edf | 10424 | update_global_location_list (int should_insert) |
0d381245 | 10425 | { |
74960c60 | 10426 | struct breakpoint *b; |
876fa593 | 10427 | struct bp_location **locp, *loc; |
f7545552 TT |
10428 | struct cleanup *cleanups; |
10429 | ||
2d134ed3 PA |
10430 | /* Used in the duplicates detection below. When iterating over all |
10431 | bp_locations, points to the first bp_location of a given address. | |
10432 | Breakpoints and watchpoints of different types are never | |
10433 | duplicates of each other. Keep one pointer for each type of | |
10434 | breakpoint/watchpoint, so we only need to loop over all locations | |
10435 | once. */ | |
10436 | struct bp_location *bp_loc_first; /* breakpoint */ | |
10437 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
10438 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
10439 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 10440 | |
4a64f543 MS |
10441 | /* Saved former bp_location array which we compare against the newly |
10442 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
10443 | struct bp_location **old_location, **old_locp; |
10444 | unsigned old_location_count; | |
10445 | ||
10446 | old_location = bp_location; | |
10447 | old_location_count = bp_location_count; | |
10448 | bp_location = NULL; | |
10449 | bp_location_count = 0; | |
10450 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 10451 | |
74960c60 | 10452 | ALL_BREAKPOINTS (b) |
876fa593 JK |
10453 | for (loc = b->loc; loc; loc = loc->next) |
10454 | bp_location_count++; | |
10455 | ||
10456 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
10457 | locp = bp_location; | |
10458 | ALL_BREAKPOINTS (b) | |
10459 | for (loc = b->loc; loc; loc = loc->next) | |
10460 | *locp++ = loc; | |
10461 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 10462 | bp_location_compare); |
876fa593 JK |
10463 | |
10464 | bp_location_target_extensions_update (); | |
74960c60 | 10465 | |
4a64f543 MS |
10466 | /* Identify bp_location instances that are no longer present in the |
10467 | new list, and therefore should be freed. Note that it's not | |
10468 | necessary that those locations should be removed from inferior -- | |
10469 | if there's another location at the same address (previously | |
10470 | marked as duplicate), we don't need to remove/insert the | |
10471 | location. | |
876fa593 | 10472 | |
4a64f543 MS |
10473 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
10474 | and former bp_location array state respectively. */ | |
876fa593 JK |
10475 | |
10476 | locp = bp_location; | |
10477 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
10478 | old_locp++) | |
74960c60 | 10479 | { |
876fa593 | 10480 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 10481 | struct bp_location **loc2p; |
876fa593 | 10482 | |
e5dd4106 | 10483 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 10484 | not, we have to free it. */ |
c7d46a38 | 10485 | int found_object = 0; |
20874c92 VP |
10486 | /* Tells if the location should remain inserted in the target. */ |
10487 | int keep_in_target = 0; | |
10488 | int removed = 0; | |
876fa593 | 10489 | |
4a64f543 MS |
10490 | /* Skip LOCP entries which will definitely never be needed. |
10491 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 10492 | while (locp < bp_location + bp_location_count |
c7d46a38 | 10493 | && (*locp)->address < old_loc->address) |
876fa593 | 10494 | locp++; |
c7d46a38 PA |
10495 | |
10496 | for (loc2p = locp; | |
10497 | (loc2p < bp_location + bp_location_count | |
10498 | && (*loc2p)->address == old_loc->address); | |
10499 | loc2p++) | |
10500 | { | |
10501 | if (*loc2p == old_loc) | |
10502 | { | |
10503 | found_object = 1; | |
10504 | break; | |
10505 | } | |
10506 | } | |
74960c60 | 10507 | |
4a64f543 MS |
10508 | /* If this location is no longer present, and inserted, look if |
10509 | there's maybe a new location at the same address. If so, | |
10510 | mark that one inserted, and don't remove this one. This is | |
10511 | needed so that we don't have a time window where a breakpoint | |
10512 | at certain location is not inserted. */ | |
74960c60 | 10513 | |
876fa593 | 10514 | if (old_loc->inserted) |
0d381245 | 10515 | { |
4a64f543 MS |
10516 | /* If the location is inserted now, we might have to remove |
10517 | it. */ | |
74960c60 | 10518 | |
876fa593 | 10519 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 10520 | { |
4a64f543 MS |
10521 | /* The location is still present in the location list, |
10522 | and still should be inserted. Don't do anything. */ | |
20874c92 | 10523 | keep_in_target = 1; |
74960c60 VP |
10524 | } |
10525 | else | |
10526 | { | |
4a64f543 MS |
10527 | /* The location is either no longer present, or got |
10528 | disabled. See if there's another location at the | |
10529 | same address, in which case we don't need to remove | |
10530 | this one from the target. */ | |
876fa593 | 10531 | |
2bdf28a0 | 10532 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
10533 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
10534 | { | |
876fa593 | 10535 | for (loc2p = locp; |
c7d46a38 PA |
10536 | (loc2p < bp_location + bp_location_count |
10537 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
10538 | loc2p++) |
10539 | { | |
10540 | struct bp_location *loc2 = *loc2p; | |
10541 | ||
2d134ed3 | 10542 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 10543 | { |
85d721b8 PA |
10544 | /* Read watchpoint locations are switched to |
10545 | access watchpoints, if the former are not | |
10546 | supported, but the latter are. */ | |
10547 | if (is_hardware_watchpoint (old_loc->owner)) | |
10548 | { | |
10549 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
10550 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
10551 | } | |
10552 | ||
934709f0 PW |
10553 | /* loc2 is a duplicated location. We need to check |
10554 | if it should be inserted in case it will be | |
10555 | unduplicated. */ | |
10556 | if (loc2 != old_loc | |
10557 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 10558 | { |
934709f0 | 10559 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
10560 | keep_in_target = 1; |
10561 | break; | |
10562 | } | |
876fa593 JK |
10563 | } |
10564 | } | |
10565 | } | |
74960c60 VP |
10566 | } |
10567 | ||
20874c92 VP |
10568 | if (!keep_in_target) |
10569 | { | |
876fa593 | 10570 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 10571 | { |
4a64f543 MS |
10572 | /* This is just about all we can do. We could keep |
10573 | this location on the global list, and try to | |
10574 | remove it next time, but there's no particular | |
10575 | reason why we will succeed next time. | |
20874c92 | 10576 | |
4a64f543 MS |
10577 | Note that at this point, old_loc->owner is still |
10578 | valid, as delete_breakpoint frees the breakpoint | |
10579 | only after calling us. */ | |
3e43a32a MS |
10580 | printf_filtered (_("warning: Error removing " |
10581 | "breakpoint %d\n"), | |
876fa593 | 10582 | old_loc->owner->number); |
20874c92 VP |
10583 | } |
10584 | removed = 1; | |
10585 | } | |
0d381245 | 10586 | } |
74960c60 VP |
10587 | |
10588 | if (!found_object) | |
1c5cfe86 | 10589 | { |
db82e815 PA |
10590 | if (removed && non_stop |
10591 | && breakpoint_address_is_meaningful (old_loc->owner) | |
10592 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 10593 | { |
db82e815 PA |
10594 | /* This location was removed from the target. In |
10595 | non-stop mode, a race condition is possible where | |
10596 | we've removed a breakpoint, but stop events for that | |
10597 | breakpoint are already queued and will arrive later. | |
10598 | We apply an heuristic to be able to distinguish such | |
10599 | SIGTRAPs from other random SIGTRAPs: we keep this | |
10600 | breakpoint location for a bit, and will retire it | |
10601 | after we see some number of events. The theory here | |
10602 | is that reporting of events should, "on the average", | |
10603 | be fair, so after a while we'll see events from all | |
10604 | threads that have anything of interest, and no longer | |
10605 | need to keep this breakpoint location around. We | |
10606 | don't hold locations forever so to reduce chances of | |
10607 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
10608 | SIGTRAP. | |
10609 | ||
10610 | The heuristic failing can be disastrous on | |
10611 | decr_pc_after_break targets. | |
10612 | ||
10613 | On decr_pc_after_break targets, like e.g., x86-linux, | |
10614 | if we fail to recognize a late breakpoint SIGTRAP, | |
10615 | because events_till_retirement has reached 0 too | |
10616 | soon, we'll fail to do the PC adjustment, and report | |
10617 | a random SIGTRAP to the user. When the user resumes | |
10618 | the inferior, it will most likely immediately crash | |
2dec564e | 10619 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
10620 | corrupted, because of being resumed e.g., in the |
10621 | middle of a multi-byte instruction, or skipped a | |
10622 | one-byte instruction. This was actually seen happen | |
10623 | on native x86-linux, and should be less rare on | |
10624 | targets that do not support new thread events, like | |
10625 | remote, due to the heuristic depending on | |
10626 | thread_count. | |
10627 | ||
10628 | Mistaking a random SIGTRAP for a breakpoint trap | |
10629 | causes similar symptoms (PC adjustment applied when | |
10630 | it shouldn't), but then again, playing with SIGTRAPs | |
10631 | behind the debugger's back is asking for trouble. | |
10632 | ||
10633 | Since hardware watchpoint traps are always | |
10634 | distinguishable from other traps, so we don't need to | |
10635 | apply keep hardware watchpoint moribund locations | |
10636 | around. We simply always ignore hardware watchpoint | |
10637 | traps we can no longer explain. */ | |
10638 | ||
876fa593 JK |
10639 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
10640 | old_loc->owner = NULL; | |
20874c92 | 10641 | |
876fa593 | 10642 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
10643 | } |
10644 | else | |
f431efe5 PA |
10645 | { |
10646 | old_loc->owner = NULL; | |
10647 | decref_bp_location (&old_loc); | |
10648 | } | |
20874c92 | 10649 | } |
74960c60 | 10650 | } |
1c5cfe86 | 10651 | |
348d480f PA |
10652 | /* Rescan breakpoints at the same address and section, marking the |
10653 | first one as "first" and any others as "duplicates". This is so | |
10654 | that the bpt instruction is only inserted once. If we have a | |
10655 | permanent breakpoint at the same place as BPT, make that one the | |
10656 | official one, and the rest as duplicates. Permanent breakpoints | |
10657 | are sorted first for the same address. | |
10658 | ||
10659 | Do the same for hardware watchpoints, but also considering the | |
10660 | watchpoint's type (regular/access/read) and length. */ | |
10661 | ||
10662 | bp_loc_first = NULL; | |
10663 | wp_loc_first = NULL; | |
10664 | awp_loc_first = NULL; | |
10665 | rwp_loc_first = NULL; | |
10666 | ALL_BP_LOCATIONS (loc, locp) | |
10667 | { | |
10668 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
10669 | non-NULL. */ | |
10670 | struct breakpoint *b = loc->owner; | |
10671 | struct bp_location **loc_first_p; | |
10672 | ||
10673 | if (b->enable_state == bp_disabled | |
10674 | || b->enable_state == bp_call_disabled | |
10675 | || b->enable_state == bp_startup_disabled | |
10676 | || !loc->enabled | |
10677 | || loc->shlib_disabled | |
10678 | || !breakpoint_address_is_meaningful (b) | |
1e4d1764 YQ |
10679 | /* Don't detect duplicate for tracepoint locations because they are |
10680 | never duplicated. See the comments in field `duplicate' of | |
10681 | `struct bp_location'. */ | |
348d480f PA |
10682 | || is_tracepoint (b)) |
10683 | continue; | |
10684 | ||
10685 | /* Permanent breakpoint should always be inserted. */ | |
10686 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
10687 | internal_error (__FILE__, __LINE__, | |
10688 | _("allegedly permanent breakpoint is not " | |
10689 | "actually inserted")); | |
10690 | ||
10691 | if (b->type == bp_hardware_watchpoint) | |
10692 | loc_first_p = &wp_loc_first; | |
10693 | else if (b->type == bp_read_watchpoint) | |
10694 | loc_first_p = &rwp_loc_first; | |
10695 | else if (b->type == bp_access_watchpoint) | |
10696 | loc_first_p = &awp_loc_first; | |
10697 | else | |
10698 | loc_first_p = &bp_loc_first; | |
10699 | ||
10700 | if (*loc_first_p == NULL | |
10701 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
10702 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
10703 | { | |
10704 | *loc_first_p = loc; | |
10705 | loc->duplicate = 0; | |
10706 | continue; | |
10707 | } | |
10708 | ||
934709f0 PW |
10709 | |
10710 | /* This and the above ensure the invariant that the first location | |
10711 | is not duplicated, and is the inserted one. | |
10712 | All following are marked as duplicated, and are not inserted. */ | |
10713 | if (loc->inserted) | |
10714 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
10715 | loc->duplicate = 1; |
10716 | ||
10717 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted | |
10718 | && b->enable_state != bp_permanent) | |
10719 | internal_error (__FILE__, __LINE__, | |
10720 | _("another breakpoint was inserted on top of " | |
10721 | "a permanent breakpoint")); | |
10722 | } | |
10723 | ||
10724 | if (breakpoints_always_inserted_mode () && should_insert | |
10725 | && (have_live_inferiors () | |
10726 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) | |
10727 | insert_breakpoint_locations (); | |
10728 | ||
1e4d1764 YQ |
10729 | if (should_insert) |
10730 | download_tracepoint_locations (); | |
10731 | ||
348d480f PA |
10732 | do_cleanups (cleanups); |
10733 | } | |
10734 | ||
10735 | void | |
10736 | breakpoint_retire_moribund (void) | |
10737 | { | |
10738 | struct bp_location *loc; | |
10739 | int ix; | |
10740 | ||
10741 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
10742 | if (--(loc->events_till_retirement) == 0) | |
10743 | { | |
10744 | decref_bp_location (&loc); | |
10745 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
10746 | --ix; | |
10747 | } | |
10748 | } | |
10749 | ||
10750 | static void | |
10751 | update_global_location_list_nothrow (int inserting) | |
10752 | { | |
10753 | struct gdb_exception e; | |
10754 | ||
10755 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
10756 | update_global_location_list (inserting); | |
10757 | } | |
10758 | ||
10759 | /* Clear BKP from a BPS. */ | |
10760 | ||
10761 | static void | |
10762 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
10763 | { | |
10764 | bpstat bs; | |
10765 | ||
10766 | for (bs = bps; bs; bs = bs->next) | |
10767 | if (bs->breakpoint_at == bpt) | |
10768 | { | |
10769 | bs->breakpoint_at = NULL; | |
10770 | bs->old_val = NULL; | |
10771 | /* bs->commands will be freed later. */ | |
10772 | } | |
10773 | } | |
10774 | ||
10775 | /* Callback for iterate_over_threads. */ | |
10776 | static int | |
10777 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
10778 | { | |
10779 | struct breakpoint *bpt = data; | |
10780 | ||
10781 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
10782 | return 0; | |
10783 | } | |
10784 | ||
10785 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
10786 | callbacks. */ | |
10787 | ||
10788 | static void | |
10789 | say_where (struct breakpoint *b) | |
10790 | { | |
79a45e25 | 10791 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10792 | struct value_print_options opts; |
10793 | ||
10794 | get_user_print_options (&opts); | |
10795 | ||
10796 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
10797 | single string. */ | |
10798 | if (b->loc == NULL) | |
10799 | { | |
10800 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
10801 | } | |
10802 | else | |
10803 | { | |
10804 | if (opts.addressprint || b->source_file == NULL) | |
10805 | { | |
10806 | printf_filtered (" at "); | |
10807 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
10808 | gdb_stdout); | |
10809 | } | |
10810 | if (b->source_file) | |
10811 | printf_filtered (": file %s, line %d.", | |
10812 | b->source_file, b->line_number); | |
10813 | ||
10814 | if (b->loc->next) | |
10815 | { | |
10816 | struct bp_location *loc = b->loc; | |
10817 | int n = 0; | |
10818 | for (; loc; loc = loc->next) | |
10819 | ++n; | |
10820 | printf_filtered (" (%d locations)", n); | |
10821 | } | |
10822 | } | |
10823 | } | |
10824 | ||
348d480f PA |
10825 | /* Default bp_location_ops methods. */ |
10826 | ||
10827 | static void | |
10828 | bp_location_dtor (struct bp_location *self) | |
10829 | { | |
10830 | xfree (self->cond); | |
10831 | xfree (self->function_name); | |
10832 | } | |
10833 | ||
10834 | static const struct bp_location_ops bp_location_ops = | |
10835 | { | |
10836 | bp_location_dtor | |
10837 | }; | |
10838 | ||
2060206e PA |
10839 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
10840 | inherit from. */ | |
348d480f | 10841 | |
2060206e PA |
10842 | static void |
10843 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
10844 | { |
10845 | decref_counted_command_line (&self->commands); | |
10846 | xfree (self->cond_string); | |
348d480f PA |
10847 | xfree (self->addr_string); |
10848 | xfree (self->addr_string_range_end); | |
348d480f PA |
10849 | xfree (self->source_file); |
10850 | } | |
10851 | ||
2060206e PA |
10852 | static struct bp_location * |
10853 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
10854 | { |
10855 | struct bp_location *loc; | |
10856 | ||
10857 | loc = XNEW (struct bp_location); | |
10858 | init_bp_location (loc, &bp_location_ops, self); | |
10859 | return loc; | |
10860 | } | |
10861 | ||
2060206e PA |
10862 | static void |
10863 | base_breakpoint_re_set (struct breakpoint *b) | |
10864 | { | |
10865 | /* Nothing to re-set. */ | |
10866 | } | |
10867 | ||
10868 | #define internal_error_pure_virtual_called() \ | |
10869 | gdb_assert_not_reached ("pure virtual function called") | |
10870 | ||
10871 | static int | |
10872 | base_breakpoint_insert_location (struct bp_location *bl) | |
10873 | { | |
10874 | internal_error_pure_virtual_called (); | |
10875 | } | |
10876 | ||
10877 | static int | |
10878 | base_breakpoint_remove_location (struct bp_location *bl) | |
10879 | { | |
10880 | internal_error_pure_virtual_called (); | |
10881 | } | |
10882 | ||
10883 | static int | |
10884 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
10885 | struct address_space *aspace, | |
10886 | CORE_ADDR bp_addr) | |
10887 | { | |
10888 | internal_error_pure_virtual_called (); | |
10889 | } | |
10890 | ||
10891 | static void | |
10892 | base_breakpoint_check_status (bpstat bs) | |
10893 | { | |
10894 | /* Always stop. */ | |
10895 | } | |
10896 | ||
10897 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
10898 | errors. */ | |
10899 | ||
10900 | static int | |
10901 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
10902 | { | |
10903 | internal_error_pure_virtual_called (); | |
10904 | } | |
10905 | ||
10906 | /* A "resources_needed" breakpoint_ops method that just internal | |
10907 | errors. */ | |
10908 | ||
10909 | static int | |
10910 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
10911 | { | |
10912 | internal_error_pure_virtual_called (); | |
10913 | } | |
10914 | ||
10915 | static enum print_stop_action | |
10916 | base_breakpoint_print_it (bpstat bs) | |
10917 | { | |
10918 | internal_error_pure_virtual_called (); | |
10919 | } | |
10920 | ||
10921 | static void | |
10922 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
10923 | struct ui_out *uiout) | |
10924 | { | |
10925 | /* nothing */ | |
10926 | } | |
10927 | ||
10928 | static void | |
10929 | base_breakpoint_print_mention (struct breakpoint *b) | |
10930 | { | |
10931 | internal_error_pure_virtual_called (); | |
10932 | } | |
10933 | ||
10934 | static void | |
10935 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
10936 | { | |
10937 | internal_error_pure_virtual_called (); | |
10938 | } | |
10939 | ||
10940 | static struct breakpoint_ops base_breakpoint_ops = | |
10941 | { | |
10942 | base_breakpoint_dtor, | |
10943 | base_breakpoint_allocate_location, | |
10944 | base_breakpoint_re_set, | |
10945 | base_breakpoint_insert_location, | |
10946 | base_breakpoint_remove_location, | |
10947 | base_breakpoint_breakpoint_hit, | |
10948 | base_breakpoint_check_status, | |
10949 | base_breakpoint_resources_needed, | |
10950 | base_breakpoint_works_in_software_mode, | |
10951 | base_breakpoint_print_it, | |
10952 | NULL, | |
10953 | base_breakpoint_print_one_detail, | |
10954 | base_breakpoint_print_mention, | |
10955 | base_breakpoint_print_recreate | |
10956 | }; | |
10957 | ||
10958 | /* Default breakpoint_ops methods. */ | |
10959 | ||
10960 | static void | |
348d480f PA |
10961 | bkpt_re_set (struct breakpoint *b) |
10962 | { | |
06edf0c0 PA |
10963 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
10964 | if (b->enable_state == bp_startup_disabled) | |
10965 | return; | |
348d480f | 10966 | |
06edf0c0 PA |
10967 | /* FIXME: is this still reachable? */ |
10968 | if (b->addr_string == NULL) | |
10969 | { | |
10970 | /* Anything without a string can't be re-set. */ | |
348d480f | 10971 | delete_breakpoint (b); |
06edf0c0 | 10972 | return; |
348d480f | 10973 | } |
06edf0c0 PA |
10974 | |
10975 | breakpoint_re_set_default (b); | |
348d480f PA |
10976 | } |
10977 | ||
2060206e | 10978 | static int |
348d480f PA |
10979 | bkpt_insert_location (struct bp_location *bl) |
10980 | { | |
10981 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
10982 | return target_insert_hw_breakpoint (bl->gdbarch, | |
10983 | &bl->target_info); | |
10984 | else | |
10985 | return target_insert_breakpoint (bl->gdbarch, | |
10986 | &bl->target_info); | |
10987 | } | |
10988 | ||
2060206e | 10989 | static int |
348d480f PA |
10990 | bkpt_remove_location (struct bp_location *bl) |
10991 | { | |
10992 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
10993 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
10994 | else | |
10995 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
10996 | } | |
10997 | ||
2060206e | 10998 | static int |
348d480f PA |
10999 | bkpt_breakpoint_hit (const struct bp_location *bl, |
11000 | struct address_space *aspace, CORE_ADDR bp_addr) | |
11001 | { | |
11002 | struct breakpoint *b = bl->owner; | |
11003 | ||
11004 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, | |
11005 | aspace, bp_addr)) | |
11006 | return 0; | |
11007 | ||
11008 | if (overlay_debugging /* unmapped overlay section */ | |
11009 | && section_is_overlay (bl->section) | |
11010 | && !section_is_mapped (bl->section)) | |
11011 | return 0; | |
11012 | ||
11013 | return 1; | |
11014 | } | |
11015 | ||
2060206e | 11016 | static int |
348d480f PA |
11017 | bkpt_resources_needed (const struct bp_location *bl) |
11018 | { | |
11019 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
11020 | ||
11021 | return 1; | |
11022 | } | |
11023 | ||
2060206e | 11024 | static enum print_stop_action |
348d480f PA |
11025 | bkpt_print_it (bpstat bs) |
11026 | { | |
348d480f PA |
11027 | struct breakpoint *b; |
11028 | const struct bp_location *bl; | |
001c8c33 | 11029 | int bp_temp; |
79a45e25 | 11030 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11031 | |
11032 | gdb_assert (bs->bp_location_at != NULL); | |
11033 | ||
11034 | bl = bs->bp_location_at; | |
11035 | b = bs->breakpoint_at; | |
11036 | ||
001c8c33 PA |
11037 | bp_temp = b->disposition == disp_del; |
11038 | if (bl->address != bl->requested_address) | |
11039 | breakpoint_adjustment_warning (bl->requested_address, | |
11040 | bl->address, | |
11041 | b->number, 1); | |
11042 | annotate_breakpoint (b->number); | |
11043 | if (bp_temp) | |
11044 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
11045 | else | |
11046 | ui_out_text (uiout, "\nBreakpoint "); | |
11047 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 11048 | { |
001c8c33 PA |
11049 | ui_out_field_string (uiout, "reason", |
11050 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
11051 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 11052 | } |
001c8c33 PA |
11053 | ui_out_field_int (uiout, "bkptno", b->number); |
11054 | ui_out_text (uiout, ", "); | |
06edf0c0 | 11055 | |
001c8c33 | 11056 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
11057 | } |
11058 | ||
2060206e | 11059 | static void |
06edf0c0 PA |
11060 | bkpt_print_mention (struct breakpoint *b) |
11061 | { | |
79a45e25 | 11062 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
11063 | return; |
11064 | ||
11065 | switch (b->type) | |
11066 | { | |
11067 | case bp_breakpoint: | |
11068 | case bp_gnu_ifunc_resolver: | |
11069 | if (b->disposition == disp_del) | |
11070 | printf_filtered (_("Temporary breakpoint")); | |
11071 | else | |
11072 | printf_filtered (_("Breakpoint")); | |
11073 | printf_filtered (_(" %d"), b->number); | |
11074 | if (b->type == bp_gnu_ifunc_resolver) | |
11075 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
11076 | break; | |
11077 | case bp_hardware_breakpoint: | |
11078 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
11079 | break; | |
11080 | } | |
11081 | ||
11082 | say_where (b); | |
11083 | } | |
11084 | ||
2060206e | 11085 | static void |
06edf0c0 PA |
11086 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
11087 | { | |
11088 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
11089 | fprintf_unfiltered (fp, "tbreak"); | |
11090 | else if (tp->type == bp_breakpoint) | |
11091 | fprintf_unfiltered (fp, "break"); | |
11092 | else if (tp->type == bp_hardware_breakpoint | |
11093 | && tp->disposition == disp_del) | |
11094 | fprintf_unfiltered (fp, "thbreak"); | |
11095 | else if (tp->type == bp_hardware_breakpoint) | |
11096 | fprintf_unfiltered (fp, "hbreak"); | |
11097 | else | |
11098 | internal_error (__FILE__, __LINE__, | |
11099 | _("unhandled breakpoint type %d"), (int) tp->type); | |
11100 | ||
2060206e | 11101 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 11102 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
11103 | } |
11104 | ||
06edf0c0 PA |
11105 | /* Virtual table for internal breakpoints. */ |
11106 | ||
11107 | static void | |
11108 | internal_bkpt_re_set (struct breakpoint *b) | |
11109 | { | |
11110 | switch (b->type) | |
11111 | { | |
11112 | /* Delete overlay event and longjmp master breakpoints; they | |
11113 | will be reset later by breakpoint_re_set. */ | |
11114 | case bp_overlay_event: | |
11115 | case bp_longjmp_master: | |
11116 | case bp_std_terminate_master: | |
11117 | case bp_exception_master: | |
11118 | delete_breakpoint (b); | |
11119 | break; | |
11120 | ||
11121 | /* This breakpoint is special, it's set up when the inferior | |
11122 | starts and we really don't want to touch it. */ | |
11123 | case bp_shlib_event: | |
11124 | ||
11125 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
11126 | it is set up, we do not want to touch it. */ | |
11127 | case bp_thread_event: | |
11128 | break; | |
11129 | } | |
11130 | } | |
11131 | ||
11132 | static void | |
11133 | internal_bkpt_check_status (bpstat bs) | |
11134 | { | |
11135 | /* We do not stop for these. */ | |
11136 | bs->stop = 0; | |
11137 | } | |
11138 | ||
11139 | static enum print_stop_action | |
11140 | internal_bkpt_print_it (bpstat bs) | |
11141 | { | |
06edf0c0 | 11142 | struct breakpoint *b; |
06edf0c0 | 11143 | |
06edf0c0 PA |
11144 | b = bs->breakpoint_at; |
11145 | ||
06edf0c0 PA |
11146 | switch (b->type) |
11147 | { | |
348d480f PA |
11148 | case bp_shlib_event: |
11149 | /* Did we stop because the user set the stop_on_solib_events | |
11150 | variable? (If so, we report this as a generic, "Stopped due | |
11151 | to shlib event" message.) */ | |
11152 | printf_filtered (_("Stopped due to shared library event\n")); | |
348d480f PA |
11153 | break; |
11154 | ||
11155 | case bp_thread_event: | |
11156 | /* Not sure how we will get here. | |
11157 | GDB should not stop for these breakpoints. */ | |
11158 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11159 | break; |
11160 | ||
11161 | case bp_overlay_event: | |
11162 | /* By analogy with the thread event, GDB should not stop for these. */ | |
11163 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11164 | break; |
11165 | ||
11166 | case bp_longjmp_master: | |
11167 | /* These should never be enabled. */ | |
11168 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11169 | break; |
11170 | ||
11171 | case bp_std_terminate_master: | |
11172 | /* These should never be enabled. */ | |
11173 | printf_filtered (_("std::terminate Master Breakpoint: " | |
11174 | "gdb should not stop!\n")); | |
348d480f PA |
11175 | break; |
11176 | ||
11177 | case bp_exception_master: | |
11178 | /* These should never be enabled. */ | |
11179 | printf_filtered (_("Exception Master Breakpoint: " | |
11180 | "gdb should not stop!\n")); | |
06edf0c0 PA |
11181 | break; |
11182 | } | |
11183 | ||
001c8c33 | 11184 | return PRINT_NOTHING; |
06edf0c0 PA |
11185 | } |
11186 | ||
11187 | static void | |
11188 | internal_bkpt_print_mention (struct breakpoint *b) | |
11189 | { | |
11190 | /* Nothing to mention. These breakpoints are internal. */ | |
11191 | } | |
11192 | ||
06edf0c0 PA |
11193 | /* Virtual table for momentary breakpoints */ |
11194 | ||
11195 | static void | |
11196 | momentary_bkpt_re_set (struct breakpoint *b) | |
11197 | { | |
11198 | /* Keep temporary breakpoints, which can be encountered when we step | |
11199 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
11200 | Otherwise these should have been blown away via the cleanup chain | |
11201 | or by breakpoint_init_inferior when we rerun the executable. */ | |
11202 | } | |
11203 | ||
11204 | static void | |
11205 | momentary_bkpt_check_status (bpstat bs) | |
11206 | { | |
11207 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
11208 | } | |
11209 | ||
11210 | static enum print_stop_action | |
11211 | momentary_bkpt_print_it (bpstat bs) | |
11212 | { | |
79a45e25 PA |
11213 | struct ui_out *uiout = current_uiout; |
11214 | ||
001c8c33 | 11215 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 11216 | { |
001c8c33 | 11217 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 11218 | |
001c8c33 PA |
11219 | switch (b->type) |
11220 | { | |
11221 | case bp_finish: | |
11222 | ui_out_field_string | |
11223 | (uiout, "reason", | |
11224 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
11225 | break; | |
348d480f | 11226 | |
001c8c33 PA |
11227 | case bp_until: |
11228 | ui_out_field_string | |
11229 | (uiout, "reason", | |
11230 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
11231 | break; | |
11232 | } | |
348d480f PA |
11233 | } |
11234 | ||
001c8c33 | 11235 | return PRINT_UNKNOWN; |
348d480f PA |
11236 | } |
11237 | ||
06edf0c0 PA |
11238 | static void |
11239 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 11240 | { |
06edf0c0 | 11241 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
11242 | } |
11243 | ||
348d480f | 11244 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 11245 | |
348d480f PA |
11246 | static void |
11247 | tracepoint_re_set (struct breakpoint *b) | |
11248 | { | |
11249 | breakpoint_re_set_default (b); | |
11250 | } | |
876fa593 | 11251 | |
348d480f PA |
11252 | static int |
11253 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
11254 | struct address_space *aspace, CORE_ADDR bp_addr) | |
11255 | { | |
11256 | /* By definition, the inferior does not report stops at | |
11257 | tracepoints. */ | |
11258 | return 0; | |
74960c60 VP |
11259 | } |
11260 | ||
11261 | static void | |
348d480f PA |
11262 | tracepoint_print_one_detail (const struct breakpoint *self, |
11263 | struct ui_out *uiout) | |
74960c60 | 11264 | { |
d9b3f62e PA |
11265 | struct tracepoint *tp = (struct tracepoint *) self; |
11266 | if (tp->static_trace_marker_id) | |
348d480f PA |
11267 | { |
11268 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 11269 | |
348d480f PA |
11270 | ui_out_text (uiout, "\tmarker id is "); |
11271 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 11272 | tp->static_trace_marker_id); |
348d480f PA |
11273 | ui_out_text (uiout, "\n"); |
11274 | } | |
0d381245 VP |
11275 | } |
11276 | ||
a474d7c2 | 11277 | static void |
348d480f | 11278 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 11279 | { |
79a45e25 | 11280 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 11281 | return; |
cc59ec59 | 11282 | |
348d480f PA |
11283 | switch (b->type) |
11284 | { | |
11285 | case bp_tracepoint: | |
11286 | printf_filtered (_("Tracepoint")); | |
11287 | printf_filtered (_(" %d"), b->number); | |
11288 | break; | |
11289 | case bp_fast_tracepoint: | |
11290 | printf_filtered (_("Fast tracepoint")); | |
11291 | printf_filtered (_(" %d"), b->number); | |
11292 | break; | |
11293 | case bp_static_tracepoint: | |
11294 | printf_filtered (_("Static tracepoint")); | |
11295 | printf_filtered (_(" %d"), b->number); | |
11296 | break; | |
11297 | default: | |
11298 | internal_error (__FILE__, __LINE__, | |
11299 | _("unhandled tracepoint type %d"), (int) b->type); | |
11300 | } | |
11301 | ||
11302 | say_where (b); | |
a474d7c2 PA |
11303 | } |
11304 | ||
348d480f | 11305 | static void |
d9b3f62e | 11306 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 11307 | { |
d9b3f62e PA |
11308 | struct tracepoint *tp = (struct tracepoint *) self; |
11309 | ||
11310 | if (self->type == bp_fast_tracepoint) | |
348d480f | 11311 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 11312 | if (self->type == bp_static_tracepoint) |
348d480f | 11313 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 11314 | else if (self->type == bp_tracepoint) |
348d480f PA |
11315 | fprintf_unfiltered (fp, "trace"); |
11316 | else | |
11317 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 11318 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 11319 | |
d9b3f62e PA |
11320 | fprintf_unfiltered (fp, " %s", self->addr_string); |
11321 | print_recreate_thread (self, fp); | |
11322 | ||
11323 | if (tp->pass_count) | |
11324 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
11325 | } |
11326 | ||
2060206e | 11327 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 11328 | |
53a5351d | 11329 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 11330 | structures. */ |
c906108c SS |
11331 | |
11332 | void | |
fba45db2 | 11333 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 11334 | { |
52f0bd74 | 11335 | struct breakpoint *b; |
c906108c | 11336 | |
8a3fe4f8 | 11337 | gdb_assert (bpt != NULL); |
c906108c | 11338 | |
4a64f543 MS |
11339 | /* Has this bp already been deleted? This can happen because |
11340 | multiple lists can hold pointers to bp's. bpstat lists are | |
11341 | especial culprits. | |
11342 | ||
11343 | One example of this happening is a watchpoint's scope bp. When | |
11344 | the scope bp triggers, we notice that the watchpoint is out of | |
11345 | scope, and delete it. We also delete its scope bp. But the | |
11346 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
11347 | That bpstat is then checked for auto-deleting bp's, which are | |
11348 | deleted. | |
11349 | ||
11350 | A real solution to this problem might involve reference counts in | |
11351 | bp's, and/or giving them pointers back to their referencing | |
11352 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
11353 | storage when no more references were extent. A cheaper bandaid | |
11354 | was chosen. */ | |
c906108c SS |
11355 | if (bpt->type == bp_none) |
11356 | return; | |
11357 | ||
4a64f543 MS |
11358 | /* At least avoid this stale reference until the reference counting |
11359 | of breakpoints gets resolved. */ | |
d0fb5eae | 11360 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 11361 | { |
d0fb5eae | 11362 | struct breakpoint *related; |
3a5c3e22 | 11363 | struct watchpoint *w; |
d0fb5eae JK |
11364 | |
11365 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 11366 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 11367 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
11368 | w = (struct watchpoint *) bpt; |
11369 | else | |
11370 | w = NULL; | |
11371 | if (w != NULL) | |
11372 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
11373 | |
11374 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
11375 | for (related = bpt; related->related_breakpoint != bpt; | |
11376 | related = related->related_breakpoint); | |
11377 | related->related_breakpoint = bpt->related_breakpoint; | |
11378 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
11379 | } |
11380 | ||
a9634178 TJB |
11381 | /* watch_command_1 creates a watchpoint but only sets its number if |
11382 | update_watchpoint succeeds in creating its bp_locations. If there's | |
11383 | a problem in that process, we'll be asked to delete the half-created | |
11384 | watchpoint. In that case, don't announce the deletion. */ | |
11385 | if (bpt->number) | |
11386 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 11387 | |
c906108c SS |
11388 | if (breakpoint_chain == bpt) |
11389 | breakpoint_chain = bpt->next; | |
11390 | ||
c906108c SS |
11391 | ALL_BREAKPOINTS (b) |
11392 | if (b->next == bpt) | |
c5aa993b JM |
11393 | { |
11394 | b->next = bpt->next; | |
11395 | break; | |
11396 | } | |
c906108c | 11397 | |
f431efe5 PA |
11398 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
11399 | been freed. */ | |
11400 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 11401 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
11402 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
11403 | commands are associated with the bpstat; if we remove it here, | |
11404 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
11405 | event-top.c won't do anything, and temporary breakpoints with | |
11406 | commands won't work. */ | |
11407 | ||
11408 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
11409 | ||
4a64f543 MS |
11410 | /* Now that breakpoint is removed from breakpoint list, update the |
11411 | global location list. This will remove locations that used to | |
11412 | belong to this breakpoint. Do this before freeing the breakpoint | |
11413 | itself, since remove_breakpoint looks at location's owner. It | |
11414 | might be better design to have location completely | |
11415 | self-contained, but it's not the case now. */ | |
b60e7edf | 11416 | update_global_location_list (0); |
74960c60 | 11417 | |
348d480f | 11418 | bpt->ops->dtor (bpt); |
4a64f543 MS |
11419 | /* On the chance that someone will soon try again to delete this |
11420 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 11421 | bpt->type = bp_none; |
b8c9b27d | 11422 | xfree (bpt); |
c906108c SS |
11423 | } |
11424 | ||
4d6140d9 AC |
11425 | static void |
11426 | do_delete_breakpoint_cleanup (void *b) | |
11427 | { | |
11428 | delete_breakpoint (b); | |
11429 | } | |
11430 | ||
11431 | struct cleanup * | |
11432 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
11433 | { | |
11434 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
11435 | } | |
11436 | ||
51be5b68 PA |
11437 | /* Iterator function to call a user-provided callback function once |
11438 | for each of B and its related breakpoints. */ | |
11439 | ||
11440 | static void | |
11441 | iterate_over_related_breakpoints (struct breakpoint *b, | |
11442 | void (*function) (struct breakpoint *, | |
11443 | void *), | |
11444 | void *data) | |
11445 | { | |
11446 | struct breakpoint *related; | |
11447 | ||
11448 | related = b; | |
11449 | do | |
11450 | { | |
11451 | struct breakpoint *next; | |
11452 | ||
11453 | /* FUNCTION may delete RELATED. */ | |
11454 | next = related->related_breakpoint; | |
11455 | ||
11456 | if (next == related) | |
11457 | { | |
11458 | /* RELATED is the last ring entry. */ | |
11459 | function (related, data); | |
11460 | ||
11461 | /* FUNCTION may have deleted it, so we'd never reach back to | |
11462 | B. There's nothing left to do anyway, so just break | |
11463 | out. */ | |
11464 | break; | |
11465 | } | |
11466 | else | |
11467 | function (related, data); | |
11468 | ||
11469 | related = next; | |
11470 | } | |
11471 | while (related != b); | |
11472 | } | |
95a42b64 TT |
11473 | |
11474 | static void | |
11475 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11476 | { | |
11477 | delete_breakpoint (b); | |
11478 | } | |
11479 | ||
51be5b68 PA |
11480 | /* A callback for map_breakpoint_numbers that calls |
11481 | delete_breakpoint. */ | |
11482 | ||
11483 | static void | |
11484 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11485 | { | |
11486 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
11487 | } | |
11488 | ||
c906108c | 11489 | void |
fba45db2 | 11490 | delete_command (char *arg, int from_tty) |
c906108c | 11491 | { |
35df4500 | 11492 | struct breakpoint *b, *b_tmp; |
c906108c | 11493 | |
ea9365bb TT |
11494 | dont_repeat (); |
11495 | ||
c906108c SS |
11496 | if (arg == 0) |
11497 | { | |
11498 | int breaks_to_delete = 0; | |
11499 | ||
46c6471b PA |
11500 | /* Delete all breakpoints if no argument. Do not delete |
11501 | internal breakpoints, these have to be deleted with an | |
11502 | explicit breakpoint number argument. */ | |
c5aa993b | 11503 | ALL_BREAKPOINTS (b) |
46c6471b | 11504 | if (user_breakpoint_p (b)) |
973d738b DJ |
11505 | { |
11506 | breaks_to_delete = 1; | |
11507 | break; | |
11508 | } | |
c906108c SS |
11509 | |
11510 | /* Ask user only if there are some breakpoints to delete. */ | |
11511 | if (!from_tty | |
e2e0b3e5 | 11512 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 11513 | { |
35df4500 | 11514 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 11515 | if (user_breakpoint_p (b)) |
c5aa993b | 11516 | delete_breakpoint (b); |
c906108c SS |
11517 | } |
11518 | } | |
11519 | else | |
51be5b68 | 11520 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
11521 | } |
11522 | ||
0d381245 VP |
11523 | static int |
11524 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 11525 | { |
0d381245 VP |
11526 | for (; loc; loc = loc->next) |
11527 | if (!loc->shlib_disabled) | |
11528 | return 0; | |
11529 | return 1; | |
fe3f5fa8 VP |
11530 | } |
11531 | ||
776592bf DE |
11532 | /* Subroutine of update_breakpoint_locations to simplify it. |
11533 | Return non-zero if multiple fns in list LOC have the same name. | |
11534 | Null names are ignored. */ | |
11535 | ||
11536 | static int | |
11537 | ambiguous_names_p (struct bp_location *loc) | |
11538 | { | |
11539 | struct bp_location *l; | |
11540 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
11541 | (int (*) (const void *, |
11542 | const void *)) streq, | |
776592bf DE |
11543 | NULL, xcalloc, xfree); |
11544 | ||
11545 | for (l = loc; l != NULL; l = l->next) | |
11546 | { | |
11547 | const char **slot; | |
11548 | const char *name = l->function_name; | |
11549 | ||
11550 | /* Allow for some names to be NULL, ignore them. */ | |
11551 | if (name == NULL) | |
11552 | continue; | |
11553 | ||
11554 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
11555 | INSERT); | |
4a64f543 MS |
11556 | /* NOTE: We can assume slot != NULL here because xcalloc never |
11557 | returns NULL. */ | |
776592bf DE |
11558 | if (*slot != NULL) |
11559 | { | |
11560 | htab_delete (htab); | |
11561 | return 1; | |
11562 | } | |
11563 | *slot = name; | |
11564 | } | |
11565 | ||
11566 | htab_delete (htab); | |
11567 | return 0; | |
11568 | } | |
11569 | ||
0fb4aa4b PA |
11570 | /* When symbols change, it probably means the sources changed as well, |
11571 | and it might mean the static tracepoint markers are no longer at | |
11572 | the same address or line numbers they used to be at last we | |
11573 | checked. Losing your static tracepoints whenever you rebuild is | |
11574 | undesirable. This function tries to resync/rematch gdb static | |
11575 | tracepoints with the markers on the target, for static tracepoints | |
11576 | that have not been set by marker id. Static tracepoint that have | |
11577 | been set by marker id are reset by marker id in breakpoint_re_set. | |
11578 | The heuristic is: | |
11579 | ||
11580 | 1) For a tracepoint set at a specific address, look for a marker at | |
11581 | the old PC. If one is found there, assume to be the same marker. | |
11582 | If the name / string id of the marker found is different from the | |
11583 | previous known name, assume that means the user renamed the marker | |
11584 | in the sources, and output a warning. | |
11585 | ||
11586 | 2) For a tracepoint set at a given line number, look for a marker | |
11587 | at the new address of the old line number. If one is found there, | |
11588 | assume to be the same marker. If the name / string id of the | |
11589 | marker found is different from the previous known name, assume that | |
11590 | means the user renamed the marker in the sources, and output a | |
11591 | warning. | |
11592 | ||
11593 | 3) If a marker is no longer found at the same address or line, it | |
11594 | may mean the marker no longer exists. But it may also just mean | |
11595 | the code changed a bit. Maybe the user added a few lines of code | |
11596 | that made the marker move up or down (in line number terms). Ask | |
11597 | the target for info about the marker with the string id as we knew | |
11598 | it. If found, update line number and address in the matching | |
11599 | static tracepoint. This will get confused if there's more than one | |
11600 | marker with the same ID (possible in UST, although unadvised | |
11601 | precisely because it confuses tools). */ | |
11602 | ||
11603 | static struct symtab_and_line | |
11604 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
11605 | { | |
d9b3f62e | 11606 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
11607 | struct static_tracepoint_marker marker; |
11608 | CORE_ADDR pc; | |
11609 | int i; | |
11610 | ||
11611 | pc = sal.pc; | |
11612 | if (sal.line) | |
11613 | find_line_pc (sal.symtab, sal.line, &pc); | |
11614 | ||
11615 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
11616 | { | |
d9b3f62e | 11617 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
11618 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
11619 | b->number, | |
d9b3f62e | 11620 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 11621 | |
d9b3f62e PA |
11622 | xfree (tp->static_trace_marker_id); |
11623 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
11624 | release_static_tracepoint_marker (&marker); |
11625 | ||
11626 | return sal; | |
11627 | } | |
11628 | ||
11629 | /* Old marker wasn't found on target at lineno. Try looking it up | |
11630 | by string ID. */ | |
11631 | if (!sal.explicit_pc | |
11632 | && sal.line != 0 | |
11633 | && sal.symtab != NULL | |
d9b3f62e | 11634 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
11635 | { |
11636 | VEC(static_tracepoint_marker_p) *markers; | |
11637 | ||
11638 | markers | |
d9b3f62e | 11639 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
11640 | |
11641 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
11642 | { | |
11643 | struct symtab_and_line sal; | |
11644 | struct symbol *sym; | |
11645 | struct static_tracepoint_marker *marker; | |
79a45e25 | 11646 | struct ui_out *uiout = current_uiout; |
0fb4aa4b PA |
11647 | |
11648 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
11649 | ||
d9b3f62e PA |
11650 | xfree (tp->static_trace_marker_id); |
11651 | tp->static_trace_marker_id = xstrdup (marker->str_id); | |
0fb4aa4b PA |
11652 | |
11653 | warning (_("marker for static tracepoint %d (%s) not " | |
11654 | "found at previous line number"), | |
d9b3f62e | 11655 | b->number, tp->static_trace_marker_id); |
0fb4aa4b PA |
11656 | |
11657 | init_sal (&sal); | |
11658 | ||
11659 | sal.pc = marker->address; | |
11660 | ||
11661 | sal = find_pc_line (marker->address, 0); | |
11662 | sym = find_pc_sect_function (marker->address, NULL); | |
11663 | ui_out_text (uiout, "Now in "); | |
11664 | if (sym) | |
11665 | { | |
11666 | ui_out_field_string (uiout, "func", | |
11667 | SYMBOL_PRINT_NAME (sym)); | |
11668 | ui_out_text (uiout, " at "); | |
11669 | } | |
11670 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
11671 | ui_out_text (uiout, ":"); | |
11672 | ||
11673 | if (ui_out_is_mi_like_p (uiout)) | |
11674 | { | |
11675 | char *fullname = symtab_to_fullname (sal.symtab); | |
11676 | ||
11677 | if (fullname) | |
11678 | ui_out_field_string (uiout, "fullname", fullname); | |
11679 | } | |
11680 | ||
11681 | ui_out_field_int (uiout, "line", sal.line); | |
11682 | ui_out_text (uiout, "\n"); | |
11683 | ||
11684 | b->line_number = sal.line; | |
11685 | ||
11686 | xfree (b->source_file); | |
11687 | if (sym) | |
11688 | b->source_file = xstrdup (sal.symtab->filename); | |
11689 | else | |
11690 | b->source_file = NULL; | |
11691 | ||
11692 | xfree (b->addr_string); | |
11693 | b->addr_string = xstrprintf ("%s:%d", | |
11694 | sal.symtab->filename, b->line_number); | |
11695 | ||
11696 | /* Might be nice to check if function changed, and warn if | |
11697 | so. */ | |
11698 | ||
11699 | release_static_tracepoint_marker (marker); | |
11700 | } | |
11701 | } | |
11702 | return sal; | |
11703 | } | |
11704 | ||
8d3788bd VP |
11705 | /* Returns 1 iff locations A and B are sufficiently same that |
11706 | we don't need to report breakpoint as changed. */ | |
11707 | ||
11708 | static int | |
11709 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
11710 | { | |
11711 | while (a && b) | |
11712 | { | |
11713 | if (a->address != b->address) | |
11714 | return 0; | |
11715 | ||
11716 | if (a->shlib_disabled != b->shlib_disabled) | |
11717 | return 0; | |
11718 | ||
11719 | if (a->enabled != b->enabled) | |
11720 | return 0; | |
11721 | ||
11722 | a = a->next; | |
11723 | b = b->next; | |
11724 | } | |
11725 | ||
11726 | if ((a == NULL) != (b == NULL)) | |
11727 | return 0; | |
11728 | ||
11729 | return 1; | |
11730 | } | |
11731 | ||
f1310107 TJB |
11732 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
11733 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
11734 | a ranged breakpoint. */ | |
11735 | ||
0e30163f | 11736 | void |
0d381245 | 11737 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
11738 | struct symtabs_and_lines sals, |
11739 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
11740 | { |
11741 | int i; | |
0d381245 VP |
11742 | struct bp_location *existing_locations = b->loc; |
11743 | ||
f1310107 TJB |
11744 | /* Ranged breakpoints have only one start location and one end location. */ |
11745 | gdb_assert (sals_end.nelts == 0 || (sals.nelts == 1 && sals_end.nelts == 1)); | |
11746 | ||
4a64f543 MS |
11747 | /* If there's no new locations, and all existing locations are |
11748 | pending, don't do anything. This optimizes the common case where | |
11749 | all locations are in the same shared library, that was unloaded. | |
11750 | We'd like to retain the location, so that when the library is | |
11751 | loaded again, we don't loose the enabled/disabled status of the | |
11752 | individual locations. */ | |
0d381245 | 11753 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
11754 | return; |
11755 | ||
fe3f5fa8 VP |
11756 | b->loc = NULL; |
11757 | ||
0d381245 | 11758 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 11759 | { |
0d381245 | 11760 | struct bp_location *new_loc = |
39d61571 | 11761 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 11762 | |
0d381245 VP |
11763 | /* Reparse conditions, they might contain references to the |
11764 | old symtab. */ | |
11765 | if (b->cond_string != NULL) | |
11766 | { | |
f1310107 | 11767 | char *s; |
0d381245 | 11768 | struct gdb_exception e; |
fe3f5fa8 | 11769 | |
0d381245 VP |
11770 | s = b->cond_string; |
11771 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11772 | { | |
11773 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
11774 | 0); | |
11775 | } | |
11776 | if (e.reason < 0) | |
11777 | { | |
3e43a32a MS |
11778 | warning (_("failed to reevaluate condition " |
11779 | "for breakpoint %d: %s"), | |
0d381245 VP |
11780 | b->number, e.message); |
11781 | new_loc->enabled = 0; | |
11782 | } | |
11783 | } | |
fe3f5fa8 | 11784 | |
0d381245 VP |
11785 | if (b->source_file != NULL) |
11786 | xfree (b->source_file); | |
11787 | if (sals.sals[i].symtab == NULL) | |
11788 | b->source_file = NULL; | |
11789 | else | |
1b36a34b | 11790 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 11791 | |
0d381245 VP |
11792 | if (b->line_number == 0) |
11793 | b->line_number = sals.sals[i].line; | |
f1310107 TJB |
11794 | |
11795 | if (sals_end.nelts) | |
11796 | { | |
11797 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
11798 | ||
11799 | new_loc->length = end - sals.sals[0].pc + 1; | |
11800 | } | |
0d381245 | 11801 | } |
fe3f5fa8 | 11802 | |
514f746b AR |
11803 | /* Update locations of permanent breakpoints. */ |
11804 | if (b->enable_state == bp_permanent) | |
11805 | make_breakpoint_permanent (b); | |
11806 | ||
4a64f543 MS |
11807 | /* If possible, carry over 'disable' status from existing |
11808 | breakpoints. */ | |
0d381245 VP |
11809 | { |
11810 | struct bp_location *e = existing_locations; | |
776592bf DE |
11811 | /* If there are multiple breakpoints with the same function name, |
11812 | e.g. for inline functions, comparing function names won't work. | |
11813 | Instead compare pc addresses; this is just a heuristic as things | |
11814 | may have moved, but in practice it gives the correct answer | |
11815 | often enough until a better solution is found. */ | |
11816 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
11817 | ||
0d381245 VP |
11818 | for (; e; e = e->next) |
11819 | { | |
11820 | if (!e->enabled && e->function_name) | |
11821 | { | |
11822 | struct bp_location *l = b->loc; | |
776592bf DE |
11823 | if (have_ambiguous_names) |
11824 | { | |
11825 | for (; l; l = l->next) | |
f1310107 | 11826 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
11827 | { |
11828 | l->enabled = 0; | |
11829 | break; | |
11830 | } | |
11831 | } | |
11832 | else | |
11833 | { | |
11834 | for (; l; l = l->next) | |
11835 | if (l->function_name | |
11836 | && strcmp (e->function_name, l->function_name) == 0) | |
11837 | { | |
11838 | l->enabled = 0; | |
11839 | break; | |
11840 | } | |
11841 | } | |
0d381245 VP |
11842 | } |
11843 | } | |
11844 | } | |
fe3f5fa8 | 11845 | |
8d3788bd VP |
11846 | if (!locations_are_equal (existing_locations, b->loc)) |
11847 | observer_notify_breakpoint_modified (b); | |
11848 | ||
b60e7edf | 11849 | update_global_location_list (1); |
fe3f5fa8 VP |
11850 | } |
11851 | ||
ef23e705 TJB |
11852 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
11853 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
11854 | ||
11855 | static struct symtabs_and_lines | |
11856 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
11857 | { | |
11858 | char *s; | |
58438ac1 | 11859 | int marker_spec; |
02d20e4a | 11860 | struct symtabs_and_lines sals = {0}; |
ef23e705 TJB |
11861 | struct gdb_exception e; |
11862 | ||
11863 | s = addr_string; | |
11864 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); | |
11865 | ||
11866 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11867 | { | |
11868 | if (marker_spec) | |
11869 | { | |
d9b3f62e PA |
11870 | struct tracepoint *tp = (struct tracepoint *) b; |
11871 | ||
ef23e705 | 11872 | sals = decode_static_tracepoint_spec (&s); |
d9b3f62e | 11873 | if (sals.nelts > tp->static_trace_marker_id_idx) |
ef23e705 | 11874 | { |
d9b3f62e | 11875 | sals.sals[0] = sals.sals[tp->static_trace_marker_id_idx]; |
ef23e705 TJB |
11876 | sals.nelts = 1; |
11877 | } | |
11878 | else | |
d9b3f62e | 11879 | error (_("marker %s not found"), tp->static_trace_marker_id); |
ef23e705 TJB |
11880 | } |
11881 | else | |
58438ac1 | 11882 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, NULL); |
ef23e705 TJB |
11883 | } |
11884 | if (e.reason < 0) | |
11885 | { | |
11886 | int not_found_and_ok = 0; | |
11887 | /* For pending breakpoints, it's expected that parsing will | |
11888 | fail until the right shared library is loaded. User has | |
11889 | already told to create pending breakpoints and don't need | |
11890 | extra messages. If breakpoint is in bp_shlib_disabled | |
11891 | state, then user already saw the message about that | |
11892 | breakpoint being disabled, and don't want to see more | |
11893 | errors. */ | |
58438ac1 | 11894 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
11895 | && (b->condition_not_parsed |
11896 | || (b->loc && b->loc->shlib_disabled) | |
11897 | || b->enable_state == bp_disabled)) | |
11898 | not_found_and_ok = 1; | |
11899 | ||
11900 | if (!not_found_and_ok) | |
11901 | { | |
11902 | /* We surely don't want to warn about the same breakpoint | |
11903 | 10 times. One solution, implemented here, is disable | |
11904 | the breakpoint on error. Another solution would be to | |
11905 | have separate 'warning emitted' flag. Since this | |
11906 | happens only when a binary has changed, I don't know | |
11907 | which approach is better. */ | |
11908 | b->enable_state = bp_disabled; | |
11909 | throw_exception (e); | |
11910 | } | |
11911 | } | |
11912 | ||
58438ac1 | 11913 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 TJB |
11914 | { |
11915 | gdb_assert (sals.nelts == 1); | |
11916 | ||
11917 | resolve_sal_pc (&sals.sals[0]); | |
11918 | if (b->condition_not_parsed && s && s[0]) | |
11919 | { | |
11920 | char *cond_string = 0; | |
11921 | int thread = -1; | |
11922 | int task = 0; | |
11923 | ||
11924 | find_condition_and_thread (s, sals.sals[0].pc, | |
11925 | &cond_string, &thread, &task); | |
11926 | if (cond_string) | |
11927 | b->cond_string = cond_string; | |
11928 | b->thread = thread; | |
11929 | b->task = task; | |
11930 | b->condition_not_parsed = 0; | |
11931 | } | |
11932 | ||
11933 | if (b->type == bp_static_tracepoint && !marker_spec) | |
11934 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
ef23e705 | 11935 | |
58438ac1 TT |
11936 | *found = 1; |
11937 | } | |
11938 | else | |
11939 | *found = 0; | |
ef23e705 TJB |
11940 | |
11941 | return sals; | |
11942 | } | |
11943 | ||
348d480f PA |
11944 | /* The default re_set method, for typical hardware or software |
11945 | breakpoints. Reevaluate the breakpoint and recreate its | |
11946 | locations. */ | |
11947 | ||
11948 | static void | |
28010a5d | 11949 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
11950 | { |
11951 | int found; | |
f1310107 | 11952 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 11953 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 11954 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
11955 | |
11956 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
11957 | if (found) | |
11958 | { | |
11959 | make_cleanup (xfree, sals.sals); | |
11960 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
11961 | } | |
11962 | ||
f1310107 TJB |
11963 | if (b->addr_string_range_end) |
11964 | { | |
11965 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
11966 | if (found) | |
11967 | { | |
11968 | make_cleanup (xfree, sals_end.sals); | |
11969 | expanded_end = expand_line_sal_maybe (sals_end.sals[0]); | |
11970 | } | |
11971 | } | |
11972 | ||
11973 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
11974 | } |
11975 | ||
11976 | /* Prepare the global context for a re-set of breakpoint B. */ | |
11977 | ||
11978 | static struct cleanup * | |
11979 | prepare_re_set_context (struct breakpoint *b) | |
11980 | { | |
11981 | struct cleanup *cleanups; | |
11982 | ||
11983 | input_radix = b->input_radix; | |
11984 | cleanups = save_current_space_and_thread (); | |
11985 | switch_to_program_space_and_thread (b->pspace); | |
11986 | set_language (b->language); | |
11987 | ||
11988 | return cleanups; | |
ef23e705 TJB |
11989 | } |
11990 | ||
c906108c SS |
11991 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
11992 | The value we return ends up being the return value from catch_errors. | |
11993 | Unused in this case. */ | |
11994 | ||
11995 | static int | |
4efb68b1 | 11996 | breakpoint_re_set_one (void *bint) |
c906108c | 11997 | { |
4a64f543 | 11998 | /* Get past catch_errs. */ |
53a5351d | 11999 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 12000 | struct cleanup *cleanups; |
c906108c | 12001 | |
348d480f PA |
12002 | cleanups = prepare_re_set_context (b); |
12003 | b->ops->re_set (b); | |
12004 | do_cleanups (cleanups); | |
c906108c SS |
12005 | return 0; |
12006 | } | |
12007 | ||
69de3c6a | 12008 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 12009 | void |
69de3c6a | 12010 | breakpoint_re_set (void) |
c906108c | 12011 | { |
35df4500 | 12012 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12013 | enum language save_language; |
12014 | int save_input_radix; | |
6c95b8df | 12015 | struct cleanup *old_chain; |
c5aa993b | 12016 | |
c906108c SS |
12017 | save_language = current_language->la_language; |
12018 | save_input_radix = input_radix; | |
6c95b8df PA |
12019 | old_chain = save_current_program_space (); |
12020 | ||
35df4500 | 12021 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12022 | { |
4a64f543 | 12023 | /* Format possible error msg. */ |
fe3f5fa8 | 12024 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
12025 | b->number); |
12026 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 12027 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 12028 | do_cleanups (cleanups); |
c5aa993b | 12029 | } |
c906108c SS |
12030 | set_language (save_language); |
12031 | input_radix = save_input_radix; | |
e62c965a | 12032 | |
0756c555 | 12033 | jit_breakpoint_re_set (); |
4efc6507 | 12034 | |
6c95b8df PA |
12035 | do_cleanups (old_chain); |
12036 | ||
af02033e PP |
12037 | create_overlay_event_breakpoint (); |
12038 | create_longjmp_master_breakpoint (); | |
12039 | create_std_terminate_master_breakpoint (); | |
186c406b | 12040 | create_exception_master_breakpoint (); |
1bfeeb0f JL |
12041 | |
12042 | /* While we're at it, reset the skip list too. */ | |
12043 | skip_re_set (); | |
c906108c SS |
12044 | } |
12045 | \f | |
c906108c SS |
12046 | /* Reset the thread number of this breakpoint: |
12047 | ||
12048 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 12049 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 12050 | void |
fba45db2 | 12051 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
12052 | { |
12053 | if (b->thread != -1) | |
12054 | { | |
39f77062 KB |
12055 | if (in_thread_list (inferior_ptid)) |
12056 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
12057 | |
12058 | /* We're being called after following a fork. The new fork is | |
12059 | selected as current, and unless this was a vfork will have a | |
12060 | different program space from the original thread. Reset that | |
12061 | as well. */ | |
12062 | b->loc->pspace = current_program_space; | |
c906108c SS |
12063 | } |
12064 | } | |
12065 | ||
03ac34d5 MS |
12066 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
12067 | If from_tty is nonzero, it prints a message to that effect, | |
12068 | which ends with a period (no newline). */ | |
12069 | ||
c906108c | 12070 | void |
fba45db2 | 12071 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 12072 | { |
52f0bd74 | 12073 | struct breakpoint *b; |
c906108c SS |
12074 | |
12075 | if (count < 0) | |
12076 | count = 0; | |
12077 | ||
12078 | ALL_BREAKPOINTS (b) | |
12079 | if (b->number == bptnum) | |
c5aa993b | 12080 | { |
d77f58be SS |
12081 | if (is_tracepoint (b)) |
12082 | { | |
12083 | if (from_tty && count != 0) | |
12084 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
12085 | bptnum); | |
12086 | return; | |
12087 | } | |
12088 | ||
c5aa993b | 12089 | b->ignore_count = count; |
221ea385 KS |
12090 | if (from_tty) |
12091 | { | |
12092 | if (count == 0) | |
3e43a32a MS |
12093 | printf_filtered (_("Will stop next time " |
12094 | "breakpoint %d is reached."), | |
221ea385 KS |
12095 | bptnum); |
12096 | else if (count == 1) | |
a3f17187 | 12097 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
12098 | bptnum); |
12099 | else | |
3e43a32a MS |
12100 | printf_filtered (_("Will ignore next %d " |
12101 | "crossings of breakpoint %d."), | |
221ea385 KS |
12102 | count, bptnum); |
12103 | } | |
c5aa993b | 12104 | breakpoints_changed (); |
8d3788bd | 12105 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
12106 | return; |
12107 | } | |
c906108c | 12108 | |
8a3fe4f8 | 12109 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
12110 | } |
12111 | ||
c906108c SS |
12112 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
12113 | ||
12114 | static void | |
fba45db2 | 12115 | ignore_command (char *args, int from_tty) |
c906108c SS |
12116 | { |
12117 | char *p = args; | |
52f0bd74 | 12118 | int num; |
c906108c SS |
12119 | |
12120 | if (p == 0) | |
e2e0b3e5 | 12121 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 12122 | |
c906108c | 12123 | num = get_number (&p); |
5c44784c | 12124 | if (num == 0) |
8a3fe4f8 | 12125 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 12126 | if (*p == 0) |
8a3fe4f8 | 12127 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
12128 | |
12129 | set_ignore_count (num, | |
12130 | longest_to_int (value_as_long (parse_and_eval (p))), | |
12131 | from_tty); | |
221ea385 KS |
12132 | if (from_tty) |
12133 | printf_filtered ("\n"); | |
c906108c SS |
12134 | } |
12135 | \f | |
12136 | /* Call FUNCTION on each of the breakpoints | |
12137 | whose numbers are given in ARGS. */ | |
12138 | ||
12139 | static void | |
95a42b64 TT |
12140 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
12141 | void *), | |
12142 | void *data) | |
c906108c | 12143 | { |
52f0bd74 AC |
12144 | int num; |
12145 | struct breakpoint *b, *tmp; | |
11cf8741 | 12146 | int match; |
197f0a60 | 12147 | struct get_number_or_range_state state; |
c906108c | 12148 | |
197f0a60 | 12149 | if (args == 0) |
e2e0b3e5 | 12150 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 12151 | |
197f0a60 TT |
12152 | init_number_or_range (&state, args); |
12153 | ||
12154 | while (!state.finished) | |
c906108c | 12155 | { |
197f0a60 TT |
12156 | char *p = state.string; |
12157 | ||
11cf8741 | 12158 | match = 0; |
c5aa993b | 12159 | |
197f0a60 | 12160 | num = get_number_or_range (&state); |
5c44784c | 12161 | if (num == 0) |
c5aa993b | 12162 | { |
8a3fe4f8 | 12163 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
12164 | } |
12165 | else | |
12166 | { | |
12167 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
12168 | if (b->number == num) | |
12169 | { | |
11cf8741 | 12170 | match = 1; |
cdac0397 | 12171 | function (b, data); |
11cf8741 | 12172 | break; |
5c44784c | 12173 | } |
11cf8741 | 12174 | if (match == 0) |
a3f17187 | 12175 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 12176 | } |
c906108c SS |
12177 | } |
12178 | } | |
12179 | ||
0d381245 VP |
12180 | static struct bp_location * |
12181 | find_location_by_number (char *number) | |
12182 | { | |
12183 | char *dot = strchr (number, '.'); | |
12184 | char *p1; | |
12185 | int bp_num; | |
12186 | int loc_num; | |
12187 | struct breakpoint *b; | |
12188 | struct bp_location *loc; | |
12189 | ||
12190 | *dot = '\0'; | |
12191 | ||
12192 | p1 = number; | |
197f0a60 | 12193 | bp_num = get_number (&p1); |
0d381245 VP |
12194 | if (bp_num == 0) |
12195 | error (_("Bad breakpoint number '%s'"), number); | |
12196 | ||
12197 | ALL_BREAKPOINTS (b) | |
12198 | if (b->number == bp_num) | |
12199 | { | |
12200 | break; | |
12201 | } | |
12202 | ||
12203 | if (!b || b->number != bp_num) | |
12204 | error (_("Bad breakpoint number '%s'"), number); | |
12205 | ||
12206 | p1 = dot+1; | |
197f0a60 | 12207 | loc_num = get_number (&p1); |
0d381245 VP |
12208 | if (loc_num == 0) |
12209 | error (_("Bad breakpoint location number '%s'"), number); | |
12210 | ||
12211 | --loc_num; | |
12212 | loc = b->loc; | |
12213 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
12214 | ; | |
12215 | if (!loc) | |
12216 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
12217 | ||
12218 | return loc; | |
12219 | } | |
12220 | ||
12221 | ||
1900040c MS |
12222 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
12223 | If from_tty is nonzero, it prints a message to that effect, | |
12224 | which ends with a period (no newline). */ | |
12225 | ||
c906108c | 12226 | void |
fba45db2 | 12227 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
12228 | { |
12229 | /* Never disable a watchpoint scope breakpoint; we want to | |
12230 | hit them when we leave scope so we can delete both the | |
12231 | watchpoint and its scope breakpoint at that time. */ | |
12232 | if (bpt->type == bp_watchpoint_scope) | |
12233 | return; | |
12234 | ||
c2c6d25f | 12235 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 12236 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
12237 | return; |
12238 | ||
b5de0fa7 | 12239 | bpt->enable_state = bp_disabled; |
c906108c | 12240 | |
d248b706 KY |
12241 | if (target_supports_enable_disable_tracepoint () |
12242 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12243 | { | |
12244 | struct bp_location *location; | |
12245 | ||
12246 | for (location = bpt->loc; location; location = location->next) | |
12247 | target_disable_tracepoint (location); | |
12248 | } | |
12249 | ||
b60e7edf | 12250 | update_global_location_list (0); |
c906108c | 12251 | |
8d3788bd | 12252 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12253 | } |
12254 | ||
51be5b68 PA |
12255 | /* A callback for iterate_over_related_breakpoints. */ |
12256 | ||
12257 | static void | |
12258 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12259 | { | |
12260 | disable_breakpoint (b); | |
12261 | } | |
12262 | ||
95a42b64 TT |
12263 | /* A callback for map_breakpoint_numbers that calls |
12264 | disable_breakpoint. */ | |
12265 | ||
12266 | static void | |
12267 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12268 | { | |
51be5b68 | 12269 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
12270 | } |
12271 | ||
c906108c | 12272 | static void |
fba45db2 | 12273 | disable_command (char *args, int from_tty) |
c906108c | 12274 | { |
c906108c | 12275 | if (args == 0) |
46c6471b PA |
12276 | { |
12277 | struct breakpoint *bpt; | |
12278 | ||
12279 | ALL_BREAKPOINTS (bpt) | |
12280 | if (user_breakpoint_p (bpt)) | |
12281 | disable_breakpoint (bpt); | |
12282 | } | |
0d381245 VP |
12283 | else if (strchr (args, '.')) |
12284 | { | |
12285 | struct bp_location *loc = find_location_by_number (args); | |
12286 | if (loc) | |
d248b706 KY |
12287 | { |
12288 | loc->enabled = 0; | |
12289 | if (target_supports_enable_disable_tracepoint () | |
12290 | && current_trace_status ()->running && loc->owner | |
12291 | && is_tracepoint (loc->owner)) | |
12292 | target_disable_tracepoint (loc); | |
12293 | } | |
b60e7edf | 12294 | update_global_location_list (0); |
0d381245 | 12295 | } |
c906108c | 12296 | else |
95a42b64 | 12297 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
12298 | } |
12299 | ||
12300 | static void | |
51be5b68 | 12301 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 12302 | { |
afe38095 | 12303 | int target_resources_ok; |
c906108c SS |
12304 | |
12305 | if (bpt->type == bp_hardware_breakpoint) | |
12306 | { | |
12307 | int i; | |
c5aa993b | 12308 | i = hw_breakpoint_used_count (); |
53a5351d | 12309 | target_resources_ok = |
d92524f1 | 12310 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 12311 | i + 1, 0); |
c906108c | 12312 | if (target_resources_ok == 0) |
8a3fe4f8 | 12313 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 12314 | else if (target_resources_ok < 0) |
8a3fe4f8 | 12315 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
12316 | } |
12317 | ||
cc60f2e3 | 12318 | if (is_watchpoint (bpt)) |
c906108c | 12319 | { |
d07205c2 JK |
12320 | /* Initialize it just to avoid a GCC false warning. */ |
12321 | enum enable_state orig_enable_state = 0; | |
dde02812 ES |
12322 | struct gdb_exception e; |
12323 | ||
12324 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 12325 | { |
3a5c3e22 PA |
12326 | struct watchpoint *w = (struct watchpoint *) bpt; |
12327 | ||
1e718ff1 TJB |
12328 | orig_enable_state = bpt->enable_state; |
12329 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 12330 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 12331 | } |
dde02812 | 12332 | if (e.reason < 0) |
c5aa993b | 12333 | { |
1e718ff1 | 12334 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
12335 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
12336 | bpt->number); | |
12337 | return; | |
c5aa993b | 12338 | } |
c906108c | 12339 | } |
0101ce28 | 12340 | |
b4c291bb KH |
12341 | if (bpt->enable_state != bp_permanent) |
12342 | bpt->enable_state = bp_enabled; | |
d248b706 KY |
12343 | |
12344 | if (target_supports_enable_disable_tracepoint () | |
12345 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12346 | { | |
12347 | struct bp_location *location; | |
12348 | ||
12349 | for (location = bpt->loc; location; location = location->next) | |
12350 | target_enable_tracepoint (location); | |
12351 | } | |
12352 | ||
b4c291bb | 12353 | bpt->disposition = disposition; |
b60e7edf | 12354 | update_global_location_list (1); |
b4c291bb KH |
12355 | breakpoints_changed (); |
12356 | ||
8d3788bd | 12357 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12358 | } |
12359 | ||
fe3f5fa8 | 12360 | |
c906108c | 12361 | void |
fba45db2 | 12362 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 12363 | { |
51be5b68 PA |
12364 | enable_breakpoint_disp (bpt, bpt->disposition); |
12365 | } | |
12366 | ||
12367 | static void | |
12368 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
12369 | { | |
12370 | enable_breakpoint (bpt); | |
c906108c SS |
12371 | } |
12372 | ||
95a42b64 TT |
12373 | /* A callback for map_breakpoint_numbers that calls |
12374 | enable_breakpoint. */ | |
12375 | ||
12376 | static void | |
12377 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
12378 | { | |
51be5b68 | 12379 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
12380 | } |
12381 | ||
c906108c SS |
12382 | /* The enable command enables the specified breakpoints (or all defined |
12383 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 12384 | in stopping the inferior. */ |
c906108c | 12385 | |
c906108c | 12386 | static void |
fba45db2 | 12387 | enable_command (char *args, int from_tty) |
c906108c | 12388 | { |
c906108c | 12389 | if (args == 0) |
46c6471b PA |
12390 | { |
12391 | struct breakpoint *bpt; | |
12392 | ||
12393 | ALL_BREAKPOINTS (bpt) | |
12394 | if (user_breakpoint_p (bpt)) | |
12395 | enable_breakpoint (bpt); | |
12396 | } | |
0d381245 VP |
12397 | else if (strchr (args, '.')) |
12398 | { | |
12399 | struct bp_location *loc = find_location_by_number (args); | |
12400 | if (loc) | |
d248b706 KY |
12401 | { |
12402 | loc->enabled = 1; | |
12403 | if (target_supports_enable_disable_tracepoint () | |
12404 | && current_trace_status ()->running && loc->owner | |
12405 | && is_tracepoint (loc->owner)) | |
12406 | target_enable_tracepoint (loc); | |
12407 | } | |
b60e7edf | 12408 | update_global_location_list (1); |
0d381245 | 12409 | } |
c906108c | 12410 | else |
95a42b64 | 12411 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
12412 | } |
12413 | ||
12414 | static void | |
51be5b68 PA |
12415 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
12416 | { | |
12417 | enum bpdisp disp = *(enum bpdisp *) arg; | |
12418 | ||
12419 | enable_breakpoint_disp (bpt, disp); | |
12420 | } | |
12421 | ||
12422 | static void | |
12423 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 12424 | { |
51be5b68 PA |
12425 | enum bpdisp disp = disp_disable; |
12426 | ||
12427 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12428 | } |
12429 | ||
c906108c | 12430 | static void |
fba45db2 | 12431 | enable_once_command (char *args, int from_tty) |
c906108c | 12432 | { |
51be5b68 | 12433 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
12434 | } |
12435 | ||
12436 | static void | |
51be5b68 | 12437 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 12438 | { |
51be5b68 PA |
12439 | enum bpdisp disp = disp_del; |
12440 | ||
12441 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12442 | } |
12443 | ||
c906108c | 12444 | static void |
fba45db2 | 12445 | enable_delete_command (char *args, int from_tty) |
c906108c | 12446 | { |
51be5b68 | 12447 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
12448 | } |
12449 | \f | |
fa8d40ab JJ |
12450 | static void |
12451 | set_breakpoint_cmd (char *args, int from_tty) | |
12452 | { | |
12453 | } | |
12454 | ||
12455 | static void | |
12456 | show_breakpoint_cmd (char *args, int from_tty) | |
12457 | { | |
12458 | } | |
12459 | ||
1f3b5d1b PP |
12460 | /* Invalidate last known value of any hardware watchpoint if |
12461 | the memory which that value represents has been written to by | |
12462 | GDB itself. */ | |
12463 | ||
12464 | static void | |
12465 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
12466 | const bfd_byte *data) | |
12467 | { | |
12468 | struct breakpoint *bp; | |
12469 | ||
12470 | ALL_BREAKPOINTS (bp) | |
12471 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 12472 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 12473 | { |
3a5c3e22 | 12474 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 12475 | |
3a5c3e22 PA |
12476 | if (wp->val_valid && wp->val) |
12477 | { | |
12478 | struct bp_location *loc; | |
12479 | ||
12480 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
12481 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
12482 | && loc->address + loc->length > addr | |
12483 | && addr + len > loc->address) | |
12484 | { | |
12485 | value_free (wp->val); | |
12486 | wp->val = NULL; | |
12487 | wp->val_valid = 0; | |
12488 | } | |
12489 | } | |
1f3b5d1b PP |
12490 | } |
12491 | } | |
12492 | ||
1bfeeb0f JL |
12493 | /* Use the last displayed codepoint's values, or nothing |
12494 | if they aren't valid. */ | |
c906108c SS |
12495 | |
12496 | struct symtabs_and_lines | |
fba45db2 | 12497 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
12498 | { |
12499 | struct symtabs_and_lines sals; | |
cc59ec59 | 12500 | |
c906108c | 12501 | if (string == 0) |
8a3fe4f8 | 12502 | error (_("Empty line specification.")); |
1bfeeb0f | 12503 | if (last_displayed_sal_is_valid ()) |
c906108c | 12504 | sals = decode_line_1 (&string, funfirstline, |
1bfeeb0f JL |
12505 | get_last_displayed_symtab (), |
12506 | get_last_displayed_line (), | |
58438ac1 | 12507 | NULL); |
c906108c SS |
12508 | else |
12509 | sals = decode_line_1 (&string, funfirstline, | |
58438ac1 | 12510 | (struct symtab *) NULL, 0, NULL); |
c906108c | 12511 | if (*string) |
8a3fe4f8 | 12512 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
12513 | return sals; |
12514 | } | |
8181d85f DJ |
12515 | |
12516 | /* Create and insert a raw software breakpoint at PC. Return an | |
12517 | identifier, which should be used to remove the breakpoint later. | |
12518 | In general, places which call this should be using something on the | |
12519 | breakpoint chain instead; this function should be eliminated | |
12520 | someday. */ | |
12521 | ||
12522 | void * | |
6c95b8df PA |
12523 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
12524 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
12525 | { |
12526 | struct bp_target_info *bp_tgt; | |
12527 | ||
6c95b8df | 12528 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 12529 | |
6c95b8df | 12530 | bp_tgt->placed_address_space = aspace; |
8181d85f | 12531 | bp_tgt->placed_address = pc; |
6c95b8df | 12532 | |
a6d9a66e | 12533 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
12534 | { |
12535 | /* Could not insert the breakpoint. */ | |
12536 | xfree (bp_tgt); | |
12537 | return NULL; | |
12538 | } | |
12539 | ||
12540 | return bp_tgt; | |
12541 | } | |
12542 | ||
4a64f543 MS |
12543 | /* Remove a breakpoint BP inserted by |
12544 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
12545 | |
12546 | int | |
a6d9a66e | 12547 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
12548 | { |
12549 | struct bp_target_info *bp_tgt = bp; | |
12550 | int ret; | |
12551 | ||
a6d9a66e | 12552 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
12553 | xfree (bp_tgt); |
12554 | ||
12555 | return ret; | |
12556 | } | |
12557 | ||
4a64f543 MS |
12558 | /* One (or perhaps two) breakpoints used for software single |
12559 | stepping. */ | |
8181d85f DJ |
12560 | |
12561 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 12562 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
12563 | |
12564 | /* Create and insert a breakpoint for software single step. */ | |
12565 | ||
12566 | void | |
6c95b8df | 12567 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
12568 | struct address_space *aspace, |
12569 | CORE_ADDR next_pc) | |
8181d85f DJ |
12570 | { |
12571 | void **bpt_p; | |
12572 | ||
12573 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
12574 | { |
12575 | bpt_p = &single_step_breakpoints[0]; | |
12576 | single_step_gdbarch[0] = gdbarch; | |
12577 | } | |
8181d85f DJ |
12578 | else |
12579 | { | |
12580 | gdb_assert (single_step_breakpoints[1] == NULL); | |
12581 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 12582 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
12583 | } |
12584 | ||
4a64f543 MS |
12585 | /* NOTE drow/2006-04-11: A future improvement to this function would |
12586 | be to only create the breakpoints once, and actually put them on | |
12587 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
12588 | We could adjust the addresses each time they were needed. Doing | |
12589 | this requires corresponding changes elsewhere where single step | |
12590 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 12591 | |
6c95b8df | 12592 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 12593 | if (*bpt_p == NULL) |
5af949e3 UW |
12594 | error (_("Could not insert single-step breakpoint at %s"), |
12595 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
12596 | } |
12597 | ||
f02253f1 HZ |
12598 | /* Check if the breakpoints used for software single stepping |
12599 | were inserted or not. */ | |
12600 | ||
12601 | int | |
12602 | single_step_breakpoints_inserted (void) | |
12603 | { | |
12604 | return (single_step_breakpoints[0] != NULL | |
12605 | || single_step_breakpoints[1] != NULL); | |
12606 | } | |
12607 | ||
8181d85f DJ |
12608 | /* Remove and delete any breakpoints used for software single step. */ |
12609 | ||
12610 | void | |
12611 | remove_single_step_breakpoints (void) | |
12612 | { | |
12613 | gdb_assert (single_step_breakpoints[0] != NULL); | |
12614 | ||
12615 | /* See insert_single_step_breakpoint for more about this deprecated | |
12616 | call. */ | |
a6d9a66e UW |
12617 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
12618 | single_step_breakpoints[0]); | |
12619 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
12620 | single_step_breakpoints[0] = NULL; |
12621 | ||
12622 | if (single_step_breakpoints[1] != NULL) | |
12623 | { | |
a6d9a66e UW |
12624 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
12625 | single_step_breakpoints[1]); | |
12626 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
12627 | single_step_breakpoints[1] = NULL; |
12628 | } | |
12629 | } | |
12630 | ||
d03285ec UW |
12631 | /* Delete software single step breakpoints without removing them from |
12632 | the inferior. This is intended to be used if the inferior's address | |
12633 | space where they were inserted is already gone, e.g. after exit or | |
12634 | exec. */ | |
12635 | ||
12636 | void | |
12637 | cancel_single_step_breakpoints (void) | |
12638 | { | |
12639 | int i; | |
12640 | ||
12641 | for (i = 0; i < 2; i++) | |
12642 | if (single_step_breakpoints[i]) | |
12643 | { | |
12644 | xfree (single_step_breakpoints[i]); | |
12645 | single_step_breakpoints[i] = NULL; | |
12646 | single_step_gdbarch[i] = NULL; | |
12647 | } | |
12648 | } | |
12649 | ||
12650 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
12651 | removing them. */ | |
12652 | ||
12653 | static void | |
12654 | detach_single_step_breakpoints (void) | |
12655 | { | |
12656 | int i; | |
12657 | ||
12658 | for (i = 0; i < 2; i++) | |
12659 | if (single_step_breakpoints[i]) | |
12660 | target_remove_breakpoint (single_step_gdbarch[i], | |
12661 | single_step_breakpoints[i]); | |
12662 | } | |
12663 | ||
4a64f543 MS |
12664 | /* Check whether a software single-step breakpoint is inserted at |
12665 | PC. */ | |
1aafd4da UW |
12666 | |
12667 | static int | |
cc59ec59 MS |
12668 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
12669 | CORE_ADDR pc) | |
1aafd4da UW |
12670 | { |
12671 | int i; | |
12672 | ||
12673 | for (i = 0; i < 2; i++) | |
12674 | { | |
12675 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
12676 | if (bp_tgt |
12677 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
12678 | bp_tgt->placed_address, | |
12679 | aspace, pc)) | |
1aafd4da UW |
12680 | return 1; |
12681 | } | |
12682 | ||
12683 | return 0; | |
12684 | } | |
12685 | ||
a96d9b2e SDJ |
12686 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
12687 | non-zero otherwise. */ | |
12688 | static int | |
12689 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
12690 | { | |
12691 | if (syscall_catchpoint_p (bp) | |
12692 | && bp->enable_state != bp_disabled | |
12693 | && bp->enable_state != bp_call_disabled) | |
12694 | return 1; | |
12695 | else | |
12696 | return 0; | |
12697 | } | |
12698 | ||
12699 | int | |
12700 | catch_syscall_enabled (void) | |
12701 | { | |
12702 | struct inferior *inf = current_inferior (); | |
12703 | ||
12704 | return inf->total_syscalls_count != 0; | |
12705 | } | |
12706 | ||
12707 | int | |
12708 | catching_syscall_number (int syscall_number) | |
12709 | { | |
12710 | struct breakpoint *bp; | |
12711 | ||
12712 | ALL_BREAKPOINTS (bp) | |
12713 | if (is_syscall_catchpoint_enabled (bp)) | |
12714 | { | |
be5c67c1 PA |
12715 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
12716 | ||
12717 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
12718 | { |
12719 | int i, iter; | |
12720 | for (i = 0; | |
be5c67c1 | 12721 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
12722 | i++) |
12723 | if (syscall_number == iter) | |
12724 | return 1; | |
12725 | } | |
12726 | else | |
12727 | return 1; | |
12728 | } | |
12729 | ||
12730 | return 0; | |
12731 | } | |
12732 | ||
12733 | /* Complete syscall names. Used by "catch syscall". */ | |
12734 | static char ** | |
12735 | catch_syscall_completer (struct cmd_list_element *cmd, | |
12736 | char *text, char *word) | |
12737 | { | |
12738 | const char **list = get_syscall_names (); | |
c38eea1a MS |
12739 | char **retlist |
12740 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 12741 | |
c38eea1a MS |
12742 | xfree (list); |
12743 | return retlist; | |
a96d9b2e SDJ |
12744 | } |
12745 | ||
1042e4c0 SS |
12746 | /* Tracepoint-specific operations. */ |
12747 | ||
12748 | /* Set tracepoint count to NUM. */ | |
12749 | static void | |
12750 | set_tracepoint_count (int num) | |
12751 | { | |
12752 | tracepoint_count = num; | |
4fa62494 | 12753 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
12754 | } |
12755 | ||
12756 | void | |
12757 | trace_command (char *arg, int from_tty) | |
12758 | { | |
8cdf0e15 VP |
12759 | if (create_breakpoint (get_current_arch (), |
12760 | arg, | |
12761 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12762 | 0 /* tempflag */, |
12763 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12764 | 0 /* Ignore count */, |
12765 | pending_break_support, | |
348d480f | 12766 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12767 | from_tty, |
84f4c1fe PM |
12768 | 1 /* enabled */, |
12769 | 0 /* internal */)) | |
fd9b8c24 | 12770 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
12771 | } |
12772 | ||
7a697b8d SS |
12773 | void |
12774 | ftrace_command (char *arg, int from_tty) | |
12775 | { | |
8cdf0e15 VP |
12776 | if (create_breakpoint (get_current_arch (), |
12777 | arg, | |
12778 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12779 | 0 /* tempflag */, |
12780 | bp_fast_tracepoint /* type_wanted */, | |
12781 | 0 /* Ignore count */, | |
12782 | pending_break_support, | |
348d480f | 12783 | &tracepoint_breakpoint_ops, |
0fb4aa4b | 12784 | from_tty, |
84f4c1fe PM |
12785 | 1 /* enabled */, |
12786 | 0 /* internal */)) | |
0fb4aa4b PA |
12787 | set_tracepoint_count (breakpoint_count); |
12788 | } | |
12789 | ||
12790 | /* strace command implementation. Creates a static tracepoint. */ | |
12791 | ||
12792 | void | |
12793 | strace_command (char *arg, int from_tty) | |
12794 | { | |
12795 | if (create_breakpoint (get_current_arch (), | |
12796 | arg, | |
12797 | NULL, 0, 1 /* parse arg */, | |
12798 | 0 /* tempflag */, | |
12799 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12800 | 0 /* Ignore count */, |
12801 | pending_break_support, | |
348d480f | 12802 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12803 | from_tty, |
84f4c1fe PM |
12804 | 1 /* enabled */, |
12805 | 0 /* internal */)) | |
fd9b8c24 | 12806 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
12807 | } |
12808 | ||
409873ef SS |
12809 | /* Set up a fake reader function that gets command lines from a linked |
12810 | list that was acquired during tracepoint uploading. */ | |
12811 | ||
12812 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 12813 | static int next_cmd; |
409873ef SS |
12814 | |
12815 | static char * | |
12816 | read_uploaded_action (void) | |
12817 | { | |
12818 | char *rslt; | |
12819 | ||
3149d8c1 | 12820 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 12821 | |
3149d8c1 | 12822 | next_cmd++; |
409873ef SS |
12823 | |
12824 | return rslt; | |
12825 | } | |
12826 | ||
00bf0b85 SS |
12827 | /* Given information about a tracepoint as recorded on a target (which |
12828 | can be either a live system or a trace file), attempt to create an | |
12829 | equivalent GDB tracepoint. This is not a reliable process, since | |
12830 | the target does not necessarily have all the information used when | |
12831 | the tracepoint was originally defined. */ | |
12832 | ||
d9b3f62e | 12833 | struct tracepoint * |
00bf0b85 | 12834 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 12835 | { |
409873ef | 12836 | char *addr_str, small_buf[100]; |
d9b3f62e | 12837 | struct tracepoint *tp; |
fd9b8c24 | 12838 | |
409873ef SS |
12839 | if (utp->at_string) |
12840 | addr_str = utp->at_string; | |
12841 | else | |
12842 | { | |
12843 | /* In the absence of a source location, fall back to raw | |
12844 | address. Since there is no way to confirm that the address | |
12845 | means the same thing as when the trace was started, warn the | |
12846 | user. */ | |
3e43a32a MS |
12847 | warning (_("Uploaded tracepoint %d has no " |
12848 | "source location, using raw address"), | |
409873ef SS |
12849 | utp->number); |
12850 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
12851 | addr_str = small_buf; | |
12852 | } | |
12853 | ||
12854 | /* There's not much we can do with a sequence of bytecodes. */ | |
12855 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
12856 | warning (_("Uploaded tracepoint %d condition " |
12857 | "has no source form, ignoring it"), | |
409873ef | 12858 | utp->number); |
d5551862 | 12859 | |
8cdf0e15 | 12860 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
12861 | addr_str, |
12862 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 12863 | 0 /* tempflag */, |
0fb4aa4b | 12864 | utp->type /* type_wanted */, |
8cdf0e15 VP |
12865 | 0 /* Ignore count */, |
12866 | pending_break_support, | |
348d480f | 12867 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12868 | 0 /* from_tty */, |
84f4c1fe PM |
12869 | utp->enabled /* enabled */, |
12870 | 0 /* internal */)) | |
fd9b8c24 PA |
12871 | return NULL; |
12872 | ||
00bf0b85 SS |
12873 | set_tracepoint_count (breakpoint_count); |
12874 | ||
409873ef | 12875 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
12876 | tp = get_tracepoint (tracepoint_count); |
12877 | gdb_assert (tp != NULL); | |
d5551862 | 12878 | |
00bf0b85 SS |
12879 | if (utp->pass > 0) |
12880 | { | |
d9b3f62e | 12881 | sprintf (small_buf, "%d %d", utp->pass, tp->base.number); |
00bf0b85 | 12882 | |
409873ef | 12883 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
12884 | } |
12885 | ||
409873ef SS |
12886 | /* If we have uploaded versions of the original commands, set up a |
12887 | special-purpose "reader" function and call the usual command line | |
12888 | reader, then pass the result to the breakpoint command-setting | |
12889 | function. */ | |
3149d8c1 | 12890 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 12891 | { |
409873ef | 12892 | struct command_line *cmd_list; |
00bf0b85 | 12893 | |
409873ef | 12894 | this_utp = utp; |
3149d8c1 | 12895 | next_cmd = 0; |
d5551862 | 12896 | |
409873ef SS |
12897 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
12898 | ||
d9b3f62e | 12899 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 12900 | } |
3149d8c1 SS |
12901 | else if (!VEC_empty (char_ptr, utp->actions) |
12902 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
12903 | warning (_("Uploaded tracepoint %d actions " |
12904 | "have no source form, ignoring them"), | |
409873ef | 12905 | utp->number); |
00bf0b85 SS |
12906 | |
12907 | return tp; | |
d9b3f62e | 12908 | } |
00bf0b85 | 12909 | |
1042e4c0 SS |
12910 | /* Print information on tracepoint number TPNUM_EXP, or all if |
12911 | omitted. */ | |
12912 | ||
12913 | static void | |
e5a67952 | 12914 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 12915 | { |
79a45e25 | 12916 | struct ui_out *uiout = current_uiout; |
e5a67952 | 12917 | int num_printed; |
1042e4c0 | 12918 | |
e5a67952 | 12919 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
12920 | |
12921 | if (num_printed == 0) | |
1042e4c0 | 12922 | { |
e5a67952 | 12923 | if (args == NULL || *args == '\0') |
d77f58be SS |
12924 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
12925 | else | |
e5a67952 | 12926 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 12927 | } |
ad443146 SS |
12928 | |
12929 | default_collect_info (); | |
1042e4c0 SS |
12930 | } |
12931 | ||
4a64f543 | 12932 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
12933 | Not supported by all targets. */ |
12934 | static void | |
12935 | enable_trace_command (char *args, int from_tty) | |
12936 | { | |
12937 | enable_command (args, from_tty); | |
12938 | } | |
12939 | ||
4a64f543 | 12940 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
12941 | Not supported by all targets. */ |
12942 | static void | |
12943 | disable_trace_command (char *args, int from_tty) | |
12944 | { | |
12945 | disable_command (args, from_tty); | |
12946 | } | |
12947 | ||
4a64f543 | 12948 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
12949 | static void |
12950 | delete_trace_command (char *arg, int from_tty) | |
12951 | { | |
35df4500 | 12952 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
12953 | |
12954 | dont_repeat (); | |
12955 | ||
12956 | if (arg == 0) | |
12957 | { | |
12958 | int breaks_to_delete = 0; | |
12959 | ||
12960 | /* Delete all breakpoints if no argument. | |
12961 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
12962 | have to be deleted with an explicit breakpoint number |
12963 | argument. */ | |
1042e4c0 | 12964 | ALL_TRACEPOINTS (b) |
46c6471b | 12965 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
12966 | { |
12967 | breaks_to_delete = 1; | |
12968 | break; | |
12969 | } | |
1042e4c0 SS |
12970 | |
12971 | /* Ask user only if there are some breakpoints to delete. */ | |
12972 | if (!from_tty | |
12973 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
12974 | { | |
35df4500 | 12975 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 12976 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 12977 | delete_breakpoint (b); |
1042e4c0 SS |
12978 | } |
12979 | } | |
12980 | else | |
51be5b68 | 12981 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
12982 | } |
12983 | ||
197f0a60 TT |
12984 | /* Helper function for trace_pass_command. */ |
12985 | ||
12986 | static void | |
d9b3f62e | 12987 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 12988 | { |
d9b3f62e PA |
12989 | tp->pass_count = count; |
12990 | observer_notify_tracepoint_modified (tp->base.number); | |
197f0a60 TT |
12991 | if (from_tty) |
12992 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 12993 | tp->base.number, count); |
197f0a60 TT |
12994 | } |
12995 | ||
1042e4c0 SS |
12996 | /* Set passcount for tracepoint. |
12997 | ||
12998 | First command argument is passcount, second is tracepoint number. | |
12999 | If tracepoint number omitted, apply to most recently defined. | |
13000 | Also accepts special argument "all". */ | |
13001 | ||
13002 | static void | |
13003 | trace_pass_command (char *args, int from_tty) | |
13004 | { | |
d9b3f62e | 13005 | struct tracepoint *t1; |
1042e4c0 | 13006 | unsigned int count; |
1042e4c0 SS |
13007 | |
13008 | if (args == 0 || *args == 0) | |
3e43a32a MS |
13009 | error (_("passcount command requires an " |
13010 | "argument (count + optional TP num)")); | |
1042e4c0 | 13011 | |
4a64f543 | 13012 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
13013 | |
13014 | while (*args && isspace ((int) *args)) | |
13015 | args++; | |
13016 | ||
13017 | if (*args && strncasecmp (args, "all", 3) == 0) | |
13018 | { | |
d9b3f62e PA |
13019 | struct breakpoint *b; |
13020 | ||
1042e4c0 | 13021 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
13022 | if (*args) |
13023 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 13024 | |
d9b3f62e | 13025 | ALL_TRACEPOINTS (b) |
197f0a60 | 13026 | { |
d9b3f62e | 13027 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
13028 | trace_pass_set_count (t1, count, from_tty); |
13029 | } | |
13030 | } | |
13031 | else if (*args == '\0') | |
1042e4c0 | 13032 | { |
197f0a60 | 13033 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 13034 | if (t1) |
197f0a60 TT |
13035 | trace_pass_set_count (t1, count, from_tty); |
13036 | } | |
13037 | else | |
13038 | { | |
13039 | struct get_number_or_range_state state; | |
13040 | ||
13041 | init_number_or_range (&state, args); | |
13042 | while (!state.finished) | |
1042e4c0 | 13043 | { |
197f0a60 TT |
13044 | t1 = get_tracepoint_by_number (&args, &state, 1); |
13045 | if (t1) | |
13046 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
13047 | } |
13048 | } | |
1042e4c0 SS |
13049 | } |
13050 | ||
d9b3f62e | 13051 | struct tracepoint * |
1042e4c0 SS |
13052 | get_tracepoint (int num) |
13053 | { | |
13054 | struct breakpoint *t; | |
13055 | ||
13056 | ALL_TRACEPOINTS (t) | |
13057 | if (t->number == num) | |
d9b3f62e | 13058 | return (struct tracepoint *) t; |
1042e4c0 SS |
13059 | |
13060 | return NULL; | |
13061 | } | |
13062 | ||
d5551862 SS |
13063 | /* Find the tracepoint with the given target-side number (which may be |
13064 | different from the tracepoint number after disconnecting and | |
13065 | reconnecting). */ | |
13066 | ||
d9b3f62e | 13067 | struct tracepoint * |
d5551862 SS |
13068 | get_tracepoint_by_number_on_target (int num) |
13069 | { | |
d9b3f62e | 13070 | struct breakpoint *b; |
d5551862 | 13071 | |
d9b3f62e PA |
13072 | ALL_TRACEPOINTS (b) |
13073 | { | |
13074 | struct tracepoint *t = (struct tracepoint *) b; | |
13075 | ||
13076 | if (t->number_on_target == num) | |
13077 | return t; | |
13078 | } | |
d5551862 SS |
13079 | |
13080 | return NULL; | |
13081 | } | |
13082 | ||
1042e4c0 | 13083 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
13084 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
13085 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 13086 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 13087 | struct tracepoint * |
197f0a60 TT |
13088 | get_tracepoint_by_number (char **arg, |
13089 | struct get_number_or_range_state *state, | |
13090 | int optional_p) | |
1042e4c0 SS |
13091 | { |
13092 | extern int tracepoint_count; | |
13093 | struct breakpoint *t; | |
13094 | int tpnum; | |
13095 | char *instring = arg == NULL ? NULL : *arg; | |
13096 | ||
197f0a60 TT |
13097 | if (state) |
13098 | { | |
13099 | gdb_assert (!state->finished); | |
13100 | tpnum = get_number_or_range (state); | |
13101 | } | |
13102 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
13103 | { |
13104 | if (optional_p) | |
13105 | tpnum = tracepoint_count; | |
13106 | else | |
13107 | error_no_arg (_("tracepoint number")); | |
13108 | } | |
13109 | else | |
197f0a60 | 13110 | tpnum = get_number (arg); |
1042e4c0 SS |
13111 | |
13112 | if (tpnum <= 0) | |
13113 | { | |
13114 | if (instring && *instring) | |
13115 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
13116 | instring); | |
13117 | else | |
3e43a32a MS |
13118 | printf_filtered (_("Tracepoint argument missing " |
13119 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
13120 | return NULL; |
13121 | } | |
13122 | ||
13123 | ALL_TRACEPOINTS (t) | |
13124 | if (t->number == tpnum) | |
13125 | { | |
d9b3f62e | 13126 | return (struct tracepoint *) t; |
1042e4c0 SS |
13127 | } |
13128 | ||
1042e4c0 SS |
13129 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
13130 | return NULL; | |
13131 | } | |
13132 | ||
d9b3f62e PA |
13133 | void |
13134 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
13135 | { | |
13136 | if (b->thread != -1) | |
13137 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
13138 | ||
13139 | if (b->task != 0) | |
13140 | fprintf_unfiltered (fp, " task %d", b->task); | |
13141 | ||
13142 | fprintf_unfiltered (fp, "\n"); | |
13143 | } | |
13144 | ||
6149aea9 PA |
13145 | /* Save information on user settable breakpoints (watchpoints, etc) to |
13146 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
13147 | on each breakpoint and only include the ones for which it returns | |
13148 | non-zero. */ | |
13149 | ||
1042e4c0 | 13150 | static void |
6149aea9 PA |
13151 | save_breakpoints (char *filename, int from_tty, |
13152 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
13153 | { |
13154 | struct breakpoint *tp; | |
6149aea9 | 13155 | int any = 0; |
a7bdde9e | 13156 | char *pathname; |
1042e4c0 | 13157 | struct cleanup *cleanup; |
a7bdde9e | 13158 | struct ui_file *fp; |
6149aea9 | 13159 | int extra_trace_bits = 0; |
1042e4c0 | 13160 | |
6149aea9 PA |
13161 | if (filename == 0 || *filename == 0) |
13162 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
13163 | |
13164 | /* See if we have anything to save. */ | |
6149aea9 | 13165 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13166 | { |
6149aea9 | 13167 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13168 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
13169 | continue; |
13170 | ||
13171 | /* If we have a filter, only save the breakpoints it accepts. */ | |
13172 | if (filter && !filter (tp)) | |
13173 | continue; | |
13174 | ||
13175 | any = 1; | |
13176 | ||
13177 | if (is_tracepoint (tp)) | |
13178 | { | |
13179 | extra_trace_bits = 1; | |
13180 | ||
13181 | /* We can stop searching. */ | |
13182 | break; | |
13183 | } | |
1042e4c0 | 13184 | } |
6149aea9 PA |
13185 | |
13186 | if (!any) | |
1042e4c0 | 13187 | { |
6149aea9 | 13188 | warning (_("Nothing to save.")); |
1042e4c0 SS |
13189 | return; |
13190 | } | |
13191 | ||
6149aea9 | 13192 | pathname = tilde_expand (filename); |
1042e4c0 | 13193 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 13194 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 13195 | if (!fp) |
6149aea9 PA |
13196 | error (_("Unable to open file '%s' for saving (%s)"), |
13197 | filename, safe_strerror (errno)); | |
a7bdde9e | 13198 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 13199 | |
6149aea9 PA |
13200 | if (extra_trace_bits) |
13201 | save_trace_state_variables (fp); | |
8bf6485c | 13202 | |
6149aea9 | 13203 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13204 | { |
6149aea9 | 13205 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13206 | if (!user_breakpoint_p (tp)) |
6149aea9 | 13207 | continue; |
8bf6485c | 13208 | |
6149aea9 PA |
13209 | /* If we have a filter, only save the breakpoints it accepts. */ |
13210 | if (filter && !filter (tp)) | |
13211 | continue; | |
13212 | ||
348d480f | 13213 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 13214 | |
6149aea9 PA |
13215 | /* Note, we can't rely on tp->number for anything, as we can't |
13216 | assume the recreated breakpoint numbers will match. Use $bpnum | |
13217 | instead. */ | |
13218 | ||
13219 | if (tp->cond_string) | |
13220 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
13221 | ||
13222 | if (tp->ignore_count) | |
13223 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
13224 | ||
a7bdde9e | 13225 | if (tp->commands) |
1042e4c0 | 13226 | { |
a7bdde9e VP |
13227 | volatile struct gdb_exception ex; |
13228 | ||
6149aea9 | 13229 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 13230 | |
79a45e25 | 13231 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 13232 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 13233 | { |
79a45e25 | 13234 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 13235 | } |
79a45e25 | 13236 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 13237 | |
a7bdde9e VP |
13238 | if (ex.reason < 0) |
13239 | throw_exception (ex); | |
1042e4c0 | 13240 | |
a7bdde9e | 13241 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 13242 | } |
6149aea9 PA |
13243 | |
13244 | if (tp->enable_state == bp_disabled) | |
13245 | fprintf_unfiltered (fp, "disable\n"); | |
13246 | ||
13247 | /* If this is a multi-location breakpoint, check if the locations | |
13248 | should be individually disabled. Watchpoint locations are | |
13249 | special, and not user visible. */ | |
13250 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
13251 | { | |
13252 | struct bp_location *loc; | |
13253 | int n = 1; | |
13254 | ||
13255 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
13256 | if (!loc->enabled) | |
13257 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
13258 | } | |
1042e4c0 | 13259 | } |
8bf6485c | 13260 | |
6149aea9 | 13261 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
13262 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
13263 | ||
1042e4c0 SS |
13264 | do_cleanups (cleanup); |
13265 | if (from_tty) | |
6149aea9 PA |
13266 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
13267 | } | |
13268 | ||
13269 | /* The `save breakpoints' command. */ | |
13270 | ||
13271 | static void | |
13272 | save_breakpoints_command (char *args, int from_tty) | |
13273 | { | |
13274 | save_breakpoints (args, from_tty, NULL); | |
13275 | } | |
13276 | ||
13277 | /* The `save tracepoints' command. */ | |
13278 | ||
13279 | static void | |
13280 | save_tracepoints_command (char *args, int from_tty) | |
13281 | { | |
13282 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
13283 | } |
13284 | ||
13285 | /* Create a vector of all tracepoints. */ | |
13286 | ||
13287 | VEC(breakpoint_p) * | |
eeae04df | 13288 | all_tracepoints (void) |
1042e4c0 SS |
13289 | { |
13290 | VEC(breakpoint_p) *tp_vec = 0; | |
13291 | struct breakpoint *tp; | |
13292 | ||
13293 | ALL_TRACEPOINTS (tp) | |
13294 | { | |
13295 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
13296 | } | |
13297 | ||
13298 | return tp_vec; | |
13299 | } | |
13300 | ||
c906108c | 13301 | \f |
4a64f543 MS |
13302 | /* This help string is used for the break, hbreak, tbreak and thbreak |
13303 | commands. It is defined as a macro to prevent duplication. | |
13304 | COMMAND should be a string constant containing the name of the | |
13305 | command. */ | |
31e2b00f AS |
13306 | #define BREAK_ARGS_HELP(command) \ |
13307 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
13308 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
13309 | If a line number is specified, break at start of code for that line.\n\ | |
13310 | If a function is specified, break at start of code for that function.\n\ | |
13311 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
13312 | With no LOCATION, uses current execution address of the selected\n\ |
13313 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
13314 | \n\ |
13315 | THREADNUM is the number from \"info threads\".\n\ | |
13316 | CONDITION is a boolean expression.\n\ | |
13317 | \n\ | |
d41c0fc8 PA |
13318 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
13319 | conditions are different.\n\ | |
31e2b00f AS |
13320 | \n\ |
13321 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
13322 | ||
44feb3ce TT |
13323 | /* List of subcommands for "catch". */ |
13324 | static struct cmd_list_element *catch_cmdlist; | |
13325 | ||
13326 | /* List of subcommands for "tcatch". */ | |
13327 | static struct cmd_list_element *tcatch_cmdlist; | |
13328 | ||
9ac4176b | 13329 | void |
44feb3ce TT |
13330 | add_catch_command (char *name, char *docstring, |
13331 | void (*sfunc) (char *args, int from_tty, | |
13332 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
13333 | char **(*completer) (struct cmd_list_element *cmd, |
13334 | char *text, char *word), | |
44feb3ce TT |
13335 | void *user_data_catch, |
13336 | void *user_data_tcatch) | |
13337 | { | |
13338 | struct cmd_list_element *command; | |
13339 | ||
13340 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13341 | &catch_cmdlist); | |
13342 | set_cmd_sfunc (command, sfunc); | |
13343 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 13344 | set_cmd_completer (command, completer); |
44feb3ce TT |
13345 | |
13346 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13347 | &tcatch_cmdlist); | |
13348 | set_cmd_sfunc (command, sfunc); | |
13349 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 13350 | set_cmd_completer (command, completer); |
44feb3ce TT |
13351 | } |
13352 | ||
6c95b8df | 13353 | static void |
a79b8f6e | 13354 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 13355 | { |
6c95b8df PA |
13356 | inf->total_syscalls_count = 0; |
13357 | inf->any_syscall_count = 0; | |
13358 | VEC_free (int, inf->syscalls_counts); | |
13359 | } | |
13360 | ||
6149aea9 PA |
13361 | static void |
13362 | save_command (char *arg, int from_tty) | |
13363 | { | |
3e43a32a MS |
13364 | printf_unfiltered (_("\"save\" must be followed by " |
13365 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
13366 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
13367 | } | |
13368 | ||
84f4c1fe PM |
13369 | struct breakpoint * |
13370 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
13371 | void *data) | |
13372 | { | |
35df4500 | 13373 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 13374 | |
35df4500 | 13375 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
13376 | { |
13377 | if ((*callback) (b, data)) | |
13378 | return b; | |
13379 | } | |
13380 | ||
13381 | return NULL; | |
13382 | } | |
13383 | ||
0574c78f GB |
13384 | /* Zero if any of the breakpoint's locations could be a location where |
13385 | functions have been inlined, nonzero otherwise. */ | |
13386 | ||
13387 | static int | |
13388 | is_non_inline_function (struct breakpoint *b) | |
13389 | { | |
13390 | /* The shared library event breakpoint is set on the address of a | |
13391 | non-inline function. */ | |
13392 | if (b->type == bp_shlib_event) | |
13393 | return 1; | |
13394 | ||
13395 | return 0; | |
13396 | } | |
13397 | ||
13398 | /* Nonzero if the specified PC cannot be a location where functions | |
13399 | have been inlined. */ | |
13400 | ||
13401 | int | |
13402 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc) | |
13403 | { | |
13404 | struct breakpoint *b; | |
13405 | struct bp_location *bl; | |
13406 | ||
13407 | ALL_BREAKPOINTS (b) | |
13408 | { | |
13409 | if (!is_non_inline_function (b)) | |
13410 | continue; | |
13411 | ||
13412 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
13413 | { | |
13414 | if (!bl->shlib_disabled | |
13415 | && bpstat_check_location (bl, aspace, pc)) | |
13416 | return 1; | |
13417 | } | |
13418 | } | |
13419 | ||
13420 | return 0; | |
13421 | } | |
13422 | ||
2060206e PA |
13423 | void |
13424 | initialize_breakpoint_ops (void) | |
13425 | { | |
13426 | static int initialized = 0; | |
13427 | ||
13428 | struct breakpoint_ops *ops; | |
13429 | ||
13430 | if (initialized) | |
13431 | return; | |
13432 | initialized = 1; | |
13433 | ||
13434 | /* The breakpoint_ops structure to be inherit by all kinds of | |
13435 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
13436 | internal and momentary breakpoints, etc.). */ | |
13437 | ops = &bkpt_base_breakpoint_ops; | |
13438 | *ops = base_breakpoint_ops; | |
13439 | ops->re_set = bkpt_re_set; | |
13440 | ops->insert_location = bkpt_insert_location; | |
13441 | ops->remove_location = bkpt_remove_location; | |
13442 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
13443 | ||
13444 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
13445 | ops = &bkpt_breakpoint_ops; | |
13446 | *ops = bkpt_base_breakpoint_ops; | |
13447 | ops->re_set = bkpt_re_set; | |
13448 | ops->resources_needed = bkpt_resources_needed; | |
13449 | ops->print_it = bkpt_print_it; | |
13450 | ops->print_mention = bkpt_print_mention; | |
13451 | ops->print_recreate = bkpt_print_recreate; | |
13452 | ||
13453 | /* Ranged breakpoints. */ | |
13454 | ops = &ranged_breakpoint_ops; | |
13455 | *ops = bkpt_breakpoint_ops; | |
13456 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
13457 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
13458 | ops->print_it = print_it_ranged_breakpoint; | |
13459 | ops->print_one = print_one_ranged_breakpoint; | |
13460 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
13461 | ops->print_mention = print_mention_ranged_breakpoint; | |
13462 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
13463 | ||
13464 | /* Internal breakpoints. */ | |
13465 | ops = &internal_breakpoint_ops; | |
13466 | *ops = bkpt_base_breakpoint_ops; | |
13467 | ops->re_set = internal_bkpt_re_set; | |
13468 | ops->check_status = internal_bkpt_check_status; | |
13469 | ops->print_it = internal_bkpt_print_it; | |
13470 | ops->print_mention = internal_bkpt_print_mention; | |
13471 | ||
13472 | /* Momentary breakpoints. */ | |
13473 | ops = &momentary_breakpoint_ops; | |
13474 | *ops = bkpt_base_breakpoint_ops; | |
13475 | ops->re_set = momentary_bkpt_re_set; | |
13476 | ops->check_status = momentary_bkpt_check_status; | |
13477 | ops->print_it = momentary_bkpt_print_it; | |
13478 | ops->print_mention = momentary_bkpt_print_mention; | |
13479 | ||
13480 | /* GNU v3 exception catchpoints. */ | |
13481 | ops = &gnu_v3_exception_catchpoint_ops; | |
13482 | *ops = bkpt_breakpoint_ops; | |
13483 | ops->print_it = print_it_exception_catchpoint; | |
13484 | ops->print_one = print_one_exception_catchpoint; | |
13485 | ops->print_mention = print_mention_exception_catchpoint; | |
13486 | ops->print_recreate = print_recreate_exception_catchpoint; | |
13487 | ||
13488 | /* Watchpoints. */ | |
13489 | ops = &watchpoint_breakpoint_ops; | |
13490 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 13491 | ops->dtor = dtor_watchpoint; |
2060206e PA |
13492 | ops->re_set = re_set_watchpoint; |
13493 | ops->insert_location = insert_watchpoint; | |
13494 | ops->remove_location = remove_watchpoint; | |
13495 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
13496 | ops->check_status = check_status_watchpoint; | |
13497 | ops->resources_needed = resources_needed_watchpoint; | |
13498 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
13499 | ops->print_it = print_it_watchpoint; | |
13500 | ops->print_mention = print_mention_watchpoint; | |
13501 | ops->print_recreate = print_recreate_watchpoint; | |
13502 | ||
13503 | /* Masked watchpoints. */ | |
13504 | ops = &masked_watchpoint_breakpoint_ops; | |
13505 | *ops = watchpoint_breakpoint_ops; | |
13506 | ops->insert_location = insert_masked_watchpoint; | |
13507 | ops->remove_location = remove_masked_watchpoint; | |
13508 | ops->resources_needed = resources_needed_masked_watchpoint; | |
13509 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
13510 | ops->print_it = print_it_masked_watchpoint; | |
13511 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
13512 | ops->print_mention = print_mention_masked_watchpoint; | |
13513 | ops->print_recreate = print_recreate_masked_watchpoint; | |
13514 | ||
13515 | /* Tracepoints. */ | |
13516 | ops = &tracepoint_breakpoint_ops; | |
13517 | *ops = base_breakpoint_ops; | |
13518 | ops->re_set = tracepoint_re_set; | |
13519 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
13520 | ops->print_one_detail = tracepoint_print_one_detail; | |
13521 | ops->print_mention = tracepoint_print_mention; | |
13522 | ops->print_recreate = tracepoint_print_recreate; | |
13523 | ||
13524 | /* Fork catchpoints. */ | |
13525 | ops = &catch_fork_breakpoint_ops; | |
13526 | *ops = base_breakpoint_ops; | |
13527 | ops->insert_location = insert_catch_fork; | |
13528 | ops->remove_location = remove_catch_fork; | |
13529 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
13530 | ops->print_it = print_it_catch_fork; | |
13531 | ops->print_one = print_one_catch_fork; | |
13532 | ops->print_mention = print_mention_catch_fork; | |
13533 | ops->print_recreate = print_recreate_catch_fork; | |
13534 | ||
13535 | /* Vfork catchpoints. */ | |
13536 | ops = &catch_vfork_breakpoint_ops; | |
13537 | *ops = base_breakpoint_ops; | |
13538 | ops->insert_location = insert_catch_vfork; | |
13539 | ops->remove_location = remove_catch_vfork; | |
13540 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
13541 | ops->print_it = print_it_catch_vfork; | |
13542 | ops->print_one = print_one_catch_vfork; | |
13543 | ops->print_mention = print_mention_catch_vfork; | |
13544 | ops->print_recreate = print_recreate_catch_vfork; | |
13545 | ||
13546 | /* Exec catchpoints. */ | |
13547 | ops = &catch_exec_breakpoint_ops; | |
13548 | *ops = base_breakpoint_ops; | |
13549 | ops->dtor = dtor_catch_exec; | |
13550 | ops->insert_location = insert_catch_exec; | |
13551 | ops->remove_location = remove_catch_exec; | |
13552 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
13553 | ops->print_it = print_it_catch_exec; | |
13554 | ops->print_one = print_one_catch_exec; | |
13555 | ops->print_mention = print_mention_catch_exec; | |
13556 | ops->print_recreate = print_recreate_catch_exec; | |
13557 | ||
13558 | /* Syscall catchpoints. */ | |
13559 | ops = &catch_syscall_breakpoint_ops; | |
13560 | *ops = base_breakpoint_ops; | |
13561 | ops->dtor = dtor_catch_syscall; | |
13562 | ops->insert_location = insert_catch_syscall; | |
13563 | ops->remove_location = remove_catch_syscall; | |
13564 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
13565 | ops->print_it = print_it_catch_syscall; | |
13566 | ops->print_one = print_one_catch_syscall; | |
13567 | ops->print_mention = print_mention_catch_syscall; | |
13568 | ops->print_recreate = print_recreate_catch_syscall; | |
13569 | } | |
13570 | ||
c906108c | 13571 | void |
fba45db2 | 13572 | _initialize_breakpoint (void) |
c906108c SS |
13573 | { |
13574 | struct cmd_list_element *c; | |
13575 | ||
2060206e PA |
13576 | initialize_breakpoint_ops (); |
13577 | ||
84acb35a | 13578 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 13579 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 13580 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 13581 | |
17450429 PP |
13582 | breakpoint_objfile_key = register_objfile_data (); |
13583 | ||
c906108c SS |
13584 | breakpoint_chain = 0; |
13585 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
13586 | before a breakpoint is set. */ | |
13587 | breakpoint_count = 0; | |
13588 | ||
1042e4c0 SS |
13589 | tracepoint_count = 0; |
13590 | ||
1bedd215 AC |
13591 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
13592 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
13593 | Usage is `ignore N COUNT'.")); | |
c906108c | 13594 | if (xdb_commands) |
c5aa993b | 13595 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 13596 | |
1bedd215 AC |
13597 | add_com ("commands", class_breakpoint, commands_command, _("\ |
13598 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
13599 | Give breakpoint number as argument after \"commands\".\n\ |
13600 | With no argument, the targeted breakpoint is the last one set.\n\ | |
13601 | The commands themselves follow starting on the next line.\n\ | |
13602 | Type a line containing \"end\" to indicate the end of them.\n\ | |
13603 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 13604 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 13605 | |
1bedd215 AC |
13606 | add_com ("condition", class_breakpoint, condition_command, _("\ |
13607 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 13608 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 13609 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 13610 | |
1bedd215 | 13611 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 13612 | Set a temporary breakpoint.\n\ |
c906108c SS |
13613 | Like \"break\" except the breakpoint is only temporary,\n\ |
13614 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
13615 | by using \"enable delete\" on the breakpoint number.\n\ |
13616 | \n" | |
13617 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 13618 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13619 | |
1bedd215 | 13620 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 13621 | Set a hardware assisted breakpoint.\n\ |
c906108c | 13622 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
13623 | some target hardware may not have this support.\n\ |
13624 | \n" | |
13625 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 13626 | set_cmd_completer (c, location_completer); |
c906108c | 13627 | |
1bedd215 | 13628 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 13629 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 13630 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
13631 | so it will be deleted when hit.\n\ |
13632 | \n" | |
13633 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 13634 | set_cmd_completer (c, location_completer); |
c906108c | 13635 | |
1bedd215 AC |
13636 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
13637 | Enable some breakpoints.\n\ | |
c906108c SS |
13638 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13639 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13640 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13641 | With a subcommand you can enable temporarily."), |
c906108c SS |
13642 | &enablelist, "enable ", 1, &cmdlist); |
13643 | if (xdb_commands) | |
1bedd215 AC |
13644 | add_com ("ab", class_breakpoint, enable_command, _("\ |
13645 | Enable some breakpoints.\n\ | |
c906108c SS |
13646 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13647 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13648 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13649 | With a subcommand you can enable temporarily.")); |
c906108c SS |
13650 | |
13651 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
13652 | ||
84951ab5 | 13653 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 13654 | Enable some breakpoints.\n\ |
c906108c SS |
13655 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13656 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13657 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 13658 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 13659 | |
1a966eab AC |
13660 | add_cmd ("once", no_class, enable_once_command, _("\ |
13661 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13662 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13663 | &enablebreaklist); |
13664 | ||
1a966eab AC |
13665 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13666 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13667 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13668 | &enablebreaklist); |
13669 | ||
1a966eab AC |
13670 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13671 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13672 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13673 | &enablelist); |
13674 | ||
1a966eab AC |
13675 | add_cmd ("once", no_class, enable_once_command, _("\ |
13676 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13677 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13678 | &enablelist); |
13679 | ||
1bedd215 AC |
13680 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
13681 | Disable some breakpoints.\n\ | |
c906108c SS |
13682 | Arguments are breakpoint numbers with spaces in between.\n\ |
13683 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13684 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
13685 | &disablelist, "disable ", 1, &cmdlist); |
13686 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
13687 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
13688 | if (xdb_commands) | |
1bedd215 AC |
13689 | add_com ("sb", class_breakpoint, disable_command, _("\ |
13690 | Disable some breakpoints.\n\ | |
c906108c SS |
13691 | Arguments are breakpoint numbers with spaces in between.\n\ |
13692 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13693 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 13694 | |
1a966eab AC |
13695 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
13696 | Disable some breakpoints.\n\ | |
c906108c SS |
13697 | Arguments are breakpoint numbers with spaces in between.\n\ |
13698 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13699 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 13700 | This command may be abbreviated \"disable\"."), |
c906108c SS |
13701 | &disablelist); |
13702 | ||
1bedd215 AC |
13703 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
13704 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13705 | Arguments are breakpoint numbers with spaces in between.\n\ |
13706 | To delete all breakpoints, give no argument.\n\ | |
13707 | \n\ | |
13708 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 13709 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
13710 | &deletelist, "delete ", 1, &cmdlist); |
13711 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 13712 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 13713 | if (xdb_commands) |
1bedd215 AC |
13714 | add_com ("db", class_breakpoint, delete_command, _("\ |
13715 | Delete some breakpoints.\n\ | |
c906108c | 13716 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 13717 | To delete all breakpoints, give no argument.\n")); |
c906108c | 13718 | |
1a966eab AC |
13719 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
13720 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13721 | Arguments are breakpoint numbers with spaces in between.\n\ |
13722 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 13723 | This command may be abbreviated \"delete\"."), |
c906108c SS |
13724 | &deletelist); |
13725 | ||
1bedd215 AC |
13726 | add_com ("clear", class_breakpoint, clear_command, _("\ |
13727 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
13728 | Argument may be line number, function name, or \"*\" and an address.\n\ |
13729 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
13730 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
13731 | If an address is specified, breakpoints at that address are cleared.\n\ |
13732 | \n\ | |
13733 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
13734 | is executing in.\n\ |
13735 | \n\ | |
1bedd215 | 13736 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 13737 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 13738 | |
1bedd215 | 13739 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
13740 | Set breakpoint at specified line or function.\n" |
13741 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 13742 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13743 | |
c906108c SS |
13744 | add_com_alias ("b", "break", class_run, 1); |
13745 | add_com_alias ("br", "break", class_run, 1); | |
13746 | add_com_alias ("bre", "break", class_run, 1); | |
13747 | add_com_alias ("brea", "break", class_run, 1); | |
13748 | ||
7681d515 PM |
13749 | if (xdb_commands) |
13750 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
13751 | |
13752 | if (dbx_commands) | |
13753 | { | |
1bedd215 AC |
13754 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
13755 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
13756 | &stoplist, "stop ", 1, &cmdlist); |
13757 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 13758 | _("Break in function or address."), &stoplist); |
c5aa993b | 13759 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 13760 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
13761 | add_com ("status", class_info, breakpoints_info, _("\ |
13762 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13763 | The \"Type\" column indicates one of:\n\ |
13764 | \tbreakpoint - normal breakpoint\n\ | |
13765 | \twatchpoint - watchpoint\n\ | |
13766 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13767 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13768 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13769 | address and file/line number respectively.\n\ |
13770 | \n\ | |
13771 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13772 | are set to the address of the last breakpoint listed unless the command\n\ |
13773 | is prefixed with \"server \".\n\n\ | |
c906108c | 13774 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13775 | breakpoint set.")); |
c906108c SS |
13776 | } |
13777 | ||
1bedd215 | 13778 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 13779 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
13780 | The \"Type\" column indicates one of:\n\ |
13781 | \tbreakpoint - normal breakpoint\n\ | |
13782 | \twatchpoint - watchpoint\n\ | |
13783 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13784 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13785 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13786 | address and file/line number respectively.\n\ |
13787 | \n\ | |
13788 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13789 | are set to the address of the last breakpoint listed unless the command\n\ |
13790 | is prefixed with \"server \".\n\n\ | |
c906108c | 13791 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13792 | breakpoint set.")); |
c906108c | 13793 | |
6b04bdb7 MS |
13794 | add_info_alias ("b", "breakpoints", 1); |
13795 | ||
c906108c | 13796 | if (xdb_commands) |
1bedd215 AC |
13797 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
13798 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13799 | The \"Type\" column indicates one of:\n\ |
13800 | \tbreakpoint - normal breakpoint\n\ | |
13801 | \twatchpoint - watchpoint\n\ | |
13802 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13803 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13804 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13805 | address and file/line number respectively.\n\ |
13806 | \n\ | |
13807 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13808 | are set to the address of the last breakpoint listed unless the command\n\ |
13809 | is prefixed with \"server \".\n\n\ | |
c906108c | 13810 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13811 | breakpoint set.")); |
c906108c | 13812 | |
1a966eab AC |
13813 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
13814 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13815 | The \"Type\" column indicates one of:\n\ |
13816 | \tbreakpoint - normal breakpoint\n\ | |
13817 | \twatchpoint - watchpoint\n\ | |
13818 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
13819 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
13820 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
13821 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
13822 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
13823 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
13824 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
13825 | address and file/line number respectively.\n\ |
13826 | \n\ | |
13827 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13828 | are set to the address of the last breakpoint listed unless the command\n\ |
13829 | is prefixed with \"server \".\n\n\ | |
c906108c | 13830 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 13831 | breakpoint set."), |
c906108c SS |
13832 | &maintenanceinfolist); |
13833 | ||
44feb3ce TT |
13834 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
13835 | Set catchpoints to catch events."), | |
13836 | &catch_cmdlist, "catch ", | |
13837 | 0/*allow-unknown*/, &cmdlist); | |
13838 | ||
13839 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
13840 | Set temporary catchpoints to catch events."), | |
13841 | &tcatch_cmdlist, "tcatch ", | |
13842 | 0/*allow-unknown*/, &cmdlist); | |
13843 | ||
13844 | /* Add catch and tcatch sub-commands. */ | |
13845 | add_catch_command ("catch", _("\ | |
13846 | Catch an exception, when caught.\n\ | |
13847 | With an argument, catch only exceptions with the given name."), | |
13848 | catch_catch_command, | |
a96d9b2e | 13849 | NULL, |
44feb3ce TT |
13850 | CATCH_PERMANENT, |
13851 | CATCH_TEMPORARY); | |
13852 | add_catch_command ("throw", _("\ | |
13853 | Catch an exception, when thrown.\n\ | |
13854 | With an argument, catch only exceptions with the given name."), | |
13855 | catch_throw_command, | |
a96d9b2e | 13856 | NULL, |
44feb3ce TT |
13857 | CATCH_PERMANENT, |
13858 | CATCH_TEMPORARY); | |
13859 | add_catch_command ("fork", _("Catch calls to fork."), | |
13860 | catch_fork_command_1, | |
a96d9b2e | 13861 | NULL, |
44feb3ce TT |
13862 | (void *) (uintptr_t) catch_fork_permanent, |
13863 | (void *) (uintptr_t) catch_fork_temporary); | |
13864 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
13865 | catch_fork_command_1, | |
a96d9b2e | 13866 | NULL, |
44feb3ce TT |
13867 | (void *) (uintptr_t) catch_vfork_permanent, |
13868 | (void *) (uintptr_t) catch_vfork_temporary); | |
13869 | add_catch_command ("exec", _("Catch calls to exec."), | |
13870 | catch_exec_command_1, | |
a96d9b2e SDJ |
13871 | NULL, |
13872 | CATCH_PERMANENT, | |
13873 | CATCH_TEMPORARY); | |
13874 | add_catch_command ("syscall", _("\ | |
13875 | Catch system calls by their names and/or numbers.\n\ | |
13876 | Arguments say which system calls to catch. If no arguments\n\ | |
13877 | are given, every system call will be caught.\n\ | |
13878 | Arguments, if given, should be one or more system call names\n\ | |
13879 | (if your system supports that), or system call numbers."), | |
13880 | catch_syscall_command_1, | |
13881 | catch_syscall_completer, | |
44feb3ce TT |
13882 | CATCH_PERMANENT, |
13883 | CATCH_TEMPORARY); | |
c5aa993b | 13884 | |
1bedd215 AC |
13885 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
13886 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13887 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 13888 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13889 | an expression changes.\n\ |
13890 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13891 | the memory to which it refers.")); | |
65d12d83 | 13892 | set_cmd_completer (c, expression_completer); |
c906108c | 13893 | |
1bedd215 AC |
13894 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
13895 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 13896 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 13897 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13898 | an expression is read.\n\ |
13899 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13900 | the memory to which it refers.")); | |
65d12d83 | 13901 | set_cmd_completer (c, expression_completer); |
c906108c | 13902 | |
1bedd215 AC |
13903 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
13904 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13905 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 13906 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13907 | an expression is either read or written.\n\ |
13908 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13909 | the memory to which it refers.")); | |
65d12d83 | 13910 | set_cmd_completer (c, expression_completer); |
c906108c | 13911 | |
d77f58be | 13912 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 13913 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 13914 | |
920d2a44 AC |
13915 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
13916 | respond to changes - contrary to the description. */ | |
85c07804 AC |
13917 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
13918 | &can_use_hw_watchpoints, _("\ | |
13919 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
13920 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
13921 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
13922 | such is available. (However, any hardware watchpoints that were\n\ | |
13923 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
13924 | hardware.)"), |
13925 | NULL, | |
920d2a44 | 13926 | show_can_use_hw_watchpoints, |
85c07804 | 13927 | &setlist, &showlist); |
c906108c SS |
13928 | |
13929 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 13930 | |
1042e4c0 SS |
13931 | /* Tracepoint manipulation commands. */ |
13932 | ||
13933 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
13934 | Set a tracepoint at specified line or function.\n\ | |
13935 | \n" | |
13936 | BREAK_ARGS_HELP ("trace") "\n\ | |
13937 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13938 | set_cmd_completer (c, location_completer); | |
13939 | ||
13940 | add_com_alias ("tp", "trace", class_alias, 0); | |
13941 | add_com_alias ("tr", "trace", class_alias, 1); | |
13942 | add_com_alias ("tra", "trace", class_alias, 1); | |
13943 | add_com_alias ("trac", "trace", class_alias, 1); | |
13944 | ||
7a697b8d SS |
13945 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
13946 | Set a fast tracepoint at specified line or function.\n\ | |
13947 | \n" | |
13948 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
13949 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13950 | set_cmd_completer (c, location_completer); | |
13951 | ||
0fb4aa4b PA |
13952 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
13953 | Set a static tracepoint at specified line, function or marker.\n\ | |
13954 | \n\ | |
13955 | strace [LOCATION] [if CONDITION]\n\ | |
13956 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
13957 | or -m MARKER_ID.\n\ | |
13958 | If a line number is specified, probe the marker at start of code\n\ | |
13959 | for that line. If a function is specified, probe the marker at start\n\ | |
13960 | of code for that function. If an address is specified, probe the marker\n\ | |
13961 | at that exact address. If a marker id is specified, probe the marker\n\ | |
13962 | with that name. With no LOCATION, uses current execution address of\n\ | |
13963 | the selected stack frame.\n\ | |
13964 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
13965 | This collects arbitrary user data passed in the probe point call to the\n\ | |
13966 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
13967 | by printing the $_sdata variable like any other convenience variable.\n\ | |
13968 | \n\ | |
13969 | CONDITION is a boolean expression.\n\ | |
13970 | \n\ | |
d41c0fc8 PA |
13971 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
13972 | conditions are different.\n\ | |
0fb4aa4b PA |
13973 | \n\ |
13974 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
13975 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13976 | set_cmd_completer (c, location_completer); | |
13977 | ||
1042e4c0 | 13978 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 13979 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
13980 | Convenience variable \"$tpnum\" contains the number of the\n\ |
13981 | last tracepoint set.")); | |
13982 | ||
13983 | add_info_alias ("tp", "tracepoints", 1); | |
13984 | ||
13985 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
13986 | Delete specified tracepoints.\n\ | |
13987 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13988 | No argument means delete all tracepoints."), | |
13989 | &deletelist); | |
13990 | ||
13991 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
13992 | Disable specified tracepoints.\n\ | |
13993 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13994 | No argument means disable all tracepoints."), | |
13995 | &disablelist); | |
13996 | deprecate_cmd (c, "disable"); | |
13997 | ||
13998 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
13999 | Enable specified tracepoints.\n\ | |
14000 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
14001 | No argument means enable all tracepoints."), | |
14002 | &enablelist); | |
14003 | deprecate_cmd (c, "enable"); | |
14004 | ||
14005 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
14006 | Set the passcount for a tracepoint.\n\ | |
14007 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
14008 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
14009 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
14010 | ||
6149aea9 PA |
14011 | add_prefix_cmd ("save", class_breakpoint, save_command, |
14012 | _("Save breakpoint definitions as a script."), | |
14013 | &save_cmdlist, "save ", | |
14014 | 0/*allow-unknown*/, &cmdlist); | |
14015 | ||
14016 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
14017 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 14018 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
14019 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
14020 | session to restore them."), | |
14021 | &save_cmdlist); | |
14022 | set_cmd_completer (c, filename_completer); | |
14023 | ||
14024 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 14025 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
14026 | Use the 'source' command in another debug session to restore them."), |
14027 | &save_cmdlist); | |
1042e4c0 SS |
14028 | set_cmd_completer (c, filename_completer); |
14029 | ||
6149aea9 PA |
14030 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
14031 | deprecate_cmd (c, "save tracepoints"); | |
14032 | ||
1bedd215 | 14033 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
14034 | Breakpoint specific settings\n\ |
14035 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 14036 | pending breakpoint behavior"), |
fa8d40ab JJ |
14037 | &breakpoint_set_cmdlist, "set breakpoint ", |
14038 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 14039 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
14040 | Breakpoint specific settings\n\ |
14041 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 14042 | pending breakpoint behavior"), |
fa8d40ab JJ |
14043 | &breakpoint_show_cmdlist, "show breakpoint ", |
14044 | 0/*allow-unknown*/, &showlist); | |
14045 | ||
7915a72c AC |
14046 | add_setshow_auto_boolean_cmd ("pending", no_class, |
14047 | &pending_break_support, _("\ | |
14048 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
14049 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
14050 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
14051 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
14052 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 14053 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 14054 | NULL, |
920d2a44 | 14055 | show_pending_break_support, |
6e1d7d6c AC |
14056 | &breakpoint_set_cmdlist, |
14057 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
14058 | |
14059 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
14060 | |
14061 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
14062 | &automatic_hardware_breakpoints, _("\ | |
14063 | Set automatic usage of hardware breakpoints."), _("\ | |
14064 | Show automatic usage of hardware breakpoints."), _("\ | |
14065 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
14066 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
14067 | a warning will be emitted for such breakpoints."), | |
14068 | NULL, | |
14069 | show_automatic_hardware_breakpoints, | |
14070 | &breakpoint_set_cmdlist, | |
14071 | &breakpoint_show_cmdlist); | |
74960c60 | 14072 | |
33e5cbd6 PA |
14073 | add_setshow_enum_cmd ("always-inserted", class_support, |
14074 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
14075 | Set mode for inserting breakpoints."), _("\ |
14076 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
14077 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
14078 | resumed, and removed when execution stops. When this mode is on,\n\ | |
14079 | breakpoints are inserted immediately and removed only when the user\n\ | |
14080 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
14081 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
14082 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
14083 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
14084 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
14085 | NULL, |
14086 | &show_always_inserted_mode, | |
14087 | &breakpoint_set_cmdlist, | |
14088 | &breakpoint_show_cmdlist); | |
f1310107 TJB |
14089 | |
14090 | add_com ("break-range", class_breakpoint, break_range_command, _("\ | |
14091 | Set a breakpoint for an address range.\n\ | |
14092 | break-range START-LOCATION, END-LOCATION\n\ | |
14093 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
14094 | LINENUM, for that line in the current file,\n\ | |
14095 | FILE:LINENUM, for that line in that file,\n\ | |
14096 | +OFFSET, for that number of lines after the current line\n\ | |
14097 | or the start of the range\n\ | |
14098 | FUNCTION, for the first line in that function,\n\ | |
14099 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
14100 | *ADDRESS, for the instruction at that address.\n\ | |
14101 | \n\ | |
14102 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
14103 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
14104 | range (including START-LOCATION and END-LOCATION).")); | |
14105 | ||
765dc015 | 14106 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
14107 | |
14108 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 14109 | } |