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 | |
36dfb11c TT |
3449 | list - a list of the eventpoints that caused this stop. KIND is |
3450 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
3451 | routine calls the generic print routine for printing a message |
3452 | about reasons for stopping. This will print (for example) the | |
3453 | "Breakpoint n," part of the output. The return value of this | |
3454 | routine is one of: | |
c906108c | 3455 | |
4a64f543 | 3456 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3457 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3458 | code to print the location. An example is |
c5aa993b JM |
3459 | "Breakpoint 1, " which should be followed by |
3460 | the location. | |
917317f4 | 3461 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3462 | to also print the location part of the message. |
3463 | An example is the catch/throw messages, which | |
4a64f543 | 3464 | don't require a location appended to the end. |
917317f4 | 3465 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3466 | further info to be printed. */ |
c906108c | 3467 | |
917317f4 | 3468 | enum print_stop_action |
36dfb11c | 3469 | bpstat_print (bpstat bs, int kind) |
c906108c SS |
3470 | { |
3471 | int val; | |
c5aa993b | 3472 | |
c906108c | 3473 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3474 | (Currently all watchpoints go on the bpstat whether hit or not. |
3475 | That probably could (should) be changed, provided care is taken | |
c906108c | 3476 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3477 | for (; bs; bs = bs->next) |
3478 | { | |
3479 | val = print_bp_stop_message (bs); | |
3480 | if (val == PRINT_SRC_ONLY | |
3481 | || val == PRINT_SRC_AND_LOC | |
3482 | || val == PRINT_NOTHING) | |
3483 | return val; | |
3484 | } | |
c906108c | 3485 | |
36dfb11c TT |
3486 | /* If we had hit a shared library event breakpoint, |
3487 | print_bp_stop_message would print out this message. If we hit an | |
3488 | OS-level shared library event, do the same thing. */ | |
3489 | if (kind == TARGET_WAITKIND_LOADED) | |
3490 | { | |
3491 | ui_out_text (current_uiout, _("Stopped due to shared library event\n")); | |
3492 | if (ui_out_is_mi_like_p (current_uiout)) | |
3493 | ui_out_field_string (current_uiout, "reason", | |
3494 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
3495 | return PRINT_NOTHING; | |
3496 | } | |
3497 | ||
e514a9d6 | 3498 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3499 | with and nothing was printed. */ |
917317f4 | 3500 | return PRINT_UNKNOWN; |
c906108c SS |
3501 | } |
3502 | ||
4a64f543 MS |
3503 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3504 | used inside a catch_errors to evaluate the breakpoint condition. | |
3505 | The argument is a "struct expression *" that has been cast to a | |
3506 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3507 | |
3508 | static int | |
4efb68b1 | 3509 | breakpoint_cond_eval (void *exp) |
c906108c | 3510 | { |
278cd55f | 3511 | struct value *mark = value_mark (); |
c5aa993b | 3512 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3513 | |
c906108c SS |
3514 | value_free_to_mark (mark); |
3515 | return i; | |
3516 | } | |
3517 | ||
5760d0ab | 3518 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3519 | |
3520 | static bpstat | |
5760d0ab | 3521 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3522 | { |
3523 | bpstat bs; | |
3524 | ||
3525 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3526 | bs->next = NULL; |
3527 | **bs_link_pointer = bs; | |
3528 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3529 | bs->breakpoint_at = bl->owner; |
3530 | bs->bp_location_at = bl; | |
3531 | incref_bp_location (bl); | |
c906108c SS |
3532 | /* If the condition is false, etc., don't do the commands. */ |
3533 | bs->commands = NULL; | |
3534 | bs->old_val = NULL; | |
3535 | bs->print_it = print_it_normal; | |
3536 | return bs; | |
3537 | } | |
3538 | \f | |
d983da9c DJ |
3539 | /* The target has stopped with waitstatus WS. Check if any hardware |
3540 | watchpoints have triggered, according to the target. */ | |
3541 | ||
3542 | int | |
3543 | watchpoints_triggered (struct target_waitstatus *ws) | |
3544 | { | |
d92524f1 | 3545 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3546 | CORE_ADDR addr; |
3547 | struct breakpoint *b; | |
3548 | ||
3549 | if (!stopped_by_watchpoint) | |
3550 | { | |
3551 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3552 | as not triggered. */ | |
3553 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3554 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3555 | { |
3556 | struct watchpoint *w = (struct watchpoint *) b; | |
3557 | ||
3558 | w->watchpoint_triggered = watch_triggered_no; | |
3559 | } | |
d983da9c DJ |
3560 | |
3561 | return 0; | |
3562 | } | |
3563 | ||
3564 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3565 | { | |
3566 | /* We were stopped by a watchpoint, but we don't know where. | |
3567 | Mark all watchpoints as unknown. */ | |
3568 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3569 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3570 | { |
3571 | struct watchpoint *w = (struct watchpoint *) b; | |
3572 | ||
3573 | w->watchpoint_triggered = watch_triggered_unknown; | |
3574 | } | |
d983da9c DJ |
3575 | |
3576 | return stopped_by_watchpoint; | |
3577 | } | |
3578 | ||
3579 | /* The target could report the data address. Mark watchpoints | |
3580 | affected by this data address as triggered, and all others as not | |
3581 | triggered. */ | |
3582 | ||
3583 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3584 | if (is_hardware_watchpoint (b)) |
d983da9c | 3585 | { |
3a5c3e22 | 3586 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 3587 | struct bp_location *loc; |
d983da9c | 3588 | |
3a5c3e22 | 3589 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 3590 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 3591 | { |
3a5c3e22 | 3592 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 3593 | { |
3a5c3e22 PA |
3594 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
3595 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
3596 | |
3597 | if (newaddr == start) | |
3598 | { | |
3a5c3e22 | 3599 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3600 | break; |
3601 | } | |
3602 | } | |
3603 | /* Exact match not required. Within range is sufficient. */ | |
3604 | else if (target_watchpoint_addr_within_range (¤t_target, | |
3605 | addr, loc->address, | |
3606 | loc->length)) | |
3607 | { | |
3a5c3e22 | 3608 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3609 | break; |
3610 | } | |
3611 | } | |
d983da9c DJ |
3612 | } |
3613 | ||
3614 | return 1; | |
3615 | } | |
3616 | ||
c906108c SS |
3617 | /* Possible return values for watchpoint_check (this can't be an enum |
3618 | because of check_errors). */ | |
3619 | /* The watchpoint has been deleted. */ | |
3620 | #define WP_DELETED 1 | |
3621 | /* The value has changed. */ | |
3622 | #define WP_VALUE_CHANGED 2 | |
3623 | /* The value has not changed. */ | |
3624 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3625 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3626 | #define WP_IGNORE 4 | |
c906108c SS |
3627 | |
3628 | #define BP_TEMPFLAG 1 | |
3629 | #define BP_HARDWAREFLAG 2 | |
3630 | ||
4a64f543 MS |
3631 | /* Evaluate watchpoint condition expression and check if its value |
3632 | changed. | |
553e4c11 JB |
3633 | |
3634 | P should be a pointer to struct bpstat, but is defined as a void * | |
3635 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3636 | |
3637 | static int | |
4efb68b1 | 3638 | watchpoint_check (void *p) |
c906108c SS |
3639 | { |
3640 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 3641 | struct watchpoint *b; |
c906108c SS |
3642 | struct frame_info *fr; |
3643 | int within_current_scope; | |
3644 | ||
f431efe5 | 3645 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3646 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 3647 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 3648 | |
f6bc2008 PA |
3649 | /* If this is a local watchpoint, we only want to check if the |
3650 | watchpoint frame is in scope if the current thread is the thread | |
3651 | that was used to create the watchpoint. */ | |
3652 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3653 | return WP_IGNORE; |
f6bc2008 | 3654 | |
c906108c SS |
3655 | if (b->exp_valid_block == NULL) |
3656 | within_current_scope = 1; | |
3657 | else | |
3658 | { | |
edb3359d DJ |
3659 | struct frame_info *frame = get_current_frame (); |
3660 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3661 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3662 | ||
4a64f543 MS |
3663 | /* in_function_epilogue_p() returns a non-zero value if we're |
3664 | still in the function but the stack frame has already been | |
3665 | invalidated. Since we can't rely on the values of local | |
3666 | variables after the stack has been destroyed, we are treating | |
3667 | the watchpoint in that state as `not changed' without further | |
3668 | checking. Don't mark watchpoints as changed if the current | |
3669 | frame is in an epilogue - even if they are in some other | |
3670 | frame, our view of the stack is likely to be wrong and | |
3671 | frame_find_by_id could error out. */ | |
a0f49112 | 3672 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3673 | return WP_IGNORE; |
a0f49112 | 3674 | |
101dcfbe | 3675 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3676 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3677 | |
3678 | /* If we've gotten confused in the unwinder, we might have | |
3679 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3680 | if (within_current_scope) |
3681 | { | |
3682 | struct symbol *function; | |
3683 | ||
3684 | function = get_frame_function (fr); | |
3685 | if (function == NULL | |
3686 | || !contained_in (b->exp_valid_block, | |
3687 | SYMBOL_BLOCK_VALUE (function))) | |
3688 | within_current_scope = 0; | |
3689 | } | |
69fbadd5 | 3690 | |
edb3359d | 3691 | if (within_current_scope) |
c906108c SS |
3692 | /* If we end up stopping, the current frame will get selected |
3693 | in normal_stop. So this call to select_frame won't affect | |
3694 | the user. */ | |
0f7d239c | 3695 | select_frame (fr); |
c906108c | 3696 | } |
c5aa993b | 3697 | |
c906108c SS |
3698 | if (within_current_scope) |
3699 | { | |
4a64f543 MS |
3700 | /* We use value_{,free_to_}mark because it could be a *long* |
3701 | time before we return to the command level and call | |
3702 | free_all_values. We can't call free_all_values because we | |
3703 | might be in the middle of evaluating a function call. */ | |
c906108c | 3704 | |
0cf6dd15 | 3705 | int pc = 0; |
9c06b0b4 | 3706 | struct value *mark; |
fa4727a6 DJ |
3707 | struct value *new_val; |
3708 | ||
3a5c3e22 | 3709 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
3710 | /* Since we don't know the exact trigger address (from |
3711 | stopped_data_address), just tell the user we've triggered | |
3712 | a mask watchpoint. */ | |
3713 | return WP_VALUE_CHANGED; | |
3714 | ||
3715 | mark = value_mark (); | |
0cf6dd15 | 3716 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3717 | |
4a64f543 MS |
3718 | /* We use value_equal_contents instead of value_equal because |
3719 | the latter coerces an array to a pointer, thus comparing just | |
3720 | the address of the array instead of its contents. This is | |
3721 | not what we want. */ | |
fa4727a6 | 3722 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3723 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3724 | { |
fa4727a6 DJ |
3725 | if (new_val != NULL) |
3726 | { | |
3727 | release_value (new_val); | |
3728 | value_free_to_mark (mark); | |
3729 | } | |
c906108c SS |
3730 | bs->old_val = b->val; |
3731 | b->val = new_val; | |
fa4727a6 | 3732 | b->val_valid = 1; |
c906108c SS |
3733 | return WP_VALUE_CHANGED; |
3734 | } | |
3735 | else | |
3736 | { | |
60e1c644 | 3737 | /* Nothing changed. */ |
c906108c | 3738 | value_free_to_mark (mark); |
c906108c SS |
3739 | return WP_VALUE_NOT_CHANGED; |
3740 | } | |
3741 | } | |
3742 | else | |
3743 | { | |
79a45e25 PA |
3744 | struct ui_out *uiout = current_uiout; |
3745 | ||
c906108c | 3746 | /* This seems like the only logical thing to do because |
c5aa993b JM |
3747 | if we temporarily ignored the watchpoint, then when |
3748 | we reenter the block in which it is valid it contains | |
3749 | garbage (in the case of a function, it may have two | |
3750 | garbage values, one before and one after the prologue). | |
3751 | So we can't even detect the first assignment to it and | |
3752 | watch after that (since the garbage may or may not equal | |
3753 | the first value assigned). */ | |
348d480f PA |
3754 | /* We print all the stop information in |
3755 | breakpoint_ops->print_it, but in this case, by the time we | |
3756 | call breakpoint_ops->print_it this bp will be deleted | |
3757 | already. So we have no choice but print the information | |
3758 | here. */ | |
9dc5e2a9 | 3759 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3760 | ui_out_field_string |
3761 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3762 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 3763 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
3764 | ui_out_text (uiout, |
3765 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3766 | which its expression is valid.\n"); |
4ce44c66 | 3767 | |
cdac0397 | 3768 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 3769 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 3770 | watchpoint_del_at_next_stop (b); |
c906108c SS |
3771 | |
3772 | return WP_DELETED; | |
3773 | } | |
3774 | } | |
3775 | ||
18a18393 | 3776 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
3777 | breakpoint location BL. This function does not check if we should |
3778 | stop, only if BL explains the stop. */ | |
3779 | ||
18a18393 | 3780 | static int |
6c95b8df PA |
3781 | bpstat_check_location (const struct bp_location *bl, |
3782 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3783 | { |
3784 | struct breakpoint *b = bl->owner; | |
3785 | ||
348d480f | 3786 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
3787 | gdb_assert (b != NULL); |
3788 | ||
348d480f | 3789 | return b->ops->breakpoint_hit (bl, aspace, bp_addr); |
18a18393 VP |
3790 | } |
3791 | ||
3a5c3e22 PA |
3792 | /* Determine if the watched values have actually changed, and we |
3793 | should stop. If not, set BS->stop to 0. */ | |
3794 | ||
18a18393 VP |
3795 | static void |
3796 | bpstat_check_watchpoint (bpstat bs) | |
3797 | { | |
2bdf28a0 | 3798 | const struct bp_location *bl; |
3a5c3e22 | 3799 | struct watchpoint *b; |
2bdf28a0 JK |
3800 | |
3801 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3802 | bl = bs->bp_location_at; |
2bdf28a0 | 3803 | gdb_assert (bl != NULL); |
3a5c3e22 | 3804 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 3805 | gdb_assert (b != NULL); |
18a18393 | 3806 | |
18a18393 | 3807 | { |
18a18393 VP |
3808 | int must_check_value = 0; |
3809 | ||
3a5c3e22 | 3810 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
3811 | /* For a software watchpoint, we must always check the |
3812 | watched value. */ | |
3813 | must_check_value = 1; | |
3814 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3815 | /* We have a hardware watchpoint (read, write, or access) | |
3816 | and the target earlier reported an address watched by | |
3817 | this watchpoint. */ | |
3818 | must_check_value = 1; | |
3819 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 3820 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
3821 | /* We were stopped by a hardware watchpoint, but the target could |
3822 | not report the data address. We must check the watchpoint's | |
3823 | value. Access and read watchpoints are out of luck; without | |
3824 | a data address, we can't figure it out. */ | |
3825 | must_check_value = 1; | |
3a5c3e22 | 3826 | |
18a18393 VP |
3827 | if (must_check_value) |
3828 | { | |
3e43a32a MS |
3829 | char *message |
3830 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 3831 | b->base.number); |
18a18393 VP |
3832 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3833 | int e = catch_errors (watchpoint_check, bs, message, | |
3834 | RETURN_MASK_ALL); | |
3835 | do_cleanups (cleanups); | |
3836 | switch (e) | |
3837 | { | |
3838 | case WP_DELETED: | |
3839 | /* We've already printed what needs to be printed. */ | |
3840 | bs->print_it = print_it_done; | |
3841 | /* Stop. */ | |
3842 | break; | |
60e1c644 PA |
3843 | case WP_IGNORE: |
3844 | bs->print_it = print_it_noop; | |
3845 | bs->stop = 0; | |
3846 | break; | |
18a18393 | 3847 | case WP_VALUE_CHANGED: |
3a5c3e22 | 3848 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 3849 | { |
85d721b8 PA |
3850 | /* There are two cases to consider here: |
3851 | ||
4a64f543 | 3852 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3853 | In that case, trust the target, and always report |
3854 | the watchpoint hit to the user. Even though | |
3855 | reads don't cause value changes, the value may | |
3856 | have changed since the last time it was read, and | |
3857 | since we're not trapping writes, we will not see | |
3858 | those, and as such we should ignore our notion of | |
3859 | old value. | |
3860 | ||
4a64f543 | 3861 | 2. We're watching the triggered memory for both |
85d721b8 PA |
3862 | reads and writes. There are two ways this may |
3863 | happen: | |
3864 | ||
4a64f543 | 3865 | 2.1. This is a target that can't break on data |
85d721b8 PA |
3866 | reads only, but can break on accesses (reads or |
3867 | writes), such as e.g., x86. We detect this case | |
3868 | at the time we try to insert read watchpoints. | |
3869 | ||
4a64f543 | 3870 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
3871 | watchpoints, but, the user set an access or write |
3872 | watchpoint watching the same memory as this read | |
3873 | watchpoint. | |
3874 | ||
3875 | If we're watching memory writes as well as reads, | |
3876 | ignore watchpoint hits when we find that the | |
3877 | value hasn't changed, as reads don't cause | |
3878 | changes. This still gives false positives when | |
3879 | the program writes the same value to memory as | |
3880 | what there was already in memory (we will confuse | |
3881 | it for a read), but it's much better than | |
3882 | nothing. */ | |
3883 | ||
3884 | int other_write_watchpoint = 0; | |
3885 | ||
3886 | if (bl->watchpoint_type == hw_read) | |
3887 | { | |
3888 | struct breakpoint *other_b; | |
3889 | ||
3890 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
3891 | if (other_b->type == bp_hardware_watchpoint |
3892 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 3893 | { |
3a5c3e22 PA |
3894 | struct watchpoint *other_w = |
3895 | (struct watchpoint *) other_b; | |
3896 | ||
3897 | if (other_w->watchpoint_triggered | |
3898 | == watch_triggered_yes) | |
3899 | { | |
3900 | other_write_watchpoint = 1; | |
3901 | break; | |
3902 | } | |
85d721b8 PA |
3903 | } |
3904 | } | |
3905 | ||
3906 | if (other_write_watchpoint | |
3907 | || bl->watchpoint_type == hw_access) | |
3908 | { | |
3909 | /* We're watching the same memory for writes, | |
3910 | and the value changed since the last time we | |
3911 | updated it, so this trap must be for a write. | |
3912 | Ignore it. */ | |
3913 | bs->print_it = print_it_noop; | |
3914 | bs->stop = 0; | |
3915 | } | |
18a18393 VP |
3916 | } |
3917 | break; | |
3918 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
3919 | if (b->base.type == bp_hardware_watchpoint |
3920 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
3921 | { |
3922 | /* Don't stop: write watchpoints shouldn't fire if | |
3923 | the value hasn't changed. */ | |
3924 | bs->print_it = print_it_noop; | |
3925 | bs->stop = 0; | |
3926 | } | |
3927 | /* Stop. */ | |
3928 | break; | |
3929 | default: | |
3930 | /* Can't happen. */ | |
3931 | case 0: | |
3932 | /* Error from catch_errors. */ | |
3a5c3e22 | 3933 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 3934 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
3935 | /* We've already printed what needs to be printed. */ |
3936 | bs->print_it = print_it_done; | |
3937 | break; | |
3938 | } | |
3939 | } | |
3940 | else /* must_check_value == 0 */ | |
3941 | { | |
3942 | /* This is a case where some watchpoint(s) triggered, but | |
3943 | not at the address of this watchpoint, or else no | |
3944 | watchpoint triggered after all. So don't print | |
3945 | anything for this watchpoint. */ | |
3946 | bs->print_it = print_it_noop; | |
3947 | bs->stop = 0; | |
3948 | } | |
3949 | } | |
3950 | } | |
3951 | ||
3952 | ||
3953 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3954 | of breakpoint referred to by BS. If we should not stop for this | |
3955 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 3956 | |
18a18393 VP |
3957 | static void |
3958 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3959 | { | |
3960 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
3961 | const struct bp_location *bl; |
3962 | struct breakpoint *b; | |
3963 | ||
3964 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3965 | bl = bs->bp_location_at; |
2bdf28a0 | 3966 | gdb_assert (bl != NULL); |
f431efe5 | 3967 | b = bs->breakpoint_at; |
2bdf28a0 | 3968 | gdb_assert (b != NULL); |
18a18393 VP |
3969 | |
3970 | if (frame_id_p (b->frame_id) | |
edb3359d | 3971 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3972 | bs->stop = 0; |
3973 | else if (bs->stop) | |
3974 | { | |
3975 | int value_is_zero = 0; | |
60e1c644 PA |
3976 | struct expression *cond; |
3977 | ||
7371cf6d PM |
3978 | /* Evaluate Python breakpoints that have a "stop" |
3979 | method implemented. */ | |
3980 | if (b->py_bp_object) | |
3981 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
3982 | ||
60e1c644 | 3983 | if (is_watchpoint (b)) |
3a5c3e22 PA |
3984 | { |
3985 | struct watchpoint *w = (struct watchpoint *) b; | |
3986 | ||
3987 | cond = w->cond_exp; | |
3988 | } | |
60e1c644 PA |
3989 | else |
3990 | cond = bl->cond; | |
3991 | ||
f431efe5 | 3992 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 3993 | { |
60e1c644 | 3994 | int within_current_scope = 1; |
3a5c3e22 | 3995 | struct watchpoint * w; |
60e1c644 | 3996 | |
c5bc3a77 DJ |
3997 | /* We use value_mark and value_free_to_mark because it could |
3998 | be a long time before we return to the command level and | |
3999 | call free_all_values. We can't call free_all_values | |
4000 | because we might be in the middle of evaluating a | |
4001 | function call. */ | |
4002 | struct value *mark = value_mark (); | |
4003 | ||
3a5c3e22 PA |
4004 | if (is_watchpoint (b)) |
4005 | w = (struct watchpoint *) b; | |
4006 | else | |
4007 | w = NULL; | |
4008 | ||
edb3359d DJ |
4009 | /* Need to select the frame, with all that implies so that |
4010 | the conditions will have the right context. Because we | |
4011 | use the frame, we will not see an inlined function's | |
4012 | variables when we arrive at a breakpoint at the start | |
4013 | of the inlined function; the current frame will be the | |
4014 | call site. */ | |
3a5c3e22 | 4015 | if (w == NULL || w->cond_exp_valid_block == NULL) |
60e1c644 PA |
4016 | select_frame (get_current_frame ()); |
4017 | else | |
4018 | { | |
4019 | struct frame_info *frame; | |
4020 | ||
4021 | /* For local watchpoint expressions, which particular | |
4022 | instance of a local is being watched matters, so we | |
4023 | keep track of the frame to evaluate the expression | |
4024 | in. To evaluate the condition however, it doesn't | |
4025 | really matter which instantiation of the function | |
4026 | where the condition makes sense triggers the | |
4027 | watchpoint. This allows an expression like "watch | |
4028 | global if q > 10" set in `func', catch writes to | |
4029 | global on all threads that call `func', or catch | |
4030 | writes on all recursive calls of `func' by a single | |
4031 | thread. We simply always evaluate the condition in | |
4032 | the innermost frame that's executing where it makes | |
4033 | sense to evaluate the condition. It seems | |
4034 | intuitive. */ | |
3a5c3e22 | 4035 | frame = block_innermost_frame (w->cond_exp_valid_block); |
60e1c644 PA |
4036 | if (frame != NULL) |
4037 | select_frame (frame); | |
4038 | else | |
4039 | within_current_scope = 0; | |
4040 | } | |
4041 | if (within_current_scope) | |
4042 | value_is_zero | |
4043 | = catch_errors (breakpoint_cond_eval, cond, | |
4044 | "Error in testing breakpoint condition:\n", | |
4045 | RETURN_MASK_ALL); | |
4046 | else | |
4047 | { | |
4048 | warning (_("Watchpoint condition cannot be tested " | |
4049 | "in the current scope")); | |
4050 | /* If we failed to set the right context for this | |
4051 | watchpoint, unconditionally report it. */ | |
4052 | value_is_zero = 0; | |
4053 | } | |
4a64f543 | 4054 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4055 | value_free_to_mark (mark); |
18a18393 | 4056 | } |
60e1c644 PA |
4057 | |
4058 | if (cond && value_is_zero) | |
18a18393 VP |
4059 | { |
4060 | bs->stop = 0; | |
4061 | } | |
4062 | else if (b->thread != -1 && b->thread != thread_id) | |
4063 | { | |
4064 | bs->stop = 0; | |
4065 | } | |
4066 | else if (b->ignore_count > 0) | |
4067 | { | |
4068 | b->ignore_count--; | |
4069 | annotate_ignore_count_change (); | |
4070 | bs->stop = 0; | |
4a64f543 | 4071 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 4072 | ++(b->hit_count); |
8d3788bd | 4073 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
4074 | } |
4075 | } | |
4076 | } | |
4077 | ||
4078 | ||
9709f61c | 4079 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4080 | BP_ADDR in thread PTID. |
c906108c | 4081 | |
d983da9c | 4082 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4083 | don't understand this stop. Result is a chain of bpstat's such |
4084 | that: | |
c906108c | 4085 | |
c5aa993b | 4086 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4087 | |
c5aa993b | 4088 | if we understand why we stopped, the result is not null. |
c906108c | 4089 | |
c5aa993b JM |
4090 | Each element of the chain refers to a particular breakpoint or |
4091 | watchpoint at which we have stopped. (We may have stopped for | |
4092 | several reasons concurrently.) | |
c906108c | 4093 | |
c5aa993b JM |
4094 | Each element of the chain has valid next, breakpoint_at, |
4095 | commands, FIXME??? fields. */ | |
c906108c SS |
4096 | |
4097 | bpstat | |
6c95b8df PA |
4098 | bpstat_stop_status (struct address_space *aspace, |
4099 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4100 | { |
0d381245 | 4101 | struct breakpoint *b = NULL; |
afe38095 | 4102 | struct bp_location *bl; |
20874c92 | 4103 | struct bp_location *loc; |
5760d0ab JK |
4104 | /* First item of allocated bpstat's. */ |
4105 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4106 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4107 | bpstat bs; |
20874c92 | 4108 | int ix; |
429374b8 | 4109 | int need_remove_insert; |
f431efe5 | 4110 | int removed_any; |
c906108c | 4111 | |
f431efe5 PA |
4112 | /* First, build the bpstat chain with locations that explain a |
4113 | target stop, while being careful to not set the target running, | |
4114 | as that may invalidate locations (in particular watchpoint | |
4115 | locations are recreated). Resuming will happen here with | |
4116 | breakpoint conditions or watchpoint expressions that include | |
4117 | inferior function calls. */ | |
c5aa993b | 4118 | |
429374b8 JK |
4119 | ALL_BREAKPOINTS (b) |
4120 | { | |
4121 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4122 | continue; | |
a5606eee | 4123 | |
429374b8 JK |
4124 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4125 | { | |
4a64f543 MS |
4126 | /* For hardware watchpoints, we look only at the first |
4127 | location. The watchpoint_check function will work on the | |
4128 | entire expression, not the individual locations. For | |
4129 | read watchpoints, the watchpoints_triggered function has | |
4130 | checked all locations already. */ | |
429374b8 JK |
4131 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4132 | break; | |
18a18393 | 4133 | |
429374b8 JK |
4134 | if (bl->shlib_disabled) |
4135 | continue; | |
c5aa993b | 4136 | |
429374b8 JK |
4137 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4138 | continue; | |
c5aa993b | 4139 | |
4a64f543 MS |
4140 | /* Come here if it's a watchpoint, or if the break address |
4141 | matches. */ | |
c5aa993b | 4142 | |
4a64f543 MS |
4143 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4144 | explain stop. */ | |
c5aa993b | 4145 | |
f431efe5 PA |
4146 | /* Assume we stop. Should we find a watchpoint that is not |
4147 | actually triggered, or if the condition of the breakpoint | |
4148 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4149 | bs->stop = 1; |
4150 | bs->print = 1; | |
d983da9c | 4151 | |
f431efe5 PA |
4152 | /* If this is a scope breakpoint, mark the associated |
4153 | watchpoint as triggered so that we will handle the | |
4154 | out-of-scope event. We'll get to the watchpoint next | |
4155 | iteration. */ | |
d0fb5eae | 4156 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
4157 | { |
4158 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
4159 | ||
4160 | w->watchpoint_triggered = watch_triggered_yes; | |
4161 | } | |
f431efe5 PA |
4162 | } |
4163 | } | |
4164 | ||
4165 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4166 | { | |
f1310107 | 4167 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 4168 | { |
5760d0ab | 4169 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4170 | /* For hits of moribund locations, we should just proceed. */ |
4171 | bs->stop = 0; | |
4172 | bs->print = 0; | |
4173 | bs->print_it = print_it_noop; | |
4174 | } | |
4175 | } | |
4176 | ||
f431efe5 PA |
4177 | /* Now go through the locations that caused the target to stop, and |
4178 | check whether we're interested in reporting this stop to higher | |
4179 | layers, or whether we should resume the target transparently. */ | |
4180 | ||
4181 | removed_any = 0; | |
4182 | ||
5760d0ab | 4183 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4184 | { |
4185 | if (!bs->stop) | |
4186 | continue; | |
4187 | ||
f431efe5 | 4188 | b = bs->breakpoint_at; |
348d480f PA |
4189 | b->ops->check_status (bs); |
4190 | if (bs->stop) | |
28010a5d | 4191 | { |
348d480f | 4192 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 4193 | |
429374b8 JK |
4194 | if (bs->stop) |
4195 | { | |
4196 | ++(b->hit_count); | |
8d3788bd | 4197 | observer_notify_breakpoint_modified (b); |
c906108c | 4198 | |
4a64f543 | 4199 | /* We will stop here. */ |
429374b8 JK |
4200 | if (b->disposition == disp_disable) |
4201 | { | |
4202 | if (b->enable_state != bp_permanent) | |
4203 | b->enable_state = bp_disabled; | |
f431efe5 | 4204 | removed_any = 1; |
429374b8 JK |
4205 | } |
4206 | if (b->silent) | |
4207 | bs->print = 0; | |
4208 | bs->commands = b->commands; | |
9add0f1b | 4209 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
4210 | if (command_line_is_silent (bs->commands |
4211 | ? bs->commands->commands : NULL)) | |
4212 | bs->print = 0; | |
429374b8 JK |
4213 | } |
4214 | ||
e5dd4106 | 4215 | /* Print nothing for this entry if we don't stop or don't print. */ |
429374b8 JK |
4216 | if (bs->stop == 0 || bs->print == 0) |
4217 | bs->print_it = print_it_noop; | |
348d480f | 4218 | } |
429374b8 | 4219 | } |
876fa593 | 4220 | |
d983da9c DJ |
4221 | /* If we aren't stopping, the value of some hardware watchpoint may |
4222 | not have changed, but the intermediate memory locations we are | |
4223 | watching may have. Don't bother if we're stopping; this will get | |
4224 | done later. */ | |
d832cb68 | 4225 | need_remove_insert = 0; |
5760d0ab JK |
4226 | if (! bpstat_causes_stop (bs_head)) |
4227 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4228 | if (!bs->stop |
f431efe5 PA |
4229 | && bs->breakpoint_at |
4230 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4231 | { |
3a5c3e22 PA |
4232 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
4233 | ||
4234 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 4235 | need_remove_insert = 1; |
d983da9c DJ |
4236 | } |
4237 | ||
d832cb68 | 4238 | if (need_remove_insert) |
2d134ed3 | 4239 | update_global_location_list (1); |
f431efe5 PA |
4240 | else if (removed_any) |
4241 | update_global_location_list (0); | |
d832cb68 | 4242 | |
5760d0ab | 4243 | return bs_head; |
c906108c | 4244 | } |
628fe4e4 JK |
4245 | |
4246 | static void | |
4247 | handle_jit_event (void) | |
4248 | { | |
4249 | struct frame_info *frame; | |
4250 | struct gdbarch *gdbarch; | |
4251 | ||
4252 | /* Switch terminal for any messages produced by | |
4253 | breakpoint_re_set. */ | |
4254 | target_terminal_ours_for_output (); | |
4255 | ||
4256 | frame = get_current_frame (); | |
4257 | gdbarch = get_frame_arch (frame); | |
4258 | ||
4259 | jit_event_handler (gdbarch); | |
4260 | ||
4261 | target_terminal_inferior (); | |
4262 | } | |
4263 | ||
4264 | /* Prepare WHAT final decision for infrun. */ | |
4265 | ||
4266 | /* Decide what infrun needs to do with this bpstat. */ | |
4267 | ||
c906108c | 4268 | struct bpstat_what |
0e30163f | 4269 | bpstat_what (bpstat bs_head) |
c906108c | 4270 | { |
c906108c | 4271 | struct bpstat_what retval; |
628fe4e4 JK |
4272 | /* We need to defer calling `solib_add', as adding new symbols |
4273 | resets breakpoints, which in turn deletes breakpoint locations, | |
4274 | and hence may clear unprocessed entries in the BS chain. */ | |
4275 | int shlib_event = 0; | |
4276 | int jit_event = 0; | |
0e30163f | 4277 | bpstat bs; |
c906108c | 4278 | |
628fe4e4 | 4279 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4280 | retval.call_dummy = STOP_NONE; |
186c406b | 4281 | retval.is_longjmp = 0; |
628fe4e4 | 4282 | |
0e30163f | 4283 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 4284 | { |
628fe4e4 JK |
4285 | /* Extract this BS's action. After processing each BS, we check |
4286 | if its action overrides all we've seem so far. */ | |
4287 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4288 | enum bptype bptype; | |
4289 | ||
c906108c | 4290 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4291 | { |
4292 | /* I suspect this can happen if it was a momentary | |
4293 | breakpoint which has since been deleted. */ | |
4294 | bptype = bp_none; | |
4295 | } | |
20874c92 | 4296 | else |
f431efe5 | 4297 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4298 | |
4299 | switch (bptype) | |
c906108c SS |
4300 | { |
4301 | case bp_none: | |
628fe4e4 | 4302 | break; |
c906108c SS |
4303 | case bp_breakpoint: |
4304 | case bp_hardware_breakpoint: | |
4305 | case bp_until: | |
4306 | case bp_finish: | |
4307 | if (bs->stop) | |
4308 | { | |
4309 | if (bs->print) | |
628fe4e4 | 4310 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4311 | else |
628fe4e4 | 4312 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4313 | } |
4314 | else | |
628fe4e4 | 4315 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4316 | break; |
4317 | case bp_watchpoint: | |
4318 | case bp_hardware_watchpoint: | |
4319 | case bp_read_watchpoint: | |
4320 | case bp_access_watchpoint: | |
4321 | if (bs->stop) | |
4322 | { | |
4323 | if (bs->print) | |
628fe4e4 | 4324 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4325 | else |
628fe4e4 | 4326 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4327 | } |
4328 | else | |
628fe4e4 JK |
4329 | { |
4330 | /* There was a watchpoint, but we're not stopping. | |
4331 | This requires no further action. */ | |
4332 | } | |
c906108c SS |
4333 | break; |
4334 | case bp_longjmp: | |
186c406b | 4335 | case bp_exception: |
628fe4e4 | 4336 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4337 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4338 | break; |
4339 | case bp_longjmp_resume: | |
186c406b | 4340 | case bp_exception_resume: |
628fe4e4 | 4341 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4342 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4343 | break; |
4344 | case bp_step_resume: | |
4345 | if (bs->stop) | |
628fe4e4 JK |
4346 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4347 | else | |
c906108c | 4348 | { |
628fe4e4 JK |
4349 | /* It is for the wrong frame. */ |
4350 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4351 | } |
c906108c | 4352 | break; |
2c03e5be PA |
4353 | case bp_hp_step_resume: |
4354 | if (bs->stop) | |
4355 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
4356 | else | |
4357 | { | |
4358 | /* It is for the wrong frame. */ | |
4359 | this_action = BPSTAT_WHAT_SINGLE; | |
4360 | } | |
4361 | break; | |
c906108c | 4362 | case bp_watchpoint_scope: |
c4093a6a | 4363 | case bp_thread_event: |
1900040c | 4364 | case bp_overlay_event: |
0fd8e87f | 4365 | case bp_longjmp_master: |
aa7d318d | 4366 | case bp_std_terminate_master: |
186c406b | 4367 | case bp_exception_master: |
628fe4e4 | 4368 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4369 | break; |
ce78b96d | 4370 | case bp_catchpoint: |
c5aa993b JM |
4371 | if (bs->stop) |
4372 | { | |
4373 | if (bs->print) | |
628fe4e4 | 4374 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4375 | else |
628fe4e4 | 4376 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4377 | } |
4378 | else | |
628fe4e4 JK |
4379 | { |
4380 | /* There was a catchpoint, but we're not stopping. | |
4381 | This requires no further action. */ | |
4382 | } | |
4383 | break; | |
4384 | case bp_shlib_event: | |
4385 | shlib_event = 1; | |
4386 | ||
4387 | /* If requested, stop when the dynamic linker notifies GDB | |
4388 | of events. This allows the user to get control and place | |
4389 | breakpoints in initializer routines for dynamically | |
4390 | loaded objects (among other things). */ | |
4391 | if (stop_on_solib_events) | |
4392 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4393 | else | |
4394 | this_action = BPSTAT_WHAT_SINGLE; | |
4395 | break; | |
4396 | case bp_jit_event: | |
4397 | jit_event = 1; | |
4398 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4399 | break; |
c906108c | 4400 | case bp_call_dummy: |
53a5351d JM |
4401 | /* Make sure the action is stop (silent or noisy), |
4402 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4403 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4404 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4405 | break; |
4406 | case bp_std_terminate: | |
4407 | /* Make sure the action is stop (silent or noisy), | |
4408 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4409 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4410 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4411 | break; |
1042e4c0 | 4412 | case bp_tracepoint: |
7a697b8d | 4413 | case bp_fast_tracepoint: |
0fb4aa4b | 4414 | case bp_static_tracepoint: |
1042e4c0 SS |
4415 | /* Tracepoint hits should not be reported back to GDB, and |
4416 | if one got through somehow, it should have been filtered | |
4417 | out already. */ | |
4418 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4419 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
4420 | break; |
4421 | case bp_gnu_ifunc_resolver: | |
4422 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
4423 | this_action = BPSTAT_WHAT_SINGLE; | |
4424 | break; | |
4425 | case bp_gnu_ifunc_resolver_return: | |
4426 | /* The breakpoint will be removed, execution will restart from the | |
4427 | PC of the former breakpoint. */ | |
4428 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4429 | break; | |
628fe4e4 JK |
4430 | default: |
4431 | internal_error (__FILE__, __LINE__, | |
4432 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4433 | } |
628fe4e4 JK |
4434 | |
4435 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4436 | } |
628fe4e4 | 4437 | |
0e30163f JK |
4438 | /* These operations may affect the bs->breakpoint_at state so they are |
4439 | delayed after MAIN_ACTION is decided above. */ | |
4440 | ||
628fe4e4 JK |
4441 | if (shlib_event) |
4442 | { | |
4443 | if (debug_infrun) | |
4444 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4445 | ||
4446 | /* Check for any newly added shared libraries if we're supposed | |
4447 | to be adding them automatically. */ | |
4448 | ||
4449 | /* Switch terminal for any messages produced by | |
4450 | breakpoint_re_set. */ | |
4451 | target_terminal_ours_for_output (); | |
4452 | ||
4453 | #ifdef SOLIB_ADD | |
4454 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4455 | #else | |
4456 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4457 | #endif | |
4458 | ||
4459 | target_terminal_inferior (); | |
4460 | } | |
4461 | ||
4462 | if (jit_event) | |
4463 | { | |
4464 | if (debug_infrun) | |
4465 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4466 | ||
4467 | handle_jit_event (); | |
4468 | } | |
4469 | ||
0e30163f JK |
4470 | for (bs = bs_head; bs != NULL; bs = bs->next) |
4471 | { | |
4472 | struct breakpoint *b = bs->breakpoint_at; | |
4473 | ||
4474 | if (b == NULL) | |
4475 | continue; | |
4476 | switch (b->type) | |
4477 | { | |
4478 | case bp_gnu_ifunc_resolver: | |
4479 | gnu_ifunc_resolver_stop (b); | |
4480 | break; | |
4481 | case bp_gnu_ifunc_resolver_return: | |
4482 | gnu_ifunc_resolver_return_stop (b); | |
4483 | break; | |
4484 | } | |
4485 | } | |
4486 | ||
c906108c SS |
4487 | return retval; |
4488 | } | |
4489 | ||
4490 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4491 | without hardware support). This isn't related to a specific bpstat, | |
4492 | just to things like whether watchpoints are set. */ | |
4493 | ||
c5aa993b | 4494 | int |
fba45db2 | 4495 | bpstat_should_step (void) |
c906108c SS |
4496 | { |
4497 | struct breakpoint *b; | |
cc59ec59 | 4498 | |
c906108c | 4499 | ALL_BREAKPOINTS (b) |
717a8278 | 4500 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4501 | return 1; |
c906108c SS |
4502 | return 0; |
4503 | } | |
4504 | ||
67822962 PA |
4505 | int |
4506 | bpstat_causes_stop (bpstat bs) | |
4507 | { | |
4508 | for (; bs != NULL; bs = bs->next) | |
4509 | if (bs->stop) | |
4510 | return 1; | |
4511 | ||
4512 | return 0; | |
4513 | } | |
4514 | ||
c906108c | 4515 | \f |
c5aa993b | 4516 | |
170b53b2 UW |
4517 | /* Compute a string of spaces suitable to indent the next line |
4518 | so it starts at the position corresponding to the table column | |
4519 | named COL_NAME in the currently active table of UIOUT. */ | |
4520 | ||
4521 | static char * | |
4522 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
4523 | { | |
4524 | static char wrap_indent[80]; | |
4525 | int i, total_width, width, align; | |
4526 | char *text; | |
4527 | ||
4528 | total_width = 0; | |
4529 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
4530 | { | |
4531 | if (strcmp (text, col_name) == 0) | |
4532 | { | |
4533 | gdb_assert (total_width < sizeof wrap_indent); | |
4534 | memset (wrap_indent, ' ', total_width); | |
4535 | wrap_indent[total_width] = 0; | |
4536 | ||
4537 | return wrap_indent; | |
4538 | } | |
4539 | ||
4540 | total_width += width + 1; | |
4541 | } | |
4542 | ||
4543 | return NULL; | |
4544 | } | |
4545 | ||
859825b8 JK |
4546 | /* Print the LOC location out of the list of B->LOC locations. */ |
4547 | ||
170b53b2 UW |
4548 | static void |
4549 | print_breakpoint_location (struct breakpoint *b, | |
4550 | struct bp_location *loc) | |
0d381245 | 4551 | { |
79a45e25 | 4552 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
4553 | struct cleanup *old_chain = save_current_program_space (); |
4554 | ||
859825b8 JK |
4555 | if (loc != NULL && loc->shlib_disabled) |
4556 | loc = NULL; | |
4557 | ||
6c95b8df PA |
4558 | if (loc != NULL) |
4559 | set_current_program_space (loc->pspace); | |
4560 | ||
56435ebe TT |
4561 | if (b->display_canonical) |
4562 | ui_out_field_string (uiout, "what", b->addr_string); | |
4563 | else if (b->source_file && loc) | |
0d381245 VP |
4564 | { |
4565 | struct symbol *sym | |
4566 | = find_pc_sect_function (loc->address, loc->section); | |
4567 | if (sym) | |
4568 | { | |
4569 | ui_out_text (uiout, "in "); | |
4570 | ui_out_field_string (uiout, "func", | |
4571 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
4572 | ui_out_text (uiout, " "); |
4573 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
4574 | ui_out_text (uiout, "at "); | |
0d381245 VP |
4575 | } |
4576 | ui_out_field_string (uiout, "file", b->source_file); | |
4577 | ui_out_text (uiout, ":"); | |
4578 | ||
4579 | if (ui_out_is_mi_like_p (uiout)) | |
4580 | { | |
4581 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4582 | char *fullname = symtab_to_fullname (sal.symtab); | |
4583 | ||
4584 | if (fullname) | |
4585 | ui_out_field_string (uiout, "fullname", fullname); | |
4586 | } | |
4587 | ||
4588 | ui_out_field_int (uiout, "line", b->line_number); | |
4589 | } | |
859825b8 | 4590 | else if (loc) |
0d381245 | 4591 | { |
170b53b2 UW |
4592 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4593 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
4594 | ||
22e722e1 DJ |
4595 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4596 | demangle, ""); | |
0d381245 | 4597 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
4598 | |
4599 | do_cleanups (stb_chain); | |
0d381245 | 4600 | } |
859825b8 JK |
4601 | else |
4602 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4603 | |
4604 | do_cleanups (old_chain); | |
0d381245 VP |
4605 | } |
4606 | ||
269b11a2 PA |
4607 | static const char * |
4608 | bptype_string (enum bptype type) | |
c906108c | 4609 | { |
c4093a6a JM |
4610 | struct ep_type_description |
4611 | { | |
4612 | enum bptype type; | |
4613 | char *description; | |
4614 | }; | |
4615 | static struct ep_type_description bptypes[] = | |
c906108c | 4616 | { |
c5aa993b JM |
4617 | {bp_none, "?deleted?"}, |
4618 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4619 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4620 | {bp_until, "until"}, |
4621 | {bp_finish, "finish"}, | |
4622 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4623 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4624 | {bp_read_watchpoint, "read watchpoint"}, |
4625 | {bp_access_watchpoint, "acc watchpoint"}, | |
4626 | {bp_longjmp, "longjmp"}, | |
4627 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4628 | {bp_exception, "exception"}, |
4629 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4630 | {bp_step_resume, "step resume"}, |
2c03e5be | 4631 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
4632 | {bp_watchpoint_scope, "watchpoint scope"}, |
4633 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4634 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4635 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4636 | {bp_thread_event, "thread events"}, |
1900040c | 4637 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4638 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4639 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4640 | {bp_exception_master, "exception master"}, |
ce78b96d | 4641 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4642 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4643 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4644 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4645 | {bp_jit_event, "jit events"}, |
0e30163f JK |
4646 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
4647 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 4648 | }; |
269b11a2 PA |
4649 | |
4650 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4651 | || ((int) type != bptypes[(int) type].type)) | |
4652 | internal_error (__FILE__, __LINE__, | |
4653 | _("bptypes table does not describe type #%d."), | |
4654 | (int) type); | |
4655 | ||
4656 | return bptypes[(int) type].description; | |
4657 | } | |
4658 | ||
4659 | /* Print B to gdb_stdout. */ | |
4660 | ||
4661 | static void | |
4662 | print_one_breakpoint_location (struct breakpoint *b, | |
4663 | struct bp_location *loc, | |
4664 | int loc_number, | |
4665 | struct bp_location **last_loc, | |
269b11a2 PA |
4666 | int allflag) |
4667 | { | |
4668 | struct command_line *l; | |
c2c6d25f | 4669 | static char bpenables[] = "nynny"; |
c906108c | 4670 | |
79a45e25 | 4671 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
4672 | int header_of_multiple = 0; |
4673 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4674 | struct value_print_options opts; |
4675 | ||
4676 | get_user_print_options (&opts); | |
0d381245 VP |
4677 | |
4678 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4679 | /* See comment in print_one_breakpoint concerning treatment of |
4680 | breakpoints with single disabled location. */ | |
0d381245 VP |
4681 | if (loc == NULL |
4682 | && (b->loc != NULL | |
4683 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4684 | header_of_multiple = 1; | |
4685 | if (loc == NULL) | |
4686 | loc = b->loc; | |
4687 | ||
c4093a6a JM |
4688 | annotate_record (); |
4689 | ||
4690 | /* 1 */ | |
4691 | annotate_field (0); | |
0d381245 VP |
4692 | if (part_of_multiple) |
4693 | { | |
4694 | char *formatted; | |
0c6773c1 | 4695 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4696 | ui_out_field_string (uiout, "number", formatted); |
4697 | xfree (formatted); | |
4698 | } | |
4699 | else | |
4700 | { | |
4701 | ui_out_field_int (uiout, "number", b->number); | |
4702 | } | |
c4093a6a JM |
4703 | |
4704 | /* 2 */ | |
4705 | annotate_field (1); | |
0d381245 VP |
4706 | if (part_of_multiple) |
4707 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4708 | else |
4709 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4710 | |
4711 | /* 3 */ | |
4712 | annotate_field (2); | |
0d381245 VP |
4713 | if (part_of_multiple) |
4714 | ui_out_field_skip (uiout, "disp"); | |
4715 | else | |
2cec12e5 | 4716 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4717 | |
c4093a6a JM |
4718 | |
4719 | /* 4 */ | |
4720 | annotate_field (3); | |
0d381245 | 4721 | if (part_of_multiple) |
54e52265 | 4722 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4723 | else |
4a64f543 MS |
4724 | ui_out_field_fmt (uiout, "enabled", "%c", |
4725 | bpenables[(int) b->enable_state]); | |
54e52265 | 4726 | ui_out_spaces (uiout, 2); |
0d381245 | 4727 | |
c4093a6a JM |
4728 | |
4729 | /* 5 and 6 */ | |
3086aeae | 4730 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4731 | { |
4a64f543 MS |
4732 | /* Although the print_one can possibly print all locations, |
4733 | calling it here is not likely to get any nice result. So, | |
4734 | make sure there's just one location. */ | |
0d381245 | 4735 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4736 | b->ops->print_one (b, last_loc); |
0d381245 | 4737 | } |
3086aeae DJ |
4738 | else |
4739 | switch (b->type) | |
4740 | { | |
4741 | case bp_none: | |
4742 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4743 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4744 | break; |
c906108c | 4745 | |
3086aeae DJ |
4746 | case bp_watchpoint: |
4747 | case bp_hardware_watchpoint: | |
4748 | case bp_read_watchpoint: | |
4749 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4750 | { |
4751 | struct watchpoint *w = (struct watchpoint *) b; | |
4752 | ||
4753 | /* Field 4, the address, is omitted (which makes the columns | |
4754 | not line up too nicely with the headers, but the effect | |
4755 | is relatively readable). */ | |
4756 | if (opts.addressprint) | |
4757 | ui_out_field_skip (uiout, "addr"); | |
4758 | annotate_field (5); | |
4759 | ui_out_field_string (uiout, "what", w->exp_string); | |
4760 | } | |
3086aeae DJ |
4761 | break; |
4762 | ||
3086aeae DJ |
4763 | case bp_breakpoint: |
4764 | case bp_hardware_breakpoint: | |
4765 | case bp_until: | |
4766 | case bp_finish: | |
4767 | case bp_longjmp: | |
4768 | case bp_longjmp_resume: | |
186c406b TT |
4769 | case bp_exception: |
4770 | case bp_exception_resume: | |
3086aeae | 4771 | case bp_step_resume: |
2c03e5be | 4772 | case bp_hp_step_resume: |
3086aeae DJ |
4773 | case bp_watchpoint_scope: |
4774 | case bp_call_dummy: | |
aa7d318d | 4775 | case bp_std_terminate: |
3086aeae DJ |
4776 | case bp_shlib_event: |
4777 | case bp_thread_event: | |
4778 | case bp_overlay_event: | |
0fd8e87f | 4779 | case bp_longjmp_master: |
aa7d318d | 4780 | case bp_std_terminate_master: |
186c406b | 4781 | case bp_exception_master: |
1042e4c0 | 4782 | case bp_tracepoint: |
7a697b8d | 4783 | case bp_fast_tracepoint: |
0fb4aa4b | 4784 | case bp_static_tracepoint: |
4efc6507 | 4785 | case bp_jit_event: |
0e30163f JK |
4786 | case bp_gnu_ifunc_resolver: |
4787 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 4788 | if (opts.addressprint) |
3086aeae DJ |
4789 | { |
4790 | annotate_field (4); | |
54e52265 | 4791 | if (header_of_multiple) |
0d381245 | 4792 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4793 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4794 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4795 | else |
5af949e3 UW |
4796 | ui_out_field_core_addr (uiout, "addr", |
4797 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4798 | } |
4799 | annotate_field (5); | |
0d381245 | 4800 | if (!header_of_multiple) |
170b53b2 | 4801 | print_breakpoint_location (b, loc); |
0d381245 | 4802 | if (b->loc) |
a6d9a66e | 4803 | *last_loc = b->loc; |
3086aeae DJ |
4804 | break; |
4805 | } | |
c906108c | 4806 | |
6c95b8df PA |
4807 | |
4808 | /* For backward compatibility, don't display inferiors unless there | |
4809 | are several. */ | |
4810 | if (loc != NULL | |
4811 | && !header_of_multiple | |
4812 | && (allflag | |
4813 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4814 | && (number_of_program_spaces () > 1 | |
4815 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4816 | /* LOC is for existing B, it cannot be in |
4817 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4818 | && loc->owner->type != bp_catchpoint))) |
4819 | { | |
4820 | struct inferior *inf; | |
4821 | int first = 1; | |
4822 | ||
4823 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4824 | { | |
4825 | if (inf->pspace == loc->pspace) | |
4826 | { | |
4827 | if (first) | |
4828 | { | |
4829 | first = 0; | |
4830 | ui_out_text (uiout, " inf "); | |
4831 | } | |
4832 | else | |
4833 | ui_out_text (uiout, ", "); | |
4834 | ui_out_text (uiout, plongest (inf->num)); | |
4835 | } | |
4836 | } | |
4837 | } | |
4838 | ||
4a306c9a | 4839 | if (!part_of_multiple) |
c4093a6a | 4840 | { |
4a306c9a JB |
4841 | if (b->thread != -1) |
4842 | { | |
4843 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4844 | "stop only in" line a little further down. */ |
4a306c9a JB |
4845 | ui_out_text (uiout, " thread "); |
4846 | ui_out_field_int (uiout, "thread", b->thread); | |
4847 | } | |
4848 | else if (b->task != 0) | |
4849 | { | |
4850 | ui_out_text (uiout, " task "); | |
4851 | ui_out_field_int (uiout, "task", b->task); | |
4852 | } | |
c4093a6a | 4853 | } |
f1310107 | 4854 | |
8b93c638 | 4855 | ui_out_text (uiout, "\n"); |
f1310107 | 4856 | |
348d480f | 4857 | if (!part_of_multiple) |
f1310107 TJB |
4858 | b->ops->print_one_detail (b, uiout); |
4859 | ||
0d381245 | 4860 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4861 | { |
4862 | annotate_field (6); | |
8b93c638 | 4863 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 4864 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 4865 | the frame ID. */ |
5af949e3 UW |
4866 | ui_out_field_core_addr (uiout, "frame", |
4867 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4868 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4869 | } |
4870 | ||
28010a5d | 4871 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
4872 | { |
4873 | annotate_field (7); | |
d77f58be | 4874 | if (is_tracepoint (b)) |
1042e4c0 SS |
4875 | ui_out_text (uiout, "\ttrace only if "); |
4876 | else | |
4877 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4878 | ui_out_field_string (uiout, "cond", b->cond_string); |
4879 | ui_out_text (uiout, "\n"); | |
4880 | } | |
4881 | ||
0d381245 | 4882 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 4883 | { |
4a64f543 | 4884 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4885 | ui_out_text (uiout, "\tstop only in thread "); |
4886 | ui_out_field_int (uiout, "thread", b->thread); | |
4887 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4888 | } |
4889 | ||
63c715c6 | 4890 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 4891 | { |
4a64f543 | 4892 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4893 | if (ep_is_catchpoint (b)) |
4894 | ui_out_text (uiout, "\tcatchpoint"); | |
f196051f SS |
4895 | else if (is_tracepoint (b)) |
4896 | ui_out_text (uiout, "\ttracepoint"); | |
8b93c638 JM |
4897 | else |
4898 | ui_out_text (uiout, "\tbreakpoint"); | |
4899 | ui_out_text (uiout, " already hit "); | |
4900 | ui_out_field_int (uiout, "times", b->hit_count); | |
4901 | if (b->hit_count == 1) | |
4902 | ui_out_text (uiout, " time\n"); | |
4903 | else | |
4904 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4905 | } |
4906 | ||
4a64f543 MS |
4907 | /* Output the count also if it is zero, but only if this is mi. |
4908 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4909 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4910 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4911 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4912 | |
0d381245 | 4913 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4914 | { |
4915 | annotate_field (8); | |
8b93c638 JM |
4916 | ui_out_text (uiout, "\tignore next "); |
4917 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4918 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4919 | } |
059fb39f | 4920 | |
f196051f SS |
4921 | if (!part_of_multiple && is_tracepoint (b)) |
4922 | { | |
4923 | struct tracepoint *tp = (struct tracepoint *) b; | |
4924 | ||
4925 | if (tp->traceframe_usage) | |
4926 | { | |
4927 | ui_out_text (uiout, "\ttrace buffer usage "); | |
4928 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
4929 | ui_out_text (uiout, " bytes\n"); | |
4930 | } | |
4931 | } | |
4932 | ||
9add0f1b | 4933 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4934 | if (!part_of_multiple && l) |
c4093a6a | 4935 | { |
3b31d625 EZ |
4936 | struct cleanup *script_chain; |
4937 | ||
c4093a6a | 4938 | annotate_field (9); |
3b31d625 | 4939 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4940 | print_command_lines (uiout, l, 4); |
3b31d625 | 4941 | do_cleanups (script_chain); |
c4093a6a | 4942 | } |
d24317b4 | 4943 | |
d9b3f62e | 4944 | if (is_tracepoint (b)) |
1042e4c0 | 4945 | { |
d9b3f62e PA |
4946 | struct tracepoint *t = (struct tracepoint *) b; |
4947 | ||
4948 | if (!part_of_multiple && t->pass_count) | |
4949 | { | |
4950 | annotate_field (10); | |
4951 | ui_out_text (uiout, "\tpass count "); | |
4952 | ui_out_field_int (uiout, "pass", t->pass_count); | |
4953 | ui_out_text (uiout, " \n"); | |
4954 | } | |
1042e4c0 SS |
4955 | } |
4956 | ||
d24317b4 VP |
4957 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4958 | { | |
3a5c3e22 PA |
4959 | if (is_watchpoint (b)) |
4960 | { | |
4961 | struct watchpoint *w = (struct watchpoint *) b; | |
4962 | ||
4963 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
4964 | } | |
4965 | else if (b->addr_string) | |
d24317b4 | 4966 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 4967 | } |
c4093a6a | 4968 | } |
c5aa993b | 4969 | |
0d381245 VP |
4970 | static void |
4971 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 4972 | struct bp_location **last_loc, |
6c95b8df | 4973 | int allflag) |
0d381245 | 4974 | { |
8d3788bd | 4975 | struct cleanup *bkpt_chain; |
79a45e25 | 4976 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
4977 | |
4978 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
4979 | ||
12c5a436 | 4980 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 4981 | do_cleanups (bkpt_chain); |
0d381245 VP |
4982 | |
4983 | /* If this breakpoint has custom print function, | |
4984 | it's already printed. Otherwise, print individual | |
4985 | locations, if any. */ | |
4986 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4987 | { | |
4a64f543 MS |
4988 | /* If breakpoint has a single location that is disabled, we |
4989 | print it as if it had several locations, since otherwise it's | |
4990 | hard to represent "breakpoint enabled, location disabled" | |
4991 | situation. | |
4992 | ||
4993 | Note that while hardware watchpoints have several locations | |
a3be7890 | 4994 | internally, that's not a property exposed to user. */ |
0d381245 | 4995 | if (b->loc |
a5606eee | 4996 | && !is_hardware_watchpoint (b) |
8d3788bd | 4997 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
4998 | { |
4999 | struct bp_location *loc; | |
5000 | int n = 1; | |
8d3788bd | 5001 | |
0d381245 | 5002 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
5003 | { |
5004 | struct cleanup *inner2 = | |
5005 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
5006 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
5007 | do_cleanups (inner2); | |
5008 | } | |
0d381245 VP |
5009 | } |
5010 | } | |
5011 | } | |
5012 | ||
a6d9a66e UW |
5013 | static int |
5014 | breakpoint_address_bits (struct breakpoint *b) | |
5015 | { | |
5016 | int print_address_bits = 0; | |
5017 | struct bp_location *loc; | |
5018 | ||
5019 | for (loc = b->loc; loc; loc = loc->next) | |
5020 | { | |
c7437ca6 PA |
5021 | int addr_bit; |
5022 | ||
5023 | /* Software watchpoints that aren't watching memory don't have | |
5024 | an address to print. */ | |
5025 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5026 | continue; | |
5027 | ||
5028 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5029 | if (addr_bit > print_address_bits) |
5030 | print_address_bits = addr_bit; | |
5031 | } | |
5032 | ||
5033 | return print_address_bits; | |
5034 | } | |
0d381245 | 5035 | |
c4093a6a JM |
5036 | struct captured_breakpoint_query_args |
5037 | { | |
5038 | int bnum; | |
5039 | }; | |
c5aa993b | 5040 | |
c4093a6a | 5041 | static int |
2b65245e | 5042 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5043 | { |
5044 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5045 | struct breakpoint *b; |
a6d9a66e | 5046 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5047 | |
c4093a6a JM |
5048 | ALL_BREAKPOINTS (b) |
5049 | { | |
5050 | if (args->bnum == b->number) | |
c5aa993b | 5051 | { |
12c5a436 | 5052 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5053 | return GDB_RC_OK; |
c5aa993b | 5054 | } |
c4093a6a JM |
5055 | } |
5056 | return GDB_RC_NONE; | |
5057 | } | |
c5aa993b | 5058 | |
c4093a6a | 5059 | enum gdb_rc |
4a64f543 MS |
5060 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5061 | char **error_message) | |
c4093a6a JM |
5062 | { |
5063 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5064 | |
c4093a6a JM |
5065 | args.bnum = bnum; |
5066 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5067 | an error. */ |
b0b13bb4 DJ |
5068 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5069 | error_message, RETURN_MASK_ALL) < 0) | |
5070 | return GDB_RC_FAIL; | |
5071 | else | |
5072 | return GDB_RC_OK; | |
c4093a6a | 5073 | } |
c5aa993b | 5074 | |
09d682a4 TT |
5075 | /* Return true if this breakpoint was set by the user, false if it is |
5076 | internal or momentary. */ | |
5077 | ||
5078 | int | |
5079 | user_breakpoint_p (struct breakpoint *b) | |
5080 | { | |
46c6471b | 5081 | return b->number > 0; |
09d682a4 TT |
5082 | } |
5083 | ||
7f3b0473 | 5084 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5085 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5086 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5087 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5088 | ones for which it returns non-zero. Return the total number of | |
5089 | breakpoints listed. */ | |
c906108c | 5090 | |
d77f58be | 5091 | static int |
e5a67952 | 5092 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5093 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5094 | { |
52f0bd74 | 5095 | struct breakpoint *b; |
a6d9a66e | 5096 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5097 | int nr_printable_breakpoints; |
3b31d625 | 5098 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5099 | struct value_print_options opts; |
a6d9a66e | 5100 | int print_address_bits = 0; |
269b11a2 | 5101 | int print_type_col_width = 14; |
79a45e25 | 5102 | struct ui_out *uiout = current_uiout; |
269b11a2 | 5103 | |
79a45b7d TT |
5104 | get_user_print_options (&opts); |
5105 | ||
4a64f543 MS |
5106 | /* Compute the number of rows in the table, as well as the size |
5107 | required for address fields. */ | |
7f3b0473 AC |
5108 | nr_printable_breakpoints = 0; |
5109 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5110 | { |
5111 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5112 | if (filter && !filter (b)) | |
5113 | continue; | |
5114 | ||
5115 | /* If we have an "args" string, it is a list of breakpoints to | |
5116 | accept. Skip the others. */ | |
5117 | if (args != NULL && *args != '\0') | |
5118 | { | |
5119 | if (allflag && parse_and_eval_long (args) != b->number) | |
5120 | continue; | |
5121 | if (!allflag && !number_is_in_list (args, b->number)) | |
5122 | continue; | |
5123 | } | |
269b11a2 | 5124 | |
e5a67952 MS |
5125 | if (allflag || user_breakpoint_p (b)) |
5126 | { | |
5127 | int addr_bit, type_len; | |
a6d9a66e | 5128 | |
e5a67952 MS |
5129 | addr_bit = breakpoint_address_bits (b); |
5130 | if (addr_bit > print_address_bits) | |
5131 | print_address_bits = addr_bit; | |
269b11a2 | 5132 | |
e5a67952 MS |
5133 | type_len = strlen (bptype_string (b->type)); |
5134 | if (type_len > print_type_col_width) | |
5135 | print_type_col_width = type_len; | |
5136 | ||
5137 | nr_printable_breakpoints++; | |
5138 | } | |
5139 | } | |
7f3b0473 | 5140 | |
79a45b7d | 5141 | if (opts.addressprint) |
3b31d625 | 5142 | bkpttbl_chain |
3e43a32a MS |
5143 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5144 | nr_printable_breakpoints, | |
3b31d625 | 5145 | "BreakpointTable"); |
8b93c638 | 5146 | else |
3b31d625 | 5147 | bkpttbl_chain |
3e43a32a MS |
5148 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5149 | nr_printable_breakpoints, | |
3b31d625 | 5150 | "BreakpointTable"); |
8b93c638 | 5151 | |
7f3b0473 | 5152 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5153 | annotate_breakpoints_headers (); |
5154 | if (nr_printable_breakpoints > 0) | |
5155 | annotate_field (0); | |
4a64f543 | 5156 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5157 | if (nr_printable_breakpoints > 0) |
5158 | annotate_field (1); | |
269b11a2 | 5159 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5160 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5161 | if (nr_printable_breakpoints > 0) |
5162 | annotate_field (2); | |
4a64f543 | 5163 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5164 | if (nr_printable_breakpoints > 0) |
5165 | annotate_field (3); | |
54e52265 | 5166 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5167 | if (opts.addressprint) |
e5a67952 MS |
5168 | { |
5169 | if (nr_printable_breakpoints > 0) | |
5170 | annotate_field (4); | |
5171 | if (print_address_bits <= 32) | |
5172 | ui_out_table_header (uiout, 10, ui_left, | |
5173 | "addr", "Address"); /* 5 */ | |
5174 | else | |
5175 | ui_out_table_header (uiout, 18, ui_left, | |
5176 | "addr", "Address"); /* 5 */ | |
5177 | } | |
d7faa9e7 AC |
5178 | if (nr_printable_breakpoints > 0) |
5179 | annotate_field (5); | |
5180 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5181 | ui_out_table_body (uiout); | |
5182 | if (nr_printable_breakpoints > 0) | |
5183 | annotate_breakpoints_table (); | |
7f3b0473 | 5184 | |
c4093a6a | 5185 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5186 | { |
5187 | QUIT; | |
5188 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5189 | if (filter && !filter (b)) | |
5190 | continue; | |
5191 | ||
5192 | /* If we have an "args" string, it is a list of breakpoints to | |
5193 | accept. Skip the others. */ | |
5194 | ||
5195 | if (args != NULL && *args != '\0') | |
5196 | { | |
5197 | if (allflag) /* maintenance info breakpoint */ | |
5198 | { | |
5199 | if (parse_and_eval_long (args) != b->number) | |
5200 | continue; | |
5201 | } | |
5202 | else /* all others */ | |
5203 | { | |
5204 | if (!number_is_in_list (args, b->number)) | |
5205 | continue; | |
5206 | } | |
5207 | } | |
5208 | /* We only print out user settable breakpoints unless the | |
5209 | allflag is set. */ | |
5210 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5211 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5212 | } |
5213 | ||
3b31d625 | 5214 | do_cleanups (bkpttbl_chain); |
698384cd | 5215 | |
7f3b0473 | 5216 | if (nr_printable_breakpoints == 0) |
c906108c | 5217 | { |
4a64f543 MS |
5218 | /* If there's a filter, let the caller decide how to report |
5219 | empty list. */ | |
d77f58be SS |
5220 | if (!filter) |
5221 | { | |
e5a67952 | 5222 | if (args == NULL || *args == '\0') |
d77f58be SS |
5223 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5224 | else | |
4a64f543 | 5225 | ui_out_message (uiout, 0, |
e5a67952 MS |
5226 | "No breakpoint or watchpoint matching '%s'.\n", |
5227 | args); | |
d77f58be | 5228 | } |
c906108c SS |
5229 | } |
5230 | else | |
c4093a6a | 5231 | { |
a6d9a66e UW |
5232 | if (last_loc && !server_command) |
5233 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5234 | } |
c906108c | 5235 | |
4a64f543 | 5236 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5237 | there have been breakpoints? */ |
c906108c | 5238 | annotate_breakpoints_table_end (); |
d77f58be SS |
5239 | |
5240 | return nr_printable_breakpoints; | |
c906108c SS |
5241 | } |
5242 | ||
ad443146 SS |
5243 | /* Display the value of default-collect in a way that is generally |
5244 | compatible with the breakpoint list. */ | |
5245 | ||
5246 | static void | |
5247 | default_collect_info (void) | |
5248 | { | |
79a45e25 PA |
5249 | struct ui_out *uiout = current_uiout; |
5250 | ||
ad443146 SS |
5251 | /* If it has no value (which is frequently the case), say nothing; a |
5252 | message like "No default-collect." gets in user's face when it's | |
5253 | not wanted. */ | |
5254 | if (!*default_collect) | |
5255 | return; | |
5256 | ||
5257 | /* The following phrase lines up nicely with per-tracepoint collect | |
5258 | actions. */ | |
5259 | ui_out_text (uiout, "default collect "); | |
5260 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5261 | ui_out_text (uiout, " \n"); | |
5262 | } | |
5263 | ||
c906108c | 5264 | static void |
e5a67952 | 5265 | breakpoints_info (char *args, int from_tty) |
c906108c | 5266 | { |
e5a67952 | 5267 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5268 | |
5269 | default_collect_info (); | |
d77f58be SS |
5270 | } |
5271 | ||
5272 | static void | |
e5a67952 | 5273 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5274 | { |
e5a67952 | 5275 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 5276 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
5277 | |
5278 | if (num_printed == 0) | |
5279 | { | |
e5a67952 | 5280 | if (args == NULL || *args == '\0') |
d77f58be SS |
5281 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5282 | else | |
e5a67952 | 5283 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5284 | } |
c906108c SS |
5285 | } |
5286 | ||
7a292a7a | 5287 | static void |
e5a67952 | 5288 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5289 | { |
e5a67952 | 5290 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5291 | |
5292 | default_collect_info (); | |
c906108c SS |
5293 | } |
5294 | ||
0d381245 | 5295 | static int |
714835d5 | 5296 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5297 | struct program_space *pspace, |
714835d5 | 5298 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5299 | { |
5300 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5301 | |
0d381245 VP |
5302 | for (; bl; bl = bl->next) |
5303 | { | |
6c95b8df PA |
5304 | if (bl->pspace == pspace |
5305 | && bl->address == pc | |
0d381245 VP |
5306 | && (!overlay_debugging || bl->section == section)) |
5307 | return 1; | |
5308 | } | |
5309 | return 0; | |
5310 | } | |
5311 | ||
672f9b60 | 5312 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
5313 | concerns with logical breakpoints, so we match program spaces, not |
5314 | address spaces. */ | |
c906108c SS |
5315 | |
5316 | static void | |
6c95b8df PA |
5317 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5318 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5319 | struct obj_section *section, int thread) |
c906108c | 5320 | { |
52f0bd74 AC |
5321 | int others = 0; |
5322 | struct breakpoint *b; | |
c906108c SS |
5323 | |
5324 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
5325 | others += (user_breakpoint_p (b) |
5326 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
5327 | if (others > 0) |
5328 | { | |
a3f17187 AC |
5329 | if (others == 1) |
5330 | printf_filtered (_("Note: breakpoint ")); | |
5331 | else /* if (others == ???) */ | |
5332 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5333 | ALL_BREAKPOINTS (b) |
672f9b60 | 5334 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5335 | { |
5336 | others--; | |
5337 | printf_filtered ("%d", b->number); | |
5338 | if (b->thread == -1 && thread != -1) | |
5339 | printf_filtered (" (all threads)"); | |
5340 | else if (b->thread != -1) | |
5341 | printf_filtered (" (thread %d)", b->thread); | |
5342 | printf_filtered ("%s%s ", | |
059fb39f | 5343 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5344 | || b->enable_state == bp_call_disabled |
5345 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5346 | ? " (disabled)" |
5347 | : b->enable_state == bp_permanent | |
5348 | ? " (permanent)" | |
5349 | : ""), | |
5350 | (others > 1) ? "," | |
5351 | : ((others == 1) ? " and" : "")); | |
5352 | } | |
a3f17187 | 5353 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5354 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5355 | printf_filtered (".\n"); |
5356 | } | |
5357 | } | |
5358 | \f | |
c906108c | 5359 | |
e4f237da KB |
5360 | /* Return true iff it is meaningful to use the address member of |
5361 | BPT. For some breakpoint types, the address member is irrelevant | |
5362 | and it makes no sense to attempt to compare it to other addresses | |
5363 | (or use it for any other purpose either). | |
5364 | ||
4a64f543 MS |
5365 | More specifically, each of the following breakpoint types will |
5366 | always have a zero valued address and we don't want to mark | |
5367 | breakpoints of any of these types to be a duplicate of an actual | |
5368 | breakpoint at address zero: | |
e4f237da KB |
5369 | |
5370 | bp_watchpoint | |
2d134ed3 PA |
5371 | bp_catchpoint |
5372 | ||
5373 | */ | |
e4f237da KB |
5374 | |
5375 | static int | |
5376 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5377 | { | |
5378 | enum bptype type = bpt->type; | |
5379 | ||
2d134ed3 PA |
5380 | return (type != bp_watchpoint && type != bp_catchpoint); |
5381 | } | |
5382 | ||
5383 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5384 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5385 | ||
5386 | static int | |
4a64f543 MS |
5387 | watchpoint_locations_match (struct bp_location *loc1, |
5388 | struct bp_location *loc2) | |
2d134ed3 | 5389 | { |
3a5c3e22 PA |
5390 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
5391 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
5392 | ||
5393 | /* Both of them must exist. */ | |
5394 | gdb_assert (w1 != NULL); | |
5395 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 5396 | |
4a64f543 MS |
5397 | /* If the target can evaluate the condition expression in hardware, |
5398 | then we we need to insert both watchpoints even if they are at | |
5399 | the same place. Otherwise the watchpoint will only trigger when | |
5400 | the condition of whichever watchpoint was inserted evaluates to | |
5401 | true, not giving a chance for GDB to check the condition of the | |
5402 | other watchpoint. */ | |
3a5c3e22 | 5403 | if ((w1->cond_exp |
4a64f543 MS |
5404 | && target_can_accel_watchpoint_condition (loc1->address, |
5405 | loc1->length, | |
0cf6dd15 | 5406 | loc1->watchpoint_type, |
3a5c3e22 PA |
5407 | w1->cond_exp)) |
5408 | || (w2->cond_exp | |
4a64f543 MS |
5409 | && target_can_accel_watchpoint_condition (loc2->address, |
5410 | loc2->length, | |
0cf6dd15 | 5411 | loc2->watchpoint_type, |
3a5c3e22 | 5412 | w2->cond_exp))) |
0cf6dd15 TJB |
5413 | return 0; |
5414 | ||
85d721b8 PA |
5415 | /* Note that this checks the owner's type, not the location's. In |
5416 | case the target does not support read watchpoints, but does | |
5417 | support access watchpoints, we'll have bp_read_watchpoint | |
5418 | watchpoints with hw_access locations. Those should be considered | |
5419 | duplicates of hw_read locations. The hw_read locations will | |
5420 | become hw_access locations later. */ | |
2d134ed3 PA |
5421 | return (loc1->owner->type == loc2->owner->type |
5422 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5423 | && loc1->address == loc2->address | |
5424 | && loc1->length == loc2->length); | |
e4f237da KB |
5425 | } |
5426 | ||
6c95b8df PA |
5427 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5428 | same breakpoint location. In most targets, this can only be true | |
5429 | if ASPACE1 matches ASPACE2. On targets that have global | |
5430 | breakpoints, the address space doesn't really matter. */ | |
5431 | ||
5432 | static int | |
5433 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5434 | struct address_space *aspace2, CORE_ADDR addr2) | |
5435 | { | |
5436 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5437 | || aspace1 == aspace2) | |
5438 | && addr1 == addr2); | |
5439 | } | |
5440 | ||
f1310107 TJB |
5441 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
5442 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
5443 | matches ASPACE2. On targets that have global breakpoints, the address | |
5444 | space doesn't really matter. */ | |
5445 | ||
5446 | static int | |
5447 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
5448 | int len1, struct address_space *aspace2, | |
5449 | CORE_ADDR addr2) | |
5450 | { | |
5451 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5452 | || aspace1 == aspace2) | |
5453 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
5454 | } | |
5455 | ||
5456 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
5457 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
5458 | matches the breakpoint's address space. On targets that have global | |
5459 | breakpoints, the address space doesn't really matter. */ | |
5460 | ||
5461 | static int | |
5462 | breakpoint_location_address_match (struct bp_location *bl, | |
5463 | struct address_space *aspace, | |
5464 | CORE_ADDR addr) | |
5465 | { | |
5466 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
5467 | aspace, addr) | |
5468 | || (bl->length | |
5469 | && breakpoint_address_match_range (bl->pspace->aspace, | |
5470 | bl->address, bl->length, | |
5471 | aspace, addr))); | |
5472 | } | |
5473 | ||
1e4d1764 YQ |
5474 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
5475 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
5476 | true, otherwise returns false. */ | |
5477 | ||
5478 | static int | |
5479 | tracepoint_locations_match (struct bp_location *loc1, | |
5480 | struct bp_location *loc2) | |
5481 | { | |
5482 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
5483 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
5484 | locations at the same address of different tracepoints are regarded as | |
5485 | different locations. */ | |
5486 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
5487 | else | |
5488 | return 0; | |
5489 | } | |
5490 | ||
2d134ed3 PA |
5491 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5492 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5493 | represent the same location. */ | |
5494 | ||
5495 | static int | |
4a64f543 MS |
5496 | breakpoint_locations_match (struct bp_location *loc1, |
5497 | struct bp_location *loc2) | |
2d134ed3 | 5498 | { |
2bdf28a0 JK |
5499 | int hw_point1, hw_point2; |
5500 | ||
5501 | /* Both of them must not be in moribund_locations. */ | |
5502 | gdb_assert (loc1->owner != NULL); | |
5503 | gdb_assert (loc2->owner != NULL); | |
5504 | ||
5505 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5506 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5507 | |
5508 | if (hw_point1 != hw_point2) | |
5509 | return 0; | |
5510 | else if (hw_point1) | |
5511 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
5512 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
5513 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 5514 | else |
f1310107 TJB |
5515 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
5516 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5517 | loc2->pspace->aspace, loc2->address) | |
5518 | && loc1->length == loc2->length); | |
2d134ed3 PA |
5519 | } |
5520 | ||
76897487 KB |
5521 | static void |
5522 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5523 | int bnum, int have_bnum) | |
5524 | { | |
f63fbe86 MS |
5525 | /* The longest string possibly returned by hex_string_custom |
5526 | is 50 chars. These must be at least that big for safety. */ | |
5527 | char astr1[64]; | |
5528 | char astr2[64]; | |
76897487 | 5529 | |
bb599908 PH |
5530 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5531 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5532 | if (have_bnum) |
8a3fe4f8 | 5533 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5534 | bnum, astr1, astr2); |
5535 | else | |
8a3fe4f8 | 5536 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5537 | } |
5538 | ||
4a64f543 MS |
5539 | /* Adjust a breakpoint's address to account for architectural |
5540 | constraints on breakpoint placement. Return the adjusted address. | |
5541 | Note: Very few targets require this kind of adjustment. For most | |
5542 | targets, this function is simply the identity function. */ | |
76897487 KB |
5543 | |
5544 | static CORE_ADDR | |
a6d9a66e UW |
5545 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5546 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5547 | { |
a6d9a66e | 5548 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5549 | { |
5550 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5551 | return bpaddr; | |
5552 | } | |
88f7da05 KB |
5553 | else if (bptype == bp_watchpoint |
5554 | || bptype == bp_hardware_watchpoint | |
5555 | || bptype == bp_read_watchpoint | |
5556 | || bptype == bp_access_watchpoint | |
fe798b75 | 5557 | || bptype == bp_catchpoint) |
88f7da05 KB |
5558 | { |
5559 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5560 | have their addresses modified. */ | |
5561 | return bpaddr; | |
5562 | } | |
76897487 KB |
5563 | else |
5564 | { | |
5565 | CORE_ADDR adjusted_bpaddr; | |
5566 | ||
5567 | /* Some targets have architectural constraints on the placement | |
5568 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5569 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5570 | |
5571 | /* An adjusted breakpoint address can significantly alter | |
5572 | a user's expectations. Print a warning if an adjustment | |
5573 | is required. */ | |
5574 | if (adjusted_bpaddr != bpaddr) | |
5575 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5576 | ||
5577 | return adjusted_bpaddr; | |
5578 | } | |
5579 | } | |
5580 | ||
28010a5d PA |
5581 | void |
5582 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
5583 | struct breakpoint *owner) | |
7cc221ef | 5584 | { |
7cc221ef DJ |
5585 | memset (loc, 0, sizeof (*loc)); |
5586 | ||
348d480f PA |
5587 | gdb_assert (ops != NULL); |
5588 | ||
28010a5d PA |
5589 | loc->ops = ops; |
5590 | loc->owner = owner; | |
511a6cd4 | 5591 | loc->cond = NULL; |
0d381245 VP |
5592 | loc->shlib_disabled = 0; |
5593 | loc->enabled = 1; | |
e049a4b5 | 5594 | |
28010a5d | 5595 | switch (owner->type) |
e049a4b5 DJ |
5596 | { |
5597 | case bp_breakpoint: | |
5598 | case bp_until: | |
5599 | case bp_finish: | |
5600 | case bp_longjmp: | |
5601 | case bp_longjmp_resume: | |
186c406b TT |
5602 | case bp_exception: |
5603 | case bp_exception_resume: | |
e049a4b5 | 5604 | case bp_step_resume: |
2c03e5be | 5605 | case bp_hp_step_resume: |
e049a4b5 DJ |
5606 | case bp_watchpoint_scope: |
5607 | case bp_call_dummy: | |
aa7d318d | 5608 | case bp_std_terminate: |
e049a4b5 DJ |
5609 | case bp_shlib_event: |
5610 | case bp_thread_event: | |
5611 | case bp_overlay_event: | |
4efc6507 | 5612 | case bp_jit_event: |
0fd8e87f | 5613 | case bp_longjmp_master: |
aa7d318d | 5614 | case bp_std_terminate_master: |
186c406b | 5615 | case bp_exception_master: |
0e30163f JK |
5616 | case bp_gnu_ifunc_resolver: |
5617 | case bp_gnu_ifunc_resolver_return: | |
e049a4b5 DJ |
5618 | loc->loc_type = bp_loc_software_breakpoint; |
5619 | break; | |
5620 | case bp_hardware_breakpoint: | |
5621 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5622 | break; | |
5623 | case bp_hardware_watchpoint: | |
5624 | case bp_read_watchpoint: | |
5625 | case bp_access_watchpoint: | |
5626 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5627 | break; | |
5628 | case bp_watchpoint: | |
ce78b96d | 5629 | case bp_catchpoint: |
15c3d785 PA |
5630 | case bp_tracepoint: |
5631 | case bp_fast_tracepoint: | |
0fb4aa4b | 5632 | case bp_static_tracepoint: |
e049a4b5 DJ |
5633 | loc->loc_type = bp_loc_other; |
5634 | break; | |
5635 | default: | |
e2e0b3e5 | 5636 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5637 | } |
5638 | ||
f431efe5 | 5639 | loc->refc = 1; |
28010a5d PA |
5640 | } |
5641 | ||
5642 | /* Allocate a struct bp_location. */ | |
5643 | ||
5644 | static struct bp_location * | |
5645 | allocate_bp_location (struct breakpoint *bpt) | |
5646 | { | |
348d480f PA |
5647 | return bpt->ops->allocate_location (bpt); |
5648 | } | |
7cc221ef | 5649 | |
f431efe5 PA |
5650 | static void |
5651 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 5652 | { |
348d480f | 5653 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
5654 | xfree (loc); |
5655 | } | |
5656 | ||
f431efe5 PA |
5657 | /* Increment reference count. */ |
5658 | ||
5659 | static void | |
5660 | incref_bp_location (struct bp_location *bl) | |
5661 | { | |
5662 | ++bl->refc; | |
5663 | } | |
5664 | ||
5665 | /* Decrement reference count. If the reference count reaches 0, | |
5666 | destroy the bp_location. Sets *BLP to NULL. */ | |
5667 | ||
5668 | static void | |
5669 | decref_bp_location (struct bp_location **blp) | |
5670 | { | |
0807b50c PA |
5671 | gdb_assert ((*blp)->refc > 0); |
5672 | ||
f431efe5 PA |
5673 | if (--(*blp)->refc == 0) |
5674 | free_bp_location (*blp); | |
5675 | *blp = NULL; | |
5676 | } | |
5677 | ||
346774a9 | 5678 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 5679 | |
346774a9 PA |
5680 | static void |
5681 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 5682 | { |
346774a9 | 5683 | struct breakpoint *b1; |
c906108c | 5684 | |
346774a9 PA |
5685 | /* Add this breakpoint to the end of the chain so that a list of |
5686 | breakpoints will come out in order of increasing numbers. */ | |
5687 | ||
5688 | b1 = breakpoint_chain; | |
5689 | if (b1 == 0) | |
5690 | breakpoint_chain = b; | |
5691 | else | |
5692 | { | |
5693 | while (b1->next) | |
5694 | b1 = b1->next; | |
5695 | b1->next = b; | |
5696 | } | |
5697 | } | |
5698 | ||
5699 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
5700 | ||
5701 | static void | |
5702 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
5703 | struct gdbarch *gdbarch, | |
28010a5d | 5704 | enum bptype bptype, |
c0a91b2b | 5705 | const struct breakpoint_ops *ops) |
346774a9 | 5706 | { |
c906108c | 5707 | memset (b, 0, sizeof (*b)); |
2219d63c | 5708 | |
348d480f PA |
5709 | gdb_assert (ops != NULL); |
5710 | ||
28010a5d | 5711 | b->ops = ops; |
4d28f7a8 | 5712 | b->type = bptype; |
a6d9a66e | 5713 | b->gdbarch = gdbarch; |
c906108c SS |
5714 | b->language = current_language->la_language; |
5715 | b->input_radix = input_radix; | |
5716 | b->thread = -1; | |
b5de0fa7 | 5717 | b->enable_state = bp_enabled; |
c906108c SS |
5718 | b->next = 0; |
5719 | b->silent = 0; | |
5720 | b->ignore_count = 0; | |
5721 | b->commands = NULL; | |
818dd999 | 5722 | b->frame_id = null_frame_id; |
0d381245 | 5723 | b->condition_not_parsed = 0; |
84f4c1fe | 5724 | b->py_bp_object = NULL; |
d0fb5eae | 5725 | b->related_breakpoint = b; |
346774a9 PA |
5726 | } |
5727 | ||
5728 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
5729 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
5730 | |
5731 | static struct breakpoint * | |
5732 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 5733 | enum bptype bptype, |
c0a91b2b | 5734 | const struct breakpoint_ops *ops) |
346774a9 PA |
5735 | { |
5736 | struct breakpoint *b = XNEW (struct breakpoint); | |
5737 | ||
348d480f | 5738 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 5739 | add_to_breakpoint_chain (b); |
0d381245 VP |
5740 | return b; |
5741 | } | |
5742 | ||
0e30163f JK |
5743 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
5744 | resolutions should be made as the user specified the location explicitly | |
5745 | enough. */ | |
5746 | ||
0d381245 | 5747 | static void |
0e30163f | 5748 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 5749 | { |
2bdf28a0 JK |
5750 | gdb_assert (loc->owner != NULL); |
5751 | ||
0d381245 | 5752 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5753 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5754 | || is_tracepoint (loc->owner)) |
0d381245 | 5755 | { |
0e30163f JK |
5756 | int is_gnu_ifunc; |
5757 | ||
5758 | find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name, | |
5759 | NULL, NULL, &is_gnu_ifunc); | |
5760 | ||
5761 | if (is_gnu_ifunc && !explicit_loc) | |
5762 | { | |
5763 | struct breakpoint *b = loc->owner; | |
5764 | ||
5765 | gdb_assert (loc->pspace == current_program_space); | |
5766 | if (gnu_ifunc_resolve_name (loc->function_name, | |
5767 | &loc->requested_address)) | |
5768 | { | |
5769 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
5770 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
5771 | loc->requested_address, | |
5772 | b->type); | |
5773 | } | |
5774 | else if (b->type == bp_breakpoint && b->loc == loc | |
5775 | && loc->next == NULL && b->related_breakpoint == b) | |
5776 | { | |
5777 | /* Create only the whole new breakpoint of this type but do not | |
5778 | mess more complicated breakpoints with multiple locations. */ | |
5779 | b->type = bp_gnu_ifunc_resolver; | |
5780 | } | |
5781 | } | |
5782 | ||
0d381245 VP |
5783 | if (loc->function_name) |
5784 | loc->function_name = xstrdup (loc->function_name); | |
5785 | } | |
5786 | } | |
5787 | ||
a6d9a66e | 5788 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 5789 | struct gdbarch * |
a6d9a66e UW |
5790 | get_sal_arch (struct symtab_and_line sal) |
5791 | { | |
5792 | if (sal.section) | |
5793 | return get_objfile_arch (sal.section->objfile); | |
5794 | if (sal.symtab) | |
5795 | return get_objfile_arch (sal.symtab->objfile); | |
5796 | ||
5797 | return NULL; | |
5798 | } | |
5799 | ||
346774a9 PA |
5800 | /* Low level routine for partially initializing a breakpoint of type |
5801 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 5802 | file name, and line number are provided by SAL. |
0d381245 VP |
5803 | |
5804 | It is expected that the caller will complete the initialization of | |
5805 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 5806 | information regarding the creation of a new breakpoint. */ |
0d381245 | 5807 | |
346774a9 PA |
5808 | static void |
5809 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 5810 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5811 | const struct breakpoint_ops *ops) |
0d381245 | 5812 | { |
28010a5d | 5813 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 5814 | |
3742cc8b | 5815 | add_location_to_breakpoint (b, &sal); |
0d381245 | 5816 | |
6c95b8df PA |
5817 | if (bptype != bp_catchpoint) |
5818 | gdb_assert (sal.pspace != NULL); | |
5819 | ||
6c95b8df PA |
5820 | /* Store the program space that was used to set the breakpoint, for |
5821 | breakpoint resetting. */ | |
5822 | b->pspace = sal.pspace; | |
0d381245 VP |
5823 | |
5824 | if (sal.symtab == NULL) | |
5825 | b->source_file = NULL; | |
5826 | else | |
1b36a34b | 5827 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5828 | b->line_number = sal.line; |
5829 | ||
c906108c | 5830 | breakpoints_changed (); |
346774a9 | 5831 | } |
c906108c | 5832 | |
346774a9 PA |
5833 | /* set_raw_breakpoint is a low level routine for allocating and |
5834 | partially initializing a breakpoint of type BPTYPE. The newly | |
5835 | created breakpoint's address, section, source file name, and line | |
5836 | number are provided by SAL. The newly created and partially | |
5837 | initialized breakpoint is added to the breakpoint chain and | |
5838 | is also returned as the value of this function. | |
5839 | ||
5840 | It is expected that the caller will complete the initialization of | |
5841 | the newly created breakpoint struct as well as output any status | |
5842 | information regarding the creation of a new breakpoint. In | |
5843 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5844 | number! Care should be taken to not allow an error to occur | |
5845 | prior to completing the initialization of the breakpoint. If this | |
5846 | should happen, a bogus breakpoint will be left on the chain. */ | |
5847 | ||
5848 | struct breakpoint * | |
5849 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 5850 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5851 | const struct breakpoint_ops *ops) |
346774a9 PA |
5852 | { |
5853 | struct breakpoint *b = XNEW (struct breakpoint); | |
5854 | ||
348d480f | 5855 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 5856 | add_to_breakpoint_chain (b); |
c906108c SS |
5857 | return b; |
5858 | } | |
5859 | ||
c2c6d25f JM |
5860 | |
5861 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5862 | instruction, hard-wired into the inferior's code. */ | |
5863 | void | |
5864 | make_breakpoint_permanent (struct breakpoint *b) | |
5865 | { | |
0d381245 | 5866 | struct bp_location *bl; |
cc59ec59 | 5867 | |
b5de0fa7 | 5868 | b->enable_state = bp_permanent; |
c2c6d25f | 5869 | |
4a64f543 MS |
5870 | /* By definition, permanent breakpoints are already present in the |
5871 | code. Mark all locations as inserted. For now, | |
5872 | make_breakpoint_permanent is called in just one place, so it's | |
5873 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 5874 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
5875 | for (bl = b->loc; bl; bl = bl->next) |
5876 | bl->inserted = 1; | |
c2c6d25f JM |
5877 | } |
5878 | ||
53a5351d | 5879 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5880 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5881 | initiated the operation. */ | |
c906108c SS |
5882 | |
5883 | void | |
186c406b | 5884 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5885 | { |
35df4500 | 5886 | struct breakpoint *b, *b_tmp; |
186c406b | 5887 | int thread = tp->num; |
0fd8e87f UW |
5888 | |
5889 | /* To avoid having to rescan all objfile symbols at every step, | |
5890 | we maintain a list of continually-inserted but always disabled | |
5891 | longjmp "master" breakpoints. Here, we simply create momentary | |
5892 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5893 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5894 | if (b->pspace == current_program_space |
186c406b TT |
5895 | && (b->type == bp_longjmp_master |
5896 | || b->type == bp_exception_master)) | |
0fd8e87f | 5897 | { |
06edf0c0 PA |
5898 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
5899 | struct breakpoint *clone; | |
cc59ec59 | 5900 | |
06edf0c0 PA |
5901 | clone = momentary_breakpoint_from_master (b, type, |
5902 | &momentary_breakpoint_ops); | |
0fd8e87f UW |
5903 | clone->thread = thread; |
5904 | } | |
186c406b TT |
5905 | |
5906 | tp->initiating_frame = frame; | |
c906108c SS |
5907 | } |
5908 | ||
611c83ae | 5909 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5910 | void |
611c83ae | 5911 | delete_longjmp_breakpoint (int thread) |
c906108c | 5912 | { |
35df4500 | 5913 | struct breakpoint *b, *b_tmp; |
c906108c | 5914 | |
35df4500 | 5915 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 5916 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
5917 | { |
5918 | if (b->thread == thread) | |
5919 | delete_breakpoint (b); | |
5920 | } | |
c906108c SS |
5921 | } |
5922 | ||
1900040c MS |
5923 | void |
5924 | enable_overlay_breakpoints (void) | |
5925 | { | |
52f0bd74 | 5926 | struct breakpoint *b; |
1900040c MS |
5927 | |
5928 | ALL_BREAKPOINTS (b) | |
5929 | if (b->type == bp_overlay_event) | |
5930 | { | |
5931 | b->enable_state = bp_enabled; | |
b60e7edf | 5932 | update_global_location_list (1); |
c02f5703 | 5933 | overlay_events_enabled = 1; |
1900040c MS |
5934 | } |
5935 | } | |
5936 | ||
5937 | void | |
5938 | disable_overlay_breakpoints (void) | |
5939 | { | |
52f0bd74 | 5940 | struct breakpoint *b; |
1900040c MS |
5941 | |
5942 | ALL_BREAKPOINTS (b) | |
5943 | if (b->type == bp_overlay_event) | |
5944 | { | |
5945 | b->enable_state = bp_disabled; | |
b60e7edf | 5946 | update_global_location_list (0); |
c02f5703 | 5947 | overlay_events_enabled = 0; |
1900040c MS |
5948 | } |
5949 | } | |
5950 | ||
aa7d318d TT |
5951 | /* Set an active std::terminate breakpoint for each std::terminate |
5952 | master breakpoint. */ | |
5953 | void | |
5954 | set_std_terminate_breakpoint (void) | |
5955 | { | |
35df4500 | 5956 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5957 | |
35df4500 | 5958 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5959 | if (b->pspace == current_program_space |
5960 | && b->type == bp_std_terminate_master) | |
5961 | { | |
06edf0c0 PA |
5962 | momentary_breakpoint_from_master (b, bp_std_terminate, |
5963 | &momentary_breakpoint_ops); | |
aa7d318d TT |
5964 | } |
5965 | } | |
5966 | ||
5967 | /* Delete all the std::terminate breakpoints. */ | |
5968 | void | |
5969 | delete_std_terminate_breakpoint (void) | |
5970 | { | |
35df4500 | 5971 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5972 | |
35df4500 | 5973 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5974 | if (b->type == bp_std_terminate) |
5975 | delete_breakpoint (b); | |
5976 | } | |
5977 | ||
c4093a6a | 5978 | struct breakpoint * |
a6d9a66e | 5979 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5980 | { |
5981 | struct breakpoint *b; | |
c4093a6a | 5982 | |
06edf0c0 PA |
5983 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
5984 | &internal_breakpoint_ops); | |
5985 | ||
b5de0fa7 | 5986 | b->enable_state = bp_enabled; |
c4093a6a | 5987 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5988 | b->addr_string |
5989 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5990 | |
b60e7edf | 5991 | update_global_location_list_nothrow (1); |
74960c60 | 5992 | |
c4093a6a JM |
5993 | return b; |
5994 | } | |
5995 | ||
5996 | void | |
5997 | remove_thread_event_breakpoints (void) | |
5998 | { | |
35df4500 | 5999 | struct breakpoint *b, *b_tmp; |
c4093a6a | 6000 | |
35df4500 | 6001 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6002 | if (b->type == bp_thread_event |
6003 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
6004 | delete_breakpoint (b); |
6005 | } | |
6006 | ||
0101ce28 JJ |
6007 | struct lang_and_radix |
6008 | { | |
6009 | enum language lang; | |
6010 | int radix; | |
6011 | }; | |
6012 | ||
4efc6507 DE |
6013 | /* Create a breakpoint for JIT code registration and unregistration. */ |
6014 | ||
6015 | struct breakpoint * | |
6016 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
6017 | { | |
6018 | struct breakpoint *b; | |
6019 | ||
06edf0c0 PA |
6020 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
6021 | &internal_breakpoint_ops); | |
4efc6507 DE |
6022 | update_global_location_list_nothrow (1); |
6023 | return b; | |
6024 | } | |
0101ce28 | 6025 | |
03673fc7 PP |
6026 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
6027 | ||
6028 | void | |
6029 | remove_jit_event_breakpoints (void) | |
6030 | { | |
6031 | struct breakpoint *b, *b_tmp; | |
6032 | ||
6033 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6034 | if (b->type == bp_jit_event | |
6035 | && b->loc->pspace == current_program_space) | |
6036 | delete_breakpoint (b); | |
6037 | } | |
6038 | ||
cae688ec JJ |
6039 | void |
6040 | remove_solib_event_breakpoints (void) | |
6041 | { | |
35df4500 | 6042 | struct breakpoint *b, *b_tmp; |
cae688ec | 6043 | |
35df4500 | 6044 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6045 | if (b->type == bp_shlib_event |
6046 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6047 | delete_breakpoint (b); |
6048 | } | |
6049 | ||
6050 | struct breakpoint * | |
a6d9a66e | 6051 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6052 | { |
6053 | struct breakpoint *b; | |
6054 | ||
06edf0c0 PA |
6055 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
6056 | &internal_breakpoint_ops); | |
b60e7edf | 6057 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6058 | return b; |
6059 | } | |
6060 | ||
6061 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6062 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6063 | ||
6064 | void | |
cb851954 | 6065 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6066 | { |
876fa593 | 6067 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6068 | |
876fa593 | 6069 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6070 | { |
2bdf28a0 | 6071 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6072 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6073 | |
4a64f543 MS |
6074 | /* We apply the check to all breakpoints, including disabled for |
6075 | those with loc->duplicate set. This is so that when breakpoint | |
6076 | becomes enabled, or the duplicate is removed, gdb will try to | |
6077 | insert all breakpoints. If we don't set shlib_disabled here, | |
6078 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6079 | if (((b->type == bp_breakpoint) |
508ccb1f | 6080 | || (b->type == bp_jit_event) |
1042e4c0 | 6081 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6082 | || (is_tracepoint (b))) |
6c95b8df | 6083 | && loc->pspace == current_program_space |
0d381245 | 6084 | && !loc->shlib_disabled |
a77053c2 | 6085 | #ifdef PC_SOLIB |
0d381245 | 6086 | && PC_SOLIB (loc->address) |
a77053c2 | 6087 | #else |
6c95b8df | 6088 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6089 | #endif |
6090 | ) | |
0d381245 VP |
6091 | { |
6092 | loc->shlib_disabled = 1; | |
6093 | } | |
cae688ec JJ |
6094 | } |
6095 | } | |
6096 | ||
1e4d1764 YQ |
6097 | /* Disable any breakpoints and tracepoints that are in an unloaded shared |
6098 | library. Only apply to enabled breakpoints, disabled ones can just stay | |
4a64f543 | 6099 | disabled. */ |
84acb35a | 6100 | |
75149521 | 6101 | static void |
84acb35a JJ |
6102 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6103 | { | |
876fa593 | 6104 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6105 | int disabled_shlib_breaks = 0; |
6106 | ||
c86cf029 VP |
6107 | /* SunOS a.out shared libraries are always mapped, so do not |
6108 | disable breakpoints; they will only be reported as unloaded | |
6109 | through clear_solib when GDB discards its shared library | |
6110 | list. See clear_solib for more information. */ | |
6111 | if (exec_bfd != NULL | |
6112 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6113 | return; | |
6114 | ||
876fa593 | 6115 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6116 | { |
2bdf28a0 | 6117 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6118 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6119 | |
1e4d1764 | 6120 | if (solib->pspace == loc->pspace |
e2dd7057 | 6121 | && !loc->shlib_disabled |
1e4d1764 YQ |
6122 | && (((b->type == bp_breakpoint |
6123 | || b->type == bp_jit_event | |
6124 | || b->type == bp_hardware_breakpoint) | |
6125 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
6126 | || loc->loc_type == bp_loc_software_breakpoint)) | |
6127 | || is_tracepoint (b)) | |
e2dd7057 | 6128 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6129 | { |
e2dd7057 PP |
6130 | loc->shlib_disabled = 1; |
6131 | /* At this point, we cannot rely on remove_breakpoint | |
6132 | succeeding so we must mark the breakpoint as not inserted | |
6133 | to prevent future errors occurring in remove_breakpoints. */ | |
6134 | loc->inserted = 0; | |
8d3788bd VP |
6135 | |
6136 | /* This may cause duplicate notifications for the same breakpoint. */ | |
6137 | observer_notify_breakpoint_modified (b); | |
6138 | ||
e2dd7057 PP |
6139 | if (!disabled_shlib_breaks) |
6140 | { | |
6141 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6142 | warning (_("Temporarily disabling breakpoints " |
6143 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6144 | solib->so_name); |
84acb35a | 6145 | } |
e2dd7057 | 6146 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6147 | } |
6148 | } | |
84acb35a JJ |
6149 | } |
6150 | ||
ce78b96d JB |
6151 | /* FORK & VFORK catchpoints. */ |
6152 | ||
e29a4733 PA |
6153 | /* An instance of this type is used to represent a fork or vfork |
6154 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
6155 | class; users downcast to "struct breakpoint *" when needed. A | |
6156 | breakpoint is really of this type iff its ops pointer points to | |
6157 | CATCH_FORK_BREAKPOINT_OPS. */ | |
6158 | ||
6159 | struct fork_catchpoint | |
6160 | { | |
6161 | /* The base class. */ | |
6162 | struct breakpoint base; | |
6163 | ||
6164 | /* Process id of a child process whose forking triggered this | |
6165 | catchpoint. This field is only valid immediately after this | |
6166 | catchpoint has triggered. */ | |
6167 | ptid_t forked_inferior_pid; | |
6168 | }; | |
6169 | ||
4a64f543 MS |
6170 | /* Implement the "insert" breakpoint_ops method for fork |
6171 | catchpoints. */ | |
ce78b96d | 6172 | |
77b06cd7 TJB |
6173 | static int |
6174 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6175 | { |
77b06cd7 | 6176 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6177 | } |
6178 | ||
4a64f543 MS |
6179 | /* Implement the "remove" breakpoint_ops method for fork |
6180 | catchpoints. */ | |
ce78b96d JB |
6181 | |
6182 | static int | |
77b06cd7 | 6183 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6184 | { |
6185 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6186 | } | |
6187 | ||
6188 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6189 | catchpoints. */ | |
6190 | ||
6191 | static int | |
f1310107 TJB |
6192 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
6193 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6194 | { |
e29a4733 PA |
6195 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6196 | ||
6197 | return inferior_has_forked (inferior_ptid, &c->forked_inferior_pid); | |
ce78b96d JB |
6198 | } |
6199 | ||
4a64f543 MS |
6200 | /* Implement the "print_it" breakpoint_ops method for fork |
6201 | catchpoints. */ | |
ce78b96d JB |
6202 | |
6203 | static enum print_stop_action | |
348d480f | 6204 | print_it_catch_fork (bpstat bs) |
ce78b96d | 6205 | { |
36dfb11c | 6206 | struct ui_out *uiout = current_uiout; |
348d480f PA |
6207 | struct breakpoint *b = bs->breakpoint_at; |
6208 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 6209 | |
ce78b96d | 6210 | annotate_catchpoint (b->number); |
36dfb11c TT |
6211 | if (b->disposition == disp_del) |
6212 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
6213 | else | |
6214 | ui_out_text (uiout, "\nCatchpoint "); | |
6215 | if (ui_out_is_mi_like_p (uiout)) | |
6216 | { | |
6217 | ui_out_field_string (uiout, "reason", | |
6218 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
6219 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6220 | } | |
6221 | ui_out_field_int (uiout, "bkptno", b->number); | |
6222 | ui_out_text (uiout, " (forked process "); | |
6223 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
6224 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
6225 | return PRINT_SRC_AND_LOC; |
6226 | } | |
6227 | ||
4a64f543 MS |
6228 | /* Implement the "print_one" breakpoint_ops method for fork |
6229 | catchpoints. */ | |
ce78b96d JB |
6230 | |
6231 | static void | |
a6d9a66e | 6232 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6233 | { |
e29a4733 | 6234 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6235 | struct value_print_options opts; |
79a45e25 | 6236 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6237 | |
6238 | get_user_print_options (&opts); | |
6239 | ||
4a64f543 MS |
6240 | /* Field 4, the address, is omitted (which makes the columns not |
6241 | line up too nicely with the headers, but the effect is relatively | |
6242 | readable). */ | |
79a45b7d | 6243 | if (opts.addressprint) |
ce78b96d JB |
6244 | ui_out_field_skip (uiout, "addr"); |
6245 | annotate_field (5); | |
6246 | ui_out_text (uiout, "fork"); | |
e29a4733 | 6247 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6248 | { |
6249 | ui_out_text (uiout, ", process "); | |
6250 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6251 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6252 | ui_out_spaces (uiout, 1); |
6253 | } | |
6254 | } | |
6255 | ||
6256 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6257 | catchpoints. */ | |
6258 | ||
6259 | static void | |
6260 | print_mention_catch_fork (struct breakpoint *b) | |
6261 | { | |
6262 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6263 | } | |
6264 | ||
6149aea9 PA |
6265 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6266 | catchpoints. */ | |
6267 | ||
6268 | static void | |
6269 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6270 | { | |
6271 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 6272 | print_recreate_thread (b, fp); |
6149aea9 PA |
6273 | } |
6274 | ||
ce78b96d JB |
6275 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6276 | ||
2060206e | 6277 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 6278 | |
4a64f543 MS |
6279 | /* Implement the "insert" breakpoint_ops method for vfork |
6280 | catchpoints. */ | |
ce78b96d | 6281 | |
77b06cd7 TJB |
6282 | static int |
6283 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6284 | { |
77b06cd7 | 6285 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6286 | } |
6287 | ||
4a64f543 MS |
6288 | /* Implement the "remove" breakpoint_ops method for vfork |
6289 | catchpoints. */ | |
ce78b96d JB |
6290 | |
6291 | static int | |
77b06cd7 | 6292 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6293 | { |
6294 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6295 | } | |
6296 | ||
6297 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6298 | catchpoints. */ | |
6299 | ||
6300 | static int | |
f1310107 TJB |
6301 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
6302 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6303 | { |
e29a4733 PA |
6304 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6305 | ||
6306 | return inferior_has_vforked (inferior_ptid, &c->forked_inferior_pid); | |
ce78b96d JB |
6307 | } |
6308 | ||
4a64f543 MS |
6309 | /* Implement the "print_it" breakpoint_ops method for vfork |
6310 | catchpoints. */ | |
ce78b96d JB |
6311 | |
6312 | static enum print_stop_action | |
348d480f | 6313 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 6314 | { |
36dfb11c | 6315 | struct ui_out *uiout = current_uiout; |
348d480f | 6316 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
6317 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
6318 | ||
ce78b96d | 6319 | annotate_catchpoint (b->number); |
36dfb11c TT |
6320 | if (b->disposition == disp_del) |
6321 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
6322 | else | |
6323 | ui_out_text (uiout, "\nCatchpoint "); | |
6324 | if (ui_out_is_mi_like_p (uiout)) | |
6325 | { | |
6326 | ui_out_field_string (uiout, "reason", | |
6327 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
6328 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6329 | } | |
6330 | ui_out_field_int (uiout, "bkptno", b->number); | |
6331 | ui_out_text (uiout, " (vforked process "); | |
6332 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
6333 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
6334 | return PRINT_SRC_AND_LOC; |
6335 | } | |
6336 | ||
4a64f543 MS |
6337 | /* Implement the "print_one" breakpoint_ops method for vfork |
6338 | catchpoints. */ | |
ce78b96d JB |
6339 | |
6340 | static void | |
a6d9a66e | 6341 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6342 | { |
e29a4733 | 6343 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6344 | struct value_print_options opts; |
79a45e25 | 6345 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6346 | |
6347 | get_user_print_options (&opts); | |
4a64f543 MS |
6348 | /* Field 4, the address, is omitted (which makes the columns not |
6349 | line up too nicely with the headers, but the effect is relatively | |
6350 | readable). */ | |
79a45b7d | 6351 | if (opts.addressprint) |
ce78b96d JB |
6352 | ui_out_field_skip (uiout, "addr"); |
6353 | annotate_field (5); | |
6354 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 6355 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6356 | { |
6357 | ui_out_text (uiout, ", process "); | |
6358 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6359 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6360 | ui_out_spaces (uiout, 1); |
6361 | } | |
6362 | } | |
6363 | ||
6364 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6365 | catchpoints. */ | |
6366 | ||
6367 | static void | |
6368 | print_mention_catch_vfork (struct breakpoint *b) | |
6369 | { | |
6370 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6371 | } | |
6372 | ||
6149aea9 PA |
6373 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6374 | catchpoints. */ | |
6375 | ||
6376 | static void | |
6377 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6378 | { | |
6379 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 6380 | print_recreate_thread (b, fp); |
6149aea9 PA |
6381 | } |
6382 | ||
ce78b96d JB |
6383 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6384 | ||
2060206e | 6385 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 6386 | |
be5c67c1 PA |
6387 | /* An instance of this type is used to represent a syscall catchpoint. |
6388 | It includes a "struct breakpoint" as a kind of base class; users | |
6389 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6390 | really of this type iff its ops pointer points to | |
6391 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
6392 | ||
6393 | struct syscall_catchpoint | |
6394 | { | |
6395 | /* The base class. */ | |
6396 | struct breakpoint base; | |
6397 | ||
6398 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
6399 | syscall has been specified for filtering, its value is NULL. | |
6400 | Otherwise, it holds a list of all syscalls to be caught. The | |
6401 | list elements are allocated with xmalloc. */ | |
6402 | VEC(int) *syscalls_to_be_caught; | |
6403 | }; | |
6404 | ||
6405 | /* Implement the "dtor" breakpoint_ops method for syscall | |
6406 | catchpoints. */ | |
6407 | ||
6408 | static void | |
6409 | dtor_catch_syscall (struct breakpoint *b) | |
6410 | { | |
6411 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
6412 | ||
6413 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 6414 | |
2060206e | 6415 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
6416 | } |
6417 | ||
a96d9b2e SDJ |
6418 | /* Implement the "insert" breakpoint_ops method for syscall |
6419 | catchpoints. */ | |
6420 | ||
77b06cd7 TJB |
6421 | static int |
6422 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 6423 | { |
be5c67c1 | 6424 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6425 | struct inferior *inf = current_inferior (); |
6426 | ||
6427 | ++inf->total_syscalls_count; | |
be5c67c1 | 6428 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6429 | ++inf->any_syscall_count; |
6430 | else | |
6431 | { | |
6432 | int i, iter; | |
cc59ec59 | 6433 | |
a96d9b2e | 6434 | for (i = 0; |
be5c67c1 | 6435 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6436 | i++) |
6437 | { | |
6438 | int elem; | |
cc59ec59 | 6439 | |
a96d9b2e SDJ |
6440 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6441 | { | |
6442 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6443 | uintptr_t vec_addr_offset |
6444 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6445 | uintptr_t vec_addr; |
6446 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6447 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6448 | vec_addr_offset; | |
6449 | memset ((void *) vec_addr, 0, | |
6450 | (iter + 1 - old_size) * sizeof (int)); | |
6451 | } | |
6452 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6453 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6454 | } | |
6455 | } | |
6456 | ||
77b06cd7 TJB |
6457 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6458 | inf->total_syscalls_count != 0, | |
6459 | inf->any_syscall_count, | |
6460 | VEC_length (int, inf->syscalls_counts), | |
6461 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6462 | } |
6463 | ||
6464 | /* Implement the "remove" breakpoint_ops method for syscall | |
6465 | catchpoints. */ | |
6466 | ||
6467 | static int | |
77b06cd7 | 6468 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 6469 | { |
be5c67c1 | 6470 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6471 | struct inferior *inf = current_inferior (); |
6472 | ||
6473 | --inf->total_syscalls_count; | |
be5c67c1 | 6474 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6475 | --inf->any_syscall_count; |
6476 | else | |
6477 | { | |
6478 | int i, iter; | |
cc59ec59 | 6479 | |
a96d9b2e | 6480 | for (i = 0; |
be5c67c1 | 6481 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6482 | i++) |
6483 | { | |
6484 | int elem; | |
6485 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6486 | /* Shouldn't happen. */ | |
6487 | continue; | |
6488 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6489 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6490 | } | |
6491 | } | |
6492 | ||
6493 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6494 | inf->total_syscalls_count != 0, | |
6495 | inf->any_syscall_count, | |
6496 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6497 | VEC_address (int, |
6498 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6499 | } |
6500 | ||
6501 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6502 | catchpoints. */ | |
6503 | ||
6504 | static int | |
f1310107 TJB |
6505 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
6506 | struct address_space *aspace, CORE_ADDR bp_addr) | |
a96d9b2e | 6507 | { |
4a64f543 MS |
6508 | /* We must check if we are catching specific syscalls in this |
6509 | breakpoint. If we are, then we must guarantee that the called | |
6510 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 6511 | int syscall_number = 0; |
be5c67c1 PA |
6512 | const struct syscall_catchpoint *c |
6513 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e SDJ |
6514 | |
6515 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6516 | return 0; | |
6517 | ||
6518 | /* Now, checking if the syscall is the same. */ | |
be5c67c1 | 6519 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6520 | { |
6521 | int i, iter; | |
cc59ec59 | 6522 | |
a96d9b2e | 6523 | for (i = 0; |
be5c67c1 | 6524 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6525 | i++) |
6526 | if (syscall_number == iter) | |
6527 | break; | |
6528 | /* Not the same. */ | |
6529 | if (!iter) | |
6530 | return 0; | |
6531 | } | |
6532 | ||
6533 | return 1; | |
6534 | } | |
6535 | ||
6536 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6537 | catchpoints. */ | |
6538 | ||
6539 | static enum print_stop_action | |
348d480f | 6540 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 6541 | { |
36dfb11c | 6542 | struct ui_out *uiout = current_uiout; |
348d480f | 6543 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
6544 | /* These are needed because we want to know in which state a |
6545 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6546 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6547 | must print "called syscall" or "returned from syscall". */ | |
6548 | ptid_t ptid; | |
6549 | struct target_waitstatus last; | |
6550 | struct syscall s; | |
a96d9b2e SDJ |
6551 | char *syscall_id; |
6552 | ||
6553 | get_last_target_status (&ptid, &last); | |
6554 | ||
6555 | get_syscall_by_number (last.value.syscall_number, &s); | |
6556 | ||
6557 | annotate_catchpoint (b->number); | |
6558 | ||
36dfb11c TT |
6559 | if (b->disposition == disp_del) |
6560 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
a96d9b2e | 6561 | else |
36dfb11c TT |
6562 | ui_out_text (uiout, "\nCatchpoint "); |
6563 | if (ui_out_is_mi_like_p (uiout)) | |
6564 | { | |
6565 | ui_out_field_string (uiout, "reason", | |
6566 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY | |
6567 | ? EXEC_ASYNC_SYSCALL_ENTRY | |
6568 | : EXEC_ASYNC_SYSCALL_RETURN)); | |
6569 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6570 | } | |
6571 | ui_out_field_int (uiout, "bkptno", b->number); | |
a96d9b2e SDJ |
6572 | |
6573 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
36dfb11c TT |
6574 | ui_out_text (uiout, " (call to syscall "); |
6575 | else | |
6576 | ui_out_text (uiout, " (returned from syscall "); | |
a96d9b2e | 6577 | |
36dfb11c TT |
6578 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
6579 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); | |
6580 | if (s.name != NULL) | |
6581 | ui_out_field_string (uiout, "syscall-name", s.name); | |
6582 | ||
6583 | ui_out_text (uiout, "), "); | |
a96d9b2e SDJ |
6584 | |
6585 | return PRINT_SRC_AND_LOC; | |
6586 | } | |
6587 | ||
6588 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6589 | catchpoints. */ | |
6590 | ||
6591 | static void | |
6592 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 6593 | struct bp_location **last_loc) |
a96d9b2e | 6594 | { |
be5c67c1 | 6595 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 6596 | struct value_print_options opts; |
79a45e25 | 6597 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
6598 | |
6599 | get_user_print_options (&opts); | |
4a64f543 MS |
6600 | /* Field 4, the address, is omitted (which makes the columns not |
6601 | line up too nicely with the headers, but the effect is relatively | |
6602 | readable). */ | |
a96d9b2e SDJ |
6603 | if (opts.addressprint) |
6604 | ui_out_field_skip (uiout, "addr"); | |
6605 | annotate_field (5); | |
6606 | ||
be5c67c1 PA |
6607 | if (c->syscalls_to_be_caught |
6608 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
6609 | ui_out_text (uiout, "syscalls \""); |
6610 | else | |
6611 | ui_out_text (uiout, "syscall \""); | |
6612 | ||
be5c67c1 | 6613 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6614 | { |
6615 | int i, iter; | |
6616 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6617 | |
a96d9b2e | 6618 | for (i = 0; |
be5c67c1 | 6619 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6620 | i++) |
6621 | { | |
6622 | char *x = text; | |
6623 | struct syscall s; | |
6624 | get_syscall_by_number (iter, &s); | |
6625 | ||
6626 | if (s.name != NULL) | |
6627 | text = xstrprintf ("%s%s, ", text, s.name); | |
6628 | else | |
6629 | text = xstrprintf ("%s%d, ", text, iter); | |
6630 | ||
6631 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 6632 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
6633 | on every call. */ |
6634 | xfree (x); | |
6635 | } | |
6636 | /* Remove the last comma. */ | |
6637 | text[strlen (text) - 2] = '\0'; | |
6638 | ui_out_field_string (uiout, "what", text); | |
6639 | } | |
6640 | else | |
6641 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6642 | ui_out_text (uiout, "\" "); | |
6643 | } | |
6644 | ||
6645 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6646 | catchpoints. */ | |
6647 | ||
6648 | static void | |
6649 | print_mention_catch_syscall (struct breakpoint *b) | |
6650 | { | |
be5c67c1 PA |
6651 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6652 | ||
6653 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
6654 | { |
6655 | int i, iter; | |
6656 | ||
be5c67c1 | 6657 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
6658 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
6659 | else | |
6660 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6661 | ||
6662 | for (i = 0; | |
be5c67c1 | 6663 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6664 | i++) |
6665 | { | |
6666 | struct syscall s; | |
6667 | get_syscall_by_number (iter, &s); | |
6668 | ||
6669 | if (s.name) | |
6670 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6671 | else | |
6672 | printf_filtered (" %d", s.number); | |
6673 | } | |
6674 | printf_filtered (")"); | |
6675 | } | |
6676 | else | |
6677 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6678 | b->number); | |
6679 | } | |
6680 | ||
6149aea9 PA |
6681 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6682 | catchpoints. */ | |
6683 | ||
6684 | static void | |
6685 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6686 | { | |
be5c67c1 PA |
6687 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6688 | ||
6149aea9 PA |
6689 | fprintf_unfiltered (fp, "catch syscall"); |
6690 | ||
be5c67c1 | 6691 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
6692 | { |
6693 | int i, iter; | |
6694 | ||
6695 | for (i = 0; | |
be5c67c1 | 6696 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
6697 | i++) |
6698 | { | |
6699 | struct syscall s; | |
6700 | ||
6701 | get_syscall_by_number (iter, &s); | |
6702 | if (s.name) | |
6703 | fprintf_unfiltered (fp, " %s", s.name); | |
6704 | else | |
6705 | fprintf_unfiltered (fp, " %d", s.number); | |
6706 | } | |
6707 | } | |
d9b3f62e | 6708 | print_recreate_thread (b, fp); |
6149aea9 PA |
6709 | } |
6710 | ||
a96d9b2e SDJ |
6711 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6712 | ||
2060206e | 6713 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
6714 | |
6715 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6716 | ||
6717 | static int | |
6718 | syscall_catchpoint_p (struct breakpoint *b) | |
6719 | { | |
6720 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6721 | } | |
6722 | ||
346774a9 PA |
6723 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
6724 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
6725 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
6726 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 6727 | |
346774a9 PA |
6728 | static void |
6729 | init_catchpoint (struct breakpoint *b, | |
6730 | struct gdbarch *gdbarch, int tempflag, | |
6731 | char *cond_string, | |
c0a91b2b | 6732 | const struct breakpoint_ops *ops) |
c906108c | 6733 | { |
c5aa993b | 6734 | struct symtab_and_line sal; |
346774a9 | 6735 | |
fe39c653 | 6736 | init_sal (&sal); |
6c95b8df | 6737 | sal.pspace = current_program_space; |
c5aa993b | 6738 | |
28010a5d | 6739 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 6740 | |
1b36a34b | 6741 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 6742 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
6743 | } |
6744 | ||
28010a5d | 6745 | void |
3ea46bff | 6746 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
6747 | { |
6748 | add_to_breakpoint_chain (b); | |
3a5c3e22 PA |
6749 | set_breakpoint_number (internal, b); |
6750 | if (!internal) | |
6751 | mention (b); | |
c56053d2 | 6752 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
6753 | |
6754 | if (update_gll) | |
6755 | update_global_location_list (1); | |
c56053d2 PA |
6756 | } |
6757 | ||
9b70b993 | 6758 | static void |
a6d9a66e UW |
6759 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6760 | int tempflag, char *cond_string, | |
c0a91b2b | 6761 | const struct breakpoint_ops *ops) |
c906108c | 6762 | { |
e29a4733 | 6763 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 6764 | |
e29a4733 PA |
6765 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
6766 | ||
6767 | c->forked_inferior_pid = null_ptid; | |
6768 | ||
3ea46bff | 6769 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
6770 | } |
6771 | ||
fe798b75 JB |
6772 | /* Exec catchpoints. */ |
6773 | ||
b4d90040 PA |
6774 | /* An instance of this type is used to represent an exec catchpoint. |
6775 | It includes a "struct breakpoint" as a kind of base class; users | |
6776 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6777 | really of this type iff its ops pointer points to | |
6778 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
6779 | ||
6780 | struct exec_catchpoint | |
6781 | { | |
6782 | /* The base class. */ | |
6783 | struct breakpoint base; | |
6784 | ||
6785 | /* Filename of a program whose exec triggered this catchpoint. | |
6786 | This field is only valid immediately after this catchpoint has | |
6787 | triggered. */ | |
6788 | char *exec_pathname; | |
6789 | }; | |
6790 | ||
6791 | /* Implement the "dtor" breakpoint_ops method for exec | |
6792 | catchpoints. */ | |
6793 | ||
6794 | static void | |
6795 | dtor_catch_exec (struct breakpoint *b) | |
6796 | { | |
6797 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
6798 | ||
6799 | xfree (c->exec_pathname); | |
348d480f | 6800 | |
2060206e | 6801 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
6802 | } |
6803 | ||
77b06cd7 TJB |
6804 | static int |
6805 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6806 | { |
77b06cd7 | 6807 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6808 | } |
c906108c | 6809 | |
fe798b75 | 6810 | static int |
77b06cd7 | 6811 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6812 | { |
6813 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6814 | } | |
c906108c | 6815 | |
fe798b75 | 6816 | static int |
f1310107 TJB |
6817 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
6818 | struct address_space *aspace, CORE_ADDR bp_addr) | |
fe798b75 | 6819 | { |
b4d90040 PA |
6820 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
6821 | ||
6822 | return inferior_has_execd (inferior_ptid, &c->exec_pathname); | |
fe798b75 | 6823 | } |
c906108c | 6824 | |
fe798b75 | 6825 | static enum print_stop_action |
348d480f | 6826 | print_it_catch_exec (bpstat bs) |
fe798b75 | 6827 | { |
36dfb11c | 6828 | struct ui_out *uiout = current_uiout; |
348d480f | 6829 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
6830 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
6831 | ||
fe798b75 | 6832 | annotate_catchpoint (b->number); |
36dfb11c TT |
6833 | if (b->disposition == disp_del) |
6834 | ui_out_text (uiout, "\nTemporary catchpoint "); | |
6835 | else | |
6836 | ui_out_text (uiout, "\nCatchpoint "); | |
6837 | if (ui_out_is_mi_like_p (uiout)) | |
6838 | { | |
6839 | ui_out_field_string (uiout, "reason", | |
6840 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
6841 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
6842 | } | |
6843 | ui_out_field_int (uiout, "bkptno", b->number); | |
6844 | ui_out_text (uiout, " (exec'd "); | |
6845 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
6846 | ui_out_text (uiout, "), "); | |
6847 | ||
fe798b75 | 6848 | return PRINT_SRC_AND_LOC; |
c906108c SS |
6849 | } |
6850 | ||
fe798b75 | 6851 | static void |
a6d9a66e | 6852 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 6853 | { |
b4d90040 | 6854 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 6855 | struct value_print_options opts; |
79a45e25 | 6856 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
6857 | |
6858 | get_user_print_options (&opts); | |
6859 | ||
6860 | /* Field 4, the address, is omitted (which makes the columns | |
6861 | not line up too nicely with the headers, but the effect | |
6862 | is relatively readable). */ | |
6863 | if (opts.addressprint) | |
6864 | ui_out_field_skip (uiout, "addr"); | |
6865 | annotate_field (5); | |
6866 | ui_out_text (uiout, "exec"); | |
b4d90040 | 6867 | if (c->exec_pathname != NULL) |
fe798b75 JB |
6868 | { |
6869 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 6870 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
6871 | ui_out_text (uiout, "\" "); |
6872 | } | |
6873 | } | |
6874 | ||
6875 | static void | |
6876 | print_mention_catch_exec (struct breakpoint *b) | |
6877 | { | |
6878 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6879 | } | |
6880 | ||
6149aea9 PA |
6881 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6882 | catchpoints. */ | |
6883 | ||
6884 | static void | |
6885 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6886 | { | |
6887 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 6888 | print_recreate_thread (b, fp); |
6149aea9 PA |
6889 | } |
6890 | ||
2060206e | 6891 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 6892 | |
a96d9b2e SDJ |
6893 | static void |
6894 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 6895 | const struct breakpoint_ops *ops) |
a96d9b2e | 6896 | { |
be5c67c1 | 6897 | struct syscall_catchpoint *c; |
a96d9b2e | 6898 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 6899 | |
be5c67c1 PA |
6900 | c = XNEW (struct syscall_catchpoint); |
6901 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
6902 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 6903 | |
3ea46bff | 6904 | install_breakpoint (0, &c->base, 1); |
a96d9b2e SDJ |
6905 | } |
6906 | ||
c906108c | 6907 | static int |
fba45db2 | 6908 | hw_breakpoint_used_count (void) |
c906108c | 6909 | { |
c906108c | 6910 | int i = 0; |
f1310107 TJB |
6911 | struct breakpoint *b; |
6912 | struct bp_location *bl; | |
c906108c SS |
6913 | |
6914 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6915 | { |
d6b74ac4 | 6916 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
6917 | for (bl = b->loc; bl; bl = bl->next) |
6918 | { | |
6919 | /* Special types of hardware breakpoints may use more than | |
6920 | one register. */ | |
348d480f | 6921 | i += b->ops->resources_needed (bl); |
f1310107 | 6922 | } |
c5aa993b | 6923 | } |
c906108c SS |
6924 | |
6925 | return i; | |
6926 | } | |
6927 | ||
a1398e0c PA |
6928 | /* Returns the resources B would use if it were a hardware |
6929 | watchpoint. */ | |
6930 | ||
c906108c | 6931 | static int |
a1398e0c | 6932 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 6933 | { |
c906108c | 6934 | int i = 0; |
e09342b5 | 6935 | struct bp_location *bl; |
c906108c | 6936 | |
a1398e0c PA |
6937 | if (!breakpoint_enabled (b)) |
6938 | return 0; | |
6939 | ||
6940 | for (bl = b->loc; bl; bl = bl->next) | |
6941 | { | |
6942 | /* Special types of hardware watchpoints may use more than | |
6943 | one register. */ | |
6944 | i += b->ops->resources_needed (bl); | |
6945 | } | |
6946 | ||
6947 | return i; | |
6948 | } | |
6949 | ||
6950 | /* Returns the sum the used resources of all hardware watchpoints of | |
6951 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
6952 | the sum of the used resources of all hardware watchpoints of other | |
6953 | types _not_ TYPE. */ | |
6954 | ||
6955 | static int | |
6956 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
6957 | enum bptype type, int *other_type_used) | |
6958 | { | |
6959 | int i = 0; | |
6960 | struct breakpoint *b; | |
6961 | ||
c906108c SS |
6962 | *other_type_used = 0; |
6963 | ALL_BREAKPOINTS (b) | |
e09342b5 | 6964 | { |
a1398e0c PA |
6965 | if (b == except) |
6966 | continue; | |
e09342b5 TJB |
6967 | if (!breakpoint_enabled (b)) |
6968 | continue; | |
6969 | ||
a1398e0c PA |
6970 | if (b->type == type) |
6971 | i += hw_watchpoint_use_count (b); | |
6972 | else if (is_hardware_watchpoint (b)) | |
6973 | *other_type_used = 1; | |
e09342b5 TJB |
6974 | } |
6975 | ||
c906108c SS |
6976 | return i; |
6977 | } | |
6978 | ||
c906108c | 6979 | void |
fba45db2 | 6980 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6981 | { |
c5aa993b | 6982 | struct breakpoint *b; |
c906108c SS |
6983 | |
6984 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6985 | { |
cc60f2e3 | 6986 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6987 | { |
b5de0fa7 | 6988 | b->enable_state = bp_call_disabled; |
b60e7edf | 6989 | update_global_location_list (0); |
c5aa993b JM |
6990 | } |
6991 | } | |
c906108c SS |
6992 | } |
6993 | ||
6994 | void | |
fba45db2 | 6995 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6996 | { |
c5aa993b | 6997 | struct breakpoint *b; |
c906108c SS |
6998 | |
6999 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7000 | { |
cc60f2e3 | 7001 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 7002 | { |
b5de0fa7 | 7003 | b->enable_state = bp_enabled; |
b60e7edf | 7004 | update_global_location_list (1); |
c5aa993b JM |
7005 | } |
7006 | } | |
c906108c SS |
7007 | } |
7008 | ||
8bea4e01 UW |
7009 | void |
7010 | disable_breakpoints_before_startup (void) | |
7011 | { | |
7012 | struct breakpoint *b; | |
7013 | int found = 0; | |
7014 | ||
7015 | ALL_BREAKPOINTS (b) | |
7016 | { | |
6c95b8df PA |
7017 | if (b->pspace != current_program_space) |
7018 | continue; | |
7019 | ||
8bea4e01 UW |
7020 | if ((b->type == bp_breakpoint |
7021 | || b->type == bp_hardware_breakpoint) | |
7022 | && breakpoint_enabled (b)) | |
7023 | { | |
7024 | b->enable_state = bp_startup_disabled; | |
7025 | found = 1; | |
7026 | } | |
7027 | } | |
7028 | ||
7029 | if (found) | |
7030 | update_global_location_list (0); | |
7031 | ||
6c95b8df | 7032 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
7033 | } |
7034 | ||
7035 | void | |
7036 | enable_breakpoints_after_startup (void) | |
7037 | { | |
7038 | struct breakpoint *b; | |
7039 | int found = 0; | |
7040 | ||
6c95b8df | 7041 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
7042 | |
7043 | ALL_BREAKPOINTS (b) | |
7044 | { | |
6c95b8df PA |
7045 | if (b->pspace != current_program_space) |
7046 | continue; | |
7047 | ||
8bea4e01 UW |
7048 | if ((b->type == bp_breakpoint |
7049 | || b->type == bp_hardware_breakpoint) | |
7050 | && b->enable_state == bp_startup_disabled) | |
7051 | { | |
7052 | b->enable_state = bp_enabled; | |
7053 | found = 1; | |
7054 | } | |
7055 | } | |
7056 | ||
7057 | if (found) | |
7058 | breakpoint_re_set (); | |
7059 | } | |
7060 | ||
c906108c SS |
7061 | |
7062 | /* Set a breakpoint that will evaporate an end of command | |
7063 | at address specified by SAL. | |
7064 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
7065 | ||
7066 | struct breakpoint * | |
a6d9a66e UW |
7067 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
7068 | struct frame_id frame_id, enum bptype type) | |
c906108c | 7069 | { |
52f0bd74 | 7070 | struct breakpoint *b; |
edb3359d DJ |
7071 | |
7072 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
7073 | one. */ | |
7074 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
7075 | ||
06edf0c0 | 7076 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
7077 | b->enable_state = bp_enabled; |
7078 | b->disposition = disp_donttouch; | |
818dd999 | 7079 | b->frame_id = frame_id; |
c906108c | 7080 | |
4a64f543 MS |
7081 | /* If we're debugging a multi-threaded program, then we want |
7082 | momentary breakpoints to be active in only a single thread of | |
7083 | control. */ | |
39f77062 KB |
7084 | if (in_thread_list (inferior_ptid)) |
7085 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 7086 | |
b60e7edf | 7087 | update_global_location_list_nothrow (1); |
74960c60 | 7088 | |
c906108c SS |
7089 | return b; |
7090 | } | |
611c83ae | 7091 | |
06edf0c0 PA |
7092 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
7093 | The new breakpoint will have type TYPE, and use OPS as it | |
7094 | breakpoint_ops. */ | |
e58b0e63 | 7095 | |
06edf0c0 PA |
7096 | static struct breakpoint * |
7097 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
7098 | enum bptype type, | |
c0a91b2b | 7099 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
7100 | { |
7101 | struct breakpoint *copy; | |
7102 | ||
06edf0c0 | 7103 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 7104 | copy->loc = allocate_bp_location (copy); |
0e30163f | 7105 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 7106 | |
a6d9a66e | 7107 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
7108 | copy->loc->requested_address = orig->loc->requested_address; |
7109 | copy->loc->address = orig->loc->address; | |
7110 | copy->loc->section = orig->loc->section; | |
6c95b8df | 7111 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
7112 | |
7113 | if (orig->source_file == NULL) | |
7114 | copy->source_file = NULL; | |
7115 | else | |
7116 | copy->source_file = xstrdup (orig->source_file); | |
7117 | ||
7118 | copy->line_number = orig->line_number; | |
7119 | copy->frame_id = orig->frame_id; | |
7120 | copy->thread = orig->thread; | |
6c95b8df | 7121 | copy->pspace = orig->pspace; |
e58b0e63 PA |
7122 | |
7123 | copy->enable_state = bp_enabled; | |
7124 | copy->disposition = disp_donttouch; | |
7125 | copy->number = internal_breakpoint_number--; | |
7126 | ||
7127 | update_global_location_list_nothrow (0); | |
7128 | return copy; | |
7129 | } | |
7130 | ||
06edf0c0 PA |
7131 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
7132 | ORIG is NULL. */ | |
7133 | ||
7134 | struct breakpoint * | |
7135 | clone_momentary_breakpoint (struct breakpoint *orig) | |
7136 | { | |
7137 | /* If there's nothing to clone, then return nothing. */ | |
7138 | if (orig == NULL) | |
7139 | return NULL; | |
7140 | ||
7141 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
7142 | } | |
7143 | ||
611c83ae | 7144 | struct breakpoint * |
a6d9a66e UW |
7145 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
7146 | enum bptype type) | |
611c83ae PA |
7147 | { |
7148 | struct symtab_and_line sal; | |
7149 | ||
7150 | sal = find_pc_line (pc, 0); | |
7151 | sal.pc = pc; | |
7152 | sal.section = find_pc_overlay (pc); | |
7153 | sal.explicit_pc = 1; | |
7154 | ||
a6d9a66e | 7155 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 7156 | } |
c906108c | 7157 | \f |
c5aa993b | 7158 | |
c906108c SS |
7159 | /* Tell the user we have just set a breakpoint B. */ |
7160 | ||
7161 | static void | |
fba45db2 | 7162 | mention (struct breakpoint *b) |
c906108c | 7163 | { |
348d480f | 7164 | b->ops->print_mention (b); |
79a45e25 | 7165 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 7166 | return; |
c906108c SS |
7167 | printf_filtered ("\n"); |
7168 | } | |
c906108c | 7169 | \f |
c5aa993b | 7170 | |
0d381245 | 7171 | static struct bp_location * |
39d61571 | 7172 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7173 | const struct symtab_and_line *sal) |
7174 | { | |
7175 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
7176 | CORE_ADDR adjusted_address; |
7177 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
7178 | ||
7179 | if (loc_gdbarch == NULL) | |
7180 | loc_gdbarch = b->gdbarch; | |
7181 | ||
7182 | /* Adjust the breakpoint's address prior to allocating a location. | |
7183 | Once we call allocate_bp_location(), that mostly uninitialized | |
7184 | location will be placed on the location chain. Adjustment of the | |
7185 | breakpoint may cause target_read_memory() to be called and we do | |
7186 | not want its scan of the location chain to find a breakpoint and | |
7187 | location that's only been partially initialized. */ | |
7188 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
7189 | sal->pc, b->type); | |
0d381245 | 7190 | |
39d61571 | 7191 | loc = allocate_bp_location (b); |
0d381245 VP |
7192 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7193 | ; | |
7194 | *tmp = loc; | |
3742cc8b | 7195 | |
0d381245 | 7196 | loc->requested_address = sal->pc; |
3742cc8b | 7197 | loc->address = adjusted_address; |
6c95b8df PA |
7198 | loc->pspace = sal->pspace; |
7199 | gdb_assert (loc->pspace != NULL); | |
0d381245 | 7200 | loc->section = sal->section; |
3742cc8b | 7201 | loc->gdbarch = loc_gdbarch; |
0e30163f JK |
7202 | set_breakpoint_location_function (loc, |
7203 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
7204 | return loc; |
7205 | } | |
514f746b AR |
7206 | \f |
7207 | ||
7208 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7209 | return 0 otherwise. */ | |
7210 | ||
7211 | static int | |
7212 | bp_loc_is_permanent (struct bp_location *loc) | |
7213 | { | |
7214 | int len; | |
7215 | CORE_ADDR addr; | |
7216 | const gdb_byte *brk; | |
7217 | gdb_byte *target_mem; | |
939c61fa JK |
7218 | struct cleanup *cleanup; |
7219 | int retval = 0; | |
514f746b AR |
7220 | |
7221 | gdb_assert (loc != NULL); | |
7222 | ||
7223 | addr = loc->address; | |
a6d9a66e | 7224 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7225 | |
939c61fa JK |
7226 | /* Software breakpoints unsupported? */ |
7227 | if (brk == NULL) | |
7228 | return 0; | |
7229 | ||
514f746b AR |
7230 | target_mem = alloca (len); |
7231 | ||
939c61fa JK |
7232 | /* Enable the automatic memory restoration from breakpoints while |
7233 | we read the memory. Otherwise we could say about our temporary | |
7234 | breakpoints they are permanent. */ | |
6c95b8df PA |
7235 | cleanup = save_current_space_and_thread (); |
7236 | ||
7237 | switch_to_program_space_and_thread (loc->pspace); | |
7238 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7239 | |
514f746b AR |
7240 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7241 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7242 | retval = 1; |
514f746b | 7243 | |
939c61fa JK |
7244 | do_cleanups (cleanup); |
7245 | ||
7246 | return retval; | |
514f746b AR |
7247 | } |
7248 | ||
7249 | ||
c3f6f71d | 7250 | |
018d34a4 VP |
7251 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7252 | as textual description of the location, and COND_STRING | |
db107f19 | 7253 | as condition expression. */ |
018d34a4 VP |
7254 | |
7255 | static void | |
d9b3f62e PA |
7256 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
7257 | struct symtabs_and_lines sals, char *addr_string, | |
7258 | char *cond_string, | |
7259 | enum bptype type, enum bpdisp disposition, | |
7260 | int thread, int task, int ignore_count, | |
c0a91b2b | 7261 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e | 7262 | int enabled, int internal, int display_canonical) |
018d34a4 | 7263 | { |
0d381245 | 7264 | int i; |
018d34a4 VP |
7265 | |
7266 | if (type == bp_hardware_breakpoint) | |
7267 | { | |
fbbd034e AS |
7268 | int target_resources_ok; |
7269 | ||
7270 | i = hw_breakpoint_used_count (); | |
7271 | target_resources_ok = | |
7272 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
7273 | i + 1, 0); |
7274 | if (target_resources_ok == 0) | |
7275 | error (_("No hardware breakpoint support in the target.")); | |
7276 | else if (target_resources_ok < 0) | |
7277 | error (_("Hardware breakpoints used exceeds limit.")); | |
7278 | } | |
7279 | ||
6c95b8df PA |
7280 | gdb_assert (sals.nelts > 0); |
7281 | ||
0d381245 VP |
7282 | for (i = 0; i < sals.nelts; ++i) |
7283 | { | |
7284 | struct symtab_and_line sal = sals.sals[i]; | |
7285 | struct bp_location *loc; | |
7286 | ||
7287 | if (from_tty) | |
5af949e3 UW |
7288 | { |
7289 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7290 | if (!loc_gdbarch) | |
7291 | loc_gdbarch = gdbarch; | |
7292 | ||
7293 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7294 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7295 | } |
0d381245 VP |
7296 | |
7297 | if (i == 0) | |
7298 | { | |
d9b3f62e | 7299 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 7300 | b->thread = thread; |
4a306c9a | 7301 | b->task = task; |
018d34a4 | 7302 | |
0d381245 VP |
7303 | b->cond_string = cond_string; |
7304 | b->ignore_count = ignore_count; | |
41447f92 | 7305 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7306 | b->disposition = disposition; |
6c95b8df PA |
7307 | b->pspace = sals.sals[0].pspace; |
7308 | ||
0fb4aa4b PA |
7309 | if (type == bp_static_tracepoint) |
7310 | { | |
d9b3f62e | 7311 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
7312 | struct static_tracepoint_marker marker; |
7313 | ||
7314 | if (is_marker_spec (addr_string)) | |
7315 | { | |
7316 | /* We already know the marker exists, otherwise, we | |
7317 | wouldn't see a sal for it. */ | |
7318 | char *p = &addr_string[3]; | |
7319 | char *endp; | |
7320 | char *marker_str; | |
0fb4aa4b | 7321 | |
e9cafbcc | 7322 | p = skip_spaces (p); |
0fb4aa4b | 7323 | |
e9cafbcc | 7324 | endp = skip_to_space (p); |
0fb4aa4b PA |
7325 | |
7326 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 7327 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 7328 | |
3e43a32a MS |
7329 | printf_filtered (_("Probed static tracepoint " |
7330 | "marker \"%s\"\n"), | |
d9b3f62e | 7331 | t->static_trace_marker_id); |
0fb4aa4b PA |
7332 | } |
7333 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7334 | { | |
d9b3f62e | 7335 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
7336 | release_static_tracepoint_marker (&marker); |
7337 | ||
3e43a32a MS |
7338 | printf_filtered (_("Probed static tracepoint " |
7339 | "marker \"%s\"\n"), | |
d9b3f62e | 7340 | t->static_trace_marker_id); |
0fb4aa4b PA |
7341 | } |
7342 | else | |
3e43a32a MS |
7343 | warning (_("Couldn't determine the static " |
7344 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7345 | } |
7346 | ||
6c95b8df | 7347 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7348 | && (b->type == bp_breakpoint |
7349 | || b->type == bp_hardware_breakpoint)) | |
7350 | b->enable_state = bp_startup_disabled; | |
7351 | ||
0d381245 VP |
7352 | loc = b->loc; |
7353 | } | |
7354 | else | |
018d34a4 | 7355 | { |
39d61571 | 7356 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7357 | } |
7358 | ||
514f746b AR |
7359 | if (bp_loc_is_permanent (loc)) |
7360 | make_breakpoint_permanent (b); | |
7361 | ||
0d381245 VP |
7362 | if (b->cond_string) |
7363 | { | |
7364 | char *arg = b->cond_string; | |
d32a6982 | 7365 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7366 | if (*arg) |
db107f19 | 7367 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7368 | } |
0d381245 | 7369 | } |
018d34a4 | 7370 | |
56435ebe | 7371 | b->display_canonical = display_canonical; |
018d34a4 VP |
7372 | if (addr_string) |
7373 | b->addr_string = addr_string; | |
7374 | else | |
7375 | /* addr_string has to be used or breakpoint_re_set will delete | |
7376 | me. */ | |
5af949e3 UW |
7377 | b->addr_string |
7378 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
d9b3f62e | 7379 | } |
018d34a4 | 7380 | |
d9b3f62e PA |
7381 | static void |
7382 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
7383 | struct symtabs_and_lines sals, char *addr_string, | |
7384 | char *cond_string, | |
7385 | enum bptype type, enum bpdisp disposition, | |
7386 | int thread, int task, int ignore_count, | |
c0a91b2b | 7387 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e PA |
7388 | int enabled, int internal, int display_canonical) |
7389 | { | |
7390 | struct breakpoint *b; | |
7391 | struct cleanup *old_chain; | |
7392 | ||
7393 | if (is_tracepoint_type (type)) | |
7394 | { | |
7395 | struct tracepoint *t; | |
7396 | ||
7397 | t = XCNEW (struct tracepoint); | |
7398 | b = &t->base; | |
7399 | } | |
7400 | else | |
7401 | b = XNEW (struct breakpoint); | |
7402 | ||
7403 | old_chain = make_cleanup (xfree, b); | |
7404 | ||
7405 | init_breakpoint_sal (b, gdbarch, | |
7406 | sals, addr_string, | |
7407 | cond_string, | |
7408 | type, disposition, | |
7409 | thread, task, ignore_count, | |
7410 | ops, from_tty, | |
7411 | enabled, internal, display_canonical); | |
7412 | discard_cleanups (old_chain); | |
7413 | ||
3ea46bff | 7414 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
7415 | } |
7416 | ||
ed0616c6 VP |
7417 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7418 | elements to fill the void space. */ | |
2c0b251b PA |
7419 | static void |
7420 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7421 | { |
7422 | int i = index_to_remove+1; | |
7423 | int last_index = sal->nelts-1; | |
7424 | ||
7425 | for (;i <= last_index; ++i) | |
7426 | sal->sals[i-1] = sal->sals[i]; | |
7427 | ||
7428 | --(sal->nelts); | |
7429 | } | |
7430 | ||
6c95b8df PA |
7431 | /* If appropriate, obtains all sals that correspond to the same file |
7432 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7433 | will want to set a breakpoint at foo.c:line, and not really care | |
7434 | about program spaces. This is done only if SAL does not have | |
7435 | explicit PC and has line and file information. If we got just a | |
7436 | single expanded sal, return the original. | |
ed0616c6 | 7437 | |
6c95b8df PA |
7438 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7439 | which the name of enclosing function is different from SAL. This | |
7440 | makes sure that if we have breakpoint originally set in template | |
7441 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7442 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7443 | |
2c0b251b | 7444 | static struct symtabs_and_lines |
ed0616c6 VP |
7445 | expand_line_sal_maybe (struct symtab_and_line sal) |
7446 | { | |
7447 | struct symtabs_and_lines expanded; | |
7448 | CORE_ADDR original_pc = sal.pc; | |
7449 | char *original_function = NULL; | |
7450 | int found; | |
7451 | int i; | |
6c95b8df | 7452 | struct cleanup *old_chain; |
ed0616c6 VP |
7453 | |
7454 | /* If we have explicit pc, don't expand. | |
7455 | If we have no line number, we can't expand. */ | |
7456 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7457 | { | |
7458 | expanded.nelts = 1; | |
7459 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7460 | expanded.sals[0] = sal; | |
7461 | return expanded; | |
7462 | } | |
7463 | ||
7464 | sal.pc = 0; | |
6c95b8df PA |
7465 | |
7466 | old_chain = save_current_space_and_thread (); | |
7467 | ||
7468 | switch_to_program_space_and_thread (sal.pspace); | |
7469 | ||
ed0616c6 | 7470 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7471 | |
7472 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7473 | expanded = expand_line_sal (sal); |
6c95b8df | 7474 | |
ed0616c6 VP |
7475 | if (expanded.nelts == 1) |
7476 | { | |
3dba1c98 JB |
7477 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7478 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7479 | xfree (expanded.sals); |
7480 | expanded.nelts = 1; | |
7481 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7482 | sal.pc = original_pc; | |
7483 | expanded.sals[0] = sal; | |
3dba1c98 | 7484 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7485 | do_cleanups (old_chain); |
ed0616c6 VP |
7486 | return expanded; |
7487 | } | |
7488 | ||
7489 | if (!sal.explicit_line) | |
7490 | { | |
7491 | CORE_ADDR func_addr, func_end; | |
7492 | for (i = 0; i < expanded.nelts; ++i) | |
7493 | { | |
7494 | CORE_ADDR pc = expanded.sals[i].pc; | |
7495 | char *this_function; | |
6c95b8df PA |
7496 | |
7497 | /* We need to switch threads as well since we're about to | |
7498 | read memory. */ | |
7499 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7500 | ||
ed0616c6 VP |
7501 | if (find_pc_partial_function (pc, &this_function, |
7502 | &func_addr, &func_end)) | |
7503 | { | |
059fb39f PM |
7504 | if (this_function |
7505 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7506 | { |
7507 | remove_sal (&expanded, i); | |
7508 | --i; | |
7509 | } | |
ed0616c6 VP |
7510 | } |
7511 | } | |
7512 | } | |
059acae7 UW |
7513 | |
7514 | /* Skip the function prologue if necessary. */ | |
7515 | for (i = 0; i < expanded.nelts; ++i) | |
7516 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7517 | |
6c95b8df PA |
7518 | do_cleanups (old_chain); |
7519 | ||
ed0616c6 VP |
7520 | if (expanded.nelts <= 1) |
7521 | { | |
e5dd4106 | 7522 | /* This is an ugly workaround. If we get zero expanded sals |
4a64f543 MS |
7523 | then something is really wrong. Fix that by returning the |
7524 | original sal. */ | |
7525 | ||
ed0616c6 VP |
7526 | xfree (expanded.sals); |
7527 | expanded.nelts = 1; | |
7528 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7529 | sal.pc = original_pc; | |
7530 | expanded.sals[0] = sal; | |
7531 | return expanded; | |
7532 | } | |
7533 | ||
7534 | if (original_pc) | |
7535 | { | |
7536 | found = 0; | |
7537 | for (i = 0; i < expanded.nelts; ++i) | |
7538 | if (expanded.sals[i].pc == original_pc) | |
7539 | { | |
7540 | found = 1; | |
7541 | break; | |
7542 | } | |
7543 | gdb_assert (found); | |
7544 | } | |
7545 | ||
7546 | return expanded; | |
7547 | } | |
7548 | ||
018d34a4 VP |
7549 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7550 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7551 | value. COND_STRING, if not NULL, specified the condition to be | |
7552 | used for all breakpoints. Essentially the only case where | |
7553 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7554 | function. In that case, it's still not possible to specify | |
7555 | separate conditions for different overloaded functions, so | |
7556 | we take just a single condition string. | |
7557 | ||
c3f6f71d | 7558 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7559 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7560 | array contents). If the function fails (error() is called), the |
7561 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7562 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7563 | |
7564 | static void | |
8cdf0e15 | 7565 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 TT |
7566 | struct symtabs_and_lines sals, |
7567 | struct linespec_result *canonical, | |
8cdf0e15 VP |
7568 | char *cond_string, |
7569 | enum bptype type, enum bpdisp disposition, | |
7570 | int thread, int task, int ignore_count, | |
c0a91b2b | 7571 | const struct breakpoint_ops *ops, int from_tty, |
84f4c1fe | 7572 | int enabled, int internal) |
c906108c | 7573 | { |
018d34a4 | 7574 | int i; |
cc59ec59 | 7575 | |
018d34a4 | 7576 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7577 | { |
ed0616c6 VP |
7578 | struct symtabs_and_lines expanded = |
7579 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7580 | |
7efd8fc2 | 7581 | create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i], |
8cdf0e15 | 7582 | cond_string, type, disposition, |
84f4c1fe | 7583 | thread, task, ignore_count, ops, |
56435ebe TT |
7584 | from_tty, enabled, internal, |
7585 | canonical->special_display); | |
c3f6f71d | 7586 | } |
c3f6f71d | 7587 | } |
c906108c | 7588 | |
9998af43 | 7589 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7590 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7591 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7592 | address strings. ADDRESS points to the end of the SAL. |
7593 | ||
7594 | The array and the line spec strings are allocated on the heap, it is | |
7595 | the caller's responsibility to free them. */ | |
c906108c | 7596 | |
b9362cc7 | 7597 | static void |
c3f6f71d JM |
7598 | parse_breakpoint_sals (char **address, |
7599 | struct symtabs_and_lines *sals, | |
58438ac1 | 7600 | struct linespec_result *canonical) |
c3f6f71d JM |
7601 | { |
7602 | char *addr_start = *address; | |
cc59ec59 | 7603 | |
c3f6f71d | 7604 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 7605 | breakpoint. */ |
c3f6f71d JM |
7606 | if ((*address) == NULL |
7607 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c | 7608 | { |
1bfeeb0f JL |
7609 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
7610 | address. */ | |
7611 | if (last_displayed_sal_is_valid ()) | |
c906108c | 7612 | { |
c3f6f71d | 7613 | struct symtab_and_line sal; |
cc59ec59 | 7614 | |
4a64f543 | 7615 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7616 | sals->sals = (struct symtab_and_line *) |
c906108c | 7617 | xmalloc (sizeof (struct symtab_and_line)); |
1bfeeb0f JL |
7618 | |
7619 | /* Set sal's pspace, pc, symtab, and line to the values | |
7620 | corresponding to the last call to print_frame_info. */ | |
7621 | get_last_displayed_sal (&sal); | |
7622 | sal.section = find_pc_overlay (sal.pc); | |
00903456 | 7623 | |
4a64f543 | 7624 | /* "break" without arguments is equivalent to "break *PC" |
1bfeeb0f JL |
7625 | where PC is the last displayed codepoint's address. So |
7626 | make sure to set sal.explicit_pc to prevent GDB from | |
7627 | trying to expand the list of sals to include all other | |
7628 | instances with the same symtab and line. */ | |
00903456 JK |
7629 | sal.explicit_pc = 1; |
7630 | ||
c3f6f71d JM |
7631 | sals->sals[0] = sal; |
7632 | sals->nelts = 1; | |
c906108c SS |
7633 | } |
7634 | else | |
8a3fe4f8 | 7635 | error (_("No default breakpoint address now.")); |
c906108c SS |
7636 | } |
7637 | else | |
7638 | { | |
c906108c | 7639 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7640 | current_source_symtab (which is decode_line_1's default). |
7641 | This should produce the results we want almost all of the | |
1bfeeb0f JL |
7642 | time while leaving the last displayed codepoint pointers |
7643 | alone. | |
4a64f543 | 7644 | |
1aeae86e AF |
7645 | ObjC: However, don't match an Objective-C method name which |
7646 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7647 | |
c214a6fd | 7648 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7649 | |
1bfeeb0f | 7650 | if (last_displayed_sal_is_valid () |
0378c332 | 7651 | && (!cursal.symtab |
1aeae86e AF |
7652 | || ((strchr ("+-", (*address)[0]) != NULL) |
7653 | && ((*address)[1] != '[')))) | |
1bfeeb0f JL |
7654 | *sals = decode_line_1 (address, 1, |
7655 | get_last_displayed_symtab (), | |
7656 | get_last_displayed_line (), | |
7657 | canonical); | |
c906108c | 7658 | else |
0101ce28 | 7659 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
58438ac1 | 7660 | canonical); |
c906108c | 7661 | } |
4a64f543 | 7662 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7efd8fc2 | 7663 | if (sals->nelts > 0 && canonical->canonical == NULL) |
38a714bb | 7664 | canonical->canonical = xcalloc (sals->nelts, sizeof (char *)); |
c3f6f71d | 7665 | if (addr_start != (*address)) |
c906108c | 7666 | { |
c3f6f71d | 7667 | int i; |
cc59ec59 | 7668 | |
c3f6f71d | 7669 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7670 | { |
4a64f543 | 7671 | /* Add the string if not present. */ |
7efd8fc2 TT |
7672 | if (canonical->canonical[i] == NULL) |
7673 | canonical->canonical[i] = savestring (addr_start, | |
7674 | (*address) - addr_start); | |
c906108c SS |
7675 | } |
7676 | } | |
c3f6f71d | 7677 | } |
c906108c | 7678 | |
c906108c | 7679 | |
c3f6f71d | 7680 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7681 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7682 | |
b9362cc7 | 7683 | static void |
23e7acfb | 7684 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7685 | { |
7686 | int i; | |
cc59ec59 | 7687 | |
c3f6f71d | 7688 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7689 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7690 | } |
7691 | ||
7a697b8d SS |
7692 | /* Fast tracepoints may have restrictions on valid locations. For |
7693 | instance, a fast tracepoint using a jump instead of a trap will | |
7694 | likely have to overwrite more bytes than a trap would, and so can | |
7695 | only be placed where the instruction is longer than the jump, or a | |
7696 | multi-instruction sequence does not have a jump into the middle of | |
7697 | it, etc. */ | |
7698 | ||
7699 | static void | |
7700 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7701 | struct symtabs_and_lines *sals) | |
7702 | { | |
7703 | int i, rslt; | |
7704 | struct symtab_and_line *sal; | |
7705 | char *msg; | |
7706 | struct cleanup *old_chain; | |
7707 | ||
7708 | for (i = 0; i < sals->nelts; i++) | |
7709 | { | |
7710 | sal = &sals->sals[i]; | |
7711 | ||
7712 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7713 | NULL, &msg); | |
7714 | old_chain = make_cleanup (xfree, msg); | |
7715 | ||
7716 | if (!rslt) | |
7717 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7718 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7719 | ||
7720 | do_cleanups (old_chain); | |
7721 | } | |
7722 | } | |
7723 | ||
018d34a4 VP |
7724 | /* Given TOK, a string specification of condition and thread, as |
7725 | accepted by the 'break' command, extract the condition | |
7726 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7727 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7728 | If no condition is found, *COND_STRING is set to NULL. |
7729 | If no thread is found, *THREAD is set to -1. */ | |
7730 | static void | |
7731 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7732 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7733 | { |
7734 | *cond_string = NULL; | |
7735 | *thread = -1; | |
7736 | while (tok && *tok) | |
7737 | { | |
7738 | char *end_tok; | |
7739 | int toklen; | |
7740 | char *cond_start = NULL; | |
7741 | char *cond_end = NULL; | |
cc59ec59 | 7742 | |
e9cafbcc | 7743 | tok = skip_spaces (tok); |
018d34a4 | 7744 | |
e9cafbcc | 7745 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7746 | |
7747 | toklen = end_tok - tok; | |
7748 | ||
7749 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7750 | { | |
f7545552 TT |
7751 | struct expression *expr; |
7752 | ||
018d34a4 | 7753 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7754 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7755 | xfree (expr); | |
018d34a4 VP |
7756 | cond_end = tok; |
7757 | *cond_string = savestring (cond_start, | |
7758 | cond_end - cond_start); | |
7759 | } | |
7760 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7761 | { | |
7762 | char *tmptok; | |
7763 | ||
7764 | tok = end_tok + 1; | |
7765 | tmptok = tok; | |
7766 | *thread = strtol (tok, &tok, 0); | |
7767 | if (tok == tmptok) | |
7768 | error (_("Junk after thread keyword.")); | |
7769 | if (!valid_thread_id (*thread)) | |
7770 | error (_("Unknown thread %d."), *thread); | |
7771 | } | |
4a306c9a JB |
7772 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7773 | { | |
7774 | char *tmptok; | |
7775 | ||
7776 | tok = end_tok + 1; | |
7777 | tmptok = tok; | |
7778 | *task = strtol (tok, &tok, 0); | |
7779 | if (tok == tmptok) | |
7780 | error (_("Junk after task keyword.")); | |
7781 | if (!valid_task_id (*task)) | |
b6199126 | 7782 | error (_("Unknown task %d."), *task); |
4a306c9a | 7783 | } |
018d34a4 VP |
7784 | else |
7785 | error (_("Junk at end of arguments.")); | |
7786 | } | |
7787 | } | |
7788 | ||
0fb4aa4b PA |
7789 | /* Decode a static tracepoint marker spec. */ |
7790 | ||
7791 | static struct symtabs_and_lines | |
7792 | decode_static_tracepoint_spec (char **arg_p) | |
7793 | { | |
7794 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7795 | struct symtabs_and_lines sals; | |
7796 | struct symtab_and_line sal; | |
7797 | struct symbol *sym; | |
7798 | struct cleanup *old_chain; | |
7799 | char *p = &(*arg_p)[3]; | |
7800 | char *endp; | |
7801 | char *marker_str; | |
7802 | int i; | |
7803 | ||
e9cafbcc | 7804 | p = skip_spaces (p); |
0fb4aa4b | 7805 | |
e9cafbcc | 7806 | endp = skip_to_space (p); |
0fb4aa4b PA |
7807 | |
7808 | marker_str = savestring (p, endp - p); | |
7809 | old_chain = make_cleanup (xfree, marker_str); | |
7810 | ||
7811 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7812 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7813 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7814 | ||
7815 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7816 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7817 | ||
7818 | for (i = 0; i < sals.nelts; i++) | |
7819 | { | |
7820 | struct static_tracepoint_marker *marker; | |
7821 | ||
7822 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7823 | ||
7824 | init_sal (&sals.sals[i]); | |
7825 | ||
7826 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7827 | sals.sals[i].pc = marker->address; | |
7828 | ||
7829 | release_static_tracepoint_marker (marker); | |
7830 | } | |
7831 | ||
7832 | do_cleanups (old_chain); | |
7833 | ||
7834 | *arg_p = endp; | |
7835 | return sals; | |
7836 | } | |
7837 | ||
fd9b8c24 PA |
7838 | /* Set a breakpoint. This function is shared between CLI and MI |
7839 | functions for setting a breakpoint. This function has two major | |
7840 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7841 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7842 | breakpoint location, address and thread. Otherwise, ARG is just |
7843 | the location of breakpoint, with condition and thread specified by | |
7844 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7845 | the breakpoint number will be allocated from the internal | |
7846 | breakpoint count. Returns true if any breakpoint was created; | |
7847 | false otherwise. */ | |
0101ce28 | 7848 | |
8cdf0e15 VP |
7849 | int |
7850 | create_breakpoint (struct gdbarch *gdbarch, | |
7851 | char *arg, char *cond_string, int thread, | |
7852 | int parse_condition_and_thread, | |
0fb4aa4b | 7853 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7854 | int ignore_count, |
7855 | enum auto_boolean pending_break_support, | |
c0a91b2b | 7856 | const struct breakpoint_ops *ops, |
84f4c1fe | 7857 | int from_tty, int enabled, int internal) |
c3f6f71d | 7858 | { |
b78a6381 | 7859 | volatile struct gdb_exception e; |
c3f6f71d | 7860 | struct symtabs_and_lines sals; |
0101ce28 | 7861 | struct symtab_and_line pending_sal; |
0101ce28 | 7862 | char *copy_arg; |
c3f6f71d | 7863 | char *addr_start = arg; |
7efd8fc2 | 7864 | struct linespec_result canonical; |
c3f6f71d | 7865 | struct cleanup *old_chain; |
80c99de1 | 7866 | struct cleanup *bkpt_chain = NULL; |
05ff989b | 7867 | int i; |
0101ce28 | 7868 | int pending = 0; |
4a306c9a | 7869 | int task = 0; |
86b17b60 | 7870 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7871 | |
348d480f PA |
7872 | gdb_assert (ops != NULL); |
7873 | ||
c3f6f71d JM |
7874 | sals.sals = NULL; |
7875 | sals.nelts = 0; | |
7efd8fc2 | 7876 | init_linespec_result (&canonical); |
c3f6f71d | 7877 | |
0fb4aa4b PA |
7878 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7879 | { | |
7880 | int i; | |
7881 | ||
7882 | sals = decode_static_tracepoint_spec (&arg); | |
7883 | ||
7884 | copy_arg = savestring (addr_start, arg - addr_start); | |
38a714bb | 7885 | canonical.canonical = xcalloc (sals.nelts, sizeof (char *)); |
0fb4aa4b | 7886 | for (i = 0; i < sals.nelts; i++) |
7efd8fc2 | 7887 | canonical.canonical[i] = xstrdup (copy_arg); |
0fb4aa4b PA |
7888 | goto done; |
7889 | } | |
7890 | ||
b78a6381 TT |
7891 | TRY_CATCH (e, RETURN_MASK_ALL) |
7892 | { | |
58438ac1 | 7893 | parse_breakpoint_sals (&arg, &sals, &canonical); |
b78a6381 | 7894 | } |
0101ce28 JJ |
7895 | |
7896 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7897 | switch (e.reason) |
0101ce28 | 7898 | { |
05ff989b | 7899 | case RETURN_QUIT: |
98deb0da | 7900 | throw_exception (e); |
05ff989b AC |
7901 | case RETURN_ERROR: |
7902 | switch (e.error) | |
0101ce28 | 7903 | { |
05ff989b | 7904 | case NOT_FOUND_ERROR: |
0101ce28 | 7905 | |
05ff989b AC |
7906 | /* If pending breakpoint support is turned off, throw |
7907 | error. */ | |
fa8d40ab JJ |
7908 | |
7909 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7910 | throw_exception (e); |
7911 | ||
7912 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7913 | |
05ff989b AC |
7914 | /* If pending breakpoint support is auto query and the user |
7915 | selects no, then simply return the error code. */ | |
059fb39f | 7916 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
7917 | && !nquery (_("Make %s pending on future shared library load? "), |
7918 | bptype_string (type_wanted))) | |
fd9b8c24 | 7919 | return 0; |
fa8d40ab | 7920 | |
05ff989b AC |
7921 | /* At this point, either the user was queried about setting |
7922 | a pending breakpoint and selected yes, or pending | |
7923 | breakpoint behavior is on and thus a pending breakpoint | |
7924 | is defaulted on behalf of the user. */ | |
0101ce28 | 7925 | copy_arg = xstrdup (addr_start); |
7efd8fc2 | 7926 | canonical.canonical = ©_arg; |
0101ce28 JJ |
7927 | sals.nelts = 1; |
7928 | sals.sals = &pending_sal; | |
7929 | pending_sal.pc = 0; | |
7930 | pending = 1; | |
05ff989b AC |
7931 | break; |
7932 | default: | |
98deb0da | 7933 | throw_exception (e); |
0101ce28 | 7934 | } |
2abae994 | 7935 | break; |
05ff989b AC |
7936 | default: |
7937 | if (!sals.nelts) | |
fd9b8c24 | 7938 | return 0; |
0101ce28 | 7939 | } |
c3f6f71d | 7940 | |
0fb4aa4b PA |
7941 | done: |
7942 | ||
4a64f543 | 7943 | /* Create a chain of things that always need to be cleaned up. */ |
c3f6f71d JM |
7944 | old_chain = make_cleanup (null_cleanup, 0); |
7945 | ||
0101ce28 JJ |
7946 | if (!pending) |
7947 | { | |
7948 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7949 | make_cleanup (xfree, sals.sals); | |
7950 | ||
7efd8fc2 TT |
7951 | /* Cleanup the canonical array but not its contents. */ |
7952 | make_cleanup (xfree, canonical.canonical); | |
0101ce28 | 7953 | } |
c3f6f71d | 7954 | |
c3f6f71d JM |
7955 | /* ----------------------------- SNIP ----------------------------- |
7956 | Anything added to the cleanup chain beyond this point is assumed | |
7957 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7958 | then the memory is not reclaimed. */ |
7959 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 7960 | |
7efd8fc2 | 7961 | /* Mark the contents of the canonical for cleanup. These go on |
80c99de1 | 7962 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7963 | for (i = 0; i < sals.nelts; i++) |
7964 | { | |
7efd8fc2 TT |
7965 | if (canonical.canonical[i] != NULL) |
7966 | make_cleanup (xfree, canonical.canonical[i]); | |
c3f6f71d JM |
7967 | } |
7968 | ||
7969 | /* Resolve all line numbers to PC's and verify that the addresses | |
7970 | are ok for the target. */ | |
0101ce28 | 7971 | if (!pending) |
23e7acfb | 7972 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 7973 | |
7a697b8d | 7974 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 7975 | if (!pending && type_wanted == bp_fast_tracepoint) |
7a697b8d SS |
7976 | check_fast_tracepoint_sals (gdbarch, &sals); |
7977 | ||
c3f6f71d JM |
7978 | /* Verify that condition can be parsed, before setting any |
7979 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 7980 | breakpoint. */ |
0101ce28 | 7981 | if (!pending) |
c3f6f71d | 7982 | { |
2f069f6f | 7983 | if (parse_condition_and_thread) |
72b2ff0e VP |
7984 | { |
7985 | /* Here we only parse 'arg' to separate condition | |
7986 | from thread number, so parsing in context of first | |
7987 | sal is OK. When setting the breakpoint we'll | |
7988 | re-parse it in context of each sal. */ | |
7989 | cond_string = NULL; | |
7990 | thread = -1; | |
4a306c9a JB |
7991 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7992 | &thread, &task); | |
72b2ff0e VP |
7993 | if (cond_string) |
7994 | make_cleanup (xfree, cond_string); | |
7995 | } | |
2f069f6f | 7996 | else |
72b2ff0e VP |
7997 | { |
7998 | /* Create a private copy of condition string. */ | |
7999 | if (cond_string) | |
8000 | { | |
8001 | cond_string = xstrdup (cond_string); | |
8002 | make_cleanup (xfree, cond_string); | |
8003 | } | |
8004 | } | |
0fb4aa4b PA |
8005 | |
8006 | /* If the user is creating a static tracepoint by marker id | |
8007 | (strace -m MARKER_ID), then store the sals index, so that | |
8008 | breakpoint_re_set can try to match up which of the newly | |
8009 | found markers corresponds to this one, and, don't try to | |
8010 | expand multiple locations for each sal, given than SALS | |
8011 | already should contain all sals for MARKER_ID. */ | |
8012 | if (type_wanted == bp_static_tracepoint | |
7efd8fc2 | 8013 | && is_marker_spec (canonical.canonical[0])) |
0fb4aa4b PA |
8014 | { |
8015 | int i; | |
8016 | ||
8017 | for (i = 0; i < sals.nelts; ++i) | |
8018 | { | |
8019 | struct symtabs_and_lines expanded; | |
d9b3f62e | 8020 | struct tracepoint *tp; |
0fb4aa4b PA |
8021 | struct cleanup *old_chain; |
8022 | ||
8023 | expanded.nelts = 1; | |
8024 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
8025 | expanded.sals[0] = sals.sals[i]; | |
8026 | old_chain = make_cleanup (xfree, expanded.sals); | |
8027 | ||
d9b3f62e PA |
8028 | tp = XCNEW (struct tracepoint); |
8029 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
8030 | canonical.canonical[i], | |
8031 | cond_string, type_wanted, | |
8032 | tempflag ? disp_del : disp_donttouch, | |
8033 | thread, task, ignore_count, ops, | |
8034 | from_tty, enabled, internal, | |
8035 | canonical.special_display); | |
0fb4aa4b PA |
8036 | /* Given that its possible to have multiple markers with |
8037 | the same string id, if the user is creating a static | |
8038 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
8039 | store the sals index, so that breakpoint_re_set can | |
8040 | try to match up which of the newly found markers | |
8041 | corresponds to this one */ | |
8042 | tp->static_trace_marker_id_idx = i; | |
d9b3f62e | 8043 | |
3ea46bff | 8044 | install_breakpoint (internal, &tp->base, 0); |
d9b3f62e PA |
8045 | |
8046 | do_cleanups (old_chain); | |
0fb4aa4b PA |
8047 | } |
8048 | } | |
8049 | else | |
7efd8fc2 | 8050 | create_breakpoints_sal (gdbarch, sals, &canonical, cond_string, |
3e43a32a MS |
8051 | type_wanted, |
8052 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 8053 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 8054 | enabled, internal); |
c906108c | 8055 | } |
0101ce28 JJ |
8056 | else |
8057 | { | |
0101ce28 JJ |
8058 | struct breakpoint *b; |
8059 | ||
0101ce28 JJ |
8060 | make_cleanup (xfree, copy_arg); |
8061 | ||
bfccc43c YQ |
8062 | if (is_tracepoint_type (type_wanted)) |
8063 | { | |
8064 | struct tracepoint *t; | |
8065 | ||
8066 | t = XCNEW (struct tracepoint); | |
8067 | b = &t->base; | |
8068 | } | |
8069 | else | |
8070 | b = XNEW (struct breakpoint); | |
8071 | ||
8072 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
8073 | ||
7efd8fc2 | 8074 | b->addr_string = canonical.canonical[0]; |
72b2ff0e | 8075 | b->cond_string = NULL; |
0101ce28 | 8076 | b->ignore_count = ignore_count; |
0101ce28 | 8077 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 8078 | b->condition_not_parsed = 1; |
41447f92 | 8079 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 8080 | b->pspace = current_program_space; |
74960c60 | 8081 | |
6c95b8df | 8082 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
8083 | && (b->type == bp_breakpoint |
8084 | || b->type == bp_hardware_breakpoint)) | |
8085 | b->enable_state = bp_startup_disabled; | |
8086 | ||
bfccc43c | 8087 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
8088 | } |
8089 | ||
c3f6f71d | 8090 | if (sals.nelts > 1) |
95a42b64 | 8091 | { |
3e43a32a MS |
8092 | warning (_("Multiple breakpoints were set.\nUse the " |
8093 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 8094 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
8095 | } |
8096 | ||
80c99de1 PA |
8097 | /* That's it. Discard the cleanups for data inserted into the |
8098 | breakpoint. */ | |
8099 | discard_cleanups (bkpt_chain); | |
8100 | /* But cleanup everything else. */ | |
c3f6f71d | 8101 | do_cleanups (old_chain); |
217dc9e2 | 8102 | |
80c99de1 | 8103 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 8104 | update_global_location_list (1); |
fd9b8c24 PA |
8105 | |
8106 | return 1; | |
c3f6f71d | 8107 | } |
c906108c | 8108 | |
348d480f | 8109 | /* Set a breakpoint. |
72b2ff0e VP |
8110 | ARG is a string describing breakpoint address, |
8111 | condition, and thread. | |
8112 | FLAG specifies if a breakpoint is hardware on, | |
8113 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8114 | and BP_TEMPFLAG. */ | |
348d480f | 8115 | |
98deb0da | 8116 | static void |
72b2ff0e | 8117 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8118 | { |
72b2ff0e | 8119 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8120 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8121 | ? bp_hardware_breakpoint | |
8122 | : bp_breakpoint); | |
c3f6f71d | 8123 | |
8cdf0e15 VP |
8124 | create_breakpoint (get_current_arch (), |
8125 | arg, | |
8126 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8127 | tempflag, type_wanted, |
8cdf0e15 VP |
8128 | 0 /* Ignore count */, |
8129 | pending_break_support, | |
348d480f | 8130 | &bkpt_breakpoint_ops, |
8cdf0e15 | 8131 | from_tty, |
84f4c1fe PM |
8132 | 1 /* enabled */, |
8133 | 0 /* internal */); | |
c906108c SS |
8134 | } |
8135 | ||
c906108c SS |
8136 | /* Helper function for break_command_1 and disassemble_command. */ |
8137 | ||
8138 | void | |
fba45db2 | 8139 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8140 | { |
8141 | CORE_ADDR pc; | |
8142 | ||
8143 | if (sal->pc == 0 && sal->symtab != NULL) | |
8144 | { | |
8145 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8146 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8147 | sal->line, sal->symtab->filename); |
8148 | sal->pc = pc; | |
6a048695 | 8149 | |
4a64f543 MS |
8150 | /* If this SAL corresponds to a breakpoint inserted using a line |
8151 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8152 | if (sal->explicit_line) |
059acae7 | 8153 | skip_prologue_sal (sal); |
c906108c SS |
8154 | } |
8155 | ||
8156 | if (sal->section == 0 && sal->symtab != NULL) | |
8157 | { | |
8158 | struct blockvector *bv; | |
c5aa993b JM |
8159 | struct block *b; |
8160 | struct symbol *sym; | |
c906108c | 8161 | |
801e3a5b | 8162 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8163 | if (bv != NULL) |
8164 | { | |
7f0df278 | 8165 | sym = block_linkage_function (b); |
c906108c SS |
8166 | if (sym != NULL) |
8167 | { | |
8168 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8169 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8170 | } |
8171 | else | |
8172 | { | |
4a64f543 MS |
8173 | /* It really is worthwhile to have the section, so we'll |
8174 | just have to look harder. This case can be executed | |
8175 | if we have line numbers but no functions (as can | |
8176 | happen in assembly source). */ | |
c906108c | 8177 | |
c5aa993b | 8178 | struct minimal_symbol *msym; |
6c95b8df PA |
8179 | struct cleanup *old_chain = save_current_space_and_thread (); |
8180 | ||
8181 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8182 | |
8183 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8184 | if (msym) | |
714835d5 | 8185 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8186 | |
8187 | do_cleanups (old_chain); | |
c906108c SS |
8188 | } |
8189 | } | |
8190 | } | |
8191 | } | |
8192 | ||
8193 | void | |
fba45db2 | 8194 | break_command (char *arg, int from_tty) |
c906108c | 8195 | { |
db107f19 | 8196 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8197 | } |
8198 | ||
c906108c | 8199 | void |
fba45db2 | 8200 | tbreak_command (char *arg, int from_tty) |
c906108c | 8201 | { |
db107f19 | 8202 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8203 | } |
8204 | ||
c906108c | 8205 | static void |
fba45db2 | 8206 | hbreak_command (char *arg, int from_tty) |
c906108c | 8207 | { |
db107f19 | 8208 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8209 | } |
8210 | ||
8211 | static void | |
fba45db2 | 8212 | thbreak_command (char *arg, int from_tty) |
c906108c | 8213 | { |
db107f19 | 8214 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8215 | } |
8216 | ||
8217 | static void | |
fba45db2 | 8218 | stop_command (char *arg, int from_tty) |
c906108c | 8219 | { |
a3f17187 | 8220 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8221 | Usage: stop in <function | address>\n\ |
a3f17187 | 8222 | stop at <line>\n")); |
c906108c SS |
8223 | } |
8224 | ||
8225 | static void | |
fba45db2 | 8226 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8227 | { |
8228 | int badInput = 0; | |
8229 | ||
c5aa993b | 8230 | if (arg == (char *) NULL) |
c906108c SS |
8231 | badInput = 1; |
8232 | else if (*arg != '*') | |
8233 | { | |
8234 | char *argptr = arg; | |
8235 | int hasColon = 0; | |
8236 | ||
4a64f543 | 8237 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8238 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8239 | function/method name. */ |
c906108c | 8240 | while (*argptr && !hasColon) |
c5aa993b JM |
8241 | { |
8242 | hasColon = (*argptr == ':'); | |
8243 | argptr++; | |
8244 | } | |
c906108c SS |
8245 | |
8246 | if (hasColon) | |
c5aa993b | 8247 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8248 | else |
c5aa993b | 8249 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8250 | } |
8251 | ||
8252 | if (badInput) | |
a3f17187 | 8253 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8254 | else |
db107f19 | 8255 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8256 | } |
8257 | ||
8258 | static void | |
fba45db2 | 8259 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8260 | { |
8261 | int badInput = 0; | |
8262 | ||
c5aa993b | 8263 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8264 | badInput = 1; |
8265 | else | |
8266 | { | |
8267 | char *argptr = arg; | |
8268 | int hasColon = 0; | |
8269 | ||
4a64f543 MS |
8270 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8271 | it is probably a line number. */ | |
c906108c | 8272 | while (*argptr && !hasColon) |
c5aa993b JM |
8273 | { |
8274 | hasColon = (*argptr == ':'); | |
8275 | argptr++; | |
8276 | } | |
c906108c SS |
8277 | |
8278 | if (hasColon) | |
c5aa993b | 8279 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8280 | else |
c5aa993b | 8281 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8282 | } |
8283 | ||
8284 | if (badInput) | |
a3f17187 | 8285 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8286 | else |
db107f19 | 8287 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8288 | } |
8289 | ||
f1310107 TJB |
8290 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
8291 | ranged breakpoints. */ | |
8292 | ||
8293 | static int | |
8294 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
8295 | struct address_space *aspace, | |
8296 | CORE_ADDR bp_addr) | |
8297 | { | |
8298 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, | |
8299 | bl->length, aspace, bp_addr); | |
8300 | } | |
8301 | ||
8302 | /* Implement the "resources_needed" breakpoint_ops method for | |
8303 | ranged breakpoints. */ | |
8304 | ||
8305 | static int | |
8306 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
8307 | { | |
8308 | return target_ranged_break_num_registers (); | |
8309 | } | |
8310 | ||
8311 | /* Implement the "print_it" breakpoint_ops method for | |
8312 | ranged breakpoints. */ | |
8313 | ||
8314 | static enum print_stop_action | |
348d480f | 8315 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 8316 | { |
348d480f | 8317 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 8318 | struct bp_location *bl = b->loc; |
79a45e25 | 8319 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8320 | |
8321 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8322 | ||
8323 | /* Ranged breakpoints have only one location. */ | |
8324 | gdb_assert (bl && bl->next == NULL); | |
8325 | ||
8326 | annotate_breakpoint (b->number); | |
8327 | if (b->disposition == disp_del) | |
8328 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
8329 | else | |
8330 | ui_out_text (uiout, "\nRanged breakpoint "); | |
8331 | if (ui_out_is_mi_like_p (uiout)) | |
8332 | { | |
8333 | ui_out_field_string (uiout, "reason", | |
8334 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8335 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8336 | } | |
8337 | ui_out_field_int (uiout, "bkptno", b->number); | |
8338 | ui_out_text (uiout, ", "); | |
8339 | ||
8340 | return PRINT_SRC_AND_LOC; | |
8341 | } | |
8342 | ||
8343 | /* Implement the "print_one" breakpoint_ops method for | |
8344 | ranged breakpoints. */ | |
8345 | ||
8346 | static void | |
8347 | print_one_ranged_breakpoint (struct breakpoint *b, | |
8348 | struct bp_location **last_loc) | |
8349 | { | |
8350 | struct bp_location *bl = b->loc; | |
8351 | struct value_print_options opts; | |
79a45e25 | 8352 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8353 | |
8354 | /* Ranged breakpoints have only one location. */ | |
8355 | gdb_assert (bl && bl->next == NULL); | |
8356 | ||
8357 | get_user_print_options (&opts); | |
8358 | ||
8359 | if (opts.addressprint) | |
8360 | /* We don't print the address range here, it will be printed later | |
8361 | by print_one_detail_ranged_breakpoint. */ | |
8362 | ui_out_field_skip (uiout, "addr"); | |
8363 | annotate_field (5); | |
8364 | print_breakpoint_location (b, bl); | |
8365 | *last_loc = bl; | |
8366 | } | |
8367 | ||
8368 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8369 | ranged breakpoints. */ | |
8370 | ||
8371 | static void | |
8372 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
8373 | struct ui_out *uiout) | |
8374 | { | |
8375 | CORE_ADDR address_start, address_end; | |
8376 | struct bp_location *bl = b->loc; | |
8377 | struct ui_stream *stb = ui_out_stream_new (uiout); | |
8378 | struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb); | |
8379 | ||
8380 | gdb_assert (bl); | |
8381 | ||
8382 | address_start = bl->address; | |
8383 | address_end = address_start + bl->length - 1; | |
8384 | ||
8385 | ui_out_text (uiout, "\taddress range: "); | |
8386 | fprintf_unfiltered (stb->stream, "[%s, %s]", | |
8387 | print_core_address (bl->gdbarch, address_start), | |
8388 | print_core_address (bl->gdbarch, address_end)); | |
8389 | ui_out_field_stream (uiout, "addr", stb); | |
8390 | ui_out_text (uiout, "\n"); | |
8391 | ||
8392 | do_cleanups (cleanup); | |
8393 | } | |
8394 | ||
8395 | /* Implement the "print_mention" breakpoint_ops method for | |
8396 | ranged breakpoints. */ | |
8397 | ||
8398 | static void | |
8399 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
8400 | { | |
8401 | struct bp_location *bl = b->loc; | |
79a45e25 | 8402 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8403 | |
8404 | gdb_assert (bl); | |
8405 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8406 | ||
8407 | if (ui_out_is_mi_like_p (uiout)) | |
8408 | return; | |
8409 | ||
8410 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
8411 | b->number, paddress (bl->gdbarch, bl->address), | |
8412 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
8413 | } | |
8414 | ||
8415 | /* Implement the "print_recreate" breakpoint_ops method for | |
8416 | ranged breakpoints. */ | |
8417 | ||
8418 | static void | |
8419 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
8420 | { | |
8421 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
8422 | b->addr_string_range_end); | |
d9b3f62e | 8423 | print_recreate_thread (b, fp); |
f1310107 TJB |
8424 | } |
8425 | ||
8426 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
8427 | ||
2060206e | 8428 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
8429 | |
8430 | /* Find the address where the end of the breakpoint range should be | |
8431 | placed, given the SAL of the end of the range. This is so that if | |
8432 | the user provides a line number, the end of the range is set to the | |
8433 | last instruction of the given line. */ | |
8434 | ||
8435 | static CORE_ADDR | |
8436 | find_breakpoint_range_end (struct symtab_and_line sal) | |
8437 | { | |
8438 | CORE_ADDR end; | |
8439 | ||
8440 | /* If the user provided a PC value, use it. Otherwise, | |
8441 | find the address of the end of the given location. */ | |
8442 | if (sal.explicit_pc) | |
8443 | end = sal.pc; | |
8444 | else | |
8445 | { | |
8446 | int ret; | |
8447 | CORE_ADDR start; | |
8448 | ||
8449 | ret = find_line_pc_range (sal, &start, &end); | |
8450 | if (!ret) | |
8451 | error (_("Could not find location of the end of the range.")); | |
8452 | ||
8453 | /* find_line_pc_range returns the start of the next line. */ | |
8454 | end--; | |
8455 | } | |
8456 | ||
8457 | return end; | |
8458 | } | |
8459 | ||
8460 | /* Implement the "break-range" CLI command. */ | |
8461 | ||
8462 | static void | |
8463 | break_range_command (char *arg, int from_tty) | |
8464 | { | |
8465 | char *arg_start, *addr_string_start, *addr_string_end; | |
8466 | struct linespec_result canonical_start, canonical_end; | |
8467 | int bp_count, can_use_bp, length; | |
8468 | CORE_ADDR end; | |
8469 | struct breakpoint *b; | |
8470 | struct symtab_and_line sal_start, sal_end; | |
8471 | struct symtabs_and_lines sals_start, sals_end; | |
8472 | struct cleanup *cleanup_bkpt; | |
8473 | ||
8474 | /* We don't support software ranged breakpoints. */ | |
8475 | if (target_ranged_break_num_registers () < 0) | |
8476 | error (_("This target does not support hardware ranged breakpoints.")); | |
8477 | ||
8478 | bp_count = hw_breakpoint_used_count (); | |
8479 | bp_count += target_ranged_break_num_registers (); | |
8480 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
8481 | bp_count, 0); | |
8482 | if (can_use_bp < 0) | |
8483 | error (_("Hardware breakpoints used exceeds limit.")); | |
8484 | ||
8485 | if (arg == NULL || arg[0] == '\0') | |
8486 | error(_("No address range specified.")); | |
8487 | ||
8488 | sals_start.sals = NULL; | |
8489 | sals_start.nelts = 0; | |
8490 | init_linespec_result (&canonical_start); | |
8491 | ||
8492 | while (*arg == ' ' || *arg == '\t') | |
8493 | arg++; | |
8494 | ||
58438ac1 | 8495 | parse_breakpoint_sals (&arg, &sals_start, &canonical_start); |
f1310107 TJB |
8496 | |
8497 | sal_start = sals_start.sals[0]; | |
8498 | addr_string_start = canonical_start.canonical[0]; | |
8499 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); | |
8500 | xfree (sals_start.sals); | |
8501 | xfree (canonical_start.canonical); | |
8502 | ||
8503 | if (arg[0] != ',') | |
8504 | error (_("Too few arguments.")); | |
8505 | else if (sals_start.nelts == 0) | |
8506 | error (_("Could not find location of the beginning of the range.")); | |
8507 | else if (sals_start.nelts != 1) | |
8508 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8509 | ||
8510 | resolve_sal_pc (&sal_start); | |
8511 | ||
8512 | arg++; /* Skip the comma. */ | |
8513 | while (*arg == ' ' || *arg == '\t') | |
8514 | arg++; | |
8515 | ||
8516 | /* Parse the end location. */ | |
8517 | ||
8518 | sals_end.sals = NULL; | |
8519 | sals_end.nelts = 0; | |
8520 | init_linespec_result (&canonical_end); | |
8521 | arg_start = arg; | |
8522 | ||
423f41a5 | 8523 | /* We call decode_line_1 directly here instead of using |
f1310107 TJB |
8524 | parse_breakpoint_sals because we need to specify the start location's |
8525 | symtab and line as the default symtab and line for the end of the | |
8526 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
8527 | where +14 means 14 lines from the start location. */ | |
8528 | sals_end = decode_line_1 (&arg, 1, sal_start.symtab, sal_start.line, | |
58438ac1 | 8529 | &canonical_end); |
f1310107 TJB |
8530 | |
8531 | /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */ | |
8532 | if (canonical_end.canonical == NULL) | |
38a714bb | 8533 | canonical_end.canonical = xcalloc (1, sizeof (char *)); |
f1310107 TJB |
8534 | /* Add the string if not present. */ |
8535 | if (arg_start != arg && canonical_end.canonical[0] == NULL) | |
8536 | canonical_end.canonical[0] = savestring (arg_start, arg - arg_start); | |
8537 | ||
8538 | sal_end = sals_end.sals[0]; | |
8539 | addr_string_end = canonical_end.canonical[0]; | |
8540 | make_cleanup (xfree, addr_string_end); | |
8541 | xfree (sals_end.sals); | |
8542 | xfree (canonical_end.canonical); | |
8543 | ||
8544 | if (sals_end.nelts == 0) | |
8545 | error (_("Could not find location of the end of the range.")); | |
8546 | else if (sals_end.nelts != 1) | |
8547 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8548 | ||
8549 | resolve_sal_pc (&sal_end); | |
8550 | ||
8551 | end = find_breakpoint_range_end (sal_end); | |
8552 | if (sal_start.pc > end) | |
177b42fe | 8553 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
8554 | |
8555 | length = end - sal_start.pc + 1; | |
8556 | if (length < 0) | |
8557 | /* Length overflowed. */ | |
8558 | error (_("Address range too large.")); | |
8559 | else if (length == 1) | |
8560 | { | |
8561 | /* This range is simple enough to be handled by | |
8562 | the `hbreak' command. */ | |
8563 | hbreak_command (addr_string_start, 1); | |
8564 | ||
8565 | do_cleanups (cleanup_bkpt); | |
8566 | ||
8567 | return; | |
8568 | } | |
8569 | ||
8570 | /* Now set up the breakpoint. */ | |
8571 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 8572 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
8573 | set_breakpoint_count (breakpoint_count + 1); |
8574 | b->number = breakpoint_count; | |
8575 | b->disposition = disp_donttouch; | |
8576 | b->addr_string = addr_string_start; | |
8577 | b->addr_string_range_end = addr_string_end; | |
f1310107 TJB |
8578 | b->loc->length = length; |
8579 | ||
8580 | discard_cleanups (cleanup_bkpt); | |
8581 | ||
8582 | mention (b); | |
8d3788bd | 8583 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
8584 | update_global_location_list (1); |
8585 | } | |
8586 | ||
4a64f543 MS |
8587 | /* Return non-zero if EXP is verified as constant. Returned zero |
8588 | means EXP is variable. Also the constant detection may fail for | |
8589 | some constant expressions and in such case still falsely return | |
8590 | zero. */ | |
65d79d4b SDJ |
8591 | static int |
8592 | watchpoint_exp_is_const (const struct expression *exp) | |
8593 | { | |
8594 | int i = exp->nelts; | |
8595 | ||
8596 | while (i > 0) | |
8597 | { | |
8598 | int oplenp, argsp; | |
8599 | ||
8600 | /* We are only interested in the descriptor of each element. */ | |
8601 | operator_length (exp, i, &oplenp, &argsp); | |
8602 | i -= oplenp; | |
8603 | ||
8604 | switch (exp->elts[i].opcode) | |
8605 | { | |
8606 | case BINOP_ADD: | |
8607 | case BINOP_SUB: | |
8608 | case BINOP_MUL: | |
8609 | case BINOP_DIV: | |
8610 | case BINOP_REM: | |
8611 | case BINOP_MOD: | |
8612 | case BINOP_LSH: | |
8613 | case BINOP_RSH: | |
8614 | case BINOP_LOGICAL_AND: | |
8615 | case BINOP_LOGICAL_OR: | |
8616 | case BINOP_BITWISE_AND: | |
8617 | case BINOP_BITWISE_IOR: | |
8618 | case BINOP_BITWISE_XOR: | |
8619 | case BINOP_EQUAL: | |
8620 | case BINOP_NOTEQUAL: | |
8621 | case BINOP_LESS: | |
8622 | case BINOP_GTR: | |
8623 | case BINOP_LEQ: | |
8624 | case BINOP_GEQ: | |
8625 | case BINOP_REPEAT: | |
8626 | case BINOP_COMMA: | |
8627 | case BINOP_EXP: | |
8628 | case BINOP_MIN: | |
8629 | case BINOP_MAX: | |
8630 | case BINOP_INTDIV: | |
8631 | case BINOP_CONCAT: | |
8632 | case BINOP_IN: | |
8633 | case BINOP_RANGE: | |
8634 | case TERNOP_COND: | |
8635 | case TERNOP_SLICE: | |
8636 | case TERNOP_SLICE_COUNT: | |
8637 | ||
8638 | case OP_LONG: | |
8639 | case OP_DOUBLE: | |
8640 | case OP_DECFLOAT: | |
8641 | case OP_LAST: | |
8642 | case OP_COMPLEX: | |
8643 | case OP_STRING: | |
8644 | case OP_BITSTRING: | |
8645 | case OP_ARRAY: | |
8646 | case OP_TYPE: | |
8647 | case OP_NAME: | |
8648 | case OP_OBJC_NSSTRING: | |
8649 | ||
8650 | case UNOP_NEG: | |
8651 | case UNOP_LOGICAL_NOT: | |
8652 | case UNOP_COMPLEMENT: | |
8653 | case UNOP_ADDR: | |
8654 | case UNOP_HIGH: | |
4a64f543 MS |
8655 | /* Unary, binary and ternary operators: We have to check |
8656 | their operands. If they are constant, then so is the | |
8657 | result of that operation. For instance, if A and B are | |
8658 | determined to be constants, then so is "A + B". | |
8659 | ||
8660 | UNOP_IND is one exception to the rule above, because the | |
8661 | value of *ADDR is not necessarily a constant, even when | |
8662 | ADDR is. */ | |
65d79d4b SDJ |
8663 | break; |
8664 | ||
8665 | case OP_VAR_VALUE: | |
8666 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8667 | |
65d79d4b | 8668 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8669 | possible that a buggy compiler could mark a variable as |
8670 | constant even when it is not, and TYPE_CONST would return | |
8671 | true in this case, while SYMBOL_CLASS wouldn't. | |
8672 | ||
8673 | We also have to check for function symbols because they | |
8674 | are always constant. */ | |
65d79d4b SDJ |
8675 | { |
8676 | struct symbol *s = exp->elts[i + 2].symbol; | |
8677 | ||
8678 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8679 | && SYMBOL_CLASS (s) != LOC_CONST | |
8680 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8681 | return 0; | |
8682 | break; | |
8683 | } | |
8684 | ||
8685 | /* The default action is to return 0 because we are using | |
8686 | the optimistic approach here: If we don't know something, | |
8687 | then it is not a constant. */ | |
8688 | default: | |
8689 | return 0; | |
8690 | } | |
8691 | } | |
8692 | ||
8693 | return 1; | |
8694 | } | |
8695 | ||
3a5c3e22 PA |
8696 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
8697 | ||
8698 | static void | |
8699 | dtor_watchpoint (struct breakpoint *self) | |
8700 | { | |
8701 | struct watchpoint *w = (struct watchpoint *) self; | |
8702 | ||
8703 | xfree (w->cond_exp); | |
8704 | xfree (w->exp); | |
8705 | xfree (w->exp_string); | |
8706 | xfree (w->exp_string_reparse); | |
8707 | value_free (w->val); | |
8708 | ||
8709 | base_breakpoint_ops.dtor (self); | |
8710 | } | |
8711 | ||
348d480f PA |
8712 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
8713 | ||
8714 | static void | |
8715 | re_set_watchpoint (struct breakpoint *b) | |
8716 | { | |
3a5c3e22 PA |
8717 | struct watchpoint *w = (struct watchpoint *) b; |
8718 | ||
348d480f PA |
8719 | /* Watchpoint can be either on expression using entirely global |
8720 | variables, or it can be on local variables. | |
8721 | ||
8722 | Watchpoints of the first kind are never auto-deleted, and even | |
8723 | persist across program restarts. Since they can use variables | |
8724 | from shared libraries, we need to reparse expression as libraries | |
8725 | are loaded and unloaded. | |
8726 | ||
8727 | Watchpoints on local variables can also change meaning as result | |
8728 | of solib event. For example, if a watchpoint uses both a local | |
8729 | and a global variables in expression, it's a local watchpoint, | |
8730 | but unloading of a shared library will make the expression | |
8731 | invalid. This is not a very common use case, but we still | |
8732 | re-evaluate expression, to avoid surprises to the user. | |
8733 | ||
8734 | Note that for local watchpoints, we re-evaluate it only if | |
8735 | watchpoints frame id is still valid. If it's not, it means the | |
8736 | watchpoint is out of scope and will be deleted soon. In fact, | |
8737 | I'm not sure we'll ever be called in this case. | |
8738 | ||
8739 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 8740 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 8741 | |
3a5c3e22 PA |
8742 | Don't do anything about disabled watchpoints, since they will be |
8743 | reevaluated again when enabled. */ | |
8744 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
8745 | } |
8746 | ||
77b06cd7 TJB |
8747 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8748 | ||
8749 | static int | |
8750 | insert_watchpoint (struct bp_location *bl) | |
8751 | { | |
3a5c3e22 PA |
8752 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8753 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8754 | |
8755 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8756 | w->cond_exp); |
77b06cd7 TJB |
8757 | } |
8758 | ||
8759 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8760 | ||
8761 | static int | |
8762 | remove_watchpoint (struct bp_location *bl) | |
8763 | { | |
3a5c3e22 PA |
8764 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8765 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8766 | |
8767 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8768 | w->cond_exp); |
e09342b5 TJB |
8769 | } |
8770 | ||
e09342b5 | 8771 | static int |
348d480f PA |
8772 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
8773 | struct address_space *aspace, CORE_ADDR bp_addr) | |
e09342b5 | 8774 | { |
348d480f | 8775 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 8776 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 8777 | |
348d480f PA |
8778 | /* Continuable hardware watchpoints are treated as non-existent if the |
8779 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
8780 | some data address). Otherwise gdb won't stop on a break instruction | |
8781 | in the code (not from a breakpoint) when a hardware watchpoint has | |
8782 | been defined. Also skip watchpoints which we know did not trigger | |
8783 | (did not match the data address). */ | |
8784 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 8785 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 8786 | return 0; |
9c06b0b4 | 8787 | |
348d480f | 8788 | return 1; |
9c06b0b4 TJB |
8789 | } |
8790 | ||
348d480f PA |
8791 | static void |
8792 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 8793 | { |
348d480f | 8794 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 8795 | |
348d480f | 8796 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
8797 | } |
8798 | ||
8799 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 8800 | hardware watchpoints. */ |
9c06b0b4 TJB |
8801 | |
8802 | static int | |
348d480f | 8803 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 8804 | { |
3a5c3e22 PA |
8805 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8806 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
8807 | |
8808 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
8809 | } |
8810 | ||
8811 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 8812 | hardware watchpoints. */ |
9c06b0b4 TJB |
8813 | |
8814 | static int | |
348d480f | 8815 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 8816 | { |
efa80663 PA |
8817 | /* Read and access watchpoints only work with hardware support. */ |
8818 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
8819 | } |
8820 | ||
9c06b0b4 | 8821 | static enum print_stop_action |
348d480f | 8822 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 8823 | { |
348d480f PA |
8824 | struct cleanup *old_chain; |
8825 | struct breakpoint *b; | |
8826 | const struct bp_location *bl; | |
8827 | struct ui_stream *stb; | |
8828 | enum print_stop_action result; | |
3a5c3e22 | 8829 | struct watchpoint *w; |
79a45e25 | 8830 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8831 | |
8832 | gdb_assert (bs->bp_location_at != NULL); | |
8833 | ||
8834 | bl = bs->bp_location_at; | |
8835 | b = bs->breakpoint_at; | |
3a5c3e22 | 8836 | w = (struct watchpoint *) b; |
348d480f PA |
8837 | |
8838 | stb = ui_out_stream_new (uiout); | |
8839 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
9c06b0b4 TJB |
8840 | |
8841 | switch (b->type) | |
8842 | { | |
348d480f | 8843 | case bp_watchpoint: |
9c06b0b4 TJB |
8844 | case bp_hardware_watchpoint: |
8845 | annotate_watchpoint (b->number); | |
8846 | if (ui_out_is_mi_like_p (uiout)) | |
8847 | ui_out_field_string | |
8848 | (uiout, "reason", | |
8849 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
8850 | mention (b); |
8851 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8852 | ui_out_text (uiout, "\nOld value = "); | |
8853 | watchpoint_value_print (bs->old_val, stb->stream); | |
8854 | ui_out_field_stream (uiout, "old", stb); | |
8855 | ui_out_text (uiout, "\nNew value = "); | |
3a5c3e22 | 8856 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8857 | ui_out_field_stream (uiout, "new", stb); |
8858 | ui_out_text (uiout, "\n"); | |
8859 | /* More than one watchpoint may have been triggered. */ | |
8860 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8861 | break; |
8862 | ||
8863 | case bp_read_watchpoint: | |
8864 | if (ui_out_is_mi_like_p (uiout)) | |
8865 | ui_out_field_string | |
8866 | (uiout, "reason", | |
8867 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
8868 | mention (b); |
8869 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8870 | ui_out_text (uiout, "\nValue = "); | |
3a5c3e22 | 8871 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8872 | ui_out_field_stream (uiout, "value", stb); |
8873 | ui_out_text (uiout, "\n"); | |
8874 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8875 | break; |
8876 | ||
8877 | case bp_access_watchpoint: | |
348d480f PA |
8878 | if (bs->old_val != NULL) |
8879 | { | |
8880 | annotate_watchpoint (b->number); | |
8881 | if (ui_out_is_mi_like_p (uiout)) | |
8882 | ui_out_field_string | |
8883 | (uiout, "reason", | |
8884 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8885 | mention (b); | |
8886 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8887 | ui_out_text (uiout, "\nOld value = "); | |
8888 | watchpoint_value_print (bs->old_val, stb->stream); | |
8889 | ui_out_field_stream (uiout, "old", stb); | |
8890 | ui_out_text (uiout, "\nNew value = "); | |
8891 | } | |
8892 | else | |
8893 | { | |
8894 | mention (b); | |
8895 | if (ui_out_is_mi_like_p (uiout)) | |
8896 | ui_out_field_string | |
8897 | (uiout, "reason", | |
8898 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8899 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8900 | ui_out_text (uiout, "\nValue = "); | |
8901 | } | |
3a5c3e22 | 8902 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8903 | ui_out_field_stream (uiout, "new", stb); |
8904 | ui_out_text (uiout, "\n"); | |
8905 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8906 | break; |
8907 | default: | |
348d480f | 8908 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
8909 | } |
8910 | ||
348d480f PA |
8911 | do_cleanups (old_chain); |
8912 | return result; | |
8913 | } | |
8914 | ||
8915 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
8916 | watchpoints. */ | |
8917 | ||
8918 | static void | |
8919 | print_mention_watchpoint (struct breakpoint *b) | |
8920 | { | |
8921 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 8922 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 8923 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8924 | |
8925 | switch (b->type) | |
8926 | { | |
8927 | case bp_watchpoint: | |
8928 | ui_out_text (uiout, "Watchpoint "); | |
8929 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8930 | break; | |
8931 | case bp_hardware_watchpoint: | |
8932 | ui_out_text (uiout, "Hardware watchpoint "); | |
8933 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8934 | break; | |
8935 | case bp_read_watchpoint: | |
8936 | ui_out_text (uiout, "Hardware read watchpoint "); | |
8937 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
8938 | break; | |
8939 | case bp_access_watchpoint: | |
8940 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
8941 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
8942 | break; | |
8943 | default: | |
8944 | internal_error (__FILE__, __LINE__, | |
8945 | _("Invalid hardware watchpoint type.")); | |
8946 | } | |
8947 | ||
8948 | ui_out_field_int (uiout, "number", b->number); | |
8949 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 8950 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
8951 | do_cleanups (ui_out_chain); |
8952 | } | |
8953 | ||
8954 | /* Implement the "print_recreate" breakpoint_ops method for | |
8955 | watchpoints. */ | |
8956 | ||
8957 | static void | |
8958 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
8959 | { | |
3a5c3e22 PA |
8960 | struct watchpoint *w = (struct watchpoint *) b; |
8961 | ||
348d480f PA |
8962 | switch (b->type) |
8963 | { | |
8964 | case bp_watchpoint: | |
8965 | case bp_hardware_watchpoint: | |
8966 | fprintf_unfiltered (fp, "watch"); | |
8967 | break; | |
8968 | case bp_read_watchpoint: | |
8969 | fprintf_unfiltered (fp, "rwatch"); | |
8970 | break; | |
8971 | case bp_access_watchpoint: | |
8972 | fprintf_unfiltered (fp, "awatch"); | |
8973 | break; | |
8974 | default: | |
8975 | internal_error (__FILE__, __LINE__, | |
8976 | _("Invalid watchpoint type.")); | |
8977 | } | |
8978 | ||
3a5c3e22 | 8979 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 8980 | print_recreate_thread (b, fp); |
348d480f PA |
8981 | } |
8982 | ||
8983 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
8984 | ||
2060206e | 8985 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
8986 | |
8987 | /* Implement the "insert" breakpoint_ops method for | |
8988 | masked hardware watchpoints. */ | |
8989 | ||
8990 | static int | |
8991 | insert_masked_watchpoint (struct bp_location *bl) | |
8992 | { | |
3a5c3e22 PA |
8993 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8994 | ||
8995 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
8996 | bl->watchpoint_type); |
8997 | } | |
8998 | ||
8999 | /* Implement the "remove" breakpoint_ops method for | |
9000 | masked hardware watchpoints. */ | |
9001 | ||
9002 | static int | |
9003 | remove_masked_watchpoint (struct bp_location *bl) | |
9004 | { | |
3a5c3e22 PA |
9005 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9006 | ||
9007 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
9008 | bl->watchpoint_type); |
9009 | } | |
9010 | ||
9011 | /* Implement the "resources_needed" breakpoint_ops method for | |
9012 | masked hardware watchpoints. */ | |
9013 | ||
9014 | static int | |
9015 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
9016 | { | |
3a5c3e22 PA |
9017 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9018 | ||
9019 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
9020 | } |
9021 | ||
9022 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
9023 | masked hardware watchpoints. */ | |
9024 | ||
9025 | static int | |
9026 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
9027 | { | |
9028 | return 0; | |
9029 | } | |
9030 | ||
9031 | /* Implement the "print_it" breakpoint_ops method for | |
9032 | masked hardware watchpoints. */ | |
9033 | ||
9034 | static enum print_stop_action | |
9035 | print_it_masked_watchpoint (bpstat bs) | |
9036 | { | |
9037 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 9038 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9039 | |
9040 | /* Masked watchpoints have only one location. */ | |
9041 | gdb_assert (b->loc && b->loc->next == NULL); | |
9042 | ||
9043 | switch (b->type) | |
9044 | { | |
9045 | case bp_hardware_watchpoint: | |
9046 | annotate_watchpoint (b->number); | |
9047 | if (ui_out_is_mi_like_p (uiout)) | |
9048 | ui_out_field_string | |
9049 | (uiout, "reason", | |
9050 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
9051 | break; | |
9052 | ||
9053 | case bp_read_watchpoint: | |
9054 | if (ui_out_is_mi_like_p (uiout)) | |
9055 | ui_out_field_string | |
9056 | (uiout, "reason", | |
9057 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
9058 | break; | |
9059 | ||
9060 | case bp_access_watchpoint: | |
9061 | if (ui_out_is_mi_like_p (uiout)) | |
9062 | ui_out_field_string | |
9063 | (uiout, "reason", | |
9064 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
9065 | break; | |
9066 | default: | |
9067 | internal_error (__FILE__, __LINE__, | |
9068 | _("Invalid hardware watchpoint type.")); | |
9069 | } | |
9070 | ||
9071 | mention (b); | |
9c06b0b4 TJB |
9072 | ui_out_text (uiout, _("\n\ |
9073 | Check the underlying instruction at PC for the memory\n\ | |
9074 | address and value which triggered this watchpoint.\n")); | |
9075 | ui_out_text (uiout, "\n"); | |
9076 | ||
9077 | /* More than one watchpoint may have been triggered. */ | |
9078 | return PRINT_UNKNOWN; | |
9079 | } | |
9080 | ||
9081 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9082 | masked hardware watchpoints. */ | |
9083 | ||
9084 | static void | |
9085 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
9086 | struct ui_out *uiout) | |
9087 | { | |
3a5c3e22 PA |
9088 | struct watchpoint *w = (struct watchpoint *) b; |
9089 | ||
9c06b0b4 TJB |
9090 | /* Masked watchpoints have only one location. */ |
9091 | gdb_assert (b->loc && b->loc->next == NULL); | |
9092 | ||
9093 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 9094 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
9095 | ui_out_text (uiout, "\n"); |
9096 | } | |
9097 | ||
9098 | /* Implement the "print_mention" breakpoint_ops method for | |
9099 | masked hardware watchpoints. */ | |
9100 | ||
9101 | static void | |
9102 | print_mention_masked_watchpoint (struct breakpoint *b) | |
9103 | { | |
3a5c3e22 | 9104 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 9105 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
9106 | struct cleanup *ui_out_chain; |
9107 | ||
9108 | switch (b->type) | |
9109 | { | |
9110 | case bp_hardware_watchpoint: | |
9111 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
9112 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9113 | break; | |
9114 | case bp_read_watchpoint: | |
9115 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
9116 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
9117 | break; | |
9118 | case bp_access_watchpoint: | |
9119 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
9120 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
9121 | break; | |
9122 | default: | |
9123 | internal_error (__FILE__, __LINE__, | |
9124 | _("Invalid hardware watchpoint type.")); | |
9125 | } | |
9126 | ||
9127 | ui_out_field_int (uiout, "number", b->number); | |
9128 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 9129 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
9130 | do_cleanups (ui_out_chain); |
9131 | } | |
9132 | ||
9133 | /* Implement the "print_recreate" breakpoint_ops method for | |
9134 | masked hardware watchpoints. */ | |
9135 | ||
9136 | static void | |
9137 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
9138 | { | |
3a5c3e22 | 9139 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
9140 | char tmp[40]; |
9141 | ||
9142 | switch (b->type) | |
9143 | { | |
9144 | case bp_hardware_watchpoint: | |
9145 | fprintf_unfiltered (fp, "watch"); | |
9146 | break; | |
9147 | case bp_read_watchpoint: | |
9148 | fprintf_unfiltered (fp, "rwatch"); | |
9149 | break; | |
9150 | case bp_access_watchpoint: | |
9151 | fprintf_unfiltered (fp, "awatch"); | |
9152 | break; | |
9153 | default: | |
9154 | internal_error (__FILE__, __LINE__, | |
9155 | _("Invalid hardware watchpoint type.")); | |
9156 | } | |
9157 | ||
3a5c3e22 PA |
9158 | sprintf_vma (tmp, w->hw_wp_mask); |
9159 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 9160 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
9161 | } |
9162 | ||
9163 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
9164 | ||
2060206e | 9165 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
9166 | |
9167 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
9168 | ||
9169 | static int | |
9170 | is_masked_watchpoint (const struct breakpoint *b) | |
9171 | { | |
9172 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
9173 | } | |
9174 | ||
53a5351d JM |
9175 | /* accessflag: hw_write: watch write, |
9176 | hw_read: watch read, | |
9177 | hw_access: watch access (read or write) */ | |
c906108c | 9178 | static void |
84f4c1fe PM |
9179 | watch_command_1 (char *arg, int accessflag, int from_tty, |
9180 | int just_location, int internal) | |
c906108c | 9181 | { |
a9634178 | 9182 | volatile struct gdb_exception e; |
d983da9c | 9183 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 9184 | struct expression *exp; |
60e1c644 | 9185 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 9186 | struct value *val, *mark, *result; |
c906108c | 9187 | struct frame_info *frame; |
c906108c SS |
9188 | char *exp_start = NULL; |
9189 | char *exp_end = NULL; | |
9c06b0b4 TJB |
9190 | char *tok, *end_tok; |
9191 | int toklen = -1; | |
c906108c SS |
9192 | char *cond_start = NULL; |
9193 | char *cond_end = NULL; | |
c906108c | 9194 | enum bptype bp_type; |
37e4754d | 9195 | int thread = -1; |
0cf6dd15 | 9196 | int pc = 0; |
9c06b0b4 TJB |
9197 | /* Flag to indicate whether we are going to use masks for |
9198 | the hardware watchpoint. */ | |
9199 | int use_mask = 0; | |
9200 | CORE_ADDR mask = 0; | |
3a5c3e22 | 9201 | struct watchpoint *w; |
c906108c | 9202 | |
37e4754d LM |
9203 | /* Make sure that we actually have parameters to parse. */ |
9204 | if (arg != NULL && arg[0] != '\0') | |
9205 | { | |
9c06b0b4 | 9206 | char *value_start; |
37e4754d | 9207 | |
9c06b0b4 TJB |
9208 | /* Look for "parameter value" pairs at the end |
9209 | of the arguments string. */ | |
9210 | for (tok = arg + strlen (arg) - 1; tok > arg; tok--) | |
9211 | { | |
9212 | /* Skip whitespace at the end of the argument list. */ | |
9213 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9214 | tok--; | |
9215 | ||
9216 | /* Find the beginning of the last token. | |
9217 | This is the value of the parameter. */ | |
9218 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9219 | tok--; | |
9220 | value_start = tok + 1; | |
9221 | ||
9222 | /* Skip whitespace. */ | |
9223 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9224 | tok--; | |
9225 | ||
9226 | end_tok = tok; | |
9227 | ||
9228 | /* Find the beginning of the second to last token. | |
9229 | This is the parameter itself. */ | |
9230 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9231 | tok--; | |
9232 | tok++; | |
9233 | toklen = end_tok - tok + 1; | |
9234 | ||
9235 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
9236 | { | |
9237 | /* At this point we've found a "thread" token, which means | |
9238 | the user is trying to set a watchpoint that triggers | |
9239 | only in a specific thread. */ | |
9240 | char *endp; | |
37e4754d | 9241 | |
9c06b0b4 TJB |
9242 | if (thread != -1) |
9243 | error(_("You can specify only one thread.")); | |
37e4754d | 9244 | |
9c06b0b4 TJB |
9245 | /* Extract the thread ID from the next token. */ |
9246 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 9247 | |
9c06b0b4 TJB |
9248 | /* Check if the user provided a valid numeric value for the |
9249 | thread ID. */ | |
9250 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
9251 | error (_("Invalid thread ID specification %s."), value_start); | |
9252 | ||
9253 | /* Check if the thread actually exists. */ | |
9254 | if (!valid_thread_id (thread)) | |
9255 | error (_("Unknown thread %d."), thread); | |
9256 | } | |
9257 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
9258 | { | |
9259 | /* We've found a "mask" token, which means the user wants to | |
9260 | create a hardware watchpoint that is going to have the mask | |
9261 | facility. */ | |
9262 | struct value *mask_value, *mark; | |
37e4754d | 9263 | |
9c06b0b4 TJB |
9264 | if (use_mask) |
9265 | error(_("You can specify only one mask.")); | |
37e4754d | 9266 | |
9c06b0b4 | 9267 | use_mask = just_location = 1; |
37e4754d | 9268 | |
9c06b0b4 TJB |
9269 | mark = value_mark (); |
9270 | mask_value = parse_to_comma_and_eval (&value_start); | |
9271 | mask = value_as_address (mask_value); | |
9272 | value_free_to_mark (mark); | |
9273 | } | |
9274 | else | |
9275 | /* We didn't recognize what we found. We should stop here. */ | |
9276 | break; | |
37e4754d | 9277 | |
9c06b0b4 TJB |
9278 | /* Truncate the string and get rid of the "parameter value" pair before |
9279 | the arguments string is parsed by the parse_exp_1 function. */ | |
9280 | *tok = '\0'; | |
9281 | } | |
37e4754d LM |
9282 | } |
9283 | ||
9284 | /* Parse the rest of the arguments. */ | |
c906108c SS |
9285 | innermost_block = NULL; |
9286 | exp_start = arg; | |
9287 | exp = parse_exp_1 (&arg, 0, 0); | |
9288 | exp_end = arg; | |
fa8a61dc TT |
9289 | /* Remove trailing whitespace from the expression before saving it. |
9290 | This makes the eventual display of the expression string a bit | |
9291 | prettier. */ | |
9292 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
9293 | --exp_end; | |
9294 | ||
65d79d4b SDJ |
9295 | /* Checking if the expression is not constant. */ |
9296 | if (watchpoint_exp_is_const (exp)) | |
9297 | { | |
9298 | int len; | |
9299 | ||
9300 | len = exp_end - exp_start; | |
9301 | while (len > 0 && isspace (exp_start[len - 1])) | |
9302 | len--; | |
9303 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
9304 | } | |
9305 | ||
c906108c SS |
9306 | exp_valid_block = innermost_block; |
9307 | mark = value_mark (); | |
a1442452 | 9308 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
9309 | |
9310 | if (just_location) | |
9311 | { | |
9c06b0b4 TJB |
9312 | int ret; |
9313 | ||
06a64a0b | 9314 | exp_valid_block = NULL; |
a1442452 | 9315 | val = value_addr (result); |
06a64a0b TT |
9316 | release_value (val); |
9317 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
9318 | |
9319 | if (use_mask) | |
9320 | { | |
9321 | ret = target_masked_watch_num_registers (value_as_address (val), | |
9322 | mask); | |
9323 | if (ret == -1) | |
9324 | error (_("This target does not support masked watchpoints.")); | |
9325 | else if (ret == -2) | |
9326 | error (_("Invalid mask or memory region.")); | |
9327 | } | |
06a64a0b TT |
9328 | } |
9329 | else if (val != NULL) | |
fa4727a6 | 9330 | release_value (val); |
c906108c | 9331 | |
e9cafbcc TT |
9332 | tok = skip_spaces (arg); |
9333 | end_tok = skip_to_space (tok); | |
c906108c SS |
9334 | |
9335 | toklen = end_tok - tok; | |
9336 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
9337 | { | |
2d134ed3 PA |
9338 | struct expression *cond; |
9339 | ||
60e1c644 | 9340 | innermost_block = NULL; |
c906108c SS |
9341 | tok = cond_start = end_tok + 1; |
9342 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
9343 | |
9344 | /* The watchpoint expression may not be local, but the condition | |
9345 | may still be. E.g.: `watch global if local > 0'. */ | |
9346 | cond_exp_valid_block = innermost_block; | |
9347 | ||
2d134ed3 | 9348 | xfree (cond); |
c906108c SS |
9349 | cond_end = tok; |
9350 | } | |
9351 | if (*tok) | |
8a3fe4f8 | 9352 | error (_("Junk at end of command.")); |
c906108c | 9353 | |
53a5351d | 9354 | if (accessflag == hw_read) |
c5aa993b | 9355 | bp_type = bp_read_watchpoint; |
53a5351d | 9356 | else if (accessflag == hw_access) |
c5aa993b JM |
9357 | bp_type = bp_access_watchpoint; |
9358 | else | |
9359 | bp_type = bp_hardware_watchpoint; | |
c906108c | 9360 | |
d983da9c | 9361 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
9362 | |
9363 | /* If the expression is "local", then set up a "watchpoint scope" | |
9364 | breakpoint at the point where we've left the scope of the watchpoint | |
9365 | expression. Create the scope breakpoint before the watchpoint, so | |
9366 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 9367 | if (exp_valid_block && frame) |
d983da9c | 9368 | { |
edb3359d DJ |
9369 | if (frame_id_p (frame_unwind_caller_id (frame))) |
9370 | { | |
9371 | scope_breakpoint | |
a6d9a66e UW |
9372 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
9373 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
9374 | bp_watchpoint_scope, |
9375 | &momentary_breakpoint_ops); | |
d983da9c | 9376 | |
edb3359d | 9377 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 9378 | |
edb3359d DJ |
9379 | /* Automatically delete the breakpoint when it hits. */ |
9380 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 9381 | |
edb3359d DJ |
9382 | /* Only break in the proper frame (help with recursion). */ |
9383 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 9384 | |
edb3359d | 9385 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
9386 | scope_breakpoint->loc->gdbarch |
9387 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
9388 | scope_breakpoint->loc->requested_address |
9389 | = frame_unwind_caller_pc (frame); | |
9390 | scope_breakpoint->loc->address | |
a6d9a66e UW |
9391 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
9392 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
9393 | scope_breakpoint->type); |
9394 | } | |
d983da9c DJ |
9395 | } |
9396 | ||
c906108c | 9397 | /* Now set up the breakpoint. */ |
3a5c3e22 PA |
9398 | |
9399 | w = XCNEW (struct watchpoint); | |
9400 | b = &w->base; | |
348d480f | 9401 | if (use_mask) |
3a5c3e22 PA |
9402 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9403 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 9404 | else |
3a5c3e22 PA |
9405 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9406 | &watchpoint_breakpoint_ops); | |
37e4754d | 9407 | b->thread = thread; |
b5de0fa7 | 9408 | b->disposition = disp_donttouch; |
348d480f | 9409 | b->pspace = current_program_space; |
3a5c3e22 PA |
9410 | w->exp = exp; |
9411 | w->exp_valid_block = exp_valid_block; | |
9412 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
9413 | if (just_location) |
9414 | { | |
9415 | struct type *t = value_type (val); | |
9416 | CORE_ADDR addr = value_as_address (val); | |
9417 | char *name; | |
9418 | ||
9419 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
9420 | name = type_to_string (t); | |
9421 | ||
3a5c3e22 | 9422 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 9423 | core_addr_to_string (addr)); |
06a64a0b TT |
9424 | xfree (name); |
9425 | ||
3a5c3e22 | 9426 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
9427 | (int) (exp_end - exp_start), exp_start); |
9428 | ||
06a64a0b TT |
9429 | /* The above expression is in C. */ |
9430 | b->language = language_c; | |
9431 | } | |
9432 | else | |
3a5c3e22 | 9433 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
9434 | |
9435 | if (use_mask) | |
9436 | { | |
3a5c3e22 | 9437 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
9438 | } |
9439 | else | |
9440 | { | |
3a5c3e22 PA |
9441 | w->val = val; |
9442 | w->val_valid = 1; | |
9c06b0b4 | 9443 | } |
77b06cd7 | 9444 | |
c906108c SS |
9445 | if (cond_start) |
9446 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
9447 | else | |
9448 | b->cond_string = 0; | |
c5aa993b | 9449 | |
c906108c | 9450 | if (frame) |
f6bc2008 | 9451 | { |
3a5c3e22 PA |
9452 | w->watchpoint_frame = get_frame_id (frame); |
9453 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 9454 | } |
c906108c | 9455 | else |
f6bc2008 | 9456 | { |
3a5c3e22 PA |
9457 | w->watchpoint_frame = null_frame_id; |
9458 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 9459 | } |
c906108c | 9460 | |
d983da9c | 9461 | if (scope_breakpoint != NULL) |
c906108c | 9462 | { |
d983da9c DJ |
9463 | /* The scope breakpoint is related to the watchpoint. We will |
9464 | need to act on them together. */ | |
9465 | b->related_breakpoint = scope_breakpoint; | |
9466 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 9467 | } |
d983da9c | 9468 | |
06a64a0b TT |
9469 | if (!just_location) |
9470 | value_free_to_mark (mark); | |
2d134ed3 | 9471 | |
a9634178 TJB |
9472 | TRY_CATCH (e, RETURN_MASK_ALL) |
9473 | { | |
9474 | /* Finally update the new watchpoint. This creates the locations | |
9475 | that should be inserted. */ | |
3a5c3e22 | 9476 | update_watchpoint (w, 1); |
a9634178 TJB |
9477 | } |
9478 | if (e.reason < 0) | |
9479 | { | |
9480 | delete_breakpoint (b); | |
9481 | throw_exception (e); | |
9482 | } | |
9483 | ||
3ea46bff | 9484 | install_breakpoint (internal, b, 1); |
c906108c SS |
9485 | } |
9486 | ||
e09342b5 | 9487 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 9488 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 9489 | |
c906108c | 9490 | static int |
a9634178 | 9491 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
9492 | { |
9493 | int found_memory_cnt = 0; | |
2e70b7b9 | 9494 | struct value *head = v; |
c906108c SS |
9495 | |
9496 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 9497 | if (!can_use_hw_watchpoints) |
c906108c | 9498 | return 0; |
c5aa993b | 9499 | |
5c44784c JM |
9500 | /* Make sure that the value of the expression depends only upon |
9501 | memory contents, and values computed from them within GDB. If we | |
9502 | find any register references or function calls, we can't use a | |
9503 | hardware watchpoint. | |
9504 | ||
9505 | The idea here is that evaluating an expression generates a series | |
9506 | of values, one holding the value of every subexpression. (The | |
9507 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
9508 | a*b+c.) GDB's values hold almost enough information to establish | |
9509 | the criteria given above --- they identify memory lvalues, | |
9510 | register lvalues, computed values, etcetera. So we can evaluate | |
9511 | the expression, and then scan the chain of values that leaves | |
9512 | behind to decide whether we can detect any possible change to the | |
9513 | expression's final value using only hardware watchpoints. | |
9514 | ||
9515 | However, I don't think that the values returned by inferior | |
9516 | function calls are special in any way. So this function may not | |
9517 | notice that an expression involving an inferior function call | |
9518 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 9519 | for (; v; v = value_next (v)) |
c906108c | 9520 | { |
5c44784c | 9521 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 9522 | { |
8464be76 DJ |
9523 | if (v != head && value_lazy (v)) |
9524 | /* A lazy memory lvalue in the chain is one that GDB never | |
9525 | needed to fetch; we either just used its address (e.g., | |
9526 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
9527 | in `a,b'). This doesn't apply to HEAD; if that is | |
9528 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 9529 | ; |
53a5351d | 9530 | else |
5c44784c JM |
9531 | { |
9532 | /* Ahh, memory we actually used! Check if we can cover | |
9533 | it with hardware watchpoints. */ | |
df407dfe | 9534 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
9535 | |
9536 | /* We only watch structs and arrays if user asked for it | |
9537 | explicitly, never if they just happen to appear in a | |
9538 | middle of some value chain. */ | |
9539 | if (v == head | |
9540 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
9541 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
9542 | { | |
42ae5230 | 9543 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
9544 | int len; |
9545 | int num_regs; | |
9546 | ||
a9634178 | 9547 | len = (target_exact_watchpoints |
e09342b5 TJB |
9548 | && is_scalar_type_recursive (vtype))? |
9549 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 9550 | |
e09342b5 TJB |
9551 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
9552 | if (!num_regs) | |
2e70b7b9 MS |
9553 | return 0; |
9554 | else | |
e09342b5 | 9555 | found_memory_cnt += num_regs; |
2e70b7b9 | 9556 | } |
5c44784c | 9557 | } |
c5aa993b | 9558 | } |
5086187c AC |
9559 | else if (VALUE_LVAL (v) != not_lval |
9560 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 9561 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 9562 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 9563 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
9564 | } |
9565 | ||
9566 | /* The expression itself looks suitable for using a hardware | |
9567 | watchpoint, but give the target machine a chance to reject it. */ | |
9568 | return found_memory_cnt; | |
9569 | } | |
9570 | ||
8b93c638 | 9571 | void |
84f4c1fe | 9572 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9573 | { |
84f4c1fe | 9574 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
9575 | } |
9576 | ||
9577 | /* A helper function that looks for an argument at the start of a | |
9578 | string. The argument must also either be at the end of the string, | |
9579 | or be followed by whitespace. Returns 1 if it finds the argument, | |
9580 | 0 otherwise. If the argument is found, it updates *STR. */ | |
9581 | ||
9582 | static int | |
9583 | check_for_argument (char **str, char *arg, int arg_len) | |
9584 | { | |
9585 | if (strncmp (*str, arg, arg_len) == 0 | |
9586 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
9587 | { | |
9588 | *str += arg_len; | |
9589 | return 1; | |
9590 | } | |
9591 | return 0; | |
9592 | } | |
9593 | ||
9594 | /* A helper function that looks for the "-location" argument and then | |
9595 | calls watch_command_1. */ | |
9596 | ||
9597 | static void | |
9598 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
9599 | { | |
9600 | int just_location = 0; | |
9601 | ||
9602 | if (arg | |
9603 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
9604 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
9605 | { | |
e9cafbcc | 9606 | arg = skip_spaces (arg); |
06a64a0b TT |
9607 | just_location = 1; |
9608 | } | |
9609 | ||
84f4c1fe | 9610 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 9611 | } |
8926118c | 9612 | |
c5aa993b | 9613 | static void |
fba45db2 | 9614 | watch_command (char *arg, int from_tty) |
c906108c | 9615 | { |
06a64a0b | 9616 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
9617 | } |
9618 | ||
8b93c638 | 9619 | void |
84f4c1fe | 9620 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9621 | { |
84f4c1fe | 9622 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 9623 | } |
8926118c | 9624 | |
c5aa993b | 9625 | static void |
fba45db2 | 9626 | rwatch_command (char *arg, int from_tty) |
c906108c | 9627 | { |
06a64a0b | 9628 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
9629 | } |
9630 | ||
8b93c638 | 9631 | void |
84f4c1fe | 9632 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9633 | { |
84f4c1fe | 9634 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 9635 | } |
8926118c | 9636 | |
c5aa993b | 9637 | static void |
fba45db2 | 9638 | awatch_command (char *arg, int from_tty) |
c906108c | 9639 | { |
06a64a0b | 9640 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 9641 | } |
c906108c | 9642 | \f |
c5aa993b | 9643 | |
43ff13b4 | 9644 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
9645 | because it uses the mechanisms of breakpoints. */ |
9646 | ||
bfec99b2 PA |
9647 | struct until_break_command_continuation_args |
9648 | { | |
9649 | struct breakpoint *breakpoint; | |
9650 | struct breakpoint *breakpoint2; | |
186c406b | 9651 | int thread_num; |
bfec99b2 PA |
9652 | }; |
9653 | ||
43ff13b4 | 9654 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 9655 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 9656 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 9657 | command. */ |
c2c6d25f | 9658 | static void |
fa4cd53f | 9659 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 9660 | { |
bfec99b2 PA |
9661 | struct until_break_command_continuation_args *a = arg; |
9662 | ||
9663 | delete_breakpoint (a->breakpoint); | |
9664 | if (a->breakpoint2) | |
9665 | delete_breakpoint (a->breakpoint2); | |
186c406b | 9666 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
9667 | } |
9668 | ||
c906108c | 9669 | void |
ae66c1fc | 9670 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
9671 | { |
9672 | struct symtabs_and_lines sals; | |
9673 | struct symtab_and_line sal; | |
206415a3 | 9674 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 9675 | struct breakpoint *breakpoint; |
f107f563 | 9676 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 9677 | struct cleanup *old_chain; |
186c406b TT |
9678 | int thread; |
9679 | struct thread_info *tp; | |
c906108c SS |
9680 | |
9681 | clear_proceed_status (); | |
9682 | ||
9683 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 9684 | this function. */ |
c5aa993b | 9685 | |
1bfeeb0f JL |
9686 | if (last_displayed_sal_is_valid ()) |
9687 | sals = decode_line_1 (&arg, 1, | |
9688 | get_last_displayed_symtab (), | |
9689 | get_last_displayed_line (), | |
9690 | NULL); | |
c906108c | 9691 | else |
58438ac1 | 9692 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL); |
c5aa993b | 9693 | |
c906108c | 9694 | if (sals.nelts != 1) |
8a3fe4f8 | 9695 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 9696 | |
c906108c | 9697 | sal = sals.sals[0]; |
4a64f543 | 9698 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 9699 | |
c906108c | 9700 | if (*arg) |
8a3fe4f8 | 9701 | error (_("Junk at end of arguments.")); |
c5aa993b | 9702 | |
c906108c | 9703 | resolve_sal_pc (&sal); |
c5aa993b | 9704 | |
ae66c1fc EZ |
9705 | if (anywhere) |
9706 | /* If the user told us to continue until a specified location, | |
9707 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
9708 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9709 | null_frame_id, bp_until); | |
ae66c1fc | 9710 | else |
4a64f543 MS |
9711 | /* Otherwise, specify the selected frame, because we want to stop |
9712 | only at the very same frame. */ | |
a6d9a66e UW |
9713 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9714 | get_stack_frame_id (frame), | |
ae66c1fc | 9715 | bp_until); |
c5aa993b | 9716 | |
f107f563 | 9717 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 9718 | |
186c406b TT |
9719 | tp = inferior_thread (); |
9720 | thread = tp->num; | |
9721 | ||
ae66c1fc EZ |
9722 | /* Keep within the current frame, or in frames called by the current |
9723 | one. */ | |
edb3359d DJ |
9724 | |
9725 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 9726 | { |
edb3359d DJ |
9727 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
9728 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
9729 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
9730 | sal, | |
edb3359d | 9731 | frame_unwind_caller_id (frame), |
f107f563 VP |
9732 | bp_until); |
9733 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
9734 | |
9735 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
9736 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 9737 | } |
c5aa993b | 9738 | |
c906108c | 9739 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 9740 | |
4a64f543 MS |
9741 | /* If we are running asynchronously, and proceed call above has |
9742 | actually managed to start the target, arrange for breakpoints to | |
9743 | be deleted when the target stops. Otherwise, we're already | |
9744 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 9745 | |
8ea051c5 | 9746 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 9747 | { |
bfec99b2 PA |
9748 | struct until_break_command_continuation_args *args; |
9749 | args = xmalloc (sizeof (*args)); | |
f107f563 | 9750 | |
bfec99b2 PA |
9751 | args->breakpoint = breakpoint; |
9752 | args->breakpoint2 = breakpoint2; | |
186c406b | 9753 | args->thread_num = thread; |
f107f563 VP |
9754 | |
9755 | discard_cleanups (old_chain); | |
95e54da7 PA |
9756 | add_continuation (inferior_thread (), |
9757 | until_break_command_continuation, args, | |
604ead4a | 9758 | xfree); |
f107f563 VP |
9759 | } |
9760 | else | |
c5aa993b | 9761 | do_cleanups (old_chain); |
c906108c | 9762 | } |
ae66c1fc | 9763 | |
c906108c SS |
9764 | /* This function attempts to parse an optional "if <cond>" clause |
9765 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 9766 | |
c906108c SS |
9767 | Else, it returns a pointer to the condition string. (It does not |
9768 | attempt to evaluate the string against a particular block.) And, | |
9769 | it updates arg to point to the first character following the parsed | |
4a64f543 | 9770 | if clause in the arg string. */ |
53a5351d | 9771 | |
c906108c | 9772 | static char * |
fba45db2 | 9773 | ep_parse_optional_if_clause (char **arg) |
c906108c | 9774 | { |
c5aa993b JM |
9775 | char *cond_string; |
9776 | ||
9777 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 9778 | return NULL; |
c5aa993b | 9779 | |
4a64f543 | 9780 | /* Skip the "if" keyword. */ |
c906108c | 9781 | (*arg) += 2; |
c5aa993b | 9782 | |
c906108c | 9783 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 9784 | condition string. */ |
e9cafbcc | 9785 | *arg = skip_spaces (*arg); |
c906108c | 9786 | cond_string = *arg; |
c5aa993b | 9787 | |
4a64f543 MS |
9788 | /* Assume that the condition occupies the remainder of the arg |
9789 | string. */ | |
c906108c | 9790 | (*arg) += strlen (cond_string); |
c5aa993b | 9791 | |
c906108c SS |
9792 | return cond_string; |
9793 | } | |
c5aa993b | 9794 | |
c906108c SS |
9795 | /* Commands to deal with catching events, such as signals, exceptions, |
9796 | process start/exit, etc. */ | |
c5aa993b JM |
9797 | |
9798 | typedef enum | |
9799 | { | |
44feb3ce TT |
9800 | catch_fork_temporary, catch_vfork_temporary, |
9801 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
9802 | } |
9803 | catch_fork_kind; | |
9804 | ||
c906108c | 9805 | static void |
cc59ec59 MS |
9806 | catch_fork_command_1 (char *arg, int from_tty, |
9807 | struct cmd_list_element *command) | |
c906108c | 9808 | { |
a6d9a66e | 9809 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 9810 | char *cond_string = NULL; |
44feb3ce TT |
9811 | catch_fork_kind fork_kind; |
9812 | int tempflag; | |
9813 | ||
9814 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
9815 | tempflag = (fork_kind == catch_fork_temporary | |
9816 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 9817 | |
44feb3ce TT |
9818 | if (!arg) |
9819 | arg = ""; | |
e9cafbcc | 9820 | arg = skip_spaces (arg); |
c5aa993b | 9821 | |
c906108c | 9822 | /* The allowed syntax is: |
c5aa993b JM |
9823 | catch [v]fork |
9824 | catch [v]fork if <cond> | |
9825 | ||
4a64f543 | 9826 | First, check if there's an if clause. */ |
c906108c | 9827 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 9828 | |
c906108c | 9829 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9830 | error (_("Junk at end of arguments.")); |
c5aa993b | 9831 | |
c906108c | 9832 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9833 | and enable reporting of such events. */ |
c5aa993b JM |
9834 | switch (fork_kind) |
9835 | { | |
44feb3ce TT |
9836 | case catch_fork_temporary: |
9837 | case catch_fork_permanent: | |
a6d9a66e | 9838 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9839 | &catch_fork_breakpoint_ops); |
c906108c | 9840 | break; |
44feb3ce TT |
9841 | case catch_vfork_temporary: |
9842 | case catch_vfork_permanent: | |
a6d9a66e | 9843 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9844 | &catch_vfork_breakpoint_ops); |
c906108c | 9845 | break; |
c5aa993b | 9846 | default: |
8a3fe4f8 | 9847 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 9848 | break; |
c5aa993b | 9849 | } |
c906108c SS |
9850 | } |
9851 | ||
9852 | static void | |
cc59ec59 MS |
9853 | catch_exec_command_1 (char *arg, int from_tty, |
9854 | struct cmd_list_element *command) | |
c906108c | 9855 | { |
b4d90040 | 9856 | struct exec_catchpoint *c; |
a6d9a66e | 9857 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9858 | int tempflag; |
c5aa993b | 9859 | char *cond_string = NULL; |
c906108c | 9860 | |
44feb3ce TT |
9861 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9862 | ||
9863 | if (!arg) | |
9864 | arg = ""; | |
e9cafbcc | 9865 | arg = skip_spaces (arg); |
c906108c SS |
9866 | |
9867 | /* The allowed syntax is: | |
c5aa993b JM |
9868 | catch exec |
9869 | catch exec if <cond> | |
c906108c | 9870 | |
4a64f543 | 9871 | First, check if there's an if clause. */ |
c906108c SS |
9872 | cond_string = ep_parse_optional_if_clause (&arg); |
9873 | ||
9874 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9875 | error (_("Junk at end of arguments.")); |
c906108c | 9876 | |
b4d90040 PA |
9877 | c = XNEW (struct exec_catchpoint); |
9878 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
9879 | &catch_exec_breakpoint_ops); | |
9880 | c->exec_pathname = NULL; | |
9881 | ||
3ea46bff | 9882 | install_breakpoint (0, &c->base, 1); |
c906108c | 9883 | } |
c5aa993b | 9884 | |
3086aeae | 9885 | static enum print_stop_action |
348d480f | 9886 | print_it_exception_catchpoint (bpstat bs) |
3086aeae | 9887 | { |
79a45e25 | 9888 | struct ui_out *uiout = current_uiout; |
348d480f | 9889 | struct breakpoint *b = bs->breakpoint_at; |
ade92717 | 9890 | int bp_temp, bp_throw; |
3086aeae | 9891 | |
ade92717 | 9892 | annotate_catchpoint (b->number); |
3086aeae | 9893 | |
ade92717 AR |
9894 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9895 | if (b->loc->address != b->loc->requested_address) | |
9896 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9897 | b->loc->address, | |
9898 | b->number, 1); | |
df2b6d2d | 9899 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9900 | ui_out_text (uiout, |
9901 | bp_temp ? "Temporary catchpoint " | |
9902 | : "Catchpoint "); | |
9903 | if (!ui_out_is_mi_like_p (uiout)) | |
9904 | ui_out_field_int (uiout, "bkptno", b->number); | |
9905 | ui_out_text (uiout, | |
c0b37c48 AR |
9906 | bp_throw ? " (exception thrown), " |
9907 | : " (exception caught), "); | |
ade92717 AR |
9908 | if (ui_out_is_mi_like_p (uiout)) |
9909 | { | |
9910 | ui_out_field_string (uiout, "reason", | |
9911 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9912 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9913 | ui_out_field_int (uiout, "bkptno", b->number); | |
9914 | } | |
3086aeae DJ |
9915 | return PRINT_SRC_AND_LOC; |
9916 | } | |
9917 | ||
9918 | static void | |
cc59ec59 MS |
9919 | print_one_exception_catchpoint (struct breakpoint *b, |
9920 | struct bp_location **last_loc) | |
3086aeae | 9921 | { |
79a45b7d | 9922 | struct value_print_options opts; |
79a45e25 | 9923 | struct ui_out *uiout = current_uiout; |
cc59ec59 | 9924 | |
79a45b7d TT |
9925 | get_user_print_options (&opts); |
9926 | if (opts.addressprint) | |
3086aeae DJ |
9927 | { |
9928 | annotate_field (4); | |
604133b5 AR |
9929 | if (b->loc == NULL || b->loc->shlib_disabled) |
9930 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9931 | else | |
5af949e3 UW |
9932 | ui_out_field_core_addr (uiout, "addr", |
9933 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9934 | } |
9935 | annotate_field (5); | |
604133b5 | 9936 | if (b->loc) |
a6d9a66e | 9937 | *last_loc = b->loc; |
3086aeae DJ |
9938 | if (strstr (b->addr_string, "throw") != NULL) |
9939 | ui_out_field_string (uiout, "what", "exception throw"); | |
9940 | else | |
9941 | ui_out_field_string (uiout, "what", "exception catch"); | |
9942 | } | |
9943 | ||
9944 | static void | |
9945 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9946 | { | |
79a45e25 | 9947 | struct ui_out *uiout = current_uiout; |
ade92717 AR |
9948 | int bp_temp; |
9949 | int bp_throw; | |
9950 | ||
df2b6d2d | 9951 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9952 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9953 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9954 | : _("Catchpoint ")); | |
9955 | ui_out_field_int (uiout, "bkptno", b->number); | |
9956 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9957 | : _(" (catch)")); | |
3086aeae DJ |
9958 | } |
9959 | ||
6149aea9 PA |
9960 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9961 | catch catchpoints. */ | |
9962 | ||
9963 | static void | |
4a64f543 MS |
9964 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9965 | struct ui_file *fp) | |
6149aea9 PA |
9966 | { |
9967 | int bp_temp; | |
9968 | int bp_throw; | |
9969 | ||
9970 | bp_temp = b->disposition == disp_del; | |
9971 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9972 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9973 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
d9b3f62e | 9974 | print_recreate_thread (b, fp); |
6149aea9 PA |
9975 | } |
9976 | ||
2060206e | 9977 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; |
3086aeae DJ |
9978 | |
9979 | static int | |
9980 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9981 | enum exception_event_kind ex_event, int from_tty) | |
9982 | { | |
604133b5 AR |
9983 | char *trigger_func_name; |
9984 | ||
3086aeae | 9985 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9986 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9987 | else |
604133b5 | 9988 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9989 | |
8cdf0e15 VP |
9990 | create_breakpoint (get_current_arch (), |
9991 | trigger_func_name, cond_string, -1, | |
9992 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9993 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9994 | 0, |
9995 | AUTO_BOOLEAN_TRUE /* pending */, | |
9996 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9997 | 1 /* enabled */, |
9998 | 0 /* internal */); | |
3086aeae | 9999 | |
3086aeae DJ |
10000 | return 1; |
10001 | } | |
10002 | ||
4a64f543 | 10003 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
10004 | |
10005 | static void | |
fba45db2 KB |
10006 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
10007 | int tempflag, int from_tty) | |
c906108c | 10008 | { |
c5aa993b | 10009 | char *cond_string = NULL; |
c5aa993b | 10010 | |
44feb3ce TT |
10011 | if (!arg) |
10012 | arg = ""; | |
e9cafbcc | 10013 | arg = skip_spaces (arg); |
c5aa993b | 10014 | |
c906108c SS |
10015 | cond_string = ep_parse_optional_if_clause (&arg); |
10016 | ||
10017 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 10018 | error (_("Junk at end of arguments.")); |
c906108c | 10019 | |
059fb39f PM |
10020 | if (ex_event != EX_EVENT_THROW |
10021 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 10022 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 10023 | |
3086aeae DJ |
10024 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
10025 | return; | |
10026 | ||
8a3fe4f8 | 10027 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
10028 | } |
10029 | ||
44feb3ce TT |
10030 | /* Implementation of "catch catch" command. */ |
10031 | ||
10032 | static void | |
10033 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
10034 | { | |
10035 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 10036 | |
44feb3ce TT |
10037 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
10038 | } | |
10039 | ||
10040 | /* Implementation of "catch throw" command. */ | |
10041 | ||
10042 | static void | |
10043 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
10044 | { | |
10045 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 10046 | |
44feb3ce TT |
10047 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
10048 | } | |
10049 | ||
9ac4176b | 10050 | void |
28010a5d PA |
10051 | init_ada_exception_breakpoint (struct breakpoint *b, |
10052 | struct gdbarch *gdbarch, | |
10053 | struct symtab_and_line sal, | |
10054 | char *addr_string, | |
c0a91b2b | 10055 | const struct breakpoint_ops *ops, |
28010a5d PA |
10056 | int tempflag, |
10057 | int from_tty) | |
f7f9143b | 10058 | { |
f7f9143b JB |
10059 | if (from_tty) |
10060 | { | |
5af949e3 UW |
10061 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
10062 | if (!loc_gdbarch) | |
10063 | loc_gdbarch = gdbarch; | |
10064 | ||
6c95b8df PA |
10065 | describe_other_breakpoints (loc_gdbarch, |
10066 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
10067 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
10068 | version for exception catchpoints, because two catchpoints | |
10069 | used for different exception names will use the same address. | |
10070 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 10071 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 10072 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
10073 | the user what type of catchpoint it is. The above is good |
10074 | enough for now, though. */ | |
10075 | } | |
10076 | ||
28010a5d | 10077 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b JB |
10078 | |
10079 | b->enable_state = bp_enabled; | |
10080 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
f7f9143b JB |
10081 | b->addr_string = addr_string; |
10082 | b->language = language_ada; | |
f7f9143b JB |
10083 | } |
10084 | ||
a96d9b2e SDJ |
10085 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
10086 | filter list, or NULL if no filtering is required. */ | |
10087 | static VEC(int) * | |
10088 | catch_syscall_split_args (char *arg) | |
10089 | { | |
10090 | VEC(int) *result = NULL; | |
29d0bb3d | 10091 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
10092 | |
10093 | while (*arg != '\0') | |
10094 | { | |
10095 | int i, syscall_number; | |
10096 | char *endptr; | |
10097 | char cur_name[128]; | |
10098 | struct syscall s; | |
10099 | ||
10100 | /* Skip whitespace. */ | |
10101 | while (isspace (*arg)) | |
10102 | arg++; | |
10103 | ||
10104 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
10105 | cur_name[i] = arg[i]; | |
10106 | cur_name[i] = '\0'; | |
10107 | arg += i; | |
10108 | ||
10109 | /* Check if the user provided a syscall name or a number. */ | |
10110 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
10111 | if (*endptr == '\0') | |
bccd0dd2 | 10112 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
10113 | else |
10114 | { | |
10115 | /* We have a name. Let's check if it's valid and convert it | |
10116 | to a number. */ | |
10117 | get_syscall_by_name (cur_name, &s); | |
10118 | ||
10119 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
10120 | /* Here we have to issue an error instead of a warning, |
10121 | because GDB cannot do anything useful if there's no | |
10122 | syscall number to be caught. */ | |
a96d9b2e SDJ |
10123 | error (_("Unknown syscall name '%s'."), cur_name); |
10124 | } | |
10125 | ||
10126 | /* Ok, it's valid. */ | |
10127 | VEC_safe_push (int, result, s.number); | |
10128 | } | |
10129 | ||
10130 | discard_cleanups (cleanup); | |
10131 | return result; | |
10132 | } | |
10133 | ||
10134 | /* Implement the "catch syscall" command. */ | |
10135 | ||
10136 | static void | |
cc59ec59 MS |
10137 | catch_syscall_command_1 (char *arg, int from_tty, |
10138 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
10139 | { |
10140 | int tempflag; | |
10141 | VEC(int) *filter; | |
10142 | struct syscall s; | |
10143 | struct gdbarch *gdbarch = get_current_arch (); | |
10144 | ||
10145 | /* Checking if the feature if supported. */ | |
10146 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
10147 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 10148 | this architecture yet.")); |
a96d9b2e SDJ |
10149 | |
10150 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
10151 | ||
e9cafbcc | 10152 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
10153 | |
10154 | /* We need to do this first "dummy" translation in order | |
10155 | to get the syscall XML file loaded or, most important, | |
10156 | to display a warning to the user if there's no XML file | |
10157 | for his/her architecture. */ | |
10158 | get_syscall_by_number (0, &s); | |
10159 | ||
10160 | /* The allowed syntax is: | |
10161 | catch syscall | |
10162 | catch syscall <name | number> [<name | number> ... <name | number>] | |
10163 | ||
10164 | Let's check if there's a syscall name. */ | |
10165 | ||
10166 | if (arg != NULL) | |
10167 | filter = catch_syscall_split_args (arg); | |
10168 | else | |
10169 | filter = NULL; | |
10170 | ||
10171 | create_syscall_event_catchpoint (tempflag, filter, | |
10172 | &catch_syscall_breakpoint_ops); | |
10173 | } | |
10174 | ||
c906108c | 10175 | static void |
fba45db2 | 10176 | catch_command (char *arg, int from_tty) |
c906108c | 10177 | { |
44feb3ce | 10178 | error (_("Catch requires an event name.")); |
c906108c SS |
10179 | } |
10180 | \f | |
10181 | ||
10182 | static void | |
fba45db2 | 10183 | tcatch_command (char *arg, int from_tty) |
c906108c | 10184 | { |
44feb3ce | 10185 | error (_("Catch requires an event name.")); |
c906108c SS |
10186 | } |
10187 | ||
80f8a6eb | 10188 | /* Delete breakpoints by address or line. */ |
c906108c SS |
10189 | |
10190 | static void | |
fba45db2 | 10191 | clear_command (char *arg, int from_tty) |
c906108c | 10192 | { |
d6e956e5 VP |
10193 | struct breakpoint *b; |
10194 | VEC(breakpoint_p) *found = 0; | |
10195 | int ix; | |
c906108c SS |
10196 | int default_match; |
10197 | struct symtabs_and_lines sals; | |
10198 | struct symtab_and_line sal; | |
c906108c SS |
10199 | int i; |
10200 | ||
10201 | if (arg) | |
10202 | { | |
10203 | sals = decode_line_spec (arg, 1); | |
10204 | default_match = 0; | |
10205 | } | |
10206 | else | |
10207 | { | |
c5aa993b | 10208 | sals.sals = (struct symtab_and_line *) |
c906108c | 10209 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 10210 | make_cleanup (xfree, sals.sals); |
4a64f543 | 10211 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
10212 | |
10213 | /* Set sal's line, symtab, pc, and pspace to the values | |
10214 | corresponding to the last call to print_frame_info. If the | |
10215 | codepoint is not valid, this will set all the fields to 0. */ | |
10216 | get_last_displayed_sal (&sal); | |
c906108c | 10217 | if (sal.symtab == 0) |
8a3fe4f8 | 10218 | error (_("No source file specified.")); |
c906108c SS |
10219 | |
10220 | sals.sals[0] = sal; | |
10221 | sals.nelts = 1; | |
10222 | ||
10223 | default_match = 1; | |
10224 | } | |
10225 | ||
4a64f543 MS |
10226 | /* We don't call resolve_sal_pc here. That's not as bad as it |
10227 | seems, because all existing breakpoints typically have both | |
10228 | file/line and pc set. So, if clear is given file/line, we can | |
10229 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
10230 | |
10231 | We only support clearing given the address explicitly | |
10232 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 10233 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 10234 | due to optimization, all in one block. |
4a64f543 MS |
10235 | |
10236 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
10237 | PC corresponding to the same file:line, the breakpoint won't |
10238 | be cleared. We probably can still clear the breakpoint, but | |
10239 | since the other PC value is never presented to user, user | |
10240 | can only find it by guessing, and it does not seem important | |
10241 | to support that. */ | |
10242 | ||
4a64f543 MS |
10243 | /* For each line spec given, delete bps which correspond to it. Do |
10244 | it in two passes, solely to preserve the current behavior that | |
10245 | from_tty is forced true if we delete more than one | |
10246 | breakpoint. */ | |
c906108c | 10247 | |
80f8a6eb | 10248 | found = NULL; |
c906108c SS |
10249 | for (i = 0; i < sals.nelts; i++) |
10250 | { | |
10251 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
10252 | If line given (pc == 0), clear all bpts on specified line. |
10253 | If defaulting, clear all bpts on default line | |
c906108c | 10254 | or at default pc. |
c5aa993b JM |
10255 | |
10256 | defaulting sal.pc != 0 tests to do | |
10257 | ||
10258 | 0 1 pc | |
10259 | 1 1 pc _and_ line | |
10260 | 0 0 line | |
10261 | 1 0 <can't happen> */ | |
c906108c SS |
10262 | |
10263 | sal = sals.sals[i]; | |
c906108c | 10264 | |
4a64f543 | 10265 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 10266 | ALL_BREAKPOINTS (b) |
c5aa993b | 10267 | { |
0d381245 | 10268 | int match = 0; |
4a64f543 | 10269 | /* Are we going to delete b? */ |
cc60f2e3 | 10270 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
10271 | { |
10272 | struct bp_location *loc = b->loc; | |
10273 | for (; loc; loc = loc->next) | |
10274 | { | |
6c95b8df PA |
10275 | int pc_match = sal.pc |
10276 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
10277 | && (loc->address == sal.pc) |
10278 | && (!section_is_overlay (loc->section) | |
10279 | || loc->section == sal.section); | |
10280 | int line_match = ((default_match || (0 == sal.pc)) | |
10281 | && b->source_file != NULL | |
10282 | && sal.symtab != NULL | |
6c95b8df | 10283 | && sal.pspace == loc->pspace |
0ba1096a KT |
10284 | && filename_cmp (b->source_file, |
10285 | sal.symtab->filename) == 0 | |
0d381245 VP |
10286 | && b->line_number == sal.line); |
10287 | if (pc_match || line_match) | |
10288 | { | |
10289 | match = 1; | |
10290 | break; | |
10291 | } | |
10292 | } | |
10293 | } | |
10294 | ||
10295 | if (match) | |
d6e956e5 | 10296 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 10297 | } |
80f8a6eb MS |
10298 | } |
10299 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 10300 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
10301 | { |
10302 | if (arg) | |
8a3fe4f8 | 10303 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 10304 | else |
8a3fe4f8 | 10305 | error (_("No breakpoint at this line.")); |
80f8a6eb | 10306 | } |
c906108c | 10307 | |
d6e956e5 | 10308 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 10309 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 10310 | if (from_tty) |
a3f17187 | 10311 | { |
d6e956e5 | 10312 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
10313 | printf_unfiltered (_("Deleted breakpoint ")); |
10314 | else | |
10315 | printf_unfiltered (_("Deleted breakpoints ")); | |
10316 | } | |
80f8a6eb | 10317 | breakpoints_changed (); |
d6e956e5 VP |
10318 | |
10319 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 10320 | { |
c5aa993b | 10321 | if (from_tty) |
d6e956e5 VP |
10322 | printf_unfiltered ("%d ", b->number); |
10323 | delete_breakpoint (b); | |
c906108c | 10324 | } |
80f8a6eb MS |
10325 | if (from_tty) |
10326 | putchar_unfiltered ('\n'); | |
c906108c SS |
10327 | } |
10328 | \f | |
10329 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
10330 | all breakpoints that are marked for deletion, whether hit or not. | |
10331 | This is called after any breakpoint is hit, or after errors. */ | |
10332 | ||
10333 | void | |
fba45db2 | 10334 | breakpoint_auto_delete (bpstat bs) |
c906108c | 10335 | { |
35df4500 | 10336 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10337 | |
10338 | for (; bs; bs = bs->next) | |
f431efe5 PA |
10339 | if (bs->breakpoint_at |
10340 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 10341 | && bs->stop) |
f431efe5 | 10342 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 10343 | |
35df4500 | 10344 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10345 | { |
b5de0fa7 | 10346 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
10347 | delete_breakpoint (b); |
10348 | } | |
c906108c SS |
10349 | } |
10350 | ||
4a64f543 MS |
10351 | /* A comparison function for bp_location AP and BP being interfaced to |
10352 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
10353 | does breakpoint_address_is_meaningful say for its OWNER), | |
10354 | secondarily by ordering first bp_permanent OWNERed elements and | |
10355 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 10356 | qsort being an unstable algorithm. */ |
876fa593 JK |
10357 | |
10358 | static int | |
494cfb0f | 10359 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 10360 | { |
494cfb0f JK |
10361 | struct bp_location *a = *(void **) ap; |
10362 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 10363 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
10364 | int a_perm = a->owner->enable_state == bp_permanent; |
10365 | int b_perm = b->owner->enable_state == bp_permanent; | |
10366 | ||
10367 | if (a->address != b->address) | |
10368 | return (a->address > b->address) - (a->address < b->address); | |
10369 | ||
10370 | /* Sort permanent breakpoints first. */ | |
10371 | if (a_perm != b_perm) | |
10372 | return (a_perm < b_perm) - (a_perm > b_perm); | |
10373 | ||
4a64f543 MS |
10374 | /* Make the user-visible order stable across GDB runs. Locations of |
10375 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
10376 | |
10377 | if (a->owner->number != b->owner->number) | |
10378 | return (a->owner->number > b->owner->number) | |
10379 | - (a->owner->number < b->owner->number); | |
10380 | ||
10381 | return (a > b) - (a < b); | |
10382 | } | |
10383 | ||
876fa593 | 10384 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
10385 | bp_location_shadow_len_after_address_max according to the current |
10386 | content of the bp_location array. */ | |
f7545552 TT |
10387 | |
10388 | static void | |
876fa593 | 10389 | bp_location_target_extensions_update (void) |
f7545552 | 10390 | { |
876fa593 JK |
10391 | struct bp_location *bl, **blp_tmp; |
10392 | ||
10393 | bp_location_placed_address_before_address_max = 0; | |
10394 | bp_location_shadow_len_after_address_max = 0; | |
10395 | ||
10396 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10397 | { | |
10398 | CORE_ADDR start, end, addr; | |
10399 | ||
10400 | if (!bp_location_has_shadow (bl)) | |
10401 | continue; | |
10402 | ||
10403 | start = bl->target_info.placed_address; | |
10404 | end = start + bl->target_info.shadow_len; | |
10405 | ||
10406 | gdb_assert (bl->address >= start); | |
10407 | addr = bl->address - start; | |
10408 | if (addr > bp_location_placed_address_before_address_max) | |
10409 | bp_location_placed_address_before_address_max = addr; | |
10410 | ||
10411 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
10412 | ||
10413 | gdb_assert (bl->address < end); | |
10414 | addr = end - bl->address; | |
10415 | if (addr > bp_location_shadow_len_after_address_max) | |
10416 | bp_location_shadow_len_after_address_max = addr; | |
10417 | } | |
f7545552 TT |
10418 | } |
10419 | ||
1e4d1764 YQ |
10420 | /* Download tracepoint locations if they haven't been. */ |
10421 | ||
10422 | static void | |
10423 | download_tracepoint_locations (void) | |
10424 | { | |
10425 | struct bp_location *bl, **blp_tmp; | |
10426 | struct cleanup *old_chain; | |
10427 | ||
10428 | if (!target_can_download_tracepoint ()) | |
10429 | return; | |
10430 | ||
10431 | old_chain = save_current_space_and_thread (); | |
10432 | ||
10433 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10434 | { | |
10435 | struct tracepoint *t; | |
10436 | ||
10437 | if (!is_tracepoint (bl->owner)) | |
10438 | continue; | |
10439 | ||
10440 | if ((bl->owner->type == bp_fast_tracepoint | |
10441 | ? !may_insert_fast_tracepoints | |
10442 | : !may_insert_tracepoints)) | |
10443 | continue; | |
10444 | ||
10445 | /* In tracepoint, locations are _never_ duplicated, so | |
10446 | should_be_inserted is equivalent to | |
10447 | unduplicated_should_be_inserted. */ | |
10448 | if (!should_be_inserted (bl) || bl->inserted) | |
10449 | continue; | |
10450 | ||
10451 | switch_to_program_space_and_thread (bl->pspace); | |
10452 | ||
10453 | target_download_tracepoint (bl); | |
10454 | ||
10455 | bl->inserted = 1; | |
10456 | t = (struct tracepoint *) bl->owner; | |
10457 | t->number_on_target = bl->owner->number; | |
10458 | } | |
10459 | ||
10460 | do_cleanups (old_chain); | |
10461 | } | |
10462 | ||
934709f0 PW |
10463 | /* Swap the insertion/duplication state between two locations. */ |
10464 | ||
10465 | static void | |
10466 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
10467 | { | |
10468 | const int left_inserted = left->inserted; | |
10469 | const int left_duplicate = left->duplicate; | |
10470 | const struct bp_target_info left_target_info = left->target_info; | |
10471 | ||
1e4d1764 YQ |
10472 | /* Locations of tracepoints can never be duplicated. */ |
10473 | if (is_tracepoint (left->owner)) | |
10474 | gdb_assert (!left->duplicate); | |
10475 | if (is_tracepoint (right->owner)) | |
10476 | gdb_assert (!right->duplicate); | |
10477 | ||
934709f0 PW |
10478 | left->inserted = right->inserted; |
10479 | left->duplicate = right->duplicate; | |
10480 | left->target_info = right->target_info; | |
10481 | right->inserted = left_inserted; | |
10482 | right->duplicate = left_duplicate; | |
10483 | right->target_info = left_target_info; | |
10484 | } | |
10485 | ||
4cd9bd08 | 10486 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
10487 | into the inferior, only remove already-inserted locations that no |
10488 | longer should be inserted. Functions that delete a breakpoint or | |
10489 | breakpoints should pass false, so that deleting a breakpoint | |
10490 | doesn't have the side effect of inserting the locations of other | |
10491 | breakpoints that are marked not-inserted, but should_be_inserted | |
10492 | returns true on them. | |
10493 | ||
10494 | This behaviour is useful is situations close to tear-down -- e.g., | |
10495 | after an exec, while the target still has execution, but breakpoint | |
10496 | shadows of the previous executable image should *NOT* be restored | |
10497 | to the new image; or before detaching, where the target still has | |
10498 | execution and wants to delete breakpoints from GDB's lists, and all | |
10499 | breakpoints had already been removed from the inferior. */ | |
10500 | ||
0d381245 | 10501 | static void |
b60e7edf | 10502 | update_global_location_list (int should_insert) |
0d381245 | 10503 | { |
74960c60 | 10504 | struct breakpoint *b; |
876fa593 | 10505 | struct bp_location **locp, *loc; |
f7545552 TT |
10506 | struct cleanup *cleanups; |
10507 | ||
2d134ed3 PA |
10508 | /* Used in the duplicates detection below. When iterating over all |
10509 | bp_locations, points to the first bp_location of a given address. | |
10510 | Breakpoints and watchpoints of different types are never | |
10511 | duplicates of each other. Keep one pointer for each type of | |
10512 | breakpoint/watchpoint, so we only need to loop over all locations | |
10513 | once. */ | |
10514 | struct bp_location *bp_loc_first; /* breakpoint */ | |
10515 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
10516 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
10517 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 10518 | |
4a64f543 MS |
10519 | /* Saved former bp_location array which we compare against the newly |
10520 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
10521 | struct bp_location **old_location, **old_locp; |
10522 | unsigned old_location_count; | |
10523 | ||
10524 | old_location = bp_location; | |
10525 | old_location_count = bp_location_count; | |
10526 | bp_location = NULL; | |
10527 | bp_location_count = 0; | |
10528 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 10529 | |
74960c60 | 10530 | ALL_BREAKPOINTS (b) |
876fa593 JK |
10531 | for (loc = b->loc; loc; loc = loc->next) |
10532 | bp_location_count++; | |
10533 | ||
10534 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
10535 | locp = bp_location; | |
10536 | ALL_BREAKPOINTS (b) | |
10537 | for (loc = b->loc; loc; loc = loc->next) | |
10538 | *locp++ = loc; | |
10539 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 10540 | bp_location_compare); |
876fa593 JK |
10541 | |
10542 | bp_location_target_extensions_update (); | |
74960c60 | 10543 | |
4a64f543 MS |
10544 | /* Identify bp_location instances that are no longer present in the |
10545 | new list, and therefore should be freed. Note that it's not | |
10546 | necessary that those locations should be removed from inferior -- | |
10547 | if there's another location at the same address (previously | |
10548 | marked as duplicate), we don't need to remove/insert the | |
10549 | location. | |
876fa593 | 10550 | |
4a64f543 MS |
10551 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
10552 | and former bp_location array state respectively. */ | |
876fa593 JK |
10553 | |
10554 | locp = bp_location; | |
10555 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
10556 | old_locp++) | |
74960c60 | 10557 | { |
876fa593 | 10558 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 10559 | struct bp_location **loc2p; |
876fa593 | 10560 | |
e5dd4106 | 10561 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 10562 | not, we have to free it. */ |
c7d46a38 | 10563 | int found_object = 0; |
20874c92 VP |
10564 | /* Tells if the location should remain inserted in the target. */ |
10565 | int keep_in_target = 0; | |
10566 | int removed = 0; | |
876fa593 | 10567 | |
4a64f543 MS |
10568 | /* Skip LOCP entries which will definitely never be needed. |
10569 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 10570 | while (locp < bp_location + bp_location_count |
c7d46a38 | 10571 | && (*locp)->address < old_loc->address) |
876fa593 | 10572 | locp++; |
c7d46a38 PA |
10573 | |
10574 | for (loc2p = locp; | |
10575 | (loc2p < bp_location + bp_location_count | |
10576 | && (*loc2p)->address == old_loc->address); | |
10577 | loc2p++) | |
10578 | { | |
10579 | if (*loc2p == old_loc) | |
10580 | { | |
10581 | found_object = 1; | |
10582 | break; | |
10583 | } | |
10584 | } | |
74960c60 | 10585 | |
4a64f543 MS |
10586 | /* If this location is no longer present, and inserted, look if |
10587 | there's maybe a new location at the same address. If so, | |
10588 | mark that one inserted, and don't remove this one. This is | |
10589 | needed so that we don't have a time window where a breakpoint | |
10590 | at certain location is not inserted. */ | |
74960c60 | 10591 | |
876fa593 | 10592 | if (old_loc->inserted) |
0d381245 | 10593 | { |
4a64f543 MS |
10594 | /* If the location is inserted now, we might have to remove |
10595 | it. */ | |
74960c60 | 10596 | |
876fa593 | 10597 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 10598 | { |
4a64f543 MS |
10599 | /* The location is still present in the location list, |
10600 | and still should be inserted. Don't do anything. */ | |
20874c92 | 10601 | keep_in_target = 1; |
74960c60 VP |
10602 | } |
10603 | else | |
10604 | { | |
4a64f543 MS |
10605 | /* The location is either no longer present, or got |
10606 | disabled. See if there's another location at the | |
10607 | same address, in which case we don't need to remove | |
10608 | this one from the target. */ | |
876fa593 | 10609 | |
2bdf28a0 | 10610 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
10611 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
10612 | { | |
876fa593 | 10613 | for (loc2p = locp; |
c7d46a38 PA |
10614 | (loc2p < bp_location + bp_location_count |
10615 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
10616 | loc2p++) |
10617 | { | |
10618 | struct bp_location *loc2 = *loc2p; | |
10619 | ||
2d134ed3 | 10620 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 10621 | { |
85d721b8 PA |
10622 | /* Read watchpoint locations are switched to |
10623 | access watchpoints, if the former are not | |
10624 | supported, but the latter are. */ | |
10625 | if (is_hardware_watchpoint (old_loc->owner)) | |
10626 | { | |
10627 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
10628 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
10629 | } | |
10630 | ||
934709f0 PW |
10631 | /* loc2 is a duplicated location. We need to check |
10632 | if it should be inserted in case it will be | |
10633 | unduplicated. */ | |
10634 | if (loc2 != old_loc | |
10635 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 10636 | { |
934709f0 | 10637 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
10638 | keep_in_target = 1; |
10639 | break; | |
10640 | } | |
876fa593 JK |
10641 | } |
10642 | } | |
10643 | } | |
74960c60 VP |
10644 | } |
10645 | ||
20874c92 VP |
10646 | if (!keep_in_target) |
10647 | { | |
876fa593 | 10648 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 10649 | { |
4a64f543 MS |
10650 | /* This is just about all we can do. We could keep |
10651 | this location on the global list, and try to | |
10652 | remove it next time, but there's no particular | |
10653 | reason why we will succeed next time. | |
20874c92 | 10654 | |
4a64f543 MS |
10655 | Note that at this point, old_loc->owner is still |
10656 | valid, as delete_breakpoint frees the breakpoint | |
10657 | only after calling us. */ | |
3e43a32a MS |
10658 | printf_filtered (_("warning: Error removing " |
10659 | "breakpoint %d\n"), | |
876fa593 | 10660 | old_loc->owner->number); |
20874c92 VP |
10661 | } |
10662 | removed = 1; | |
10663 | } | |
0d381245 | 10664 | } |
74960c60 VP |
10665 | |
10666 | if (!found_object) | |
1c5cfe86 | 10667 | { |
db82e815 PA |
10668 | if (removed && non_stop |
10669 | && breakpoint_address_is_meaningful (old_loc->owner) | |
10670 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 10671 | { |
db82e815 PA |
10672 | /* This location was removed from the target. In |
10673 | non-stop mode, a race condition is possible where | |
10674 | we've removed a breakpoint, but stop events for that | |
10675 | breakpoint are already queued and will arrive later. | |
10676 | We apply an heuristic to be able to distinguish such | |
10677 | SIGTRAPs from other random SIGTRAPs: we keep this | |
10678 | breakpoint location for a bit, and will retire it | |
10679 | after we see some number of events. The theory here | |
10680 | is that reporting of events should, "on the average", | |
10681 | be fair, so after a while we'll see events from all | |
10682 | threads that have anything of interest, and no longer | |
10683 | need to keep this breakpoint location around. We | |
10684 | don't hold locations forever so to reduce chances of | |
10685 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
10686 | SIGTRAP. | |
10687 | ||
10688 | The heuristic failing can be disastrous on | |
10689 | decr_pc_after_break targets. | |
10690 | ||
10691 | On decr_pc_after_break targets, like e.g., x86-linux, | |
10692 | if we fail to recognize a late breakpoint SIGTRAP, | |
10693 | because events_till_retirement has reached 0 too | |
10694 | soon, we'll fail to do the PC adjustment, and report | |
10695 | a random SIGTRAP to the user. When the user resumes | |
10696 | the inferior, it will most likely immediately crash | |
2dec564e | 10697 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
10698 | corrupted, because of being resumed e.g., in the |
10699 | middle of a multi-byte instruction, or skipped a | |
10700 | one-byte instruction. This was actually seen happen | |
10701 | on native x86-linux, and should be less rare on | |
10702 | targets that do not support new thread events, like | |
10703 | remote, due to the heuristic depending on | |
10704 | thread_count. | |
10705 | ||
10706 | Mistaking a random SIGTRAP for a breakpoint trap | |
10707 | causes similar symptoms (PC adjustment applied when | |
10708 | it shouldn't), but then again, playing with SIGTRAPs | |
10709 | behind the debugger's back is asking for trouble. | |
10710 | ||
10711 | Since hardware watchpoint traps are always | |
10712 | distinguishable from other traps, so we don't need to | |
10713 | apply keep hardware watchpoint moribund locations | |
10714 | around. We simply always ignore hardware watchpoint | |
10715 | traps we can no longer explain. */ | |
10716 | ||
876fa593 JK |
10717 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
10718 | old_loc->owner = NULL; | |
20874c92 | 10719 | |
876fa593 | 10720 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
10721 | } |
10722 | else | |
f431efe5 PA |
10723 | { |
10724 | old_loc->owner = NULL; | |
10725 | decref_bp_location (&old_loc); | |
10726 | } | |
20874c92 | 10727 | } |
74960c60 | 10728 | } |
1c5cfe86 | 10729 | |
348d480f PA |
10730 | /* Rescan breakpoints at the same address and section, marking the |
10731 | first one as "first" and any others as "duplicates". This is so | |
10732 | that the bpt instruction is only inserted once. If we have a | |
10733 | permanent breakpoint at the same place as BPT, make that one the | |
10734 | official one, and the rest as duplicates. Permanent breakpoints | |
10735 | are sorted first for the same address. | |
10736 | ||
10737 | Do the same for hardware watchpoints, but also considering the | |
10738 | watchpoint's type (regular/access/read) and length. */ | |
10739 | ||
10740 | bp_loc_first = NULL; | |
10741 | wp_loc_first = NULL; | |
10742 | awp_loc_first = NULL; | |
10743 | rwp_loc_first = NULL; | |
10744 | ALL_BP_LOCATIONS (loc, locp) | |
10745 | { | |
10746 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
10747 | non-NULL. */ | |
10748 | struct breakpoint *b = loc->owner; | |
10749 | struct bp_location **loc_first_p; | |
10750 | ||
10751 | if (b->enable_state == bp_disabled | |
10752 | || b->enable_state == bp_call_disabled | |
10753 | || b->enable_state == bp_startup_disabled | |
10754 | || !loc->enabled | |
10755 | || loc->shlib_disabled | |
10756 | || !breakpoint_address_is_meaningful (b) | |
1e4d1764 YQ |
10757 | /* Don't detect duplicate for tracepoint locations because they are |
10758 | never duplicated. See the comments in field `duplicate' of | |
10759 | `struct bp_location'. */ | |
348d480f PA |
10760 | || is_tracepoint (b)) |
10761 | continue; | |
10762 | ||
10763 | /* Permanent breakpoint should always be inserted. */ | |
10764 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
10765 | internal_error (__FILE__, __LINE__, | |
10766 | _("allegedly permanent breakpoint is not " | |
10767 | "actually inserted")); | |
10768 | ||
10769 | if (b->type == bp_hardware_watchpoint) | |
10770 | loc_first_p = &wp_loc_first; | |
10771 | else if (b->type == bp_read_watchpoint) | |
10772 | loc_first_p = &rwp_loc_first; | |
10773 | else if (b->type == bp_access_watchpoint) | |
10774 | loc_first_p = &awp_loc_first; | |
10775 | else | |
10776 | loc_first_p = &bp_loc_first; | |
10777 | ||
10778 | if (*loc_first_p == NULL | |
10779 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
10780 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
10781 | { | |
10782 | *loc_first_p = loc; | |
10783 | loc->duplicate = 0; | |
10784 | continue; | |
10785 | } | |
10786 | ||
934709f0 PW |
10787 | |
10788 | /* This and the above ensure the invariant that the first location | |
10789 | is not duplicated, and is the inserted one. | |
10790 | All following are marked as duplicated, and are not inserted. */ | |
10791 | if (loc->inserted) | |
10792 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
10793 | loc->duplicate = 1; |
10794 | ||
10795 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted | |
10796 | && b->enable_state != bp_permanent) | |
10797 | internal_error (__FILE__, __LINE__, | |
10798 | _("another breakpoint was inserted on top of " | |
10799 | "a permanent breakpoint")); | |
10800 | } | |
10801 | ||
10802 | if (breakpoints_always_inserted_mode () && should_insert | |
10803 | && (have_live_inferiors () | |
10804 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) | |
10805 | insert_breakpoint_locations (); | |
10806 | ||
1e4d1764 YQ |
10807 | if (should_insert) |
10808 | download_tracepoint_locations (); | |
10809 | ||
348d480f PA |
10810 | do_cleanups (cleanups); |
10811 | } | |
10812 | ||
10813 | void | |
10814 | breakpoint_retire_moribund (void) | |
10815 | { | |
10816 | struct bp_location *loc; | |
10817 | int ix; | |
10818 | ||
10819 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
10820 | if (--(loc->events_till_retirement) == 0) | |
10821 | { | |
10822 | decref_bp_location (&loc); | |
10823 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
10824 | --ix; | |
10825 | } | |
10826 | } | |
10827 | ||
10828 | static void | |
10829 | update_global_location_list_nothrow (int inserting) | |
10830 | { | |
10831 | struct gdb_exception e; | |
10832 | ||
10833 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
10834 | update_global_location_list (inserting); | |
10835 | } | |
10836 | ||
10837 | /* Clear BKP from a BPS. */ | |
10838 | ||
10839 | static void | |
10840 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
10841 | { | |
10842 | bpstat bs; | |
10843 | ||
10844 | for (bs = bps; bs; bs = bs->next) | |
10845 | if (bs->breakpoint_at == bpt) | |
10846 | { | |
10847 | bs->breakpoint_at = NULL; | |
10848 | bs->old_val = NULL; | |
10849 | /* bs->commands will be freed later. */ | |
10850 | } | |
10851 | } | |
10852 | ||
10853 | /* Callback for iterate_over_threads. */ | |
10854 | static int | |
10855 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
10856 | { | |
10857 | struct breakpoint *bpt = data; | |
10858 | ||
10859 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
10860 | return 0; | |
10861 | } | |
10862 | ||
10863 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
10864 | callbacks. */ | |
10865 | ||
10866 | static void | |
10867 | say_where (struct breakpoint *b) | |
10868 | { | |
79a45e25 | 10869 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10870 | struct value_print_options opts; |
10871 | ||
10872 | get_user_print_options (&opts); | |
10873 | ||
10874 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
10875 | single string. */ | |
10876 | if (b->loc == NULL) | |
10877 | { | |
10878 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
10879 | } | |
10880 | else | |
10881 | { | |
10882 | if (opts.addressprint || b->source_file == NULL) | |
10883 | { | |
10884 | printf_filtered (" at "); | |
10885 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
10886 | gdb_stdout); | |
10887 | } | |
10888 | if (b->source_file) | |
10889 | printf_filtered (": file %s, line %d.", | |
10890 | b->source_file, b->line_number); | |
10891 | ||
10892 | if (b->loc->next) | |
10893 | { | |
10894 | struct bp_location *loc = b->loc; | |
10895 | int n = 0; | |
10896 | for (; loc; loc = loc->next) | |
10897 | ++n; | |
10898 | printf_filtered (" (%d locations)", n); | |
10899 | } | |
10900 | } | |
10901 | } | |
10902 | ||
348d480f PA |
10903 | /* Default bp_location_ops methods. */ |
10904 | ||
10905 | static void | |
10906 | bp_location_dtor (struct bp_location *self) | |
10907 | { | |
10908 | xfree (self->cond); | |
10909 | xfree (self->function_name); | |
10910 | } | |
10911 | ||
10912 | static const struct bp_location_ops bp_location_ops = | |
10913 | { | |
10914 | bp_location_dtor | |
10915 | }; | |
10916 | ||
2060206e PA |
10917 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
10918 | inherit from. */ | |
348d480f | 10919 | |
2060206e PA |
10920 | static void |
10921 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
10922 | { |
10923 | decref_counted_command_line (&self->commands); | |
10924 | xfree (self->cond_string); | |
348d480f PA |
10925 | xfree (self->addr_string); |
10926 | xfree (self->addr_string_range_end); | |
348d480f PA |
10927 | xfree (self->source_file); |
10928 | } | |
10929 | ||
2060206e PA |
10930 | static struct bp_location * |
10931 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
10932 | { |
10933 | struct bp_location *loc; | |
10934 | ||
10935 | loc = XNEW (struct bp_location); | |
10936 | init_bp_location (loc, &bp_location_ops, self); | |
10937 | return loc; | |
10938 | } | |
10939 | ||
2060206e PA |
10940 | static void |
10941 | base_breakpoint_re_set (struct breakpoint *b) | |
10942 | { | |
10943 | /* Nothing to re-set. */ | |
10944 | } | |
10945 | ||
10946 | #define internal_error_pure_virtual_called() \ | |
10947 | gdb_assert_not_reached ("pure virtual function called") | |
10948 | ||
10949 | static int | |
10950 | base_breakpoint_insert_location (struct bp_location *bl) | |
10951 | { | |
10952 | internal_error_pure_virtual_called (); | |
10953 | } | |
10954 | ||
10955 | static int | |
10956 | base_breakpoint_remove_location (struct bp_location *bl) | |
10957 | { | |
10958 | internal_error_pure_virtual_called (); | |
10959 | } | |
10960 | ||
10961 | static int | |
10962 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
10963 | struct address_space *aspace, | |
10964 | CORE_ADDR bp_addr) | |
10965 | { | |
10966 | internal_error_pure_virtual_called (); | |
10967 | } | |
10968 | ||
10969 | static void | |
10970 | base_breakpoint_check_status (bpstat bs) | |
10971 | { | |
10972 | /* Always stop. */ | |
10973 | } | |
10974 | ||
10975 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
10976 | errors. */ | |
10977 | ||
10978 | static int | |
10979 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
10980 | { | |
10981 | internal_error_pure_virtual_called (); | |
10982 | } | |
10983 | ||
10984 | /* A "resources_needed" breakpoint_ops method that just internal | |
10985 | errors. */ | |
10986 | ||
10987 | static int | |
10988 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
10989 | { | |
10990 | internal_error_pure_virtual_called (); | |
10991 | } | |
10992 | ||
10993 | static enum print_stop_action | |
10994 | base_breakpoint_print_it (bpstat bs) | |
10995 | { | |
10996 | internal_error_pure_virtual_called (); | |
10997 | } | |
10998 | ||
10999 | static void | |
11000 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
11001 | struct ui_out *uiout) | |
11002 | { | |
11003 | /* nothing */ | |
11004 | } | |
11005 | ||
11006 | static void | |
11007 | base_breakpoint_print_mention (struct breakpoint *b) | |
11008 | { | |
11009 | internal_error_pure_virtual_called (); | |
11010 | } | |
11011 | ||
11012 | static void | |
11013 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
11014 | { | |
11015 | internal_error_pure_virtual_called (); | |
11016 | } | |
11017 | ||
11018 | static struct breakpoint_ops base_breakpoint_ops = | |
11019 | { | |
11020 | base_breakpoint_dtor, | |
11021 | base_breakpoint_allocate_location, | |
11022 | base_breakpoint_re_set, | |
11023 | base_breakpoint_insert_location, | |
11024 | base_breakpoint_remove_location, | |
11025 | base_breakpoint_breakpoint_hit, | |
11026 | base_breakpoint_check_status, | |
11027 | base_breakpoint_resources_needed, | |
11028 | base_breakpoint_works_in_software_mode, | |
11029 | base_breakpoint_print_it, | |
11030 | NULL, | |
11031 | base_breakpoint_print_one_detail, | |
11032 | base_breakpoint_print_mention, | |
11033 | base_breakpoint_print_recreate | |
11034 | }; | |
11035 | ||
11036 | /* Default breakpoint_ops methods. */ | |
11037 | ||
11038 | static void | |
348d480f PA |
11039 | bkpt_re_set (struct breakpoint *b) |
11040 | { | |
06edf0c0 PA |
11041 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
11042 | if (b->enable_state == bp_startup_disabled) | |
11043 | return; | |
348d480f | 11044 | |
06edf0c0 PA |
11045 | /* FIXME: is this still reachable? */ |
11046 | if (b->addr_string == NULL) | |
11047 | { | |
11048 | /* Anything without a string can't be re-set. */ | |
348d480f | 11049 | delete_breakpoint (b); |
06edf0c0 | 11050 | return; |
348d480f | 11051 | } |
06edf0c0 PA |
11052 | |
11053 | breakpoint_re_set_default (b); | |
348d480f PA |
11054 | } |
11055 | ||
2060206e | 11056 | static int |
348d480f PA |
11057 | bkpt_insert_location (struct bp_location *bl) |
11058 | { | |
11059 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
11060 | return target_insert_hw_breakpoint (bl->gdbarch, | |
11061 | &bl->target_info); | |
11062 | else | |
11063 | return target_insert_breakpoint (bl->gdbarch, | |
11064 | &bl->target_info); | |
11065 | } | |
11066 | ||
2060206e | 11067 | static int |
348d480f PA |
11068 | bkpt_remove_location (struct bp_location *bl) |
11069 | { | |
11070 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
11071 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
11072 | else | |
11073 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
11074 | } | |
11075 | ||
2060206e | 11076 | static int |
348d480f PA |
11077 | bkpt_breakpoint_hit (const struct bp_location *bl, |
11078 | struct address_space *aspace, CORE_ADDR bp_addr) | |
11079 | { | |
11080 | struct breakpoint *b = bl->owner; | |
11081 | ||
11082 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, | |
11083 | aspace, bp_addr)) | |
11084 | return 0; | |
11085 | ||
11086 | if (overlay_debugging /* unmapped overlay section */ | |
11087 | && section_is_overlay (bl->section) | |
11088 | && !section_is_mapped (bl->section)) | |
11089 | return 0; | |
11090 | ||
11091 | return 1; | |
11092 | } | |
11093 | ||
2060206e | 11094 | static int |
348d480f PA |
11095 | bkpt_resources_needed (const struct bp_location *bl) |
11096 | { | |
11097 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
11098 | ||
11099 | return 1; | |
11100 | } | |
11101 | ||
2060206e | 11102 | static enum print_stop_action |
348d480f PA |
11103 | bkpt_print_it (bpstat bs) |
11104 | { | |
348d480f PA |
11105 | struct breakpoint *b; |
11106 | const struct bp_location *bl; | |
001c8c33 | 11107 | int bp_temp; |
79a45e25 | 11108 | struct ui_out *uiout = current_uiout; |
348d480f PA |
11109 | |
11110 | gdb_assert (bs->bp_location_at != NULL); | |
11111 | ||
11112 | bl = bs->bp_location_at; | |
11113 | b = bs->breakpoint_at; | |
11114 | ||
001c8c33 PA |
11115 | bp_temp = b->disposition == disp_del; |
11116 | if (bl->address != bl->requested_address) | |
11117 | breakpoint_adjustment_warning (bl->requested_address, | |
11118 | bl->address, | |
11119 | b->number, 1); | |
11120 | annotate_breakpoint (b->number); | |
11121 | if (bp_temp) | |
11122 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
11123 | else | |
11124 | ui_out_text (uiout, "\nBreakpoint "); | |
11125 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 11126 | { |
001c8c33 PA |
11127 | ui_out_field_string (uiout, "reason", |
11128 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
11129 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 11130 | } |
001c8c33 PA |
11131 | ui_out_field_int (uiout, "bkptno", b->number); |
11132 | ui_out_text (uiout, ", "); | |
06edf0c0 | 11133 | |
001c8c33 | 11134 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
11135 | } |
11136 | ||
2060206e | 11137 | static void |
06edf0c0 PA |
11138 | bkpt_print_mention (struct breakpoint *b) |
11139 | { | |
79a45e25 | 11140 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
11141 | return; |
11142 | ||
11143 | switch (b->type) | |
11144 | { | |
11145 | case bp_breakpoint: | |
11146 | case bp_gnu_ifunc_resolver: | |
11147 | if (b->disposition == disp_del) | |
11148 | printf_filtered (_("Temporary breakpoint")); | |
11149 | else | |
11150 | printf_filtered (_("Breakpoint")); | |
11151 | printf_filtered (_(" %d"), b->number); | |
11152 | if (b->type == bp_gnu_ifunc_resolver) | |
11153 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
11154 | break; | |
11155 | case bp_hardware_breakpoint: | |
11156 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
11157 | break; | |
11158 | } | |
11159 | ||
11160 | say_where (b); | |
11161 | } | |
11162 | ||
2060206e | 11163 | static void |
06edf0c0 PA |
11164 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
11165 | { | |
11166 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
11167 | fprintf_unfiltered (fp, "tbreak"); | |
11168 | else if (tp->type == bp_breakpoint) | |
11169 | fprintf_unfiltered (fp, "break"); | |
11170 | else if (tp->type == bp_hardware_breakpoint | |
11171 | && tp->disposition == disp_del) | |
11172 | fprintf_unfiltered (fp, "thbreak"); | |
11173 | else if (tp->type == bp_hardware_breakpoint) | |
11174 | fprintf_unfiltered (fp, "hbreak"); | |
11175 | else | |
11176 | internal_error (__FILE__, __LINE__, | |
11177 | _("unhandled breakpoint type %d"), (int) tp->type); | |
11178 | ||
2060206e | 11179 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 11180 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
11181 | } |
11182 | ||
06edf0c0 PA |
11183 | /* Virtual table for internal breakpoints. */ |
11184 | ||
11185 | static void | |
11186 | internal_bkpt_re_set (struct breakpoint *b) | |
11187 | { | |
11188 | switch (b->type) | |
11189 | { | |
11190 | /* Delete overlay event and longjmp master breakpoints; they | |
11191 | will be reset later by breakpoint_re_set. */ | |
11192 | case bp_overlay_event: | |
11193 | case bp_longjmp_master: | |
11194 | case bp_std_terminate_master: | |
11195 | case bp_exception_master: | |
11196 | delete_breakpoint (b); | |
11197 | break; | |
11198 | ||
11199 | /* This breakpoint is special, it's set up when the inferior | |
11200 | starts and we really don't want to touch it. */ | |
11201 | case bp_shlib_event: | |
11202 | ||
11203 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
11204 | it is set up, we do not want to touch it. */ | |
11205 | case bp_thread_event: | |
11206 | break; | |
11207 | } | |
11208 | } | |
11209 | ||
11210 | static void | |
11211 | internal_bkpt_check_status (bpstat bs) | |
11212 | { | |
11213 | /* We do not stop for these. */ | |
11214 | bs->stop = 0; | |
11215 | } | |
11216 | ||
11217 | static enum print_stop_action | |
11218 | internal_bkpt_print_it (bpstat bs) | |
11219 | { | |
36dfb11c | 11220 | struct ui_out *uiout = current_uiout; |
06edf0c0 | 11221 | struct breakpoint *b; |
06edf0c0 | 11222 | |
06edf0c0 PA |
11223 | b = bs->breakpoint_at; |
11224 | ||
06edf0c0 PA |
11225 | switch (b->type) |
11226 | { | |
348d480f PA |
11227 | case bp_shlib_event: |
11228 | /* Did we stop because the user set the stop_on_solib_events | |
11229 | variable? (If so, we report this as a generic, "Stopped due | |
11230 | to shlib event" message.) */ | |
36dfb11c TT |
11231 | ui_out_text (uiout, _("Stopped due to shared library event\n")); |
11232 | if (ui_out_is_mi_like_p (uiout)) | |
11233 | ui_out_field_string (uiout, "reason", | |
11234 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
348d480f PA |
11235 | break; |
11236 | ||
11237 | case bp_thread_event: | |
11238 | /* Not sure how we will get here. | |
11239 | GDB should not stop for these breakpoints. */ | |
11240 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11241 | break; |
11242 | ||
11243 | case bp_overlay_event: | |
11244 | /* By analogy with the thread event, GDB should not stop for these. */ | |
11245 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11246 | break; |
11247 | ||
11248 | case bp_longjmp_master: | |
11249 | /* These should never be enabled. */ | |
11250 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11251 | break; |
11252 | ||
11253 | case bp_std_terminate_master: | |
11254 | /* These should never be enabled. */ | |
11255 | printf_filtered (_("std::terminate Master Breakpoint: " | |
11256 | "gdb should not stop!\n")); | |
348d480f PA |
11257 | break; |
11258 | ||
11259 | case bp_exception_master: | |
11260 | /* These should never be enabled. */ | |
11261 | printf_filtered (_("Exception Master Breakpoint: " | |
11262 | "gdb should not stop!\n")); | |
06edf0c0 PA |
11263 | break; |
11264 | } | |
11265 | ||
001c8c33 | 11266 | return PRINT_NOTHING; |
06edf0c0 PA |
11267 | } |
11268 | ||
11269 | static void | |
11270 | internal_bkpt_print_mention (struct breakpoint *b) | |
11271 | { | |
11272 | /* Nothing to mention. These breakpoints are internal. */ | |
11273 | } | |
11274 | ||
06edf0c0 PA |
11275 | /* Virtual table for momentary breakpoints */ |
11276 | ||
11277 | static void | |
11278 | momentary_bkpt_re_set (struct breakpoint *b) | |
11279 | { | |
11280 | /* Keep temporary breakpoints, which can be encountered when we step | |
11281 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
11282 | Otherwise these should have been blown away via the cleanup chain | |
11283 | or by breakpoint_init_inferior when we rerun the executable. */ | |
11284 | } | |
11285 | ||
11286 | static void | |
11287 | momentary_bkpt_check_status (bpstat bs) | |
11288 | { | |
11289 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
11290 | } | |
11291 | ||
11292 | static enum print_stop_action | |
11293 | momentary_bkpt_print_it (bpstat bs) | |
11294 | { | |
79a45e25 PA |
11295 | struct ui_out *uiout = current_uiout; |
11296 | ||
001c8c33 | 11297 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 11298 | { |
001c8c33 | 11299 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 11300 | |
001c8c33 PA |
11301 | switch (b->type) |
11302 | { | |
11303 | case bp_finish: | |
11304 | ui_out_field_string | |
11305 | (uiout, "reason", | |
11306 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
11307 | break; | |
348d480f | 11308 | |
001c8c33 PA |
11309 | case bp_until: |
11310 | ui_out_field_string | |
11311 | (uiout, "reason", | |
11312 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
11313 | break; | |
11314 | } | |
348d480f PA |
11315 | } |
11316 | ||
001c8c33 | 11317 | return PRINT_UNKNOWN; |
348d480f PA |
11318 | } |
11319 | ||
06edf0c0 PA |
11320 | static void |
11321 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 11322 | { |
06edf0c0 | 11323 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
11324 | } |
11325 | ||
348d480f | 11326 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 11327 | |
348d480f PA |
11328 | static void |
11329 | tracepoint_re_set (struct breakpoint *b) | |
11330 | { | |
11331 | breakpoint_re_set_default (b); | |
11332 | } | |
876fa593 | 11333 | |
348d480f PA |
11334 | static int |
11335 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
11336 | struct address_space *aspace, CORE_ADDR bp_addr) | |
11337 | { | |
11338 | /* By definition, the inferior does not report stops at | |
11339 | tracepoints. */ | |
11340 | return 0; | |
74960c60 VP |
11341 | } |
11342 | ||
11343 | static void | |
348d480f PA |
11344 | tracepoint_print_one_detail (const struct breakpoint *self, |
11345 | struct ui_out *uiout) | |
74960c60 | 11346 | { |
d9b3f62e PA |
11347 | struct tracepoint *tp = (struct tracepoint *) self; |
11348 | if (tp->static_trace_marker_id) | |
348d480f PA |
11349 | { |
11350 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 11351 | |
348d480f PA |
11352 | ui_out_text (uiout, "\tmarker id is "); |
11353 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 11354 | tp->static_trace_marker_id); |
348d480f PA |
11355 | ui_out_text (uiout, "\n"); |
11356 | } | |
0d381245 VP |
11357 | } |
11358 | ||
a474d7c2 | 11359 | static void |
348d480f | 11360 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 11361 | { |
79a45e25 | 11362 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 11363 | return; |
cc59ec59 | 11364 | |
348d480f PA |
11365 | switch (b->type) |
11366 | { | |
11367 | case bp_tracepoint: | |
11368 | printf_filtered (_("Tracepoint")); | |
11369 | printf_filtered (_(" %d"), b->number); | |
11370 | break; | |
11371 | case bp_fast_tracepoint: | |
11372 | printf_filtered (_("Fast tracepoint")); | |
11373 | printf_filtered (_(" %d"), b->number); | |
11374 | break; | |
11375 | case bp_static_tracepoint: | |
11376 | printf_filtered (_("Static tracepoint")); | |
11377 | printf_filtered (_(" %d"), b->number); | |
11378 | break; | |
11379 | default: | |
11380 | internal_error (__FILE__, __LINE__, | |
11381 | _("unhandled tracepoint type %d"), (int) b->type); | |
11382 | } | |
11383 | ||
11384 | say_where (b); | |
a474d7c2 PA |
11385 | } |
11386 | ||
348d480f | 11387 | static void |
d9b3f62e | 11388 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 11389 | { |
d9b3f62e PA |
11390 | struct tracepoint *tp = (struct tracepoint *) self; |
11391 | ||
11392 | if (self->type == bp_fast_tracepoint) | |
348d480f | 11393 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 11394 | if (self->type == bp_static_tracepoint) |
348d480f | 11395 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 11396 | else if (self->type == bp_tracepoint) |
348d480f PA |
11397 | fprintf_unfiltered (fp, "trace"); |
11398 | else | |
11399 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 11400 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 11401 | |
d9b3f62e PA |
11402 | fprintf_unfiltered (fp, " %s", self->addr_string); |
11403 | print_recreate_thread (self, fp); | |
11404 | ||
11405 | if (tp->pass_count) | |
11406 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
11407 | } |
11408 | ||
2060206e | 11409 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 11410 | |
53a5351d | 11411 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 11412 | structures. */ |
c906108c SS |
11413 | |
11414 | void | |
fba45db2 | 11415 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 11416 | { |
52f0bd74 | 11417 | struct breakpoint *b; |
c906108c | 11418 | |
8a3fe4f8 | 11419 | gdb_assert (bpt != NULL); |
c906108c | 11420 | |
4a64f543 MS |
11421 | /* Has this bp already been deleted? This can happen because |
11422 | multiple lists can hold pointers to bp's. bpstat lists are | |
11423 | especial culprits. | |
11424 | ||
11425 | One example of this happening is a watchpoint's scope bp. When | |
11426 | the scope bp triggers, we notice that the watchpoint is out of | |
11427 | scope, and delete it. We also delete its scope bp. But the | |
11428 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
11429 | That bpstat is then checked for auto-deleting bp's, which are | |
11430 | deleted. | |
11431 | ||
11432 | A real solution to this problem might involve reference counts in | |
11433 | bp's, and/or giving them pointers back to their referencing | |
11434 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
11435 | storage when no more references were extent. A cheaper bandaid | |
11436 | was chosen. */ | |
c906108c SS |
11437 | if (bpt->type == bp_none) |
11438 | return; | |
11439 | ||
4a64f543 MS |
11440 | /* At least avoid this stale reference until the reference counting |
11441 | of breakpoints gets resolved. */ | |
d0fb5eae | 11442 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 11443 | { |
d0fb5eae | 11444 | struct breakpoint *related; |
3a5c3e22 | 11445 | struct watchpoint *w; |
d0fb5eae JK |
11446 | |
11447 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 11448 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 11449 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
11450 | w = (struct watchpoint *) bpt; |
11451 | else | |
11452 | w = NULL; | |
11453 | if (w != NULL) | |
11454 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
11455 | |
11456 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
11457 | for (related = bpt; related->related_breakpoint != bpt; | |
11458 | related = related->related_breakpoint); | |
11459 | related->related_breakpoint = bpt->related_breakpoint; | |
11460 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
11461 | } |
11462 | ||
a9634178 TJB |
11463 | /* watch_command_1 creates a watchpoint but only sets its number if |
11464 | update_watchpoint succeeds in creating its bp_locations. If there's | |
11465 | a problem in that process, we'll be asked to delete the half-created | |
11466 | watchpoint. In that case, don't announce the deletion. */ | |
11467 | if (bpt->number) | |
11468 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 11469 | |
c906108c SS |
11470 | if (breakpoint_chain == bpt) |
11471 | breakpoint_chain = bpt->next; | |
11472 | ||
c906108c SS |
11473 | ALL_BREAKPOINTS (b) |
11474 | if (b->next == bpt) | |
c5aa993b JM |
11475 | { |
11476 | b->next = bpt->next; | |
11477 | break; | |
11478 | } | |
c906108c | 11479 | |
f431efe5 PA |
11480 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
11481 | been freed. */ | |
11482 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 11483 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
11484 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
11485 | commands are associated with the bpstat; if we remove it here, | |
11486 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
11487 | event-top.c won't do anything, and temporary breakpoints with | |
11488 | commands won't work. */ | |
11489 | ||
11490 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
11491 | ||
4a64f543 MS |
11492 | /* Now that breakpoint is removed from breakpoint list, update the |
11493 | global location list. This will remove locations that used to | |
11494 | belong to this breakpoint. Do this before freeing the breakpoint | |
11495 | itself, since remove_breakpoint looks at location's owner. It | |
11496 | might be better design to have location completely | |
11497 | self-contained, but it's not the case now. */ | |
b60e7edf | 11498 | update_global_location_list (0); |
74960c60 | 11499 | |
348d480f | 11500 | bpt->ops->dtor (bpt); |
4a64f543 MS |
11501 | /* On the chance that someone will soon try again to delete this |
11502 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 11503 | bpt->type = bp_none; |
b8c9b27d | 11504 | xfree (bpt); |
c906108c SS |
11505 | } |
11506 | ||
4d6140d9 AC |
11507 | static void |
11508 | do_delete_breakpoint_cleanup (void *b) | |
11509 | { | |
11510 | delete_breakpoint (b); | |
11511 | } | |
11512 | ||
11513 | struct cleanup * | |
11514 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
11515 | { | |
11516 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
11517 | } | |
11518 | ||
51be5b68 PA |
11519 | /* Iterator function to call a user-provided callback function once |
11520 | for each of B and its related breakpoints. */ | |
11521 | ||
11522 | static void | |
11523 | iterate_over_related_breakpoints (struct breakpoint *b, | |
11524 | void (*function) (struct breakpoint *, | |
11525 | void *), | |
11526 | void *data) | |
11527 | { | |
11528 | struct breakpoint *related; | |
11529 | ||
11530 | related = b; | |
11531 | do | |
11532 | { | |
11533 | struct breakpoint *next; | |
11534 | ||
11535 | /* FUNCTION may delete RELATED. */ | |
11536 | next = related->related_breakpoint; | |
11537 | ||
11538 | if (next == related) | |
11539 | { | |
11540 | /* RELATED is the last ring entry. */ | |
11541 | function (related, data); | |
11542 | ||
11543 | /* FUNCTION may have deleted it, so we'd never reach back to | |
11544 | B. There's nothing left to do anyway, so just break | |
11545 | out. */ | |
11546 | break; | |
11547 | } | |
11548 | else | |
11549 | function (related, data); | |
11550 | ||
11551 | related = next; | |
11552 | } | |
11553 | while (related != b); | |
11554 | } | |
95a42b64 TT |
11555 | |
11556 | static void | |
11557 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11558 | { | |
11559 | delete_breakpoint (b); | |
11560 | } | |
11561 | ||
51be5b68 PA |
11562 | /* A callback for map_breakpoint_numbers that calls |
11563 | delete_breakpoint. */ | |
11564 | ||
11565 | static void | |
11566 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11567 | { | |
11568 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
11569 | } | |
11570 | ||
c906108c | 11571 | void |
fba45db2 | 11572 | delete_command (char *arg, int from_tty) |
c906108c | 11573 | { |
35df4500 | 11574 | struct breakpoint *b, *b_tmp; |
c906108c | 11575 | |
ea9365bb TT |
11576 | dont_repeat (); |
11577 | ||
c906108c SS |
11578 | if (arg == 0) |
11579 | { | |
11580 | int breaks_to_delete = 0; | |
11581 | ||
46c6471b PA |
11582 | /* Delete all breakpoints if no argument. Do not delete |
11583 | internal breakpoints, these have to be deleted with an | |
11584 | explicit breakpoint number argument. */ | |
c5aa993b | 11585 | ALL_BREAKPOINTS (b) |
46c6471b | 11586 | if (user_breakpoint_p (b)) |
973d738b DJ |
11587 | { |
11588 | breaks_to_delete = 1; | |
11589 | break; | |
11590 | } | |
c906108c SS |
11591 | |
11592 | /* Ask user only if there are some breakpoints to delete. */ | |
11593 | if (!from_tty | |
e2e0b3e5 | 11594 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 11595 | { |
35df4500 | 11596 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 11597 | if (user_breakpoint_p (b)) |
c5aa993b | 11598 | delete_breakpoint (b); |
c906108c SS |
11599 | } |
11600 | } | |
11601 | else | |
51be5b68 | 11602 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
11603 | } |
11604 | ||
0d381245 VP |
11605 | static int |
11606 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 11607 | { |
0d381245 VP |
11608 | for (; loc; loc = loc->next) |
11609 | if (!loc->shlib_disabled) | |
11610 | return 0; | |
11611 | return 1; | |
fe3f5fa8 VP |
11612 | } |
11613 | ||
776592bf DE |
11614 | /* Subroutine of update_breakpoint_locations to simplify it. |
11615 | Return non-zero if multiple fns in list LOC have the same name. | |
11616 | Null names are ignored. */ | |
11617 | ||
11618 | static int | |
11619 | ambiguous_names_p (struct bp_location *loc) | |
11620 | { | |
11621 | struct bp_location *l; | |
11622 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
11623 | (int (*) (const void *, |
11624 | const void *)) streq, | |
776592bf DE |
11625 | NULL, xcalloc, xfree); |
11626 | ||
11627 | for (l = loc; l != NULL; l = l->next) | |
11628 | { | |
11629 | const char **slot; | |
11630 | const char *name = l->function_name; | |
11631 | ||
11632 | /* Allow for some names to be NULL, ignore them. */ | |
11633 | if (name == NULL) | |
11634 | continue; | |
11635 | ||
11636 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
11637 | INSERT); | |
4a64f543 MS |
11638 | /* NOTE: We can assume slot != NULL here because xcalloc never |
11639 | returns NULL. */ | |
776592bf DE |
11640 | if (*slot != NULL) |
11641 | { | |
11642 | htab_delete (htab); | |
11643 | return 1; | |
11644 | } | |
11645 | *slot = name; | |
11646 | } | |
11647 | ||
11648 | htab_delete (htab); | |
11649 | return 0; | |
11650 | } | |
11651 | ||
0fb4aa4b PA |
11652 | /* When symbols change, it probably means the sources changed as well, |
11653 | and it might mean the static tracepoint markers are no longer at | |
11654 | the same address or line numbers they used to be at last we | |
11655 | checked. Losing your static tracepoints whenever you rebuild is | |
11656 | undesirable. This function tries to resync/rematch gdb static | |
11657 | tracepoints with the markers on the target, for static tracepoints | |
11658 | that have not been set by marker id. Static tracepoint that have | |
11659 | been set by marker id are reset by marker id in breakpoint_re_set. | |
11660 | The heuristic is: | |
11661 | ||
11662 | 1) For a tracepoint set at a specific address, look for a marker at | |
11663 | the old PC. If one is found there, assume to be the same marker. | |
11664 | If the name / string id of the marker found is different from the | |
11665 | previous known name, assume that means the user renamed the marker | |
11666 | in the sources, and output a warning. | |
11667 | ||
11668 | 2) For a tracepoint set at a given line number, look for a marker | |
11669 | at the new address of the old line number. If one is found there, | |
11670 | assume to be the same marker. If the name / string id of the | |
11671 | marker found is different from the previous known name, assume that | |
11672 | means the user renamed the marker in the sources, and output a | |
11673 | warning. | |
11674 | ||
11675 | 3) If a marker is no longer found at the same address or line, it | |
11676 | may mean the marker no longer exists. But it may also just mean | |
11677 | the code changed a bit. Maybe the user added a few lines of code | |
11678 | that made the marker move up or down (in line number terms). Ask | |
11679 | the target for info about the marker with the string id as we knew | |
11680 | it. If found, update line number and address in the matching | |
11681 | static tracepoint. This will get confused if there's more than one | |
11682 | marker with the same ID (possible in UST, although unadvised | |
11683 | precisely because it confuses tools). */ | |
11684 | ||
11685 | static struct symtab_and_line | |
11686 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
11687 | { | |
d9b3f62e | 11688 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
11689 | struct static_tracepoint_marker marker; |
11690 | CORE_ADDR pc; | |
11691 | int i; | |
11692 | ||
11693 | pc = sal.pc; | |
11694 | if (sal.line) | |
11695 | find_line_pc (sal.symtab, sal.line, &pc); | |
11696 | ||
11697 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
11698 | { | |
d9b3f62e | 11699 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
11700 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
11701 | b->number, | |
d9b3f62e | 11702 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 11703 | |
d9b3f62e PA |
11704 | xfree (tp->static_trace_marker_id); |
11705 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
11706 | release_static_tracepoint_marker (&marker); |
11707 | ||
11708 | return sal; | |
11709 | } | |
11710 | ||
11711 | /* Old marker wasn't found on target at lineno. Try looking it up | |
11712 | by string ID. */ | |
11713 | if (!sal.explicit_pc | |
11714 | && sal.line != 0 | |
11715 | && sal.symtab != NULL | |
d9b3f62e | 11716 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
11717 | { |
11718 | VEC(static_tracepoint_marker_p) *markers; | |
11719 | ||
11720 | markers | |
d9b3f62e | 11721 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
11722 | |
11723 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
11724 | { | |
11725 | struct symtab_and_line sal; | |
11726 | struct symbol *sym; | |
11727 | struct static_tracepoint_marker *marker; | |
79a45e25 | 11728 | struct ui_out *uiout = current_uiout; |
0fb4aa4b PA |
11729 | |
11730 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
11731 | ||
d9b3f62e PA |
11732 | xfree (tp->static_trace_marker_id); |
11733 | tp->static_trace_marker_id = xstrdup (marker->str_id); | |
0fb4aa4b PA |
11734 | |
11735 | warning (_("marker for static tracepoint %d (%s) not " | |
11736 | "found at previous line number"), | |
d9b3f62e | 11737 | b->number, tp->static_trace_marker_id); |
0fb4aa4b PA |
11738 | |
11739 | init_sal (&sal); | |
11740 | ||
11741 | sal.pc = marker->address; | |
11742 | ||
11743 | sal = find_pc_line (marker->address, 0); | |
11744 | sym = find_pc_sect_function (marker->address, NULL); | |
11745 | ui_out_text (uiout, "Now in "); | |
11746 | if (sym) | |
11747 | { | |
11748 | ui_out_field_string (uiout, "func", | |
11749 | SYMBOL_PRINT_NAME (sym)); | |
11750 | ui_out_text (uiout, " at "); | |
11751 | } | |
11752 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
11753 | ui_out_text (uiout, ":"); | |
11754 | ||
11755 | if (ui_out_is_mi_like_p (uiout)) | |
11756 | { | |
11757 | char *fullname = symtab_to_fullname (sal.symtab); | |
11758 | ||
11759 | if (fullname) | |
11760 | ui_out_field_string (uiout, "fullname", fullname); | |
11761 | } | |
11762 | ||
11763 | ui_out_field_int (uiout, "line", sal.line); | |
11764 | ui_out_text (uiout, "\n"); | |
11765 | ||
11766 | b->line_number = sal.line; | |
11767 | ||
11768 | xfree (b->source_file); | |
11769 | if (sym) | |
11770 | b->source_file = xstrdup (sal.symtab->filename); | |
11771 | else | |
11772 | b->source_file = NULL; | |
11773 | ||
11774 | xfree (b->addr_string); | |
11775 | b->addr_string = xstrprintf ("%s:%d", | |
11776 | sal.symtab->filename, b->line_number); | |
11777 | ||
11778 | /* Might be nice to check if function changed, and warn if | |
11779 | so. */ | |
11780 | ||
11781 | release_static_tracepoint_marker (marker); | |
11782 | } | |
11783 | } | |
11784 | return sal; | |
11785 | } | |
11786 | ||
8d3788bd VP |
11787 | /* Returns 1 iff locations A and B are sufficiently same that |
11788 | we don't need to report breakpoint as changed. */ | |
11789 | ||
11790 | static int | |
11791 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
11792 | { | |
11793 | while (a && b) | |
11794 | { | |
11795 | if (a->address != b->address) | |
11796 | return 0; | |
11797 | ||
11798 | if (a->shlib_disabled != b->shlib_disabled) | |
11799 | return 0; | |
11800 | ||
11801 | if (a->enabled != b->enabled) | |
11802 | return 0; | |
11803 | ||
11804 | a = a->next; | |
11805 | b = b->next; | |
11806 | } | |
11807 | ||
11808 | if ((a == NULL) != (b == NULL)) | |
11809 | return 0; | |
11810 | ||
11811 | return 1; | |
11812 | } | |
11813 | ||
f1310107 TJB |
11814 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
11815 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
11816 | a ranged breakpoint. */ | |
11817 | ||
0e30163f | 11818 | void |
0d381245 | 11819 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
11820 | struct symtabs_and_lines sals, |
11821 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
11822 | { |
11823 | int i; | |
0d381245 VP |
11824 | struct bp_location *existing_locations = b->loc; |
11825 | ||
f1310107 TJB |
11826 | /* Ranged breakpoints have only one start location and one end location. */ |
11827 | gdb_assert (sals_end.nelts == 0 || (sals.nelts == 1 && sals_end.nelts == 1)); | |
11828 | ||
4a64f543 MS |
11829 | /* If there's no new locations, and all existing locations are |
11830 | pending, don't do anything. This optimizes the common case where | |
11831 | all locations are in the same shared library, that was unloaded. | |
11832 | We'd like to retain the location, so that when the library is | |
11833 | loaded again, we don't loose the enabled/disabled status of the | |
11834 | individual locations. */ | |
0d381245 | 11835 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
11836 | return; |
11837 | ||
fe3f5fa8 VP |
11838 | b->loc = NULL; |
11839 | ||
0d381245 | 11840 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 11841 | { |
0d381245 | 11842 | struct bp_location *new_loc = |
39d61571 | 11843 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 11844 | |
0d381245 VP |
11845 | /* Reparse conditions, they might contain references to the |
11846 | old symtab. */ | |
11847 | if (b->cond_string != NULL) | |
11848 | { | |
f1310107 | 11849 | char *s; |
0d381245 | 11850 | struct gdb_exception e; |
fe3f5fa8 | 11851 | |
0d381245 VP |
11852 | s = b->cond_string; |
11853 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11854 | { | |
11855 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
11856 | 0); | |
11857 | } | |
11858 | if (e.reason < 0) | |
11859 | { | |
3e43a32a MS |
11860 | warning (_("failed to reevaluate condition " |
11861 | "for breakpoint %d: %s"), | |
0d381245 VP |
11862 | b->number, e.message); |
11863 | new_loc->enabled = 0; | |
11864 | } | |
11865 | } | |
fe3f5fa8 | 11866 | |
0d381245 VP |
11867 | if (b->source_file != NULL) |
11868 | xfree (b->source_file); | |
11869 | if (sals.sals[i].symtab == NULL) | |
11870 | b->source_file = NULL; | |
11871 | else | |
1b36a34b | 11872 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 11873 | |
0d381245 VP |
11874 | if (b->line_number == 0) |
11875 | b->line_number = sals.sals[i].line; | |
f1310107 TJB |
11876 | |
11877 | if (sals_end.nelts) | |
11878 | { | |
11879 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
11880 | ||
11881 | new_loc->length = end - sals.sals[0].pc + 1; | |
11882 | } | |
0d381245 | 11883 | } |
fe3f5fa8 | 11884 | |
514f746b AR |
11885 | /* Update locations of permanent breakpoints. */ |
11886 | if (b->enable_state == bp_permanent) | |
11887 | make_breakpoint_permanent (b); | |
11888 | ||
4a64f543 MS |
11889 | /* If possible, carry over 'disable' status from existing |
11890 | breakpoints. */ | |
0d381245 VP |
11891 | { |
11892 | struct bp_location *e = existing_locations; | |
776592bf DE |
11893 | /* If there are multiple breakpoints with the same function name, |
11894 | e.g. for inline functions, comparing function names won't work. | |
11895 | Instead compare pc addresses; this is just a heuristic as things | |
11896 | may have moved, but in practice it gives the correct answer | |
11897 | often enough until a better solution is found. */ | |
11898 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
11899 | ||
0d381245 VP |
11900 | for (; e; e = e->next) |
11901 | { | |
11902 | if (!e->enabled && e->function_name) | |
11903 | { | |
11904 | struct bp_location *l = b->loc; | |
776592bf DE |
11905 | if (have_ambiguous_names) |
11906 | { | |
11907 | for (; l; l = l->next) | |
f1310107 | 11908 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
11909 | { |
11910 | l->enabled = 0; | |
11911 | break; | |
11912 | } | |
11913 | } | |
11914 | else | |
11915 | { | |
11916 | for (; l; l = l->next) | |
11917 | if (l->function_name | |
11918 | && strcmp (e->function_name, l->function_name) == 0) | |
11919 | { | |
11920 | l->enabled = 0; | |
11921 | break; | |
11922 | } | |
11923 | } | |
0d381245 VP |
11924 | } |
11925 | } | |
11926 | } | |
fe3f5fa8 | 11927 | |
8d3788bd VP |
11928 | if (!locations_are_equal (existing_locations, b->loc)) |
11929 | observer_notify_breakpoint_modified (b); | |
11930 | ||
b60e7edf | 11931 | update_global_location_list (1); |
fe3f5fa8 VP |
11932 | } |
11933 | ||
ef23e705 TJB |
11934 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
11935 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
11936 | ||
11937 | static struct symtabs_and_lines | |
11938 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
11939 | { | |
11940 | char *s; | |
58438ac1 | 11941 | int marker_spec; |
02d20e4a | 11942 | struct symtabs_and_lines sals = {0}; |
ef23e705 TJB |
11943 | struct gdb_exception e; |
11944 | ||
11945 | s = addr_string; | |
11946 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); | |
11947 | ||
11948 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11949 | { | |
11950 | if (marker_spec) | |
11951 | { | |
d9b3f62e PA |
11952 | struct tracepoint *tp = (struct tracepoint *) b; |
11953 | ||
ef23e705 | 11954 | sals = decode_static_tracepoint_spec (&s); |
d9b3f62e | 11955 | if (sals.nelts > tp->static_trace_marker_id_idx) |
ef23e705 | 11956 | { |
d9b3f62e | 11957 | sals.sals[0] = sals.sals[tp->static_trace_marker_id_idx]; |
ef23e705 TJB |
11958 | sals.nelts = 1; |
11959 | } | |
11960 | else | |
d9b3f62e | 11961 | error (_("marker %s not found"), tp->static_trace_marker_id); |
ef23e705 TJB |
11962 | } |
11963 | else | |
58438ac1 | 11964 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, NULL); |
ef23e705 TJB |
11965 | } |
11966 | if (e.reason < 0) | |
11967 | { | |
11968 | int not_found_and_ok = 0; | |
11969 | /* For pending breakpoints, it's expected that parsing will | |
11970 | fail until the right shared library is loaded. User has | |
11971 | already told to create pending breakpoints and don't need | |
11972 | extra messages. If breakpoint is in bp_shlib_disabled | |
11973 | state, then user already saw the message about that | |
11974 | breakpoint being disabled, and don't want to see more | |
11975 | errors. */ | |
58438ac1 | 11976 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
11977 | && (b->condition_not_parsed |
11978 | || (b->loc && b->loc->shlib_disabled) | |
11979 | || b->enable_state == bp_disabled)) | |
11980 | not_found_and_ok = 1; | |
11981 | ||
11982 | if (!not_found_and_ok) | |
11983 | { | |
11984 | /* We surely don't want to warn about the same breakpoint | |
11985 | 10 times. One solution, implemented here, is disable | |
11986 | the breakpoint on error. Another solution would be to | |
11987 | have separate 'warning emitted' flag. Since this | |
11988 | happens only when a binary has changed, I don't know | |
11989 | which approach is better. */ | |
11990 | b->enable_state = bp_disabled; | |
11991 | throw_exception (e); | |
11992 | } | |
11993 | } | |
11994 | ||
58438ac1 | 11995 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 TJB |
11996 | { |
11997 | gdb_assert (sals.nelts == 1); | |
11998 | ||
11999 | resolve_sal_pc (&sals.sals[0]); | |
12000 | if (b->condition_not_parsed && s && s[0]) | |
12001 | { | |
12002 | char *cond_string = 0; | |
12003 | int thread = -1; | |
12004 | int task = 0; | |
12005 | ||
12006 | find_condition_and_thread (s, sals.sals[0].pc, | |
12007 | &cond_string, &thread, &task); | |
12008 | if (cond_string) | |
12009 | b->cond_string = cond_string; | |
12010 | b->thread = thread; | |
12011 | b->task = task; | |
12012 | b->condition_not_parsed = 0; | |
12013 | } | |
12014 | ||
12015 | if (b->type == bp_static_tracepoint && !marker_spec) | |
12016 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
ef23e705 | 12017 | |
58438ac1 TT |
12018 | *found = 1; |
12019 | } | |
12020 | else | |
12021 | *found = 0; | |
ef23e705 TJB |
12022 | |
12023 | return sals; | |
12024 | } | |
12025 | ||
348d480f PA |
12026 | /* The default re_set method, for typical hardware or software |
12027 | breakpoints. Reevaluate the breakpoint and recreate its | |
12028 | locations. */ | |
12029 | ||
12030 | static void | |
28010a5d | 12031 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
12032 | { |
12033 | int found; | |
f1310107 | 12034 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 12035 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 12036 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
12037 | |
12038 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
12039 | if (found) | |
12040 | { | |
12041 | make_cleanup (xfree, sals.sals); | |
12042 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
12043 | } | |
12044 | ||
f1310107 TJB |
12045 | if (b->addr_string_range_end) |
12046 | { | |
12047 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
12048 | if (found) | |
12049 | { | |
12050 | make_cleanup (xfree, sals_end.sals); | |
12051 | expanded_end = expand_line_sal_maybe (sals_end.sals[0]); | |
12052 | } | |
12053 | } | |
12054 | ||
12055 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
12056 | } |
12057 | ||
12058 | /* Prepare the global context for a re-set of breakpoint B. */ | |
12059 | ||
12060 | static struct cleanup * | |
12061 | prepare_re_set_context (struct breakpoint *b) | |
12062 | { | |
12063 | struct cleanup *cleanups; | |
12064 | ||
12065 | input_radix = b->input_radix; | |
12066 | cleanups = save_current_space_and_thread (); | |
12067 | switch_to_program_space_and_thread (b->pspace); | |
12068 | set_language (b->language); | |
12069 | ||
12070 | return cleanups; | |
ef23e705 TJB |
12071 | } |
12072 | ||
c906108c SS |
12073 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
12074 | The value we return ends up being the return value from catch_errors. | |
12075 | Unused in this case. */ | |
12076 | ||
12077 | static int | |
4efb68b1 | 12078 | breakpoint_re_set_one (void *bint) |
c906108c | 12079 | { |
4a64f543 | 12080 | /* Get past catch_errs. */ |
53a5351d | 12081 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 12082 | struct cleanup *cleanups; |
c906108c | 12083 | |
348d480f PA |
12084 | cleanups = prepare_re_set_context (b); |
12085 | b->ops->re_set (b); | |
12086 | do_cleanups (cleanups); | |
c906108c SS |
12087 | return 0; |
12088 | } | |
12089 | ||
69de3c6a | 12090 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 12091 | void |
69de3c6a | 12092 | breakpoint_re_set (void) |
c906108c | 12093 | { |
35df4500 | 12094 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12095 | enum language save_language; |
12096 | int save_input_radix; | |
6c95b8df | 12097 | struct cleanup *old_chain; |
c5aa993b | 12098 | |
c906108c SS |
12099 | save_language = current_language->la_language; |
12100 | save_input_radix = input_radix; | |
6c95b8df PA |
12101 | old_chain = save_current_program_space (); |
12102 | ||
35df4500 | 12103 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12104 | { |
4a64f543 | 12105 | /* Format possible error msg. */ |
fe3f5fa8 | 12106 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
12107 | b->number); |
12108 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 12109 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 12110 | do_cleanups (cleanups); |
c5aa993b | 12111 | } |
c906108c SS |
12112 | set_language (save_language); |
12113 | input_radix = save_input_radix; | |
e62c965a | 12114 | |
0756c555 | 12115 | jit_breakpoint_re_set (); |
4efc6507 | 12116 | |
6c95b8df PA |
12117 | do_cleanups (old_chain); |
12118 | ||
af02033e PP |
12119 | create_overlay_event_breakpoint (); |
12120 | create_longjmp_master_breakpoint (); | |
12121 | create_std_terminate_master_breakpoint (); | |
186c406b | 12122 | create_exception_master_breakpoint (); |
1bfeeb0f JL |
12123 | |
12124 | /* While we're at it, reset the skip list too. */ | |
12125 | skip_re_set (); | |
c906108c SS |
12126 | } |
12127 | \f | |
c906108c SS |
12128 | /* Reset the thread number of this breakpoint: |
12129 | ||
12130 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 12131 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 12132 | void |
fba45db2 | 12133 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
12134 | { |
12135 | if (b->thread != -1) | |
12136 | { | |
39f77062 KB |
12137 | if (in_thread_list (inferior_ptid)) |
12138 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
12139 | |
12140 | /* We're being called after following a fork. The new fork is | |
12141 | selected as current, and unless this was a vfork will have a | |
12142 | different program space from the original thread. Reset that | |
12143 | as well. */ | |
12144 | b->loc->pspace = current_program_space; | |
c906108c SS |
12145 | } |
12146 | } | |
12147 | ||
03ac34d5 MS |
12148 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
12149 | If from_tty is nonzero, it prints a message to that effect, | |
12150 | which ends with a period (no newline). */ | |
12151 | ||
c906108c | 12152 | void |
fba45db2 | 12153 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 12154 | { |
52f0bd74 | 12155 | struct breakpoint *b; |
c906108c SS |
12156 | |
12157 | if (count < 0) | |
12158 | count = 0; | |
12159 | ||
12160 | ALL_BREAKPOINTS (b) | |
12161 | if (b->number == bptnum) | |
c5aa993b | 12162 | { |
d77f58be SS |
12163 | if (is_tracepoint (b)) |
12164 | { | |
12165 | if (from_tty && count != 0) | |
12166 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
12167 | bptnum); | |
12168 | return; | |
12169 | } | |
12170 | ||
c5aa993b | 12171 | b->ignore_count = count; |
221ea385 KS |
12172 | if (from_tty) |
12173 | { | |
12174 | if (count == 0) | |
3e43a32a MS |
12175 | printf_filtered (_("Will stop next time " |
12176 | "breakpoint %d is reached."), | |
221ea385 KS |
12177 | bptnum); |
12178 | else if (count == 1) | |
a3f17187 | 12179 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
12180 | bptnum); |
12181 | else | |
3e43a32a MS |
12182 | printf_filtered (_("Will ignore next %d " |
12183 | "crossings of breakpoint %d."), | |
221ea385 KS |
12184 | count, bptnum); |
12185 | } | |
c5aa993b | 12186 | breakpoints_changed (); |
8d3788bd | 12187 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
12188 | return; |
12189 | } | |
c906108c | 12190 | |
8a3fe4f8 | 12191 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
12192 | } |
12193 | ||
c906108c SS |
12194 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
12195 | ||
12196 | static void | |
fba45db2 | 12197 | ignore_command (char *args, int from_tty) |
c906108c SS |
12198 | { |
12199 | char *p = args; | |
52f0bd74 | 12200 | int num; |
c906108c SS |
12201 | |
12202 | if (p == 0) | |
e2e0b3e5 | 12203 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 12204 | |
c906108c | 12205 | num = get_number (&p); |
5c44784c | 12206 | if (num == 0) |
8a3fe4f8 | 12207 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 12208 | if (*p == 0) |
8a3fe4f8 | 12209 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
12210 | |
12211 | set_ignore_count (num, | |
12212 | longest_to_int (value_as_long (parse_and_eval (p))), | |
12213 | from_tty); | |
221ea385 KS |
12214 | if (from_tty) |
12215 | printf_filtered ("\n"); | |
c906108c SS |
12216 | } |
12217 | \f | |
12218 | /* Call FUNCTION on each of the breakpoints | |
12219 | whose numbers are given in ARGS. */ | |
12220 | ||
12221 | static void | |
95a42b64 TT |
12222 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
12223 | void *), | |
12224 | void *data) | |
c906108c | 12225 | { |
52f0bd74 AC |
12226 | int num; |
12227 | struct breakpoint *b, *tmp; | |
11cf8741 | 12228 | int match; |
197f0a60 | 12229 | struct get_number_or_range_state state; |
c906108c | 12230 | |
197f0a60 | 12231 | if (args == 0) |
e2e0b3e5 | 12232 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 12233 | |
197f0a60 TT |
12234 | init_number_or_range (&state, args); |
12235 | ||
12236 | while (!state.finished) | |
c906108c | 12237 | { |
197f0a60 TT |
12238 | char *p = state.string; |
12239 | ||
11cf8741 | 12240 | match = 0; |
c5aa993b | 12241 | |
197f0a60 | 12242 | num = get_number_or_range (&state); |
5c44784c | 12243 | if (num == 0) |
c5aa993b | 12244 | { |
8a3fe4f8 | 12245 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
12246 | } |
12247 | else | |
12248 | { | |
12249 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
12250 | if (b->number == num) | |
12251 | { | |
11cf8741 | 12252 | match = 1; |
cdac0397 | 12253 | function (b, data); |
11cf8741 | 12254 | break; |
5c44784c | 12255 | } |
11cf8741 | 12256 | if (match == 0) |
a3f17187 | 12257 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 12258 | } |
c906108c SS |
12259 | } |
12260 | } | |
12261 | ||
0d381245 VP |
12262 | static struct bp_location * |
12263 | find_location_by_number (char *number) | |
12264 | { | |
12265 | char *dot = strchr (number, '.'); | |
12266 | char *p1; | |
12267 | int bp_num; | |
12268 | int loc_num; | |
12269 | struct breakpoint *b; | |
12270 | struct bp_location *loc; | |
12271 | ||
12272 | *dot = '\0'; | |
12273 | ||
12274 | p1 = number; | |
197f0a60 | 12275 | bp_num = get_number (&p1); |
0d381245 VP |
12276 | if (bp_num == 0) |
12277 | error (_("Bad breakpoint number '%s'"), number); | |
12278 | ||
12279 | ALL_BREAKPOINTS (b) | |
12280 | if (b->number == bp_num) | |
12281 | { | |
12282 | break; | |
12283 | } | |
12284 | ||
12285 | if (!b || b->number != bp_num) | |
12286 | error (_("Bad breakpoint number '%s'"), number); | |
12287 | ||
12288 | p1 = dot+1; | |
197f0a60 | 12289 | loc_num = get_number (&p1); |
0d381245 VP |
12290 | if (loc_num == 0) |
12291 | error (_("Bad breakpoint location number '%s'"), number); | |
12292 | ||
12293 | --loc_num; | |
12294 | loc = b->loc; | |
12295 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
12296 | ; | |
12297 | if (!loc) | |
12298 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
12299 | ||
12300 | return loc; | |
12301 | } | |
12302 | ||
12303 | ||
1900040c MS |
12304 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
12305 | If from_tty is nonzero, it prints a message to that effect, | |
12306 | which ends with a period (no newline). */ | |
12307 | ||
c906108c | 12308 | void |
fba45db2 | 12309 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
12310 | { |
12311 | /* Never disable a watchpoint scope breakpoint; we want to | |
12312 | hit them when we leave scope so we can delete both the | |
12313 | watchpoint and its scope breakpoint at that time. */ | |
12314 | if (bpt->type == bp_watchpoint_scope) | |
12315 | return; | |
12316 | ||
c2c6d25f | 12317 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 12318 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
12319 | return; |
12320 | ||
b5de0fa7 | 12321 | bpt->enable_state = bp_disabled; |
c906108c | 12322 | |
d248b706 KY |
12323 | if (target_supports_enable_disable_tracepoint () |
12324 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12325 | { | |
12326 | struct bp_location *location; | |
12327 | ||
12328 | for (location = bpt->loc; location; location = location->next) | |
12329 | target_disable_tracepoint (location); | |
12330 | } | |
12331 | ||
b60e7edf | 12332 | update_global_location_list (0); |
c906108c | 12333 | |
8d3788bd | 12334 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12335 | } |
12336 | ||
51be5b68 PA |
12337 | /* A callback for iterate_over_related_breakpoints. */ |
12338 | ||
12339 | static void | |
12340 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12341 | { | |
12342 | disable_breakpoint (b); | |
12343 | } | |
12344 | ||
95a42b64 TT |
12345 | /* A callback for map_breakpoint_numbers that calls |
12346 | disable_breakpoint. */ | |
12347 | ||
12348 | static void | |
12349 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12350 | { | |
51be5b68 | 12351 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
12352 | } |
12353 | ||
c906108c | 12354 | static void |
fba45db2 | 12355 | disable_command (char *args, int from_tty) |
c906108c | 12356 | { |
c906108c | 12357 | if (args == 0) |
46c6471b PA |
12358 | { |
12359 | struct breakpoint *bpt; | |
12360 | ||
12361 | ALL_BREAKPOINTS (bpt) | |
12362 | if (user_breakpoint_p (bpt)) | |
12363 | disable_breakpoint (bpt); | |
12364 | } | |
0d381245 VP |
12365 | else if (strchr (args, '.')) |
12366 | { | |
12367 | struct bp_location *loc = find_location_by_number (args); | |
12368 | if (loc) | |
d248b706 KY |
12369 | { |
12370 | loc->enabled = 0; | |
12371 | if (target_supports_enable_disable_tracepoint () | |
12372 | && current_trace_status ()->running && loc->owner | |
12373 | && is_tracepoint (loc->owner)) | |
12374 | target_disable_tracepoint (loc); | |
12375 | } | |
b60e7edf | 12376 | update_global_location_list (0); |
0d381245 | 12377 | } |
c906108c | 12378 | else |
95a42b64 | 12379 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
12380 | } |
12381 | ||
12382 | static void | |
51be5b68 | 12383 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 12384 | { |
afe38095 | 12385 | int target_resources_ok; |
c906108c SS |
12386 | |
12387 | if (bpt->type == bp_hardware_breakpoint) | |
12388 | { | |
12389 | int i; | |
c5aa993b | 12390 | i = hw_breakpoint_used_count (); |
53a5351d | 12391 | target_resources_ok = |
d92524f1 | 12392 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 12393 | i + 1, 0); |
c906108c | 12394 | if (target_resources_ok == 0) |
8a3fe4f8 | 12395 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 12396 | else if (target_resources_ok < 0) |
8a3fe4f8 | 12397 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
12398 | } |
12399 | ||
cc60f2e3 | 12400 | if (is_watchpoint (bpt)) |
c906108c | 12401 | { |
d07205c2 JK |
12402 | /* Initialize it just to avoid a GCC false warning. */ |
12403 | enum enable_state orig_enable_state = 0; | |
dde02812 ES |
12404 | struct gdb_exception e; |
12405 | ||
12406 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 12407 | { |
3a5c3e22 PA |
12408 | struct watchpoint *w = (struct watchpoint *) bpt; |
12409 | ||
1e718ff1 TJB |
12410 | orig_enable_state = bpt->enable_state; |
12411 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 12412 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 12413 | } |
dde02812 | 12414 | if (e.reason < 0) |
c5aa993b | 12415 | { |
1e718ff1 | 12416 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
12417 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
12418 | bpt->number); | |
12419 | return; | |
c5aa993b | 12420 | } |
c906108c | 12421 | } |
0101ce28 | 12422 | |
b4c291bb KH |
12423 | if (bpt->enable_state != bp_permanent) |
12424 | bpt->enable_state = bp_enabled; | |
d248b706 KY |
12425 | |
12426 | if (target_supports_enable_disable_tracepoint () | |
12427 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12428 | { | |
12429 | struct bp_location *location; | |
12430 | ||
12431 | for (location = bpt->loc; location; location = location->next) | |
12432 | target_enable_tracepoint (location); | |
12433 | } | |
12434 | ||
b4c291bb | 12435 | bpt->disposition = disposition; |
b60e7edf | 12436 | update_global_location_list (1); |
b4c291bb KH |
12437 | breakpoints_changed (); |
12438 | ||
8d3788bd | 12439 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12440 | } |
12441 | ||
fe3f5fa8 | 12442 | |
c906108c | 12443 | void |
fba45db2 | 12444 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 12445 | { |
51be5b68 PA |
12446 | enable_breakpoint_disp (bpt, bpt->disposition); |
12447 | } | |
12448 | ||
12449 | static void | |
12450 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
12451 | { | |
12452 | enable_breakpoint (bpt); | |
c906108c SS |
12453 | } |
12454 | ||
95a42b64 TT |
12455 | /* A callback for map_breakpoint_numbers that calls |
12456 | enable_breakpoint. */ | |
12457 | ||
12458 | static void | |
12459 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
12460 | { | |
51be5b68 | 12461 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
12462 | } |
12463 | ||
c906108c SS |
12464 | /* The enable command enables the specified breakpoints (or all defined |
12465 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 12466 | in stopping the inferior. */ |
c906108c | 12467 | |
c906108c | 12468 | static void |
fba45db2 | 12469 | enable_command (char *args, int from_tty) |
c906108c | 12470 | { |
c906108c | 12471 | if (args == 0) |
46c6471b PA |
12472 | { |
12473 | struct breakpoint *bpt; | |
12474 | ||
12475 | ALL_BREAKPOINTS (bpt) | |
12476 | if (user_breakpoint_p (bpt)) | |
12477 | enable_breakpoint (bpt); | |
12478 | } | |
0d381245 VP |
12479 | else if (strchr (args, '.')) |
12480 | { | |
12481 | struct bp_location *loc = find_location_by_number (args); | |
12482 | if (loc) | |
d248b706 KY |
12483 | { |
12484 | loc->enabled = 1; | |
12485 | if (target_supports_enable_disable_tracepoint () | |
12486 | && current_trace_status ()->running && loc->owner | |
12487 | && is_tracepoint (loc->owner)) | |
12488 | target_enable_tracepoint (loc); | |
12489 | } | |
b60e7edf | 12490 | update_global_location_list (1); |
0d381245 | 12491 | } |
c906108c | 12492 | else |
95a42b64 | 12493 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
12494 | } |
12495 | ||
12496 | static void | |
51be5b68 PA |
12497 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
12498 | { | |
12499 | enum bpdisp disp = *(enum bpdisp *) arg; | |
12500 | ||
12501 | enable_breakpoint_disp (bpt, disp); | |
12502 | } | |
12503 | ||
12504 | static void | |
12505 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 12506 | { |
51be5b68 PA |
12507 | enum bpdisp disp = disp_disable; |
12508 | ||
12509 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12510 | } |
12511 | ||
c906108c | 12512 | static void |
fba45db2 | 12513 | enable_once_command (char *args, int from_tty) |
c906108c | 12514 | { |
51be5b68 | 12515 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
12516 | } |
12517 | ||
12518 | static void | |
51be5b68 | 12519 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 12520 | { |
51be5b68 PA |
12521 | enum bpdisp disp = disp_del; |
12522 | ||
12523 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12524 | } |
12525 | ||
c906108c | 12526 | static void |
fba45db2 | 12527 | enable_delete_command (char *args, int from_tty) |
c906108c | 12528 | { |
51be5b68 | 12529 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
12530 | } |
12531 | \f | |
fa8d40ab JJ |
12532 | static void |
12533 | set_breakpoint_cmd (char *args, int from_tty) | |
12534 | { | |
12535 | } | |
12536 | ||
12537 | static void | |
12538 | show_breakpoint_cmd (char *args, int from_tty) | |
12539 | { | |
12540 | } | |
12541 | ||
1f3b5d1b PP |
12542 | /* Invalidate last known value of any hardware watchpoint if |
12543 | the memory which that value represents has been written to by | |
12544 | GDB itself. */ | |
12545 | ||
12546 | static void | |
12547 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
12548 | const bfd_byte *data) | |
12549 | { | |
12550 | struct breakpoint *bp; | |
12551 | ||
12552 | ALL_BREAKPOINTS (bp) | |
12553 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 12554 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 12555 | { |
3a5c3e22 | 12556 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 12557 | |
3a5c3e22 PA |
12558 | if (wp->val_valid && wp->val) |
12559 | { | |
12560 | struct bp_location *loc; | |
12561 | ||
12562 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
12563 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
12564 | && loc->address + loc->length > addr | |
12565 | && addr + len > loc->address) | |
12566 | { | |
12567 | value_free (wp->val); | |
12568 | wp->val = NULL; | |
12569 | wp->val_valid = 0; | |
12570 | } | |
12571 | } | |
1f3b5d1b PP |
12572 | } |
12573 | } | |
12574 | ||
1bfeeb0f JL |
12575 | /* Use the last displayed codepoint's values, or nothing |
12576 | if they aren't valid. */ | |
c906108c SS |
12577 | |
12578 | struct symtabs_and_lines | |
fba45db2 | 12579 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
12580 | { |
12581 | struct symtabs_and_lines sals; | |
cc59ec59 | 12582 | |
c906108c | 12583 | if (string == 0) |
8a3fe4f8 | 12584 | error (_("Empty line specification.")); |
1bfeeb0f | 12585 | if (last_displayed_sal_is_valid ()) |
c906108c | 12586 | sals = decode_line_1 (&string, funfirstline, |
1bfeeb0f JL |
12587 | get_last_displayed_symtab (), |
12588 | get_last_displayed_line (), | |
58438ac1 | 12589 | NULL); |
c906108c SS |
12590 | else |
12591 | sals = decode_line_1 (&string, funfirstline, | |
58438ac1 | 12592 | (struct symtab *) NULL, 0, NULL); |
c906108c | 12593 | if (*string) |
8a3fe4f8 | 12594 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
12595 | return sals; |
12596 | } | |
8181d85f DJ |
12597 | |
12598 | /* Create and insert a raw software breakpoint at PC. Return an | |
12599 | identifier, which should be used to remove the breakpoint later. | |
12600 | In general, places which call this should be using something on the | |
12601 | breakpoint chain instead; this function should be eliminated | |
12602 | someday. */ | |
12603 | ||
12604 | void * | |
6c95b8df PA |
12605 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
12606 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
12607 | { |
12608 | struct bp_target_info *bp_tgt; | |
12609 | ||
6c95b8df | 12610 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 12611 | |
6c95b8df | 12612 | bp_tgt->placed_address_space = aspace; |
8181d85f | 12613 | bp_tgt->placed_address = pc; |
6c95b8df | 12614 | |
a6d9a66e | 12615 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
12616 | { |
12617 | /* Could not insert the breakpoint. */ | |
12618 | xfree (bp_tgt); | |
12619 | return NULL; | |
12620 | } | |
12621 | ||
12622 | return bp_tgt; | |
12623 | } | |
12624 | ||
4a64f543 MS |
12625 | /* Remove a breakpoint BP inserted by |
12626 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
12627 | |
12628 | int | |
a6d9a66e | 12629 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
12630 | { |
12631 | struct bp_target_info *bp_tgt = bp; | |
12632 | int ret; | |
12633 | ||
a6d9a66e | 12634 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
12635 | xfree (bp_tgt); |
12636 | ||
12637 | return ret; | |
12638 | } | |
12639 | ||
4a64f543 MS |
12640 | /* One (or perhaps two) breakpoints used for software single |
12641 | stepping. */ | |
8181d85f DJ |
12642 | |
12643 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 12644 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
12645 | |
12646 | /* Create and insert a breakpoint for software single step. */ | |
12647 | ||
12648 | void | |
6c95b8df | 12649 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
12650 | struct address_space *aspace, |
12651 | CORE_ADDR next_pc) | |
8181d85f DJ |
12652 | { |
12653 | void **bpt_p; | |
12654 | ||
12655 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
12656 | { |
12657 | bpt_p = &single_step_breakpoints[0]; | |
12658 | single_step_gdbarch[0] = gdbarch; | |
12659 | } | |
8181d85f DJ |
12660 | else |
12661 | { | |
12662 | gdb_assert (single_step_breakpoints[1] == NULL); | |
12663 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 12664 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
12665 | } |
12666 | ||
4a64f543 MS |
12667 | /* NOTE drow/2006-04-11: A future improvement to this function would |
12668 | be to only create the breakpoints once, and actually put them on | |
12669 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
12670 | We could adjust the addresses each time they were needed. Doing | |
12671 | this requires corresponding changes elsewhere where single step | |
12672 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 12673 | |
6c95b8df | 12674 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 12675 | if (*bpt_p == NULL) |
5af949e3 UW |
12676 | error (_("Could not insert single-step breakpoint at %s"), |
12677 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
12678 | } |
12679 | ||
f02253f1 HZ |
12680 | /* Check if the breakpoints used for software single stepping |
12681 | were inserted or not. */ | |
12682 | ||
12683 | int | |
12684 | single_step_breakpoints_inserted (void) | |
12685 | { | |
12686 | return (single_step_breakpoints[0] != NULL | |
12687 | || single_step_breakpoints[1] != NULL); | |
12688 | } | |
12689 | ||
8181d85f DJ |
12690 | /* Remove and delete any breakpoints used for software single step. */ |
12691 | ||
12692 | void | |
12693 | remove_single_step_breakpoints (void) | |
12694 | { | |
12695 | gdb_assert (single_step_breakpoints[0] != NULL); | |
12696 | ||
12697 | /* See insert_single_step_breakpoint for more about this deprecated | |
12698 | call. */ | |
a6d9a66e UW |
12699 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
12700 | single_step_breakpoints[0]); | |
12701 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
12702 | single_step_breakpoints[0] = NULL; |
12703 | ||
12704 | if (single_step_breakpoints[1] != NULL) | |
12705 | { | |
a6d9a66e UW |
12706 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
12707 | single_step_breakpoints[1]); | |
12708 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
12709 | single_step_breakpoints[1] = NULL; |
12710 | } | |
12711 | } | |
12712 | ||
d03285ec UW |
12713 | /* Delete software single step breakpoints without removing them from |
12714 | the inferior. This is intended to be used if the inferior's address | |
12715 | space where they were inserted is already gone, e.g. after exit or | |
12716 | exec. */ | |
12717 | ||
12718 | void | |
12719 | cancel_single_step_breakpoints (void) | |
12720 | { | |
12721 | int i; | |
12722 | ||
12723 | for (i = 0; i < 2; i++) | |
12724 | if (single_step_breakpoints[i]) | |
12725 | { | |
12726 | xfree (single_step_breakpoints[i]); | |
12727 | single_step_breakpoints[i] = NULL; | |
12728 | single_step_gdbarch[i] = NULL; | |
12729 | } | |
12730 | } | |
12731 | ||
12732 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
12733 | removing them. */ | |
12734 | ||
12735 | static void | |
12736 | detach_single_step_breakpoints (void) | |
12737 | { | |
12738 | int i; | |
12739 | ||
12740 | for (i = 0; i < 2; i++) | |
12741 | if (single_step_breakpoints[i]) | |
12742 | target_remove_breakpoint (single_step_gdbarch[i], | |
12743 | single_step_breakpoints[i]); | |
12744 | } | |
12745 | ||
4a64f543 MS |
12746 | /* Check whether a software single-step breakpoint is inserted at |
12747 | PC. */ | |
1aafd4da UW |
12748 | |
12749 | static int | |
cc59ec59 MS |
12750 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
12751 | CORE_ADDR pc) | |
1aafd4da UW |
12752 | { |
12753 | int i; | |
12754 | ||
12755 | for (i = 0; i < 2; i++) | |
12756 | { | |
12757 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
12758 | if (bp_tgt |
12759 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
12760 | bp_tgt->placed_address, | |
12761 | aspace, pc)) | |
1aafd4da UW |
12762 | return 1; |
12763 | } | |
12764 | ||
12765 | return 0; | |
12766 | } | |
12767 | ||
a96d9b2e SDJ |
12768 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
12769 | non-zero otherwise. */ | |
12770 | static int | |
12771 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
12772 | { | |
12773 | if (syscall_catchpoint_p (bp) | |
12774 | && bp->enable_state != bp_disabled | |
12775 | && bp->enable_state != bp_call_disabled) | |
12776 | return 1; | |
12777 | else | |
12778 | return 0; | |
12779 | } | |
12780 | ||
12781 | int | |
12782 | catch_syscall_enabled (void) | |
12783 | { | |
12784 | struct inferior *inf = current_inferior (); | |
12785 | ||
12786 | return inf->total_syscalls_count != 0; | |
12787 | } | |
12788 | ||
12789 | int | |
12790 | catching_syscall_number (int syscall_number) | |
12791 | { | |
12792 | struct breakpoint *bp; | |
12793 | ||
12794 | ALL_BREAKPOINTS (bp) | |
12795 | if (is_syscall_catchpoint_enabled (bp)) | |
12796 | { | |
be5c67c1 PA |
12797 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
12798 | ||
12799 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
12800 | { |
12801 | int i, iter; | |
12802 | for (i = 0; | |
be5c67c1 | 12803 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
12804 | i++) |
12805 | if (syscall_number == iter) | |
12806 | return 1; | |
12807 | } | |
12808 | else | |
12809 | return 1; | |
12810 | } | |
12811 | ||
12812 | return 0; | |
12813 | } | |
12814 | ||
12815 | /* Complete syscall names. Used by "catch syscall". */ | |
12816 | static char ** | |
12817 | catch_syscall_completer (struct cmd_list_element *cmd, | |
12818 | char *text, char *word) | |
12819 | { | |
12820 | const char **list = get_syscall_names (); | |
c38eea1a MS |
12821 | char **retlist |
12822 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 12823 | |
c38eea1a MS |
12824 | xfree (list); |
12825 | return retlist; | |
a96d9b2e SDJ |
12826 | } |
12827 | ||
1042e4c0 SS |
12828 | /* Tracepoint-specific operations. */ |
12829 | ||
12830 | /* Set tracepoint count to NUM. */ | |
12831 | static void | |
12832 | set_tracepoint_count (int num) | |
12833 | { | |
12834 | tracepoint_count = num; | |
4fa62494 | 12835 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
12836 | } |
12837 | ||
12838 | void | |
12839 | trace_command (char *arg, int from_tty) | |
12840 | { | |
8cdf0e15 VP |
12841 | if (create_breakpoint (get_current_arch (), |
12842 | arg, | |
12843 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12844 | 0 /* tempflag */, |
12845 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12846 | 0 /* Ignore count */, |
12847 | pending_break_support, | |
348d480f | 12848 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12849 | from_tty, |
84f4c1fe PM |
12850 | 1 /* enabled */, |
12851 | 0 /* internal */)) | |
fd9b8c24 | 12852 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
12853 | } |
12854 | ||
7a697b8d SS |
12855 | void |
12856 | ftrace_command (char *arg, int from_tty) | |
12857 | { | |
8cdf0e15 VP |
12858 | if (create_breakpoint (get_current_arch (), |
12859 | arg, | |
12860 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12861 | 0 /* tempflag */, |
12862 | bp_fast_tracepoint /* type_wanted */, | |
12863 | 0 /* Ignore count */, | |
12864 | pending_break_support, | |
348d480f | 12865 | &tracepoint_breakpoint_ops, |
0fb4aa4b | 12866 | from_tty, |
84f4c1fe PM |
12867 | 1 /* enabled */, |
12868 | 0 /* internal */)) | |
0fb4aa4b PA |
12869 | set_tracepoint_count (breakpoint_count); |
12870 | } | |
12871 | ||
12872 | /* strace command implementation. Creates a static tracepoint. */ | |
12873 | ||
12874 | void | |
12875 | strace_command (char *arg, int from_tty) | |
12876 | { | |
12877 | if (create_breakpoint (get_current_arch (), | |
12878 | arg, | |
12879 | NULL, 0, 1 /* parse arg */, | |
12880 | 0 /* tempflag */, | |
12881 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12882 | 0 /* Ignore count */, |
12883 | pending_break_support, | |
348d480f | 12884 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12885 | from_tty, |
84f4c1fe PM |
12886 | 1 /* enabled */, |
12887 | 0 /* internal */)) | |
fd9b8c24 | 12888 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
12889 | } |
12890 | ||
409873ef SS |
12891 | /* Set up a fake reader function that gets command lines from a linked |
12892 | list that was acquired during tracepoint uploading. */ | |
12893 | ||
12894 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 12895 | static int next_cmd; |
409873ef SS |
12896 | |
12897 | static char * | |
12898 | read_uploaded_action (void) | |
12899 | { | |
12900 | char *rslt; | |
12901 | ||
3149d8c1 | 12902 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 12903 | |
3149d8c1 | 12904 | next_cmd++; |
409873ef SS |
12905 | |
12906 | return rslt; | |
12907 | } | |
12908 | ||
00bf0b85 SS |
12909 | /* Given information about a tracepoint as recorded on a target (which |
12910 | can be either a live system or a trace file), attempt to create an | |
12911 | equivalent GDB tracepoint. This is not a reliable process, since | |
12912 | the target does not necessarily have all the information used when | |
12913 | the tracepoint was originally defined. */ | |
12914 | ||
d9b3f62e | 12915 | struct tracepoint * |
00bf0b85 | 12916 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 12917 | { |
409873ef | 12918 | char *addr_str, small_buf[100]; |
d9b3f62e | 12919 | struct tracepoint *tp; |
fd9b8c24 | 12920 | |
409873ef SS |
12921 | if (utp->at_string) |
12922 | addr_str = utp->at_string; | |
12923 | else | |
12924 | { | |
12925 | /* In the absence of a source location, fall back to raw | |
12926 | address. Since there is no way to confirm that the address | |
12927 | means the same thing as when the trace was started, warn the | |
12928 | user. */ | |
3e43a32a MS |
12929 | warning (_("Uploaded tracepoint %d has no " |
12930 | "source location, using raw address"), | |
409873ef SS |
12931 | utp->number); |
12932 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
12933 | addr_str = small_buf; | |
12934 | } | |
12935 | ||
12936 | /* There's not much we can do with a sequence of bytecodes. */ | |
12937 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
12938 | warning (_("Uploaded tracepoint %d condition " |
12939 | "has no source form, ignoring it"), | |
409873ef | 12940 | utp->number); |
d5551862 | 12941 | |
8cdf0e15 | 12942 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
12943 | addr_str, |
12944 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 12945 | 0 /* tempflag */, |
0fb4aa4b | 12946 | utp->type /* type_wanted */, |
8cdf0e15 VP |
12947 | 0 /* Ignore count */, |
12948 | pending_break_support, | |
348d480f | 12949 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12950 | 0 /* from_tty */, |
84f4c1fe PM |
12951 | utp->enabled /* enabled */, |
12952 | 0 /* internal */)) | |
fd9b8c24 PA |
12953 | return NULL; |
12954 | ||
00bf0b85 SS |
12955 | set_tracepoint_count (breakpoint_count); |
12956 | ||
409873ef | 12957 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
12958 | tp = get_tracepoint (tracepoint_count); |
12959 | gdb_assert (tp != NULL); | |
d5551862 | 12960 | |
00bf0b85 SS |
12961 | if (utp->pass > 0) |
12962 | { | |
d9b3f62e | 12963 | sprintf (small_buf, "%d %d", utp->pass, tp->base.number); |
00bf0b85 | 12964 | |
409873ef | 12965 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
12966 | } |
12967 | ||
409873ef SS |
12968 | /* If we have uploaded versions of the original commands, set up a |
12969 | special-purpose "reader" function and call the usual command line | |
12970 | reader, then pass the result to the breakpoint command-setting | |
12971 | function. */ | |
3149d8c1 | 12972 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 12973 | { |
409873ef | 12974 | struct command_line *cmd_list; |
00bf0b85 | 12975 | |
409873ef | 12976 | this_utp = utp; |
3149d8c1 | 12977 | next_cmd = 0; |
d5551862 | 12978 | |
409873ef SS |
12979 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
12980 | ||
d9b3f62e | 12981 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 12982 | } |
3149d8c1 SS |
12983 | else if (!VEC_empty (char_ptr, utp->actions) |
12984 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
12985 | warning (_("Uploaded tracepoint %d actions " |
12986 | "have no source form, ignoring them"), | |
409873ef | 12987 | utp->number); |
00bf0b85 | 12988 | |
f196051f SS |
12989 | /* Copy any status information that might be available. */ |
12990 | tp->base.hit_count = utp->hit_count; | |
12991 | tp->traceframe_usage = utp->traceframe_usage; | |
12992 | ||
00bf0b85 | 12993 | return tp; |
d9b3f62e | 12994 | } |
00bf0b85 | 12995 | |
1042e4c0 SS |
12996 | /* Print information on tracepoint number TPNUM_EXP, or all if |
12997 | omitted. */ | |
12998 | ||
12999 | static void | |
e5a67952 | 13000 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 13001 | { |
79a45e25 | 13002 | struct ui_out *uiout = current_uiout; |
e5a67952 | 13003 | int num_printed; |
1042e4c0 | 13004 | |
e5a67952 | 13005 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
13006 | |
13007 | if (num_printed == 0) | |
1042e4c0 | 13008 | { |
e5a67952 | 13009 | if (args == NULL || *args == '\0') |
d77f58be SS |
13010 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
13011 | else | |
e5a67952 | 13012 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 13013 | } |
ad443146 SS |
13014 | |
13015 | default_collect_info (); | |
1042e4c0 SS |
13016 | } |
13017 | ||
4a64f543 | 13018 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
13019 | Not supported by all targets. */ |
13020 | static void | |
13021 | enable_trace_command (char *args, int from_tty) | |
13022 | { | |
13023 | enable_command (args, from_tty); | |
13024 | } | |
13025 | ||
4a64f543 | 13026 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
13027 | Not supported by all targets. */ |
13028 | static void | |
13029 | disable_trace_command (char *args, int from_tty) | |
13030 | { | |
13031 | disable_command (args, from_tty); | |
13032 | } | |
13033 | ||
4a64f543 | 13034 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
13035 | static void |
13036 | delete_trace_command (char *arg, int from_tty) | |
13037 | { | |
35df4500 | 13038 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
13039 | |
13040 | dont_repeat (); | |
13041 | ||
13042 | if (arg == 0) | |
13043 | { | |
13044 | int breaks_to_delete = 0; | |
13045 | ||
13046 | /* Delete all breakpoints if no argument. | |
13047 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
13048 | have to be deleted with an explicit breakpoint number |
13049 | argument. */ | |
1042e4c0 | 13050 | ALL_TRACEPOINTS (b) |
46c6471b | 13051 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
13052 | { |
13053 | breaks_to_delete = 1; | |
13054 | break; | |
13055 | } | |
1042e4c0 SS |
13056 | |
13057 | /* Ask user only if there are some breakpoints to delete. */ | |
13058 | if (!from_tty | |
13059 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
13060 | { | |
35df4500 | 13061 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13062 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 13063 | delete_breakpoint (b); |
1042e4c0 SS |
13064 | } |
13065 | } | |
13066 | else | |
51be5b68 | 13067 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
13068 | } |
13069 | ||
197f0a60 TT |
13070 | /* Helper function for trace_pass_command. */ |
13071 | ||
13072 | static void | |
d9b3f62e | 13073 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 13074 | { |
d9b3f62e PA |
13075 | tp->pass_count = count; |
13076 | observer_notify_tracepoint_modified (tp->base.number); | |
197f0a60 TT |
13077 | if (from_tty) |
13078 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 13079 | tp->base.number, count); |
197f0a60 TT |
13080 | } |
13081 | ||
1042e4c0 SS |
13082 | /* Set passcount for tracepoint. |
13083 | ||
13084 | First command argument is passcount, second is tracepoint number. | |
13085 | If tracepoint number omitted, apply to most recently defined. | |
13086 | Also accepts special argument "all". */ | |
13087 | ||
13088 | static void | |
13089 | trace_pass_command (char *args, int from_tty) | |
13090 | { | |
d9b3f62e | 13091 | struct tracepoint *t1; |
1042e4c0 | 13092 | unsigned int count; |
1042e4c0 SS |
13093 | |
13094 | if (args == 0 || *args == 0) | |
3e43a32a MS |
13095 | error (_("passcount command requires an " |
13096 | "argument (count + optional TP num)")); | |
1042e4c0 | 13097 | |
4a64f543 | 13098 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
13099 | |
13100 | while (*args && isspace ((int) *args)) | |
13101 | args++; | |
13102 | ||
13103 | if (*args && strncasecmp (args, "all", 3) == 0) | |
13104 | { | |
d9b3f62e PA |
13105 | struct breakpoint *b; |
13106 | ||
1042e4c0 | 13107 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
13108 | if (*args) |
13109 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 13110 | |
d9b3f62e | 13111 | ALL_TRACEPOINTS (b) |
197f0a60 | 13112 | { |
d9b3f62e | 13113 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
13114 | trace_pass_set_count (t1, count, from_tty); |
13115 | } | |
13116 | } | |
13117 | else if (*args == '\0') | |
1042e4c0 | 13118 | { |
197f0a60 | 13119 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 13120 | if (t1) |
197f0a60 TT |
13121 | trace_pass_set_count (t1, count, from_tty); |
13122 | } | |
13123 | else | |
13124 | { | |
13125 | struct get_number_or_range_state state; | |
13126 | ||
13127 | init_number_or_range (&state, args); | |
13128 | while (!state.finished) | |
1042e4c0 | 13129 | { |
197f0a60 TT |
13130 | t1 = get_tracepoint_by_number (&args, &state, 1); |
13131 | if (t1) | |
13132 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
13133 | } |
13134 | } | |
1042e4c0 SS |
13135 | } |
13136 | ||
d9b3f62e | 13137 | struct tracepoint * |
1042e4c0 SS |
13138 | get_tracepoint (int num) |
13139 | { | |
13140 | struct breakpoint *t; | |
13141 | ||
13142 | ALL_TRACEPOINTS (t) | |
13143 | if (t->number == num) | |
d9b3f62e | 13144 | return (struct tracepoint *) t; |
1042e4c0 SS |
13145 | |
13146 | return NULL; | |
13147 | } | |
13148 | ||
d5551862 SS |
13149 | /* Find the tracepoint with the given target-side number (which may be |
13150 | different from the tracepoint number after disconnecting and | |
13151 | reconnecting). */ | |
13152 | ||
d9b3f62e | 13153 | struct tracepoint * |
d5551862 SS |
13154 | get_tracepoint_by_number_on_target (int num) |
13155 | { | |
d9b3f62e | 13156 | struct breakpoint *b; |
d5551862 | 13157 | |
d9b3f62e PA |
13158 | ALL_TRACEPOINTS (b) |
13159 | { | |
13160 | struct tracepoint *t = (struct tracepoint *) b; | |
13161 | ||
13162 | if (t->number_on_target == num) | |
13163 | return t; | |
13164 | } | |
d5551862 SS |
13165 | |
13166 | return NULL; | |
13167 | } | |
13168 | ||
1042e4c0 | 13169 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
13170 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
13171 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 13172 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 13173 | struct tracepoint * |
197f0a60 TT |
13174 | get_tracepoint_by_number (char **arg, |
13175 | struct get_number_or_range_state *state, | |
13176 | int optional_p) | |
1042e4c0 SS |
13177 | { |
13178 | extern int tracepoint_count; | |
13179 | struct breakpoint *t; | |
13180 | int tpnum; | |
13181 | char *instring = arg == NULL ? NULL : *arg; | |
13182 | ||
197f0a60 TT |
13183 | if (state) |
13184 | { | |
13185 | gdb_assert (!state->finished); | |
13186 | tpnum = get_number_or_range (state); | |
13187 | } | |
13188 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
13189 | { |
13190 | if (optional_p) | |
13191 | tpnum = tracepoint_count; | |
13192 | else | |
13193 | error_no_arg (_("tracepoint number")); | |
13194 | } | |
13195 | else | |
197f0a60 | 13196 | tpnum = get_number (arg); |
1042e4c0 SS |
13197 | |
13198 | if (tpnum <= 0) | |
13199 | { | |
13200 | if (instring && *instring) | |
13201 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
13202 | instring); | |
13203 | else | |
3e43a32a MS |
13204 | printf_filtered (_("Tracepoint argument missing " |
13205 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
13206 | return NULL; |
13207 | } | |
13208 | ||
13209 | ALL_TRACEPOINTS (t) | |
13210 | if (t->number == tpnum) | |
13211 | { | |
d9b3f62e | 13212 | return (struct tracepoint *) t; |
1042e4c0 SS |
13213 | } |
13214 | ||
1042e4c0 SS |
13215 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
13216 | return NULL; | |
13217 | } | |
13218 | ||
d9b3f62e PA |
13219 | void |
13220 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
13221 | { | |
13222 | if (b->thread != -1) | |
13223 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
13224 | ||
13225 | if (b->task != 0) | |
13226 | fprintf_unfiltered (fp, " task %d", b->task); | |
13227 | ||
13228 | fprintf_unfiltered (fp, "\n"); | |
13229 | } | |
13230 | ||
6149aea9 PA |
13231 | /* Save information on user settable breakpoints (watchpoints, etc) to |
13232 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
13233 | on each breakpoint and only include the ones for which it returns | |
13234 | non-zero. */ | |
13235 | ||
1042e4c0 | 13236 | static void |
6149aea9 PA |
13237 | save_breakpoints (char *filename, int from_tty, |
13238 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
13239 | { |
13240 | struct breakpoint *tp; | |
6149aea9 | 13241 | int any = 0; |
a7bdde9e | 13242 | char *pathname; |
1042e4c0 | 13243 | struct cleanup *cleanup; |
a7bdde9e | 13244 | struct ui_file *fp; |
6149aea9 | 13245 | int extra_trace_bits = 0; |
1042e4c0 | 13246 | |
6149aea9 PA |
13247 | if (filename == 0 || *filename == 0) |
13248 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
13249 | |
13250 | /* See if we have anything to save. */ | |
6149aea9 | 13251 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13252 | { |
6149aea9 | 13253 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13254 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
13255 | continue; |
13256 | ||
13257 | /* If we have a filter, only save the breakpoints it accepts. */ | |
13258 | if (filter && !filter (tp)) | |
13259 | continue; | |
13260 | ||
13261 | any = 1; | |
13262 | ||
13263 | if (is_tracepoint (tp)) | |
13264 | { | |
13265 | extra_trace_bits = 1; | |
13266 | ||
13267 | /* We can stop searching. */ | |
13268 | break; | |
13269 | } | |
1042e4c0 | 13270 | } |
6149aea9 PA |
13271 | |
13272 | if (!any) | |
1042e4c0 | 13273 | { |
6149aea9 | 13274 | warning (_("Nothing to save.")); |
1042e4c0 SS |
13275 | return; |
13276 | } | |
13277 | ||
6149aea9 | 13278 | pathname = tilde_expand (filename); |
1042e4c0 | 13279 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 13280 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 13281 | if (!fp) |
6149aea9 PA |
13282 | error (_("Unable to open file '%s' for saving (%s)"), |
13283 | filename, safe_strerror (errno)); | |
a7bdde9e | 13284 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 13285 | |
6149aea9 PA |
13286 | if (extra_trace_bits) |
13287 | save_trace_state_variables (fp); | |
8bf6485c | 13288 | |
6149aea9 | 13289 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13290 | { |
6149aea9 | 13291 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13292 | if (!user_breakpoint_p (tp)) |
6149aea9 | 13293 | continue; |
8bf6485c | 13294 | |
6149aea9 PA |
13295 | /* If we have a filter, only save the breakpoints it accepts. */ |
13296 | if (filter && !filter (tp)) | |
13297 | continue; | |
13298 | ||
348d480f | 13299 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 13300 | |
6149aea9 PA |
13301 | /* Note, we can't rely on tp->number for anything, as we can't |
13302 | assume the recreated breakpoint numbers will match. Use $bpnum | |
13303 | instead. */ | |
13304 | ||
13305 | if (tp->cond_string) | |
13306 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
13307 | ||
13308 | if (tp->ignore_count) | |
13309 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
13310 | ||
a7bdde9e | 13311 | if (tp->commands) |
1042e4c0 | 13312 | { |
a7bdde9e VP |
13313 | volatile struct gdb_exception ex; |
13314 | ||
6149aea9 | 13315 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 13316 | |
79a45e25 | 13317 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 13318 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 13319 | { |
79a45e25 | 13320 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 13321 | } |
79a45e25 | 13322 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 13323 | |
a7bdde9e VP |
13324 | if (ex.reason < 0) |
13325 | throw_exception (ex); | |
1042e4c0 | 13326 | |
a7bdde9e | 13327 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 13328 | } |
6149aea9 PA |
13329 | |
13330 | if (tp->enable_state == bp_disabled) | |
13331 | fprintf_unfiltered (fp, "disable\n"); | |
13332 | ||
13333 | /* If this is a multi-location breakpoint, check if the locations | |
13334 | should be individually disabled. Watchpoint locations are | |
13335 | special, and not user visible. */ | |
13336 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
13337 | { | |
13338 | struct bp_location *loc; | |
13339 | int n = 1; | |
13340 | ||
13341 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
13342 | if (!loc->enabled) | |
13343 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
13344 | } | |
1042e4c0 | 13345 | } |
8bf6485c | 13346 | |
6149aea9 | 13347 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
13348 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
13349 | ||
1042e4c0 SS |
13350 | do_cleanups (cleanup); |
13351 | if (from_tty) | |
6149aea9 PA |
13352 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
13353 | } | |
13354 | ||
13355 | /* The `save breakpoints' command. */ | |
13356 | ||
13357 | static void | |
13358 | save_breakpoints_command (char *args, int from_tty) | |
13359 | { | |
13360 | save_breakpoints (args, from_tty, NULL); | |
13361 | } | |
13362 | ||
13363 | /* The `save tracepoints' command. */ | |
13364 | ||
13365 | static void | |
13366 | save_tracepoints_command (char *args, int from_tty) | |
13367 | { | |
13368 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
13369 | } |
13370 | ||
13371 | /* Create a vector of all tracepoints. */ | |
13372 | ||
13373 | VEC(breakpoint_p) * | |
eeae04df | 13374 | all_tracepoints (void) |
1042e4c0 SS |
13375 | { |
13376 | VEC(breakpoint_p) *tp_vec = 0; | |
13377 | struct breakpoint *tp; | |
13378 | ||
13379 | ALL_TRACEPOINTS (tp) | |
13380 | { | |
13381 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
13382 | } | |
13383 | ||
13384 | return tp_vec; | |
13385 | } | |
13386 | ||
c906108c | 13387 | \f |
4a64f543 MS |
13388 | /* This help string is used for the break, hbreak, tbreak and thbreak |
13389 | commands. It is defined as a macro to prevent duplication. | |
13390 | COMMAND should be a string constant containing the name of the | |
13391 | command. */ | |
31e2b00f AS |
13392 | #define BREAK_ARGS_HELP(command) \ |
13393 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
13394 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
13395 | If a line number is specified, break at start of code for that line.\n\ | |
13396 | If a function is specified, break at start of code for that function.\n\ | |
13397 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
13398 | With no LOCATION, uses current execution address of the selected\n\ |
13399 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
13400 | \n\ |
13401 | THREADNUM is the number from \"info threads\".\n\ | |
13402 | CONDITION is a boolean expression.\n\ | |
13403 | \n\ | |
d41c0fc8 PA |
13404 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
13405 | conditions are different.\n\ | |
31e2b00f AS |
13406 | \n\ |
13407 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
13408 | ||
44feb3ce TT |
13409 | /* List of subcommands for "catch". */ |
13410 | static struct cmd_list_element *catch_cmdlist; | |
13411 | ||
13412 | /* List of subcommands for "tcatch". */ | |
13413 | static struct cmd_list_element *tcatch_cmdlist; | |
13414 | ||
9ac4176b | 13415 | void |
44feb3ce TT |
13416 | add_catch_command (char *name, char *docstring, |
13417 | void (*sfunc) (char *args, int from_tty, | |
13418 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
13419 | char **(*completer) (struct cmd_list_element *cmd, |
13420 | char *text, char *word), | |
44feb3ce TT |
13421 | void *user_data_catch, |
13422 | void *user_data_tcatch) | |
13423 | { | |
13424 | struct cmd_list_element *command; | |
13425 | ||
13426 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13427 | &catch_cmdlist); | |
13428 | set_cmd_sfunc (command, sfunc); | |
13429 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 13430 | set_cmd_completer (command, completer); |
44feb3ce TT |
13431 | |
13432 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13433 | &tcatch_cmdlist); | |
13434 | set_cmd_sfunc (command, sfunc); | |
13435 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 13436 | set_cmd_completer (command, completer); |
44feb3ce TT |
13437 | } |
13438 | ||
6c95b8df | 13439 | static void |
a79b8f6e | 13440 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 13441 | { |
6c95b8df PA |
13442 | inf->total_syscalls_count = 0; |
13443 | inf->any_syscall_count = 0; | |
13444 | VEC_free (int, inf->syscalls_counts); | |
13445 | } | |
13446 | ||
6149aea9 PA |
13447 | static void |
13448 | save_command (char *arg, int from_tty) | |
13449 | { | |
3e43a32a MS |
13450 | printf_unfiltered (_("\"save\" must be followed by " |
13451 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
13452 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
13453 | } | |
13454 | ||
84f4c1fe PM |
13455 | struct breakpoint * |
13456 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
13457 | void *data) | |
13458 | { | |
35df4500 | 13459 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 13460 | |
35df4500 | 13461 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
13462 | { |
13463 | if ((*callback) (b, data)) | |
13464 | return b; | |
13465 | } | |
13466 | ||
13467 | return NULL; | |
13468 | } | |
13469 | ||
0574c78f GB |
13470 | /* Zero if any of the breakpoint's locations could be a location where |
13471 | functions have been inlined, nonzero otherwise. */ | |
13472 | ||
13473 | static int | |
13474 | is_non_inline_function (struct breakpoint *b) | |
13475 | { | |
13476 | /* The shared library event breakpoint is set on the address of a | |
13477 | non-inline function. */ | |
13478 | if (b->type == bp_shlib_event) | |
13479 | return 1; | |
13480 | ||
13481 | return 0; | |
13482 | } | |
13483 | ||
13484 | /* Nonzero if the specified PC cannot be a location where functions | |
13485 | have been inlined. */ | |
13486 | ||
13487 | int | |
13488 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc) | |
13489 | { | |
13490 | struct breakpoint *b; | |
13491 | struct bp_location *bl; | |
13492 | ||
13493 | ALL_BREAKPOINTS (b) | |
13494 | { | |
13495 | if (!is_non_inline_function (b)) | |
13496 | continue; | |
13497 | ||
13498 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
13499 | { | |
13500 | if (!bl->shlib_disabled | |
13501 | && bpstat_check_location (bl, aspace, pc)) | |
13502 | return 1; | |
13503 | } | |
13504 | } | |
13505 | ||
13506 | return 0; | |
13507 | } | |
13508 | ||
2060206e PA |
13509 | void |
13510 | initialize_breakpoint_ops (void) | |
13511 | { | |
13512 | static int initialized = 0; | |
13513 | ||
13514 | struct breakpoint_ops *ops; | |
13515 | ||
13516 | if (initialized) | |
13517 | return; | |
13518 | initialized = 1; | |
13519 | ||
13520 | /* The breakpoint_ops structure to be inherit by all kinds of | |
13521 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
13522 | internal and momentary breakpoints, etc.). */ | |
13523 | ops = &bkpt_base_breakpoint_ops; | |
13524 | *ops = base_breakpoint_ops; | |
13525 | ops->re_set = bkpt_re_set; | |
13526 | ops->insert_location = bkpt_insert_location; | |
13527 | ops->remove_location = bkpt_remove_location; | |
13528 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
13529 | ||
13530 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
13531 | ops = &bkpt_breakpoint_ops; | |
13532 | *ops = bkpt_base_breakpoint_ops; | |
13533 | ops->re_set = bkpt_re_set; | |
13534 | ops->resources_needed = bkpt_resources_needed; | |
13535 | ops->print_it = bkpt_print_it; | |
13536 | ops->print_mention = bkpt_print_mention; | |
13537 | ops->print_recreate = bkpt_print_recreate; | |
13538 | ||
13539 | /* Ranged breakpoints. */ | |
13540 | ops = &ranged_breakpoint_ops; | |
13541 | *ops = bkpt_breakpoint_ops; | |
13542 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
13543 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
13544 | ops->print_it = print_it_ranged_breakpoint; | |
13545 | ops->print_one = print_one_ranged_breakpoint; | |
13546 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
13547 | ops->print_mention = print_mention_ranged_breakpoint; | |
13548 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
13549 | ||
13550 | /* Internal breakpoints. */ | |
13551 | ops = &internal_breakpoint_ops; | |
13552 | *ops = bkpt_base_breakpoint_ops; | |
13553 | ops->re_set = internal_bkpt_re_set; | |
13554 | ops->check_status = internal_bkpt_check_status; | |
13555 | ops->print_it = internal_bkpt_print_it; | |
13556 | ops->print_mention = internal_bkpt_print_mention; | |
13557 | ||
13558 | /* Momentary breakpoints. */ | |
13559 | ops = &momentary_breakpoint_ops; | |
13560 | *ops = bkpt_base_breakpoint_ops; | |
13561 | ops->re_set = momentary_bkpt_re_set; | |
13562 | ops->check_status = momentary_bkpt_check_status; | |
13563 | ops->print_it = momentary_bkpt_print_it; | |
13564 | ops->print_mention = momentary_bkpt_print_mention; | |
13565 | ||
13566 | /* GNU v3 exception catchpoints. */ | |
13567 | ops = &gnu_v3_exception_catchpoint_ops; | |
13568 | *ops = bkpt_breakpoint_ops; | |
13569 | ops->print_it = print_it_exception_catchpoint; | |
13570 | ops->print_one = print_one_exception_catchpoint; | |
13571 | ops->print_mention = print_mention_exception_catchpoint; | |
13572 | ops->print_recreate = print_recreate_exception_catchpoint; | |
13573 | ||
13574 | /* Watchpoints. */ | |
13575 | ops = &watchpoint_breakpoint_ops; | |
13576 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 13577 | ops->dtor = dtor_watchpoint; |
2060206e PA |
13578 | ops->re_set = re_set_watchpoint; |
13579 | ops->insert_location = insert_watchpoint; | |
13580 | ops->remove_location = remove_watchpoint; | |
13581 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
13582 | ops->check_status = check_status_watchpoint; | |
13583 | ops->resources_needed = resources_needed_watchpoint; | |
13584 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
13585 | ops->print_it = print_it_watchpoint; | |
13586 | ops->print_mention = print_mention_watchpoint; | |
13587 | ops->print_recreate = print_recreate_watchpoint; | |
13588 | ||
13589 | /* Masked watchpoints. */ | |
13590 | ops = &masked_watchpoint_breakpoint_ops; | |
13591 | *ops = watchpoint_breakpoint_ops; | |
13592 | ops->insert_location = insert_masked_watchpoint; | |
13593 | ops->remove_location = remove_masked_watchpoint; | |
13594 | ops->resources_needed = resources_needed_masked_watchpoint; | |
13595 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
13596 | ops->print_it = print_it_masked_watchpoint; | |
13597 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
13598 | ops->print_mention = print_mention_masked_watchpoint; | |
13599 | ops->print_recreate = print_recreate_masked_watchpoint; | |
13600 | ||
13601 | /* Tracepoints. */ | |
13602 | ops = &tracepoint_breakpoint_ops; | |
13603 | *ops = base_breakpoint_ops; | |
13604 | ops->re_set = tracepoint_re_set; | |
13605 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
13606 | ops->print_one_detail = tracepoint_print_one_detail; | |
13607 | ops->print_mention = tracepoint_print_mention; | |
13608 | ops->print_recreate = tracepoint_print_recreate; | |
13609 | ||
13610 | /* Fork catchpoints. */ | |
13611 | ops = &catch_fork_breakpoint_ops; | |
13612 | *ops = base_breakpoint_ops; | |
13613 | ops->insert_location = insert_catch_fork; | |
13614 | ops->remove_location = remove_catch_fork; | |
13615 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
13616 | ops->print_it = print_it_catch_fork; | |
13617 | ops->print_one = print_one_catch_fork; | |
13618 | ops->print_mention = print_mention_catch_fork; | |
13619 | ops->print_recreate = print_recreate_catch_fork; | |
13620 | ||
13621 | /* Vfork catchpoints. */ | |
13622 | ops = &catch_vfork_breakpoint_ops; | |
13623 | *ops = base_breakpoint_ops; | |
13624 | ops->insert_location = insert_catch_vfork; | |
13625 | ops->remove_location = remove_catch_vfork; | |
13626 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
13627 | ops->print_it = print_it_catch_vfork; | |
13628 | ops->print_one = print_one_catch_vfork; | |
13629 | ops->print_mention = print_mention_catch_vfork; | |
13630 | ops->print_recreate = print_recreate_catch_vfork; | |
13631 | ||
13632 | /* Exec catchpoints. */ | |
13633 | ops = &catch_exec_breakpoint_ops; | |
13634 | *ops = base_breakpoint_ops; | |
13635 | ops->dtor = dtor_catch_exec; | |
13636 | ops->insert_location = insert_catch_exec; | |
13637 | ops->remove_location = remove_catch_exec; | |
13638 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
13639 | ops->print_it = print_it_catch_exec; | |
13640 | ops->print_one = print_one_catch_exec; | |
13641 | ops->print_mention = print_mention_catch_exec; | |
13642 | ops->print_recreate = print_recreate_catch_exec; | |
13643 | ||
13644 | /* Syscall catchpoints. */ | |
13645 | ops = &catch_syscall_breakpoint_ops; | |
13646 | *ops = base_breakpoint_ops; | |
13647 | ops->dtor = dtor_catch_syscall; | |
13648 | ops->insert_location = insert_catch_syscall; | |
13649 | ops->remove_location = remove_catch_syscall; | |
13650 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
13651 | ops->print_it = print_it_catch_syscall; | |
13652 | ops->print_one = print_one_catch_syscall; | |
13653 | ops->print_mention = print_mention_catch_syscall; | |
13654 | ops->print_recreate = print_recreate_catch_syscall; | |
13655 | } | |
13656 | ||
c906108c | 13657 | void |
fba45db2 | 13658 | _initialize_breakpoint (void) |
c906108c SS |
13659 | { |
13660 | struct cmd_list_element *c; | |
13661 | ||
2060206e PA |
13662 | initialize_breakpoint_ops (); |
13663 | ||
84acb35a | 13664 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 13665 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 13666 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 13667 | |
17450429 PP |
13668 | breakpoint_objfile_key = register_objfile_data (); |
13669 | ||
c906108c SS |
13670 | breakpoint_chain = 0; |
13671 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
13672 | before a breakpoint is set. */ | |
13673 | breakpoint_count = 0; | |
13674 | ||
1042e4c0 SS |
13675 | tracepoint_count = 0; |
13676 | ||
1bedd215 AC |
13677 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
13678 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
13679 | Usage is `ignore N COUNT'.")); | |
c906108c | 13680 | if (xdb_commands) |
c5aa993b | 13681 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 13682 | |
1bedd215 AC |
13683 | add_com ("commands", class_breakpoint, commands_command, _("\ |
13684 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
13685 | Give breakpoint number as argument after \"commands\".\n\ |
13686 | With no argument, the targeted breakpoint is the last one set.\n\ | |
13687 | The commands themselves follow starting on the next line.\n\ | |
13688 | Type a line containing \"end\" to indicate the end of them.\n\ | |
13689 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 13690 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 13691 | |
1bedd215 AC |
13692 | add_com ("condition", class_breakpoint, condition_command, _("\ |
13693 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 13694 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 13695 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 13696 | |
1bedd215 | 13697 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 13698 | Set a temporary breakpoint.\n\ |
c906108c SS |
13699 | Like \"break\" except the breakpoint is only temporary,\n\ |
13700 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
13701 | by using \"enable delete\" on the breakpoint number.\n\ |
13702 | \n" | |
13703 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 13704 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13705 | |
1bedd215 | 13706 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 13707 | Set a hardware assisted breakpoint.\n\ |
c906108c | 13708 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
13709 | some target hardware may not have this support.\n\ |
13710 | \n" | |
13711 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 13712 | set_cmd_completer (c, location_completer); |
c906108c | 13713 | |
1bedd215 | 13714 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 13715 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 13716 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
13717 | so it will be deleted when hit.\n\ |
13718 | \n" | |
13719 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 13720 | set_cmd_completer (c, location_completer); |
c906108c | 13721 | |
1bedd215 AC |
13722 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
13723 | Enable some breakpoints.\n\ | |
c906108c SS |
13724 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13725 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13726 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13727 | With a subcommand you can enable temporarily."), |
c906108c SS |
13728 | &enablelist, "enable ", 1, &cmdlist); |
13729 | if (xdb_commands) | |
1bedd215 AC |
13730 | add_com ("ab", class_breakpoint, enable_command, _("\ |
13731 | Enable some breakpoints.\n\ | |
c906108c SS |
13732 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13733 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13734 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13735 | With a subcommand you can enable temporarily.")); |
c906108c SS |
13736 | |
13737 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
13738 | ||
84951ab5 | 13739 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 13740 | Enable some breakpoints.\n\ |
c906108c SS |
13741 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13742 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13743 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 13744 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 13745 | |
1a966eab AC |
13746 | add_cmd ("once", no_class, enable_once_command, _("\ |
13747 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13748 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13749 | &enablebreaklist); |
13750 | ||
1a966eab AC |
13751 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13752 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13753 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13754 | &enablebreaklist); |
13755 | ||
1a966eab AC |
13756 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13757 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13758 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13759 | &enablelist); |
13760 | ||
1a966eab AC |
13761 | add_cmd ("once", no_class, enable_once_command, _("\ |
13762 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13763 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13764 | &enablelist); |
13765 | ||
1bedd215 AC |
13766 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
13767 | Disable some breakpoints.\n\ | |
c906108c SS |
13768 | Arguments are breakpoint numbers with spaces in between.\n\ |
13769 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13770 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
13771 | &disablelist, "disable ", 1, &cmdlist); |
13772 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
13773 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
13774 | if (xdb_commands) | |
1bedd215 AC |
13775 | add_com ("sb", class_breakpoint, disable_command, _("\ |
13776 | Disable some breakpoints.\n\ | |
c906108c SS |
13777 | Arguments are breakpoint numbers with spaces in between.\n\ |
13778 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13779 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 13780 | |
1a966eab AC |
13781 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
13782 | Disable some breakpoints.\n\ | |
c906108c SS |
13783 | Arguments are breakpoint numbers with spaces in between.\n\ |
13784 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13785 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 13786 | This command may be abbreviated \"disable\"."), |
c906108c SS |
13787 | &disablelist); |
13788 | ||
1bedd215 AC |
13789 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
13790 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13791 | Arguments are breakpoint numbers with spaces in between.\n\ |
13792 | To delete all breakpoints, give no argument.\n\ | |
13793 | \n\ | |
13794 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 13795 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
13796 | &deletelist, "delete ", 1, &cmdlist); |
13797 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 13798 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 13799 | if (xdb_commands) |
1bedd215 AC |
13800 | add_com ("db", class_breakpoint, delete_command, _("\ |
13801 | Delete some breakpoints.\n\ | |
c906108c | 13802 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 13803 | To delete all breakpoints, give no argument.\n")); |
c906108c | 13804 | |
1a966eab AC |
13805 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
13806 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13807 | Arguments are breakpoint numbers with spaces in between.\n\ |
13808 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 13809 | This command may be abbreviated \"delete\"."), |
c906108c SS |
13810 | &deletelist); |
13811 | ||
1bedd215 AC |
13812 | add_com ("clear", class_breakpoint, clear_command, _("\ |
13813 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
13814 | Argument may be line number, function name, or \"*\" and an address.\n\ |
13815 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
13816 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
13817 | If an address is specified, breakpoints at that address are cleared.\n\ |
13818 | \n\ | |
13819 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
13820 | is executing in.\n\ |
13821 | \n\ | |
1bedd215 | 13822 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 13823 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 13824 | |
1bedd215 | 13825 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
13826 | Set breakpoint at specified line or function.\n" |
13827 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 13828 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13829 | |
c906108c SS |
13830 | add_com_alias ("b", "break", class_run, 1); |
13831 | add_com_alias ("br", "break", class_run, 1); | |
13832 | add_com_alias ("bre", "break", class_run, 1); | |
13833 | add_com_alias ("brea", "break", class_run, 1); | |
13834 | ||
7681d515 PM |
13835 | if (xdb_commands) |
13836 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
13837 | |
13838 | if (dbx_commands) | |
13839 | { | |
1bedd215 AC |
13840 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
13841 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
13842 | &stoplist, "stop ", 1, &cmdlist); |
13843 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 13844 | _("Break in function or address."), &stoplist); |
c5aa993b | 13845 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 13846 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
13847 | add_com ("status", class_info, breakpoints_info, _("\ |
13848 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13849 | The \"Type\" column indicates one of:\n\ |
13850 | \tbreakpoint - normal breakpoint\n\ | |
13851 | \twatchpoint - watchpoint\n\ | |
13852 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13853 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13854 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13855 | address and file/line number respectively.\n\ |
13856 | \n\ | |
13857 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13858 | are set to the address of the last breakpoint listed unless the command\n\ |
13859 | is prefixed with \"server \".\n\n\ | |
c906108c | 13860 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13861 | breakpoint set.")); |
c906108c SS |
13862 | } |
13863 | ||
1bedd215 | 13864 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 13865 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
13866 | The \"Type\" column indicates one of:\n\ |
13867 | \tbreakpoint - normal breakpoint\n\ | |
13868 | \twatchpoint - watchpoint\n\ | |
13869 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13870 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13871 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13872 | address and file/line number respectively.\n\ |
13873 | \n\ | |
13874 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13875 | are set to the address of the last breakpoint listed unless the command\n\ |
13876 | is prefixed with \"server \".\n\n\ | |
c906108c | 13877 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13878 | breakpoint set.")); |
c906108c | 13879 | |
6b04bdb7 MS |
13880 | add_info_alias ("b", "breakpoints", 1); |
13881 | ||
c906108c | 13882 | if (xdb_commands) |
1bedd215 AC |
13883 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
13884 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13885 | The \"Type\" column indicates one of:\n\ |
13886 | \tbreakpoint - normal breakpoint\n\ | |
13887 | \twatchpoint - watchpoint\n\ | |
13888 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13889 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13890 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13891 | address and file/line number respectively.\n\ |
13892 | \n\ | |
13893 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13894 | are set to the address of the last breakpoint listed unless the command\n\ |
13895 | is prefixed with \"server \".\n\n\ | |
c906108c | 13896 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13897 | breakpoint set.")); |
c906108c | 13898 | |
1a966eab AC |
13899 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
13900 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13901 | The \"Type\" column indicates one of:\n\ |
13902 | \tbreakpoint - normal breakpoint\n\ | |
13903 | \twatchpoint - watchpoint\n\ | |
13904 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
13905 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
13906 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
13907 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
13908 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
13909 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
13910 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
13911 | address and file/line number respectively.\n\ |
13912 | \n\ | |
13913 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13914 | are set to the address of the last breakpoint listed unless the command\n\ |
13915 | is prefixed with \"server \".\n\n\ | |
c906108c | 13916 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 13917 | breakpoint set."), |
c906108c SS |
13918 | &maintenanceinfolist); |
13919 | ||
44feb3ce TT |
13920 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
13921 | Set catchpoints to catch events."), | |
13922 | &catch_cmdlist, "catch ", | |
13923 | 0/*allow-unknown*/, &cmdlist); | |
13924 | ||
13925 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
13926 | Set temporary catchpoints to catch events."), | |
13927 | &tcatch_cmdlist, "tcatch ", | |
13928 | 0/*allow-unknown*/, &cmdlist); | |
13929 | ||
13930 | /* Add catch and tcatch sub-commands. */ | |
13931 | add_catch_command ("catch", _("\ | |
13932 | Catch an exception, when caught.\n\ | |
13933 | With an argument, catch only exceptions with the given name."), | |
13934 | catch_catch_command, | |
a96d9b2e | 13935 | NULL, |
44feb3ce TT |
13936 | CATCH_PERMANENT, |
13937 | CATCH_TEMPORARY); | |
13938 | add_catch_command ("throw", _("\ | |
13939 | Catch an exception, when thrown.\n\ | |
13940 | With an argument, catch only exceptions with the given name."), | |
13941 | catch_throw_command, | |
a96d9b2e | 13942 | NULL, |
44feb3ce TT |
13943 | CATCH_PERMANENT, |
13944 | CATCH_TEMPORARY); | |
13945 | add_catch_command ("fork", _("Catch calls to fork."), | |
13946 | catch_fork_command_1, | |
a96d9b2e | 13947 | NULL, |
44feb3ce TT |
13948 | (void *) (uintptr_t) catch_fork_permanent, |
13949 | (void *) (uintptr_t) catch_fork_temporary); | |
13950 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
13951 | catch_fork_command_1, | |
a96d9b2e | 13952 | NULL, |
44feb3ce TT |
13953 | (void *) (uintptr_t) catch_vfork_permanent, |
13954 | (void *) (uintptr_t) catch_vfork_temporary); | |
13955 | add_catch_command ("exec", _("Catch calls to exec."), | |
13956 | catch_exec_command_1, | |
a96d9b2e SDJ |
13957 | NULL, |
13958 | CATCH_PERMANENT, | |
13959 | CATCH_TEMPORARY); | |
13960 | add_catch_command ("syscall", _("\ | |
13961 | Catch system calls by their names and/or numbers.\n\ | |
13962 | Arguments say which system calls to catch. If no arguments\n\ | |
13963 | are given, every system call will be caught.\n\ | |
13964 | Arguments, if given, should be one or more system call names\n\ | |
13965 | (if your system supports that), or system call numbers."), | |
13966 | catch_syscall_command_1, | |
13967 | catch_syscall_completer, | |
44feb3ce TT |
13968 | CATCH_PERMANENT, |
13969 | CATCH_TEMPORARY); | |
c5aa993b | 13970 | |
1bedd215 AC |
13971 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
13972 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13973 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 13974 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13975 | an expression changes.\n\ |
13976 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13977 | the memory to which it refers.")); | |
65d12d83 | 13978 | set_cmd_completer (c, expression_completer); |
c906108c | 13979 | |
1bedd215 AC |
13980 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
13981 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 13982 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 13983 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13984 | an expression is read.\n\ |
13985 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13986 | the memory to which it refers.")); | |
65d12d83 | 13987 | set_cmd_completer (c, expression_completer); |
c906108c | 13988 | |
1bedd215 AC |
13989 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
13990 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13991 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 13992 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13993 | an expression is either read or written.\n\ |
13994 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13995 | the memory to which it refers.")); | |
65d12d83 | 13996 | set_cmd_completer (c, expression_completer); |
c906108c | 13997 | |
d77f58be | 13998 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 13999 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 14000 | |
920d2a44 AC |
14001 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
14002 | respond to changes - contrary to the description. */ | |
85c07804 AC |
14003 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
14004 | &can_use_hw_watchpoints, _("\ | |
14005 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
14006 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
14007 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
14008 | such is available. (However, any hardware watchpoints that were\n\ | |
14009 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
14010 | hardware.)"), |
14011 | NULL, | |
920d2a44 | 14012 | show_can_use_hw_watchpoints, |
85c07804 | 14013 | &setlist, &showlist); |
c906108c SS |
14014 | |
14015 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 14016 | |
1042e4c0 SS |
14017 | /* Tracepoint manipulation commands. */ |
14018 | ||
14019 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
14020 | Set a tracepoint at specified line or function.\n\ | |
14021 | \n" | |
14022 | BREAK_ARGS_HELP ("trace") "\n\ | |
14023 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
14024 | set_cmd_completer (c, location_completer); | |
14025 | ||
14026 | add_com_alias ("tp", "trace", class_alias, 0); | |
14027 | add_com_alias ("tr", "trace", class_alias, 1); | |
14028 | add_com_alias ("tra", "trace", class_alias, 1); | |
14029 | add_com_alias ("trac", "trace", class_alias, 1); | |
14030 | ||
7a697b8d SS |
14031 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
14032 | Set a fast tracepoint at specified line or function.\n\ | |
14033 | \n" | |
14034 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
14035 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
14036 | set_cmd_completer (c, location_completer); | |
14037 | ||
0fb4aa4b PA |
14038 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
14039 | Set a static tracepoint at specified line, function or marker.\n\ | |
14040 | \n\ | |
14041 | strace [LOCATION] [if CONDITION]\n\ | |
14042 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
14043 | or -m MARKER_ID.\n\ | |
14044 | If a line number is specified, probe the marker at start of code\n\ | |
14045 | for that line. If a function is specified, probe the marker at start\n\ | |
14046 | of code for that function. If an address is specified, probe the marker\n\ | |
14047 | at that exact address. If a marker id is specified, probe the marker\n\ | |
14048 | with that name. With no LOCATION, uses current execution address of\n\ | |
14049 | the selected stack frame.\n\ | |
14050 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
14051 | This collects arbitrary user data passed in the probe point call to the\n\ | |
14052 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
14053 | by printing the $_sdata variable like any other convenience variable.\n\ | |
14054 | \n\ | |
14055 | CONDITION is a boolean expression.\n\ | |
14056 | \n\ | |
d41c0fc8 PA |
14057 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
14058 | conditions are different.\n\ | |
0fb4aa4b PA |
14059 | \n\ |
14060 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
14061 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
14062 | set_cmd_completer (c, location_completer); | |
14063 | ||
1042e4c0 | 14064 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 14065 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
14066 | Convenience variable \"$tpnum\" contains the number of the\n\ |
14067 | last tracepoint set.")); | |
14068 | ||
14069 | add_info_alias ("tp", "tracepoints", 1); | |
14070 | ||
14071 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
14072 | Delete specified tracepoints.\n\ | |
14073 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
14074 | No argument means delete all tracepoints."), | |
14075 | &deletelist); | |
14076 | ||
14077 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
14078 | Disable specified tracepoints.\n\ | |
14079 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
14080 | No argument means disable all tracepoints."), | |
14081 | &disablelist); | |
14082 | deprecate_cmd (c, "disable"); | |
14083 | ||
14084 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
14085 | Enable specified tracepoints.\n\ | |
14086 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
14087 | No argument means enable all tracepoints."), | |
14088 | &enablelist); | |
14089 | deprecate_cmd (c, "enable"); | |
14090 | ||
14091 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
14092 | Set the passcount for a tracepoint.\n\ | |
14093 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
14094 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
14095 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
14096 | ||
6149aea9 PA |
14097 | add_prefix_cmd ("save", class_breakpoint, save_command, |
14098 | _("Save breakpoint definitions as a script."), | |
14099 | &save_cmdlist, "save ", | |
14100 | 0/*allow-unknown*/, &cmdlist); | |
14101 | ||
14102 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
14103 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 14104 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
14105 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
14106 | session to restore them."), | |
14107 | &save_cmdlist); | |
14108 | set_cmd_completer (c, filename_completer); | |
14109 | ||
14110 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 14111 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
14112 | Use the 'source' command in another debug session to restore them."), |
14113 | &save_cmdlist); | |
1042e4c0 SS |
14114 | set_cmd_completer (c, filename_completer); |
14115 | ||
6149aea9 PA |
14116 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
14117 | deprecate_cmd (c, "save tracepoints"); | |
14118 | ||
1bedd215 | 14119 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
14120 | Breakpoint specific settings\n\ |
14121 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 14122 | pending breakpoint behavior"), |
fa8d40ab JJ |
14123 | &breakpoint_set_cmdlist, "set breakpoint ", |
14124 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 14125 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
14126 | Breakpoint specific settings\n\ |
14127 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 14128 | pending breakpoint behavior"), |
fa8d40ab JJ |
14129 | &breakpoint_show_cmdlist, "show breakpoint ", |
14130 | 0/*allow-unknown*/, &showlist); | |
14131 | ||
7915a72c AC |
14132 | add_setshow_auto_boolean_cmd ("pending", no_class, |
14133 | &pending_break_support, _("\ | |
14134 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
14135 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
14136 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
14137 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
14138 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 14139 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 14140 | NULL, |
920d2a44 | 14141 | show_pending_break_support, |
6e1d7d6c AC |
14142 | &breakpoint_set_cmdlist, |
14143 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
14144 | |
14145 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
14146 | |
14147 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
14148 | &automatic_hardware_breakpoints, _("\ | |
14149 | Set automatic usage of hardware breakpoints."), _("\ | |
14150 | Show automatic usage of hardware breakpoints."), _("\ | |
14151 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
14152 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
14153 | a warning will be emitted for such breakpoints."), | |
14154 | NULL, | |
14155 | show_automatic_hardware_breakpoints, | |
14156 | &breakpoint_set_cmdlist, | |
14157 | &breakpoint_show_cmdlist); | |
74960c60 | 14158 | |
33e5cbd6 PA |
14159 | add_setshow_enum_cmd ("always-inserted", class_support, |
14160 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
14161 | Set mode for inserting breakpoints."), _("\ |
14162 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
14163 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
14164 | resumed, and removed when execution stops. When this mode is on,\n\ | |
14165 | breakpoints are inserted immediately and removed only when the user\n\ | |
14166 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
14167 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
14168 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
14169 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
14170 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
14171 | NULL, |
14172 | &show_always_inserted_mode, | |
14173 | &breakpoint_set_cmdlist, | |
14174 | &breakpoint_show_cmdlist); | |
f1310107 TJB |
14175 | |
14176 | add_com ("break-range", class_breakpoint, break_range_command, _("\ | |
14177 | Set a breakpoint for an address range.\n\ | |
14178 | break-range START-LOCATION, END-LOCATION\n\ | |
14179 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
14180 | LINENUM, for that line in the current file,\n\ | |
14181 | FILE:LINENUM, for that line in that file,\n\ | |
14182 | +OFFSET, for that number of lines after the current line\n\ | |
14183 | or the start of the range\n\ | |
14184 | FUNCTION, for the first line in that function,\n\ | |
14185 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
14186 | *ADDRESS, for the instruction at that address.\n\ | |
14187 | \n\ | |
14188 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
14189 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
14190 | range (including START-LOCATION and END-LOCATION).")); | |
14191 | ||
765dc015 | 14192 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
14193 | |
14194 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 14195 | } |