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" | |
41 | #include "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" |
c906108c | 68 | |
1042e4c0 SS |
69 | /* readline include files */ |
70 | #include "readline/readline.h" | |
71 | #include "readline/history.h" | |
72 | ||
73 | /* readline defines this. */ | |
74 | #undef savestring | |
75 | ||
034dad6f | 76 | #include "mi/mi-common.h" |
7371cf6d | 77 | #include "python/python.h" |
104c1213 | 78 | |
4a64f543 | 79 | /* Prototypes for local functions. */ |
c906108c | 80 | |
a14ed312 | 81 | static void enable_delete_command (char *, int); |
c906108c | 82 | |
a14ed312 | 83 | static void enable_once_command (char *, int); |
c906108c | 84 | |
a14ed312 | 85 | static void disable_command (char *, int); |
c906108c | 86 | |
a14ed312 | 87 | static void enable_command (char *, int); |
c906108c | 88 | |
95a42b64 TT |
89 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
90 | void *), | |
91 | void *); | |
c906108c | 92 | |
a14ed312 | 93 | static void ignore_command (char *, int); |
c906108c | 94 | |
4efb68b1 | 95 | static int breakpoint_re_set_one (void *); |
c906108c | 96 | |
348d480f PA |
97 | static void breakpoint_re_set_default (struct breakpoint *); |
98 | ||
a14ed312 | 99 | static void clear_command (char *, int); |
c906108c | 100 | |
a14ed312 | 101 | static void catch_command (char *, int); |
c906108c | 102 | |
a9634178 | 103 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 104 | |
98deb0da | 105 | static void break_command_1 (char *, int, int); |
c906108c | 106 | |
a14ed312 | 107 | static void mention (struct breakpoint *); |
c906108c | 108 | |
348d480f PA |
109 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
110 | enum bptype, | |
c0a91b2b | 111 | const struct breakpoint_ops *); |
4a64f543 MS |
112 | /* This function is used in gdbtk sources and thus can not be made |
113 | static. */ | |
63c252f8 | 114 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 115 | struct symtab_and_line, |
c0a91b2b TT |
116 | enum bptype, |
117 | const struct breakpoint_ops *); | |
c906108c | 118 | |
06edf0c0 PA |
119 | static struct breakpoint * |
120 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
121 | enum bptype type, | |
c0a91b2b | 122 | const struct breakpoint_ops *ops); |
06edf0c0 | 123 | |
76897487 KB |
124 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
125 | ||
a6d9a66e UW |
126 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
127 | CORE_ADDR bpaddr, | |
88f7da05 | 128 | enum bptype bptype); |
76897487 | 129 | |
6c95b8df PA |
130 | static void describe_other_breakpoints (struct gdbarch *, |
131 | struct program_space *, CORE_ADDR, | |
5af949e3 | 132 | struct obj_section *, int); |
c906108c | 133 | |
6c95b8df PA |
134 | static int breakpoint_address_match (struct address_space *aspace1, |
135 | CORE_ADDR addr1, | |
136 | struct address_space *aspace2, | |
137 | CORE_ADDR addr2); | |
138 | ||
85d721b8 PA |
139 | static int watchpoint_locations_match (struct bp_location *loc1, |
140 | struct bp_location *loc2); | |
141 | ||
f1310107 TJB |
142 | static int breakpoint_location_address_match (struct bp_location *bl, |
143 | struct address_space *aspace, | |
144 | CORE_ADDR addr); | |
145 | ||
a14ed312 | 146 | static void breakpoints_info (char *, int); |
c906108c | 147 | |
d77f58be SS |
148 | static void watchpoints_info (char *, int); |
149 | ||
e5a67952 MS |
150 | static int breakpoint_1 (char *, int, |
151 | int (*) (const struct breakpoint *)); | |
c906108c | 152 | |
4efb68b1 | 153 | static int breakpoint_cond_eval (void *); |
c906108c | 154 | |
4efb68b1 | 155 | static void cleanup_executing_breakpoints (void *); |
c906108c | 156 | |
a14ed312 | 157 | static void commands_command (char *, int); |
c906108c | 158 | |
a14ed312 | 159 | static void condition_command (char *, int); |
c906108c | 160 | |
c5aa993b JM |
161 | typedef enum |
162 | { | |
163 | mark_inserted, | |
164 | mark_uninserted | |
165 | } | |
166 | insertion_state_t; | |
c906108c | 167 | |
0bde7532 | 168 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 169 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 170 | |
e514a9d6 | 171 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 172 | |
4efb68b1 | 173 | static int watchpoint_check (void *); |
c906108c | 174 | |
a14ed312 | 175 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 176 | |
a14ed312 | 177 | static int hw_breakpoint_used_count (void); |
c906108c | 178 | |
a1398e0c PA |
179 | static int hw_watchpoint_use_count (struct breakpoint *); |
180 | ||
181 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
182 | enum bptype type, | |
183 | int *other_type_used); | |
c906108c | 184 | |
a14ed312 | 185 | static void hbreak_command (char *, int); |
c906108c | 186 | |
a14ed312 | 187 | static void thbreak_command (char *, int); |
c906108c | 188 | |
51be5b68 | 189 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp); |
c906108c | 190 | |
a14ed312 | 191 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 192 | |
a14ed312 | 193 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 194 | |
a14ed312 | 195 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 196 | |
a14ed312 | 197 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 198 | |
d85310f7 MS |
199 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
200 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 201 | |
a14ed312 | 202 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 203 | |
d03285ec UW |
204 | static void detach_single_step_breakpoints (void); |
205 | ||
6c95b8df PA |
206 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
207 | CORE_ADDR pc); | |
1aafd4da | 208 | |
fe3f5fa8 | 209 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
210 | static void incref_bp_location (struct bp_location *loc); |
211 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 212 | |
39d61571 | 213 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 214 | |
b60e7edf | 215 | static void update_global_location_list (int); |
a5606eee | 216 | |
b60e7edf | 217 | static void update_global_location_list_nothrow (int); |
74960c60 | 218 | |
d77f58be | 219 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
220 | |
221 | static void insert_breakpoint_locations (void); | |
a5606eee | 222 | |
a96d9b2e SDJ |
223 | static int syscall_catchpoint_p (struct breakpoint *b); |
224 | ||
1042e4c0 SS |
225 | static void tracepoints_info (char *, int); |
226 | ||
227 | static void delete_trace_command (char *, int); | |
228 | ||
229 | static void enable_trace_command (char *, int); | |
230 | ||
231 | static void disable_trace_command (char *, int); | |
232 | ||
233 | static void trace_pass_command (char *, int); | |
234 | ||
9c06b0b4 TJB |
235 | static int is_masked_watchpoint (const struct breakpoint *b); |
236 | ||
0fb4aa4b PA |
237 | /* Assuming we're creating a static tracepoint, does S look like a |
238 | static tracepoint marker spec ("-m MARKER_ID")? */ | |
239 | #define is_marker_spec(s) \ | |
f5a8e22b | 240 | (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t')) |
0fb4aa4b | 241 | |
2060206e PA |
242 | /* The abstract base class all breakpoint_ops structures inherit |
243 | from. */ | |
244 | static struct breakpoint_ops base_breakpoint_ops; | |
245 | ||
246 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
247 | that are implemented on top of software or hardware breakpoints | |
248 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
249 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
250 | ||
251 | /* Internal breakpoints class type. */ | |
06edf0c0 | 252 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
253 | |
254 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
255 | static struct breakpoint_ops momentary_breakpoint_ops; |
256 | ||
2060206e PA |
257 | /* The breakpoint_ops structure to be used in regular user created |
258 | breakpoints. */ | |
259 | struct breakpoint_ops bkpt_breakpoint_ops; | |
260 | ||
5cea2a26 PA |
261 | /* A reference-counted struct command_line. This lets multiple |
262 | breakpoints share a single command list. */ | |
263 | struct counted_command_line | |
264 | { | |
265 | /* The reference count. */ | |
266 | int refc; | |
267 | ||
268 | /* The command list. */ | |
269 | struct command_line *commands; | |
270 | }; | |
271 | ||
272 | struct command_line * | |
273 | breakpoint_commands (struct breakpoint *b) | |
274 | { | |
275 | return b->commands ? b->commands->commands : NULL; | |
276 | } | |
3daf8fe5 | 277 | |
f3b1572e PA |
278 | /* Flag indicating that a command has proceeded the inferior past the |
279 | current breakpoint. */ | |
280 | ||
281 | static int breakpoint_proceeded; | |
282 | ||
956a9fb9 | 283 | const char * |
2cec12e5 AR |
284 | bpdisp_text (enum bpdisp disp) |
285 | { | |
4a64f543 MS |
286 | /* NOTE: the following values are a part of MI protocol and |
287 | represent values of 'disp' field returned when inferior stops at | |
288 | a breakpoint. */ | |
bc043ef3 | 289 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 290 | |
2cec12e5 AR |
291 | return bpdisps[(int) disp]; |
292 | } | |
c906108c | 293 | |
4a64f543 | 294 | /* Prototypes for exported functions. */ |
c906108c | 295 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 296 | if such is available. */ |
c906108c SS |
297 | static int can_use_hw_watchpoints; |
298 | ||
920d2a44 AC |
299 | static void |
300 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
301 | struct cmd_list_element *c, | |
302 | const char *value) | |
303 | { | |
3e43a32a MS |
304 | fprintf_filtered (file, |
305 | _("Debugger's willingness to use " | |
306 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
307 | value); |
308 | } | |
309 | ||
fa8d40ab JJ |
310 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
311 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 312 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
313 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
314 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
315 | static void |
316 | show_pending_break_support (struct ui_file *file, int from_tty, | |
317 | struct cmd_list_element *c, | |
318 | const char *value) | |
319 | { | |
3e43a32a MS |
320 | fprintf_filtered (file, |
321 | _("Debugger's behavior regarding " | |
322 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
323 | value); |
324 | } | |
fa8d40ab | 325 | |
765dc015 | 326 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 327 | set with "break" but falling in read-only memory. |
765dc015 VP |
328 | If 0, gdb will warn about such breakpoints, but won't automatically |
329 | use hardware breakpoints. */ | |
330 | static int automatic_hardware_breakpoints; | |
331 | static void | |
332 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
333 | struct cmd_list_element *c, | |
334 | const char *value) | |
335 | { | |
3e43a32a MS |
336 | fprintf_filtered (file, |
337 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
338 | value); |
339 | } | |
340 | ||
33e5cbd6 PA |
341 | /* If on, gdb will keep breakpoints inserted even as inferior is |
342 | stopped, and immediately insert any new breakpoints. If off, gdb | |
343 | will insert breakpoints into inferior only when resuming it, and | |
344 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
345 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
346 | ||
347 | static const char always_inserted_auto[] = "auto"; | |
348 | static const char always_inserted_on[] = "on"; | |
349 | static const char always_inserted_off[] = "off"; | |
350 | static const char *always_inserted_enums[] = { | |
351 | always_inserted_auto, | |
352 | always_inserted_off, | |
353 | always_inserted_on, | |
354 | NULL | |
355 | }; | |
356 | static const char *always_inserted_mode = always_inserted_auto; | |
357 | static void | |
74960c60 | 358 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 359 | struct cmd_list_element *c, const char *value) |
74960c60 | 360 | { |
33e5cbd6 | 361 | if (always_inserted_mode == always_inserted_auto) |
3e43a32a MS |
362 | fprintf_filtered (file, |
363 | _("Always inserted breakpoint " | |
364 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
365 | value, |
366 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
367 | else | |
3e43a32a MS |
368 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
369 | value); | |
74960c60 VP |
370 | } |
371 | ||
33e5cbd6 PA |
372 | int |
373 | breakpoints_always_inserted_mode (void) | |
374 | { | |
375 | return (always_inserted_mode == always_inserted_on | |
376 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
377 | } | |
765dc015 | 378 | |
a14ed312 | 379 | void _initialize_breakpoint (void); |
c906108c | 380 | |
c906108c SS |
381 | /* Are we executing breakpoint commands? */ |
382 | static int executing_breakpoint_commands; | |
383 | ||
c02f5703 MS |
384 | /* Are overlay event breakpoints enabled? */ |
385 | static int overlay_events_enabled; | |
386 | ||
e09342b5 TJB |
387 | /* See description in breakpoint.h. */ |
388 | int target_exact_watchpoints = 0; | |
389 | ||
c906108c | 390 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 391 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 392 | current breakpoint. */ |
c906108c | 393 | |
5c44784c | 394 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 395 | |
5c44784c JM |
396 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
397 | for (B = breakpoint_chain; \ | |
398 | B ? (TMP=B->next, 1): 0; \ | |
399 | B = TMP) | |
c906108c | 400 | |
4a64f543 MS |
401 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
402 | not provided so update_global_location_list must not be called | |
403 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 404 | |
876fa593 JK |
405 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
406 | for (BP_TMP = bp_location; \ | |
407 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
408 | BP_TMP++) | |
7cc221ef | 409 | |
1042e4c0 SS |
410 | /* Iterator for tracepoints only. */ |
411 | ||
412 | #define ALL_TRACEPOINTS(B) \ | |
413 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 414 | if (is_tracepoint (B)) |
1042e4c0 | 415 | |
7cc221ef | 416 | /* Chains of all breakpoints defined. */ |
c906108c SS |
417 | |
418 | struct breakpoint *breakpoint_chain; | |
419 | ||
876fa593 JK |
420 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
421 | ||
422 | static struct bp_location **bp_location; | |
423 | ||
424 | /* Number of elements of BP_LOCATION. */ | |
425 | ||
426 | static unsigned bp_location_count; | |
427 | ||
4a64f543 MS |
428 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
429 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
430 | result from bp_location_has_shadow. You can use it for roughly | |
431 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
432 | an address you need to read. */ | |
876fa593 JK |
433 | |
434 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
435 | ||
4a64f543 MS |
436 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
437 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
438 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
439 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
440 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
441 | |
442 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 443 | |
4a64f543 MS |
444 | /* The locations that no longer correspond to any breakpoint, unlinked |
445 | from bp_location array, but for which a hit may still be reported | |
446 | by a target. */ | |
20874c92 VP |
447 | VEC(bp_location_p) *moribund_locations = NULL; |
448 | ||
c906108c SS |
449 | /* Number of last breakpoint made. */ |
450 | ||
95a42b64 TT |
451 | static int breakpoint_count; |
452 | ||
86b17b60 PA |
453 | /* The value of `breakpoint_count' before the last command that |
454 | created breakpoints. If the last (break-like) command created more | |
455 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
456 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
457 | static int prev_breakpoint_count; | |
c906108c | 458 | |
1042e4c0 SS |
459 | /* Number of last tracepoint made. */ |
460 | ||
95a42b64 | 461 | static int tracepoint_count; |
1042e4c0 | 462 | |
6149aea9 PA |
463 | static struct cmd_list_element *breakpoint_set_cmdlist; |
464 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 465 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 466 | |
468d015d JJ |
467 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
468 | static int | |
469 | breakpoint_enabled (struct breakpoint *b) | |
470 | { | |
0d381245 | 471 | return (b->enable_state == bp_enabled); |
468d015d JJ |
472 | } |
473 | ||
c906108c SS |
474 | /* Set breakpoint count to NUM. */ |
475 | ||
95a42b64 | 476 | static void |
fba45db2 | 477 | set_breakpoint_count (int num) |
c906108c | 478 | { |
86b17b60 | 479 | prev_breakpoint_count = breakpoint_count; |
c906108c | 480 | breakpoint_count = num; |
4fa62494 | 481 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
482 | } |
483 | ||
86b17b60 PA |
484 | /* Used by `start_rbreak_breakpoints' below, to record the current |
485 | breakpoint count before "rbreak" creates any breakpoint. */ | |
486 | static int rbreak_start_breakpoint_count; | |
487 | ||
95a42b64 TT |
488 | /* Called at the start an "rbreak" command to record the first |
489 | breakpoint made. */ | |
86b17b60 | 490 | |
95a42b64 TT |
491 | void |
492 | start_rbreak_breakpoints (void) | |
493 | { | |
86b17b60 | 494 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
495 | } |
496 | ||
497 | /* Called at the end of an "rbreak" command to record the last | |
498 | breakpoint made. */ | |
86b17b60 | 499 | |
95a42b64 TT |
500 | void |
501 | end_rbreak_breakpoints (void) | |
502 | { | |
86b17b60 | 503 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
504 | } |
505 | ||
4a64f543 | 506 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
507 | |
508 | void | |
fba45db2 | 509 | clear_breakpoint_hit_counts (void) |
c906108c SS |
510 | { |
511 | struct breakpoint *b; | |
512 | ||
513 | ALL_BREAKPOINTS (b) | |
514 | b->hit_count = 0; | |
515 | } | |
516 | ||
9add0f1b TT |
517 | /* Allocate a new counted_command_line with reference count of 1. |
518 | The new structure owns COMMANDS. */ | |
519 | ||
520 | static struct counted_command_line * | |
521 | alloc_counted_command_line (struct command_line *commands) | |
522 | { | |
523 | struct counted_command_line *result | |
524 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 525 | |
9add0f1b TT |
526 | result->refc = 1; |
527 | result->commands = commands; | |
528 | return result; | |
529 | } | |
530 | ||
531 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
532 | ||
533 | static void | |
534 | incref_counted_command_line (struct counted_command_line *cmd) | |
535 | { | |
536 | if (cmd) | |
537 | ++cmd->refc; | |
538 | } | |
539 | ||
540 | /* Decrement reference count. If the reference count reaches 0, | |
541 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
542 | nothing if *CMDP is NULL. */ | |
543 | ||
544 | static void | |
545 | decref_counted_command_line (struct counted_command_line **cmdp) | |
546 | { | |
547 | if (*cmdp) | |
548 | { | |
549 | if (--(*cmdp)->refc == 0) | |
550 | { | |
551 | free_command_lines (&(*cmdp)->commands); | |
552 | xfree (*cmdp); | |
553 | } | |
554 | *cmdp = NULL; | |
555 | } | |
556 | } | |
557 | ||
558 | /* A cleanup function that calls decref_counted_command_line. */ | |
559 | ||
560 | static void | |
561 | do_cleanup_counted_command_line (void *arg) | |
562 | { | |
563 | decref_counted_command_line (arg); | |
564 | } | |
565 | ||
566 | /* Create a cleanup that calls decref_counted_command_line on the | |
567 | argument. */ | |
568 | ||
569 | static struct cleanup * | |
570 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
571 | { | |
572 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
573 | } | |
574 | ||
c906108c SS |
575 | /* Default address, symtab and line to put a breakpoint at |
576 | for "break" command with no arg. | |
4a64f543 | 577 | If default_breakpoint_valid is zero, the other three are |
c906108c SS |
578 | not valid, and "break" with no arg is an error. |
579 | ||
580 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
581 | ||
582 | int default_breakpoint_valid; | |
583 | CORE_ADDR default_breakpoint_address; | |
584 | struct symtab *default_breakpoint_symtab; | |
585 | int default_breakpoint_line; | |
6c95b8df PA |
586 | struct program_space *default_breakpoint_pspace; |
587 | ||
c906108c | 588 | \f |
48cb2d85 VP |
589 | /* Return the breakpoint with the specified number, or NULL |
590 | if the number does not refer to an existing breakpoint. */ | |
591 | ||
592 | struct breakpoint * | |
593 | get_breakpoint (int num) | |
594 | { | |
595 | struct breakpoint *b; | |
596 | ||
597 | ALL_BREAKPOINTS (b) | |
598 | if (b->number == num) | |
599 | return b; | |
600 | ||
601 | return NULL; | |
602 | } | |
5c44784c | 603 | |
c906108c | 604 | \f |
adc36818 PM |
605 | |
606 | void | |
607 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
608 | int from_tty) | |
609 | { | |
3a5c3e22 PA |
610 | xfree (b->cond_string); |
611 | b->cond_string = NULL; | |
adc36818 | 612 | |
3a5c3e22 | 613 | if (is_watchpoint (b)) |
adc36818 | 614 | { |
3a5c3e22 PA |
615 | struct watchpoint *w = (struct watchpoint *) b; |
616 | ||
617 | xfree (w->cond_exp); | |
618 | w->cond_exp = NULL; | |
619 | } | |
620 | else | |
621 | { | |
622 | struct bp_location *loc; | |
623 | ||
624 | for (loc = b->loc; loc; loc = loc->next) | |
625 | { | |
626 | xfree (loc->cond); | |
627 | loc->cond = NULL; | |
628 | } | |
adc36818 | 629 | } |
adc36818 PM |
630 | |
631 | if (*exp == 0) | |
632 | { | |
633 | if (from_tty) | |
634 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
635 | } | |
636 | else | |
637 | { | |
638 | char *arg = exp; | |
cc59ec59 | 639 | |
adc36818 PM |
640 | /* I don't know if it matters whether this is the string the user |
641 | typed in or the decompiled expression. */ | |
642 | b->cond_string = xstrdup (arg); | |
643 | b->condition_not_parsed = 0; | |
644 | ||
645 | if (is_watchpoint (b)) | |
646 | { | |
3a5c3e22 PA |
647 | struct watchpoint *w = (struct watchpoint *) b; |
648 | ||
adc36818 PM |
649 | innermost_block = NULL; |
650 | arg = exp; | |
3a5c3e22 | 651 | w->cond_exp = parse_exp_1 (&arg, 0, 0); |
adc36818 PM |
652 | if (*arg) |
653 | error (_("Junk at end of expression")); | |
3a5c3e22 | 654 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
655 | } |
656 | else | |
657 | { | |
3a5c3e22 PA |
658 | struct bp_location *loc; |
659 | ||
adc36818 PM |
660 | for (loc = b->loc; loc; loc = loc->next) |
661 | { | |
662 | arg = exp; | |
663 | loc->cond = | |
664 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
665 | if (*arg) | |
666 | error (_("Junk at end of expression")); | |
667 | } | |
668 | } | |
669 | } | |
670 | breakpoints_changed (); | |
8d3788bd | 671 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
672 | } |
673 | ||
c906108c SS |
674 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
675 | ||
676 | static void | |
fba45db2 | 677 | condition_command (char *arg, int from_tty) |
c906108c | 678 | { |
52f0bd74 | 679 | struct breakpoint *b; |
c906108c | 680 | char *p; |
52f0bd74 | 681 | int bnum; |
c906108c SS |
682 | |
683 | if (arg == 0) | |
e2e0b3e5 | 684 | error_no_arg (_("breakpoint number")); |
c906108c SS |
685 | |
686 | p = arg; | |
687 | bnum = get_number (&p); | |
5c44784c | 688 | if (bnum == 0) |
8a3fe4f8 | 689 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
690 | |
691 | ALL_BREAKPOINTS (b) | |
692 | if (b->number == bnum) | |
2f069f6f | 693 | { |
7371cf6d PM |
694 | /* Check if this breakpoint has a Python object assigned to |
695 | it, and if it has a definition of the "stop" | |
696 | method. This method and conditions entered into GDB from | |
697 | the CLI are mutually exclusive. */ | |
698 | if (b->py_bp_object | |
699 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
700 | error (_("Cannot set a condition where a Python 'stop' " | |
701 | "method has been defined in the breakpoint.")); | |
2566ad2d | 702 | set_breakpoint_condition (b, p, from_tty); |
2f069f6f JB |
703 | return; |
704 | } | |
c906108c | 705 | |
8a3fe4f8 | 706 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
707 | } |
708 | ||
a7bdde9e VP |
709 | /* Check that COMMAND do not contain commands that are suitable |
710 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
711 | Throw if any such commands is found. */ |
712 | ||
a7bdde9e VP |
713 | static void |
714 | check_no_tracepoint_commands (struct command_line *commands) | |
715 | { | |
716 | struct command_line *c; | |
cc59ec59 | 717 | |
a7bdde9e VP |
718 | for (c = commands; c; c = c->next) |
719 | { | |
720 | int i; | |
721 | ||
722 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
723 | error (_("The 'while-stepping' command can " |
724 | "only be used for tracepoints")); | |
a7bdde9e VP |
725 | |
726 | for (i = 0; i < c->body_count; ++i) | |
727 | check_no_tracepoint_commands ((c->body_list)[i]); | |
728 | ||
729 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 730 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
731 | command directly. */ |
732 | if (strstr (c->line, "collect ") == c->line) | |
733 | error (_("The 'collect' command can only be used for tracepoints")); | |
734 | ||
51661e93 VP |
735 | if (strstr (c->line, "teval ") == c->line) |
736 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
737 | } |
738 | } | |
739 | ||
d77f58be SS |
740 | /* Encapsulate tests for different types of tracepoints. */ |
741 | ||
d9b3f62e PA |
742 | static int |
743 | is_tracepoint_type (enum bptype type) | |
744 | { | |
745 | return (type == bp_tracepoint | |
746 | || type == bp_fast_tracepoint | |
747 | || type == bp_static_tracepoint); | |
748 | } | |
749 | ||
a7bdde9e | 750 | int |
d77f58be | 751 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 752 | { |
d9b3f62e | 753 | return is_tracepoint_type (b->type); |
a7bdde9e | 754 | } |
d9b3f62e | 755 | |
e5dd4106 | 756 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
757 | breakpoint. This function will throw an exception if a problem is |
758 | found. */ | |
48cb2d85 | 759 | |
95a42b64 TT |
760 | static void |
761 | validate_commands_for_breakpoint (struct breakpoint *b, | |
762 | struct command_line *commands) | |
48cb2d85 | 763 | { |
d77f58be | 764 | if (is_tracepoint (b)) |
a7bdde9e | 765 | { |
4a64f543 MS |
766 | /* We need to verify that each top-level element of commands is |
767 | valid for tracepoints, that there's at most one | |
768 | while-stepping element, and that while-stepping's body has | |
769 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
770 | struct command_line *c; |
771 | struct command_line *while_stepping = 0; | |
772 | for (c = commands; c; c = c->next) | |
773 | { | |
a7bdde9e VP |
774 | if (c->control_type == while_stepping_control) |
775 | { | |
776 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
777 | error (_("The 'while-stepping' command " |
778 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 779 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
780 | error (_("The 'while-stepping' command " |
781 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
782 | |
783 | if (while_stepping) | |
3e43a32a MS |
784 | error (_("The 'while-stepping' command " |
785 | "can be used only once")); | |
a7bdde9e VP |
786 | else |
787 | while_stepping = c; | |
788 | } | |
789 | } | |
790 | if (while_stepping) | |
791 | { | |
792 | struct command_line *c2; | |
793 | ||
794 | gdb_assert (while_stepping->body_count == 1); | |
795 | c2 = while_stepping->body_list[0]; | |
796 | for (; c2; c2 = c2->next) | |
797 | { | |
a7bdde9e VP |
798 | if (c2->control_type == while_stepping_control) |
799 | error (_("The 'while-stepping' command cannot be nested")); | |
800 | } | |
801 | } | |
802 | } | |
803 | else | |
804 | { | |
805 | check_no_tracepoint_commands (commands); | |
806 | } | |
95a42b64 TT |
807 | } |
808 | ||
0fb4aa4b PA |
809 | /* Return a vector of all the static tracepoints set at ADDR. The |
810 | caller is responsible for releasing the vector. */ | |
811 | ||
812 | VEC(breakpoint_p) * | |
813 | static_tracepoints_here (CORE_ADDR addr) | |
814 | { | |
815 | struct breakpoint *b; | |
816 | VEC(breakpoint_p) *found = 0; | |
817 | struct bp_location *loc; | |
818 | ||
819 | ALL_BREAKPOINTS (b) | |
820 | if (b->type == bp_static_tracepoint) | |
821 | { | |
822 | for (loc = b->loc; loc; loc = loc->next) | |
823 | if (loc->address == addr) | |
824 | VEC_safe_push(breakpoint_p, found, b); | |
825 | } | |
826 | ||
827 | return found; | |
828 | } | |
829 | ||
95a42b64 | 830 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 831 | validate that only allowed commands are included. */ |
95a42b64 TT |
832 | |
833 | void | |
4a64f543 MS |
834 | breakpoint_set_commands (struct breakpoint *b, |
835 | struct command_line *commands) | |
95a42b64 TT |
836 | { |
837 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 838 | |
9add0f1b TT |
839 | decref_counted_command_line (&b->commands); |
840 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 | 841 | breakpoints_changed (); |
8d3788bd | 842 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
843 | } |
844 | ||
45a43567 TT |
845 | /* Set the internal `silent' flag on the breakpoint. Note that this |
846 | is not the same as the "silent" that may appear in the breakpoint's | |
847 | commands. */ | |
848 | ||
849 | void | |
850 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
851 | { | |
852 | int old_silent = b->silent; | |
853 | ||
854 | b->silent = silent; | |
855 | if (old_silent != silent) | |
8d3788bd | 856 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
857 | } |
858 | ||
859 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
860 | breakpoint work for any thread. */ | |
861 | ||
862 | void | |
863 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
864 | { | |
865 | int old_thread = b->thread; | |
866 | ||
867 | b->thread = thread; | |
868 | if (old_thread != thread) | |
8d3788bd | 869 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
870 | } |
871 | ||
872 | /* Set the task for this breakpoint. If TASK is 0, make the | |
873 | breakpoint work for any task. */ | |
874 | ||
875 | void | |
876 | breakpoint_set_task (struct breakpoint *b, int task) | |
877 | { | |
878 | int old_task = b->task; | |
879 | ||
880 | b->task = task; | |
881 | if (old_task != task) | |
8d3788bd | 882 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
883 | } |
884 | ||
95a42b64 TT |
885 | void |
886 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
887 | { |
888 | struct breakpoint *b = closure; | |
cc59ec59 | 889 | |
a7bdde9e VP |
890 | validate_actionline (&line, b); |
891 | } | |
892 | ||
95a42b64 TT |
893 | /* A structure used to pass information through |
894 | map_breakpoint_numbers. */ | |
895 | ||
896 | struct commands_info | |
897 | { | |
898 | /* True if the command was typed at a tty. */ | |
899 | int from_tty; | |
86b17b60 PA |
900 | |
901 | /* The breakpoint range spec. */ | |
902 | char *arg; | |
903 | ||
95a42b64 TT |
904 | /* Non-NULL if the body of the commands are being read from this |
905 | already-parsed command. */ | |
906 | struct command_line *control; | |
86b17b60 | 907 | |
95a42b64 TT |
908 | /* The command lines read from the user, or NULL if they have not |
909 | yet been read. */ | |
910 | struct counted_command_line *cmd; | |
911 | }; | |
912 | ||
913 | /* A callback for map_breakpoint_numbers that sets the commands for | |
914 | commands_command. */ | |
915 | ||
c906108c | 916 | static void |
95a42b64 | 917 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 918 | { |
95a42b64 | 919 | struct commands_info *info = data; |
c906108c | 920 | |
95a42b64 TT |
921 | if (info->cmd == NULL) |
922 | { | |
923 | struct command_line *l; | |
5c44784c | 924 | |
95a42b64 TT |
925 | if (info->control != NULL) |
926 | l = copy_command_lines (info->control->body_list[0]); | |
927 | else | |
86b17b60 PA |
928 | { |
929 | struct cleanup *old_chain; | |
930 | char *str; | |
c5aa993b | 931 | |
3e43a32a MS |
932 | str = xstrprintf (_("Type commands for breakpoint(s) " |
933 | "%s, one per line."), | |
86b17b60 PA |
934 | info->arg); |
935 | ||
936 | old_chain = make_cleanup (xfree, str); | |
937 | ||
938 | l = read_command_lines (str, | |
939 | info->from_tty, 1, | |
d77f58be | 940 | (is_tracepoint (b) |
86b17b60 PA |
941 | ? check_tracepoint_command : 0), |
942 | b); | |
943 | ||
944 | do_cleanups (old_chain); | |
945 | } | |
a7bdde9e | 946 | |
95a42b64 TT |
947 | info->cmd = alloc_counted_command_line (l); |
948 | } | |
949 | ||
950 | /* If a breakpoint was on the list more than once, we don't need to | |
951 | do anything. */ | |
952 | if (b->commands != info->cmd) | |
953 | { | |
954 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
955 | incref_counted_command_line (info->cmd); | |
956 | decref_counted_command_line (&b->commands); | |
957 | b->commands = info->cmd; | |
958 | breakpoints_changed (); | |
8d3788bd | 959 | observer_notify_breakpoint_modified (b); |
c5aa993b | 960 | } |
95a42b64 TT |
961 | } |
962 | ||
963 | static void | |
4a64f543 MS |
964 | commands_command_1 (char *arg, int from_tty, |
965 | struct command_line *control) | |
95a42b64 TT |
966 | { |
967 | struct cleanup *cleanups; | |
968 | struct commands_info info; | |
969 | ||
970 | info.from_tty = from_tty; | |
971 | info.control = control; | |
972 | info.cmd = NULL; | |
973 | /* If we read command lines from the user, then `info' will hold an | |
974 | extra reference to the commands that we must clean up. */ | |
975 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
976 | ||
977 | if (arg == NULL || !*arg) | |
978 | { | |
86b17b60 | 979 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
980 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
981 | breakpoint_count); | |
95a42b64 TT |
982 | else if (breakpoint_count > 0) |
983 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
984 | else |
985 | { | |
986 | /* So that we don't try to free the incoming non-NULL | |
987 | argument in the cleanup below. Mapping breakpoint | |
988 | numbers will fail in this case. */ | |
989 | arg = NULL; | |
990 | } | |
95a42b64 | 991 | } |
9766ced4 SS |
992 | else |
993 | /* The command loop has some static state, so we need to preserve | |
994 | our argument. */ | |
995 | arg = xstrdup (arg); | |
86b17b60 PA |
996 | |
997 | if (arg != NULL) | |
998 | make_cleanup (xfree, arg); | |
999 | ||
1000 | info.arg = arg; | |
95a42b64 TT |
1001 | |
1002 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1003 | ||
1004 | if (info.cmd == NULL) | |
1005 | error (_("No breakpoints specified.")); | |
1006 | ||
1007 | do_cleanups (cleanups); | |
1008 | } | |
1009 | ||
1010 | static void | |
1011 | commands_command (char *arg, int from_tty) | |
1012 | { | |
1013 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1014 | } |
40c03ae8 EZ |
1015 | |
1016 | /* Like commands_command, but instead of reading the commands from | |
1017 | input stream, takes them from an already parsed command structure. | |
1018 | ||
1019 | This is used by cli-script.c to DTRT with breakpoint commands | |
1020 | that are part of if and while bodies. */ | |
1021 | enum command_control_type | |
1022 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1023 | { | |
95a42b64 TT |
1024 | commands_command_1 (arg, 0, cmd); |
1025 | return simple_control; | |
40c03ae8 | 1026 | } |
876fa593 JK |
1027 | |
1028 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1029 | ||
1030 | static int | |
1031 | bp_location_has_shadow (struct bp_location *bl) | |
1032 | { | |
1033 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1034 | return 0; | |
1035 | if (!bl->inserted) | |
1036 | return 0; | |
1037 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1038 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1039 | return 0; |
1040 | return 1; | |
1041 | } | |
1042 | ||
8defab1a | 1043 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1044 | by replacing any memory breakpoints with their shadowed contents. |
1045 | ||
1046 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
1047 | bl->address - bp_location_placed_address_before_address_max |
1048 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1049 | The range we were requested to resolve shadows for is: |
1050 | memaddr ... memaddr + len | |
1051 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1052 | memaddr + len <= (bl->address |
1053 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1054 | and: |
35df4500 | 1055 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1056 | |
8defab1a DJ |
1057 | void |
1058 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1059 | { |
4a64f543 MS |
1060 | /* Left boundary, right boundary and median element of our binary |
1061 | search. */ | |
876fa593 JK |
1062 | unsigned bc_l, bc_r, bc; |
1063 | ||
4a64f543 MS |
1064 | /* Find BC_L which is a leftmost element which may affect BUF |
1065 | content. It is safe to report lower value but a failure to | |
1066 | report higher one. */ | |
876fa593 JK |
1067 | |
1068 | bc_l = 0; | |
1069 | bc_r = bp_location_count; | |
1070 | while (bc_l + 1 < bc_r) | |
1071 | { | |
35df4500 | 1072 | struct bp_location *bl; |
876fa593 JK |
1073 | |
1074 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1075 | bl = bp_location[bc]; |
876fa593 | 1076 | |
4a64f543 MS |
1077 | /* Check first BL->ADDRESS will not overflow due to the added |
1078 | constant. Then advance the left boundary only if we are sure | |
1079 | the BC element can in no way affect the BUF content (MEMADDR | |
1080 | to MEMADDR + LEN range). | |
876fa593 | 1081 | |
4a64f543 MS |
1082 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1083 | offset so that we cannot miss a breakpoint with its shadow | |
1084 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1085 | |
35df4500 TJB |
1086 | if ((bl->address + bp_location_shadow_len_after_address_max |
1087 | >= bl->address) | |
1088 | && (bl->address + bp_location_shadow_len_after_address_max | |
1089 | <= memaddr)) | |
876fa593 JK |
1090 | bc_l = bc; |
1091 | else | |
1092 | bc_r = bc; | |
1093 | } | |
1094 | ||
128070bb PA |
1095 | /* Due to the binary search above, we need to make sure we pick the |
1096 | first location that's at BC_L's address. E.g., if there are | |
1097 | multiple locations at the same address, BC_L may end up pointing | |
1098 | at a duplicate location, and miss the "master"/"inserted" | |
1099 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1100 | B: | |
1101 | ||
1102 | L1@A, L2@A, L3@B, ... | |
1103 | ||
1104 | BC_L could end up pointing at location L2, while the "master" | |
1105 | location could be L1. Since the `loc->inserted' flag is only set | |
1106 | on "master" locations, we'd forget to restore the shadow of L1 | |
1107 | and L2. */ | |
1108 | while (bc_l > 0 | |
1109 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1110 | bc_l--; | |
1111 | ||
876fa593 JK |
1112 | /* Now do full processing of the found relevant range of elements. */ |
1113 | ||
1114 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1115 | { |
35df4500 | 1116 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1117 | CORE_ADDR bp_addr = 0; |
1118 | int bp_size = 0; | |
1119 | int bptoffset = 0; | |
1120 | ||
35df4500 TJB |
1121 | /* bp_location array has BL->OWNER always non-NULL. */ |
1122 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1123 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1124 | bl->owner->number); |
ffce0d52 | 1125 | |
e5dd4106 | 1126 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1127 | content. */ |
1128 | ||
35df4500 TJB |
1129 | if (bl->address >= bp_location_placed_address_before_address_max |
1130 | && memaddr + len <= (bl->address | |
1131 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1132 | break; |
1133 | ||
35df4500 | 1134 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1135 | continue; |
35df4500 | 1136 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1137 | current_program_space->aspace, 0)) |
1138 | continue; | |
1139 | ||
c5aa993b JM |
1140 | /* Addresses and length of the part of the breakpoint that |
1141 | we need to copy. */ | |
35df4500 TJB |
1142 | bp_addr = bl->target_info.placed_address; |
1143 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1144 | |
c5aa993b JM |
1145 | if (bp_addr + bp_size <= memaddr) |
1146 | /* The breakpoint is entirely before the chunk of memory we | |
1147 | are reading. */ | |
1148 | continue; | |
8defab1a | 1149 | |
c5aa993b JM |
1150 | if (bp_addr >= memaddr + len) |
1151 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1152 | reading. */ |
c5aa993b | 1153 | continue; |
c5aa993b | 1154 | |
8defab1a DJ |
1155 | /* Offset within shadow_contents. */ |
1156 | if (bp_addr < memaddr) | |
1157 | { | |
1158 | /* Only copy the second part of the breakpoint. */ | |
1159 | bp_size -= memaddr - bp_addr; | |
1160 | bptoffset = memaddr - bp_addr; | |
1161 | bp_addr = memaddr; | |
1162 | } | |
c5aa993b | 1163 | |
8defab1a DJ |
1164 | if (bp_addr + bp_size > memaddr + len) |
1165 | { | |
1166 | /* Only copy the first part of the breakpoint. */ | |
1167 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1168 | } | |
c5aa993b | 1169 | |
8defab1a | 1170 | memcpy (buf + bp_addr - memaddr, |
35df4500 | 1171 | bl->target_info.shadow_contents + bptoffset, bp_size); |
c5aa993b | 1172 | } |
c906108c | 1173 | } |
c906108c | 1174 | \f |
c5aa993b | 1175 | |
60e1c644 PA |
1176 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1177 | ||
a5606eee | 1178 | static int |
d77f58be | 1179 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1180 | { |
1181 | return (bpt->type == bp_hardware_watchpoint | |
1182 | || bpt->type == bp_read_watchpoint | |
1183 | || bpt->type == bp_access_watchpoint); | |
1184 | } | |
7270d8f2 | 1185 | |
60e1c644 PA |
1186 | /* Return true if BPT is of any watchpoint kind, hardware or |
1187 | software. */ | |
1188 | ||
3a5c3e22 | 1189 | int |
d77f58be | 1190 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1191 | { |
1192 | return (is_hardware_watchpoint (bpt) | |
1193 | || bpt->type == bp_watchpoint); | |
1194 | } | |
1195 | ||
3a5c3e22 PA |
1196 | /* Returns true if the current thread and its running state are safe |
1197 | to evaluate or update watchpoint B. Watchpoints on local | |
1198 | expressions need to be evaluated in the context of the thread that | |
1199 | was current when the watchpoint was created, and, that thread needs | |
1200 | to be stopped to be able to select the correct frame context. | |
1201 | Watchpoints on global expressions can be evaluated on any thread, | |
1202 | and in any state. It is presently left to the target allowing | |
1203 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1204 | |
1205 | static int | |
3a5c3e22 | 1206 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 PA |
1207 | { |
1208 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1209 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1210 | && !is_executing (inferior_ptid))); | |
1211 | } | |
1212 | ||
d0fb5eae JK |
1213 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1214 | associated bp_watchpoint_scope breakpoint. */ | |
1215 | ||
1216 | static void | |
3a5c3e22 | 1217 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1218 | { |
3a5c3e22 | 1219 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1220 | |
1221 | if (b->related_breakpoint != b) | |
1222 | { | |
1223 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1224 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1225 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1226 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1227 | b->related_breakpoint = b; | |
1228 | } | |
1229 | b->disposition = disp_del_at_next_stop; | |
1230 | } | |
1231 | ||
567e1b4e JB |
1232 | /* Assuming that B is a watchpoint: |
1233 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1234 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1235 | - Evaluate the condition if there is one, and store the result |
1236 | in b->loc->cond. | |
a5606eee VP |
1237 | - Update the list of values that must be watched in B->loc. |
1238 | ||
4a64f543 MS |
1239 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1240 | nothing. If this is local watchpoint that is out of scope, delete | |
1241 | it. | |
1242 | ||
1243 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1244 | removed + inserted on each stop here. Normal breakpoints must | |
1245 | never be removed because they might be missed by a running thread | |
1246 | when debugging in non-stop mode. On the other hand, hardware | |
1247 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1248 | to each LWP since they are stored in each LWP's hardware debug | |
1249 | registers. Therefore, such LWP must be stopped first in order to | |
1250 | be able to modify its hardware watchpoints. | |
1251 | ||
1252 | Hardware watchpoints must be reset exactly once after being | |
1253 | presented to the user. It cannot be done sooner, because it would | |
1254 | reset the data used to present the watchpoint hit to the user. And | |
1255 | it must not be done later because it could display the same single | |
1256 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1257 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1258 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1259 | not user-visible - its hit is suppressed if the memory content has | |
1260 | not changed. | |
1261 | ||
1262 | The following constraints influence the location where we can reset | |
1263 | hardware watchpoints: | |
1264 | ||
1265 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1266 | called several times when GDB stops. | |
1267 | ||
1268 | [linux] | |
1269 | * Multiple hardware watchpoints can be hit at the same time, | |
1270 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1271 | hit at a time as the reason for stopping, and all the other hits | |
1272 | are presented later, one after the other, each time the user | |
1273 | requests the execution to be resumed. Execution is not resumed | |
1274 | for the threads still having pending hit event stored in | |
1275 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1276 | the inferior on the first stop the thread hit event is kept being | |
1277 | reported from its cached value by linux_nat_stopped_data_address | |
1278 | until the real thread resume happens after the watchpoint gets | |
1279 | presented and thus its LWP_INFO->STATUS gets reset. | |
1280 | ||
1281 | Therefore the hardware watchpoint hit can get safely reset on the | |
1282 | watchpoint removal from inferior. */ | |
a79d3c27 | 1283 | |
b40ce68a | 1284 | static void |
3a5c3e22 | 1285 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1286 | { |
a5606eee | 1287 | int within_current_scope; |
a5606eee | 1288 | struct frame_id saved_frame_id; |
66076460 | 1289 | int frame_saved; |
a5606eee | 1290 | |
f6bc2008 PA |
1291 | /* If this is a local watchpoint, we only want to check if the |
1292 | watchpoint frame is in scope if the current thread is the thread | |
1293 | that was used to create the watchpoint. */ | |
1294 | if (!watchpoint_in_thread_scope (b)) | |
1295 | return; | |
1296 | ||
3a5c3e22 | 1297 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1298 | return; |
1299 | ||
66076460 | 1300 | frame_saved = 0; |
a5606eee VP |
1301 | |
1302 | /* Determine if the watchpoint is within scope. */ | |
1303 | if (b->exp_valid_block == NULL) | |
1304 | within_current_scope = 1; | |
1305 | else | |
1306 | { | |
b5db5dfc UW |
1307 | struct frame_info *fi = get_current_frame (); |
1308 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1309 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1310 | ||
1311 | /* If we're in a function epilogue, unwinding may not work | |
1312 | properly, so do not attempt to recreate locations at this | |
1313 | point. See similar comments in watchpoint_check. */ | |
1314 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1315 | return; | |
66076460 DJ |
1316 | |
1317 | /* Save the current frame's ID so we can restore it after | |
1318 | evaluating the watchpoint expression on its own frame. */ | |
1319 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1320 | took a frame parameter, so that we didn't have to change the | |
1321 | selected frame. */ | |
1322 | frame_saved = 1; | |
1323 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1324 | ||
a5606eee VP |
1325 | fi = frame_find_by_id (b->watchpoint_frame); |
1326 | within_current_scope = (fi != NULL); | |
1327 | if (within_current_scope) | |
1328 | select_frame (fi); | |
1329 | } | |
1330 | ||
b5db5dfc UW |
1331 | /* We don't free locations. They are stored in the bp_location array |
1332 | and update_global_location_list will eventually delete them and | |
1333 | remove breakpoints if needed. */ | |
3a5c3e22 | 1334 | b->base.loc = NULL; |
b5db5dfc | 1335 | |
a5606eee VP |
1336 | if (within_current_scope && reparse) |
1337 | { | |
1338 | char *s; | |
d63d0675 | 1339 | |
a5606eee VP |
1340 | if (b->exp) |
1341 | { | |
1342 | xfree (b->exp); | |
1343 | b->exp = NULL; | |
1344 | } | |
d63d0675 | 1345 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1346 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1347 | /* If the meaning of expression itself changed, the old value is | |
1348 | no longer relevant. We don't want to report a watchpoint hit | |
1349 | to the user when the old value and the new value may actually | |
1350 | be completely different objects. */ | |
1351 | value_free (b->val); | |
fa4727a6 DJ |
1352 | b->val = NULL; |
1353 | b->val_valid = 0; | |
60e1c644 PA |
1354 | |
1355 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1356 | expression is stored in the breakpoint object, not in the | |
1357 | locations (re)created below. */ | |
3a5c3e22 | 1358 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1359 | { |
1360 | if (b->cond_exp != NULL) | |
1361 | { | |
1362 | xfree (b->cond_exp); | |
1363 | b->cond_exp = NULL; | |
1364 | } | |
1365 | ||
3a5c3e22 | 1366 | s = b->base.cond_string; |
60e1c644 PA |
1367 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); |
1368 | } | |
a5606eee | 1369 | } |
a5606eee VP |
1370 | |
1371 | /* If we failed to parse the expression, for example because | |
1372 | it refers to a global variable in a not-yet-loaded shared library, | |
1373 | don't try to insert watchpoint. We don't automatically delete | |
1374 | such watchpoint, though, since failure to parse expression | |
1375 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1376 | if ( !target_has_execution) |
1377 | { | |
1378 | /* Without execution, memory can't change. No use to try and | |
1379 | set watchpoint locations. The watchpoint will be reset when | |
1380 | the target gains execution, through breakpoint_re_set. */ | |
1381 | } | |
1382 | else if (within_current_scope && b->exp) | |
a5606eee | 1383 | { |
0cf6dd15 | 1384 | int pc = 0; |
fa4727a6 | 1385 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1386 | struct program_space *frame_pspace; |
a5606eee | 1387 | |
0cf6dd15 | 1388 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1389 | |
a5606eee VP |
1390 | /* Avoid setting b->val if it's already set. The meaning of |
1391 | b->val is 'the last value' user saw, and we should update | |
1392 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1393 | happens, the code that reports it updates b->val directly. |
1394 | We don't keep track of the memory value for masked | |
1395 | watchpoints. */ | |
3a5c3e22 | 1396 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1397 | { |
1398 | b->val = v; | |
1399 | b->val_valid = 1; | |
1400 | } | |
a5606eee | 1401 | |
2d134ed3 PA |
1402 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1403 | ||
a5606eee | 1404 | /* Look at each value on the value chain. */ |
9fa40276 | 1405 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1406 | { |
1407 | /* If it's a memory location, and GDB actually needed | |
1408 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1409 | must watch it. If the first value returned is |
1410 | still lazy, that means an error occurred reading it; | |
1411 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1412 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1413 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1414 | { |
1415 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1416 | |
a5606eee VP |
1417 | /* We only watch structs and arrays if user asked |
1418 | for it explicitly, never if they just happen to | |
1419 | appear in the middle of some value chain. */ | |
fa4727a6 | 1420 | if (v == result |
a5606eee VP |
1421 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1422 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1423 | { | |
1424 | CORE_ADDR addr; | |
1425 | int len, type; | |
1426 | struct bp_location *loc, **tmp; | |
1427 | ||
42ae5230 | 1428 | addr = value_address (v); |
a5606eee VP |
1429 | len = TYPE_LENGTH (value_type (v)); |
1430 | type = hw_write; | |
3a5c3e22 | 1431 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1432 | type = hw_read; |
3a5c3e22 | 1433 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1434 | type = hw_access; |
3a5c3e22 PA |
1435 | |
1436 | loc = allocate_bp_location (&b->base); | |
1437 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1438 | ; |
1439 | *tmp = loc; | |
a6d9a66e | 1440 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1441 | |
1442 | loc->pspace = frame_pspace; | |
a5606eee VP |
1443 | loc->address = addr; |
1444 | loc->length = len; | |
1445 | loc->watchpoint_type = type; | |
1446 | } | |
1447 | } | |
9fa40276 TJB |
1448 | } |
1449 | ||
1450 | /* Change the type of breakpoint between hardware assisted or | |
1451 | an ordinary watchpoint depending on the hardware support | |
1452 | and free hardware slots. REPARSE is set when the inferior | |
1453 | is started. */ | |
a9634178 | 1454 | if (reparse) |
9fa40276 | 1455 | { |
e09342b5 | 1456 | int reg_cnt; |
9fa40276 TJB |
1457 | enum bp_loc_type loc_type; |
1458 | struct bp_location *bl; | |
a5606eee | 1459 | |
a9634178 | 1460 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1461 | |
1462 | if (reg_cnt) | |
9fa40276 TJB |
1463 | { |
1464 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1465 | enum bptype type; |
9fa40276 | 1466 | |
a9634178 TJB |
1467 | /* Use an exact watchpoint when there's only one memory region to be |
1468 | watched, and only one debug register is needed to watch it. */ | |
1469 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1470 | ||
9fa40276 | 1471 | /* We need to determine how many resources are already |
e09342b5 TJB |
1472 | used for all other hardware watchpoints plus this one |
1473 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1474 | this watchpoint in as well. */ |
1475 | ||
1476 | /* If this is a software watchpoint, we try to turn it | |
1477 | to a hardware one -- count resources as if B was of | |
1478 | hardware watchpoint type. */ | |
1479 | type = b->base.type; | |
1480 | if (type == bp_watchpoint) | |
1481 | type = bp_hardware_watchpoint; | |
1482 | ||
1483 | /* This watchpoint may or may not have been placed on | |
1484 | the list yet at this point (it won't be in the list | |
1485 | if we're trying to create it for the first time, | |
1486 | through watch_command), so always account for it | |
1487 | manually. */ | |
1488 | ||
1489 | /* Count resources used by all watchpoints except B. */ | |
1490 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
1491 | ||
1492 | /* Add in the resources needed for B. */ | |
1493 | i += hw_watchpoint_use_count (&b->base); | |
1494 | ||
1495 | target_resources_ok | |
1496 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1497 | if (target_resources_ok <= 0) |
a9634178 | 1498 | { |
3a5c3e22 | 1499 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1500 | |
1501 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1502 | error (_("Target does not support this type of " |
1503 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1504 | else if (target_resources_ok < 0 && !sw_mode) |
1505 | error (_("There are not enough available hardware " | |
1506 | "resources for this watchpoint.")); | |
a1398e0c PA |
1507 | |
1508 | /* Downgrade to software watchpoint. */ | |
1509 | b->base.type = bp_watchpoint; | |
1510 | } | |
1511 | else | |
1512 | { | |
1513 | /* If this was a software watchpoint, we've just | |
1514 | found we have enough resources to turn it to a | |
1515 | hardware watchpoint. Otherwise, this is a | |
1516 | nop. */ | |
1517 | b->base.type = type; | |
a9634178 | 1518 | } |
9fa40276 | 1519 | } |
3a5c3e22 | 1520 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
a9634178 TJB |
1521 | error (_("Expression cannot be implemented with " |
1522 | "read/access watchpoint.")); | |
9fa40276 | 1523 | else |
3a5c3e22 | 1524 | b->base.type = bp_watchpoint; |
9fa40276 | 1525 | |
3a5c3e22 | 1526 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1527 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1528 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1529 | bl->loc_type = loc_type; |
1530 | } | |
1531 | ||
1532 | for (v = val_chain; v; v = next) | |
1533 | { | |
a5606eee VP |
1534 | next = value_next (v); |
1535 | if (v != b->val) | |
1536 | value_free (v); | |
1537 | } | |
1538 | ||
c7437ca6 PA |
1539 | /* If a software watchpoint is not watching any memory, then the |
1540 | above left it without any location set up. But, | |
1541 | bpstat_stop_status requires a location to be able to report | |
1542 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1543 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1544 | { |
3a5c3e22 PA |
1545 | struct breakpoint *base = &b->base; |
1546 | base->loc = allocate_bp_location (base); | |
1547 | base->loc->pspace = frame_pspace; | |
1548 | base->loc->address = -1; | |
1549 | base->loc->length = -1; | |
1550 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1551 | } |
a5606eee VP |
1552 | } |
1553 | else if (!within_current_scope) | |
7270d8f2 | 1554 | { |
ac74f770 MS |
1555 | printf_filtered (_("\ |
1556 | Watchpoint %d deleted because the program has left the block\n\ | |
1557 | in which its expression is valid.\n"), | |
3a5c3e22 | 1558 | b->base.number); |
d0fb5eae | 1559 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1560 | } |
a5606eee VP |
1561 | |
1562 | /* Restore the selected frame. */ | |
66076460 DJ |
1563 | if (frame_saved) |
1564 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1565 | } |
1566 | ||
a5606eee | 1567 | |
74960c60 VP |
1568 | /* Returns 1 iff breakpoint location should be |
1569 | inserted in the inferior. */ | |
1570 | static int | |
35df4500 | 1571 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1572 | { |
35df4500 | 1573 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1574 | return 0; |
1575 | ||
35df4500 | 1576 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1577 | return 0; |
1578 | ||
35df4500 | 1579 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1580 | return 0; |
1581 | ||
56710373 PA |
1582 | /* This is set for example, when we're attached to the parent of a |
1583 | vfork, and have detached from the child. The child is running | |
1584 | free, and we expect it to do an exec or exit, at which point the | |
1585 | OS makes the parent schedulable again (and the target reports | |
1586 | that the vfork is done). Until the child is done with the shared | |
1587 | memory region, do not insert breakpoints in the parent, otherwise | |
1588 | the child could still trip on the parent's breakpoints. Since | |
1589 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1590 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1591 | return 0; |
1592 | ||
1042e4c0 SS |
1593 | /* Tracepoints are inserted by the target at a time of its choosing, |
1594 | not by us. */ | |
35df4500 | 1595 | if (is_tracepoint (bl->owner)) |
1042e4c0 SS |
1596 | return 0; |
1597 | ||
74960c60 VP |
1598 | return 1; |
1599 | } | |
1600 | ||
934709f0 PW |
1601 | /* Same as should_be_inserted but does the check assuming |
1602 | that the location is not duplicated. */ | |
1603 | ||
1604 | static int | |
1605 | unduplicated_should_be_inserted (struct bp_location *bl) | |
1606 | { | |
1607 | int result; | |
1608 | const int save_duplicate = bl->duplicate; | |
1609 | ||
1610 | bl->duplicate = 0; | |
1611 | result = should_be_inserted (bl); | |
1612 | bl->duplicate = save_duplicate; | |
1613 | return result; | |
1614 | } | |
1615 | ||
35df4500 TJB |
1616 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
1617 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 1618 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
1619 | Returns 0 for success, 1 if the bp_location type is not supported or |
1620 | -1 for failure. | |
879bfdc2 | 1621 | |
4a64f543 MS |
1622 | NOTE drow/2003-09-09: This routine could be broken down to an |
1623 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1624 | static int |
35df4500 | 1625 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 1626 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 1627 | int *disabled_breaks, |
26bb91f3 | 1628 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1629 | { |
1630 | int val = 0; | |
1631 | ||
35df4500 | 1632 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1633 | return 0; |
1634 | ||
8181d85f | 1635 | /* Initialize the target-specific information. */ |
35df4500 TJB |
1636 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
1637 | bl->target_info.placed_address = bl->address; | |
1638 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 1639 | bl->target_info.length = bl->length; |
8181d85f | 1640 | |
35df4500 TJB |
1641 | if (bl->loc_type == bp_loc_software_breakpoint |
1642 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 1643 | { |
35df4500 | 1644 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
1645 | { |
1646 | /* If the explicitly specified breakpoint type | |
1647 | is not hardware breakpoint, check the memory map to see | |
1648 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 1649 | |
765dc015 VP |
1650 | Two important cases are: |
1651 | - location type is not hardware breakpoint, memory | |
1652 | is readonly. We change the type of the location to | |
1653 | hardware breakpoint. | |
4a64f543 MS |
1654 | - location type is hardware breakpoint, memory is |
1655 | read-write. This means we've previously made the | |
1656 | location hardware one, but then the memory map changed, | |
1657 | so we undo. | |
765dc015 | 1658 | |
4a64f543 MS |
1659 | When breakpoints are removed, remove_breakpoints will use |
1660 | location types we've just set here, the only possible | |
1661 | problem is that memory map has changed during running | |
1662 | program, but it's not going to work anyway with current | |
1663 | gdb. */ | |
765dc015 | 1664 | struct mem_region *mr |
35df4500 | 1665 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
1666 | |
1667 | if (mr) | |
1668 | { | |
1669 | if (automatic_hardware_breakpoints) | |
1670 | { | |
765dc015 VP |
1671 | enum bp_loc_type new_type; |
1672 | ||
1673 | if (mr->attrib.mode != MEM_RW) | |
1674 | new_type = bp_loc_hardware_breakpoint; | |
1675 | else | |
1676 | new_type = bp_loc_software_breakpoint; | |
1677 | ||
35df4500 | 1678 | if (new_type != bl->loc_type) |
765dc015 VP |
1679 | { |
1680 | static int said = 0; | |
cc59ec59 | 1681 | |
35df4500 | 1682 | bl->loc_type = new_type; |
765dc015 VP |
1683 | if (!said) |
1684 | { | |
3e43a32a MS |
1685 | fprintf_filtered (gdb_stdout, |
1686 | _("Note: automatically using " | |
1687 | "hardware breakpoints for " | |
1688 | "read-only addresses.\n")); | |
765dc015 VP |
1689 | said = 1; |
1690 | } | |
1691 | } | |
1692 | } | |
35df4500 | 1693 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 1694 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
1695 | warning (_("cannot set software breakpoint " |
1696 | "at readonly address %s"), | |
35df4500 | 1697 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
1698 | } |
1699 | } | |
1700 | ||
879bfdc2 DJ |
1701 | /* First check to see if we have to handle an overlay. */ |
1702 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
1703 | || bl->section == NULL |
1704 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
1705 | { |
1706 | /* No overlay handling: just set the breakpoint. */ | |
1707 | ||
348d480f | 1708 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
1709 | } |
1710 | else | |
1711 | { | |
4a64f543 | 1712 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
1713 | Shall we set a breakpoint at the LMA? */ |
1714 | if (!overlay_events_enabled) | |
1715 | { | |
1716 | /* Yes -- overlay event support is not active, | |
1717 | so we must try to set a breakpoint at the LMA. | |
1718 | This will not work for a hardware breakpoint. */ | |
35df4500 | 1719 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 1720 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 1721 | bl->owner->number); |
879bfdc2 DJ |
1722 | else |
1723 | { | |
35df4500 TJB |
1724 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
1725 | bl->section); | |
879bfdc2 | 1726 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
1727 | bl->overlay_target_info = bl->target_info; |
1728 | bl->overlay_target_info.placed_address = addr; | |
1729 | val = target_insert_breakpoint (bl->gdbarch, | |
1730 | &bl->overlay_target_info); | |
879bfdc2 | 1731 | if (val != 0) |
99361f52 | 1732 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1733 | "Overlay breakpoint %d " |
1734 | "failed: in ROM?\n", | |
35df4500 | 1735 | bl->owner->number); |
879bfdc2 DJ |
1736 | } |
1737 | } | |
1738 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 1739 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
1740 | { |
1741 | /* Yes. This overlay section is mapped into memory. */ | |
348d480f | 1742 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
1743 | } |
1744 | else | |
1745 | { | |
1746 | /* No. This breakpoint will not be inserted. | |
1747 | No error, but do not mark the bp as 'inserted'. */ | |
1748 | return 0; | |
1749 | } | |
1750 | } | |
1751 | ||
1752 | if (val) | |
1753 | { | |
1754 | /* Can't set the breakpoint. */ | |
35df4500 | 1755 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 1756 | { |
4a64f543 | 1757 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 1758 | val = 0; |
35df4500 | 1759 | bl->shlib_disabled = 1; |
8d3788bd | 1760 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
1761 | if (!*disabled_breaks) |
1762 | { | |
1763 | fprintf_unfiltered (tmp_error_stream, | |
1764 | "Cannot insert breakpoint %d.\n", | |
1765 | bl->owner->number); | |
1766 | fprintf_unfiltered (tmp_error_stream, | |
1767 | "Temporarily disabling shared " | |
1768 | "library breakpoints:\n"); | |
1769 | } | |
1770 | *disabled_breaks = 1; | |
879bfdc2 | 1771 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 1772 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
1773 | } |
1774 | else | |
879bfdc2 | 1775 | { |
35df4500 | 1776 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
1777 | { |
1778 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
1779 | fprintf_unfiltered (tmp_error_stream, |
1780 | "Cannot insert hardware " | |
1781 | "breakpoint %d.\n", | |
35df4500 | 1782 | bl->owner->number); |
879bfdc2 DJ |
1783 | } |
1784 | else | |
1785 | { | |
1786 | fprintf_unfiltered (tmp_error_stream, | |
1787 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1788 | bl->owner->number); |
879bfdc2 DJ |
1789 | fprintf_filtered (tmp_error_stream, |
1790 | "Error accessing memory address "); | |
35df4500 | 1791 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 1792 | tmp_error_stream); |
879bfdc2 DJ |
1793 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1794 | safe_strerror (val)); | |
1795 | } | |
1796 | ||
1797 | } | |
1798 | } | |
1799 | else | |
35df4500 | 1800 | bl->inserted = 1; |
879bfdc2 DJ |
1801 | |
1802 | return val; | |
1803 | } | |
1804 | ||
35df4500 | 1805 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 1806 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 1807 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 1808 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 1809 | { |
77b06cd7 TJB |
1810 | gdb_assert (bl->owner->ops != NULL |
1811 | && bl->owner->ops->insert_location != NULL); | |
1812 | ||
1813 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
1814 | |
1815 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1816 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 1817 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
1818 | { |
1819 | struct bp_location *loc, **loc_temp; | |
1820 | ||
1821 | /* But don't try to insert it, if there's already another | |
1822 | hw_access location that would be considered a duplicate | |
1823 | of this one. */ | |
1824 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 1825 | if (loc != bl |
85d721b8 | 1826 | && loc->watchpoint_type == hw_access |
35df4500 | 1827 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 1828 | { |
35df4500 TJB |
1829 | bl->duplicate = 1; |
1830 | bl->inserted = 1; | |
1831 | bl->target_info = loc->target_info; | |
1832 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
1833 | val = 0; |
1834 | break; | |
1835 | } | |
1836 | ||
1837 | if (val == 1) | |
1838 | { | |
77b06cd7 TJB |
1839 | bl->watchpoint_type = hw_access; |
1840 | val = bl->owner->ops->insert_location (bl); | |
1841 | ||
1842 | if (val) | |
1843 | /* Back to the original value. */ | |
1844 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
1845 | } |
1846 | } | |
1847 | ||
35df4500 | 1848 | bl->inserted = (val == 0); |
879bfdc2 DJ |
1849 | } |
1850 | ||
35df4500 | 1851 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 1852 | { |
77b06cd7 TJB |
1853 | gdb_assert (bl->owner->ops != NULL |
1854 | && bl->owner->ops->insert_location != NULL); | |
1855 | ||
1856 | val = bl->owner->ops->insert_location (bl); | |
1857 | if (val) | |
1858 | { | |
1859 | bl->owner->enable_state = bp_disabled; | |
1860 | ||
1861 | if (val == 1) | |
1862 | warning (_("\ | |
1863 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
1864 | of catchpoint."), bl->owner->number); | |
1865 | else | |
1866 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
1867 | } | |
1868 | ||
1869 | bl->inserted = (val == 0); | |
1640b821 DJ |
1870 | |
1871 | /* We've already printed an error message if there was a problem | |
1872 | inserting this catchpoint, and we've disabled the catchpoint, | |
1873 | so just return success. */ | |
1874 | return 0; | |
879bfdc2 DJ |
1875 | } |
1876 | ||
1877 | return 0; | |
1878 | } | |
1879 | ||
6c95b8df PA |
1880 | /* This function is called when program space PSPACE is about to be |
1881 | deleted. It takes care of updating breakpoints to not reference | |
1882 | PSPACE anymore. */ | |
1883 | ||
1884 | void | |
1885 | breakpoint_program_space_exit (struct program_space *pspace) | |
1886 | { | |
1887 | struct breakpoint *b, *b_temp; | |
876fa593 | 1888 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1889 | |
1890 | /* Remove any breakpoint that was set through this program space. */ | |
1891 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1892 | { | |
1893 | if (b->pspace == pspace) | |
1894 | delete_breakpoint (b); | |
1895 | } | |
1896 | ||
1897 | /* Breakpoints set through other program spaces could have locations | |
1898 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1899 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1900 | { |
1901 | struct bp_location *tmp; | |
1902 | ||
1903 | if (loc->pspace == pspace) | |
1904 | { | |
2bdf28a0 | 1905 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1906 | if (loc->owner->loc == loc) |
1907 | loc->owner->loc = loc->next; | |
1908 | else | |
1909 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1910 | if (tmp->next == loc) | |
1911 | { | |
1912 | tmp->next = loc->next; | |
1913 | break; | |
1914 | } | |
1915 | } | |
1916 | } | |
1917 | ||
1918 | /* Now update the global location list to permanently delete the | |
1919 | removed locations above. */ | |
1920 | update_global_location_list (0); | |
1921 | } | |
1922 | ||
74960c60 VP |
1923 | /* Make sure all breakpoints are inserted in inferior. |
1924 | Throws exception on any error. | |
1925 | A breakpoint that is already inserted won't be inserted | |
1926 | again, so calling this function twice is safe. */ | |
1927 | void | |
1928 | insert_breakpoints (void) | |
1929 | { | |
1930 | struct breakpoint *bpt; | |
1931 | ||
1932 | ALL_BREAKPOINTS (bpt) | |
1933 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
1934 | { |
1935 | struct watchpoint *w = (struct watchpoint *) bpt; | |
1936 | ||
1937 | update_watchpoint (w, 0 /* don't reparse. */); | |
1938 | } | |
74960c60 | 1939 | |
b60e7edf | 1940 | update_global_location_list (1); |
74960c60 | 1941 | |
c35b1492 PA |
1942 | /* update_global_location_list does not insert breakpoints when |
1943 | always_inserted_mode is not enabled. Explicitly insert them | |
1944 | now. */ | |
1945 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1946 | insert_breakpoint_locations (); |
1947 | } | |
1948 | ||
c30eee59 | 1949 | /* Used when starting or continuing the program. */ |
c906108c | 1950 | |
74960c60 VP |
1951 | static void |
1952 | insert_breakpoint_locations (void) | |
c906108c | 1953 | { |
a5606eee | 1954 | struct breakpoint *bpt; |
35df4500 | 1955 | struct bp_location *bl, **blp_tmp; |
e236ba44 | 1956 | int error = 0; |
c906108c | 1957 | int val = 0; |
3fbb6ffa | 1958 | int disabled_breaks = 0; |
81d0cc19 | 1959 | int hw_breakpoint_error = 0; |
c906108c | 1960 | |
81d0cc19 | 1961 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1962 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1963 | |
81d0cc19 GS |
1964 | /* Explicitly mark the warning -- this will only be printed if |
1965 | there was an error. */ | |
1966 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1967 | |
1968 | save_current_space_and_thread (); | |
1969 | ||
35df4500 | 1970 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 1971 | { |
35df4500 | 1972 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1973 | continue; |
1974 | ||
4a64f543 MS |
1975 | /* There is no point inserting thread-specific breakpoints if |
1976 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
1977 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
1978 | if (bl->owner->thread != -1 |
1979 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
1980 | continue; |
1981 | ||
35df4500 | 1982 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
1983 | |
1984 | /* For targets that support global breakpoints, there's no need | |
1985 | to select an inferior to insert breakpoint to. In fact, even | |
1986 | if we aren't attached to any process yet, we should still | |
1987 | insert breakpoints. */ | |
1988 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1989 | && ptid_equal (inferior_ptid, null_ptid)) | |
1990 | continue; | |
1991 | ||
3fbb6ffa TJB |
1992 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
1993 | &hw_breakpoint_error); | |
879bfdc2 | 1994 | if (val) |
e236ba44 | 1995 | error = val; |
879bfdc2 | 1996 | } |
c906108c | 1997 | |
4a64f543 MS |
1998 | /* If we failed to insert all locations of a watchpoint, remove |
1999 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2000 | ALL_BREAKPOINTS (bpt) |
2001 | { | |
2002 | int some_failed = 0; | |
2003 | struct bp_location *loc; | |
2004 | ||
2005 | if (!is_hardware_watchpoint (bpt)) | |
2006 | continue; | |
2007 | ||
d6b74ac4 | 2008 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2009 | continue; |
74960c60 VP |
2010 | |
2011 | if (bpt->disposition == disp_del_at_next_stop) | |
2012 | continue; | |
a5606eee VP |
2013 | |
2014 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2015 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2016 | { |
2017 | some_failed = 1; | |
2018 | break; | |
2019 | } | |
2020 | if (some_failed) | |
2021 | { | |
2022 | for (loc = bpt->loc; loc; loc = loc->next) | |
2023 | if (loc->inserted) | |
2024 | remove_breakpoint (loc, mark_uninserted); | |
2025 | ||
2026 | hw_breakpoint_error = 1; | |
2027 | fprintf_unfiltered (tmp_error_stream, | |
2028 | "Could not insert hardware watchpoint %d.\n", | |
2029 | bpt->number); | |
2030 | error = -1; | |
2031 | } | |
2032 | } | |
2033 | ||
e236ba44 | 2034 | if (error) |
81d0cc19 GS |
2035 | { |
2036 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2037 | message about possibly exhausted resources. */ | |
879bfdc2 | 2038 | if (hw_breakpoint_error) |
81d0cc19 | 2039 | { |
c6510018 MS |
2040 | fprintf_unfiltered (tmp_error_stream, |
2041 | "Could not insert hardware breakpoints:\n\ | |
2042 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2043 | } |
81d0cc19 GS |
2044 | target_terminal_ours_for_output (); |
2045 | error_stream (tmp_error_stream); | |
2046 | } | |
f7545552 TT |
2047 | |
2048 | do_cleanups (cleanups); | |
c906108c SS |
2049 | } |
2050 | ||
c30eee59 TJB |
2051 | /* Used when the program stops. |
2052 | Returns zero if successful, or non-zero if there was a problem | |
2053 | removing a breakpoint location. */ | |
2054 | ||
c906108c | 2055 | int |
fba45db2 | 2056 | remove_breakpoints (void) |
c906108c | 2057 | { |
35df4500 | 2058 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2059 | int val = 0; |
c906108c | 2060 | |
35df4500 | 2061 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2062 | { |
35df4500 TJB |
2063 | if (bl->inserted) |
2064 | val |= remove_breakpoint (bl, mark_uninserted); | |
c5aa993b | 2065 | } |
3a1bae8e | 2066 | return val; |
c906108c SS |
2067 | } |
2068 | ||
6c95b8df PA |
2069 | /* Remove breakpoints of process PID. */ |
2070 | ||
2071 | int | |
2072 | remove_breakpoints_pid (int pid) | |
2073 | { | |
35df4500 | 2074 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2075 | int val; |
2076 | struct inferior *inf = find_inferior_pid (pid); | |
2077 | ||
35df4500 | 2078 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2079 | { |
35df4500 | 2080 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2081 | continue; |
2082 | ||
35df4500 | 2083 | if (bl->inserted) |
6c95b8df | 2084 | { |
35df4500 | 2085 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2086 | if (val != 0) |
2087 | return val; | |
2088 | } | |
2089 | } | |
2090 | return 0; | |
2091 | } | |
2092 | ||
c906108c | 2093 | int |
fba45db2 | 2094 | reattach_breakpoints (int pid) |
c906108c | 2095 | { |
6c95b8df | 2096 | struct cleanup *old_chain; |
35df4500 | 2097 | struct bp_location *bl, **blp_tmp; |
c906108c | 2098 | int val; |
86b887df | 2099 | struct ui_file *tmp_error_stream; |
3fbb6ffa | 2100 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2101 | struct inferior *inf; |
2102 | struct thread_info *tp; | |
2103 | ||
2104 | tp = any_live_thread_of_process (pid); | |
2105 | if (tp == NULL) | |
2106 | return 1; | |
2107 | ||
2108 | inf = find_inferior_pid (pid); | |
2109 | old_chain = save_inferior_ptid (); | |
2110 | ||
2111 | inferior_ptid = tp->ptid; | |
a4954f26 | 2112 | |
86b887df | 2113 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2114 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2115 | |
35df4500 | 2116 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2117 | { |
35df4500 | 2118 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2119 | continue; |
2120 | ||
35df4500 | 2121 | if (bl->inserted) |
c5aa993b | 2122 | { |
35df4500 | 2123 | bl->inserted = 0; |
3fbb6ffa | 2124 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); |
c5aa993b JM |
2125 | if (val != 0) |
2126 | { | |
ce696e05 | 2127 | do_cleanups (old_chain); |
c5aa993b JM |
2128 | return val; |
2129 | } | |
2130 | } | |
2131 | } | |
ce696e05 | 2132 | do_cleanups (old_chain); |
c906108c SS |
2133 | return 0; |
2134 | } | |
2135 | ||
e58b0e63 PA |
2136 | static int internal_breakpoint_number = -1; |
2137 | ||
84f4c1fe PM |
2138 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2139 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2140 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 2141 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
2142 | breakpoint_count and that value incremented. Internal breakpoints |
2143 | do not set the internal var bpnum. */ | |
2144 | static void | |
2145 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2146 | { | |
2147 | if (internal) | |
2148 | b->number = internal_breakpoint_number--; | |
2149 | else | |
2150 | { | |
2151 | set_breakpoint_count (breakpoint_count + 1); | |
2152 | b->number = breakpoint_count; | |
2153 | } | |
2154 | } | |
2155 | ||
e62c965a | 2156 | static struct breakpoint * |
a6d9a66e | 2157 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 2158 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 2159 | const struct breakpoint_ops *ops) |
e62c965a | 2160 | { |
e62c965a PP |
2161 | struct symtab_and_line sal; |
2162 | struct breakpoint *b; | |
2163 | ||
4a64f543 | 2164 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2165 | |
2166 | sal.pc = address; | |
2167 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2168 | sal.pspace = current_program_space; |
e62c965a | 2169 | |
06edf0c0 | 2170 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
2171 | b->number = internal_breakpoint_number--; |
2172 | b->disposition = disp_donttouch; | |
2173 | ||
2174 | return b; | |
2175 | } | |
2176 | ||
17450429 PP |
2177 | static const char *const longjmp_names[] = |
2178 | { | |
2179 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2180 | }; | |
2181 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2182 | ||
2183 | /* Per-objfile data private to breakpoint.c. */ | |
2184 | struct breakpoint_objfile_data | |
2185 | { | |
2186 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2187 | struct minimal_symbol *overlay_msym; | |
2188 | ||
2189 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2190 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2191 | ||
2192 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2193 | struct minimal_symbol *terminate_msym; | |
2194 | ||
2195 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2196 | struct minimal_symbol *exception_msym; | |
2197 | }; | |
2198 | ||
2199 | static const struct objfile_data *breakpoint_objfile_key; | |
2200 | ||
2201 | /* Minimal symbol not found sentinel. */ | |
2202 | static struct minimal_symbol msym_not_found; | |
2203 | ||
2204 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2205 | ||
2206 | static int | |
2207 | msym_not_found_p (const struct minimal_symbol *msym) | |
2208 | { | |
2209 | return msym == &msym_not_found; | |
2210 | } | |
2211 | ||
2212 | /* Return per-objfile data needed by breakpoint.c. | |
2213 | Allocate the data if necessary. */ | |
2214 | ||
2215 | static struct breakpoint_objfile_data * | |
2216 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2217 | { | |
2218 | struct breakpoint_objfile_data *bp_objfile_data; | |
2219 | ||
2220 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2221 | if (bp_objfile_data == NULL) | |
2222 | { | |
2223 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2224 | sizeof (*bp_objfile_data)); | |
2225 | ||
2226 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2227 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2228 | } | |
2229 | return bp_objfile_data; | |
2230 | } | |
2231 | ||
e62c965a | 2232 | static void |
af02033e | 2233 | create_overlay_event_breakpoint (void) |
e62c965a | 2234 | { |
69de3c6a | 2235 | struct objfile *objfile; |
af02033e | 2236 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2237 | |
69de3c6a PP |
2238 | ALL_OBJFILES (objfile) |
2239 | { | |
2240 | struct breakpoint *b; | |
17450429 PP |
2241 | struct breakpoint_objfile_data *bp_objfile_data; |
2242 | CORE_ADDR addr; | |
69de3c6a | 2243 | |
17450429 PP |
2244 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2245 | ||
2246 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2247 | continue; | |
2248 | ||
2249 | if (bp_objfile_data->overlay_msym == NULL) | |
2250 | { | |
2251 | struct minimal_symbol *m; | |
2252 | ||
2253 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2254 | if (m == NULL) | |
2255 | { | |
2256 | /* Avoid future lookups in this objfile. */ | |
2257 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2258 | continue; | |
2259 | } | |
2260 | bp_objfile_data->overlay_msym = m; | |
2261 | } | |
e62c965a | 2262 | |
17450429 PP |
2263 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2264 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2265 | bp_overlay_event, |
2266 | &internal_breakpoint_ops); | |
69de3c6a | 2267 | b->addr_string = xstrdup (func_name); |
e62c965a | 2268 | |
69de3c6a PP |
2269 | if (overlay_debugging == ovly_auto) |
2270 | { | |
2271 | b->enable_state = bp_enabled; | |
2272 | overlay_events_enabled = 1; | |
2273 | } | |
2274 | else | |
2275 | { | |
2276 | b->enable_state = bp_disabled; | |
2277 | overlay_events_enabled = 0; | |
2278 | } | |
e62c965a PP |
2279 | } |
2280 | update_global_location_list (1); | |
2281 | } | |
2282 | ||
0fd8e87f | 2283 | static void |
af02033e | 2284 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2285 | { |
6c95b8df | 2286 | struct program_space *pspace; |
6c95b8df PA |
2287 | struct cleanup *old_chain; |
2288 | ||
2289 | old_chain = save_current_program_space (); | |
0fd8e87f | 2290 | |
6c95b8df | 2291 | ALL_PSPACES (pspace) |
af02033e PP |
2292 | { |
2293 | struct objfile *objfile; | |
2294 | ||
2295 | set_current_program_space (pspace); | |
2296 | ||
2297 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2298 | { |
af02033e PP |
2299 | int i; |
2300 | struct gdbarch *gdbarch; | |
17450429 | 2301 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2302 | |
af02033e PP |
2303 | gdbarch = get_objfile_arch (objfile); |
2304 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2305 | continue; |
2306 | ||
17450429 PP |
2307 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2308 | ||
2309 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2310 | { |
2311 | struct breakpoint *b; | |
af02033e | 2312 | const char *func_name; |
17450429 | 2313 | CORE_ADDR addr; |
6c95b8df | 2314 | |
17450429 | 2315 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2316 | continue; |
0fd8e87f | 2317 | |
17450429 PP |
2318 | func_name = longjmp_names[i]; |
2319 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2320 | { | |
2321 | struct minimal_symbol *m; | |
2322 | ||
2323 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2324 | if (m == NULL) | |
2325 | { | |
2326 | /* Prevent future lookups in this objfile. */ | |
2327 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2328 | continue; | |
2329 | } | |
2330 | bp_objfile_data->longjmp_msym[i] = m; | |
2331 | } | |
2332 | ||
2333 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
06edf0c0 PA |
2334 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
2335 | &internal_breakpoint_ops); | |
af02033e PP |
2336 | b->addr_string = xstrdup (func_name); |
2337 | b->enable_state = bp_disabled; | |
2338 | } | |
0fd8e87f | 2339 | } |
af02033e | 2340 | } |
0fd8e87f | 2341 | update_global_location_list (1); |
6c95b8df PA |
2342 | |
2343 | do_cleanups (old_chain); | |
0fd8e87f UW |
2344 | } |
2345 | ||
af02033e | 2346 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2347 | static void |
af02033e | 2348 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2349 | { |
2350 | struct program_space *pspace; | |
aa7d318d | 2351 | struct cleanup *old_chain; |
af02033e | 2352 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2353 | |
2354 | old_chain = save_current_program_space (); | |
2355 | ||
2356 | ALL_PSPACES (pspace) | |
17450429 PP |
2357 | { |
2358 | struct objfile *objfile; | |
2359 | CORE_ADDR addr; | |
2360 | ||
2361 | set_current_program_space (pspace); | |
2362 | ||
aa7d318d TT |
2363 | ALL_OBJFILES (objfile) |
2364 | { | |
2365 | struct breakpoint *b; | |
17450429 | 2366 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2367 | |
17450429 | 2368 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2369 | |
17450429 PP |
2370 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2371 | continue; | |
2372 | ||
2373 | if (bp_objfile_data->terminate_msym == NULL) | |
2374 | { | |
2375 | struct minimal_symbol *m; | |
2376 | ||
2377 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2378 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2379 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2380 | { | |
2381 | /* Prevent future lookups in this objfile. */ | |
2382 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2383 | continue; | |
2384 | } | |
2385 | bp_objfile_data->terminate_msym = m; | |
2386 | } | |
aa7d318d | 2387 | |
17450429 PP |
2388 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2389 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2390 | bp_std_terminate_master, |
2391 | &internal_breakpoint_ops); | |
aa7d318d TT |
2392 | b->addr_string = xstrdup (func_name); |
2393 | b->enable_state = bp_disabled; | |
2394 | } | |
17450429 PP |
2395 | } |
2396 | ||
aa7d318d TT |
2397 | update_global_location_list (1); |
2398 | ||
2399 | do_cleanups (old_chain); | |
2400 | } | |
2401 | ||
186c406b TT |
2402 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2403 | ||
2404 | void | |
2405 | create_exception_master_breakpoint (void) | |
2406 | { | |
2407 | struct objfile *objfile; | |
17450429 | 2408 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2409 | |
2410 | ALL_OBJFILES (objfile) | |
2411 | { | |
17450429 PP |
2412 | struct breakpoint *b; |
2413 | struct gdbarch *gdbarch; | |
2414 | struct breakpoint_objfile_data *bp_objfile_data; | |
2415 | CORE_ADDR addr; | |
2416 | ||
2417 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2418 | ||
2419 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2420 | continue; | |
2421 | ||
2422 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2423 | |
17450429 | 2424 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2425 | { |
17450429 | 2426 | struct minimal_symbol *debug_hook; |
186c406b | 2427 | |
17450429 PP |
2428 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2429 | if (debug_hook == NULL) | |
2430 | { | |
2431 | bp_objfile_data->exception_msym = &msym_not_found; | |
2432 | continue; | |
2433 | } | |
2434 | ||
2435 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2436 | } |
17450429 PP |
2437 | |
2438 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2439 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2440 | ¤t_target); | |
06edf0c0 PA |
2441 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
2442 | &internal_breakpoint_ops); | |
17450429 PP |
2443 | b->addr_string = xstrdup (func_name); |
2444 | b->enable_state = bp_disabled; | |
186c406b TT |
2445 | } |
2446 | ||
2447 | update_global_location_list (1); | |
2448 | } | |
2449 | ||
c906108c | 2450 | void |
fba45db2 | 2451 | update_breakpoints_after_exec (void) |
c906108c | 2452 | { |
35df4500 | 2453 | struct breakpoint *b, *b_tmp; |
876fa593 | 2454 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2455 | |
25b22b0a PA |
2456 | /* We're about to delete breakpoints from GDB's lists. If the |
2457 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2458 | writing the breakpoints' "shadow contents" back into memory. The | |
2459 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2460 | do that. Instead, the target is responsible from marking | |
2461 | breakpoints out as soon as it detects an exec. We don't do that | |
2462 | here instead, because there may be other attempts to delete | |
2463 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2464 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2465 | if (bploc->pspace == current_program_space) |
2466 | gdb_assert (!bploc->inserted); | |
c906108c | 2467 | |
35df4500 | 2468 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2469 | { |
6c95b8df PA |
2470 | if (b->pspace != current_program_space) |
2471 | continue; | |
2472 | ||
4a64f543 | 2473 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2474 | if (b->type == bp_shlib_event) |
2475 | { | |
2476 | delete_breakpoint (b); | |
2477 | continue; | |
2478 | } | |
c906108c | 2479 | |
4a64f543 | 2480 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2481 | if (b->type == bp_jit_event) |
2482 | { | |
2483 | delete_breakpoint (b); | |
2484 | continue; | |
2485 | } | |
2486 | ||
1900040c | 2487 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2488 | as must overlay event and longjmp master breakpoints. */ |
2489 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2490 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2491 | || b->type == bp_exception_master) | |
c4093a6a JM |
2492 | { |
2493 | delete_breakpoint (b); | |
2494 | continue; | |
2495 | } | |
2496 | ||
4a64f543 | 2497 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 2498 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
2499 | { |
2500 | delete_breakpoint (b); | |
2501 | continue; | |
2502 | } | |
2503 | ||
611c83ae PA |
2504 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2505 | after an exec. */ | |
186c406b TT |
2506 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2507 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2508 | { |
2509 | delete_breakpoint (b); | |
2510 | continue; | |
2511 | } | |
2512 | ||
ce78b96d JB |
2513 | if (b->type == bp_catchpoint) |
2514 | { | |
2515 | /* For now, none of the bp_catchpoint breakpoints need to | |
2516 | do anything at this point. In the future, if some of | |
2517 | the catchpoints need to something, we will need to add | |
2518 | a new method, and call this method from here. */ | |
2519 | continue; | |
2520 | } | |
2521 | ||
c5aa993b JM |
2522 | /* bp_finish is a special case. The only way we ought to be able |
2523 | to see one of these when an exec() has happened, is if the user | |
2524 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2525 | carries them to the call-site of the current callee, by setting | |
2526 | a temporary bp there and resuming. But in this case, the finish | |
2527 | will carry them entirely through the vfork & exec. | |
2528 | ||
2529 | We don't want to allow a bp_finish to remain inserted now. But | |
2530 | we can't safely delete it, 'cause finish_command has a handle to | |
2531 | the bp on a bpstat, and will later want to delete it. There's a | |
2532 | chance (and I've seen it happen) that if we delete the bp_finish | |
2533 | here, that its storage will get reused by the time finish_command | |
2534 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2535 | We really must allow finish_command to delete a bp_finish. | |
2536 | ||
e5dd4106 | 2537 | In the absence of a general solution for the "how do we know |
53a5351d JM |
2538 | it's safe to delete something others may have handles to?" |
2539 | problem, what we'll do here is just uninsert the bp_finish, and | |
2540 | let finish_command delete it. | |
2541 | ||
2542 | (We know the bp_finish is "doomed" in the sense that it's | |
2543 | momentary, and will be deleted as soon as finish_command sees | |
2544 | the inferior stopped. So it doesn't matter that the bp's | |
2545 | address is probably bogus in the new a.out, unlike e.g., the | |
2546 | solib breakpoints.) */ | |
c5aa993b | 2547 | |
c5aa993b JM |
2548 | if (b->type == bp_finish) |
2549 | { | |
2550 | continue; | |
2551 | } | |
2552 | ||
2553 | /* Without a symbolic address, we have little hope of the | |
2554 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2555 | a.out. */ |
c5aa993b JM |
2556 | if (b->addr_string == NULL) |
2557 | { | |
2558 | delete_breakpoint (b); | |
2559 | continue; | |
2560 | } | |
c5aa993b | 2561 | } |
1900040c | 2562 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
2563 | create_overlay_event_breakpoint (); |
2564 | create_longjmp_master_breakpoint (); | |
2565 | create_std_terminate_master_breakpoint (); | |
186c406b | 2566 | create_exception_master_breakpoint (); |
c906108c SS |
2567 | } |
2568 | ||
2569 | int | |
fba45db2 | 2570 | detach_breakpoints (int pid) |
c906108c | 2571 | { |
35df4500 | 2572 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2573 | int val = 0; |
ce696e05 | 2574 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2575 | struct inferior *inf = current_inferior (); |
c5aa993b | 2576 | |
39f77062 | 2577 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2578 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2579 | |
6c95b8df | 2580 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2581 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2582 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2583 | { |
35df4500 | 2584 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2585 | continue; |
2586 | ||
35df4500 TJB |
2587 | if (bl->inserted) |
2588 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2589 | } |
d03285ec UW |
2590 | |
2591 | /* Detach single-step breakpoints as well. */ | |
2592 | detach_single_step_breakpoints (); | |
2593 | ||
ce696e05 | 2594 | do_cleanups (old_chain); |
3a1bae8e | 2595 | return val; |
c906108c SS |
2596 | } |
2597 | ||
35df4500 | 2598 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2599 | Note that this is used to detach breakpoints from a child fork. |
2600 | When we get here, the child isn't in the inferior list, and neither | |
2601 | do we have objects to represent its address space --- we should | |
35df4500 | 2602 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2603 | |
c906108c | 2604 | static int |
35df4500 | 2605 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2606 | { |
2607 | int val; | |
c5aa993b | 2608 | |
35df4500 TJB |
2609 | /* BL is never in moribund_locations by our callers. */ |
2610 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2611 | |
35df4500 | 2612 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2613 | /* Permanent breakpoints cannot be inserted or removed. */ |
2614 | return 0; | |
2615 | ||
74960c60 VP |
2616 | /* The type of none suggests that owner is actually deleted. |
2617 | This should not ever happen. */ | |
35df4500 | 2618 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2619 | |
35df4500 TJB |
2620 | if (bl->loc_type == bp_loc_software_breakpoint |
2621 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2622 | { |
c02f5703 MS |
2623 | /* "Normal" instruction breakpoint: either the standard |
2624 | trap-instruction bp (bp_breakpoint), or a | |
2625 | bp_hardware_breakpoint. */ | |
2626 | ||
2627 | /* First check to see if we have to handle an overlay. */ | |
2628 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2629 | || bl->section == NULL |
2630 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2631 | { |
2632 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 2633 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 2634 | } |
c906108c SS |
2635 | else |
2636 | { | |
4a64f543 | 2637 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2638 | Did we set a breakpoint at the LMA? */ |
2639 | if (!overlay_events_enabled) | |
2640 | { | |
2641 | /* Yes -- overlay event support is not active, so we | |
2642 | should have set a breakpoint at the LMA. Remove it. | |
2643 | */ | |
c02f5703 MS |
2644 | /* Ignore any failures: if the LMA is in ROM, we will |
2645 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2646 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2647 | target_remove_hw_breakpoint (bl->gdbarch, | |
2648 | &bl->overlay_target_info); | |
c02f5703 | 2649 | else |
35df4500 TJB |
2650 | target_remove_breakpoint (bl->gdbarch, |
2651 | &bl->overlay_target_info); | |
c02f5703 MS |
2652 | } |
2653 | /* Did we set a breakpoint at the VMA? | |
2654 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2655 | if (bl->inserted) |
c906108c | 2656 | { |
c02f5703 MS |
2657 | /* Yes -- remove it. Previously we did not bother to |
2658 | remove the breakpoint if the section had been | |
2659 | unmapped, but let's not rely on that being safe. We | |
2660 | don't know what the overlay manager might do. */ | |
aa67235e UW |
2661 | |
2662 | /* However, we should remove *software* breakpoints only | |
2663 | if the section is still mapped, or else we overwrite | |
2664 | wrong code with the saved shadow contents. */ | |
348d480f PA |
2665 | if (bl->loc_type == bp_loc_hardware_breakpoint |
2666 | || section_is_mapped (bl->section)) | |
2667 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
2668 | else |
2669 | val = 0; | |
c906108c | 2670 | } |
c02f5703 MS |
2671 | else |
2672 | { | |
2673 | /* No -- not inserted, so no need to remove. No error. */ | |
2674 | val = 0; | |
2675 | } | |
c906108c | 2676 | } |
879d1e6b UW |
2677 | |
2678 | /* In some cases, we might not be able to remove a breakpoint | |
2679 | in a shared library that has already been removed, but we | |
2680 | have not yet processed the shlib unload event. */ | |
35df4500 | 2681 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2682 | val = 0; |
2683 | ||
c906108c SS |
2684 | if (val) |
2685 | return val; | |
35df4500 | 2686 | bl->inserted = (is == mark_inserted); |
c906108c | 2687 | } |
35df4500 | 2688 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2689 | { |
77b06cd7 TJB |
2690 | gdb_assert (bl->owner->ops != NULL |
2691 | && bl->owner->ops->remove_location != NULL); | |
2692 | ||
35df4500 | 2693 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2694 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2695 | |
c906108c | 2696 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2697 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2698 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2699 | bl->owner->number); |
c906108c | 2700 | } |
35df4500 TJB |
2701 | else if (bl->owner->type == bp_catchpoint |
2702 | && breakpoint_enabled (bl->owner) | |
2703 | && !bl->duplicate) | |
ce78b96d | 2704 | { |
77b06cd7 TJB |
2705 | gdb_assert (bl->owner->ops != NULL |
2706 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2707 | |
77b06cd7 | 2708 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2709 | if (val) |
2710 | return val; | |
77b06cd7 | 2711 | |
35df4500 | 2712 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2713 | } |
c906108c SS |
2714 | |
2715 | return 0; | |
2716 | } | |
2717 | ||
6c95b8df | 2718 | static int |
35df4500 | 2719 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2720 | { |
2721 | int ret; | |
2722 | struct cleanup *old_chain; | |
2723 | ||
35df4500 TJB |
2724 | /* BL is never in moribund_locations by our callers. */ |
2725 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2726 | |
35df4500 | 2727 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2728 | /* Permanent breakpoints cannot be inserted or removed. */ |
2729 | return 0; | |
2730 | ||
2731 | /* The type of none suggests that owner is actually deleted. | |
2732 | This should not ever happen. */ | |
35df4500 | 2733 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2734 | |
2735 | old_chain = save_current_space_and_thread (); | |
2736 | ||
35df4500 | 2737 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2738 | |
35df4500 | 2739 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2740 | |
2741 | do_cleanups (old_chain); | |
2742 | return ret; | |
2743 | } | |
2744 | ||
c906108c SS |
2745 | /* Clear the "inserted" flag in all breakpoints. */ |
2746 | ||
25b22b0a | 2747 | void |
fba45db2 | 2748 | mark_breakpoints_out (void) |
c906108c | 2749 | { |
35df4500 | 2750 | struct bp_location *bl, **blp_tmp; |
c906108c | 2751 | |
35df4500 TJB |
2752 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2753 | if (bl->pspace == current_program_space) | |
2754 | bl->inserted = 0; | |
c906108c SS |
2755 | } |
2756 | ||
53a5351d JM |
2757 | /* Clear the "inserted" flag in all breakpoints and delete any |
2758 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2759 | |
2760 | Plus other such housekeeping that has to be done for breakpoints | |
2761 | between runs. | |
2762 | ||
53a5351d JM |
2763 | Note: this function gets called at the end of a run (by |
2764 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2765 | init_wait_for_inferior). */ |
c906108c SS |
2766 | |
2767 | ||
2768 | ||
2769 | void | |
fba45db2 | 2770 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2771 | { |
35df4500 TJB |
2772 | struct breakpoint *b, *b_tmp; |
2773 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2774 | int ix; |
6c95b8df | 2775 | struct program_space *pspace = current_program_space; |
c906108c | 2776 | |
50c71eaf PA |
2777 | /* If breakpoint locations are shared across processes, then there's |
2778 | nothing to do. */ | |
2567c7d9 | 2779 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2780 | return; |
2781 | ||
35df4500 | 2782 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2783 | { |
35df4500 TJB |
2784 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2785 | if (bl->pspace == pspace | |
2786 | && bl->owner->enable_state != bp_permanent) | |
2787 | bl->inserted = 0; | |
6c95b8df | 2788 | } |
075f6582 | 2789 | |
35df4500 | 2790 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2791 | { |
6c95b8df PA |
2792 | if (b->loc && b->loc->pspace != pspace) |
2793 | continue; | |
2794 | ||
c5aa993b JM |
2795 | switch (b->type) |
2796 | { | |
2797 | case bp_call_dummy: | |
c906108c | 2798 | |
c5aa993b | 2799 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2800 | cause problems when the inferior is rerun, so we better get |
2801 | rid of it. */ | |
2802 | ||
2803 | case bp_watchpoint_scope: | |
2804 | ||
2805 | /* Also get rid of scope breakpoints. */ | |
2806 | ||
2807 | case bp_shlib_event: | |
2808 | ||
2809 | /* Also remove solib event breakpoints. Their addresses may | |
2810 | have changed since the last time we ran the program. | |
2811 | Actually we may now be debugging against different target; | |
2812 | and so the solib backend that installed this breakpoint may | |
2813 | not be used in by the target. E.g., | |
2814 | ||
2815 | (gdb) file prog-linux | |
2816 | (gdb) run # native linux target | |
2817 | ... | |
2818 | (gdb) kill | |
2819 | (gdb) file prog-win.exe | |
2820 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2821 | */ | |
c906108c | 2822 | |
c5aa993b JM |
2823 | delete_breakpoint (b); |
2824 | break; | |
c906108c | 2825 | |
c5aa993b JM |
2826 | case bp_watchpoint: |
2827 | case bp_hardware_watchpoint: | |
2828 | case bp_read_watchpoint: | |
2829 | case bp_access_watchpoint: | |
3a5c3e22 PA |
2830 | { |
2831 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 2832 | |
3a5c3e22 PA |
2833 | /* Likewise for watchpoints on local expressions. */ |
2834 | if (w->exp_valid_block != NULL) | |
2835 | delete_breakpoint (b); | |
2836 | else if (context == inf_starting) | |
2837 | { | |
2838 | /* Reset val field to force reread of starting value in | |
2839 | insert_breakpoints. */ | |
2840 | if (w->val) | |
2841 | value_free (w->val); | |
2842 | w->val = NULL; | |
2843 | w->val_valid = 0; | |
c860120c | 2844 | } |
3a5c3e22 | 2845 | } |
c5aa993b JM |
2846 | break; |
2847 | default: | |
c5aa993b JM |
2848 | break; |
2849 | } | |
2850 | } | |
1c5cfe86 PA |
2851 | |
2852 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2853 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2854 | decref_bp_location (&bl); | |
1c5cfe86 | 2855 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2856 | } |
2857 | ||
6c95b8df PA |
2858 | /* These functions concern about actual breakpoints inserted in the |
2859 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2860 | we need to hop over the bkpt --- so we check for address space | |
2861 | match, not program space. */ | |
2862 | ||
c2c6d25f JM |
2863 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2864 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2865 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2866 | permanent breakpoint. | |
2867 | - When continuing from a location with an ordinary breakpoint, we | |
2868 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 2869 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
2870 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
2871 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2872 | |
c2c6d25f | 2873 | enum breakpoint_here |
6c95b8df | 2874 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2875 | { |
35df4500 | 2876 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2877 | int any_breakpoint_here = 0; |
c906108c | 2878 | |
35df4500 | 2879 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2880 | { |
35df4500 TJB |
2881 | if (bl->loc_type != bp_loc_software_breakpoint |
2882 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2883 | continue; |
2884 | ||
f1310107 | 2885 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
2886 | if ((breakpoint_enabled (bl->owner) |
2887 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 2888 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2889 | { |
2890 | if (overlay_debugging | |
35df4500 TJB |
2891 | && section_is_overlay (bl->section) |
2892 | && !section_is_mapped (bl->section)) | |
075f6582 | 2893 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2894 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2895 | return permanent_breakpoint_here; |
2896 | else | |
2897 | any_breakpoint_here = 1; | |
2898 | } | |
2899 | } | |
c906108c | 2900 | |
c2c6d25f | 2901 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2902 | } |
2903 | ||
1c5cfe86 PA |
2904 | /* Return true if there's a moribund breakpoint at PC. */ |
2905 | ||
2906 | int | |
6c95b8df | 2907 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2908 | { |
2909 | struct bp_location *loc; | |
2910 | int ix; | |
2911 | ||
2912 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 2913 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
2914 | return 1; |
2915 | ||
2916 | return 0; | |
2917 | } | |
c2c6d25f | 2918 | |
c36b740a | 2919 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2920 | inserted using regular breakpoint_chain / bp_location array |
2921 | mechanism. This does not check for single-step breakpoints, which | |
2922 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2923 | |
2924 | int | |
4a64f543 MS |
2925 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2926 | CORE_ADDR pc) | |
c906108c | 2927 | { |
35df4500 | 2928 | struct bp_location *bl, **blp_tmp; |
c906108c | 2929 | |
35df4500 | 2930 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2931 | { |
35df4500 TJB |
2932 | if (bl->loc_type != bp_loc_software_breakpoint |
2933 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2934 | continue; |
2935 | ||
35df4500 | 2936 | if (bl->inserted |
f1310107 | 2937 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2938 | { |
2939 | if (overlay_debugging | |
35df4500 TJB |
2940 | && section_is_overlay (bl->section) |
2941 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2942 | continue; /* unmapped overlay -- can't be a match */ |
2943 | else | |
2944 | return 1; | |
2945 | } | |
c5aa993b | 2946 | } |
c36b740a VP |
2947 | return 0; |
2948 | } | |
2949 | ||
2950 | /* Returns non-zero iff there's either regular breakpoint | |
2951 | or a single step breakpoint inserted at PC. */ | |
2952 | ||
2953 | int | |
6c95b8df | 2954 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2955 | { |
6c95b8df | 2956 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2957 | return 1; |
c906108c | 2958 | |
6c95b8df | 2959 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2960 | return 1; |
2961 | ||
c906108c SS |
2962 | return 0; |
2963 | } | |
2964 | ||
4fa8626c DJ |
2965 | /* This function returns non-zero iff there is a software breakpoint |
2966 | inserted at PC. */ | |
2967 | ||
2968 | int | |
3e43a32a MS |
2969 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
2970 | CORE_ADDR pc) | |
4fa8626c | 2971 | { |
35df4500 | 2972 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 2973 | |
35df4500 | 2974 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 2975 | { |
35df4500 | 2976 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
2977 | continue; |
2978 | ||
35df4500 TJB |
2979 | if (bl->inserted |
2980 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2981 | aspace, pc)) |
4fa8626c DJ |
2982 | { |
2983 | if (overlay_debugging | |
35df4500 TJB |
2984 | && section_is_overlay (bl->section) |
2985 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
2986 | continue; /* unmapped overlay -- can't be a match */ |
2987 | else | |
2988 | return 1; | |
2989 | } | |
2990 | } | |
2991 | ||
1aafd4da | 2992 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2993 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2994 | return 1; |
2995 | ||
4fa8626c DJ |
2996 | return 0; |
2997 | } | |
2998 | ||
9093389c PA |
2999 | int |
3000 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
3001 | CORE_ADDR addr, ULONGEST len) | |
3002 | { | |
3003 | struct breakpoint *bpt; | |
3004 | ||
3005 | ALL_BREAKPOINTS (bpt) | |
3006 | { | |
3007 | struct bp_location *loc; | |
3008 | ||
3009 | if (bpt->type != bp_hardware_watchpoint | |
3010 | && bpt->type != bp_access_watchpoint) | |
3011 | continue; | |
3012 | ||
3013 | if (!breakpoint_enabled (bpt)) | |
3014 | continue; | |
3015 | ||
3016 | for (loc = bpt->loc; loc; loc = loc->next) | |
3017 | if (loc->pspace->aspace == aspace && loc->inserted) | |
3018 | { | |
3019 | CORE_ADDR l, h; | |
3020 | ||
3021 | /* Check for intersection. */ | |
3022 | l = max (loc->address, addr); | |
3023 | h = min (loc->address + loc->length, addr + len); | |
3024 | if (l < h) | |
3025 | return 1; | |
3026 | } | |
3027 | } | |
3028 | return 0; | |
3029 | } | |
3030 | ||
075f6582 DJ |
3031 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
3032 | PC is valid for process/thread PTID. */ | |
c906108c SS |
3033 | |
3034 | int | |
6c95b8df PA |
3035 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
3036 | ptid_t ptid) | |
c906108c | 3037 | { |
35df4500 | 3038 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 3039 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 3040 | int thread = -1; |
4a306c9a | 3041 | int task = 0; |
a6f1cd96 | 3042 | |
35df4500 | 3043 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3044 | { |
35df4500 TJB |
3045 | if (bl->loc_type != bp_loc_software_breakpoint |
3046 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3047 | continue; |
3048 | ||
35df4500 TJB |
3049 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
3050 | if (!breakpoint_enabled (bl->owner) | |
3051 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
3052 | continue; |
3053 | ||
f1310107 | 3054 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
3055 | continue; |
3056 | ||
35df4500 | 3057 | if (bl->owner->thread != -1) |
075f6582 | 3058 | { |
a6f1cd96 JB |
3059 | /* This is a thread-specific breakpoint. Check that ptid |
3060 | matches that thread. If thread hasn't been computed yet, | |
3061 | it is now time to do so. */ | |
3062 | if (thread == -1) | |
3063 | thread = pid_to_thread_id (ptid); | |
35df4500 | 3064 | if (bl->owner->thread != thread) |
a6f1cd96 | 3065 | continue; |
075f6582 | 3066 | } |
a6f1cd96 | 3067 | |
35df4500 | 3068 | if (bl->owner->task != 0) |
4a306c9a JB |
3069 | { |
3070 | /* This is a task-specific breakpoint. Check that ptid | |
3071 | matches that task. If task hasn't been computed yet, | |
3072 | it is now time to do so. */ | |
3073 | if (task == 0) | |
3074 | task = ada_get_task_number (ptid); | |
35df4500 | 3075 | if (bl->owner->task != task) |
4a306c9a JB |
3076 | continue; |
3077 | } | |
3078 | ||
a6f1cd96 | 3079 | if (overlay_debugging |
35df4500 TJB |
3080 | && section_is_overlay (bl->section) |
3081 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
3082 | continue; /* unmapped overlay -- can't be a match */ |
3083 | ||
3084 | return 1; | |
c5aa993b | 3085 | } |
c906108c SS |
3086 | |
3087 | return 0; | |
3088 | } | |
c906108c | 3089 | \f |
c5aa993b | 3090 | |
c906108c SS |
3091 | /* bpstat stuff. External routines' interfaces are documented |
3092 | in breakpoint.h. */ | |
3093 | ||
3094 | int | |
fba45db2 | 3095 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3096 | { |
533be4dd | 3097 | return (ep->type == bp_catchpoint); |
c906108c SS |
3098 | } |
3099 | ||
f431efe5 PA |
3100 | /* Frees any storage that is part of a bpstat. Does not walk the |
3101 | 'next' chain. */ | |
3102 | ||
3103 | static void | |
198757a8 VP |
3104 | bpstat_free (bpstat bs) |
3105 | { | |
3106 | if (bs->old_val != NULL) | |
3107 | value_free (bs->old_val); | |
9add0f1b | 3108 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3109 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3110 | xfree (bs); |
3111 | } | |
3112 | ||
c906108c SS |
3113 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3114 | Also free any storage that is part of a bpstat. */ | |
3115 | ||
3116 | void | |
fba45db2 | 3117 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3118 | { |
3119 | bpstat p; | |
3120 | bpstat q; | |
3121 | ||
3122 | if (bsp == 0) | |
3123 | return; | |
3124 | p = *bsp; | |
3125 | while (p != NULL) | |
3126 | { | |
3127 | q = p->next; | |
198757a8 | 3128 | bpstat_free (p); |
c906108c SS |
3129 | p = q; |
3130 | } | |
3131 | *bsp = NULL; | |
3132 | } | |
3133 | ||
3134 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3135 | is part of the bpstat is copied as well. */ | |
3136 | ||
3137 | bpstat | |
fba45db2 | 3138 | bpstat_copy (bpstat bs) |
c906108c SS |
3139 | { |
3140 | bpstat p = NULL; | |
3141 | bpstat tmp; | |
3142 | bpstat retval = NULL; | |
3143 | ||
3144 | if (bs == NULL) | |
3145 | return bs; | |
3146 | ||
3147 | for (; bs != NULL; bs = bs->next) | |
3148 | { | |
3149 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3150 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3151 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3152 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3153 | if (bs->old_val != NULL) |
3c3185ac JK |
3154 | { |
3155 | tmp->old_val = value_copy (bs->old_val); | |
3156 | release_value (tmp->old_val); | |
3157 | } | |
31cc81e9 | 3158 | |
c906108c SS |
3159 | if (p == NULL) |
3160 | /* This is the first thing in the chain. */ | |
3161 | retval = tmp; | |
3162 | else | |
3163 | p->next = tmp; | |
3164 | p = tmp; | |
3165 | } | |
3166 | p->next = NULL; | |
3167 | return retval; | |
3168 | } | |
3169 | ||
4a64f543 | 3170 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3171 | |
3172 | bpstat | |
fba45db2 | 3173 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3174 | { |
c5aa993b JM |
3175 | if (bsp == NULL) |
3176 | return NULL; | |
c906108c | 3177 | |
c5aa993b JM |
3178 | for (; bsp != NULL; bsp = bsp->next) |
3179 | { | |
f431efe5 | 3180 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3181 | return bsp; |
3182 | } | |
c906108c SS |
3183 | return NULL; |
3184 | } | |
3185 | ||
4a64f543 MS |
3186 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3187 | stopped at. *BSP upon return is a bpstat which points to the | |
3188 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3189 | good for anything but further calls to bpstat_num). | |
3190 | ||
8671a17b PA |
3191 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3192 | Return -1 if stopped at a breakpoint that has been deleted since | |
3193 | we set it. | |
3194 | Return 1 otherwise. */ | |
c906108c SS |
3195 | |
3196 | int | |
8671a17b | 3197 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3198 | { |
3199 | struct breakpoint *b; | |
3200 | ||
3201 | if ((*bsp) == NULL) | |
3202 | return 0; /* No more breakpoint values */ | |
8671a17b | 3203 | |
4a64f543 MS |
3204 | /* We assume we'll never have several bpstats that correspond to a |
3205 | single breakpoint -- otherwise, this function might return the | |
3206 | same number more than once and this will look ugly. */ | |
f431efe5 | 3207 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3208 | *bsp = (*bsp)->next; |
3209 | if (b == NULL) | |
3210 | return -1; /* breakpoint that's been deleted since */ | |
3211 | ||
3212 | *num = b->number; /* We have its number */ | |
3213 | return 1; | |
c906108c SS |
3214 | } |
3215 | ||
e93ca019 | 3216 | /* See breakpoint.h. */ |
c906108c SS |
3217 | |
3218 | void | |
e93ca019 | 3219 | bpstat_clear_actions (void) |
c906108c | 3220 | { |
e93ca019 JK |
3221 | struct thread_info *tp; |
3222 | bpstat bs; | |
3223 | ||
3224 | if (ptid_equal (inferior_ptid, null_ptid)) | |
3225 | return; | |
3226 | ||
3227 | tp = find_thread_ptid (inferior_ptid); | |
3228 | if (tp == NULL) | |
3229 | return; | |
3230 | ||
3231 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 3232 | { |
9add0f1b | 3233 | decref_counted_command_line (&bs->commands); |
abf85f46 | 3234 | |
c906108c SS |
3235 | if (bs->old_val != NULL) |
3236 | { | |
3237 | value_free (bs->old_val); | |
3238 | bs->old_val = NULL; | |
3239 | } | |
3240 | } | |
3241 | } | |
3242 | ||
f3b1572e PA |
3243 | /* Called when a command is about to proceed the inferior. */ |
3244 | ||
3245 | static void | |
3246 | breakpoint_about_to_proceed (void) | |
3247 | { | |
3248 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3249 | { | |
3250 | struct thread_info *tp = inferior_thread (); | |
3251 | ||
3252 | /* Allow inferior function calls in breakpoint commands to not | |
3253 | interrupt the command list. When the call finishes | |
3254 | successfully, the inferior will be standing at the same | |
3255 | breakpoint as if nothing happened. */ | |
16c381f0 | 3256 | if (tp->control.in_infcall) |
f3b1572e PA |
3257 | return; |
3258 | } | |
3259 | ||
3260 | breakpoint_proceeded = 1; | |
3261 | } | |
3262 | ||
4a64f543 MS |
3263 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3264 | command. */ | |
c906108c | 3265 | static void |
4efb68b1 | 3266 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3267 | { |
3268 | executing_breakpoint_commands = 0; | |
3269 | } | |
3270 | ||
abf85f46 JK |
3271 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
3272 | or its equivalent. */ | |
3273 | ||
3274 | static int | |
3275 | command_line_is_silent (struct command_line *cmd) | |
3276 | { | |
3277 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
3278 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
3279 | } | |
3280 | ||
4a64f543 MS |
3281 | /* Execute all the commands associated with all the breakpoints at |
3282 | this location. Any of these commands could cause the process to | |
3283 | proceed beyond this point, etc. We look out for such changes by | |
3284 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3285 | |
347bddb7 PA |
3286 | Returns true if a breakpoint command resumed the inferior. In that |
3287 | case, it is the caller's responsibility to recall it again with the | |
3288 | bpstat of the current thread. */ | |
3289 | ||
3290 | static int | |
3291 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3292 | { |
3293 | bpstat bs; | |
3294 | struct cleanup *old_chain; | |
347bddb7 | 3295 | int again = 0; |
c906108c SS |
3296 | |
3297 | /* Avoid endless recursion if a `source' command is contained | |
3298 | in bs->commands. */ | |
3299 | if (executing_breakpoint_commands) | |
347bddb7 | 3300 | return 0; |
c906108c SS |
3301 | |
3302 | executing_breakpoint_commands = 1; | |
3303 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3304 | ||
cf6c5ffb TT |
3305 | prevent_dont_repeat (); |
3306 | ||
4a64f543 | 3307 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3308 | bs = *bsp; |
3309 | ||
3310 | breakpoint_proceeded = 0; | |
3311 | for (; bs != NULL; bs = bs->next) | |
3312 | { | |
9add0f1b | 3313 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3314 | struct command_line *cmd; |
3315 | struct cleanup *this_cmd_tree_chain; | |
3316 | ||
3317 | /* Take ownership of the BSP's command tree, if it has one. | |
3318 | ||
3319 | The command tree could legitimately contain commands like | |
3320 | 'step' and 'next', which call clear_proceed_status, which | |
3321 | frees stop_bpstat's command tree. To make sure this doesn't | |
3322 | free the tree we're executing out from under us, we need to | |
3323 | take ownership of the tree ourselves. Since a given bpstat's | |
3324 | commands are only executed once, we don't need to copy it; we | |
3325 | can clear the pointer in the bpstat, and make sure we free | |
3326 | the tree when we're done. */ | |
9add0f1b TT |
3327 | ccmd = bs->commands; |
3328 | bs->commands = NULL; | |
abf85f46 JK |
3329 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
3330 | cmd = ccmd ? ccmd->commands : NULL; | |
3331 | if (command_line_is_silent (cmd)) | |
3332 | { | |
3333 | /* The action has been already done by bpstat_stop_status. */ | |
3334 | cmd = cmd->next; | |
3335 | } | |
6c50ab1c | 3336 | |
c906108c SS |
3337 | while (cmd != NULL) |
3338 | { | |
3339 | execute_control_command (cmd); | |
3340 | ||
3341 | if (breakpoint_proceeded) | |
3342 | break; | |
3343 | else | |
3344 | cmd = cmd->next; | |
3345 | } | |
6c50ab1c JB |
3346 | |
3347 | /* We can free this command tree now. */ | |
3348 | do_cleanups (this_cmd_tree_chain); | |
3349 | ||
c906108c | 3350 | if (breakpoint_proceeded) |
32c1e744 VP |
3351 | { |
3352 | if (target_can_async_p ()) | |
347bddb7 PA |
3353 | /* If we are in async mode, then the target might be still |
3354 | running, not stopped at any breakpoint, so nothing for | |
3355 | us to do here -- just return to the event loop. */ | |
3356 | ; | |
32c1e744 VP |
3357 | else |
3358 | /* In sync mode, when execute_control_command returns | |
3359 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3360 | Breakpoint commands for that stop were not run, since |
3361 | execute_command does not run breakpoint commands -- | |
3362 | only command_line_handler does, but that one is not | |
3363 | involved in execution of breakpoint commands. So, we | |
3364 | can now execute breakpoint commands. It should be | |
3365 | noted that making execute_command do bpstat actions is | |
3366 | not an option -- in this case we'll have recursive | |
3367 | invocation of bpstat for each breakpoint with a | |
3368 | command, and can easily blow up GDB stack. Instead, we | |
3369 | return true, which will trigger the caller to recall us | |
3370 | with the new stop_bpstat. */ | |
3371 | again = 1; | |
3372 | break; | |
32c1e744 | 3373 | } |
c906108c | 3374 | } |
c2b8ed2c | 3375 | do_cleanups (old_chain); |
347bddb7 PA |
3376 | return again; |
3377 | } | |
3378 | ||
3379 | void | |
3380 | bpstat_do_actions (void) | |
3381 | { | |
353d1d73 JK |
3382 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
3383 | ||
347bddb7 PA |
3384 | /* Do any commands attached to breakpoint we are stopped at. */ |
3385 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3386 | && target_has_execution | |
3387 | && !is_exited (inferior_ptid) | |
3388 | && !is_executing (inferior_ptid)) | |
3389 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3390 | and only return when it is stopped at the next breakpoint, we | |
3391 | keep doing breakpoint actions until it returns false to | |
3392 | indicate the inferior was not resumed. */ | |
16c381f0 | 3393 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3394 | break; |
353d1d73 JK |
3395 | |
3396 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
3397 | } |
3398 | ||
fa4727a6 DJ |
3399 | /* Print out the (old or new) value associated with a watchpoint. */ |
3400 | ||
3401 | static void | |
3402 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3403 | { | |
3404 | if (val == NULL) | |
3405 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3406 | else | |
79a45b7d TT |
3407 | { |
3408 | struct value_print_options opts; | |
3409 | get_user_print_options (&opts); | |
3410 | value_print (val, stream, &opts); | |
3411 | } | |
fa4727a6 DJ |
3412 | } |
3413 | ||
e514a9d6 | 3414 | /* Generic routine for printing messages indicating why we |
4a64f543 | 3415 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3416 | 'print_it' in the bpstat structure. Under some circumstances we |
3417 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3418 | normal_stop(). */ |
e514a9d6 JM |
3419 | |
3420 | static enum print_stop_action | |
3421 | print_bp_stop_message (bpstat bs) | |
3422 | { | |
3423 | switch (bs->print_it) | |
3424 | { | |
3425 | case print_it_noop: | |
4a64f543 | 3426 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3427 | return PRINT_UNKNOWN; |
3428 | break; | |
3429 | ||
3430 | case print_it_done: | |
3431 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3432 | relevant messages. */ |
e514a9d6 JM |
3433 | return PRINT_SRC_AND_LOC; |
3434 | break; | |
3435 | ||
3436 | case print_it_normal: | |
4f8d1dc6 | 3437 | { |
f431efe5 PA |
3438 | struct breakpoint *b = bs->breakpoint_at; |
3439 | ||
1a6a67de TJB |
3440 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3441 | which has since been deleted. */ | |
3442 | if (b == NULL) | |
3443 | return PRINT_UNKNOWN; | |
3444 | ||
348d480f PA |
3445 | /* Normal case. Call the breakpoint's print_it method. */ |
3446 | return b->ops->print_it (bs); | |
4f8d1dc6 | 3447 | } |
348d480f | 3448 | break; |
3086aeae | 3449 | |
e514a9d6 | 3450 | default: |
8e65ff28 | 3451 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3452 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3453 | break; |
c906108c | 3454 | } |
c906108c SS |
3455 | } |
3456 | ||
e514a9d6 JM |
3457 | /* Print a message indicating what happened. This is called from |
3458 | normal_stop(). The input to this routine is the head of the bpstat | |
3459 | list - a list of the eventpoints that caused this stop. This | |
3460 | routine calls the generic print routine for printing a message | |
3461 | about reasons for stopping. This will print (for example) the | |
3462 | "Breakpoint n," part of the output. The return value of this | |
3463 | routine is one of: | |
c906108c | 3464 | |
4a64f543 | 3465 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3466 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3467 | code to print the location. An example is |
c5aa993b JM |
3468 | "Breakpoint 1, " which should be followed by |
3469 | the location. | |
917317f4 | 3470 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3471 | to also print the location part of the message. |
3472 | An example is the catch/throw messages, which | |
4a64f543 | 3473 | don't require a location appended to the end. |
917317f4 | 3474 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3475 | further info to be printed. */ |
c906108c | 3476 | |
917317f4 | 3477 | enum print_stop_action |
fba45db2 | 3478 | bpstat_print (bpstat bs) |
c906108c SS |
3479 | { |
3480 | int val; | |
c5aa993b | 3481 | |
c906108c | 3482 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3483 | (Currently all watchpoints go on the bpstat whether hit or not. |
3484 | That probably could (should) be changed, provided care is taken | |
c906108c | 3485 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3486 | for (; bs; bs = bs->next) |
3487 | { | |
3488 | val = print_bp_stop_message (bs); | |
3489 | if (val == PRINT_SRC_ONLY | |
3490 | || val == PRINT_SRC_AND_LOC | |
3491 | || val == PRINT_NOTHING) | |
3492 | return val; | |
3493 | } | |
c906108c | 3494 | |
e514a9d6 | 3495 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3496 | with and nothing was printed. */ |
917317f4 | 3497 | return PRINT_UNKNOWN; |
c906108c SS |
3498 | } |
3499 | ||
4a64f543 MS |
3500 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3501 | used inside a catch_errors to evaluate the breakpoint condition. | |
3502 | The argument is a "struct expression *" that has been cast to a | |
3503 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3504 | |
3505 | static int | |
4efb68b1 | 3506 | breakpoint_cond_eval (void *exp) |
c906108c | 3507 | { |
278cd55f | 3508 | struct value *mark = value_mark (); |
c5aa993b | 3509 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3510 | |
c906108c SS |
3511 | value_free_to_mark (mark); |
3512 | return i; | |
3513 | } | |
3514 | ||
5760d0ab | 3515 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3516 | |
3517 | static bpstat | |
5760d0ab | 3518 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3519 | { |
3520 | bpstat bs; | |
3521 | ||
3522 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3523 | bs->next = NULL; |
3524 | **bs_link_pointer = bs; | |
3525 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3526 | bs->breakpoint_at = bl->owner; |
3527 | bs->bp_location_at = bl; | |
3528 | incref_bp_location (bl); | |
c906108c SS |
3529 | /* If the condition is false, etc., don't do the commands. */ |
3530 | bs->commands = NULL; | |
3531 | bs->old_val = NULL; | |
3532 | bs->print_it = print_it_normal; | |
3533 | return bs; | |
3534 | } | |
3535 | \f | |
d983da9c DJ |
3536 | /* The target has stopped with waitstatus WS. Check if any hardware |
3537 | watchpoints have triggered, according to the target. */ | |
3538 | ||
3539 | int | |
3540 | watchpoints_triggered (struct target_waitstatus *ws) | |
3541 | { | |
d92524f1 | 3542 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3543 | CORE_ADDR addr; |
3544 | struct breakpoint *b; | |
3545 | ||
3546 | if (!stopped_by_watchpoint) | |
3547 | { | |
3548 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3549 | as not triggered. */ | |
3550 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3551 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3552 | { |
3553 | struct watchpoint *w = (struct watchpoint *) b; | |
3554 | ||
3555 | w->watchpoint_triggered = watch_triggered_no; | |
3556 | } | |
d983da9c DJ |
3557 | |
3558 | return 0; | |
3559 | } | |
3560 | ||
3561 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3562 | { | |
3563 | /* We were stopped by a watchpoint, but we don't know where. | |
3564 | Mark all watchpoints as unknown. */ | |
3565 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3566 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3567 | { |
3568 | struct watchpoint *w = (struct watchpoint *) b; | |
3569 | ||
3570 | w->watchpoint_triggered = watch_triggered_unknown; | |
3571 | } | |
d983da9c DJ |
3572 | |
3573 | return stopped_by_watchpoint; | |
3574 | } | |
3575 | ||
3576 | /* The target could report the data address. Mark watchpoints | |
3577 | affected by this data address as triggered, and all others as not | |
3578 | triggered. */ | |
3579 | ||
3580 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3581 | if (is_hardware_watchpoint (b)) |
d983da9c | 3582 | { |
3a5c3e22 | 3583 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 3584 | struct bp_location *loc; |
d983da9c | 3585 | |
3a5c3e22 | 3586 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 3587 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 3588 | { |
3a5c3e22 | 3589 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 3590 | { |
3a5c3e22 PA |
3591 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
3592 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
3593 | |
3594 | if (newaddr == start) | |
3595 | { | |
3a5c3e22 | 3596 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3597 | break; |
3598 | } | |
3599 | } | |
3600 | /* Exact match not required. Within range is sufficient. */ | |
3601 | else if (target_watchpoint_addr_within_range (¤t_target, | |
3602 | addr, loc->address, | |
3603 | loc->length)) | |
3604 | { | |
3a5c3e22 | 3605 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3606 | break; |
3607 | } | |
3608 | } | |
d983da9c DJ |
3609 | } |
3610 | ||
3611 | return 1; | |
3612 | } | |
3613 | ||
c906108c SS |
3614 | /* Possible return values for watchpoint_check (this can't be an enum |
3615 | because of check_errors). */ | |
3616 | /* The watchpoint has been deleted. */ | |
3617 | #define WP_DELETED 1 | |
3618 | /* The value has changed. */ | |
3619 | #define WP_VALUE_CHANGED 2 | |
3620 | /* The value has not changed. */ | |
3621 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3622 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3623 | #define WP_IGNORE 4 | |
c906108c SS |
3624 | |
3625 | #define BP_TEMPFLAG 1 | |
3626 | #define BP_HARDWAREFLAG 2 | |
3627 | ||
4a64f543 MS |
3628 | /* Evaluate watchpoint condition expression and check if its value |
3629 | changed. | |
553e4c11 JB |
3630 | |
3631 | P should be a pointer to struct bpstat, but is defined as a void * | |
3632 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3633 | |
3634 | static int | |
4efb68b1 | 3635 | watchpoint_check (void *p) |
c906108c SS |
3636 | { |
3637 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 3638 | struct watchpoint *b; |
c906108c SS |
3639 | struct frame_info *fr; |
3640 | int within_current_scope; | |
3641 | ||
f431efe5 | 3642 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3643 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 3644 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 3645 | |
f6bc2008 PA |
3646 | /* If this is a local watchpoint, we only want to check if the |
3647 | watchpoint frame is in scope if the current thread is the thread | |
3648 | that was used to create the watchpoint. */ | |
3649 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3650 | return WP_IGNORE; |
f6bc2008 | 3651 | |
c906108c SS |
3652 | if (b->exp_valid_block == NULL) |
3653 | within_current_scope = 1; | |
3654 | else | |
3655 | { | |
edb3359d DJ |
3656 | struct frame_info *frame = get_current_frame (); |
3657 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3658 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3659 | ||
4a64f543 MS |
3660 | /* in_function_epilogue_p() returns a non-zero value if we're |
3661 | still in the function but the stack frame has already been | |
3662 | invalidated. Since we can't rely on the values of local | |
3663 | variables after the stack has been destroyed, we are treating | |
3664 | the watchpoint in that state as `not changed' without further | |
3665 | checking. Don't mark watchpoints as changed if the current | |
3666 | frame is in an epilogue - even if they are in some other | |
3667 | frame, our view of the stack is likely to be wrong and | |
3668 | frame_find_by_id could error out. */ | |
a0f49112 | 3669 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3670 | return WP_IGNORE; |
a0f49112 | 3671 | |
101dcfbe | 3672 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3673 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3674 | |
3675 | /* If we've gotten confused in the unwinder, we might have | |
3676 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3677 | if (within_current_scope) |
3678 | { | |
3679 | struct symbol *function; | |
3680 | ||
3681 | function = get_frame_function (fr); | |
3682 | if (function == NULL | |
3683 | || !contained_in (b->exp_valid_block, | |
3684 | SYMBOL_BLOCK_VALUE (function))) | |
3685 | within_current_scope = 0; | |
3686 | } | |
69fbadd5 | 3687 | |
edb3359d | 3688 | if (within_current_scope) |
c906108c SS |
3689 | /* If we end up stopping, the current frame will get selected |
3690 | in normal_stop. So this call to select_frame won't affect | |
3691 | the user. */ | |
0f7d239c | 3692 | select_frame (fr); |
c906108c | 3693 | } |
c5aa993b | 3694 | |
c906108c SS |
3695 | if (within_current_scope) |
3696 | { | |
4a64f543 MS |
3697 | /* We use value_{,free_to_}mark because it could be a *long* |
3698 | time before we return to the command level and call | |
3699 | free_all_values. We can't call free_all_values because we | |
3700 | might be in the middle of evaluating a function call. */ | |
c906108c | 3701 | |
0cf6dd15 | 3702 | int pc = 0; |
9c06b0b4 | 3703 | struct value *mark; |
fa4727a6 DJ |
3704 | struct value *new_val; |
3705 | ||
3a5c3e22 | 3706 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
3707 | /* Since we don't know the exact trigger address (from |
3708 | stopped_data_address), just tell the user we've triggered | |
3709 | a mask watchpoint. */ | |
3710 | return WP_VALUE_CHANGED; | |
3711 | ||
3712 | mark = value_mark (); | |
0cf6dd15 | 3713 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3714 | |
4a64f543 MS |
3715 | /* We use value_equal_contents instead of value_equal because |
3716 | the latter coerces an array to a pointer, thus comparing just | |
3717 | the address of the array instead of its contents. This is | |
3718 | not what we want. */ | |
fa4727a6 | 3719 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3720 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3721 | { |
fa4727a6 DJ |
3722 | if (new_val != NULL) |
3723 | { | |
3724 | release_value (new_val); | |
3725 | value_free_to_mark (mark); | |
3726 | } | |
c906108c SS |
3727 | bs->old_val = b->val; |
3728 | b->val = new_val; | |
fa4727a6 | 3729 | b->val_valid = 1; |
c906108c SS |
3730 | return WP_VALUE_CHANGED; |
3731 | } | |
3732 | else | |
3733 | { | |
60e1c644 | 3734 | /* Nothing changed. */ |
c906108c | 3735 | value_free_to_mark (mark); |
c906108c SS |
3736 | return WP_VALUE_NOT_CHANGED; |
3737 | } | |
3738 | } | |
3739 | else | |
3740 | { | |
79a45e25 PA |
3741 | struct ui_out *uiout = current_uiout; |
3742 | ||
c906108c | 3743 | /* This seems like the only logical thing to do because |
c5aa993b JM |
3744 | if we temporarily ignored the watchpoint, then when |
3745 | we reenter the block in which it is valid it contains | |
3746 | garbage (in the case of a function, it may have two | |
3747 | garbage values, one before and one after the prologue). | |
3748 | So we can't even detect the first assignment to it and | |
3749 | watch after that (since the garbage may or may not equal | |
3750 | the first value assigned). */ | |
348d480f PA |
3751 | /* We print all the stop information in |
3752 | breakpoint_ops->print_it, but in this case, by the time we | |
3753 | call breakpoint_ops->print_it this bp will be deleted | |
3754 | already. So we have no choice but print the information | |
3755 | here. */ | |
9dc5e2a9 | 3756 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3757 | ui_out_field_string |
3758 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3759 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 3760 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
3761 | ui_out_text (uiout, |
3762 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3763 | which its expression is valid.\n"); |
4ce44c66 | 3764 | |
cdac0397 | 3765 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 3766 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 3767 | watchpoint_del_at_next_stop (b); |
c906108c SS |
3768 | |
3769 | return WP_DELETED; | |
3770 | } | |
3771 | } | |
3772 | ||
18a18393 | 3773 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
3774 | breakpoint location BL. This function does not check if we should |
3775 | stop, only if BL explains the stop. */ | |
3776 | ||
18a18393 | 3777 | static int |
6c95b8df PA |
3778 | bpstat_check_location (const struct bp_location *bl, |
3779 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3780 | { |
3781 | struct breakpoint *b = bl->owner; | |
3782 | ||
348d480f | 3783 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
3784 | gdb_assert (b != NULL); |
3785 | ||
348d480f | 3786 | return b->ops->breakpoint_hit (bl, aspace, bp_addr); |
18a18393 VP |
3787 | } |
3788 | ||
3a5c3e22 PA |
3789 | /* Determine if the watched values have actually changed, and we |
3790 | should stop. If not, set BS->stop to 0. */ | |
3791 | ||
18a18393 VP |
3792 | static void |
3793 | bpstat_check_watchpoint (bpstat bs) | |
3794 | { | |
2bdf28a0 | 3795 | const struct bp_location *bl; |
3a5c3e22 | 3796 | struct watchpoint *b; |
2bdf28a0 JK |
3797 | |
3798 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3799 | bl = bs->bp_location_at; |
2bdf28a0 | 3800 | gdb_assert (bl != NULL); |
3a5c3e22 | 3801 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 3802 | gdb_assert (b != NULL); |
18a18393 | 3803 | |
18a18393 | 3804 | { |
18a18393 VP |
3805 | int must_check_value = 0; |
3806 | ||
3a5c3e22 | 3807 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
3808 | /* For a software watchpoint, we must always check the |
3809 | watched value. */ | |
3810 | must_check_value = 1; | |
3811 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3812 | /* We have a hardware watchpoint (read, write, or access) | |
3813 | and the target earlier reported an address watched by | |
3814 | this watchpoint. */ | |
3815 | must_check_value = 1; | |
3816 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 3817 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
3818 | /* We were stopped by a hardware watchpoint, but the target could |
3819 | not report the data address. We must check the watchpoint's | |
3820 | value. Access and read watchpoints are out of luck; without | |
3821 | a data address, we can't figure it out. */ | |
3822 | must_check_value = 1; | |
3a5c3e22 | 3823 | |
18a18393 VP |
3824 | if (must_check_value) |
3825 | { | |
3e43a32a MS |
3826 | char *message |
3827 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 3828 | b->base.number); |
18a18393 VP |
3829 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3830 | int e = catch_errors (watchpoint_check, bs, message, | |
3831 | RETURN_MASK_ALL); | |
3832 | do_cleanups (cleanups); | |
3833 | switch (e) | |
3834 | { | |
3835 | case WP_DELETED: | |
3836 | /* We've already printed what needs to be printed. */ | |
3837 | bs->print_it = print_it_done; | |
3838 | /* Stop. */ | |
3839 | break; | |
60e1c644 PA |
3840 | case WP_IGNORE: |
3841 | bs->print_it = print_it_noop; | |
3842 | bs->stop = 0; | |
3843 | break; | |
18a18393 | 3844 | case WP_VALUE_CHANGED: |
3a5c3e22 | 3845 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 3846 | { |
85d721b8 PA |
3847 | /* There are two cases to consider here: |
3848 | ||
4a64f543 | 3849 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3850 | In that case, trust the target, and always report |
3851 | the watchpoint hit to the user. Even though | |
3852 | reads don't cause value changes, the value may | |
3853 | have changed since the last time it was read, and | |
3854 | since we're not trapping writes, we will not see | |
3855 | those, and as such we should ignore our notion of | |
3856 | old value. | |
3857 | ||
4a64f543 | 3858 | 2. We're watching the triggered memory for both |
85d721b8 PA |
3859 | reads and writes. There are two ways this may |
3860 | happen: | |
3861 | ||
4a64f543 | 3862 | 2.1. This is a target that can't break on data |
85d721b8 PA |
3863 | reads only, but can break on accesses (reads or |
3864 | writes), such as e.g., x86. We detect this case | |
3865 | at the time we try to insert read watchpoints. | |
3866 | ||
4a64f543 | 3867 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
3868 | watchpoints, but, the user set an access or write |
3869 | watchpoint watching the same memory as this read | |
3870 | watchpoint. | |
3871 | ||
3872 | If we're watching memory writes as well as reads, | |
3873 | ignore watchpoint hits when we find that the | |
3874 | value hasn't changed, as reads don't cause | |
3875 | changes. This still gives false positives when | |
3876 | the program writes the same value to memory as | |
3877 | what there was already in memory (we will confuse | |
3878 | it for a read), but it's much better than | |
3879 | nothing. */ | |
3880 | ||
3881 | int other_write_watchpoint = 0; | |
3882 | ||
3883 | if (bl->watchpoint_type == hw_read) | |
3884 | { | |
3885 | struct breakpoint *other_b; | |
3886 | ||
3887 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
3888 | if (other_b->type == bp_hardware_watchpoint |
3889 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 3890 | { |
3a5c3e22 PA |
3891 | struct watchpoint *other_w = |
3892 | (struct watchpoint *) other_b; | |
3893 | ||
3894 | if (other_w->watchpoint_triggered | |
3895 | == watch_triggered_yes) | |
3896 | { | |
3897 | other_write_watchpoint = 1; | |
3898 | break; | |
3899 | } | |
85d721b8 PA |
3900 | } |
3901 | } | |
3902 | ||
3903 | if (other_write_watchpoint | |
3904 | || bl->watchpoint_type == hw_access) | |
3905 | { | |
3906 | /* We're watching the same memory for writes, | |
3907 | and the value changed since the last time we | |
3908 | updated it, so this trap must be for a write. | |
3909 | Ignore it. */ | |
3910 | bs->print_it = print_it_noop; | |
3911 | bs->stop = 0; | |
3912 | } | |
18a18393 VP |
3913 | } |
3914 | break; | |
3915 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
3916 | if (b->base.type == bp_hardware_watchpoint |
3917 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
3918 | { |
3919 | /* Don't stop: write watchpoints shouldn't fire if | |
3920 | the value hasn't changed. */ | |
3921 | bs->print_it = print_it_noop; | |
3922 | bs->stop = 0; | |
3923 | } | |
3924 | /* Stop. */ | |
3925 | break; | |
3926 | default: | |
3927 | /* Can't happen. */ | |
3928 | case 0: | |
3929 | /* Error from catch_errors. */ | |
3a5c3e22 | 3930 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 3931 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
3932 | /* We've already printed what needs to be printed. */ |
3933 | bs->print_it = print_it_done; | |
3934 | break; | |
3935 | } | |
3936 | } | |
3937 | else /* must_check_value == 0 */ | |
3938 | { | |
3939 | /* This is a case where some watchpoint(s) triggered, but | |
3940 | not at the address of this watchpoint, or else no | |
3941 | watchpoint triggered after all. So don't print | |
3942 | anything for this watchpoint. */ | |
3943 | bs->print_it = print_it_noop; | |
3944 | bs->stop = 0; | |
3945 | } | |
3946 | } | |
3947 | } | |
3948 | ||
3949 | ||
3950 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3951 | of breakpoint referred to by BS. If we should not stop for this | |
3952 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 3953 | |
18a18393 VP |
3954 | static void |
3955 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3956 | { | |
3957 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
3958 | const struct bp_location *bl; |
3959 | struct breakpoint *b; | |
3960 | ||
3961 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3962 | bl = bs->bp_location_at; |
2bdf28a0 | 3963 | gdb_assert (bl != NULL); |
f431efe5 | 3964 | b = bs->breakpoint_at; |
2bdf28a0 | 3965 | gdb_assert (b != NULL); |
18a18393 VP |
3966 | |
3967 | if (frame_id_p (b->frame_id) | |
edb3359d | 3968 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3969 | bs->stop = 0; |
3970 | else if (bs->stop) | |
3971 | { | |
3972 | int value_is_zero = 0; | |
60e1c644 PA |
3973 | struct expression *cond; |
3974 | ||
7371cf6d PM |
3975 | /* Evaluate Python breakpoints that have a "stop" |
3976 | method implemented. */ | |
3977 | if (b->py_bp_object) | |
3978 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
3979 | ||
60e1c644 | 3980 | if (is_watchpoint (b)) |
3a5c3e22 PA |
3981 | { |
3982 | struct watchpoint *w = (struct watchpoint *) b; | |
3983 | ||
3984 | cond = w->cond_exp; | |
3985 | } | |
60e1c644 PA |
3986 | else |
3987 | cond = bl->cond; | |
3988 | ||
f431efe5 | 3989 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 3990 | { |
60e1c644 | 3991 | int within_current_scope = 1; |
3a5c3e22 | 3992 | struct watchpoint * w; |
60e1c644 | 3993 | |
c5bc3a77 DJ |
3994 | /* We use value_mark and value_free_to_mark because it could |
3995 | be a long time before we return to the command level and | |
3996 | call free_all_values. We can't call free_all_values | |
3997 | because we might be in the middle of evaluating a | |
3998 | function call. */ | |
3999 | struct value *mark = value_mark (); | |
4000 | ||
3a5c3e22 PA |
4001 | if (is_watchpoint (b)) |
4002 | w = (struct watchpoint *) b; | |
4003 | else | |
4004 | w = NULL; | |
4005 | ||
edb3359d DJ |
4006 | /* Need to select the frame, with all that implies so that |
4007 | the conditions will have the right context. Because we | |
4008 | use the frame, we will not see an inlined function's | |
4009 | variables when we arrive at a breakpoint at the start | |
4010 | of the inlined function; the current frame will be the | |
4011 | call site. */ | |
3a5c3e22 | 4012 | if (w == NULL || w->cond_exp_valid_block == NULL) |
60e1c644 PA |
4013 | select_frame (get_current_frame ()); |
4014 | else | |
4015 | { | |
4016 | struct frame_info *frame; | |
4017 | ||
4018 | /* For local watchpoint expressions, which particular | |
4019 | instance of a local is being watched matters, so we | |
4020 | keep track of the frame to evaluate the expression | |
4021 | in. To evaluate the condition however, it doesn't | |
4022 | really matter which instantiation of the function | |
4023 | where the condition makes sense triggers the | |
4024 | watchpoint. This allows an expression like "watch | |
4025 | global if q > 10" set in `func', catch writes to | |
4026 | global on all threads that call `func', or catch | |
4027 | writes on all recursive calls of `func' by a single | |
4028 | thread. We simply always evaluate the condition in | |
4029 | the innermost frame that's executing where it makes | |
4030 | sense to evaluate the condition. It seems | |
4031 | intuitive. */ | |
3a5c3e22 | 4032 | frame = block_innermost_frame (w->cond_exp_valid_block); |
60e1c644 PA |
4033 | if (frame != NULL) |
4034 | select_frame (frame); | |
4035 | else | |
4036 | within_current_scope = 0; | |
4037 | } | |
4038 | if (within_current_scope) | |
4039 | value_is_zero | |
4040 | = catch_errors (breakpoint_cond_eval, cond, | |
4041 | "Error in testing breakpoint condition:\n", | |
4042 | RETURN_MASK_ALL); | |
4043 | else | |
4044 | { | |
4045 | warning (_("Watchpoint condition cannot be tested " | |
4046 | "in the current scope")); | |
4047 | /* If we failed to set the right context for this | |
4048 | watchpoint, unconditionally report it. */ | |
4049 | value_is_zero = 0; | |
4050 | } | |
4a64f543 | 4051 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4052 | value_free_to_mark (mark); |
18a18393 | 4053 | } |
60e1c644 PA |
4054 | |
4055 | if (cond && value_is_zero) | |
18a18393 VP |
4056 | { |
4057 | bs->stop = 0; | |
4058 | } | |
4059 | else if (b->thread != -1 && b->thread != thread_id) | |
4060 | { | |
4061 | bs->stop = 0; | |
4062 | } | |
4063 | else if (b->ignore_count > 0) | |
4064 | { | |
4065 | b->ignore_count--; | |
4066 | annotate_ignore_count_change (); | |
4067 | bs->stop = 0; | |
4a64f543 | 4068 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 4069 | ++(b->hit_count); |
8d3788bd | 4070 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
4071 | } |
4072 | } | |
4073 | } | |
4074 | ||
4075 | ||
9709f61c | 4076 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4077 | BP_ADDR in thread PTID. |
c906108c | 4078 | |
d983da9c | 4079 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4080 | don't understand this stop. Result is a chain of bpstat's such |
4081 | that: | |
c906108c | 4082 | |
c5aa993b | 4083 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4084 | |
c5aa993b | 4085 | if we understand why we stopped, the result is not null. |
c906108c | 4086 | |
c5aa993b JM |
4087 | Each element of the chain refers to a particular breakpoint or |
4088 | watchpoint at which we have stopped. (We may have stopped for | |
4089 | several reasons concurrently.) | |
c906108c | 4090 | |
c5aa993b JM |
4091 | Each element of the chain has valid next, breakpoint_at, |
4092 | commands, FIXME??? fields. */ | |
c906108c SS |
4093 | |
4094 | bpstat | |
6c95b8df PA |
4095 | bpstat_stop_status (struct address_space *aspace, |
4096 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4097 | { |
0d381245 | 4098 | struct breakpoint *b = NULL; |
afe38095 | 4099 | struct bp_location *bl; |
20874c92 | 4100 | struct bp_location *loc; |
5760d0ab JK |
4101 | /* First item of allocated bpstat's. */ |
4102 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4103 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4104 | bpstat bs; |
20874c92 | 4105 | int ix; |
429374b8 | 4106 | int need_remove_insert; |
f431efe5 | 4107 | int removed_any; |
c906108c | 4108 | |
f431efe5 PA |
4109 | /* First, build the bpstat chain with locations that explain a |
4110 | target stop, while being careful to not set the target running, | |
4111 | as that may invalidate locations (in particular watchpoint | |
4112 | locations are recreated). Resuming will happen here with | |
4113 | breakpoint conditions or watchpoint expressions that include | |
4114 | inferior function calls. */ | |
c5aa993b | 4115 | |
429374b8 JK |
4116 | ALL_BREAKPOINTS (b) |
4117 | { | |
4118 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4119 | continue; | |
a5606eee | 4120 | |
429374b8 JK |
4121 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4122 | { | |
4a64f543 MS |
4123 | /* For hardware watchpoints, we look only at the first |
4124 | location. The watchpoint_check function will work on the | |
4125 | entire expression, not the individual locations. For | |
4126 | read watchpoints, the watchpoints_triggered function has | |
4127 | checked all locations already. */ | |
429374b8 JK |
4128 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4129 | break; | |
18a18393 | 4130 | |
429374b8 JK |
4131 | if (bl->shlib_disabled) |
4132 | continue; | |
c5aa993b | 4133 | |
429374b8 JK |
4134 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4135 | continue; | |
c5aa993b | 4136 | |
4a64f543 MS |
4137 | /* Come here if it's a watchpoint, or if the break address |
4138 | matches. */ | |
c5aa993b | 4139 | |
4a64f543 MS |
4140 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4141 | explain stop. */ | |
c5aa993b | 4142 | |
f431efe5 PA |
4143 | /* Assume we stop. Should we find a watchpoint that is not |
4144 | actually triggered, or if the condition of the breakpoint | |
4145 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4146 | bs->stop = 1; |
4147 | bs->print = 1; | |
d983da9c | 4148 | |
f431efe5 PA |
4149 | /* If this is a scope breakpoint, mark the associated |
4150 | watchpoint as triggered so that we will handle the | |
4151 | out-of-scope event. We'll get to the watchpoint next | |
4152 | iteration. */ | |
d0fb5eae | 4153 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
4154 | { |
4155 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
4156 | ||
4157 | w->watchpoint_triggered = watch_triggered_yes; | |
4158 | } | |
f431efe5 PA |
4159 | } |
4160 | } | |
4161 | ||
4162 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4163 | { | |
f1310107 | 4164 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 4165 | { |
5760d0ab | 4166 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4167 | /* For hits of moribund locations, we should just proceed. */ |
4168 | bs->stop = 0; | |
4169 | bs->print = 0; | |
4170 | bs->print_it = print_it_noop; | |
4171 | } | |
4172 | } | |
4173 | ||
f431efe5 PA |
4174 | /* Now go through the locations that caused the target to stop, and |
4175 | check whether we're interested in reporting this stop to higher | |
4176 | layers, or whether we should resume the target transparently. */ | |
4177 | ||
4178 | removed_any = 0; | |
4179 | ||
5760d0ab | 4180 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4181 | { |
4182 | if (!bs->stop) | |
4183 | continue; | |
4184 | ||
f431efe5 | 4185 | b = bs->breakpoint_at; |
348d480f PA |
4186 | b->ops->check_status (bs); |
4187 | if (bs->stop) | |
28010a5d | 4188 | { |
348d480f | 4189 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 4190 | |
429374b8 JK |
4191 | if (bs->stop) |
4192 | { | |
4193 | ++(b->hit_count); | |
8d3788bd | 4194 | observer_notify_breakpoint_modified (b); |
c906108c | 4195 | |
4a64f543 | 4196 | /* We will stop here. */ |
429374b8 JK |
4197 | if (b->disposition == disp_disable) |
4198 | { | |
4199 | if (b->enable_state != bp_permanent) | |
4200 | b->enable_state = bp_disabled; | |
f431efe5 | 4201 | removed_any = 1; |
429374b8 JK |
4202 | } |
4203 | if (b->silent) | |
4204 | bs->print = 0; | |
4205 | bs->commands = b->commands; | |
9add0f1b | 4206 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
4207 | if (command_line_is_silent (bs->commands |
4208 | ? bs->commands->commands : NULL)) | |
4209 | bs->print = 0; | |
429374b8 JK |
4210 | } |
4211 | ||
e5dd4106 | 4212 | /* Print nothing for this entry if we don't stop or don't print. */ |
429374b8 JK |
4213 | if (bs->stop == 0 || bs->print == 0) |
4214 | bs->print_it = print_it_noop; | |
348d480f | 4215 | } |
429374b8 | 4216 | } |
876fa593 | 4217 | |
d983da9c DJ |
4218 | /* If we aren't stopping, the value of some hardware watchpoint may |
4219 | not have changed, but the intermediate memory locations we are | |
4220 | watching may have. Don't bother if we're stopping; this will get | |
4221 | done later. */ | |
d832cb68 | 4222 | need_remove_insert = 0; |
5760d0ab JK |
4223 | if (! bpstat_causes_stop (bs_head)) |
4224 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4225 | if (!bs->stop |
f431efe5 PA |
4226 | && bs->breakpoint_at |
4227 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4228 | { |
3a5c3e22 PA |
4229 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
4230 | ||
4231 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 4232 | need_remove_insert = 1; |
d983da9c DJ |
4233 | } |
4234 | ||
d832cb68 | 4235 | if (need_remove_insert) |
2d134ed3 | 4236 | update_global_location_list (1); |
f431efe5 PA |
4237 | else if (removed_any) |
4238 | update_global_location_list (0); | |
d832cb68 | 4239 | |
5760d0ab | 4240 | return bs_head; |
c906108c | 4241 | } |
628fe4e4 JK |
4242 | |
4243 | static void | |
4244 | handle_jit_event (void) | |
4245 | { | |
4246 | struct frame_info *frame; | |
4247 | struct gdbarch *gdbarch; | |
4248 | ||
4249 | /* Switch terminal for any messages produced by | |
4250 | breakpoint_re_set. */ | |
4251 | target_terminal_ours_for_output (); | |
4252 | ||
4253 | frame = get_current_frame (); | |
4254 | gdbarch = get_frame_arch (frame); | |
4255 | ||
4256 | jit_event_handler (gdbarch); | |
4257 | ||
4258 | target_terminal_inferior (); | |
4259 | } | |
4260 | ||
4261 | /* Prepare WHAT final decision for infrun. */ | |
4262 | ||
4263 | /* Decide what infrun needs to do with this bpstat. */ | |
4264 | ||
c906108c | 4265 | struct bpstat_what |
0e30163f | 4266 | bpstat_what (bpstat bs_head) |
c906108c | 4267 | { |
c906108c | 4268 | struct bpstat_what retval; |
628fe4e4 JK |
4269 | /* We need to defer calling `solib_add', as adding new symbols |
4270 | resets breakpoints, which in turn deletes breakpoint locations, | |
4271 | and hence may clear unprocessed entries in the BS chain. */ | |
4272 | int shlib_event = 0; | |
4273 | int jit_event = 0; | |
0e30163f | 4274 | bpstat bs; |
c906108c | 4275 | |
628fe4e4 | 4276 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4277 | retval.call_dummy = STOP_NONE; |
186c406b | 4278 | retval.is_longjmp = 0; |
628fe4e4 | 4279 | |
0e30163f | 4280 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 4281 | { |
628fe4e4 JK |
4282 | /* Extract this BS's action. After processing each BS, we check |
4283 | if its action overrides all we've seem so far. */ | |
4284 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4285 | enum bptype bptype; | |
4286 | ||
c906108c | 4287 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4288 | { |
4289 | /* I suspect this can happen if it was a momentary | |
4290 | breakpoint which has since been deleted. */ | |
4291 | bptype = bp_none; | |
4292 | } | |
20874c92 | 4293 | else |
f431efe5 | 4294 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4295 | |
4296 | switch (bptype) | |
c906108c SS |
4297 | { |
4298 | case bp_none: | |
628fe4e4 | 4299 | break; |
c906108c SS |
4300 | case bp_breakpoint: |
4301 | case bp_hardware_breakpoint: | |
4302 | case bp_until: | |
4303 | case bp_finish: | |
4304 | if (bs->stop) | |
4305 | { | |
4306 | if (bs->print) | |
628fe4e4 | 4307 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4308 | else |
628fe4e4 | 4309 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4310 | } |
4311 | else | |
628fe4e4 | 4312 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4313 | break; |
4314 | case bp_watchpoint: | |
4315 | case bp_hardware_watchpoint: | |
4316 | case bp_read_watchpoint: | |
4317 | case bp_access_watchpoint: | |
4318 | if (bs->stop) | |
4319 | { | |
4320 | if (bs->print) | |
628fe4e4 | 4321 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4322 | else |
628fe4e4 | 4323 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4324 | } |
4325 | else | |
628fe4e4 JK |
4326 | { |
4327 | /* There was a watchpoint, but we're not stopping. | |
4328 | This requires no further action. */ | |
4329 | } | |
c906108c SS |
4330 | break; |
4331 | case bp_longjmp: | |
186c406b | 4332 | case bp_exception: |
628fe4e4 | 4333 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4334 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4335 | break; |
4336 | case bp_longjmp_resume: | |
186c406b | 4337 | case bp_exception_resume: |
628fe4e4 | 4338 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4339 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4340 | break; |
4341 | case bp_step_resume: | |
4342 | if (bs->stop) | |
628fe4e4 JK |
4343 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4344 | else | |
c906108c | 4345 | { |
628fe4e4 JK |
4346 | /* It is for the wrong frame. */ |
4347 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4348 | } |
c906108c | 4349 | break; |
2c03e5be PA |
4350 | case bp_hp_step_resume: |
4351 | if (bs->stop) | |
4352 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
4353 | else | |
4354 | { | |
4355 | /* It is for the wrong frame. */ | |
4356 | this_action = BPSTAT_WHAT_SINGLE; | |
4357 | } | |
4358 | break; | |
c906108c | 4359 | case bp_watchpoint_scope: |
c4093a6a | 4360 | case bp_thread_event: |
1900040c | 4361 | case bp_overlay_event: |
0fd8e87f | 4362 | case bp_longjmp_master: |
aa7d318d | 4363 | case bp_std_terminate_master: |
186c406b | 4364 | case bp_exception_master: |
628fe4e4 | 4365 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4366 | break; |
ce78b96d | 4367 | case bp_catchpoint: |
c5aa993b JM |
4368 | if (bs->stop) |
4369 | { | |
4370 | if (bs->print) | |
628fe4e4 | 4371 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4372 | else |
628fe4e4 | 4373 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4374 | } |
4375 | else | |
628fe4e4 JK |
4376 | { |
4377 | /* There was a catchpoint, but we're not stopping. | |
4378 | This requires no further action. */ | |
4379 | } | |
4380 | break; | |
4381 | case bp_shlib_event: | |
4382 | shlib_event = 1; | |
4383 | ||
4384 | /* If requested, stop when the dynamic linker notifies GDB | |
4385 | of events. This allows the user to get control and place | |
4386 | breakpoints in initializer routines for dynamically | |
4387 | loaded objects (among other things). */ | |
4388 | if (stop_on_solib_events) | |
4389 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4390 | else | |
4391 | this_action = BPSTAT_WHAT_SINGLE; | |
4392 | break; | |
4393 | case bp_jit_event: | |
4394 | jit_event = 1; | |
4395 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4396 | break; |
c906108c | 4397 | case bp_call_dummy: |
53a5351d JM |
4398 | /* Make sure the action is stop (silent or noisy), |
4399 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4400 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4401 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4402 | break; |
4403 | case bp_std_terminate: | |
4404 | /* Make sure the action is stop (silent or noisy), | |
4405 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4406 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4407 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4408 | break; |
1042e4c0 | 4409 | case bp_tracepoint: |
7a697b8d | 4410 | case bp_fast_tracepoint: |
0fb4aa4b | 4411 | case bp_static_tracepoint: |
1042e4c0 SS |
4412 | /* Tracepoint hits should not be reported back to GDB, and |
4413 | if one got through somehow, it should have been filtered | |
4414 | out already. */ | |
4415 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4416 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
4417 | break; |
4418 | case bp_gnu_ifunc_resolver: | |
4419 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
4420 | this_action = BPSTAT_WHAT_SINGLE; | |
4421 | break; | |
4422 | case bp_gnu_ifunc_resolver_return: | |
4423 | /* The breakpoint will be removed, execution will restart from the | |
4424 | PC of the former breakpoint. */ | |
4425 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4426 | break; | |
628fe4e4 JK |
4427 | default: |
4428 | internal_error (__FILE__, __LINE__, | |
4429 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4430 | } |
628fe4e4 JK |
4431 | |
4432 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4433 | } |
628fe4e4 | 4434 | |
0e30163f JK |
4435 | /* These operations may affect the bs->breakpoint_at state so they are |
4436 | delayed after MAIN_ACTION is decided above. */ | |
4437 | ||
628fe4e4 JK |
4438 | if (shlib_event) |
4439 | { | |
4440 | if (debug_infrun) | |
4441 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4442 | ||
4443 | /* Check for any newly added shared libraries if we're supposed | |
4444 | to be adding them automatically. */ | |
4445 | ||
4446 | /* Switch terminal for any messages produced by | |
4447 | breakpoint_re_set. */ | |
4448 | target_terminal_ours_for_output (); | |
4449 | ||
4450 | #ifdef SOLIB_ADD | |
4451 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4452 | #else | |
4453 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4454 | #endif | |
4455 | ||
4456 | target_terminal_inferior (); | |
4457 | } | |
4458 | ||
4459 | if (jit_event) | |
4460 | { | |
4461 | if (debug_infrun) | |
4462 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4463 | ||
4464 | handle_jit_event (); | |
4465 | } | |
4466 | ||
0e30163f JK |
4467 | for (bs = bs_head; bs != NULL; bs = bs->next) |
4468 | { | |
4469 | struct breakpoint *b = bs->breakpoint_at; | |
4470 | ||
4471 | if (b == NULL) | |
4472 | continue; | |
4473 | switch (b->type) | |
4474 | { | |
4475 | case bp_gnu_ifunc_resolver: | |
4476 | gnu_ifunc_resolver_stop (b); | |
4477 | break; | |
4478 | case bp_gnu_ifunc_resolver_return: | |
4479 | gnu_ifunc_resolver_return_stop (b); | |
4480 | break; | |
4481 | } | |
4482 | } | |
4483 | ||
c906108c SS |
4484 | return retval; |
4485 | } | |
4486 | ||
4487 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4488 | without hardware support). This isn't related to a specific bpstat, | |
4489 | just to things like whether watchpoints are set. */ | |
4490 | ||
c5aa993b | 4491 | int |
fba45db2 | 4492 | bpstat_should_step (void) |
c906108c SS |
4493 | { |
4494 | struct breakpoint *b; | |
cc59ec59 | 4495 | |
c906108c | 4496 | ALL_BREAKPOINTS (b) |
717a8278 | 4497 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4498 | return 1; |
c906108c SS |
4499 | return 0; |
4500 | } | |
4501 | ||
67822962 PA |
4502 | int |
4503 | bpstat_causes_stop (bpstat bs) | |
4504 | { | |
4505 | for (; bs != NULL; bs = bs->next) | |
4506 | if (bs->stop) | |
4507 | return 1; | |
4508 | ||
4509 | return 0; | |
4510 | } | |
4511 | ||
c906108c | 4512 | \f |
c5aa993b | 4513 | |
170b53b2 UW |
4514 | /* Compute a string of spaces suitable to indent the next line |
4515 | so it starts at the position corresponding to the table column | |
4516 | named COL_NAME in the currently active table of UIOUT. */ | |
4517 | ||
4518 | static char * | |
4519 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
4520 | { | |
4521 | static char wrap_indent[80]; | |
4522 | int i, total_width, width, align; | |
4523 | char *text; | |
4524 | ||
4525 | total_width = 0; | |
4526 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
4527 | { | |
4528 | if (strcmp (text, col_name) == 0) | |
4529 | { | |
4530 | gdb_assert (total_width < sizeof wrap_indent); | |
4531 | memset (wrap_indent, ' ', total_width); | |
4532 | wrap_indent[total_width] = 0; | |
4533 | ||
4534 | return wrap_indent; | |
4535 | } | |
4536 | ||
4537 | total_width += width + 1; | |
4538 | } | |
4539 | ||
4540 | return NULL; | |
4541 | } | |
4542 | ||
859825b8 JK |
4543 | /* Print the LOC location out of the list of B->LOC locations. */ |
4544 | ||
170b53b2 UW |
4545 | static void |
4546 | print_breakpoint_location (struct breakpoint *b, | |
4547 | struct bp_location *loc) | |
0d381245 | 4548 | { |
79a45e25 | 4549 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
4550 | struct cleanup *old_chain = save_current_program_space (); |
4551 | ||
859825b8 JK |
4552 | if (loc != NULL && loc->shlib_disabled) |
4553 | loc = NULL; | |
4554 | ||
6c95b8df PA |
4555 | if (loc != NULL) |
4556 | set_current_program_space (loc->pspace); | |
4557 | ||
56435ebe TT |
4558 | if (b->display_canonical) |
4559 | ui_out_field_string (uiout, "what", b->addr_string); | |
4560 | else if (b->source_file && loc) | |
0d381245 VP |
4561 | { |
4562 | struct symbol *sym | |
4563 | = find_pc_sect_function (loc->address, loc->section); | |
4564 | if (sym) | |
4565 | { | |
4566 | ui_out_text (uiout, "in "); | |
4567 | ui_out_field_string (uiout, "func", | |
4568 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
4569 | ui_out_text (uiout, " "); |
4570 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
4571 | ui_out_text (uiout, "at "); | |
0d381245 VP |
4572 | } |
4573 | ui_out_field_string (uiout, "file", b->source_file); | |
4574 | ui_out_text (uiout, ":"); | |
4575 | ||
4576 | if (ui_out_is_mi_like_p (uiout)) | |
4577 | { | |
4578 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4579 | char *fullname = symtab_to_fullname (sal.symtab); | |
4580 | ||
4581 | if (fullname) | |
4582 | ui_out_field_string (uiout, "fullname", fullname); | |
4583 | } | |
4584 | ||
4585 | ui_out_field_int (uiout, "line", b->line_number); | |
4586 | } | |
859825b8 | 4587 | else if (loc) |
0d381245 | 4588 | { |
170b53b2 UW |
4589 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4590 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
4591 | ||
22e722e1 DJ |
4592 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4593 | demangle, ""); | |
0d381245 | 4594 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
4595 | |
4596 | do_cleanups (stb_chain); | |
0d381245 | 4597 | } |
859825b8 JK |
4598 | else |
4599 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4600 | |
4601 | do_cleanups (old_chain); | |
0d381245 VP |
4602 | } |
4603 | ||
269b11a2 PA |
4604 | static const char * |
4605 | bptype_string (enum bptype type) | |
c906108c | 4606 | { |
c4093a6a JM |
4607 | struct ep_type_description |
4608 | { | |
4609 | enum bptype type; | |
4610 | char *description; | |
4611 | }; | |
4612 | static struct ep_type_description bptypes[] = | |
c906108c | 4613 | { |
c5aa993b JM |
4614 | {bp_none, "?deleted?"}, |
4615 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4616 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4617 | {bp_until, "until"}, |
4618 | {bp_finish, "finish"}, | |
4619 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4620 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4621 | {bp_read_watchpoint, "read watchpoint"}, |
4622 | {bp_access_watchpoint, "acc watchpoint"}, | |
4623 | {bp_longjmp, "longjmp"}, | |
4624 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4625 | {bp_exception, "exception"}, |
4626 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4627 | {bp_step_resume, "step resume"}, |
2c03e5be | 4628 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
4629 | {bp_watchpoint_scope, "watchpoint scope"}, |
4630 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4631 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4632 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4633 | {bp_thread_event, "thread events"}, |
1900040c | 4634 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4635 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4636 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4637 | {bp_exception_master, "exception master"}, |
ce78b96d | 4638 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4639 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4640 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4641 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4642 | {bp_jit_event, "jit events"}, |
0e30163f JK |
4643 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
4644 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 4645 | }; |
269b11a2 PA |
4646 | |
4647 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4648 | || ((int) type != bptypes[(int) type].type)) | |
4649 | internal_error (__FILE__, __LINE__, | |
4650 | _("bptypes table does not describe type #%d."), | |
4651 | (int) type); | |
4652 | ||
4653 | return bptypes[(int) type].description; | |
4654 | } | |
4655 | ||
4656 | /* Print B to gdb_stdout. */ | |
4657 | ||
4658 | static void | |
4659 | print_one_breakpoint_location (struct breakpoint *b, | |
4660 | struct bp_location *loc, | |
4661 | int loc_number, | |
4662 | struct bp_location **last_loc, | |
269b11a2 PA |
4663 | int allflag) |
4664 | { | |
4665 | struct command_line *l; | |
c2c6d25f | 4666 | static char bpenables[] = "nynny"; |
c906108c | 4667 | |
79a45e25 | 4668 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
4669 | int header_of_multiple = 0; |
4670 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4671 | struct value_print_options opts; |
4672 | ||
4673 | get_user_print_options (&opts); | |
0d381245 VP |
4674 | |
4675 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4676 | /* See comment in print_one_breakpoint concerning treatment of |
4677 | breakpoints with single disabled location. */ | |
0d381245 VP |
4678 | if (loc == NULL |
4679 | && (b->loc != NULL | |
4680 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4681 | header_of_multiple = 1; | |
4682 | if (loc == NULL) | |
4683 | loc = b->loc; | |
4684 | ||
c4093a6a JM |
4685 | annotate_record (); |
4686 | ||
4687 | /* 1 */ | |
4688 | annotate_field (0); | |
0d381245 VP |
4689 | if (part_of_multiple) |
4690 | { | |
4691 | char *formatted; | |
0c6773c1 | 4692 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4693 | ui_out_field_string (uiout, "number", formatted); |
4694 | xfree (formatted); | |
4695 | } | |
4696 | else | |
4697 | { | |
4698 | ui_out_field_int (uiout, "number", b->number); | |
4699 | } | |
c4093a6a JM |
4700 | |
4701 | /* 2 */ | |
4702 | annotate_field (1); | |
0d381245 VP |
4703 | if (part_of_multiple) |
4704 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4705 | else |
4706 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4707 | |
4708 | /* 3 */ | |
4709 | annotate_field (2); | |
0d381245 VP |
4710 | if (part_of_multiple) |
4711 | ui_out_field_skip (uiout, "disp"); | |
4712 | else | |
2cec12e5 | 4713 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4714 | |
c4093a6a JM |
4715 | |
4716 | /* 4 */ | |
4717 | annotate_field (3); | |
0d381245 | 4718 | if (part_of_multiple) |
54e52265 | 4719 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4720 | else |
4a64f543 MS |
4721 | ui_out_field_fmt (uiout, "enabled", "%c", |
4722 | bpenables[(int) b->enable_state]); | |
54e52265 | 4723 | ui_out_spaces (uiout, 2); |
0d381245 | 4724 | |
c4093a6a JM |
4725 | |
4726 | /* 5 and 6 */ | |
3086aeae | 4727 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4728 | { |
4a64f543 MS |
4729 | /* Although the print_one can possibly print all locations, |
4730 | calling it here is not likely to get any nice result. So, | |
4731 | make sure there's just one location. */ | |
0d381245 | 4732 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4733 | b->ops->print_one (b, last_loc); |
0d381245 | 4734 | } |
3086aeae DJ |
4735 | else |
4736 | switch (b->type) | |
4737 | { | |
4738 | case bp_none: | |
4739 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4740 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4741 | break; |
c906108c | 4742 | |
3086aeae DJ |
4743 | case bp_watchpoint: |
4744 | case bp_hardware_watchpoint: | |
4745 | case bp_read_watchpoint: | |
4746 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4747 | { |
4748 | struct watchpoint *w = (struct watchpoint *) b; | |
4749 | ||
4750 | /* Field 4, the address, is omitted (which makes the columns | |
4751 | not line up too nicely with the headers, but the effect | |
4752 | is relatively readable). */ | |
4753 | if (opts.addressprint) | |
4754 | ui_out_field_skip (uiout, "addr"); | |
4755 | annotate_field (5); | |
4756 | ui_out_field_string (uiout, "what", w->exp_string); | |
4757 | } | |
3086aeae DJ |
4758 | break; |
4759 | ||
3086aeae DJ |
4760 | case bp_breakpoint: |
4761 | case bp_hardware_breakpoint: | |
4762 | case bp_until: | |
4763 | case bp_finish: | |
4764 | case bp_longjmp: | |
4765 | case bp_longjmp_resume: | |
186c406b TT |
4766 | case bp_exception: |
4767 | case bp_exception_resume: | |
3086aeae | 4768 | case bp_step_resume: |
2c03e5be | 4769 | case bp_hp_step_resume: |
3086aeae DJ |
4770 | case bp_watchpoint_scope: |
4771 | case bp_call_dummy: | |
aa7d318d | 4772 | case bp_std_terminate: |
3086aeae DJ |
4773 | case bp_shlib_event: |
4774 | case bp_thread_event: | |
4775 | case bp_overlay_event: | |
0fd8e87f | 4776 | case bp_longjmp_master: |
aa7d318d | 4777 | case bp_std_terminate_master: |
186c406b | 4778 | case bp_exception_master: |
1042e4c0 | 4779 | case bp_tracepoint: |
7a697b8d | 4780 | case bp_fast_tracepoint: |
0fb4aa4b | 4781 | case bp_static_tracepoint: |
4efc6507 | 4782 | case bp_jit_event: |
0e30163f JK |
4783 | case bp_gnu_ifunc_resolver: |
4784 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 4785 | if (opts.addressprint) |
3086aeae DJ |
4786 | { |
4787 | annotate_field (4); | |
54e52265 | 4788 | if (header_of_multiple) |
0d381245 | 4789 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4790 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4791 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4792 | else |
5af949e3 UW |
4793 | ui_out_field_core_addr (uiout, "addr", |
4794 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4795 | } |
4796 | annotate_field (5); | |
0d381245 | 4797 | if (!header_of_multiple) |
170b53b2 | 4798 | print_breakpoint_location (b, loc); |
0d381245 | 4799 | if (b->loc) |
a6d9a66e | 4800 | *last_loc = b->loc; |
3086aeae DJ |
4801 | break; |
4802 | } | |
c906108c | 4803 | |
6c95b8df PA |
4804 | |
4805 | /* For backward compatibility, don't display inferiors unless there | |
4806 | are several. */ | |
4807 | if (loc != NULL | |
4808 | && !header_of_multiple | |
4809 | && (allflag | |
4810 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4811 | && (number_of_program_spaces () > 1 | |
4812 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4813 | /* LOC is for existing B, it cannot be in |
4814 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4815 | && loc->owner->type != bp_catchpoint))) |
4816 | { | |
4817 | struct inferior *inf; | |
4818 | int first = 1; | |
4819 | ||
4820 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4821 | { | |
4822 | if (inf->pspace == loc->pspace) | |
4823 | { | |
4824 | if (first) | |
4825 | { | |
4826 | first = 0; | |
4827 | ui_out_text (uiout, " inf "); | |
4828 | } | |
4829 | else | |
4830 | ui_out_text (uiout, ", "); | |
4831 | ui_out_text (uiout, plongest (inf->num)); | |
4832 | } | |
4833 | } | |
4834 | } | |
4835 | ||
4a306c9a | 4836 | if (!part_of_multiple) |
c4093a6a | 4837 | { |
4a306c9a JB |
4838 | if (b->thread != -1) |
4839 | { | |
4840 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4841 | "stop only in" line a little further down. */ |
4a306c9a JB |
4842 | ui_out_text (uiout, " thread "); |
4843 | ui_out_field_int (uiout, "thread", b->thread); | |
4844 | } | |
4845 | else if (b->task != 0) | |
4846 | { | |
4847 | ui_out_text (uiout, " task "); | |
4848 | ui_out_field_int (uiout, "task", b->task); | |
4849 | } | |
c4093a6a | 4850 | } |
f1310107 | 4851 | |
8b93c638 | 4852 | ui_out_text (uiout, "\n"); |
f1310107 | 4853 | |
348d480f | 4854 | if (!part_of_multiple) |
f1310107 TJB |
4855 | b->ops->print_one_detail (b, uiout); |
4856 | ||
0d381245 | 4857 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4858 | { |
4859 | annotate_field (6); | |
8b93c638 | 4860 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 4861 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 4862 | the frame ID. */ |
5af949e3 UW |
4863 | ui_out_field_core_addr (uiout, "frame", |
4864 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4865 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4866 | } |
4867 | ||
28010a5d | 4868 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
4869 | { |
4870 | annotate_field (7); | |
d77f58be | 4871 | if (is_tracepoint (b)) |
1042e4c0 SS |
4872 | ui_out_text (uiout, "\ttrace only if "); |
4873 | else | |
4874 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4875 | ui_out_field_string (uiout, "cond", b->cond_string); |
4876 | ui_out_text (uiout, "\n"); | |
4877 | } | |
4878 | ||
0d381245 | 4879 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 4880 | { |
4a64f543 | 4881 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4882 | ui_out_text (uiout, "\tstop only in thread "); |
4883 | ui_out_field_int (uiout, "thread", b->thread); | |
4884 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4885 | } |
4886 | ||
63c715c6 | 4887 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 4888 | { |
4a64f543 | 4889 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4890 | if (ep_is_catchpoint (b)) |
4891 | ui_out_text (uiout, "\tcatchpoint"); | |
4892 | else | |
4893 | ui_out_text (uiout, "\tbreakpoint"); | |
4894 | ui_out_text (uiout, " already hit "); | |
4895 | ui_out_field_int (uiout, "times", b->hit_count); | |
4896 | if (b->hit_count == 1) | |
4897 | ui_out_text (uiout, " time\n"); | |
4898 | else | |
4899 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4900 | } |
4901 | ||
4a64f543 MS |
4902 | /* Output the count also if it is zero, but only if this is mi. |
4903 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4904 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4905 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4906 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4907 | |
0d381245 | 4908 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4909 | { |
4910 | annotate_field (8); | |
8b93c638 JM |
4911 | ui_out_text (uiout, "\tignore next "); |
4912 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4913 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4914 | } |
059fb39f | 4915 | |
9add0f1b | 4916 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4917 | if (!part_of_multiple && l) |
c4093a6a | 4918 | { |
3b31d625 EZ |
4919 | struct cleanup *script_chain; |
4920 | ||
c4093a6a | 4921 | annotate_field (9); |
3b31d625 | 4922 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4923 | print_command_lines (uiout, l, 4); |
3b31d625 | 4924 | do_cleanups (script_chain); |
c4093a6a | 4925 | } |
d24317b4 | 4926 | |
d9b3f62e | 4927 | if (is_tracepoint (b)) |
1042e4c0 | 4928 | { |
d9b3f62e PA |
4929 | struct tracepoint *t = (struct tracepoint *) b; |
4930 | ||
4931 | if (!part_of_multiple && t->pass_count) | |
4932 | { | |
4933 | annotate_field (10); | |
4934 | ui_out_text (uiout, "\tpass count "); | |
4935 | ui_out_field_int (uiout, "pass", t->pass_count); | |
4936 | ui_out_text (uiout, " \n"); | |
4937 | } | |
1042e4c0 SS |
4938 | } |
4939 | ||
d24317b4 VP |
4940 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4941 | { | |
3a5c3e22 PA |
4942 | if (is_watchpoint (b)) |
4943 | { | |
4944 | struct watchpoint *w = (struct watchpoint *) b; | |
4945 | ||
4946 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
4947 | } | |
4948 | else if (b->addr_string) | |
d24317b4 | 4949 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 4950 | } |
c4093a6a | 4951 | } |
c5aa993b | 4952 | |
0d381245 VP |
4953 | static void |
4954 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 4955 | struct bp_location **last_loc, |
6c95b8df | 4956 | int allflag) |
0d381245 | 4957 | { |
8d3788bd | 4958 | struct cleanup *bkpt_chain; |
79a45e25 | 4959 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
4960 | |
4961 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
4962 | ||
12c5a436 | 4963 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 4964 | do_cleanups (bkpt_chain); |
0d381245 VP |
4965 | |
4966 | /* If this breakpoint has custom print function, | |
4967 | it's already printed. Otherwise, print individual | |
4968 | locations, if any. */ | |
4969 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4970 | { | |
4a64f543 MS |
4971 | /* If breakpoint has a single location that is disabled, we |
4972 | print it as if it had several locations, since otherwise it's | |
4973 | hard to represent "breakpoint enabled, location disabled" | |
4974 | situation. | |
4975 | ||
4976 | Note that while hardware watchpoints have several locations | |
a3be7890 | 4977 | internally, that's not a property exposed to user. */ |
0d381245 | 4978 | if (b->loc |
a5606eee | 4979 | && !is_hardware_watchpoint (b) |
8d3788bd | 4980 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
4981 | { |
4982 | struct bp_location *loc; | |
4983 | int n = 1; | |
8d3788bd | 4984 | |
0d381245 | 4985 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
4986 | { |
4987 | struct cleanup *inner2 = | |
4988 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
4989 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
4990 | do_cleanups (inner2); | |
4991 | } | |
0d381245 VP |
4992 | } |
4993 | } | |
4994 | } | |
4995 | ||
a6d9a66e UW |
4996 | static int |
4997 | breakpoint_address_bits (struct breakpoint *b) | |
4998 | { | |
4999 | int print_address_bits = 0; | |
5000 | struct bp_location *loc; | |
5001 | ||
5002 | for (loc = b->loc; loc; loc = loc->next) | |
5003 | { | |
c7437ca6 PA |
5004 | int addr_bit; |
5005 | ||
5006 | /* Software watchpoints that aren't watching memory don't have | |
5007 | an address to print. */ | |
5008 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5009 | continue; | |
5010 | ||
5011 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5012 | if (addr_bit > print_address_bits) |
5013 | print_address_bits = addr_bit; | |
5014 | } | |
5015 | ||
5016 | return print_address_bits; | |
5017 | } | |
0d381245 | 5018 | |
c4093a6a JM |
5019 | struct captured_breakpoint_query_args |
5020 | { | |
5021 | int bnum; | |
5022 | }; | |
c5aa993b | 5023 | |
c4093a6a | 5024 | static int |
2b65245e | 5025 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5026 | { |
5027 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5028 | struct breakpoint *b; |
a6d9a66e | 5029 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5030 | |
c4093a6a JM |
5031 | ALL_BREAKPOINTS (b) |
5032 | { | |
5033 | if (args->bnum == b->number) | |
c5aa993b | 5034 | { |
12c5a436 | 5035 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5036 | return GDB_RC_OK; |
c5aa993b | 5037 | } |
c4093a6a JM |
5038 | } |
5039 | return GDB_RC_NONE; | |
5040 | } | |
c5aa993b | 5041 | |
c4093a6a | 5042 | enum gdb_rc |
4a64f543 MS |
5043 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5044 | char **error_message) | |
c4093a6a JM |
5045 | { |
5046 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5047 | |
c4093a6a JM |
5048 | args.bnum = bnum; |
5049 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5050 | an error. */ |
b0b13bb4 DJ |
5051 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5052 | error_message, RETURN_MASK_ALL) < 0) | |
5053 | return GDB_RC_FAIL; | |
5054 | else | |
5055 | return GDB_RC_OK; | |
c4093a6a | 5056 | } |
c5aa993b | 5057 | |
09d682a4 TT |
5058 | /* Return true if this breakpoint was set by the user, false if it is |
5059 | internal or momentary. */ | |
5060 | ||
5061 | int | |
5062 | user_breakpoint_p (struct breakpoint *b) | |
5063 | { | |
46c6471b | 5064 | return b->number > 0; |
09d682a4 TT |
5065 | } |
5066 | ||
7f3b0473 | 5067 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5068 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5069 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5070 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5071 | ones for which it returns non-zero. Return the total number of | |
5072 | breakpoints listed. */ | |
c906108c | 5073 | |
d77f58be | 5074 | static int |
e5a67952 | 5075 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5076 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5077 | { |
52f0bd74 | 5078 | struct breakpoint *b; |
a6d9a66e | 5079 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5080 | int nr_printable_breakpoints; |
3b31d625 | 5081 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5082 | struct value_print_options opts; |
a6d9a66e | 5083 | int print_address_bits = 0; |
269b11a2 | 5084 | int print_type_col_width = 14; |
79a45e25 | 5085 | struct ui_out *uiout = current_uiout; |
269b11a2 | 5086 | |
79a45b7d TT |
5087 | get_user_print_options (&opts); |
5088 | ||
4a64f543 MS |
5089 | /* Compute the number of rows in the table, as well as the size |
5090 | required for address fields. */ | |
7f3b0473 AC |
5091 | nr_printable_breakpoints = 0; |
5092 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5093 | { |
5094 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5095 | if (filter && !filter (b)) | |
5096 | continue; | |
5097 | ||
5098 | /* If we have an "args" string, it is a list of breakpoints to | |
5099 | accept. Skip the others. */ | |
5100 | if (args != NULL && *args != '\0') | |
5101 | { | |
5102 | if (allflag && parse_and_eval_long (args) != b->number) | |
5103 | continue; | |
5104 | if (!allflag && !number_is_in_list (args, b->number)) | |
5105 | continue; | |
5106 | } | |
269b11a2 | 5107 | |
e5a67952 MS |
5108 | if (allflag || user_breakpoint_p (b)) |
5109 | { | |
5110 | int addr_bit, type_len; | |
a6d9a66e | 5111 | |
e5a67952 MS |
5112 | addr_bit = breakpoint_address_bits (b); |
5113 | if (addr_bit > print_address_bits) | |
5114 | print_address_bits = addr_bit; | |
269b11a2 | 5115 | |
e5a67952 MS |
5116 | type_len = strlen (bptype_string (b->type)); |
5117 | if (type_len > print_type_col_width) | |
5118 | print_type_col_width = type_len; | |
5119 | ||
5120 | nr_printable_breakpoints++; | |
5121 | } | |
5122 | } | |
7f3b0473 | 5123 | |
79a45b7d | 5124 | if (opts.addressprint) |
3b31d625 | 5125 | bkpttbl_chain |
3e43a32a MS |
5126 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5127 | nr_printable_breakpoints, | |
3b31d625 | 5128 | "BreakpointTable"); |
8b93c638 | 5129 | else |
3b31d625 | 5130 | bkpttbl_chain |
3e43a32a MS |
5131 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5132 | nr_printable_breakpoints, | |
3b31d625 | 5133 | "BreakpointTable"); |
8b93c638 | 5134 | |
7f3b0473 | 5135 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5136 | annotate_breakpoints_headers (); |
5137 | if (nr_printable_breakpoints > 0) | |
5138 | annotate_field (0); | |
4a64f543 | 5139 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5140 | if (nr_printable_breakpoints > 0) |
5141 | annotate_field (1); | |
269b11a2 | 5142 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5143 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5144 | if (nr_printable_breakpoints > 0) |
5145 | annotate_field (2); | |
4a64f543 | 5146 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5147 | if (nr_printable_breakpoints > 0) |
5148 | annotate_field (3); | |
54e52265 | 5149 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5150 | if (opts.addressprint) |
e5a67952 MS |
5151 | { |
5152 | if (nr_printable_breakpoints > 0) | |
5153 | annotate_field (4); | |
5154 | if (print_address_bits <= 32) | |
5155 | ui_out_table_header (uiout, 10, ui_left, | |
5156 | "addr", "Address"); /* 5 */ | |
5157 | else | |
5158 | ui_out_table_header (uiout, 18, ui_left, | |
5159 | "addr", "Address"); /* 5 */ | |
5160 | } | |
d7faa9e7 AC |
5161 | if (nr_printable_breakpoints > 0) |
5162 | annotate_field (5); | |
5163 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5164 | ui_out_table_body (uiout); | |
5165 | if (nr_printable_breakpoints > 0) | |
5166 | annotate_breakpoints_table (); | |
7f3b0473 | 5167 | |
c4093a6a | 5168 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5169 | { |
5170 | QUIT; | |
5171 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5172 | if (filter && !filter (b)) | |
5173 | continue; | |
5174 | ||
5175 | /* If we have an "args" string, it is a list of breakpoints to | |
5176 | accept. Skip the others. */ | |
5177 | ||
5178 | if (args != NULL && *args != '\0') | |
5179 | { | |
5180 | if (allflag) /* maintenance info breakpoint */ | |
5181 | { | |
5182 | if (parse_and_eval_long (args) != b->number) | |
5183 | continue; | |
5184 | } | |
5185 | else /* all others */ | |
5186 | { | |
5187 | if (!number_is_in_list (args, b->number)) | |
5188 | continue; | |
5189 | } | |
5190 | } | |
5191 | /* We only print out user settable breakpoints unless the | |
5192 | allflag is set. */ | |
5193 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5194 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5195 | } |
5196 | ||
3b31d625 | 5197 | do_cleanups (bkpttbl_chain); |
698384cd | 5198 | |
7f3b0473 | 5199 | if (nr_printable_breakpoints == 0) |
c906108c | 5200 | { |
4a64f543 MS |
5201 | /* If there's a filter, let the caller decide how to report |
5202 | empty list. */ | |
d77f58be SS |
5203 | if (!filter) |
5204 | { | |
e5a67952 | 5205 | if (args == NULL || *args == '\0') |
d77f58be SS |
5206 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5207 | else | |
4a64f543 | 5208 | ui_out_message (uiout, 0, |
e5a67952 MS |
5209 | "No breakpoint or watchpoint matching '%s'.\n", |
5210 | args); | |
d77f58be | 5211 | } |
c906108c SS |
5212 | } |
5213 | else | |
c4093a6a | 5214 | { |
a6d9a66e UW |
5215 | if (last_loc && !server_command) |
5216 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5217 | } |
c906108c | 5218 | |
4a64f543 | 5219 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5220 | there have been breakpoints? */ |
c906108c | 5221 | annotate_breakpoints_table_end (); |
d77f58be SS |
5222 | |
5223 | return nr_printable_breakpoints; | |
c906108c SS |
5224 | } |
5225 | ||
ad443146 SS |
5226 | /* Display the value of default-collect in a way that is generally |
5227 | compatible with the breakpoint list. */ | |
5228 | ||
5229 | static void | |
5230 | default_collect_info (void) | |
5231 | { | |
79a45e25 PA |
5232 | struct ui_out *uiout = current_uiout; |
5233 | ||
ad443146 SS |
5234 | /* If it has no value (which is frequently the case), say nothing; a |
5235 | message like "No default-collect." gets in user's face when it's | |
5236 | not wanted. */ | |
5237 | if (!*default_collect) | |
5238 | return; | |
5239 | ||
5240 | /* The following phrase lines up nicely with per-tracepoint collect | |
5241 | actions. */ | |
5242 | ui_out_text (uiout, "default collect "); | |
5243 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5244 | ui_out_text (uiout, " \n"); | |
5245 | } | |
5246 | ||
c906108c | 5247 | static void |
e5a67952 | 5248 | breakpoints_info (char *args, int from_tty) |
c906108c | 5249 | { |
e5a67952 | 5250 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5251 | |
5252 | default_collect_info (); | |
d77f58be SS |
5253 | } |
5254 | ||
5255 | static void | |
e5a67952 | 5256 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5257 | { |
e5a67952 | 5258 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 5259 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
5260 | |
5261 | if (num_printed == 0) | |
5262 | { | |
e5a67952 | 5263 | if (args == NULL || *args == '\0') |
d77f58be SS |
5264 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5265 | else | |
e5a67952 | 5266 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5267 | } |
c906108c SS |
5268 | } |
5269 | ||
7a292a7a | 5270 | static void |
e5a67952 | 5271 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5272 | { |
e5a67952 | 5273 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5274 | |
5275 | default_collect_info (); | |
c906108c SS |
5276 | } |
5277 | ||
0d381245 | 5278 | static int |
714835d5 | 5279 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5280 | struct program_space *pspace, |
714835d5 | 5281 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5282 | { |
5283 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5284 | |
0d381245 VP |
5285 | for (; bl; bl = bl->next) |
5286 | { | |
6c95b8df PA |
5287 | if (bl->pspace == pspace |
5288 | && bl->address == pc | |
0d381245 VP |
5289 | && (!overlay_debugging || bl->section == section)) |
5290 | return 1; | |
5291 | } | |
5292 | return 0; | |
5293 | } | |
5294 | ||
672f9b60 | 5295 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
5296 | concerns with logical breakpoints, so we match program spaces, not |
5297 | address spaces. */ | |
c906108c SS |
5298 | |
5299 | static void | |
6c95b8df PA |
5300 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5301 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5302 | struct obj_section *section, int thread) |
c906108c | 5303 | { |
52f0bd74 AC |
5304 | int others = 0; |
5305 | struct breakpoint *b; | |
c906108c SS |
5306 | |
5307 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
5308 | others += (user_breakpoint_p (b) |
5309 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
5310 | if (others > 0) |
5311 | { | |
a3f17187 AC |
5312 | if (others == 1) |
5313 | printf_filtered (_("Note: breakpoint ")); | |
5314 | else /* if (others == ???) */ | |
5315 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5316 | ALL_BREAKPOINTS (b) |
672f9b60 | 5317 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5318 | { |
5319 | others--; | |
5320 | printf_filtered ("%d", b->number); | |
5321 | if (b->thread == -1 && thread != -1) | |
5322 | printf_filtered (" (all threads)"); | |
5323 | else if (b->thread != -1) | |
5324 | printf_filtered (" (thread %d)", b->thread); | |
5325 | printf_filtered ("%s%s ", | |
059fb39f | 5326 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5327 | || b->enable_state == bp_call_disabled |
5328 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5329 | ? " (disabled)" |
5330 | : b->enable_state == bp_permanent | |
5331 | ? " (permanent)" | |
5332 | : ""), | |
5333 | (others > 1) ? "," | |
5334 | : ((others == 1) ? " and" : "")); | |
5335 | } | |
a3f17187 | 5336 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5337 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5338 | printf_filtered (".\n"); |
5339 | } | |
5340 | } | |
5341 | \f | |
5342 | /* Set the default place to put a breakpoint | |
5343 | for the `break' command with no arguments. */ | |
5344 | ||
5345 | void | |
6c95b8df PA |
5346 | set_default_breakpoint (int valid, struct program_space *pspace, |
5347 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5348 | int line) |
c906108c SS |
5349 | { |
5350 | default_breakpoint_valid = valid; | |
6c95b8df | 5351 | default_breakpoint_pspace = pspace; |
c906108c SS |
5352 | default_breakpoint_address = addr; |
5353 | default_breakpoint_symtab = symtab; | |
5354 | default_breakpoint_line = line; | |
5355 | } | |
5356 | ||
e4f237da KB |
5357 | /* Return true iff it is meaningful to use the address member of |
5358 | BPT. For some breakpoint types, the address member is irrelevant | |
5359 | and it makes no sense to attempt to compare it to other addresses | |
5360 | (or use it for any other purpose either). | |
5361 | ||
4a64f543 MS |
5362 | More specifically, each of the following breakpoint types will |
5363 | always have a zero valued address and we don't want to mark | |
5364 | breakpoints of any of these types to be a duplicate of an actual | |
5365 | breakpoint at address zero: | |
e4f237da KB |
5366 | |
5367 | bp_watchpoint | |
2d134ed3 PA |
5368 | bp_catchpoint |
5369 | ||
5370 | */ | |
e4f237da KB |
5371 | |
5372 | static int | |
5373 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5374 | { | |
5375 | enum bptype type = bpt->type; | |
5376 | ||
2d134ed3 PA |
5377 | return (type != bp_watchpoint && type != bp_catchpoint); |
5378 | } | |
5379 | ||
5380 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5381 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5382 | ||
5383 | static int | |
4a64f543 MS |
5384 | watchpoint_locations_match (struct bp_location *loc1, |
5385 | struct bp_location *loc2) | |
2d134ed3 | 5386 | { |
3a5c3e22 PA |
5387 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
5388 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
5389 | ||
5390 | /* Both of them must exist. */ | |
5391 | gdb_assert (w1 != NULL); | |
5392 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 5393 | |
4a64f543 MS |
5394 | /* If the target can evaluate the condition expression in hardware, |
5395 | then we we need to insert both watchpoints even if they are at | |
5396 | the same place. Otherwise the watchpoint will only trigger when | |
5397 | the condition of whichever watchpoint was inserted evaluates to | |
5398 | true, not giving a chance for GDB to check the condition of the | |
5399 | other watchpoint. */ | |
3a5c3e22 | 5400 | if ((w1->cond_exp |
4a64f543 MS |
5401 | && target_can_accel_watchpoint_condition (loc1->address, |
5402 | loc1->length, | |
0cf6dd15 | 5403 | loc1->watchpoint_type, |
3a5c3e22 PA |
5404 | w1->cond_exp)) |
5405 | || (w2->cond_exp | |
4a64f543 MS |
5406 | && target_can_accel_watchpoint_condition (loc2->address, |
5407 | loc2->length, | |
0cf6dd15 | 5408 | loc2->watchpoint_type, |
3a5c3e22 | 5409 | w2->cond_exp))) |
0cf6dd15 TJB |
5410 | return 0; |
5411 | ||
85d721b8 PA |
5412 | /* Note that this checks the owner's type, not the location's. In |
5413 | case the target does not support read watchpoints, but does | |
5414 | support access watchpoints, we'll have bp_read_watchpoint | |
5415 | watchpoints with hw_access locations. Those should be considered | |
5416 | duplicates of hw_read locations. The hw_read locations will | |
5417 | become hw_access locations later. */ | |
2d134ed3 PA |
5418 | return (loc1->owner->type == loc2->owner->type |
5419 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5420 | && loc1->address == loc2->address | |
5421 | && loc1->length == loc2->length); | |
e4f237da KB |
5422 | } |
5423 | ||
6c95b8df PA |
5424 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5425 | same breakpoint location. In most targets, this can only be true | |
5426 | if ASPACE1 matches ASPACE2. On targets that have global | |
5427 | breakpoints, the address space doesn't really matter. */ | |
5428 | ||
5429 | static int | |
5430 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5431 | struct address_space *aspace2, CORE_ADDR addr2) | |
5432 | { | |
5433 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5434 | || aspace1 == aspace2) | |
5435 | && addr1 == addr2); | |
5436 | } | |
5437 | ||
f1310107 TJB |
5438 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
5439 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
5440 | matches ASPACE2. On targets that have global breakpoints, the address | |
5441 | space doesn't really matter. */ | |
5442 | ||
5443 | static int | |
5444 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
5445 | int len1, struct address_space *aspace2, | |
5446 | CORE_ADDR addr2) | |
5447 | { | |
5448 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5449 | || aspace1 == aspace2) | |
5450 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
5451 | } | |
5452 | ||
5453 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
5454 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
5455 | matches the breakpoint's address space. On targets that have global | |
5456 | breakpoints, the address space doesn't really matter. */ | |
5457 | ||
5458 | static int | |
5459 | breakpoint_location_address_match (struct bp_location *bl, | |
5460 | struct address_space *aspace, | |
5461 | CORE_ADDR addr) | |
5462 | { | |
5463 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
5464 | aspace, addr) | |
5465 | || (bl->length | |
5466 | && breakpoint_address_match_range (bl->pspace->aspace, | |
5467 | bl->address, bl->length, | |
5468 | aspace, addr))); | |
5469 | } | |
5470 | ||
2d134ed3 PA |
5471 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5472 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5473 | represent the same location. */ | |
5474 | ||
5475 | static int | |
4a64f543 MS |
5476 | breakpoint_locations_match (struct bp_location *loc1, |
5477 | struct bp_location *loc2) | |
2d134ed3 | 5478 | { |
2bdf28a0 JK |
5479 | int hw_point1, hw_point2; |
5480 | ||
5481 | /* Both of them must not be in moribund_locations. */ | |
5482 | gdb_assert (loc1->owner != NULL); | |
5483 | gdb_assert (loc2->owner != NULL); | |
5484 | ||
5485 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5486 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5487 | |
5488 | if (hw_point1 != hw_point2) | |
5489 | return 0; | |
5490 | else if (hw_point1) | |
5491 | return watchpoint_locations_match (loc1, loc2); | |
5492 | else | |
f1310107 TJB |
5493 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
5494 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5495 | loc2->pspace->aspace, loc2->address) | |
5496 | && loc1->length == loc2->length); | |
2d134ed3 PA |
5497 | } |
5498 | ||
76897487 KB |
5499 | static void |
5500 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5501 | int bnum, int have_bnum) | |
5502 | { | |
f63fbe86 MS |
5503 | /* The longest string possibly returned by hex_string_custom |
5504 | is 50 chars. These must be at least that big for safety. */ | |
5505 | char astr1[64]; | |
5506 | char astr2[64]; | |
76897487 | 5507 | |
bb599908 PH |
5508 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5509 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5510 | if (have_bnum) |
8a3fe4f8 | 5511 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5512 | bnum, astr1, astr2); |
5513 | else | |
8a3fe4f8 | 5514 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5515 | } |
5516 | ||
4a64f543 MS |
5517 | /* Adjust a breakpoint's address to account for architectural |
5518 | constraints on breakpoint placement. Return the adjusted address. | |
5519 | Note: Very few targets require this kind of adjustment. For most | |
5520 | targets, this function is simply the identity function. */ | |
76897487 KB |
5521 | |
5522 | static CORE_ADDR | |
a6d9a66e UW |
5523 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5524 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5525 | { |
a6d9a66e | 5526 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5527 | { |
5528 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5529 | return bpaddr; | |
5530 | } | |
88f7da05 KB |
5531 | else if (bptype == bp_watchpoint |
5532 | || bptype == bp_hardware_watchpoint | |
5533 | || bptype == bp_read_watchpoint | |
5534 | || bptype == bp_access_watchpoint | |
fe798b75 | 5535 | || bptype == bp_catchpoint) |
88f7da05 KB |
5536 | { |
5537 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5538 | have their addresses modified. */ | |
5539 | return bpaddr; | |
5540 | } | |
76897487 KB |
5541 | else |
5542 | { | |
5543 | CORE_ADDR adjusted_bpaddr; | |
5544 | ||
5545 | /* Some targets have architectural constraints on the placement | |
5546 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5547 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5548 | |
5549 | /* An adjusted breakpoint address can significantly alter | |
5550 | a user's expectations. Print a warning if an adjustment | |
5551 | is required. */ | |
5552 | if (adjusted_bpaddr != bpaddr) | |
5553 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5554 | ||
5555 | return adjusted_bpaddr; | |
5556 | } | |
5557 | } | |
5558 | ||
28010a5d PA |
5559 | void |
5560 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
5561 | struct breakpoint *owner) | |
7cc221ef | 5562 | { |
7cc221ef DJ |
5563 | memset (loc, 0, sizeof (*loc)); |
5564 | ||
348d480f PA |
5565 | gdb_assert (ops != NULL); |
5566 | ||
28010a5d PA |
5567 | loc->ops = ops; |
5568 | loc->owner = owner; | |
511a6cd4 | 5569 | loc->cond = NULL; |
0d381245 VP |
5570 | loc->shlib_disabled = 0; |
5571 | loc->enabled = 1; | |
e049a4b5 | 5572 | |
28010a5d | 5573 | switch (owner->type) |
e049a4b5 DJ |
5574 | { |
5575 | case bp_breakpoint: | |
5576 | case bp_until: | |
5577 | case bp_finish: | |
5578 | case bp_longjmp: | |
5579 | case bp_longjmp_resume: | |
186c406b TT |
5580 | case bp_exception: |
5581 | case bp_exception_resume: | |
e049a4b5 | 5582 | case bp_step_resume: |
2c03e5be | 5583 | case bp_hp_step_resume: |
e049a4b5 DJ |
5584 | case bp_watchpoint_scope: |
5585 | case bp_call_dummy: | |
aa7d318d | 5586 | case bp_std_terminate: |
e049a4b5 DJ |
5587 | case bp_shlib_event: |
5588 | case bp_thread_event: | |
5589 | case bp_overlay_event: | |
4efc6507 | 5590 | case bp_jit_event: |
0fd8e87f | 5591 | case bp_longjmp_master: |
aa7d318d | 5592 | case bp_std_terminate_master: |
186c406b | 5593 | case bp_exception_master: |
0e30163f JK |
5594 | case bp_gnu_ifunc_resolver: |
5595 | case bp_gnu_ifunc_resolver_return: | |
e049a4b5 DJ |
5596 | loc->loc_type = bp_loc_software_breakpoint; |
5597 | break; | |
5598 | case bp_hardware_breakpoint: | |
5599 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5600 | break; | |
5601 | case bp_hardware_watchpoint: | |
5602 | case bp_read_watchpoint: | |
5603 | case bp_access_watchpoint: | |
5604 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5605 | break; | |
5606 | case bp_watchpoint: | |
ce78b96d | 5607 | case bp_catchpoint: |
15c3d785 PA |
5608 | case bp_tracepoint: |
5609 | case bp_fast_tracepoint: | |
0fb4aa4b | 5610 | case bp_static_tracepoint: |
e049a4b5 DJ |
5611 | loc->loc_type = bp_loc_other; |
5612 | break; | |
5613 | default: | |
e2e0b3e5 | 5614 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5615 | } |
5616 | ||
f431efe5 | 5617 | loc->refc = 1; |
28010a5d PA |
5618 | } |
5619 | ||
5620 | /* Allocate a struct bp_location. */ | |
5621 | ||
5622 | static struct bp_location * | |
5623 | allocate_bp_location (struct breakpoint *bpt) | |
5624 | { | |
348d480f PA |
5625 | return bpt->ops->allocate_location (bpt); |
5626 | } | |
7cc221ef | 5627 | |
f431efe5 PA |
5628 | static void |
5629 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 5630 | { |
348d480f | 5631 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
5632 | xfree (loc); |
5633 | } | |
5634 | ||
f431efe5 PA |
5635 | /* Increment reference count. */ |
5636 | ||
5637 | static void | |
5638 | incref_bp_location (struct bp_location *bl) | |
5639 | { | |
5640 | ++bl->refc; | |
5641 | } | |
5642 | ||
5643 | /* Decrement reference count. If the reference count reaches 0, | |
5644 | destroy the bp_location. Sets *BLP to NULL. */ | |
5645 | ||
5646 | static void | |
5647 | decref_bp_location (struct bp_location **blp) | |
5648 | { | |
0807b50c PA |
5649 | gdb_assert ((*blp)->refc > 0); |
5650 | ||
f431efe5 PA |
5651 | if (--(*blp)->refc == 0) |
5652 | free_bp_location (*blp); | |
5653 | *blp = NULL; | |
5654 | } | |
5655 | ||
346774a9 | 5656 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 5657 | |
346774a9 PA |
5658 | static void |
5659 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 5660 | { |
346774a9 | 5661 | struct breakpoint *b1; |
c906108c | 5662 | |
346774a9 PA |
5663 | /* Add this breakpoint to the end of the chain so that a list of |
5664 | breakpoints will come out in order of increasing numbers. */ | |
5665 | ||
5666 | b1 = breakpoint_chain; | |
5667 | if (b1 == 0) | |
5668 | breakpoint_chain = b; | |
5669 | else | |
5670 | { | |
5671 | while (b1->next) | |
5672 | b1 = b1->next; | |
5673 | b1->next = b; | |
5674 | } | |
5675 | } | |
5676 | ||
5677 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
5678 | ||
5679 | static void | |
5680 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
5681 | struct gdbarch *gdbarch, | |
28010a5d | 5682 | enum bptype bptype, |
c0a91b2b | 5683 | const struct breakpoint_ops *ops) |
346774a9 | 5684 | { |
c906108c | 5685 | memset (b, 0, sizeof (*b)); |
2219d63c | 5686 | |
348d480f PA |
5687 | gdb_assert (ops != NULL); |
5688 | ||
28010a5d | 5689 | b->ops = ops; |
4d28f7a8 | 5690 | b->type = bptype; |
a6d9a66e | 5691 | b->gdbarch = gdbarch; |
c906108c SS |
5692 | b->language = current_language->la_language; |
5693 | b->input_radix = input_radix; | |
5694 | b->thread = -1; | |
b5de0fa7 | 5695 | b->enable_state = bp_enabled; |
c906108c SS |
5696 | b->next = 0; |
5697 | b->silent = 0; | |
5698 | b->ignore_count = 0; | |
5699 | b->commands = NULL; | |
818dd999 | 5700 | b->frame_id = null_frame_id; |
0d381245 | 5701 | b->condition_not_parsed = 0; |
84f4c1fe | 5702 | b->py_bp_object = NULL; |
d0fb5eae | 5703 | b->related_breakpoint = b; |
346774a9 PA |
5704 | } |
5705 | ||
5706 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
5707 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
5708 | |
5709 | static struct breakpoint * | |
5710 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 5711 | enum bptype bptype, |
c0a91b2b | 5712 | const struct breakpoint_ops *ops) |
346774a9 PA |
5713 | { |
5714 | struct breakpoint *b = XNEW (struct breakpoint); | |
5715 | ||
348d480f | 5716 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 5717 | add_to_breakpoint_chain (b); |
0d381245 VP |
5718 | return b; |
5719 | } | |
5720 | ||
0e30163f JK |
5721 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
5722 | resolutions should be made as the user specified the location explicitly | |
5723 | enough. */ | |
5724 | ||
0d381245 | 5725 | static void |
0e30163f | 5726 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 5727 | { |
2bdf28a0 JK |
5728 | gdb_assert (loc->owner != NULL); |
5729 | ||
0d381245 | 5730 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5731 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5732 | || is_tracepoint (loc->owner)) |
0d381245 | 5733 | { |
0e30163f JK |
5734 | int is_gnu_ifunc; |
5735 | ||
5736 | find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name, | |
5737 | NULL, NULL, &is_gnu_ifunc); | |
5738 | ||
5739 | if (is_gnu_ifunc && !explicit_loc) | |
5740 | { | |
5741 | struct breakpoint *b = loc->owner; | |
5742 | ||
5743 | gdb_assert (loc->pspace == current_program_space); | |
5744 | if (gnu_ifunc_resolve_name (loc->function_name, | |
5745 | &loc->requested_address)) | |
5746 | { | |
5747 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
5748 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
5749 | loc->requested_address, | |
5750 | b->type); | |
5751 | } | |
5752 | else if (b->type == bp_breakpoint && b->loc == loc | |
5753 | && loc->next == NULL && b->related_breakpoint == b) | |
5754 | { | |
5755 | /* Create only the whole new breakpoint of this type but do not | |
5756 | mess more complicated breakpoints with multiple locations. */ | |
5757 | b->type = bp_gnu_ifunc_resolver; | |
5758 | } | |
5759 | } | |
5760 | ||
0d381245 VP |
5761 | if (loc->function_name) |
5762 | loc->function_name = xstrdup (loc->function_name); | |
5763 | } | |
5764 | } | |
5765 | ||
a6d9a66e UW |
5766 | /* Attempt to determine architecture of location identified by SAL. */ |
5767 | static struct gdbarch * | |
5768 | get_sal_arch (struct symtab_and_line sal) | |
5769 | { | |
5770 | if (sal.section) | |
5771 | return get_objfile_arch (sal.section->objfile); | |
5772 | if (sal.symtab) | |
5773 | return get_objfile_arch (sal.symtab->objfile); | |
5774 | ||
5775 | return NULL; | |
5776 | } | |
5777 | ||
346774a9 PA |
5778 | /* Low level routine for partially initializing a breakpoint of type |
5779 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 5780 | file name, and line number are provided by SAL. |
0d381245 VP |
5781 | |
5782 | It is expected that the caller will complete the initialization of | |
5783 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 5784 | information regarding the creation of a new breakpoint. */ |
0d381245 | 5785 | |
346774a9 PA |
5786 | static void |
5787 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 5788 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5789 | const struct breakpoint_ops *ops) |
0d381245 | 5790 | { |
0d381245 | 5791 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5792 | struct gdbarch *loc_gdbarch; |
5793 | ||
28010a5d | 5794 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 5795 | |
a6d9a66e UW |
5796 | loc_gdbarch = get_sal_arch (sal); |
5797 | if (!loc_gdbarch) | |
5798 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5799 | |
6c95b8df PA |
5800 | if (bptype != bp_catchpoint) |
5801 | gdb_assert (sal.pspace != NULL); | |
5802 | ||
0d381245 VP |
5803 | /* Adjust the breakpoint's address prior to allocating a location. |
5804 | Once we call allocate_bp_location(), that mostly uninitialized | |
5805 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5806 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5807 | not want its scan of the location chain to find a breakpoint and |
5808 | location that's only been partially initialized. */ | |
4a64f543 MS |
5809 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
5810 | sal.pc, b->type); | |
0d381245 | 5811 | |
39d61571 | 5812 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5813 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5814 | b->loc->requested_address = sal.pc; |
5815 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5816 | b->loc->pspace = sal.pspace; |
5817 | ||
5818 | /* Store the program space that was used to set the breakpoint, for | |
5819 | breakpoint resetting. */ | |
5820 | b->pspace = sal.pspace; | |
0d381245 VP |
5821 | |
5822 | if (sal.symtab == NULL) | |
5823 | b->source_file = NULL; | |
5824 | else | |
1b36a34b | 5825 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5826 | b->loc->section = sal.section; |
5827 | b->line_number = sal.line; | |
5828 | ||
0e30163f JK |
5829 | set_breakpoint_location_function (b->loc, |
5830 | sal.explicit_pc || sal.explicit_line); | |
c906108c | 5831 | |
c906108c | 5832 | breakpoints_changed (); |
346774a9 | 5833 | } |
c906108c | 5834 | |
346774a9 PA |
5835 | /* set_raw_breakpoint is a low level routine for allocating and |
5836 | partially initializing a breakpoint of type BPTYPE. The newly | |
5837 | created breakpoint's address, section, source file name, and line | |
5838 | number are provided by SAL. The newly created and partially | |
5839 | initialized breakpoint is added to the breakpoint chain and | |
5840 | is also returned as the value of this function. | |
5841 | ||
5842 | It is expected that the caller will complete the initialization of | |
5843 | the newly created breakpoint struct as well as output any status | |
5844 | information regarding the creation of a new breakpoint. In | |
5845 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5846 | number! Care should be taken to not allow an error to occur | |
5847 | prior to completing the initialization of the breakpoint. If this | |
5848 | should happen, a bogus breakpoint will be left on the chain. */ | |
5849 | ||
5850 | struct breakpoint * | |
5851 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 5852 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5853 | const struct breakpoint_ops *ops) |
346774a9 PA |
5854 | { |
5855 | struct breakpoint *b = XNEW (struct breakpoint); | |
5856 | ||
348d480f | 5857 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 5858 | add_to_breakpoint_chain (b); |
c906108c SS |
5859 | return b; |
5860 | } | |
5861 | ||
c2c6d25f JM |
5862 | |
5863 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5864 | instruction, hard-wired into the inferior's code. */ | |
5865 | void | |
5866 | make_breakpoint_permanent (struct breakpoint *b) | |
5867 | { | |
0d381245 | 5868 | struct bp_location *bl; |
cc59ec59 | 5869 | |
b5de0fa7 | 5870 | b->enable_state = bp_permanent; |
c2c6d25f | 5871 | |
4a64f543 MS |
5872 | /* By definition, permanent breakpoints are already present in the |
5873 | code. Mark all locations as inserted. For now, | |
5874 | make_breakpoint_permanent is called in just one place, so it's | |
5875 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 5876 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
5877 | for (bl = b->loc; bl; bl = bl->next) |
5878 | bl->inserted = 1; | |
c2c6d25f JM |
5879 | } |
5880 | ||
53a5351d | 5881 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5882 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5883 | initiated the operation. */ | |
c906108c SS |
5884 | |
5885 | void | |
186c406b | 5886 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5887 | { |
35df4500 | 5888 | struct breakpoint *b, *b_tmp; |
186c406b | 5889 | int thread = tp->num; |
0fd8e87f UW |
5890 | |
5891 | /* To avoid having to rescan all objfile symbols at every step, | |
5892 | we maintain a list of continually-inserted but always disabled | |
5893 | longjmp "master" breakpoints. Here, we simply create momentary | |
5894 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5895 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5896 | if (b->pspace == current_program_space |
186c406b TT |
5897 | && (b->type == bp_longjmp_master |
5898 | || b->type == bp_exception_master)) | |
0fd8e87f | 5899 | { |
06edf0c0 PA |
5900 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
5901 | struct breakpoint *clone; | |
cc59ec59 | 5902 | |
06edf0c0 PA |
5903 | clone = momentary_breakpoint_from_master (b, type, |
5904 | &momentary_breakpoint_ops); | |
0fd8e87f UW |
5905 | clone->thread = thread; |
5906 | } | |
186c406b TT |
5907 | |
5908 | tp->initiating_frame = frame; | |
c906108c SS |
5909 | } |
5910 | ||
611c83ae | 5911 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5912 | void |
611c83ae | 5913 | delete_longjmp_breakpoint (int thread) |
c906108c | 5914 | { |
35df4500 | 5915 | struct breakpoint *b, *b_tmp; |
c906108c | 5916 | |
35df4500 | 5917 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 5918 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
5919 | { |
5920 | if (b->thread == thread) | |
5921 | delete_breakpoint (b); | |
5922 | } | |
c906108c SS |
5923 | } |
5924 | ||
1900040c MS |
5925 | void |
5926 | enable_overlay_breakpoints (void) | |
5927 | { | |
52f0bd74 | 5928 | struct breakpoint *b; |
1900040c MS |
5929 | |
5930 | ALL_BREAKPOINTS (b) | |
5931 | if (b->type == bp_overlay_event) | |
5932 | { | |
5933 | b->enable_state = bp_enabled; | |
b60e7edf | 5934 | update_global_location_list (1); |
c02f5703 | 5935 | overlay_events_enabled = 1; |
1900040c MS |
5936 | } |
5937 | } | |
5938 | ||
5939 | void | |
5940 | disable_overlay_breakpoints (void) | |
5941 | { | |
52f0bd74 | 5942 | struct breakpoint *b; |
1900040c MS |
5943 | |
5944 | ALL_BREAKPOINTS (b) | |
5945 | if (b->type == bp_overlay_event) | |
5946 | { | |
5947 | b->enable_state = bp_disabled; | |
b60e7edf | 5948 | update_global_location_list (0); |
c02f5703 | 5949 | overlay_events_enabled = 0; |
1900040c MS |
5950 | } |
5951 | } | |
5952 | ||
aa7d318d TT |
5953 | /* Set an active std::terminate breakpoint for each std::terminate |
5954 | master breakpoint. */ | |
5955 | void | |
5956 | set_std_terminate_breakpoint (void) | |
5957 | { | |
35df4500 | 5958 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5959 | |
35df4500 | 5960 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5961 | if (b->pspace == current_program_space |
5962 | && b->type == bp_std_terminate_master) | |
5963 | { | |
06edf0c0 PA |
5964 | momentary_breakpoint_from_master (b, bp_std_terminate, |
5965 | &momentary_breakpoint_ops); | |
aa7d318d TT |
5966 | } |
5967 | } | |
5968 | ||
5969 | /* Delete all the std::terminate breakpoints. */ | |
5970 | void | |
5971 | delete_std_terminate_breakpoint (void) | |
5972 | { | |
35df4500 | 5973 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5974 | |
35df4500 | 5975 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5976 | if (b->type == bp_std_terminate) |
5977 | delete_breakpoint (b); | |
5978 | } | |
5979 | ||
c4093a6a | 5980 | struct breakpoint * |
a6d9a66e | 5981 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5982 | { |
5983 | struct breakpoint *b; | |
c4093a6a | 5984 | |
06edf0c0 PA |
5985 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
5986 | &internal_breakpoint_ops); | |
5987 | ||
b5de0fa7 | 5988 | b->enable_state = bp_enabled; |
c4093a6a | 5989 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5990 | b->addr_string |
5991 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5992 | |
b60e7edf | 5993 | update_global_location_list_nothrow (1); |
74960c60 | 5994 | |
c4093a6a JM |
5995 | return b; |
5996 | } | |
5997 | ||
5998 | void | |
5999 | remove_thread_event_breakpoints (void) | |
6000 | { | |
35df4500 | 6001 | struct breakpoint *b, *b_tmp; |
c4093a6a | 6002 | |
35df4500 | 6003 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6004 | if (b->type == bp_thread_event |
6005 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
6006 | delete_breakpoint (b); |
6007 | } | |
6008 | ||
0101ce28 JJ |
6009 | struct lang_and_radix |
6010 | { | |
6011 | enum language lang; | |
6012 | int radix; | |
6013 | }; | |
6014 | ||
4efc6507 DE |
6015 | /* Create a breakpoint for JIT code registration and unregistration. */ |
6016 | ||
6017 | struct breakpoint * | |
6018 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
6019 | { | |
6020 | struct breakpoint *b; | |
6021 | ||
06edf0c0 PA |
6022 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
6023 | &internal_breakpoint_ops); | |
4efc6507 DE |
6024 | update_global_location_list_nothrow (1); |
6025 | return b; | |
6026 | } | |
0101ce28 | 6027 | |
03673fc7 PP |
6028 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
6029 | ||
6030 | void | |
6031 | remove_jit_event_breakpoints (void) | |
6032 | { | |
6033 | struct breakpoint *b, *b_tmp; | |
6034 | ||
6035 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6036 | if (b->type == bp_jit_event | |
6037 | && b->loc->pspace == current_program_space) | |
6038 | delete_breakpoint (b); | |
6039 | } | |
6040 | ||
cae688ec JJ |
6041 | void |
6042 | remove_solib_event_breakpoints (void) | |
6043 | { | |
35df4500 | 6044 | struct breakpoint *b, *b_tmp; |
cae688ec | 6045 | |
35df4500 | 6046 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6047 | if (b->type == bp_shlib_event |
6048 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6049 | delete_breakpoint (b); |
6050 | } | |
6051 | ||
6052 | struct breakpoint * | |
a6d9a66e | 6053 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6054 | { |
6055 | struct breakpoint *b; | |
6056 | ||
06edf0c0 PA |
6057 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
6058 | &internal_breakpoint_ops); | |
b60e7edf | 6059 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6060 | return b; |
6061 | } | |
6062 | ||
6063 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6064 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6065 | ||
6066 | void | |
cb851954 | 6067 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6068 | { |
876fa593 | 6069 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6070 | |
876fa593 | 6071 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6072 | { |
2bdf28a0 | 6073 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6074 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6075 | |
4a64f543 MS |
6076 | /* We apply the check to all breakpoints, including disabled for |
6077 | those with loc->duplicate set. This is so that when breakpoint | |
6078 | becomes enabled, or the duplicate is removed, gdb will try to | |
6079 | insert all breakpoints. If we don't set shlib_disabled here, | |
6080 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6081 | if (((b->type == bp_breakpoint) |
508ccb1f | 6082 | || (b->type == bp_jit_event) |
1042e4c0 | 6083 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6084 | || (is_tracepoint (b))) |
6c95b8df | 6085 | && loc->pspace == current_program_space |
0d381245 | 6086 | && !loc->shlib_disabled |
a77053c2 | 6087 | #ifdef PC_SOLIB |
0d381245 | 6088 | && PC_SOLIB (loc->address) |
a77053c2 | 6089 | #else |
6c95b8df | 6090 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6091 | #endif |
6092 | ) | |
0d381245 VP |
6093 | { |
6094 | loc->shlib_disabled = 1; | |
6095 | } | |
cae688ec JJ |
6096 | } |
6097 | } | |
6098 | ||
7a9dd1b2 | 6099 | /* Disable any breakpoints that are in an unloaded shared library. |
4a64f543 MS |
6100 | Only apply to enabled breakpoints, disabled ones can just stay |
6101 | disabled. */ | |
84acb35a | 6102 | |
75149521 | 6103 | static void |
84acb35a JJ |
6104 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6105 | { | |
876fa593 | 6106 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6107 | int disabled_shlib_breaks = 0; |
6108 | ||
c86cf029 VP |
6109 | /* SunOS a.out shared libraries are always mapped, so do not |
6110 | disable breakpoints; they will only be reported as unloaded | |
6111 | through clear_solib when GDB discards its shared library | |
6112 | list. See clear_solib for more information. */ | |
6113 | if (exec_bfd != NULL | |
6114 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6115 | return; | |
6116 | ||
876fa593 | 6117 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6118 | { |
2bdf28a0 | 6119 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6120 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6121 | |
0d381245 VP |
6122 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
6123 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 6124 | && solib->pspace == loc->pspace |
e2dd7057 | 6125 | && !loc->shlib_disabled |
508ccb1f TT |
6126 | && (b->type == bp_breakpoint |
6127 | || b->type == bp_jit_event | |
6128 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 6129 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6130 | { |
e2dd7057 PP |
6131 | loc->shlib_disabled = 1; |
6132 | /* At this point, we cannot rely on remove_breakpoint | |
6133 | succeeding so we must mark the breakpoint as not inserted | |
6134 | to prevent future errors occurring in remove_breakpoints. */ | |
6135 | loc->inserted = 0; | |
8d3788bd VP |
6136 | |
6137 | /* This may cause duplicate notifications for the same breakpoint. */ | |
6138 | observer_notify_breakpoint_modified (b); | |
6139 | ||
e2dd7057 PP |
6140 | if (!disabled_shlib_breaks) |
6141 | { | |
6142 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6143 | warning (_("Temporarily disabling breakpoints " |
6144 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6145 | solib->so_name); |
84acb35a | 6146 | } |
e2dd7057 | 6147 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6148 | } |
6149 | } | |
84acb35a JJ |
6150 | } |
6151 | ||
ce78b96d JB |
6152 | /* FORK & VFORK catchpoints. */ |
6153 | ||
e29a4733 PA |
6154 | /* An instance of this type is used to represent a fork or vfork |
6155 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
6156 | class; users downcast to "struct breakpoint *" when needed. A | |
6157 | breakpoint is really of this type iff its ops pointer points to | |
6158 | CATCH_FORK_BREAKPOINT_OPS. */ | |
6159 | ||
6160 | struct fork_catchpoint | |
6161 | { | |
6162 | /* The base class. */ | |
6163 | struct breakpoint base; | |
6164 | ||
6165 | /* Process id of a child process whose forking triggered this | |
6166 | catchpoint. This field is only valid immediately after this | |
6167 | catchpoint has triggered. */ | |
6168 | ptid_t forked_inferior_pid; | |
6169 | }; | |
6170 | ||
4a64f543 MS |
6171 | /* Implement the "insert" breakpoint_ops method for fork |
6172 | catchpoints. */ | |
ce78b96d | 6173 | |
77b06cd7 TJB |
6174 | static int |
6175 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6176 | { |
77b06cd7 | 6177 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6178 | } |
6179 | ||
4a64f543 MS |
6180 | /* Implement the "remove" breakpoint_ops method for fork |
6181 | catchpoints. */ | |
ce78b96d JB |
6182 | |
6183 | static int | |
77b06cd7 | 6184 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6185 | { |
6186 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6187 | } | |
6188 | ||
6189 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6190 | catchpoints. */ | |
6191 | ||
6192 | static int | |
f1310107 TJB |
6193 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
6194 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6195 | { |
e29a4733 PA |
6196 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6197 | ||
6198 | return inferior_has_forked (inferior_ptid, &c->forked_inferior_pid); | |
ce78b96d JB |
6199 | } |
6200 | ||
4a64f543 MS |
6201 | /* Implement the "print_it" breakpoint_ops method for fork |
6202 | catchpoints. */ | |
ce78b96d JB |
6203 | |
6204 | static enum print_stop_action | |
348d480f | 6205 | print_it_catch_fork (bpstat bs) |
ce78b96d | 6206 | { |
348d480f PA |
6207 | struct breakpoint *b = bs->breakpoint_at; |
6208 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 6209 | |
ce78b96d JB |
6210 | annotate_catchpoint (b->number); |
6211 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
e29a4733 | 6212 | b->number, ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6213 | return PRINT_SRC_AND_LOC; |
6214 | } | |
6215 | ||
4a64f543 MS |
6216 | /* Implement the "print_one" breakpoint_ops method for fork |
6217 | catchpoints. */ | |
ce78b96d JB |
6218 | |
6219 | static void | |
a6d9a66e | 6220 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6221 | { |
e29a4733 | 6222 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6223 | struct value_print_options opts; |
79a45e25 | 6224 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6225 | |
6226 | get_user_print_options (&opts); | |
6227 | ||
4a64f543 MS |
6228 | /* Field 4, the address, is omitted (which makes the columns not |
6229 | line up too nicely with the headers, but the effect is relatively | |
6230 | readable). */ | |
79a45b7d | 6231 | if (opts.addressprint) |
ce78b96d JB |
6232 | ui_out_field_skip (uiout, "addr"); |
6233 | annotate_field (5); | |
6234 | ui_out_text (uiout, "fork"); | |
e29a4733 | 6235 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6236 | { |
6237 | ui_out_text (uiout, ", process "); | |
6238 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6239 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6240 | ui_out_spaces (uiout, 1); |
6241 | } | |
6242 | } | |
6243 | ||
6244 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6245 | catchpoints. */ | |
6246 | ||
6247 | static void | |
6248 | print_mention_catch_fork (struct breakpoint *b) | |
6249 | { | |
6250 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6251 | } | |
6252 | ||
6149aea9 PA |
6253 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6254 | catchpoints. */ | |
6255 | ||
6256 | static void | |
6257 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6258 | { | |
6259 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 6260 | print_recreate_thread (b, fp); |
6149aea9 PA |
6261 | } |
6262 | ||
ce78b96d JB |
6263 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6264 | ||
2060206e | 6265 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 6266 | |
4a64f543 MS |
6267 | /* Implement the "insert" breakpoint_ops method for vfork |
6268 | catchpoints. */ | |
ce78b96d | 6269 | |
77b06cd7 TJB |
6270 | static int |
6271 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6272 | { |
77b06cd7 | 6273 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6274 | } |
6275 | ||
4a64f543 MS |
6276 | /* Implement the "remove" breakpoint_ops method for vfork |
6277 | catchpoints. */ | |
ce78b96d JB |
6278 | |
6279 | static int | |
77b06cd7 | 6280 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6281 | { |
6282 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6283 | } | |
6284 | ||
6285 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6286 | catchpoints. */ | |
6287 | ||
6288 | static int | |
f1310107 TJB |
6289 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
6290 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6291 | { |
e29a4733 PA |
6292 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6293 | ||
6294 | return inferior_has_vforked (inferior_ptid, &c->forked_inferior_pid); | |
ce78b96d JB |
6295 | } |
6296 | ||
4a64f543 MS |
6297 | /* Implement the "print_it" breakpoint_ops method for vfork |
6298 | catchpoints. */ | |
ce78b96d JB |
6299 | |
6300 | static enum print_stop_action | |
348d480f | 6301 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 6302 | { |
348d480f | 6303 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
6304 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
6305 | ||
ce78b96d JB |
6306 | annotate_catchpoint (b->number); |
6307 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
e29a4733 | 6308 | b->number, ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6309 | return PRINT_SRC_AND_LOC; |
6310 | } | |
6311 | ||
4a64f543 MS |
6312 | /* Implement the "print_one" breakpoint_ops method for vfork |
6313 | catchpoints. */ | |
ce78b96d JB |
6314 | |
6315 | static void | |
a6d9a66e | 6316 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6317 | { |
e29a4733 | 6318 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6319 | struct value_print_options opts; |
79a45e25 | 6320 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6321 | |
6322 | get_user_print_options (&opts); | |
4a64f543 MS |
6323 | /* Field 4, the address, is omitted (which makes the columns not |
6324 | line up too nicely with the headers, but the effect is relatively | |
6325 | readable). */ | |
79a45b7d | 6326 | if (opts.addressprint) |
ce78b96d JB |
6327 | ui_out_field_skip (uiout, "addr"); |
6328 | annotate_field (5); | |
6329 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 6330 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6331 | { |
6332 | ui_out_text (uiout, ", process "); | |
6333 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6334 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6335 | ui_out_spaces (uiout, 1); |
6336 | } | |
6337 | } | |
6338 | ||
6339 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6340 | catchpoints. */ | |
6341 | ||
6342 | static void | |
6343 | print_mention_catch_vfork (struct breakpoint *b) | |
6344 | { | |
6345 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6346 | } | |
6347 | ||
6149aea9 PA |
6348 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6349 | catchpoints. */ | |
6350 | ||
6351 | static void | |
6352 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6353 | { | |
6354 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 6355 | print_recreate_thread (b, fp); |
6149aea9 PA |
6356 | } |
6357 | ||
ce78b96d JB |
6358 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6359 | ||
2060206e | 6360 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 6361 | |
be5c67c1 PA |
6362 | /* An instance of this type is used to represent a syscall catchpoint. |
6363 | It includes a "struct breakpoint" as a kind of base class; users | |
6364 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6365 | really of this type iff its ops pointer points to | |
6366 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
6367 | ||
6368 | struct syscall_catchpoint | |
6369 | { | |
6370 | /* The base class. */ | |
6371 | struct breakpoint base; | |
6372 | ||
6373 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
6374 | syscall has been specified for filtering, its value is NULL. | |
6375 | Otherwise, it holds a list of all syscalls to be caught. The | |
6376 | list elements are allocated with xmalloc. */ | |
6377 | VEC(int) *syscalls_to_be_caught; | |
6378 | }; | |
6379 | ||
6380 | /* Implement the "dtor" breakpoint_ops method for syscall | |
6381 | catchpoints. */ | |
6382 | ||
6383 | static void | |
6384 | dtor_catch_syscall (struct breakpoint *b) | |
6385 | { | |
6386 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
6387 | ||
6388 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 6389 | |
2060206e | 6390 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
6391 | } |
6392 | ||
a96d9b2e SDJ |
6393 | /* Implement the "insert" breakpoint_ops method for syscall |
6394 | catchpoints. */ | |
6395 | ||
77b06cd7 TJB |
6396 | static int |
6397 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 6398 | { |
be5c67c1 | 6399 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6400 | struct inferior *inf = current_inferior (); |
6401 | ||
6402 | ++inf->total_syscalls_count; | |
be5c67c1 | 6403 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6404 | ++inf->any_syscall_count; |
6405 | else | |
6406 | { | |
6407 | int i, iter; | |
cc59ec59 | 6408 | |
a96d9b2e | 6409 | for (i = 0; |
be5c67c1 | 6410 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6411 | i++) |
6412 | { | |
6413 | int elem; | |
cc59ec59 | 6414 | |
a96d9b2e SDJ |
6415 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6416 | { | |
6417 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6418 | uintptr_t vec_addr_offset |
6419 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6420 | uintptr_t vec_addr; |
6421 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6422 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6423 | vec_addr_offset; | |
6424 | memset ((void *) vec_addr, 0, | |
6425 | (iter + 1 - old_size) * sizeof (int)); | |
6426 | } | |
6427 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6428 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6429 | } | |
6430 | } | |
6431 | ||
77b06cd7 TJB |
6432 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6433 | inf->total_syscalls_count != 0, | |
6434 | inf->any_syscall_count, | |
6435 | VEC_length (int, inf->syscalls_counts), | |
6436 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6437 | } |
6438 | ||
6439 | /* Implement the "remove" breakpoint_ops method for syscall | |
6440 | catchpoints. */ | |
6441 | ||
6442 | static int | |
77b06cd7 | 6443 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 6444 | { |
be5c67c1 | 6445 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6446 | struct inferior *inf = current_inferior (); |
6447 | ||
6448 | --inf->total_syscalls_count; | |
be5c67c1 | 6449 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6450 | --inf->any_syscall_count; |
6451 | else | |
6452 | { | |
6453 | int i, iter; | |
cc59ec59 | 6454 | |
a96d9b2e | 6455 | for (i = 0; |
be5c67c1 | 6456 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6457 | i++) |
6458 | { | |
6459 | int elem; | |
6460 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6461 | /* Shouldn't happen. */ | |
6462 | continue; | |
6463 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6464 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6465 | } | |
6466 | } | |
6467 | ||
6468 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6469 | inf->total_syscalls_count != 0, | |
6470 | inf->any_syscall_count, | |
6471 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6472 | VEC_address (int, |
6473 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6474 | } |
6475 | ||
6476 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6477 | catchpoints. */ | |
6478 | ||
6479 | static int | |
f1310107 TJB |
6480 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
6481 | struct address_space *aspace, CORE_ADDR bp_addr) | |
a96d9b2e | 6482 | { |
4a64f543 MS |
6483 | /* We must check if we are catching specific syscalls in this |
6484 | breakpoint. If we are, then we must guarantee that the called | |
6485 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 6486 | int syscall_number = 0; |
be5c67c1 PA |
6487 | const struct syscall_catchpoint *c |
6488 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e SDJ |
6489 | |
6490 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6491 | return 0; | |
6492 | ||
6493 | /* Now, checking if the syscall is the same. */ | |
be5c67c1 | 6494 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6495 | { |
6496 | int i, iter; | |
cc59ec59 | 6497 | |
a96d9b2e | 6498 | for (i = 0; |
be5c67c1 | 6499 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6500 | i++) |
6501 | if (syscall_number == iter) | |
6502 | break; | |
6503 | /* Not the same. */ | |
6504 | if (!iter) | |
6505 | return 0; | |
6506 | } | |
6507 | ||
6508 | return 1; | |
6509 | } | |
6510 | ||
6511 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6512 | catchpoints. */ | |
6513 | ||
6514 | static enum print_stop_action | |
348d480f | 6515 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 6516 | { |
348d480f | 6517 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
6518 | /* These are needed because we want to know in which state a |
6519 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6520 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6521 | must print "called syscall" or "returned from syscall". */ | |
6522 | ptid_t ptid; | |
6523 | struct target_waitstatus last; | |
6524 | struct syscall s; | |
6525 | struct cleanup *old_chain; | |
6526 | char *syscall_id; | |
6527 | ||
6528 | get_last_target_status (&ptid, &last); | |
6529 | ||
6530 | get_syscall_by_number (last.value.syscall_number, &s); | |
6531 | ||
6532 | annotate_catchpoint (b->number); | |
6533 | ||
6534 | if (s.name == NULL) | |
6535 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6536 | else | |
6537 | syscall_id = xstrprintf ("'%s'", s.name); | |
6538 | ||
6539 | old_chain = make_cleanup (xfree, syscall_id); | |
6540 | ||
6541 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6542 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6543 | b->number, syscall_id); | |
6544 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6545 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6546 | b->number, syscall_id); | |
6547 | ||
6548 | do_cleanups (old_chain); | |
6549 | ||
6550 | return PRINT_SRC_AND_LOC; | |
6551 | } | |
6552 | ||
6553 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6554 | catchpoints. */ | |
6555 | ||
6556 | static void | |
6557 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 6558 | struct bp_location **last_loc) |
a96d9b2e | 6559 | { |
be5c67c1 | 6560 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 6561 | struct value_print_options opts; |
79a45e25 | 6562 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
6563 | |
6564 | get_user_print_options (&opts); | |
4a64f543 MS |
6565 | /* Field 4, the address, is omitted (which makes the columns not |
6566 | line up too nicely with the headers, but the effect is relatively | |
6567 | readable). */ | |
a96d9b2e SDJ |
6568 | if (opts.addressprint) |
6569 | ui_out_field_skip (uiout, "addr"); | |
6570 | annotate_field (5); | |
6571 | ||
be5c67c1 PA |
6572 | if (c->syscalls_to_be_caught |
6573 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
6574 | ui_out_text (uiout, "syscalls \""); |
6575 | else | |
6576 | ui_out_text (uiout, "syscall \""); | |
6577 | ||
be5c67c1 | 6578 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6579 | { |
6580 | int i, iter; | |
6581 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6582 | |
a96d9b2e | 6583 | for (i = 0; |
be5c67c1 | 6584 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6585 | i++) |
6586 | { | |
6587 | char *x = text; | |
6588 | struct syscall s; | |
6589 | get_syscall_by_number (iter, &s); | |
6590 | ||
6591 | if (s.name != NULL) | |
6592 | text = xstrprintf ("%s%s, ", text, s.name); | |
6593 | else | |
6594 | text = xstrprintf ("%s%d, ", text, iter); | |
6595 | ||
6596 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 6597 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
6598 | on every call. */ |
6599 | xfree (x); | |
6600 | } | |
6601 | /* Remove the last comma. */ | |
6602 | text[strlen (text) - 2] = '\0'; | |
6603 | ui_out_field_string (uiout, "what", text); | |
6604 | } | |
6605 | else | |
6606 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6607 | ui_out_text (uiout, "\" "); | |
6608 | } | |
6609 | ||
6610 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6611 | catchpoints. */ | |
6612 | ||
6613 | static void | |
6614 | print_mention_catch_syscall (struct breakpoint *b) | |
6615 | { | |
be5c67c1 PA |
6616 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6617 | ||
6618 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
6619 | { |
6620 | int i, iter; | |
6621 | ||
be5c67c1 | 6622 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
6623 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
6624 | else | |
6625 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6626 | ||
6627 | for (i = 0; | |
be5c67c1 | 6628 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6629 | i++) |
6630 | { | |
6631 | struct syscall s; | |
6632 | get_syscall_by_number (iter, &s); | |
6633 | ||
6634 | if (s.name) | |
6635 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6636 | else | |
6637 | printf_filtered (" %d", s.number); | |
6638 | } | |
6639 | printf_filtered (")"); | |
6640 | } | |
6641 | else | |
6642 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6643 | b->number); | |
6644 | } | |
6645 | ||
6149aea9 PA |
6646 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6647 | catchpoints. */ | |
6648 | ||
6649 | static void | |
6650 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6651 | { | |
be5c67c1 PA |
6652 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6653 | ||
6149aea9 PA |
6654 | fprintf_unfiltered (fp, "catch syscall"); |
6655 | ||
be5c67c1 | 6656 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
6657 | { |
6658 | int i, iter; | |
6659 | ||
6660 | for (i = 0; | |
be5c67c1 | 6661 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
6662 | i++) |
6663 | { | |
6664 | struct syscall s; | |
6665 | ||
6666 | get_syscall_by_number (iter, &s); | |
6667 | if (s.name) | |
6668 | fprintf_unfiltered (fp, " %s", s.name); | |
6669 | else | |
6670 | fprintf_unfiltered (fp, " %d", s.number); | |
6671 | } | |
6672 | } | |
d9b3f62e | 6673 | print_recreate_thread (b, fp); |
6149aea9 PA |
6674 | } |
6675 | ||
a96d9b2e SDJ |
6676 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6677 | ||
2060206e | 6678 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
6679 | |
6680 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6681 | ||
6682 | static int | |
6683 | syscall_catchpoint_p (struct breakpoint *b) | |
6684 | { | |
6685 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6686 | } | |
6687 | ||
346774a9 PA |
6688 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
6689 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
6690 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
6691 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 6692 | |
346774a9 PA |
6693 | static void |
6694 | init_catchpoint (struct breakpoint *b, | |
6695 | struct gdbarch *gdbarch, int tempflag, | |
6696 | char *cond_string, | |
c0a91b2b | 6697 | const struct breakpoint_ops *ops) |
c906108c | 6698 | { |
c5aa993b | 6699 | struct symtab_and_line sal; |
346774a9 | 6700 | |
fe39c653 | 6701 | init_sal (&sal); |
6c95b8df | 6702 | sal.pspace = current_program_space; |
c5aa993b | 6703 | |
28010a5d | 6704 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 6705 | |
1b36a34b | 6706 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 6707 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
6708 | } |
6709 | ||
28010a5d | 6710 | void |
3a5c3e22 | 6711 | install_breakpoint (int internal, struct breakpoint *b) |
c56053d2 PA |
6712 | { |
6713 | add_to_breakpoint_chain (b); | |
3a5c3e22 PA |
6714 | set_breakpoint_number (internal, b); |
6715 | if (!internal) | |
6716 | mention (b); | |
c56053d2 PA |
6717 | observer_notify_breakpoint_created (b); |
6718 | update_global_location_list (1); | |
6719 | } | |
6720 | ||
9b70b993 | 6721 | static void |
a6d9a66e UW |
6722 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6723 | int tempflag, char *cond_string, | |
c0a91b2b | 6724 | const struct breakpoint_ops *ops) |
c906108c | 6725 | { |
e29a4733 | 6726 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 6727 | |
e29a4733 PA |
6728 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
6729 | ||
6730 | c->forked_inferior_pid = null_ptid; | |
6731 | ||
3a5c3e22 | 6732 | install_breakpoint (0, &c->base); |
c906108c SS |
6733 | } |
6734 | ||
fe798b75 JB |
6735 | /* Exec catchpoints. */ |
6736 | ||
b4d90040 PA |
6737 | /* An instance of this type is used to represent an exec catchpoint. |
6738 | It includes a "struct breakpoint" as a kind of base class; users | |
6739 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6740 | really of this type iff its ops pointer points to | |
6741 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
6742 | ||
6743 | struct exec_catchpoint | |
6744 | { | |
6745 | /* The base class. */ | |
6746 | struct breakpoint base; | |
6747 | ||
6748 | /* Filename of a program whose exec triggered this catchpoint. | |
6749 | This field is only valid immediately after this catchpoint has | |
6750 | triggered. */ | |
6751 | char *exec_pathname; | |
6752 | }; | |
6753 | ||
6754 | /* Implement the "dtor" breakpoint_ops method for exec | |
6755 | catchpoints. */ | |
6756 | ||
6757 | static void | |
6758 | dtor_catch_exec (struct breakpoint *b) | |
6759 | { | |
6760 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
6761 | ||
6762 | xfree (c->exec_pathname); | |
348d480f | 6763 | |
2060206e | 6764 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
6765 | } |
6766 | ||
77b06cd7 TJB |
6767 | static int |
6768 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6769 | { |
77b06cd7 | 6770 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6771 | } |
c906108c | 6772 | |
fe798b75 | 6773 | static int |
77b06cd7 | 6774 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6775 | { |
6776 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6777 | } | |
c906108c | 6778 | |
fe798b75 | 6779 | static int |
f1310107 TJB |
6780 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
6781 | struct address_space *aspace, CORE_ADDR bp_addr) | |
fe798b75 | 6782 | { |
b4d90040 PA |
6783 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
6784 | ||
6785 | return inferior_has_execd (inferior_ptid, &c->exec_pathname); | |
fe798b75 | 6786 | } |
c906108c | 6787 | |
fe798b75 | 6788 | static enum print_stop_action |
348d480f | 6789 | print_it_catch_exec (bpstat bs) |
fe798b75 | 6790 | { |
348d480f | 6791 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
6792 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
6793 | ||
fe798b75 JB |
6794 | annotate_catchpoint (b->number); |
6795 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
b4d90040 | 6796 | c->exec_pathname); |
fe798b75 | 6797 | return PRINT_SRC_AND_LOC; |
c906108c SS |
6798 | } |
6799 | ||
fe798b75 | 6800 | static void |
a6d9a66e | 6801 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 6802 | { |
b4d90040 | 6803 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 6804 | struct value_print_options opts; |
79a45e25 | 6805 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
6806 | |
6807 | get_user_print_options (&opts); | |
6808 | ||
6809 | /* Field 4, the address, is omitted (which makes the columns | |
6810 | not line up too nicely with the headers, but the effect | |
6811 | is relatively readable). */ | |
6812 | if (opts.addressprint) | |
6813 | ui_out_field_skip (uiout, "addr"); | |
6814 | annotate_field (5); | |
6815 | ui_out_text (uiout, "exec"); | |
b4d90040 | 6816 | if (c->exec_pathname != NULL) |
fe798b75 JB |
6817 | { |
6818 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 6819 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
6820 | ui_out_text (uiout, "\" "); |
6821 | } | |
6822 | } | |
6823 | ||
6824 | static void | |
6825 | print_mention_catch_exec (struct breakpoint *b) | |
6826 | { | |
6827 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6828 | } | |
6829 | ||
6149aea9 PA |
6830 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6831 | catchpoints. */ | |
6832 | ||
6833 | static void | |
6834 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6835 | { | |
6836 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 6837 | print_recreate_thread (b, fp); |
6149aea9 PA |
6838 | } |
6839 | ||
2060206e | 6840 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 6841 | |
a96d9b2e SDJ |
6842 | static void |
6843 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 6844 | const struct breakpoint_ops *ops) |
a96d9b2e | 6845 | { |
be5c67c1 | 6846 | struct syscall_catchpoint *c; |
a96d9b2e | 6847 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 6848 | |
be5c67c1 PA |
6849 | c = XNEW (struct syscall_catchpoint); |
6850 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
6851 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 6852 | |
3a5c3e22 | 6853 | install_breakpoint (0, &c->base); |
a96d9b2e SDJ |
6854 | } |
6855 | ||
c906108c | 6856 | static int |
fba45db2 | 6857 | hw_breakpoint_used_count (void) |
c906108c | 6858 | { |
c906108c | 6859 | int i = 0; |
f1310107 TJB |
6860 | struct breakpoint *b; |
6861 | struct bp_location *bl; | |
c906108c SS |
6862 | |
6863 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6864 | { |
d6b74ac4 | 6865 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
6866 | for (bl = b->loc; bl; bl = bl->next) |
6867 | { | |
6868 | /* Special types of hardware breakpoints may use more than | |
6869 | one register. */ | |
348d480f | 6870 | i += b->ops->resources_needed (bl); |
f1310107 | 6871 | } |
c5aa993b | 6872 | } |
c906108c SS |
6873 | |
6874 | return i; | |
6875 | } | |
6876 | ||
a1398e0c PA |
6877 | /* Returns the resources B would use if it were a hardware |
6878 | watchpoint. */ | |
6879 | ||
c906108c | 6880 | static int |
a1398e0c | 6881 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 6882 | { |
c906108c | 6883 | int i = 0; |
e09342b5 | 6884 | struct bp_location *bl; |
c906108c | 6885 | |
a1398e0c PA |
6886 | if (!breakpoint_enabled (b)) |
6887 | return 0; | |
6888 | ||
6889 | for (bl = b->loc; bl; bl = bl->next) | |
6890 | { | |
6891 | /* Special types of hardware watchpoints may use more than | |
6892 | one register. */ | |
6893 | i += b->ops->resources_needed (bl); | |
6894 | } | |
6895 | ||
6896 | return i; | |
6897 | } | |
6898 | ||
6899 | /* Returns the sum the used resources of all hardware watchpoints of | |
6900 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
6901 | the sum of the used resources of all hardware watchpoints of other | |
6902 | types _not_ TYPE. */ | |
6903 | ||
6904 | static int | |
6905 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
6906 | enum bptype type, int *other_type_used) | |
6907 | { | |
6908 | int i = 0; | |
6909 | struct breakpoint *b; | |
6910 | ||
c906108c SS |
6911 | *other_type_used = 0; |
6912 | ALL_BREAKPOINTS (b) | |
e09342b5 | 6913 | { |
a1398e0c PA |
6914 | if (b == except) |
6915 | continue; | |
e09342b5 TJB |
6916 | if (!breakpoint_enabled (b)) |
6917 | continue; | |
6918 | ||
a1398e0c PA |
6919 | if (b->type == type) |
6920 | i += hw_watchpoint_use_count (b); | |
6921 | else if (is_hardware_watchpoint (b)) | |
6922 | *other_type_used = 1; | |
e09342b5 TJB |
6923 | } |
6924 | ||
c906108c SS |
6925 | return i; |
6926 | } | |
6927 | ||
c906108c | 6928 | void |
fba45db2 | 6929 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6930 | { |
c5aa993b | 6931 | struct breakpoint *b; |
c906108c SS |
6932 | |
6933 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6934 | { |
cc60f2e3 | 6935 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6936 | { |
b5de0fa7 | 6937 | b->enable_state = bp_call_disabled; |
b60e7edf | 6938 | update_global_location_list (0); |
c5aa993b JM |
6939 | } |
6940 | } | |
c906108c SS |
6941 | } |
6942 | ||
6943 | void | |
fba45db2 | 6944 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6945 | { |
c5aa993b | 6946 | struct breakpoint *b; |
c906108c SS |
6947 | |
6948 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6949 | { |
cc60f2e3 | 6950 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6951 | { |
b5de0fa7 | 6952 | b->enable_state = bp_enabled; |
b60e7edf | 6953 | update_global_location_list (1); |
c5aa993b JM |
6954 | } |
6955 | } | |
c906108c SS |
6956 | } |
6957 | ||
8bea4e01 UW |
6958 | void |
6959 | disable_breakpoints_before_startup (void) | |
6960 | { | |
6961 | struct breakpoint *b; | |
6962 | int found = 0; | |
6963 | ||
6964 | ALL_BREAKPOINTS (b) | |
6965 | { | |
6c95b8df PA |
6966 | if (b->pspace != current_program_space) |
6967 | continue; | |
6968 | ||
8bea4e01 UW |
6969 | if ((b->type == bp_breakpoint |
6970 | || b->type == bp_hardware_breakpoint) | |
6971 | && breakpoint_enabled (b)) | |
6972 | { | |
6973 | b->enable_state = bp_startup_disabled; | |
6974 | found = 1; | |
6975 | } | |
6976 | } | |
6977 | ||
6978 | if (found) | |
6979 | update_global_location_list (0); | |
6980 | ||
6c95b8df | 6981 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6982 | } |
6983 | ||
6984 | void | |
6985 | enable_breakpoints_after_startup (void) | |
6986 | { | |
6987 | struct breakpoint *b; | |
6988 | int found = 0; | |
6989 | ||
6c95b8df | 6990 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6991 | |
6992 | ALL_BREAKPOINTS (b) | |
6993 | { | |
6c95b8df PA |
6994 | if (b->pspace != current_program_space) |
6995 | continue; | |
6996 | ||
8bea4e01 UW |
6997 | if ((b->type == bp_breakpoint |
6998 | || b->type == bp_hardware_breakpoint) | |
6999 | && b->enable_state == bp_startup_disabled) | |
7000 | { | |
7001 | b->enable_state = bp_enabled; | |
7002 | found = 1; | |
7003 | } | |
7004 | } | |
7005 | ||
7006 | if (found) | |
7007 | breakpoint_re_set (); | |
7008 | } | |
7009 | ||
c906108c SS |
7010 | |
7011 | /* Set a breakpoint that will evaporate an end of command | |
7012 | at address specified by SAL. | |
7013 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
7014 | ||
7015 | struct breakpoint * | |
a6d9a66e UW |
7016 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
7017 | struct frame_id frame_id, enum bptype type) | |
c906108c | 7018 | { |
52f0bd74 | 7019 | struct breakpoint *b; |
edb3359d DJ |
7020 | |
7021 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
7022 | one. */ | |
7023 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
7024 | ||
06edf0c0 | 7025 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
7026 | b->enable_state = bp_enabled; |
7027 | b->disposition = disp_donttouch; | |
818dd999 | 7028 | b->frame_id = frame_id; |
c906108c | 7029 | |
4a64f543 MS |
7030 | /* If we're debugging a multi-threaded program, then we want |
7031 | momentary breakpoints to be active in only a single thread of | |
7032 | control. */ | |
39f77062 KB |
7033 | if (in_thread_list (inferior_ptid)) |
7034 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 7035 | |
b60e7edf | 7036 | update_global_location_list_nothrow (1); |
74960c60 | 7037 | |
c906108c SS |
7038 | return b; |
7039 | } | |
611c83ae | 7040 | |
06edf0c0 PA |
7041 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
7042 | The new breakpoint will have type TYPE, and use OPS as it | |
7043 | breakpoint_ops. */ | |
e58b0e63 | 7044 | |
06edf0c0 PA |
7045 | static struct breakpoint * |
7046 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
7047 | enum bptype type, | |
c0a91b2b | 7048 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
7049 | { |
7050 | struct breakpoint *copy; | |
7051 | ||
06edf0c0 | 7052 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 7053 | copy->loc = allocate_bp_location (copy); |
0e30163f | 7054 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 7055 | |
a6d9a66e | 7056 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
7057 | copy->loc->requested_address = orig->loc->requested_address; |
7058 | copy->loc->address = orig->loc->address; | |
7059 | copy->loc->section = orig->loc->section; | |
6c95b8df | 7060 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
7061 | |
7062 | if (orig->source_file == NULL) | |
7063 | copy->source_file = NULL; | |
7064 | else | |
7065 | copy->source_file = xstrdup (orig->source_file); | |
7066 | ||
7067 | copy->line_number = orig->line_number; | |
7068 | copy->frame_id = orig->frame_id; | |
7069 | copy->thread = orig->thread; | |
6c95b8df | 7070 | copy->pspace = orig->pspace; |
e58b0e63 PA |
7071 | |
7072 | copy->enable_state = bp_enabled; | |
7073 | copy->disposition = disp_donttouch; | |
7074 | copy->number = internal_breakpoint_number--; | |
7075 | ||
7076 | update_global_location_list_nothrow (0); | |
7077 | return copy; | |
7078 | } | |
7079 | ||
06edf0c0 PA |
7080 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
7081 | ORIG is NULL. */ | |
7082 | ||
7083 | struct breakpoint * | |
7084 | clone_momentary_breakpoint (struct breakpoint *orig) | |
7085 | { | |
7086 | /* If there's nothing to clone, then return nothing. */ | |
7087 | if (orig == NULL) | |
7088 | return NULL; | |
7089 | ||
7090 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
7091 | } | |
7092 | ||
611c83ae | 7093 | struct breakpoint * |
a6d9a66e UW |
7094 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
7095 | enum bptype type) | |
611c83ae PA |
7096 | { |
7097 | struct symtab_and_line sal; | |
7098 | ||
7099 | sal = find_pc_line (pc, 0); | |
7100 | sal.pc = pc; | |
7101 | sal.section = find_pc_overlay (pc); | |
7102 | sal.explicit_pc = 1; | |
7103 | ||
a6d9a66e | 7104 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 7105 | } |
c906108c | 7106 | \f |
c5aa993b | 7107 | |
c906108c SS |
7108 | /* Tell the user we have just set a breakpoint B. */ |
7109 | ||
7110 | static void | |
fba45db2 | 7111 | mention (struct breakpoint *b) |
c906108c | 7112 | { |
348d480f | 7113 | b->ops->print_mention (b); |
79a45e25 | 7114 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 7115 | return; |
c906108c SS |
7116 | printf_filtered ("\n"); |
7117 | } | |
c906108c | 7118 | \f |
c5aa993b | 7119 | |
0d381245 | 7120 | static struct bp_location * |
39d61571 | 7121 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7122 | const struct symtab_and_line *sal) |
7123 | { | |
7124 | struct bp_location *loc, **tmp; | |
7125 | ||
39d61571 | 7126 | loc = allocate_bp_location (b); |
0d381245 VP |
7127 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7128 | ; | |
7129 | *tmp = loc; | |
a6d9a66e UW |
7130 | loc->gdbarch = get_sal_arch (*sal); |
7131 | if (!loc->gdbarch) | |
7132 | loc->gdbarch = b->gdbarch; | |
0d381245 | 7133 | loc->requested_address = sal->pc; |
a6d9a66e UW |
7134 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
7135 | loc->requested_address, b->type); | |
6c95b8df PA |
7136 | loc->pspace = sal->pspace; |
7137 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
7138 | loc->section = sal->section; |
7139 | ||
0e30163f JK |
7140 | set_breakpoint_location_function (loc, |
7141 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
7142 | return loc; |
7143 | } | |
514f746b AR |
7144 | \f |
7145 | ||
7146 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7147 | return 0 otherwise. */ | |
7148 | ||
7149 | static int | |
7150 | bp_loc_is_permanent (struct bp_location *loc) | |
7151 | { | |
7152 | int len; | |
7153 | CORE_ADDR addr; | |
7154 | const gdb_byte *brk; | |
7155 | gdb_byte *target_mem; | |
939c61fa JK |
7156 | struct cleanup *cleanup; |
7157 | int retval = 0; | |
514f746b AR |
7158 | |
7159 | gdb_assert (loc != NULL); | |
7160 | ||
7161 | addr = loc->address; | |
a6d9a66e | 7162 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7163 | |
939c61fa JK |
7164 | /* Software breakpoints unsupported? */ |
7165 | if (brk == NULL) | |
7166 | return 0; | |
7167 | ||
514f746b AR |
7168 | target_mem = alloca (len); |
7169 | ||
939c61fa JK |
7170 | /* Enable the automatic memory restoration from breakpoints while |
7171 | we read the memory. Otherwise we could say about our temporary | |
7172 | breakpoints they are permanent. */ | |
6c95b8df PA |
7173 | cleanup = save_current_space_and_thread (); |
7174 | ||
7175 | switch_to_program_space_and_thread (loc->pspace); | |
7176 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7177 | |
514f746b AR |
7178 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7179 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7180 | retval = 1; |
514f746b | 7181 | |
939c61fa JK |
7182 | do_cleanups (cleanup); |
7183 | ||
7184 | return retval; | |
514f746b AR |
7185 | } |
7186 | ||
7187 | ||
c3f6f71d | 7188 | |
018d34a4 VP |
7189 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7190 | as textual description of the location, and COND_STRING | |
db107f19 | 7191 | as condition expression. */ |
018d34a4 VP |
7192 | |
7193 | static void | |
d9b3f62e PA |
7194 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
7195 | struct symtabs_and_lines sals, char *addr_string, | |
7196 | char *cond_string, | |
7197 | enum bptype type, enum bpdisp disposition, | |
7198 | int thread, int task, int ignore_count, | |
c0a91b2b | 7199 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e | 7200 | int enabled, int internal, int display_canonical) |
018d34a4 | 7201 | { |
0d381245 | 7202 | int i; |
018d34a4 VP |
7203 | |
7204 | if (type == bp_hardware_breakpoint) | |
7205 | { | |
7206 | int i = hw_breakpoint_used_count (); | |
7207 | int target_resources_ok = | |
d92524f1 | 7208 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
7209 | i + 1, 0); |
7210 | if (target_resources_ok == 0) | |
7211 | error (_("No hardware breakpoint support in the target.")); | |
7212 | else if (target_resources_ok < 0) | |
7213 | error (_("Hardware breakpoints used exceeds limit.")); | |
7214 | } | |
7215 | ||
6c95b8df PA |
7216 | gdb_assert (sals.nelts > 0); |
7217 | ||
0d381245 VP |
7218 | for (i = 0; i < sals.nelts; ++i) |
7219 | { | |
7220 | struct symtab_and_line sal = sals.sals[i]; | |
7221 | struct bp_location *loc; | |
7222 | ||
7223 | if (from_tty) | |
5af949e3 UW |
7224 | { |
7225 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7226 | if (!loc_gdbarch) | |
7227 | loc_gdbarch = gdbarch; | |
7228 | ||
7229 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7230 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7231 | } |
0d381245 VP |
7232 | |
7233 | if (i == 0) | |
7234 | { | |
d9b3f62e | 7235 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 7236 | b->thread = thread; |
4a306c9a | 7237 | b->task = task; |
018d34a4 | 7238 | |
0d381245 VP |
7239 | b->cond_string = cond_string; |
7240 | b->ignore_count = ignore_count; | |
41447f92 | 7241 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7242 | b->disposition = disposition; |
6c95b8df PA |
7243 | b->pspace = sals.sals[0].pspace; |
7244 | ||
0fb4aa4b PA |
7245 | if (type == bp_static_tracepoint) |
7246 | { | |
d9b3f62e | 7247 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
7248 | struct static_tracepoint_marker marker; |
7249 | ||
7250 | if (is_marker_spec (addr_string)) | |
7251 | { | |
7252 | /* We already know the marker exists, otherwise, we | |
7253 | wouldn't see a sal for it. */ | |
7254 | char *p = &addr_string[3]; | |
7255 | char *endp; | |
7256 | char *marker_str; | |
7257 | int i; | |
7258 | ||
e9cafbcc | 7259 | p = skip_spaces (p); |
0fb4aa4b | 7260 | |
e9cafbcc | 7261 | endp = skip_to_space (p); |
0fb4aa4b PA |
7262 | |
7263 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 7264 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 7265 | |
3e43a32a MS |
7266 | printf_filtered (_("Probed static tracepoint " |
7267 | "marker \"%s\"\n"), | |
d9b3f62e | 7268 | t->static_trace_marker_id); |
0fb4aa4b PA |
7269 | } |
7270 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7271 | { | |
d9b3f62e | 7272 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
7273 | release_static_tracepoint_marker (&marker); |
7274 | ||
3e43a32a MS |
7275 | printf_filtered (_("Probed static tracepoint " |
7276 | "marker \"%s\"\n"), | |
d9b3f62e | 7277 | t->static_trace_marker_id); |
0fb4aa4b PA |
7278 | } |
7279 | else | |
3e43a32a MS |
7280 | warning (_("Couldn't determine the static " |
7281 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7282 | } |
7283 | ||
6c95b8df | 7284 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7285 | && (b->type == bp_breakpoint |
7286 | || b->type == bp_hardware_breakpoint)) | |
7287 | b->enable_state = bp_startup_disabled; | |
7288 | ||
0d381245 VP |
7289 | loc = b->loc; |
7290 | } | |
7291 | else | |
018d34a4 | 7292 | { |
39d61571 | 7293 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7294 | } |
7295 | ||
514f746b AR |
7296 | if (bp_loc_is_permanent (loc)) |
7297 | make_breakpoint_permanent (b); | |
7298 | ||
0d381245 VP |
7299 | if (b->cond_string) |
7300 | { | |
7301 | char *arg = b->cond_string; | |
d32a6982 | 7302 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7303 | if (*arg) |
db107f19 | 7304 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7305 | } |
0d381245 | 7306 | } |
018d34a4 | 7307 | |
56435ebe | 7308 | b->display_canonical = display_canonical; |
018d34a4 VP |
7309 | if (addr_string) |
7310 | b->addr_string = addr_string; | |
7311 | else | |
7312 | /* addr_string has to be used or breakpoint_re_set will delete | |
7313 | me. */ | |
5af949e3 UW |
7314 | b->addr_string |
7315 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
d9b3f62e | 7316 | } |
018d34a4 | 7317 | |
d9b3f62e PA |
7318 | static void |
7319 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
7320 | struct symtabs_and_lines sals, char *addr_string, | |
7321 | char *cond_string, | |
7322 | enum bptype type, enum bpdisp disposition, | |
7323 | int thread, int task, int ignore_count, | |
c0a91b2b | 7324 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e PA |
7325 | int enabled, int internal, int display_canonical) |
7326 | { | |
7327 | struct breakpoint *b; | |
7328 | struct cleanup *old_chain; | |
7329 | ||
7330 | if (is_tracepoint_type (type)) | |
7331 | { | |
7332 | struct tracepoint *t; | |
7333 | ||
7334 | t = XCNEW (struct tracepoint); | |
7335 | b = &t->base; | |
7336 | } | |
7337 | else | |
7338 | b = XNEW (struct breakpoint); | |
7339 | ||
7340 | old_chain = make_cleanup (xfree, b); | |
7341 | ||
7342 | init_breakpoint_sal (b, gdbarch, | |
7343 | sals, addr_string, | |
7344 | cond_string, | |
7345 | type, disposition, | |
7346 | thread, task, ignore_count, | |
7347 | ops, from_tty, | |
7348 | enabled, internal, display_canonical); | |
7349 | discard_cleanups (old_chain); | |
7350 | ||
7351 | install_breakpoint (internal, b); | |
018d34a4 VP |
7352 | } |
7353 | ||
ed0616c6 VP |
7354 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7355 | elements to fill the void space. */ | |
2c0b251b PA |
7356 | static void |
7357 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7358 | { |
7359 | int i = index_to_remove+1; | |
7360 | int last_index = sal->nelts-1; | |
7361 | ||
7362 | for (;i <= last_index; ++i) | |
7363 | sal->sals[i-1] = sal->sals[i]; | |
7364 | ||
7365 | --(sal->nelts); | |
7366 | } | |
7367 | ||
6c95b8df PA |
7368 | /* If appropriate, obtains all sals that correspond to the same file |
7369 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7370 | will want to set a breakpoint at foo.c:line, and not really care | |
7371 | about program spaces. This is done only if SAL does not have | |
7372 | explicit PC and has line and file information. If we got just a | |
7373 | single expanded sal, return the original. | |
ed0616c6 | 7374 | |
6c95b8df PA |
7375 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7376 | which the name of enclosing function is different from SAL. This | |
7377 | makes sure that if we have breakpoint originally set in template | |
7378 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7379 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7380 | |
2c0b251b | 7381 | static struct symtabs_and_lines |
ed0616c6 VP |
7382 | expand_line_sal_maybe (struct symtab_and_line sal) |
7383 | { | |
7384 | struct symtabs_and_lines expanded; | |
7385 | CORE_ADDR original_pc = sal.pc; | |
7386 | char *original_function = NULL; | |
7387 | int found; | |
7388 | int i; | |
6c95b8df | 7389 | struct cleanup *old_chain; |
ed0616c6 VP |
7390 | |
7391 | /* If we have explicit pc, don't expand. | |
7392 | If we have no line number, we can't expand. */ | |
7393 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7394 | { | |
7395 | expanded.nelts = 1; | |
7396 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7397 | expanded.sals[0] = sal; | |
7398 | return expanded; | |
7399 | } | |
7400 | ||
7401 | sal.pc = 0; | |
6c95b8df PA |
7402 | |
7403 | old_chain = save_current_space_and_thread (); | |
7404 | ||
7405 | switch_to_program_space_and_thread (sal.pspace); | |
7406 | ||
ed0616c6 | 7407 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7408 | |
7409 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7410 | expanded = expand_line_sal (sal); |
6c95b8df | 7411 | |
ed0616c6 VP |
7412 | if (expanded.nelts == 1) |
7413 | { | |
3dba1c98 JB |
7414 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7415 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7416 | xfree (expanded.sals); |
7417 | expanded.nelts = 1; | |
7418 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7419 | sal.pc = original_pc; | |
7420 | expanded.sals[0] = sal; | |
3dba1c98 | 7421 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7422 | do_cleanups (old_chain); |
ed0616c6 VP |
7423 | return expanded; |
7424 | } | |
7425 | ||
7426 | if (!sal.explicit_line) | |
7427 | { | |
7428 | CORE_ADDR func_addr, func_end; | |
7429 | for (i = 0; i < expanded.nelts; ++i) | |
7430 | { | |
7431 | CORE_ADDR pc = expanded.sals[i].pc; | |
7432 | char *this_function; | |
6c95b8df PA |
7433 | |
7434 | /* We need to switch threads as well since we're about to | |
7435 | read memory. */ | |
7436 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7437 | ||
ed0616c6 VP |
7438 | if (find_pc_partial_function (pc, &this_function, |
7439 | &func_addr, &func_end)) | |
7440 | { | |
059fb39f PM |
7441 | if (this_function |
7442 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7443 | { |
7444 | remove_sal (&expanded, i); | |
7445 | --i; | |
7446 | } | |
ed0616c6 VP |
7447 | } |
7448 | } | |
7449 | } | |
059acae7 UW |
7450 | |
7451 | /* Skip the function prologue if necessary. */ | |
7452 | for (i = 0; i < expanded.nelts; ++i) | |
7453 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7454 | |
6c95b8df PA |
7455 | do_cleanups (old_chain); |
7456 | ||
ed0616c6 VP |
7457 | if (expanded.nelts <= 1) |
7458 | { | |
e5dd4106 | 7459 | /* This is an ugly workaround. If we get zero expanded sals |
4a64f543 MS |
7460 | then something is really wrong. Fix that by returning the |
7461 | original sal. */ | |
7462 | ||
ed0616c6 VP |
7463 | xfree (expanded.sals); |
7464 | expanded.nelts = 1; | |
7465 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7466 | sal.pc = original_pc; | |
7467 | expanded.sals[0] = sal; | |
7468 | return expanded; | |
7469 | } | |
7470 | ||
7471 | if (original_pc) | |
7472 | { | |
7473 | found = 0; | |
7474 | for (i = 0; i < expanded.nelts; ++i) | |
7475 | if (expanded.sals[i].pc == original_pc) | |
7476 | { | |
7477 | found = 1; | |
7478 | break; | |
7479 | } | |
7480 | gdb_assert (found); | |
7481 | } | |
7482 | ||
7483 | return expanded; | |
7484 | } | |
7485 | ||
018d34a4 VP |
7486 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7487 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7488 | value. COND_STRING, if not NULL, specified the condition to be | |
7489 | used for all breakpoints. Essentially the only case where | |
7490 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7491 | function. In that case, it's still not possible to specify | |
7492 | separate conditions for different overloaded functions, so | |
7493 | we take just a single condition string. | |
7494 | ||
c3f6f71d | 7495 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7496 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7497 | array contents). If the function fails (error() is called), the |
7498 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7499 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7500 | |
7501 | static void | |
8cdf0e15 | 7502 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 TT |
7503 | struct symtabs_and_lines sals, |
7504 | struct linespec_result *canonical, | |
8cdf0e15 VP |
7505 | char *cond_string, |
7506 | enum bptype type, enum bpdisp disposition, | |
7507 | int thread, int task, int ignore_count, | |
c0a91b2b | 7508 | const struct breakpoint_ops *ops, int from_tty, |
84f4c1fe | 7509 | int enabled, int internal) |
c906108c | 7510 | { |
018d34a4 | 7511 | int i; |
cc59ec59 | 7512 | |
018d34a4 | 7513 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7514 | { |
ed0616c6 VP |
7515 | struct symtabs_and_lines expanded = |
7516 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7517 | |
7efd8fc2 | 7518 | create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i], |
8cdf0e15 | 7519 | cond_string, type, disposition, |
84f4c1fe | 7520 | thread, task, ignore_count, ops, |
56435ebe TT |
7521 | from_tty, enabled, internal, |
7522 | canonical->special_display); | |
c3f6f71d | 7523 | } |
c3f6f71d | 7524 | } |
c906108c | 7525 | |
9998af43 | 7526 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7527 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7528 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7529 | address strings. ADDRESS points to the end of the SAL. |
7530 | ||
7531 | The array and the line spec strings are allocated on the heap, it is | |
7532 | the caller's responsibility to free them. */ | |
c906108c | 7533 | |
b9362cc7 | 7534 | static void |
c3f6f71d JM |
7535 | parse_breakpoint_sals (char **address, |
7536 | struct symtabs_and_lines *sals, | |
58438ac1 | 7537 | struct linespec_result *canonical) |
c3f6f71d JM |
7538 | { |
7539 | char *addr_start = *address; | |
cc59ec59 | 7540 | |
c3f6f71d | 7541 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 7542 | breakpoint. */ |
c3f6f71d JM |
7543 | if ((*address) == NULL |
7544 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7545 | { |
7546 | if (default_breakpoint_valid) | |
7547 | { | |
c3f6f71d | 7548 | struct symtab_and_line sal; |
cc59ec59 | 7549 | |
4a64f543 | 7550 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7551 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7552 | xmalloc (sizeof (struct symtab_and_line)); |
7553 | sal.pc = default_breakpoint_address; | |
7554 | sal.line = default_breakpoint_line; | |
7555 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7556 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7557 | sal.section = find_pc_overlay (sal.pc); |
00903456 | 7558 | |
4a64f543 MS |
7559 | /* "break" without arguments is equivalent to "break *PC" |
7560 | where PC is the default_breakpoint_address. So make sure | |
7561 | to set sal.explicit_pc to prevent GDB from trying to | |
7562 | expand the list of sals to include all other instances | |
7563 | with the same symtab and line. */ | |
00903456 JK |
7564 | sal.explicit_pc = 1; |
7565 | ||
c3f6f71d JM |
7566 | sals->sals[0] = sal; |
7567 | sals->nelts = 1; | |
c906108c SS |
7568 | } |
7569 | else | |
8a3fe4f8 | 7570 | error (_("No default breakpoint address now.")); |
c906108c SS |
7571 | } |
7572 | else | |
7573 | { | |
c906108c | 7574 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7575 | current_source_symtab (which is decode_line_1's default). |
7576 | This should produce the results we want almost all of the | |
7577 | time while leaving default_breakpoint_* alone. | |
7578 | ||
1aeae86e AF |
7579 | ObjC: However, don't match an Objective-C method name which |
7580 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7581 | |
c214a6fd | 7582 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7583 | |
c906108c | 7584 | if (default_breakpoint_valid |
0378c332 | 7585 | && (!cursal.symtab |
1aeae86e AF |
7586 | || ((strchr ("+-", (*address)[0]) != NULL) |
7587 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7588 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
58438ac1 | 7589 | default_breakpoint_line, canonical); |
c906108c | 7590 | else |
0101ce28 | 7591 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
58438ac1 | 7592 | canonical); |
c906108c | 7593 | } |
4a64f543 | 7594 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7efd8fc2 | 7595 | if (sals->nelts > 0 && canonical->canonical == NULL) |
38a714bb | 7596 | canonical->canonical = xcalloc (sals->nelts, sizeof (char *)); |
c3f6f71d | 7597 | if (addr_start != (*address)) |
c906108c | 7598 | { |
c3f6f71d | 7599 | int i; |
cc59ec59 | 7600 | |
c3f6f71d | 7601 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7602 | { |
4a64f543 | 7603 | /* Add the string if not present. */ |
7efd8fc2 TT |
7604 | if (canonical->canonical[i] == NULL) |
7605 | canonical->canonical[i] = savestring (addr_start, | |
7606 | (*address) - addr_start); | |
c906108c SS |
7607 | } |
7608 | } | |
c3f6f71d | 7609 | } |
c906108c | 7610 | |
c906108c | 7611 | |
c3f6f71d | 7612 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7613 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7614 | |
b9362cc7 | 7615 | static void |
23e7acfb | 7616 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7617 | { |
7618 | int i; | |
cc59ec59 | 7619 | |
c3f6f71d | 7620 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7621 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7622 | } |
7623 | ||
7a697b8d SS |
7624 | /* Fast tracepoints may have restrictions on valid locations. For |
7625 | instance, a fast tracepoint using a jump instead of a trap will | |
7626 | likely have to overwrite more bytes than a trap would, and so can | |
7627 | only be placed where the instruction is longer than the jump, or a | |
7628 | multi-instruction sequence does not have a jump into the middle of | |
7629 | it, etc. */ | |
7630 | ||
7631 | static void | |
7632 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7633 | struct symtabs_and_lines *sals) | |
7634 | { | |
7635 | int i, rslt; | |
7636 | struct symtab_and_line *sal; | |
7637 | char *msg; | |
7638 | struct cleanup *old_chain; | |
7639 | ||
7640 | for (i = 0; i < sals->nelts; i++) | |
7641 | { | |
7642 | sal = &sals->sals[i]; | |
7643 | ||
7644 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7645 | NULL, &msg); | |
7646 | old_chain = make_cleanup (xfree, msg); | |
7647 | ||
7648 | if (!rslt) | |
7649 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7650 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7651 | ||
7652 | do_cleanups (old_chain); | |
7653 | } | |
7654 | } | |
7655 | ||
018d34a4 VP |
7656 | /* Given TOK, a string specification of condition and thread, as |
7657 | accepted by the 'break' command, extract the condition | |
7658 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7659 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7660 | If no condition is found, *COND_STRING is set to NULL. |
7661 | If no thread is found, *THREAD is set to -1. */ | |
7662 | static void | |
7663 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7664 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7665 | { |
7666 | *cond_string = NULL; | |
7667 | *thread = -1; | |
7668 | while (tok && *tok) | |
7669 | { | |
7670 | char *end_tok; | |
7671 | int toklen; | |
7672 | char *cond_start = NULL; | |
7673 | char *cond_end = NULL; | |
cc59ec59 | 7674 | |
e9cafbcc | 7675 | tok = skip_spaces (tok); |
018d34a4 | 7676 | |
e9cafbcc | 7677 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7678 | |
7679 | toklen = end_tok - tok; | |
7680 | ||
7681 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7682 | { | |
f7545552 TT |
7683 | struct expression *expr; |
7684 | ||
018d34a4 | 7685 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7686 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7687 | xfree (expr); | |
018d34a4 VP |
7688 | cond_end = tok; |
7689 | *cond_string = savestring (cond_start, | |
7690 | cond_end - cond_start); | |
7691 | } | |
7692 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7693 | { | |
7694 | char *tmptok; | |
7695 | ||
7696 | tok = end_tok + 1; | |
7697 | tmptok = tok; | |
7698 | *thread = strtol (tok, &tok, 0); | |
7699 | if (tok == tmptok) | |
7700 | error (_("Junk after thread keyword.")); | |
7701 | if (!valid_thread_id (*thread)) | |
7702 | error (_("Unknown thread %d."), *thread); | |
7703 | } | |
4a306c9a JB |
7704 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7705 | { | |
7706 | char *tmptok; | |
7707 | ||
7708 | tok = end_tok + 1; | |
7709 | tmptok = tok; | |
7710 | *task = strtol (tok, &tok, 0); | |
7711 | if (tok == tmptok) | |
7712 | error (_("Junk after task keyword.")); | |
7713 | if (!valid_task_id (*task)) | |
b6199126 | 7714 | error (_("Unknown task %d."), *task); |
4a306c9a | 7715 | } |
018d34a4 VP |
7716 | else |
7717 | error (_("Junk at end of arguments.")); | |
7718 | } | |
7719 | } | |
7720 | ||
0fb4aa4b PA |
7721 | /* Decode a static tracepoint marker spec. */ |
7722 | ||
7723 | static struct symtabs_and_lines | |
7724 | decode_static_tracepoint_spec (char **arg_p) | |
7725 | { | |
7726 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7727 | struct symtabs_and_lines sals; | |
7728 | struct symtab_and_line sal; | |
7729 | struct symbol *sym; | |
7730 | struct cleanup *old_chain; | |
7731 | char *p = &(*arg_p)[3]; | |
7732 | char *endp; | |
7733 | char *marker_str; | |
7734 | int i; | |
7735 | ||
e9cafbcc | 7736 | p = skip_spaces (p); |
0fb4aa4b | 7737 | |
e9cafbcc | 7738 | endp = skip_to_space (p); |
0fb4aa4b PA |
7739 | |
7740 | marker_str = savestring (p, endp - p); | |
7741 | old_chain = make_cleanup (xfree, marker_str); | |
7742 | ||
7743 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7744 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7745 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7746 | ||
7747 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7748 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7749 | ||
7750 | for (i = 0; i < sals.nelts; i++) | |
7751 | { | |
7752 | struct static_tracepoint_marker *marker; | |
7753 | ||
7754 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7755 | ||
7756 | init_sal (&sals.sals[i]); | |
7757 | ||
7758 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7759 | sals.sals[i].pc = marker->address; | |
7760 | ||
7761 | release_static_tracepoint_marker (marker); | |
7762 | } | |
7763 | ||
7764 | do_cleanups (old_chain); | |
7765 | ||
7766 | *arg_p = endp; | |
7767 | return sals; | |
7768 | } | |
7769 | ||
fd9b8c24 PA |
7770 | /* Set a breakpoint. This function is shared between CLI and MI |
7771 | functions for setting a breakpoint. This function has two major | |
7772 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7773 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7774 | breakpoint location, address and thread. Otherwise, ARG is just |
7775 | the location of breakpoint, with condition and thread specified by | |
7776 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7777 | the breakpoint number will be allocated from the internal | |
7778 | breakpoint count. Returns true if any breakpoint was created; | |
7779 | false otherwise. */ | |
0101ce28 | 7780 | |
8cdf0e15 VP |
7781 | int |
7782 | create_breakpoint (struct gdbarch *gdbarch, | |
7783 | char *arg, char *cond_string, int thread, | |
7784 | int parse_condition_and_thread, | |
0fb4aa4b | 7785 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7786 | int ignore_count, |
7787 | enum auto_boolean pending_break_support, | |
c0a91b2b | 7788 | const struct breakpoint_ops *ops, |
84f4c1fe | 7789 | int from_tty, int enabled, int internal) |
c3f6f71d | 7790 | { |
b78a6381 | 7791 | volatile struct gdb_exception e; |
c3f6f71d | 7792 | struct symtabs_and_lines sals; |
0101ce28 | 7793 | struct symtab_and_line pending_sal; |
0101ce28 | 7794 | char *copy_arg; |
c3f6f71d | 7795 | char *addr_start = arg; |
7efd8fc2 | 7796 | struct linespec_result canonical; |
c3f6f71d | 7797 | struct cleanup *old_chain; |
80c99de1 | 7798 | struct cleanup *bkpt_chain = NULL; |
05ff989b | 7799 | int i; |
0101ce28 | 7800 | int pending = 0; |
4a306c9a | 7801 | int task = 0; |
86b17b60 | 7802 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7803 | |
348d480f PA |
7804 | gdb_assert (ops != NULL); |
7805 | ||
c3f6f71d JM |
7806 | sals.sals = NULL; |
7807 | sals.nelts = 0; | |
7efd8fc2 | 7808 | init_linespec_result (&canonical); |
c3f6f71d | 7809 | |
0fb4aa4b PA |
7810 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7811 | { | |
7812 | int i; | |
7813 | ||
7814 | sals = decode_static_tracepoint_spec (&arg); | |
7815 | ||
7816 | copy_arg = savestring (addr_start, arg - addr_start); | |
38a714bb | 7817 | canonical.canonical = xcalloc (sals.nelts, sizeof (char *)); |
0fb4aa4b | 7818 | for (i = 0; i < sals.nelts; i++) |
7efd8fc2 | 7819 | canonical.canonical[i] = xstrdup (copy_arg); |
0fb4aa4b PA |
7820 | goto done; |
7821 | } | |
7822 | ||
b78a6381 TT |
7823 | TRY_CATCH (e, RETURN_MASK_ALL) |
7824 | { | |
58438ac1 | 7825 | parse_breakpoint_sals (&arg, &sals, &canonical); |
b78a6381 | 7826 | } |
0101ce28 JJ |
7827 | |
7828 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7829 | switch (e.reason) |
0101ce28 | 7830 | { |
05ff989b | 7831 | case RETURN_QUIT: |
98deb0da | 7832 | throw_exception (e); |
05ff989b AC |
7833 | case RETURN_ERROR: |
7834 | switch (e.error) | |
0101ce28 | 7835 | { |
05ff989b | 7836 | case NOT_FOUND_ERROR: |
0101ce28 | 7837 | |
05ff989b AC |
7838 | /* If pending breakpoint support is turned off, throw |
7839 | error. */ | |
fa8d40ab JJ |
7840 | |
7841 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7842 | throw_exception (e); |
7843 | ||
7844 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7845 | |
05ff989b AC |
7846 | /* If pending breakpoint support is auto query and the user |
7847 | selects no, then simply return the error code. */ | |
059fb39f | 7848 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
3e43a32a MS |
7849 | && !nquery (_("Make breakpoint pending on " |
7850 | "future shared library load? "))) | |
fd9b8c24 | 7851 | return 0; |
fa8d40ab | 7852 | |
05ff989b AC |
7853 | /* At this point, either the user was queried about setting |
7854 | a pending breakpoint and selected yes, or pending | |
7855 | breakpoint behavior is on and thus a pending breakpoint | |
7856 | is defaulted on behalf of the user. */ | |
0101ce28 | 7857 | copy_arg = xstrdup (addr_start); |
7efd8fc2 | 7858 | canonical.canonical = ©_arg; |
0101ce28 JJ |
7859 | sals.nelts = 1; |
7860 | sals.sals = &pending_sal; | |
7861 | pending_sal.pc = 0; | |
7862 | pending = 1; | |
05ff989b AC |
7863 | break; |
7864 | default: | |
98deb0da | 7865 | throw_exception (e); |
0101ce28 | 7866 | } |
2abae994 | 7867 | break; |
05ff989b AC |
7868 | default: |
7869 | if (!sals.nelts) | |
fd9b8c24 | 7870 | return 0; |
0101ce28 | 7871 | } |
c3f6f71d | 7872 | |
0fb4aa4b PA |
7873 | done: |
7874 | ||
4a64f543 | 7875 | /* Create a chain of things that always need to be cleaned up. */ |
c3f6f71d JM |
7876 | old_chain = make_cleanup (null_cleanup, 0); |
7877 | ||
0101ce28 JJ |
7878 | if (!pending) |
7879 | { | |
7880 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7881 | make_cleanup (xfree, sals.sals); | |
7882 | ||
7efd8fc2 TT |
7883 | /* Cleanup the canonical array but not its contents. */ |
7884 | make_cleanup (xfree, canonical.canonical); | |
0101ce28 | 7885 | } |
c3f6f71d | 7886 | |
c3f6f71d JM |
7887 | /* ----------------------------- SNIP ----------------------------- |
7888 | Anything added to the cleanup chain beyond this point is assumed | |
7889 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7890 | then the memory is not reclaimed. */ |
7891 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 7892 | |
7efd8fc2 | 7893 | /* Mark the contents of the canonical for cleanup. These go on |
80c99de1 | 7894 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7895 | for (i = 0; i < sals.nelts; i++) |
7896 | { | |
7efd8fc2 TT |
7897 | if (canonical.canonical[i] != NULL) |
7898 | make_cleanup (xfree, canonical.canonical[i]); | |
c3f6f71d JM |
7899 | } |
7900 | ||
7901 | /* Resolve all line numbers to PC's and verify that the addresses | |
7902 | are ok for the target. */ | |
0101ce28 | 7903 | if (!pending) |
23e7acfb | 7904 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 7905 | |
7a697b8d SS |
7906 | /* Fast tracepoints may have additional restrictions on location. */ |
7907 | if (type_wanted == bp_fast_tracepoint) | |
7908 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7909 | ||
c3f6f71d JM |
7910 | /* Verify that condition can be parsed, before setting any |
7911 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 7912 | breakpoint. */ |
0101ce28 | 7913 | if (!pending) |
c3f6f71d | 7914 | { |
2f069f6f | 7915 | if (parse_condition_and_thread) |
72b2ff0e VP |
7916 | { |
7917 | /* Here we only parse 'arg' to separate condition | |
7918 | from thread number, so parsing in context of first | |
7919 | sal is OK. When setting the breakpoint we'll | |
7920 | re-parse it in context of each sal. */ | |
7921 | cond_string = NULL; | |
7922 | thread = -1; | |
4a306c9a JB |
7923 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7924 | &thread, &task); | |
72b2ff0e VP |
7925 | if (cond_string) |
7926 | make_cleanup (xfree, cond_string); | |
7927 | } | |
2f069f6f | 7928 | else |
72b2ff0e VP |
7929 | { |
7930 | /* Create a private copy of condition string. */ | |
7931 | if (cond_string) | |
7932 | { | |
7933 | cond_string = xstrdup (cond_string); | |
7934 | make_cleanup (xfree, cond_string); | |
7935 | } | |
7936 | } | |
0fb4aa4b PA |
7937 | |
7938 | /* If the user is creating a static tracepoint by marker id | |
7939 | (strace -m MARKER_ID), then store the sals index, so that | |
7940 | breakpoint_re_set can try to match up which of the newly | |
7941 | found markers corresponds to this one, and, don't try to | |
7942 | expand multiple locations for each sal, given than SALS | |
7943 | already should contain all sals for MARKER_ID. */ | |
7944 | if (type_wanted == bp_static_tracepoint | |
7efd8fc2 | 7945 | && is_marker_spec (canonical.canonical[0])) |
0fb4aa4b PA |
7946 | { |
7947 | int i; | |
7948 | ||
7949 | for (i = 0; i < sals.nelts; ++i) | |
7950 | { | |
7951 | struct symtabs_and_lines expanded; | |
d9b3f62e | 7952 | struct tracepoint *tp; |
0fb4aa4b PA |
7953 | struct cleanup *old_chain; |
7954 | ||
7955 | expanded.nelts = 1; | |
7956 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7957 | expanded.sals[0] = sals.sals[i]; | |
7958 | old_chain = make_cleanup (xfree, expanded.sals); | |
7959 | ||
d9b3f62e PA |
7960 | tp = XCNEW (struct tracepoint); |
7961 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
7962 | canonical.canonical[i], | |
7963 | cond_string, type_wanted, | |
7964 | tempflag ? disp_del : disp_donttouch, | |
7965 | thread, task, ignore_count, ops, | |
7966 | from_tty, enabled, internal, | |
7967 | canonical.special_display); | |
0fb4aa4b PA |
7968 | /* Given that its possible to have multiple markers with |
7969 | the same string id, if the user is creating a static | |
7970 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
7971 | store the sals index, so that breakpoint_re_set can | |
7972 | try to match up which of the newly found markers | |
7973 | corresponds to this one */ | |
7974 | tp->static_trace_marker_id_idx = i; | |
d9b3f62e PA |
7975 | |
7976 | install_breakpoint (internal, &tp->base); | |
7977 | ||
7978 | do_cleanups (old_chain); | |
0fb4aa4b PA |
7979 | } |
7980 | } | |
7981 | else | |
7efd8fc2 | 7982 | create_breakpoints_sal (gdbarch, sals, &canonical, cond_string, |
3e43a32a MS |
7983 | type_wanted, |
7984 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 7985 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 7986 | enabled, internal); |
c906108c | 7987 | } |
0101ce28 JJ |
7988 | else |
7989 | { | |
0101ce28 JJ |
7990 | struct breakpoint *b; |
7991 | ||
0101ce28 JJ |
7992 | make_cleanup (xfree, copy_arg); |
7993 | ||
348d480f | 7994 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted, ops); |
84f4c1fe | 7995 | set_breakpoint_number (internal, b); |
72b2ff0e | 7996 | b->thread = -1; |
7efd8fc2 | 7997 | b->addr_string = canonical.canonical[0]; |
72b2ff0e | 7998 | b->cond_string = NULL; |
0101ce28 | 7999 | b->ignore_count = ignore_count; |
0101ce28 | 8000 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 8001 | b->condition_not_parsed = 1; |
41447f92 | 8002 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 8003 | b->pspace = current_program_space; |
84f4c1fe | 8004 | b->py_bp_object = NULL; |
74960c60 | 8005 | |
6c95b8df | 8006 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
8007 | && (b->type == bp_breakpoint |
8008 | || b->type == bp_hardware_breakpoint)) | |
8009 | b->enable_state = bp_startup_disabled; | |
8010 | ||
8d3788bd | 8011 | if (!internal) |
84f4c1fe PM |
8012 | /* Do not mention breakpoints with a negative number, |
8013 | but do notify observers. */ | |
8d3788bd VP |
8014 | mention (b); |
8015 | observer_notify_breakpoint_created (b); | |
0101ce28 JJ |
8016 | } |
8017 | ||
c3f6f71d | 8018 | if (sals.nelts > 1) |
95a42b64 | 8019 | { |
3e43a32a MS |
8020 | warning (_("Multiple breakpoints were set.\nUse the " |
8021 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 8022 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
8023 | } |
8024 | ||
80c99de1 PA |
8025 | /* That's it. Discard the cleanups for data inserted into the |
8026 | breakpoint. */ | |
8027 | discard_cleanups (bkpt_chain); | |
8028 | /* But cleanup everything else. */ | |
c3f6f71d | 8029 | do_cleanups (old_chain); |
217dc9e2 | 8030 | |
80c99de1 | 8031 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 8032 | update_global_location_list (1); |
fd9b8c24 PA |
8033 | |
8034 | return 1; | |
c3f6f71d | 8035 | } |
c906108c | 8036 | |
348d480f | 8037 | /* Set a breakpoint. |
72b2ff0e VP |
8038 | ARG is a string describing breakpoint address, |
8039 | condition, and thread. | |
8040 | FLAG specifies if a breakpoint is hardware on, | |
8041 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8042 | and BP_TEMPFLAG. */ | |
348d480f | 8043 | |
98deb0da | 8044 | static void |
72b2ff0e | 8045 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8046 | { |
72b2ff0e | 8047 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8048 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8049 | ? bp_hardware_breakpoint | |
8050 | : bp_breakpoint); | |
c3f6f71d | 8051 | |
8cdf0e15 VP |
8052 | create_breakpoint (get_current_arch (), |
8053 | arg, | |
8054 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8055 | tempflag, type_wanted, |
8cdf0e15 VP |
8056 | 0 /* Ignore count */, |
8057 | pending_break_support, | |
348d480f | 8058 | &bkpt_breakpoint_ops, |
8cdf0e15 | 8059 | from_tty, |
84f4c1fe PM |
8060 | 1 /* enabled */, |
8061 | 0 /* internal */); | |
c906108c SS |
8062 | } |
8063 | ||
c906108c SS |
8064 | /* Helper function for break_command_1 and disassemble_command. */ |
8065 | ||
8066 | void | |
fba45db2 | 8067 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8068 | { |
8069 | CORE_ADDR pc; | |
8070 | ||
8071 | if (sal->pc == 0 && sal->symtab != NULL) | |
8072 | { | |
8073 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8074 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8075 | sal->line, sal->symtab->filename); |
8076 | sal->pc = pc; | |
6a048695 | 8077 | |
4a64f543 MS |
8078 | /* If this SAL corresponds to a breakpoint inserted using a line |
8079 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8080 | if (sal->explicit_line) |
059acae7 | 8081 | skip_prologue_sal (sal); |
c906108c SS |
8082 | } |
8083 | ||
8084 | if (sal->section == 0 && sal->symtab != NULL) | |
8085 | { | |
8086 | struct blockvector *bv; | |
c5aa993b JM |
8087 | struct block *b; |
8088 | struct symbol *sym; | |
c906108c | 8089 | |
801e3a5b | 8090 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8091 | if (bv != NULL) |
8092 | { | |
7f0df278 | 8093 | sym = block_linkage_function (b); |
c906108c SS |
8094 | if (sym != NULL) |
8095 | { | |
8096 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8097 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8098 | } |
8099 | else | |
8100 | { | |
4a64f543 MS |
8101 | /* It really is worthwhile to have the section, so we'll |
8102 | just have to look harder. This case can be executed | |
8103 | if we have line numbers but no functions (as can | |
8104 | happen in assembly source). */ | |
c906108c | 8105 | |
c5aa993b | 8106 | struct minimal_symbol *msym; |
6c95b8df PA |
8107 | struct cleanup *old_chain = save_current_space_and_thread (); |
8108 | ||
8109 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8110 | |
8111 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8112 | if (msym) | |
714835d5 | 8113 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8114 | |
8115 | do_cleanups (old_chain); | |
c906108c SS |
8116 | } |
8117 | } | |
8118 | } | |
8119 | } | |
8120 | ||
8121 | void | |
fba45db2 | 8122 | break_command (char *arg, int from_tty) |
c906108c | 8123 | { |
db107f19 | 8124 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8125 | } |
8126 | ||
c906108c | 8127 | void |
fba45db2 | 8128 | tbreak_command (char *arg, int from_tty) |
c906108c | 8129 | { |
db107f19 | 8130 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8131 | } |
8132 | ||
c906108c | 8133 | static void |
fba45db2 | 8134 | hbreak_command (char *arg, int from_tty) |
c906108c | 8135 | { |
db107f19 | 8136 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8137 | } |
8138 | ||
8139 | static void | |
fba45db2 | 8140 | thbreak_command (char *arg, int from_tty) |
c906108c | 8141 | { |
db107f19 | 8142 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8143 | } |
8144 | ||
8145 | static void | |
fba45db2 | 8146 | stop_command (char *arg, int from_tty) |
c906108c | 8147 | { |
a3f17187 | 8148 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8149 | Usage: stop in <function | address>\n\ |
a3f17187 | 8150 | stop at <line>\n")); |
c906108c SS |
8151 | } |
8152 | ||
8153 | static void | |
fba45db2 | 8154 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8155 | { |
8156 | int badInput = 0; | |
8157 | ||
c5aa993b | 8158 | if (arg == (char *) NULL) |
c906108c SS |
8159 | badInput = 1; |
8160 | else if (*arg != '*') | |
8161 | { | |
8162 | char *argptr = arg; | |
8163 | int hasColon = 0; | |
8164 | ||
4a64f543 | 8165 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8166 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8167 | function/method name. */ |
c906108c | 8168 | while (*argptr && !hasColon) |
c5aa993b JM |
8169 | { |
8170 | hasColon = (*argptr == ':'); | |
8171 | argptr++; | |
8172 | } | |
c906108c SS |
8173 | |
8174 | if (hasColon) | |
c5aa993b | 8175 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8176 | else |
c5aa993b | 8177 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8178 | } |
8179 | ||
8180 | if (badInput) | |
a3f17187 | 8181 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8182 | else |
db107f19 | 8183 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8184 | } |
8185 | ||
8186 | static void | |
fba45db2 | 8187 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8188 | { |
8189 | int badInput = 0; | |
8190 | ||
c5aa993b | 8191 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8192 | badInput = 1; |
8193 | else | |
8194 | { | |
8195 | char *argptr = arg; | |
8196 | int hasColon = 0; | |
8197 | ||
4a64f543 MS |
8198 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8199 | it is probably a line number. */ | |
c906108c | 8200 | while (*argptr && !hasColon) |
c5aa993b JM |
8201 | { |
8202 | hasColon = (*argptr == ':'); | |
8203 | argptr++; | |
8204 | } | |
c906108c SS |
8205 | |
8206 | if (hasColon) | |
c5aa993b | 8207 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8208 | else |
c5aa993b | 8209 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8210 | } |
8211 | ||
8212 | if (badInput) | |
a3f17187 | 8213 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8214 | else |
db107f19 | 8215 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8216 | } |
8217 | ||
f1310107 TJB |
8218 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
8219 | ranged breakpoints. */ | |
8220 | ||
8221 | static int | |
8222 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
8223 | struct address_space *aspace, | |
8224 | CORE_ADDR bp_addr) | |
8225 | { | |
8226 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, | |
8227 | bl->length, aspace, bp_addr); | |
8228 | } | |
8229 | ||
8230 | /* Implement the "resources_needed" breakpoint_ops method for | |
8231 | ranged breakpoints. */ | |
8232 | ||
8233 | static int | |
8234 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
8235 | { | |
8236 | return target_ranged_break_num_registers (); | |
8237 | } | |
8238 | ||
8239 | /* Implement the "print_it" breakpoint_ops method for | |
8240 | ranged breakpoints. */ | |
8241 | ||
8242 | static enum print_stop_action | |
348d480f | 8243 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 8244 | { |
348d480f | 8245 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 8246 | struct bp_location *bl = b->loc; |
79a45e25 | 8247 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8248 | |
8249 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8250 | ||
8251 | /* Ranged breakpoints have only one location. */ | |
8252 | gdb_assert (bl && bl->next == NULL); | |
8253 | ||
8254 | annotate_breakpoint (b->number); | |
8255 | if (b->disposition == disp_del) | |
8256 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
8257 | else | |
8258 | ui_out_text (uiout, "\nRanged breakpoint "); | |
8259 | if (ui_out_is_mi_like_p (uiout)) | |
8260 | { | |
8261 | ui_out_field_string (uiout, "reason", | |
8262 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8263 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8264 | } | |
8265 | ui_out_field_int (uiout, "bkptno", b->number); | |
8266 | ui_out_text (uiout, ", "); | |
8267 | ||
8268 | return PRINT_SRC_AND_LOC; | |
8269 | } | |
8270 | ||
8271 | /* Implement the "print_one" breakpoint_ops method for | |
8272 | ranged breakpoints. */ | |
8273 | ||
8274 | static void | |
8275 | print_one_ranged_breakpoint (struct breakpoint *b, | |
8276 | struct bp_location **last_loc) | |
8277 | { | |
8278 | struct bp_location *bl = b->loc; | |
8279 | struct value_print_options opts; | |
79a45e25 | 8280 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8281 | |
8282 | /* Ranged breakpoints have only one location. */ | |
8283 | gdb_assert (bl && bl->next == NULL); | |
8284 | ||
8285 | get_user_print_options (&opts); | |
8286 | ||
8287 | if (opts.addressprint) | |
8288 | /* We don't print the address range here, it will be printed later | |
8289 | by print_one_detail_ranged_breakpoint. */ | |
8290 | ui_out_field_skip (uiout, "addr"); | |
8291 | annotate_field (5); | |
8292 | print_breakpoint_location (b, bl); | |
8293 | *last_loc = bl; | |
8294 | } | |
8295 | ||
8296 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8297 | ranged breakpoints. */ | |
8298 | ||
8299 | static void | |
8300 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
8301 | struct ui_out *uiout) | |
8302 | { | |
8303 | CORE_ADDR address_start, address_end; | |
8304 | struct bp_location *bl = b->loc; | |
8305 | struct ui_stream *stb = ui_out_stream_new (uiout); | |
8306 | struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb); | |
8307 | ||
8308 | gdb_assert (bl); | |
8309 | ||
8310 | address_start = bl->address; | |
8311 | address_end = address_start + bl->length - 1; | |
8312 | ||
8313 | ui_out_text (uiout, "\taddress range: "); | |
8314 | fprintf_unfiltered (stb->stream, "[%s, %s]", | |
8315 | print_core_address (bl->gdbarch, address_start), | |
8316 | print_core_address (bl->gdbarch, address_end)); | |
8317 | ui_out_field_stream (uiout, "addr", stb); | |
8318 | ui_out_text (uiout, "\n"); | |
8319 | ||
8320 | do_cleanups (cleanup); | |
8321 | } | |
8322 | ||
8323 | /* Implement the "print_mention" breakpoint_ops method for | |
8324 | ranged breakpoints. */ | |
8325 | ||
8326 | static void | |
8327 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
8328 | { | |
8329 | struct bp_location *bl = b->loc; | |
79a45e25 | 8330 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8331 | |
8332 | gdb_assert (bl); | |
8333 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8334 | ||
8335 | if (ui_out_is_mi_like_p (uiout)) | |
8336 | return; | |
8337 | ||
8338 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
8339 | b->number, paddress (bl->gdbarch, bl->address), | |
8340 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
8341 | } | |
8342 | ||
8343 | /* Implement the "print_recreate" breakpoint_ops method for | |
8344 | ranged breakpoints. */ | |
8345 | ||
8346 | static void | |
8347 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
8348 | { | |
8349 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
8350 | b->addr_string_range_end); | |
d9b3f62e | 8351 | print_recreate_thread (b, fp); |
f1310107 TJB |
8352 | } |
8353 | ||
8354 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
8355 | ||
2060206e | 8356 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
8357 | |
8358 | /* Find the address where the end of the breakpoint range should be | |
8359 | placed, given the SAL of the end of the range. This is so that if | |
8360 | the user provides a line number, the end of the range is set to the | |
8361 | last instruction of the given line. */ | |
8362 | ||
8363 | static CORE_ADDR | |
8364 | find_breakpoint_range_end (struct symtab_and_line sal) | |
8365 | { | |
8366 | CORE_ADDR end; | |
8367 | ||
8368 | /* If the user provided a PC value, use it. Otherwise, | |
8369 | find the address of the end of the given location. */ | |
8370 | if (sal.explicit_pc) | |
8371 | end = sal.pc; | |
8372 | else | |
8373 | { | |
8374 | int ret; | |
8375 | CORE_ADDR start; | |
8376 | ||
8377 | ret = find_line_pc_range (sal, &start, &end); | |
8378 | if (!ret) | |
8379 | error (_("Could not find location of the end of the range.")); | |
8380 | ||
8381 | /* find_line_pc_range returns the start of the next line. */ | |
8382 | end--; | |
8383 | } | |
8384 | ||
8385 | return end; | |
8386 | } | |
8387 | ||
8388 | /* Implement the "break-range" CLI command. */ | |
8389 | ||
8390 | static void | |
8391 | break_range_command (char *arg, int from_tty) | |
8392 | { | |
8393 | char *arg_start, *addr_string_start, *addr_string_end; | |
8394 | struct linespec_result canonical_start, canonical_end; | |
8395 | int bp_count, can_use_bp, length; | |
8396 | CORE_ADDR end; | |
8397 | struct breakpoint *b; | |
8398 | struct symtab_and_line sal_start, sal_end; | |
8399 | struct symtabs_and_lines sals_start, sals_end; | |
8400 | struct cleanup *cleanup_bkpt; | |
8401 | ||
8402 | /* We don't support software ranged breakpoints. */ | |
8403 | if (target_ranged_break_num_registers () < 0) | |
8404 | error (_("This target does not support hardware ranged breakpoints.")); | |
8405 | ||
8406 | bp_count = hw_breakpoint_used_count (); | |
8407 | bp_count += target_ranged_break_num_registers (); | |
8408 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
8409 | bp_count, 0); | |
8410 | if (can_use_bp < 0) | |
8411 | error (_("Hardware breakpoints used exceeds limit.")); | |
8412 | ||
8413 | if (arg == NULL || arg[0] == '\0') | |
8414 | error(_("No address range specified.")); | |
8415 | ||
8416 | sals_start.sals = NULL; | |
8417 | sals_start.nelts = 0; | |
8418 | init_linespec_result (&canonical_start); | |
8419 | ||
8420 | while (*arg == ' ' || *arg == '\t') | |
8421 | arg++; | |
8422 | ||
58438ac1 | 8423 | parse_breakpoint_sals (&arg, &sals_start, &canonical_start); |
f1310107 TJB |
8424 | |
8425 | sal_start = sals_start.sals[0]; | |
8426 | addr_string_start = canonical_start.canonical[0]; | |
8427 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); | |
8428 | xfree (sals_start.sals); | |
8429 | xfree (canonical_start.canonical); | |
8430 | ||
8431 | if (arg[0] != ',') | |
8432 | error (_("Too few arguments.")); | |
8433 | else if (sals_start.nelts == 0) | |
8434 | error (_("Could not find location of the beginning of the range.")); | |
8435 | else if (sals_start.nelts != 1) | |
8436 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8437 | ||
8438 | resolve_sal_pc (&sal_start); | |
8439 | ||
8440 | arg++; /* Skip the comma. */ | |
8441 | while (*arg == ' ' || *arg == '\t') | |
8442 | arg++; | |
8443 | ||
8444 | /* Parse the end location. */ | |
8445 | ||
8446 | sals_end.sals = NULL; | |
8447 | sals_end.nelts = 0; | |
8448 | init_linespec_result (&canonical_end); | |
8449 | arg_start = arg; | |
8450 | ||
423f41a5 | 8451 | /* We call decode_line_1 directly here instead of using |
f1310107 TJB |
8452 | parse_breakpoint_sals because we need to specify the start location's |
8453 | symtab and line as the default symtab and line for the end of the | |
8454 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
8455 | where +14 means 14 lines from the start location. */ | |
8456 | sals_end = decode_line_1 (&arg, 1, sal_start.symtab, sal_start.line, | |
58438ac1 | 8457 | &canonical_end); |
f1310107 TJB |
8458 | |
8459 | /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */ | |
8460 | if (canonical_end.canonical == NULL) | |
38a714bb | 8461 | canonical_end.canonical = xcalloc (1, sizeof (char *)); |
f1310107 TJB |
8462 | /* Add the string if not present. */ |
8463 | if (arg_start != arg && canonical_end.canonical[0] == NULL) | |
8464 | canonical_end.canonical[0] = savestring (arg_start, arg - arg_start); | |
8465 | ||
8466 | sal_end = sals_end.sals[0]; | |
8467 | addr_string_end = canonical_end.canonical[0]; | |
8468 | make_cleanup (xfree, addr_string_end); | |
8469 | xfree (sals_end.sals); | |
8470 | xfree (canonical_end.canonical); | |
8471 | ||
8472 | if (sals_end.nelts == 0) | |
8473 | error (_("Could not find location of the end of the range.")); | |
8474 | else if (sals_end.nelts != 1) | |
8475 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8476 | ||
8477 | resolve_sal_pc (&sal_end); | |
8478 | ||
8479 | end = find_breakpoint_range_end (sal_end); | |
8480 | if (sal_start.pc > end) | |
177b42fe | 8481 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
8482 | |
8483 | length = end - sal_start.pc + 1; | |
8484 | if (length < 0) | |
8485 | /* Length overflowed. */ | |
8486 | error (_("Address range too large.")); | |
8487 | else if (length == 1) | |
8488 | { | |
8489 | /* This range is simple enough to be handled by | |
8490 | the `hbreak' command. */ | |
8491 | hbreak_command (addr_string_start, 1); | |
8492 | ||
8493 | do_cleanups (cleanup_bkpt); | |
8494 | ||
8495 | return; | |
8496 | } | |
8497 | ||
8498 | /* Now set up the breakpoint. */ | |
8499 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 8500 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
8501 | set_breakpoint_count (breakpoint_count + 1); |
8502 | b->number = breakpoint_count; | |
8503 | b->disposition = disp_donttouch; | |
8504 | b->addr_string = addr_string_start; | |
8505 | b->addr_string_range_end = addr_string_end; | |
f1310107 TJB |
8506 | b->loc->length = length; |
8507 | ||
8508 | discard_cleanups (cleanup_bkpt); | |
8509 | ||
8510 | mention (b); | |
8d3788bd | 8511 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
8512 | update_global_location_list (1); |
8513 | } | |
8514 | ||
4a64f543 MS |
8515 | /* Return non-zero if EXP is verified as constant. Returned zero |
8516 | means EXP is variable. Also the constant detection may fail for | |
8517 | some constant expressions and in such case still falsely return | |
8518 | zero. */ | |
65d79d4b SDJ |
8519 | static int |
8520 | watchpoint_exp_is_const (const struct expression *exp) | |
8521 | { | |
8522 | int i = exp->nelts; | |
8523 | ||
8524 | while (i > 0) | |
8525 | { | |
8526 | int oplenp, argsp; | |
8527 | ||
8528 | /* We are only interested in the descriptor of each element. */ | |
8529 | operator_length (exp, i, &oplenp, &argsp); | |
8530 | i -= oplenp; | |
8531 | ||
8532 | switch (exp->elts[i].opcode) | |
8533 | { | |
8534 | case BINOP_ADD: | |
8535 | case BINOP_SUB: | |
8536 | case BINOP_MUL: | |
8537 | case BINOP_DIV: | |
8538 | case BINOP_REM: | |
8539 | case BINOP_MOD: | |
8540 | case BINOP_LSH: | |
8541 | case BINOP_RSH: | |
8542 | case BINOP_LOGICAL_AND: | |
8543 | case BINOP_LOGICAL_OR: | |
8544 | case BINOP_BITWISE_AND: | |
8545 | case BINOP_BITWISE_IOR: | |
8546 | case BINOP_BITWISE_XOR: | |
8547 | case BINOP_EQUAL: | |
8548 | case BINOP_NOTEQUAL: | |
8549 | case BINOP_LESS: | |
8550 | case BINOP_GTR: | |
8551 | case BINOP_LEQ: | |
8552 | case BINOP_GEQ: | |
8553 | case BINOP_REPEAT: | |
8554 | case BINOP_COMMA: | |
8555 | case BINOP_EXP: | |
8556 | case BINOP_MIN: | |
8557 | case BINOP_MAX: | |
8558 | case BINOP_INTDIV: | |
8559 | case BINOP_CONCAT: | |
8560 | case BINOP_IN: | |
8561 | case BINOP_RANGE: | |
8562 | case TERNOP_COND: | |
8563 | case TERNOP_SLICE: | |
8564 | case TERNOP_SLICE_COUNT: | |
8565 | ||
8566 | case OP_LONG: | |
8567 | case OP_DOUBLE: | |
8568 | case OP_DECFLOAT: | |
8569 | case OP_LAST: | |
8570 | case OP_COMPLEX: | |
8571 | case OP_STRING: | |
8572 | case OP_BITSTRING: | |
8573 | case OP_ARRAY: | |
8574 | case OP_TYPE: | |
8575 | case OP_NAME: | |
8576 | case OP_OBJC_NSSTRING: | |
8577 | ||
8578 | case UNOP_NEG: | |
8579 | case UNOP_LOGICAL_NOT: | |
8580 | case UNOP_COMPLEMENT: | |
8581 | case UNOP_ADDR: | |
8582 | case UNOP_HIGH: | |
4a64f543 MS |
8583 | /* Unary, binary and ternary operators: We have to check |
8584 | their operands. If they are constant, then so is the | |
8585 | result of that operation. For instance, if A and B are | |
8586 | determined to be constants, then so is "A + B". | |
8587 | ||
8588 | UNOP_IND is one exception to the rule above, because the | |
8589 | value of *ADDR is not necessarily a constant, even when | |
8590 | ADDR is. */ | |
65d79d4b SDJ |
8591 | break; |
8592 | ||
8593 | case OP_VAR_VALUE: | |
8594 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8595 | |
65d79d4b | 8596 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8597 | possible that a buggy compiler could mark a variable as |
8598 | constant even when it is not, and TYPE_CONST would return | |
8599 | true in this case, while SYMBOL_CLASS wouldn't. | |
8600 | ||
8601 | We also have to check for function symbols because they | |
8602 | are always constant. */ | |
65d79d4b SDJ |
8603 | { |
8604 | struct symbol *s = exp->elts[i + 2].symbol; | |
8605 | ||
8606 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8607 | && SYMBOL_CLASS (s) != LOC_CONST | |
8608 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8609 | return 0; | |
8610 | break; | |
8611 | } | |
8612 | ||
8613 | /* The default action is to return 0 because we are using | |
8614 | the optimistic approach here: If we don't know something, | |
8615 | then it is not a constant. */ | |
8616 | default: | |
8617 | return 0; | |
8618 | } | |
8619 | } | |
8620 | ||
8621 | return 1; | |
8622 | } | |
8623 | ||
3a5c3e22 PA |
8624 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
8625 | ||
8626 | static void | |
8627 | dtor_watchpoint (struct breakpoint *self) | |
8628 | { | |
8629 | struct watchpoint *w = (struct watchpoint *) self; | |
8630 | ||
8631 | xfree (w->cond_exp); | |
8632 | xfree (w->exp); | |
8633 | xfree (w->exp_string); | |
8634 | xfree (w->exp_string_reparse); | |
8635 | value_free (w->val); | |
8636 | ||
8637 | base_breakpoint_ops.dtor (self); | |
8638 | } | |
8639 | ||
348d480f PA |
8640 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
8641 | ||
8642 | static void | |
8643 | re_set_watchpoint (struct breakpoint *b) | |
8644 | { | |
3a5c3e22 PA |
8645 | struct watchpoint *w = (struct watchpoint *) b; |
8646 | ||
348d480f PA |
8647 | /* Watchpoint can be either on expression using entirely global |
8648 | variables, or it can be on local variables. | |
8649 | ||
8650 | Watchpoints of the first kind are never auto-deleted, and even | |
8651 | persist across program restarts. Since they can use variables | |
8652 | from shared libraries, we need to reparse expression as libraries | |
8653 | are loaded and unloaded. | |
8654 | ||
8655 | Watchpoints on local variables can also change meaning as result | |
8656 | of solib event. For example, if a watchpoint uses both a local | |
8657 | and a global variables in expression, it's a local watchpoint, | |
8658 | but unloading of a shared library will make the expression | |
8659 | invalid. This is not a very common use case, but we still | |
8660 | re-evaluate expression, to avoid surprises to the user. | |
8661 | ||
8662 | Note that for local watchpoints, we re-evaluate it only if | |
8663 | watchpoints frame id is still valid. If it's not, it means the | |
8664 | watchpoint is out of scope and will be deleted soon. In fact, | |
8665 | I'm not sure we'll ever be called in this case. | |
8666 | ||
8667 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 8668 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 8669 | |
3a5c3e22 PA |
8670 | Don't do anything about disabled watchpoints, since they will be |
8671 | reevaluated again when enabled. */ | |
8672 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
8673 | } |
8674 | ||
77b06cd7 TJB |
8675 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8676 | ||
8677 | static int | |
8678 | insert_watchpoint (struct bp_location *bl) | |
8679 | { | |
3a5c3e22 PA |
8680 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8681 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8682 | |
8683 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8684 | w->cond_exp); |
77b06cd7 TJB |
8685 | } |
8686 | ||
8687 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8688 | ||
8689 | static int | |
8690 | remove_watchpoint (struct bp_location *bl) | |
8691 | { | |
3a5c3e22 PA |
8692 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8693 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8694 | |
8695 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8696 | w->cond_exp); |
e09342b5 TJB |
8697 | } |
8698 | ||
e09342b5 | 8699 | static int |
348d480f PA |
8700 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
8701 | struct address_space *aspace, CORE_ADDR bp_addr) | |
e09342b5 | 8702 | { |
348d480f | 8703 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 8704 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 8705 | |
348d480f PA |
8706 | /* Continuable hardware watchpoints are treated as non-existent if the |
8707 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
8708 | some data address). Otherwise gdb won't stop on a break instruction | |
8709 | in the code (not from a breakpoint) when a hardware watchpoint has | |
8710 | been defined. Also skip watchpoints which we know did not trigger | |
8711 | (did not match the data address). */ | |
8712 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 8713 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 8714 | return 0; |
9c06b0b4 | 8715 | |
348d480f | 8716 | return 1; |
9c06b0b4 TJB |
8717 | } |
8718 | ||
348d480f PA |
8719 | static void |
8720 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 8721 | { |
348d480f | 8722 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 8723 | |
348d480f | 8724 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
8725 | } |
8726 | ||
8727 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 8728 | hardware watchpoints. */ |
9c06b0b4 TJB |
8729 | |
8730 | static int | |
348d480f | 8731 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 8732 | { |
3a5c3e22 PA |
8733 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8734 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
8735 | |
8736 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
8737 | } |
8738 | ||
8739 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 8740 | hardware watchpoints. */ |
9c06b0b4 TJB |
8741 | |
8742 | static int | |
348d480f | 8743 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 8744 | { |
efa80663 PA |
8745 | /* Read and access watchpoints only work with hardware support. */ |
8746 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
8747 | } |
8748 | ||
9c06b0b4 | 8749 | static enum print_stop_action |
348d480f | 8750 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 8751 | { |
348d480f PA |
8752 | struct cleanup *old_chain; |
8753 | struct breakpoint *b; | |
8754 | const struct bp_location *bl; | |
8755 | struct ui_stream *stb; | |
8756 | enum print_stop_action result; | |
3a5c3e22 | 8757 | struct watchpoint *w; |
79a45e25 | 8758 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8759 | |
8760 | gdb_assert (bs->bp_location_at != NULL); | |
8761 | ||
8762 | bl = bs->bp_location_at; | |
8763 | b = bs->breakpoint_at; | |
3a5c3e22 | 8764 | w = (struct watchpoint *) b; |
348d480f PA |
8765 | |
8766 | stb = ui_out_stream_new (uiout); | |
8767 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
9c06b0b4 TJB |
8768 | |
8769 | switch (b->type) | |
8770 | { | |
348d480f | 8771 | case bp_watchpoint: |
9c06b0b4 TJB |
8772 | case bp_hardware_watchpoint: |
8773 | annotate_watchpoint (b->number); | |
8774 | if (ui_out_is_mi_like_p (uiout)) | |
8775 | ui_out_field_string | |
8776 | (uiout, "reason", | |
8777 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
8778 | mention (b); |
8779 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8780 | ui_out_text (uiout, "\nOld value = "); | |
8781 | watchpoint_value_print (bs->old_val, stb->stream); | |
8782 | ui_out_field_stream (uiout, "old", stb); | |
8783 | ui_out_text (uiout, "\nNew value = "); | |
3a5c3e22 | 8784 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8785 | ui_out_field_stream (uiout, "new", stb); |
8786 | ui_out_text (uiout, "\n"); | |
8787 | /* More than one watchpoint may have been triggered. */ | |
8788 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8789 | break; |
8790 | ||
8791 | case bp_read_watchpoint: | |
8792 | if (ui_out_is_mi_like_p (uiout)) | |
8793 | ui_out_field_string | |
8794 | (uiout, "reason", | |
8795 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
8796 | mention (b); |
8797 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8798 | ui_out_text (uiout, "\nValue = "); | |
3a5c3e22 | 8799 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8800 | ui_out_field_stream (uiout, "value", stb); |
8801 | ui_out_text (uiout, "\n"); | |
8802 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8803 | break; |
8804 | ||
8805 | case bp_access_watchpoint: | |
348d480f PA |
8806 | if (bs->old_val != NULL) |
8807 | { | |
8808 | annotate_watchpoint (b->number); | |
8809 | if (ui_out_is_mi_like_p (uiout)) | |
8810 | ui_out_field_string | |
8811 | (uiout, "reason", | |
8812 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8813 | mention (b); | |
8814 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8815 | ui_out_text (uiout, "\nOld value = "); | |
8816 | watchpoint_value_print (bs->old_val, stb->stream); | |
8817 | ui_out_field_stream (uiout, "old", stb); | |
8818 | ui_out_text (uiout, "\nNew value = "); | |
8819 | } | |
8820 | else | |
8821 | { | |
8822 | mention (b); | |
8823 | if (ui_out_is_mi_like_p (uiout)) | |
8824 | ui_out_field_string | |
8825 | (uiout, "reason", | |
8826 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8827 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8828 | ui_out_text (uiout, "\nValue = "); | |
8829 | } | |
3a5c3e22 | 8830 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8831 | ui_out_field_stream (uiout, "new", stb); |
8832 | ui_out_text (uiout, "\n"); | |
8833 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8834 | break; |
8835 | default: | |
348d480f | 8836 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
8837 | } |
8838 | ||
348d480f PA |
8839 | do_cleanups (old_chain); |
8840 | return result; | |
8841 | } | |
8842 | ||
8843 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
8844 | watchpoints. */ | |
8845 | ||
8846 | static void | |
8847 | print_mention_watchpoint (struct breakpoint *b) | |
8848 | { | |
8849 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 8850 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 8851 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8852 | |
8853 | switch (b->type) | |
8854 | { | |
8855 | case bp_watchpoint: | |
8856 | ui_out_text (uiout, "Watchpoint "); | |
8857 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8858 | break; | |
8859 | case bp_hardware_watchpoint: | |
8860 | ui_out_text (uiout, "Hardware watchpoint "); | |
8861 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8862 | break; | |
8863 | case bp_read_watchpoint: | |
8864 | ui_out_text (uiout, "Hardware read watchpoint "); | |
8865 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
8866 | break; | |
8867 | case bp_access_watchpoint: | |
8868 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
8869 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
8870 | break; | |
8871 | default: | |
8872 | internal_error (__FILE__, __LINE__, | |
8873 | _("Invalid hardware watchpoint type.")); | |
8874 | } | |
8875 | ||
8876 | ui_out_field_int (uiout, "number", b->number); | |
8877 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 8878 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
8879 | do_cleanups (ui_out_chain); |
8880 | } | |
8881 | ||
8882 | /* Implement the "print_recreate" breakpoint_ops method for | |
8883 | watchpoints. */ | |
8884 | ||
8885 | static void | |
8886 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
8887 | { | |
3a5c3e22 PA |
8888 | struct watchpoint *w = (struct watchpoint *) b; |
8889 | ||
348d480f PA |
8890 | switch (b->type) |
8891 | { | |
8892 | case bp_watchpoint: | |
8893 | case bp_hardware_watchpoint: | |
8894 | fprintf_unfiltered (fp, "watch"); | |
8895 | break; | |
8896 | case bp_read_watchpoint: | |
8897 | fprintf_unfiltered (fp, "rwatch"); | |
8898 | break; | |
8899 | case bp_access_watchpoint: | |
8900 | fprintf_unfiltered (fp, "awatch"); | |
8901 | break; | |
8902 | default: | |
8903 | internal_error (__FILE__, __LINE__, | |
8904 | _("Invalid watchpoint type.")); | |
8905 | } | |
8906 | ||
3a5c3e22 | 8907 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 8908 | print_recreate_thread (b, fp); |
348d480f PA |
8909 | } |
8910 | ||
8911 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
8912 | ||
2060206e | 8913 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
8914 | |
8915 | /* Implement the "insert" breakpoint_ops method for | |
8916 | masked hardware watchpoints. */ | |
8917 | ||
8918 | static int | |
8919 | insert_masked_watchpoint (struct bp_location *bl) | |
8920 | { | |
3a5c3e22 PA |
8921 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8922 | ||
8923 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
8924 | bl->watchpoint_type); |
8925 | } | |
8926 | ||
8927 | /* Implement the "remove" breakpoint_ops method for | |
8928 | masked hardware watchpoints. */ | |
8929 | ||
8930 | static int | |
8931 | remove_masked_watchpoint (struct bp_location *bl) | |
8932 | { | |
3a5c3e22 PA |
8933 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8934 | ||
8935 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
8936 | bl->watchpoint_type); |
8937 | } | |
8938 | ||
8939 | /* Implement the "resources_needed" breakpoint_ops method for | |
8940 | masked hardware watchpoints. */ | |
8941 | ||
8942 | static int | |
8943 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
8944 | { | |
3a5c3e22 PA |
8945 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8946 | ||
8947 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
8948 | } |
8949 | ||
8950 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
8951 | masked hardware watchpoints. */ | |
8952 | ||
8953 | static int | |
8954 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
8955 | { | |
8956 | return 0; | |
8957 | } | |
8958 | ||
8959 | /* Implement the "print_it" breakpoint_ops method for | |
8960 | masked hardware watchpoints. */ | |
8961 | ||
8962 | static enum print_stop_action | |
8963 | print_it_masked_watchpoint (bpstat bs) | |
8964 | { | |
8965 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 8966 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8967 | |
8968 | /* Masked watchpoints have only one location. */ | |
8969 | gdb_assert (b->loc && b->loc->next == NULL); | |
8970 | ||
8971 | switch (b->type) | |
8972 | { | |
8973 | case bp_hardware_watchpoint: | |
8974 | annotate_watchpoint (b->number); | |
8975 | if (ui_out_is_mi_like_p (uiout)) | |
8976 | ui_out_field_string | |
8977 | (uiout, "reason", | |
8978 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
8979 | break; | |
8980 | ||
8981 | case bp_read_watchpoint: | |
8982 | if (ui_out_is_mi_like_p (uiout)) | |
8983 | ui_out_field_string | |
8984 | (uiout, "reason", | |
8985 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
8986 | break; | |
8987 | ||
8988 | case bp_access_watchpoint: | |
8989 | if (ui_out_is_mi_like_p (uiout)) | |
8990 | ui_out_field_string | |
8991 | (uiout, "reason", | |
8992 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8993 | break; | |
8994 | default: | |
8995 | internal_error (__FILE__, __LINE__, | |
8996 | _("Invalid hardware watchpoint type.")); | |
8997 | } | |
8998 | ||
8999 | mention (b); | |
9c06b0b4 TJB |
9000 | ui_out_text (uiout, _("\n\ |
9001 | Check the underlying instruction at PC for the memory\n\ | |
9002 | address and value which triggered this watchpoint.\n")); | |
9003 | ui_out_text (uiout, "\n"); | |
9004 | ||
9005 | /* More than one watchpoint may have been triggered. */ | |
9006 | return PRINT_UNKNOWN; | |
9007 | } | |
9008 | ||
9009 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9010 | masked hardware watchpoints. */ | |
9011 | ||
9012 | static void | |
9013 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
9014 | struct ui_out *uiout) | |
9015 | { | |
3a5c3e22 PA |
9016 | struct watchpoint *w = (struct watchpoint *) b; |
9017 | ||
9c06b0b4 TJB |
9018 | /* Masked watchpoints have only one location. */ |
9019 | gdb_assert (b->loc && b->loc->next == NULL); | |
9020 | ||
9021 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 9022 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
9023 | ui_out_text (uiout, "\n"); |
9024 | } | |
9025 | ||
9026 | /* Implement the "print_mention" breakpoint_ops method for | |
9027 | masked hardware watchpoints. */ | |
9028 | ||
9029 | static void | |
9030 | print_mention_masked_watchpoint (struct breakpoint *b) | |
9031 | { | |
3a5c3e22 | 9032 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 9033 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
9034 | struct cleanup *ui_out_chain; |
9035 | ||
9036 | switch (b->type) | |
9037 | { | |
9038 | case bp_hardware_watchpoint: | |
9039 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
9040 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9041 | break; | |
9042 | case bp_read_watchpoint: | |
9043 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
9044 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
9045 | break; | |
9046 | case bp_access_watchpoint: | |
9047 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
9048 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
9049 | break; | |
9050 | default: | |
9051 | internal_error (__FILE__, __LINE__, | |
9052 | _("Invalid hardware watchpoint type.")); | |
9053 | } | |
9054 | ||
9055 | ui_out_field_int (uiout, "number", b->number); | |
9056 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 9057 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
9058 | do_cleanups (ui_out_chain); |
9059 | } | |
9060 | ||
9061 | /* Implement the "print_recreate" breakpoint_ops method for | |
9062 | masked hardware watchpoints. */ | |
9063 | ||
9064 | static void | |
9065 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
9066 | { | |
3a5c3e22 | 9067 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
9068 | char tmp[40]; |
9069 | ||
9070 | switch (b->type) | |
9071 | { | |
9072 | case bp_hardware_watchpoint: | |
9073 | fprintf_unfiltered (fp, "watch"); | |
9074 | break; | |
9075 | case bp_read_watchpoint: | |
9076 | fprintf_unfiltered (fp, "rwatch"); | |
9077 | break; | |
9078 | case bp_access_watchpoint: | |
9079 | fprintf_unfiltered (fp, "awatch"); | |
9080 | break; | |
9081 | default: | |
9082 | internal_error (__FILE__, __LINE__, | |
9083 | _("Invalid hardware watchpoint type.")); | |
9084 | } | |
9085 | ||
3a5c3e22 PA |
9086 | sprintf_vma (tmp, w->hw_wp_mask); |
9087 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 9088 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
9089 | } |
9090 | ||
9091 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
9092 | ||
2060206e | 9093 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
9094 | |
9095 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
9096 | ||
9097 | static int | |
9098 | is_masked_watchpoint (const struct breakpoint *b) | |
9099 | { | |
9100 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
9101 | } | |
9102 | ||
53a5351d JM |
9103 | /* accessflag: hw_write: watch write, |
9104 | hw_read: watch read, | |
9105 | hw_access: watch access (read or write) */ | |
c906108c | 9106 | static void |
84f4c1fe PM |
9107 | watch_command_1 (char *arg, int accessflag, int from_tty, |
9108 | int just_location, int internal) | |
c906108c | 9109 | { |
a9634178 | 9110 | volatile struct gdb_exception e; |
d983da9c | 9111 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 9112 | struct expression *exp; |
60e1c644 | 9113 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 9114 | struct value *val, *mark, *result; |
c906108c | 9115 | struct frame_info *frame; |
c906108c SS |
9116 | char *exp_start = NULL; |
9117 | char *exp_end = NULL; | |
9c06b0b4 TJB |
9118 | char *tok, *end_tok; |
9119 | int toklen = -1; | |
c906108c SS |
9120 | char *cond_start = NULL; |
9121 | char *cond_end = NULL; | |
c906108c | 9122 | enum bptype bp_type; |
37e4754d | 9123 | int thread = -1; |
0cf6dd15 | 9124 | int pc = 0; |
9c06b0b4 TJB |
9125 | /* Flag to indicate whether we are going to use masks for |
9126 | the hardware watchpoint. */ | |
9127 | int use_mask = 0; | |
9128 | CORE_ADDR mask = 0; | |
3a5c3e22 | 9129 | struct watchpoint *w; |
c906108c | 9130 | |
37e4754d LM |
9131 | /* Make sure that we actually have parameters to parse. */ |
9132 | if (arg != NULL && arg[0] != '\0') | |
9133 | { | |
9c06b0b4 | 9134 | char *value_start; |
37e4754d | 9135 | |
9c06b0b4 TJB |
9136 | /* Look for "parameter value" pairs at the end |
9137 | of the arguments string. */ | |
9138 | for (tok = arg + strlen (arg) - 1; tok > arg; tok--) | |
9139 | { | |
9140 | /* Skip whitespace at the end of the argument list. */ | |
9141 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9142 | tok--; | |
9143 | ||
9144 | /* Find the beginning of the last token. | |
9145 | This is the value of the parameter. */ | |
9146 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9147 | tok--; | |
9148 | value_start = tok + 1; | |
9149 | ||
9150 | /* Skip whitespace. */ | |
9151 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9152 | tok--; | |
9153 | ||
9154 | end_tok = tok; | |
9155 | ||
9156 | /* Find the beginning of the second to last token. | |
9157 | This is the parameter itself. */ | |
9158 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9159 | tok--; | |
9160 | tok++; | |
9161 | toklen = end_tok - tok + 1; | |
9162 | ||
9163 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
9164 | { | |
9165 | /* At this point we've found a "thread" token, which means | |
9166 | the user is trying to set a watchpoint that triggers | |
9167 | only in a specific thread. */ | |
9168 | char *endp; | |
37e4754d | 9169 | |
9c06b0b4 TJB |
9170 | if (thread != -1) |
9171 | error(_("You can specify only one thread.")); | |
37e4754d | 9172 | |
9c06b0b4 TJB |
9173 | /* Extract the thread ID from the next token. */ |
9174 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 9175 | |
9c06b0b4 TJB |
9176 | /* Check if the user provided a valid numeric value for the |
9177 | thread ID. */ | |
9178 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
9179 | error (_("Invalid thread ID specification %s."), value_start); | |
9180 | ||
9181 | /* Check if the thread actually exists. */ | |
9182 | if (!valid_thread_id (thread)) | |
9183 | error (_("Unknown thread %d."), thread); | |
9184 | } | |
9185 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
9186 | { | |
9187 | /* We've found a "mask" token, which means the user wants to | |
9188 | create a hardware watchpoint that is going to have the mask | |
9189 | facility. */ | |
9190 | struct value *mask_value, *mark; | |
37e4754d | 9191 | |
9c06b0b4 TJB |
9192 | if (use_mask) |
9193 | error(_("You can specify only one mask.")); | |
37e4754d | 9194 | |
9c06b0b4 | 9195 | use_mask = just_location = 1; |
37e4754d | 9196 | |
9c06b0b4 TJB |
9197 | mark = value_mark (); |
9198 | mask_value = parse_to_comma_and_eval (&value_start); | |
9199 | mask = value_as_address (mask_value); | |
9200 | value_free_to_mark (mark); | |
9201 | } | |
9202 | else | |
9203 | /* We didn't recognize what we found. We should stop here. */ | |
9204 | break; | |
37e4754d | 9205 | |
9c06b0b4 TJB |
9206 | /* Truncate the string and get rid of the "parameter value" pair before |
9207 | the arguments string is parsed by the parse_exp_1 function. */ | |
9208 | *tok = '\0'; | |
9209 | } | |
37e4754d LM |
9210 | } |
9211 | ||
9212 | /* Parse the rest of the arguments. */ | |
c906108c SS |
9213 | innermost_block = NULL; |
9214 | exp_start = arg; | |
9215 | exp = parse_exp_1 (&arg, 0, 0); | |
9216 | exp_end = arg; | |
fa8a61dc TT |
9217 | /* Remove trailing whitespace from the expression before saving it. |
9218 | This makes the eventual display of the expression string a bit | |
9219 | prettier. */ | |
9220 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
9221 | --exp_end; | |
9222 | ||
65d79d4b SDJ |
9223 | /* Checking if the expression is not constant. */ |
9224 | if (watchpoint_exp_is_const (exp)) | |
9225 | { | |
9226 | int len; | |
9227 | ||
9228 | len = exp_end - exp_start; | |
9229 | while (len > 0 && isspace (exp_start[len - 1])) | |
9230 | len--; | |
9231 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
9232 | } | |
9233 | ||
c906108c SS |
9234 | exp_valid_block = innermost_block; |
9235 | mark = value_mark (); | |
a1442452 | 9236 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
9237 | |
9238 | if (just_location) | |
9239 | { | |
9c06b0b4 TJB |
9240 | int ret; |
9241 | ||
06a64a0b | 9242 | exp_valid_block = NULL; |
a1442452 | 9243 | val = value_addr (result); |
06a64a0b TT |
9244 | release_value (val); |
9245 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
9246 | |
9247 | if (use_mask) | |
9248 | { | |
9249 | ret = target_masked_watch_num_registers (value_as_address (val), | |
9250 | mask); | |
9251 | if (ret == -1) | |
9252 | error (_("This target does not support masked watchpoints.")); | |
9253 | else if (ret == -2) | |
9254 | error (_("Invalid mask or memory region.")); | |
9255 | } | |
06a64a0b TT |
9256 | } |
9257 | else if (val != NULL) | |
fa4727a6 | 9258 | release_value (val); |
c906108c | 9259 | |
e9cafbcc TT |
9260 | tok = skip_spaces (arg); |
9261 | end_tok = skip_to_space (tok); | |
c906108c SS |
9262 | |
9263 | toklen = end_tok - tok; | |
9264 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
9265 | { | |
2d134ed3 PA |
9266 | struct expression *cond; |
9267 | ||
60e1c644 | 9268 | innermost_block = NULL; |
c906108c SS |
9269 | tok = cond_start = end_tok + 1; |
9270 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
9271 | |
9272 | /* The watchpoint expression may not be local, but the condition | |
9273 | may still be. E.g.: `watch global if local > 0'. */ | |
9274 | cond_exp_valid_block = innermost_block; | |
9275 | ||
2d134ed3 | 9276 | xfree (cond); |
c906108c SS |
9277 | cond_end = tok; |
9278 | } | |
9279 | if (*tok) | |
8a3fe4f8 | 9280 | error (_("Junk at end of command.")); |
c906108c | 9281 | |
53a5351d | 9282 | if (accessflag == hw_read) |
c5aa993b | 9283 | bp_type = bp_read_watchpoint; |
53a5351d | 9284 | else if (accessflag == hw_access) |
c5aa993b JM |
9285 | bp_type = bp_access_watchpoint; |
9286 | else | |
9287 | bp_type = bp_hardware_watchpoint; | |
c906108c | 9288 | |
d983da9c | 9289 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
9290 | |
9291 | /* If the expression is "local", then set up a "watchpoint scope" | |
9292 | breakpoint at the point where we've left the scope of the watchpoint | |
9293 | expression. Create the scope breakpoint before the watchpoint, so | |
9294 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 9295 | if (exp_valid_block && frame) |
d983da9c | 9296 | { |
edb3359d DJ |
9297 | if (frame_id_p (frame_unwind_caller_id (frame))) |
9298 | { | |
9299 | scope_breakpoint | |
a6d9a66e UW |
9300 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
9301 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
9302 | bp_watchpoint_scope, |
9303 | &momentary_breakpoint_ops); | |
d983da9c | 9304 | |
edb3359d | 9305 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 9306 | |
edb3359d DJ |
9307 | /* Automatically delete the breakpoint when it hits. */ |
9308 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 9309 | |
edb3359d DJ |
9310 | /* Only break in the proper frame (help with recursion). */ |
9311 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 9312 | |
edb3359d | 9313 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
9314 | scope_breakpoint->loc->gdbarch |
9315 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
9316 | scope_breakpoint->loc->requested_address |
9317 | = frame_unwind_caller_pc (frame); | |
9318 | scope_breakpoint->loc->address | |
a6d9a66e UW |
9319 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
9320 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
9321 | scope_breakpoint->type); |
9322 | } | |
d983da9c DJ |
9323 | } |
9324 | ||
c906108c | 9325 | /* Now set up the breakpoint. */ |
3a5c3e22 PA |
9326 | |
9327 | w = XCNEW (struct watchpoint); | |
9328 | b = &w->base; | |
348d480f | 9329 | if (use_mask) |
3a5c3e22 PA |
9330 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9331 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 9332 | else |
3a5c3e22 PA |
9333 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9334 | &watchpoint_breakpoint_ops); | |
37e4754d | 9335 | b->thread = thread; |
b5de0fa7 | 9336 | b->disposition = disp_donttouch; |
348d480f | 9337 | b->pspace = current_program_space; |
3a5c3e22 PA |
9338 | w->exp = exp; |
9339 | w->exp_valid_block = exp_valid_block; | |
9340 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
9341 | if (just_location) |
9342 | { | |
9343 | struct type *t = value_type (val); | |
9344 | CORE_ADDR addr = value_as_address (val); | |
9345 | char *name; | |
9346 | ||
9347 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
9348 | name = type_to_string (t); | |
9349 | ||
3a5c3e22 | 9350 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 9351 | core_addr_to_string (addr)); |
06a64a0b TT |
9352 | xfree (name); |
9353 | ||
3a5c3e22 | 9354 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
9355 | (int) (exp_end - exp_start), exp_start); |
9356 | ||
06a64a0b TT |
9357 | /* The above expression is in C. */ |
9358 | b->language = language_c; | |
9359 | } | |
9360 | else | |
3a5c3e22 | 9361 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
9362 | |
9363 | if (use_mask) | |
9364 | { | |
3a5c3e22 | 9365 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
9366 | } |
9367 | else | |
9368 | { | |
3a5c3e22 PA |
9369 | w->val = val; |
9370 | w->val_valid = 1; | |
9c06b0b4 | 9371 | } |
77b06cd7 | 9372 | |
c906108c SS |
9373 | if (cond_start) |
9374 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
9375 | else | |
9376 | b->cond_string = 0; | |
c5aa993b | 9377 | |
c906108c | 9378 | if (frame) |
f6bc2008 | 9379 | { |
3a5c3e22 PA |
9380 | w->watchpoint_frame = get_frame_id (frame); |
9381 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 9382 | } |
c906108c | 9383 | else |
f6bc2008 | 9384 | { |
3a5c3e22 PA |
9385 | w->watchpoint_frame = null_frame_id; |
9386 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 9387 | } |
c906108c | 9388 | |
d983da9c | 9389 | if (scope_breakpoint != NULL) |
c906108c | 9390 | { |
d983da9c DJ |
9391 | /* The scope breakpoint is related to the watchpoint. We will |
9392 | need to act on them together. */ | |
9393 | b->related_breakpoint = scope_breakpoint; | |
9394 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 9395 | } |
d983da9c | 9396 | |
06a64a0b TT |
9397 | if (!just_location) |
9398 | value_free_to_mark (mark); | |
2d134ed3 | 9399 | |
a9634178 TJB |
9400 | TRY_CATCH (e, RETURN_MASK_ALL) |
9401 | { | |
9402 | /* Finally update the new watchpoint. This creates the locations | |
9403 | that should be inserted. */ | |
3a5c3e22 | 9404 | update_watchpoint (w, 1); |
a9634178 TJB |
9405 | } |
9406 | if (e.reason < 0) | |
9407 | { | |
9408 | delete_breakpoint (b); | |
9409 | throw_exception (e); | |
9410 | } | |
9411 | ||
3a5c3e22 | 9412 | install_breakpoint (internal, b); |
c906108c SS |
9413 | } |
9414 | ||
e09342b5 | 9415 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 9416 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 9417 | |
c906108c | 9418 | static int |
a9634178 | 9419 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
9420 | { |
9421 | int found_memory_cnt = 0; | |
2e70b7b9 | 9422 | struct value *head = v; |
c906108c SS |
9423 | |
9424 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 9425 | if (!can_use_hw_watchpoints) |
c906108c | 9426 | return 0; |
c5aa993b | 9427 | |
5c44784c JM |
9428 | /* Make sure that the value of the expression depends only upon |
9429 | memory contents, and values computed from them within GDB. If we | |
9430 | find any register references or function calls, we can't use a | |
9431 | hardware watchpoint. | |
9432 | ||
9433 | The idea here is that evaluating an expression generates a series | |
9434 | of values, one holding the value of every subexpression. (The | |
9435 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
9436 | a*b+c.) GDB's values hold almost enough information to establish | |
9437 | the criteria given above --- they identify memory lvalues, | |
9438 | register lvalues, computed values, etcetera. So we can evaluate | |
9439 | the expression, and then scan the chain of values that leaves | |
9440 | behind to decide whether we can detect any possible change to the | |
9441 | expression's final value using only hardware watchpoints. | |
9442 | ||
9443 | However, I don't think that the values returned by inferior | |
9444 | function calls are special in any way. So this function may not | |
9445 | notice that an expression involving an inferior function call | |
9446 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 9447 | for (; v; v = value_next (v)) |
c906108c | 9448 | { |
5c44784c | 9449 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 9450 | { |
8464be76 DJ |
9451 | if (v != head && value_lazy (v)) |
9452 | /* A lazy memory lvalue in the chain is one that GDB never | |
9453 | needed to fetch; we either just used its address (e.g., | |
9454 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
9455 | in `a,b'). This doesn't apply to HEAD; if that is | |
9456 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 9457 | ; |
53a5351d | 9458 | else |
5c44784c JM |
9459 | { |
9460 | /* Ahh, memory we actually used! Check if we can cover | |
9461 | it with hardware watchpoints. */ | |
df407dfe | 9462 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
9463 | |
9464 | /* We only watch structs and arrays if user asked for it | |
9465 | explicitly, never if they just happen to appear in a | |
9466 | middle of some value chain. */ | |
9467 | if (v == head | |
9468 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
9469 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
9470 | { | |
42ae5230 | 9471 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
9472 | int len; |
9473 | int num_regs; | |
9474 | ||
a9634178 | 9475 | len = (target_exact_watchpoints |
e09342b5 TJB |
9476 | && is_scalar_type_recursive (vtype))? |
9477 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 9478 | |
e09342b5 TJB |
9479 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
9480 | if (!num_regs) | |
2e70b7b9 MS |
9481 | return 0; |
9482 | else | |
e09342b5 | 9483 | found_memory_cnt += num_regs; |
2e70b7b9 | 9484 | } |
5c44784c | 9485 | } |
c5aa993b | 9486 | } |
5086187c AC |
9487 | else if (VALUE_LVAL (v) != not_lval |
9488 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 9489 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 9490 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 9491 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
9492 | } |
9493 | ||
9494 | /* The expression itself looks suitable for using a hardware | |
9495 | watchpoint, but give the target machine a chance to reject it. */ | |
9496 | return found_memory_cnt; | |
9497 | } | |
9498 | ||
8b93c638 | 9499 | void |
84f4c1fe | 9500 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9501 | { |
84f4c1fe | 9502 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
9503 | } |
9504 | ||
9505 | /* A helper function that looks for an argument at the start of a | |
9506 | string. The argument must also either be at the end of the string, | |
9507 | or be followed by whitespace. Returns 1 if it finds the argument, | |
9508 | 0 otherwise. If the argument is found, it updates *STR. */ | |
9509 | ||
9510 | static int | |
9511 | check_for_argument (char **str, char *arg, int arg_len) | |
9512 | { | |
9513 | if (strncmp (*str, arg, arg_len) == 0 | |
9514 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
9515 | { | |
9516 | *str += arg_len; | |
9517 | return 1; | |
9518 | } | |
9519 | return 0; | |
9520 | } | |
9521 | ||
9522 | /* A helper function that looks for the "-location" argument and then | |
9523 | calls watch_command_1. */ | |
9524 | ||
9525 | static void | |
9526 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
9527 | { | |
9528 | int just_location = 0; | |
9529 | ||
9530 | if (arg | |
9531 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
9532 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
9533 | { | |
e9cafbcc | 9534 | arg = skip_spaces (arg); |
06a64a0b TT |
9535 | just_location = 1; |
9536 | } | |
9537 | ||
84f4c1fe | 9538 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 9539 | } |
8926118c | 9540 | |
c5aa993b | 9541 | static void |
fba45db2 | 9542 | watch_command (char *arg, int from_tty) |
c906108c | 9543 | { |
06a64a0b | 9544 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
9545 | } |
9546 | ||
8b93c638 | 9547 | void |
84f4c1fe | 9548 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9549 | { |
84f4c1fe | 9550 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 9551 | } |
8926118c | 9552 | |
c5aa993b | 9553 | static void |
fba45db2 | 9554 | rwatch_command (char *arg, int from_tty) |
c906108c | 9555 | { |
06a64a0b | 9556 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
9557 | } |
9558 | ||
8b93c638 | 9559 | void |
84f4c1fe | 9560 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9561 | { |
84f4c1fe | 9562 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 9563 | } |
8926118c | 9564 | |
c5aa993b | 9565 | static void |
fba45db2 | 9566 | awatch_command (char *arg, int from_tty) |
c906108c | 9567 | { |
06a64a0b | 9568 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 9569 | } |
c906108c | 9570 | \f |
c5aa993b | 9571 | |
43ff13b4 | 9572 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
9573 | because it uses the mechanisms of breakpoints. */ |
9574 | ||
bfec99b2 PA |
9575 | struct until_break_command_continuation_args |
9576 | { | |
9577 | struct breakpoint *breakpoint; | |
9578 | struct breakpoint *breakpoint2; | |
186c406b | 9579 | int thread_num; |
bfec99b2 PA |
9580 | }; |
9581 | ||
43ff13b4 | 9582 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 9583 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 9584 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 9585 | command. */ |
c2c6d25f | 9586 | static void |
fa4cd53f | 9587 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 9588 | { |
bfec99b2 PA |
9589 | struct until_break_command_continuation_args *a = arg; |
9590 | ||
9591 | delete_breakpoint (a->breakpoint); | |
9592 | if (a->breakpoint2) | |
9593 | delete_breakpoint (a->breakpoint2); | |
186c406b | 9594 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
9595 | } |
9596 | ||
c906108c | 9597 | void |
ae66c1fc | 9598 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
9599 | { |
9600 | struct symtabs_and_lines sals; | |
9601 | struct symtab_and_line sal; | |
206415a3 | 9602 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 9603 | struct breakpoint *breakpoint; |
f107f563 | 9604 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 9605 | struct cleanup *old_chain; |
186c406b TT |
9606 | int thread; |
9607 | struct thread_info *tp; | |
c906108c SS |
9608 | |
9609 | clear_proceed_status (); | |
9610 | ||
9611 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 9612 | this function. */ |
c5aa993b | 9613 | |
c906108c SS |
9614 | if (default_breakpoint_valid) |
9615 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
58438ac1 | 9616 | default_breakpoint_line, NULL); |
c906108c | 9617 | else |
58438ac1 | 9618 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL); |
c5aa993b | 9619 | |
c906108c | 9620 | if (sals.nelts != 1) |
8a3fe4f8 | 9621 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 9622 | |
c906108c | 9623 | sal = sals.sals[0]; |
4a64f543 | 9624 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 9625 | |
c906108c | 9626 | if (*arg) |
8a3fe4f8 | 9627 | error (_("Junk at end of arguments.")); |
c5aa993b | 9628 | |
c906108c | 9629 | resolve_sal_pc (&sal); |
c5aa993b | 9630 | |
ae66c1fc EZ |
9631 | if (anywhere) |
9632 | /* If the user told us to continue until a specified location, | |
9633 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
9634 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9635 | null_frame_id, bp_until); | |
ae66c1fc | 9636 | else |
4a64f543 MS |
9637 | /* Otherwise, specify the selected frame, because we want to stop |
9638 | only at the very same frame. */ | |
a6d9a66e UW |
9639 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9640 | get_stack_frame_id (frame), | |
ae66c1fc | 9641 | bp_until); |
c5aa993b | 9642 | |
f107f563 | 9643 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 9644 | |
186c406b TT |
9645 | tp = inferior_thread (); |
9646 | thread = tp->num; | |
9647 | ||
ae66c1fc EZ |
9648 | /* Keep within the current frame, or in frames called by the current |
9649 | one. */ | |
edb3359d DJ |
9650 | |
9651 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 9652 | { |
edb3359d DJ |
9653 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
9654 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
9655 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
9656 | sal, | |
edb3359d | 9657 | frame_unwind_caller_id (frame), |
f107f563 VP |
9658 | bp_until); |
9659 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
9660 | |
9661 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
9662 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 9663 | } |
c5aa993b | 9664 | |
c906108c | 9665 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 9666 | |
4a64f543 MS |
9667 | /* If we are running asynchronously, and proceed call above has |
9668 | actually managed to start the target, arrange for breakpoints to | |
9669 | be deleted when the target stops. Otherwise, we're already | |
9670 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 9671 | |
8ea051c5 | 9672 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 9673 | { |
bfec99b2 PA |
9674 | struct until_break_command_continuation_args *args; |
9675 | args = xmalloc (sizeof (*args)); | |
f107f563 | 9676 | |
bfec99b2 PA |
9677 | args->breakpoint = breakpoint; |
9678 | args->breakpoint2 = breakpoint2; | |
186c406b | 9679 | args->thread_num = thread; |
f107f563 VP |
9680 | |
9681 | discard_cleanups (old_chain); | |
95e54da7 PA |
9682 | add_continuation (inferior_thread (), |
9683 | until_break_command_continuation, args, | |
604ead4a | 9684 | xfree); |
f107f563 VP |
9685 | } |
9686 | else | |
c5aa993b | 9687 | do_cleanups (old_chain); |
c906108c | 9688 | } |
ae66c1fc | 9689 | |
c906108c SS |
9690 | /* This function attempts to parse an optional "if <cond>" clause |
9691 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 9692 | |
c906108c SS |
9693 | Else, it returns a pointer to the condition string. (It does not |
9694 | attempt to evaluate the string against a particular block.) And, | |
9695 | it updates arg to point to the first character following the parsed | |
4a64f543 | 9696 | if clause in the arg string. */ |
53a5351d | 9697 | |
c906108c | 9698 | static char * |
fba45db2 | 9699 | ep_parse_optional_if_clause (char **arg) |
c906108c | 9700 | { |
c5aa993b JM |
9701 | char *cond_string; |
9702 | ||
9703 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 9704 | return NULL; |
c5aa993b | 9705 | |
4a64f543 | 9706 | /* Skip the "if" keyword. */ |
c906108c | 9707 | (*arg) += 2; |
c5aa993b | 9708 | |
c906108c | 9709 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 9710 | condition string. */ |
e9cafbcc | 9711 | *arg = skip_spaces (*arg); |
c906108c | 9712 | cond_string = *arg; |
c5aa993b | 9713 | |
4a64f543 MS |
9714 | /* Assume that the condition occupies the remainder of the arg |
9715 | string. */ | |
c906108c | 9716 | (*arg) += strlen (cond_string); |
c5aa993b | 9717 | |
c906108c SS |
9718 | return cond_string; |
9719 | } | |
c5aa993b | 9720 | |
c906108c SS |
9721 | /* Commands to deal with catching events, such as signals, exceptions, |
9722 | process start/exit, etc. */ | |
c5aa993b JM |
9723 | |
9724 | typedef enum | |
9725 | { | |
44feb3ce TT |
9726 | catch_fork_temporary, catch_vfork_temporary, |
9727 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
9728 | } |
9729 | catch_fork_kind; | |
9730 | ||
c906108c | 9731 | static void |
cc59ec59 MS |
9732 | catch_fork_command_1 (char *arg, int from_tty, |
9733 | struct cmd_list_element *command) | |
c906108c | 9734 | { |
a6d9a66e | 9735 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 9736 | char *cond_string = NULL; |
44feb3ce TT |
9737 | catch_fork_kind fork_kind; |
9738 | int tempflag; | |
9739 | ||
9740 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
9741 | tempflag = (fork_kind == catch_fork_temporary | |
9742 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 9743 | |
44feb3ce TT |
9744 | if (!arg) |
9745 | arg = ""; | |
e9cafbcc | 9746 | arg = skip_spaces (arg); |
c5aa993b | 9747 | |
c906108c | 9748 | /* The allowed syntax is: |
c5aa993b JM |
9749 | catch [v]fork |
9750 | catch [v]fork if <cond> | |
9751 | ||
4a64f543 | 9752 | First, check if there's an if clause. */ |
c906108c | 9753 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 9754 | |
c906108c | 9755 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9756 | error (_("Junk at end of arguments.")); |
c5aa993b | 9757 | |
c906108c | 9758 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9759 | and enable reporting of such events. */ |
c5aa993b JM |
9760 | switch (fork_kind) |
9761 | { | |
44feb3ce TT |
9762 | case catch_fork_temporary: |
9763 | case catch_fork_permanent: | |
a6d9a66e | 9764 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9765 | &catch_fork_breakpoint_ops); |
c906108c | 9766 | break; |
44feb3ce TT |
9767 | case catch_vfork_temporary: |
9768 | case catch_vfork_permanent: | |
a6d9a66e | 9769 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9770 | &catch_vfork_breakpoint_ops); |
c906108c | 9771 | break; |
c5aa993b | 9772 | default: |
8a3fe4f8 | 9773 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 9774 | break; |
c5aa993b | 9775 | } |
c906108c SS |
9776 | } |
9777 | ||
9778 | static void | |
cc59ec59 MS |
9779 | catch_exec_command_1 (char *arg, int from_tty, |
9780 | struct cmd_list_element *command) | |
c906108c | 9781 | { |
b4d90040 | 9782 | struct exec_catchpoint *c; |
a6d9a66e | 9783 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9784 | int tempflag; |
c5aa993b | 9785 | char *cond_string = NULL; |
c906108c | 9786 | |
44feb3ce TT |
9787 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9788 | ||
9789 | if (!arg) | |
9790 | arg = ""; | |
e9cafbcc | 9791 | arg = skip_spaces (arg); |
c906108c SS |
9792 | |
9793 | /* The allowed syntax is: | |
c5aa993b JM |
9794 | catch exec |
9795 | catch exec if <cond> | |
c906108c | 9796 | |
4a64f543 | 9797 | First, check if there's an if clause. */ |
c906108c SS |
9798 | cond_string = ep_parse_optional_if_clause (&arg); |
9799 | ||
9800 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9801 | error (_("Junk at end of arguments.")); |
c906108c | 9802 | |
b4d90040 PA |
9803 | c = XNEW (struct exec_catchpoint); |
9804 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
9805 | &catch_exec_breakpoint_ops); | |
9806 | c->exec_pathname = NULL; | |
9807 | ||
3a5c3e22 | 9808 | install_breakpoint (0, &c->base); |
c906108c | 9809 | } |
c5aa993b | 9810 | |
3086aeae | 9811 | static enum print_stop_action |
348d480f | 9812 | print_it_exception_catchpoint (bpstat bs) |
3086aeae | 9813 | { |
79a45e25 | 9814 | struct ui_out *uiout = current_uiout; |
348d480f | 9815 | struct breakpoint *b = bs->breakpoint_at; |
ade92717 | 9816 | int bp_temp, bp_throw; |
3086aeae | 9817 | |
ade92717 | 9818 | annotate_catchpoint (b->number); |
3086aeae | 9819 | |
ade92717 AR |
9820 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9821 | if (b->loc->address != b->loc->requested_address) | |
9822 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9823 | b->loc->address, | |
9824 | b->number, 1); | |
df2b6d2d | 9825 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9826 | ui_out_text (uiout, |
9827 | bp_temp ? "Temporary catchpoint " | |
9828 | : "Catchpoint "); | |
9829 | if (!ui_out_is_mi_like_p (uiout)) | |
9830 | ui_out_field_int (uiout, "bkptno", b->number); | |
9831 | ui_out_text (uiout, | |
c0b37c48 AR |
9832 | bp_throw ? " (exception thrown), " |
9833 | : " (exception caught), "); | |
ade92717 AR |
9834 | if (ui_out_is_mi_like_p (uiout)) |
9835 | { | |
9836 | ui_out_field_string (uiout, "reason", | |
9837 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9838 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9839 | ui_out_field_int (uiout, "bkptno", b->number); | |
9840 | } | |
3086aeae DJ |
9841 | return PRINT_SRC_AND_LOC; |
9842 | } | |
9843 | ||
9844 | static void | |
cc59ec59 MS |
9845 | print_one_exception_catchpoint (struct breakpoint *b, |
9846 | struct bp_location **last_loc) | |
3086aeae | 9847 | { |
79a45b7d | 9848 | struct value_print_options opts; |
79a45e25 | 9849 | struct ui_out *uiout = current_uiout; |
cc59ec59 | 9850 | |
79a45b7d TT |
9851 | get_user_print_options (&opts); |
9852 | if (opts.addressprint) | |
3086aeae DJ |
9853 | { |
9854 | annotate_field (4); | |
604133b5 AR |
9855 | if (b->loc == NULL || b->loc->shlib_disabled) |
9856 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9857 | else | |
5af949e3 UW |
9858 | ui_out_field_core_addr (uiout, "addr", |
9859 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9860 | } |
9861 | annotate_field (5); | |
604133b5 | 9862 | if (b->loc) |
a6d9a66e | 9863 | *last_loc = b->loc; |
3086aeae DJ |
9864 | if (strstr (b->addr_string, "throw") != NULL) |
9865 | ui_out_field_string (uiout, "what", "exception throw"); | |
9866 | else | |
9867 | ui_out_field_string (uiout, "what", "exception catch"); | |
9868 | } | |
9869 | ||
9870 | static void | |
9871 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9872 | { | |
79a45e25 | 9873 | struct ui_out *uiout = current_uiout; |
ade92717 AR |
9874 | int bp_temp; |
9875 | int bp_throw; | |
9876 | ||
df2b6d2d | 9877 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9878 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9879 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9880 | : _("Catchpoint ")); | |
9881 | ui_out_field_int (uiout, "bkptno", b->number); | |
9882 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9883 | : _(" (catch)")); | |
3086aeae DJ |
9884 | } |
9885 | ||
6149aea9 PA |
9886 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9887 | catch catchpoints. */ | |
9888 | ||
9889 | static void | |
4a64f543 MS |
9890 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9891 | struct ui_file *fp) | |
6149aea9 PA |
9892 | { |
9893 | int bp_temp; | |
9894 | int bp_throw; | |
9895 | ||
9896 | bp_temp = b->disposition == disp_del; | |
9897 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9898 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9899 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
d9b3f62e | 9900 | print_recreate_thread (b, fp); |
6149aea9 PA |
9901 | } |
9902 | ||
2060206e | 9903 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; |
3086aeae DJ |
9904 | |
9905 | static int | |
9906 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9907 | enum exception_event_kind ex_event, int from_tty) | |
9908 | { | |
604133b5 AR |
9909 | char *trigger_func_name; |
9910 | ||
3086aeae | 9911 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9912 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9913 | else |
604133b5 | 9914 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9915 | |
8cdf0e15 VP |
9916 | create_breakpoint (get_current_arch (), |
9917 | trigger_func_name, cond_string, -1, | |
9918 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9919 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9920 | 0, |
9921 | AUTO_BOOLEAN_TRUE /* pending */, | |
9922 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9923 | 1 /* enabled */, |
9924 | 0 /* internal */); | |
3086aeae | 9925 | |
3086aeae DJ |
9926 | return 1; |
9927 | } | |
9928 | ||
4a64f543 | 9929 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9930 | |
9931 | static void | |
fba45db2 KB |
9932 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9933 | int tempflag, int from_tty) | |
c906108c | 9934 | { |
c5aa993b | 9935 | char *cond_string = NULL; |
c5aa993b | 9936 | |
44feb3ce TT |
9937 | if (!arg) |
9938 | arg = ""; | |
e9cafbcc | 9939 | arg = skip_spaces (arg); |
c5aa993b | 9940 | |
c906108c SS |
9941 | cond_string = ep_parse_optional_if_clause (&arg); |
9942 | ||
9943 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9944 | error (_("Junk at end of arguments.")); |
c906108c | 9945 | |
059fb39f PM |
9946 | if (ex_event != EX_EVENT_THROW |
9947 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 9948 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 9949 | |
3086aeae DJ |
9950 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
9951 | return; | |
9952 | ||
8a3fe4f8 | 9953 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
9954 | } |
9955 | ||
44feb3ce TT |
9956 | /* Implementation of "catch catch" command. */ |
9957 | ||
9958 | static void | |
9959 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9960 | { | |
9961 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9962 | |
44feb3ce TT |
9963 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
9964 | } | |
9965 | ||
9966 | /* Implementation of "catch throw" command. */ | |
9967 | ||
9968 | static void | |
9969 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9970 | { | |
9971 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9972 | |
44feb3ce TT |
9973 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
9974 | } | |
9975 | ||
9ac4176b | 9976 | void |
28010a5d PA |
9977 | init_ada_exception_breakpoint (struct breakpoint *b, |
9978 | struct gdbarch *gdbarch, | |
9979 | struct symtab_and_line sal, | |
9980 | char *addr_string, | |
c0a91b2b | 9981 | const struct breakpoint_ops *ops, |
28010a5d PA |
9982 | int tempflag, |
9983 | int from_tty) | |
f7f9143b | 9984 | { |
f7f9143b JB |
9985 | if (from_tty) |
9986 | { | |
5af949e3 UW |
9987 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
9988 | if (!loc_gdbarch) | |
9989 | loc_gdbarch = gdbarch; | |
9990 | ||
6c95b8df PA |
9991 | describe_other_breakpoints (loc_gdbarch, |
9992 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
9993 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
9994 | version for exception catchpoints, because two catchpoints | |
9995 | used for different exception names will use the same address. | |
9996 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 9997 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 9998 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
9999 | the user what type of catchpoint it is. The above is good |
10000 | enough for now, though. */ | |
10001 | } | |
10002 | ||
28010a5d | 10003 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b JB |
10004 | |
10005 | b->enable_state = bp_enabled; | |
10006 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
f7f9143b JB |
10007 | b->addr_string = addr_string; |
10008 | b->language = language_ada; | |
f7f9143b JB |
10009 | } |
10010 | ||
a96d9b2e SDJ |
10011 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
10012 | filter list, or NULL if no filtering is required. */ | |
10013 | static VEC(int) * | |
10014 | catch_syscall_split_args (char *arg) | |
10015 | { | |
10016 | VEC(int) *result = NULL; | |
29d0bb3d | 10017 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
10018 | |
10019 | while (*arg != '\0') | |
10020 | { | |
10021 | int i, syscall_number; | |
10022 | char *endptr; | |
10023 | char cur_name[128]; | |
10024 | struct syscall s; | |
10025 | ||
10026 | /* Skip whitespace. */ | |
10027 | while (isspace (*arg)) | |
10028 | arg++; | |
10029 | ||
10030 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
10031 | cur_name[i] = arg[i]; | |
10032 | cur_name[i] = '\0'; | |
10033 | arg += i; | |
10034 | ||
10035 | /* Check if the user provided a syscall name or a number. */ | |
10036 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
10037 | if (*endptr == '\0') | |
bccd0dd2 | 10038 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
10039 | else |
10040 | { | |
10041 | /* We have a name. Let's check if it's valid and convert it | |
10042 | to a number. */ | |
10043 | get_syscall_by_name (cur_name, &s); | |
10044 | ||
10045 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
10046 | /* Here we have to issue an error instead of a warning, |
10047 | because GDB cannot do anything useful if there's no | |
10048 | syscall number to be caught. */ | |
a96d9b2e SDJ |
10049 | error (_("Unknown syscall name '%s'."), cur_name); |
10050 | } | |
10051 | ||
10052 | /* Ok, it's valid. */ | |
10053 | VEC_safe_push (int, result, s.number); | |
10054 | } | |
10055 | ||
10056 | discard_cleanups (cleanup); | |
10057 | return result; | |
10058 | } | |
10059 | ||
10060 | /* Implement the "catch syscall" command. */ | |
10061 | ||
10062 | static void | |
cc59ec59 MS |
10063 | catch_syscall_command_1 (char *arg, int from_tty, |
10064 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
10065 | { |
10066 | int tempflag; | |
10067 | VEC(int) *filter; | |
10068 | struct syscall s; | |
10069 | struct gdbarch *gdbarch = get_current_arch (); | |
10070 | ||
10071 | /* Checking if the feature if supported. */ | |
10072 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
10073 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 10074 | this architecture yet.")); |
a96d9b2e SDJ |
10075 | |
10076 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
10077 | ||
e9cafbcc | 10078 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
10079 | |
10080 | /* We need to do this first "dummy" translation in order | |
10081 | to get the syscall XML file loaded or, most important, | |
10082 | to display a warning to the user if there's no XML file | |
10083 | for his/her architecture. */ | |
10084 | get_syscall_by_number (0, &s); | |
10085 | ||
10086 | /* The allowed syntax is: | |
10087 | catch syscall | |
10088 | catch syscall <name | number> [<name | number> ... <name | number>] | |
10089 | ||
10090 | Let's check if there's a syscall name. */ | |
10091 | ||
10092 | if (arg != NULL) | |
10093 | filter = catch_syscall_split_args (arg); | |
10094 | else | |
10095 | filter = NULL; | |
10096 | ||
10097 | create_syscall_event_catchpoint (tempflag, filter, | |
10098 | &catch_syscall_breakpoint_ops); | |
10099 | } | |
10100 | ||
c906108c | 10101 | static void |
fba45db2 | 10102 | catch_command (char *arg, int from_tty) |
c906108c | 10103 | { |
44feb3ce | 10104 | error (_("Catch requires an event name.")); |
c906108c SS |
10105 | } |
10106 | \f | |
10107 | ||
10108 | static void | |
fba45db2 | 10109 | tcatch_command (char *arg, int from_tty) |
c906108c | 10110 | { |
44feb3ce | 10111 | error (_("Catch requires an event name.")); |
c906108c SS |
10112 | } |
10113 | ||
80f8a6eb | 10114 | /* Delete breakpoints by address or line. */ |
c906108c SS |
10115 | |
10116 | static void | |
fba45db2 | 10117 | clear_command (char *arg, int from_tty) |
c906108c | 10118 | { |
d6e956e5 VP |
10119 | struct breakpoint *b; |
10120 | VEC(breakpoint_p) *found = 0; | |
10121 | int ix; | |
c906108c SS |
10122 | int default_match; |
10123 | struct symtabs_and_lines sals; | |
10124 | struct symtab_and_line sal; | |
c906108c SS |
10125 | int i; |
10126 | ||
10127 | if (arg) | |
10128 | { | |
10129 | sals = decode_line_spec (arg, 1); | |
10130 | default_match = 0; | |
10131 | } | |
10132 | else | |
10133 | { | |
c5aa993b | 10134 | sals.sals = (struct symtab_and_line *) |
c906108c | 10135 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 10136 | make_cleanup (xfree, sals.sals); |
4a64f543 | 10137 | init_sal (&sal); /* Initialize to zeroes. */ |
c906108c SS |
10138 | sal.line = default_breakpoint_line; |
10139 | sal.symtab = default_breakpoint_symtab; | |
10140 | sal.pc = default_breakpoint_address; | |
6c95b8df | 10141 | sal.pspace = default_breakpoint_pspace; |
c906108c | 10142 | if (sal.symtab == 0) |
8a3fe4f8 | 10143 | error (_("No source file specified.")); |
c906108c SS |
10144 | |
10145 | sals.sals[0] = sal; | |
10146 | sals.nelts = 1; | |
10147 | ||
10148 | default_match = 1; | |
10149 | } | |
10150 | ||
4a64f543 MS |
10151 | /* We don't call resolve_sal_pc here. That's not as bad as it |
10152 | seems, because all existing breakpoints typically have both | |
10153 | file/line and pc set. So, if clear is given file/line, we can | |
10154 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
10155 | |
10156 | We only support clearing given the address explicitly | |
10157 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 10158 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 10159 | due to optimization, all in one block. |
4a64f543 MS |
10160 | |
10161 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
10162 | PC corresponding to the same file:line, the breakpoint won't |
10163 | be cleared. We probably can still clear the breakpoint, but | |
10164 | since the other PC value is never presented to user, user | |
10165 | can only find it by guessing, and it does not seem important | |
10166 | to support that. */ | |
10167 | ||
4a64f543 MS |
10168 | /* For each line spec given, delete bps which correspond to it. Do |
10169 | it in two passes, solely to preserve the current behavior that | |
10170 | from_tty is forced true if we delete more than one | |
10171 | breakpoint. */ | |
c906108c | 10172 | |
80f8a6eb | 10173 | found = NULL; |
c906108c SS |
10174 | for (i = 0; i < sals.nelts; i++) |
10175 | { | |
10176 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
10177 | If line given (pc == 0), clear all bpts on specified line. |
10178 | If defaulting, clear all bpts on default line | |
c906108c | 10179 | or at default pc. |
c5aa993b JM |
10180 | |
10181 | defaulting sal.pc != 0 tests to do | |
10182 | ||
10183 | 0 1 pc | |
10184 | 1 1 pc _and_ line | |
10185 | 0 0 line | |
10186 | 1 0 <can't happen> */ | |
c906108c SS |
10187 | |
10188 | sal = sals.sals[i]; | |
c906108c | 10189 | |
4a64f543 | 10190 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 10191 | ALL_BREAKPOINTS (b) |
c5aa993b | 10192 | { |
0d381245 | 10193 | int match = 0; |
4a64f543 | 10194 | /* Are we going to delete b? */ |
cc60f2e3 | 10195 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
10196 | { |
10197 | struct bp_location *loc = b->loc; | |
10198 | for (; loc; loc = loc->next) | |
10199 | { | |
6c95b8df PA |
10200 | int pc_match = sal.pc |
10201 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
10202 | && (loc->address == sal.pc) |
10203 | && (!section_is_overlay (loc->section) | |
10204 | || loc->section == sal.section); | |
10205 | int line_match = ((default_match || (0 == sal.pc)) | |
10206 | && b->source_file != NULL | |
10207 | && sal.symtab != NULL | |
6c95b8df | 10208 | && sal.pspace == loc->pspace |
0ba1096a KT |
10209 | && filename_cmp (b->source_file, |
10210 | sal.symtab->filename) == 0 | |
0d381245 VP |
10211 | && b->line_number == sal.line); |
10212 | if (pc_match || line_match) | |
10213 | { | |
10214 | match = 1; | |
10215 | break; | |
10216 | } | |
10217 | } | |
10218 | } | |
10219 | ||
10220 | if (match) | |
d6e956e5 | 10221 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 10222 | } |
80f8a6eb MS |
10223 | } |
10224 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 10225 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
10226 | { |
10227 | if (arg) | |
8a3fe4f8 | 10228 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 10229 | else |
8a3fe4f8 | 10230 | error (_("No breakpoint at this line.")); |
80f8a6eb | 10231 | } |
c906108c | 10232 | |
d6e956e5 | 10233 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 10234 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 10235 | if (from_tty) |
a3f17187 | 10236 | { |
d6e956e5 | 10237 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
10238 | printf_unfiltered (_("Deleted breakpoint ")); |
10239 | else | |
10240 | printf_unfiltered (_("Deleted breakpoints ")); | |
10241 | } | |
80f8a6eb | 10242 | breakpoints_changed (); |
d6e956e5 VP |
10243 | |
10244 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 10245 | { |
c5aa993b | 10246 | if (from_tty) |
d6e956e5 VP |
10247 | printf_unfiltered ("%d ", b->number); |
10248 | delete_breakpoint (b); | |
c906108c | 10249 | } |
80f8a6eb MS |
10250 | if (from_tty) |
10251 | putchar_unfiltered ('\n'); | |
c906108c SS |
10252 | } |
10253 | \f | |
10254 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
10255 | all breakpoints that are marked for deletion, whether hit or not. | |
10256 | This is called after any breakpoint is hit, or after errors. */ | |
10257 | ||
10258 | void | |
fba45db2 | 10259 | breakpoint_auto_delete (bpstat bs) |
c906108c | 10260 | { |
35df4500 | 10261 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10262 | |
10263 | for (; bs; bs = bs->next) | |
f431efe5 PA |
10264 | if (bs->breakpoint_at |
10265 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 10266 | && bs->stop) |
f431efe5 | 10267 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 10268 | |
35df4500 | 10269 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10270 | { |
b5de0fa7 | 10271 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
10272 | delete_breakpoint (b); |
10273 | } | |
c906108c SS |
10274 | } |
10275 | ||
4a64f543 MS |
10276 | /* A comparison function for bp_location AP and BP being interfaced to |
10277 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
10278 | does breakpoint_address_is_meaningful say for its OWNER), | |
10279 | secondarily by ordering first bp_permanent OWNERed elements and | |
10280 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 10281 | qsort being an unstable algorithm. */ |
876fa593 JK |
10282 | |
10283 | static int | |
494cfb0f | 10284 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 10285 | { |
494cfb0f JK |
10286 | struct bp_location *a = *(void **) ap; |
10287 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 10288 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
10289 | int a_perm = a->owner->enable_state == bp_permanent; |
10290 | int b_perm = b->owner->enable_state == bp_permanent; | |
10291 | ||
10292 | if (a->address != b->address) | |
10293 | return (a->address > b->address) - (a->address < b->address); | |
10294 | ||
10295 | /* Sort permanent breakpoints first. */ | |
10296 | if (a_perm != b_perm) | |
10297 | return (a_perm < b_perm) - (a_perm > b_perm); | |
10298 | ||
4a64f543 MS |
10299 | /* Make the user-visible order stable across GDB runs. Locations of |
10300 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
10301 | |
10302 | if (a->owner->number != b->owner->number) | |
10303 | return (a->owner->number > b->owner->number) | |
10304 | - (a->owner->number < b->owner->number); | |
10305 | ||
10306 | return (a > b) - (a < b); | |
10307 | } | |
10308 | ||
876fa593 | 10309 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
10310 | bp_location_shadow_len_after_address_max according to the current |
10311 | content of the bp_location array. */ | |
f7545552 TT |
10312 | |
10313 | static void | |
876fa593 | 10314 | bp_location_target_extensions_update (void) |
f7545552 | 10315 | { |
876fa593 JK |
10316 | struct bp_location *bl, **blp_tmp; |
10317 | ||
10318 | bp_location_placed_address_before_address_max = 0; | |
10319 | bp_location_shadow_len_after_address_max = 0; | |
10320 | ||
10321 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10322 | { | |
10323 | CORE_ADDR start, end, addr; | |
10324 | ||
10325 | if (!bp_location_has_shadow (bl)) | |
10326 | continue; | |
10327 | ||
10328 | start = bl->target_info.placed_address; | |
10329 | end = start + bl->target_info.shadow_len; | |
10330 | ||
10331 | gdb_assert (bl->address >= start); | |
10332 | addr = bl->address - start; | |
10333 | if (addr > bp_location_placed_address_before_address_max) | |
10334 | bp_location_placed_address_before_address_max = addr; | |
10335 | ||
10336 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
10337 | ||
10338 | gdb_assert (bl->address < end); | |
10339 | addr = end - bl->address; | |
10340 | if (addr > bp_location_shadow_len_after_address_max) | |
10341 | bp_location_shadow_len_after_address_max = addr; | |
10342 | } | |
f7545552 TT |
10343 | } |
10344 | ||
934709f0 PW |
10345 | /* Swap the insertion/duplication state between two locations. */ |
10346 | ||
10347 | static void | |
10348 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
10349 | { | |
10350 | const int left_inserted = left->inserted; | |
10351 | const int left_duplicate = left->duplicate; | |
10352 | const struct bp_target_info left_target_info = left->target_info; | |
10353 | ||
10354 | left->inserted = right->inserted; | |
10355 | left->duplicate = right->duplicate; | |
10356 | left->target_info = right->target_info; | |
10357 | right->inserted = left_inserted; | |
10358 | right->duplicate = left_duplicate; | |
10359 | right->target_info = left_target_info; | |
10360 | } | |
10361 | ||
4cd9bd08 | 10362 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
10363 | into the inferior, only remove already-inserted locations that no |
10364 | longer should be inserted. Functions that delete a breakpoint or | |
10365 | breakpoints should pass false, so that deleting a breakpoint | |
10366 | doesn't have the side effect of inserting the locations of other | |
10367 | breakpoints that are marked not-inserted, but should_be_inserted | |
10368 | returns true on them. | |
10369 | ||
10370 | This behaviour is useful is situations close to tear-down -- e.g., | |
10371 | after an exec, while the target still has execution, but breakpoint | |
10372 | shadows of the previous executable image should *NOT* be restored | |
10373 | to the new image; or before detaching, where the target still has | |
10374 | execution and wants to delete breakpoints from GDB's lists, and all | |
10375 | breakpoints had already been removed from the inferior. */ | |
10376 | ||
0d381245 | 10377 | static void |
b60e7edf | 10378 | update_global_location_list (int should_insert) |
0d381245 | 10379 | { |
74960c60 | 10380 | struct breakpoint *b; |
876fa593 | 10381 | struct bp_location **locp, *loc; |
f7545552 TT |
10382 | struct cleanup *cleanups; |
10383 | ||
2d134ed3 PA |
10384 | /* Used in the duplicates detection below. When iterating over all |
10385 | bp_locations, points to the first bp_location of a given address. | |
10386 | Breakpoints and watchpoints of different types are never | |
10387 | duplicates of each other. Keep one pointer for each type of | |
10388 | breakpoint/watchpoint, so we only need to loop over all locations | |
10389 | once. */ | |
10390 | struct bp_location *bp_loc_first; /* breakpoint */ | |
10391 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
10392 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
10393 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 10394 | |
4a64f543 MS |
10395 | /* Saved former bp_location array which we compare against the newly |
10396 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
10397 | struct bp_location **old_location, **old_locp; |
10398 | unsigned old_location_count; | |
10399 | ||
10400 | old_location = bp_location; | |
10401 | old_location_count = bp_location_count; | |
10402 | bp_location = NULL; | |
10403 | bp_location_count = 0; | |
10404 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 10405 | |
74960c60 | 10406 | ALL_BREAKPOINTS (b) |
876fa593 JK |
10407 | for (loc = b->loc; loc; loc = loc->next) |
10408 | bp_location_count++; | |
10409 | ||
10410 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
10411 | locp = bp_location; | |
10412 | ALL_BREAKPOINTS (b) | |
10413 | for (loc = b->loc; loc; loc = loc->next) | |
10414 | *locp++ = loc; | |
10415 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 10416 | bp_location_compare); |
876fa593 JK |
10417 | |
10418 | bp_location_target_extensions_update (); | |
74960c60 | 10419 | |
4a64f543 MS |
10420 | /* Identify bp_location instances that are no longer present in the |
10421 | new list, and therefore should be freed. Note that it's not | |
10422 | necessary that those locations should be removed from inferior -- | |
10423 | if there's another location at the same address (previously | |
10424 | marked as duplicate), we don't need to remove/insert the | |
10425 | location. | |
876fa593 | 10426 | |
4a64f543 MS |
10427 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
10428 | and former bp_location array state respectively. */ | |
876fa593 JK |
10429 | |
10430 | locp = bp_location; | |
10431 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
10432 | old_locp++) | |
74960c60 | 10433 | { |
876fa593 | 10434 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 10435 | struct bp_location **loc2p; |
876fa593 | 10436 | |
e5dd4106 | 10437 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 10438 | not, we have to free it. */ |
c7d46a38 | 10439 | int found_object = 0; |
20874c92 VP |
10440 | /* Tells if the location should remain inserted in the target. */ |
10441 | int keep_in_target = 0; | |
10442 | int removed = 0; | |
876fa593 | 10443 | |
4a64f543 MS |
10444 | /* Skip LOCP entries which will definitely never be needed. |
10445 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 10446 | while (locp < bp_location + bp_location_count |
c7d46a38 | 10447 | && (*locp)->address < old_loc->address) |
876fa593 | 10448 | locp++; |
c7d46a38 PA |
10449 | |
10450 | for (loc2p = locp; | |
10451 | (loc2p < bp_location + bp_location_count | |
10452 | && (*loc2p)->address == old_loc->address); | |
10453 | loc2p++) | |
10454 | { | |
10455 | if (*loc2p == old_loc) | |
10456 | { | |
10457 | found_object = 1; | |
10458 | break; | |
10459 | } | |
10460 | } | |
74960c60 | 10461 | |
4a64f543 MS |
10462 | /* If this location is no longer present, and inserted, look if |
10463 | there's maybe a new location at the same address. If so, | |
10464 | mark that one inserted, and don't remove this one. This is | |
10465 | needed so that we don't have a time window where a breakpoint | |
10466 | at certain location is not inserted. */ | |
74960c60 | 10467 | |
876fa593 | 10468 | if (old_loc->inserted) |
0d381245 | 10469 | { |
4a64f543 MS |
10470 | /* If the location is inserted now, we might have to remove |
10471 | it. */ | |
74960c60 | 10472 | |
876fa593 | 10473 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 10474 | { |
4a64f543 MS |
10475 | /* The location is still present in the location list, |
10476 | and still should be inserted. Don't do anything. */ | |
20874c92 | 10477 | keep_in_target = 1; |
74960c60 VP |
10478 | } |
10479 | else | |
10480 | { | |
4a64f543 MS |
10481 | /* The location is either no longer present, or got |
10482 | disabled. See if there's another location at the | |
10483 | same address, in which case we don't need to remove | |
10484 | this one from the target. */ | |
876fa593 | 10485 | |
2bdf28a0 | 10486 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
10487 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
10488 | { | |
876fa593 | 10489 | for (loc2p = locp; |
c7d46a38 PA |
10490 | (loc2p < bp_location + bp_location_count |
10491 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
10492 | loc2p++) |
10493 | { | |
10494 | struct bp_location *loc2 = *loc2p; | |
10495 | ||
2d134ed3 | 10496 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 10497 | { |
85d721b8 PA |
10498 | /* Read watchpoint locations are switched to |
10499 | access watchpoints, if the former are not | |
10500 | supported, but the latter are. */ | |
10501 | if (is_hardware_watchpoint (old_loc->owner)) | |
10502 | { | |
10503 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
10504 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
10505 | } | |
10506 | ||
934709f0 PW |
10507 | /* loc2 is a duplicated location. We need to check |
10508 | if it should be inserted in case it will be | |
10509 | unduplicated. */ | |
10510 | if (loc2 != old_loc | |
10511 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 10512 | { |
934709f0 | 10513 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
10514 | keep_in_target = 1; |
10515 | break; | |
10516 | } | |
876fa593 JK |
10517 | } |
10518 | } | |
10519 | } | |
74960c60 VP |
10520 | } |
10521 | ||
20874c92 VP |
10522 | if (!keep_in_target) |
10523 | { | |
876fa593 | 10524 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 10525 | { |
4a64f543 MS |
10526 | /* This is just about all we can do. We could keep |
10527 | this location on the global list, and try to | |
10528 | remove it next time, but there's no particular | |
10529 | reason why we will succeed next time. | |
20874c92 | 10530 | |
4a64f543 MS |
10531 | Note that at this point, old_loc->owner is still |
10532 | valid, as delete_breakpoint frees the breakpoint | |
10533 | only after calling us. */ | |
3e43a32a MS |
10534 | printf_filtered (_("warning: Error removing " |
10535 | "breakpoint %d\n"), | |
876fa593 | 10536 | old_loc->owner->number); |
20874c92 VP |
10537 | } |
10538 | removed = 1; | |
10539 | } | |
0d381245 | 10540 | } |
74960c60 VP |
10541 | |
10542 | if (!found_object) | |
1c5cfe86 | 10543 | { |
db82e815 PA |
10544 | if (removed && non_stop |
10545 | && breakpoint_address_is_meaningful (old_loc->owner) | |
10546 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 10547 | { |
db82e815 PA |
10548 | /* This location was removed from the target. In |
10549 | non-stop mode, a race condition is possible where | |
10550 | we've removed a breakpoint, but stop events for that | |
10551 | breakpoint are already queued and will arrive later. | |
10552 | We apply an heuristic to be able to distinguish such | |
10553 | SIGTRAPs from other random SIGTRAPs: we keep this | |
10554 | breakpoint location for a bit, and will retire it | |
10555 | after we see some number of events. The theory here | |
10556 | is that reporting of events should, "on the average", | |
10557 | be fair, so after a while we'll see events from all | |
10558 | threads that have anything of interest, and no longer | |
10559 | need to keep this breakpoint location around. We | |
10560 | don't hold locations forever so to reduce chances of | |
10561 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
10562 | SIGTRAP. | |
10563 | ||
10564 | The heuristic failing can be disastrous on | |
10565 | decr_pc_after_break targets. | |
10566 | ||
10567 | On decr_pc_after_break targets, like e.g., x86-linux, | |
10568 | if we fail to recognize a late breakpoint SIGTRAP, | |
10569 | because events_till_retirement has reached 0 too | |
10570 | soon, we'll fail to do the PC adjustment, and report | |
10571 | a random SIGTRAP to the user. When the user resumes | |
10572 | the inferior, it will most likely immediately crash | |
2dec564e | 10573 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
10574 | corrupted, because of being resumed e.g., in the |
10575 | middle of a multi-byte instruction, or skipped a | |
10576 | one-byte instruction. This was actually seen happen | |
10577 | on native x86-linux, and should be less rare on | |
10578 | targets that do not support new thread events, like | |
10579 | remote, due to the heuristic depending on | |
10580 | thread_count. | |
10581 | ||
10582 | Mistaking a random SIGTRAP for a breakpoint trap | |
10583 | causes similar symptoms (PC adjustment applied when | |
10584 | it shouldn't), but then again, playing with SIGTRAPs | |
10585 | behind the debugger's back is asking for trouble. | |
10586 | ||
10587 | Since hardware watchpoint traps are always | |
10588 | distinguishable from other traps, so we don't need to | |
10589 | apply keep hardware watchpoint moribund locations | |
10590 | around. We simply always ignore hardware watchpoint | |
10591 | traps we can no longer explain. */ | |
10592 | ||
876fa593 JK |
10593 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
10594 | old_loc->owner = NULL; | |
20874c92 | 10595 | |
876fa593 | 10596 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
10597 | } |
10598 | else | |
f431efe5 PA |
10599 | { |
10600 | old_loc->owner = NULL; | |
10601 | decref_bp_location (&old_loc); | |
10602 | } | |
20874c92 | 10603 | } |
74960c60 | 10604 | } |
1c5cfe86 | 10605 | |
348d480f PA |
10606 | /* Rescan breakpoints at the same address and section, marking the |
10607 | first one as "first" and any others as "duplicates". This is so | |
10608 | that the bpt instruction is only inserted once. If we have a | |
10609 | permanent breakpoint at the same place as BPT, make that one the | |
10610 | official one, and the rest as duplicates. Permanent breakpoints | |
10611 | are sorted first for the same address. | |
10612 | ||
10613 | Do the same for hardware watchpoints, but also considering the | |
10614 | watchpoint's type (regular/access/read) and length. */ | |
10615 | ||
10616 | bp_loc_first = NULL; | |
10617 | wp_loc_first = NULL; | |
10618 | awp_loc_first = NULL; | |
10619 | rwp_loc_first = NULL; | |
10620 | ALL_BP_LOCATIONS (loc, locp) | |
10621 | { | |
10622 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
10623 | non-NULL. */ | |
10624 | struct breakpoint *b = loc->owner; | |
10625 | struct bp_location **loc_first_p; | |
10626 | ||
10627 | if (b->enable_state == bp_disabled | |
10628 | || b->enable_state == bp_call_disabled | |
10629 | || b->enable_state == bp_startup_disabled | |
10630 | || !loc->enabled | |
10631 | || loc->shlib_disabled | |
10632 | || !breakpoint_address_is_meaningful (b) | |
10633 | || is_tracepoint (b)) | |
10634 | continue; | |
10635 | ||
10636 | /* Permanent breakpoint should always be inserted. */ | |
10637 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
10638 | internal_error (__FILE__, __LINE__, | |
10639 | _("allegedly permanent breakpoint is not " | |
10640 | "actually inserted")); | |
10641 | ||
10642 | if (b->type == bp_hardware_watchpoint) | |
10643 | loc_first_p = &wp_loc_first; | |
10644 | else if (b->type == bp_read_watchpoint) | |
10645 | loc_first_p = &rwp_loc_first; | |
10646 | else if (b->type == bp_access_watchpoint) | |
10647 | loc_first_p = &awp_loc_first; | |
10648 | else | |
10649 | loc_first_p = &bp_loc_first; | |
10650 | ||
10651 | if (*loc_first_p == NULL | |
10652 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
10653 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
10654 | { | |
10655 | *loc_first_p = loc; | |
10656 | loc->duplicate = 0; | |
10657 | continue; | |
10658 | } | |
10659 | ||
934709f0 PW |
10660 | |
10661 | /* This and the above ensure the invariant that the first location | |
10662 | is not duplicated, and is the inserted one. | |
10663 | All following are marked as duplicated, and are not inserted. */ | |
10664 | if (loc->inserted) | |
10665 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
10666 | loc->duplicate = 1; |
10667 | ||
10668 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted | |
10669 | && b->enable_state != bp_permanent) | |
10670 | internal_error (__FILE__, __LINE__, | |
10671 | _("another breakpoint was inserted on top of " | |
10672 | "a permanent breakpoint")); | |
10673 | } | |
10674 | ||
10675 | if (breakpoints_always_inserted_mode () && should_insert | |
10676 | && (have_live_inferiors () | |
10677 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) | |
10678 | insert_breakpoint_locations (); | |
10679 | ||
10680 | do_cleanups (cleanups); | |
10681 | } | |
10682 | ||
10683 | void | |
10684 | breakpoint_retire_moribund (void) | |
10685 | { | |
10686 | struct bp_location *loc; | |
10687 | int ix; | |
10688 | ||
10689 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
10690 | if (--(loc->events_till_retirement) == 0) | |
10691 | { | |
10692 | decref_bp_location (&loc); | |
10693 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
10694 | --ix; | |
10695 | } | |
10696 | } | |
10697 | ||
10698 | static void | |
10699 | update_global_location_list_nothrow (int inserting) | |
10700 | { | |
10701 | struct gdb_exception e; | |
10702 | ||
10703 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
10704 | update_global_location_list (inserting); | |
10705 | } | |
10706 | ||
10707 | /* Clear BKP from a BPS. */ | |
10708 | ||
10709 | static void | |
10710 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
10711 | { | |
10712 | bpstat bs; | |
10713 | ||
10714 | for (bs = bps; bs; bs = bs->next) | |
10715 | if (bs->breakpoint_at == bpt) | |
10716 | { | |
10717 | bs->breakpoint_at = NULL; | |
10718 | bs->old_val = NULL; | |
10719 | /* bs->commands will be freed later. */ | |
10720 | } | |
10721 | } | |
10722 | ||
10723 | /* Callback for iterate_over_threads. */ | |
10724 | static int | |
10725 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
10726 | { | |
10727 | struct breakpoint *bpt = data; | |
10728 | ||
10729 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
10730 | return 0; | |
10731 | } | |
10732 | ||
10733 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
10734 | callbacks. */ | |
10735 | ||
10736 | static void | |
10737 | say_where (struct breakpoint *b) | |
10738 | { | |
79a45e25 | 10739 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10740 | struct value_print_options opts; |
10741 | ||
10742 | get_user_print_options (&opts); | |
10743 | ||
10744 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
10745 | single string. */ | |
10746 | if (b->loc == NULL) | |
10747 | { | |
10748 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
10749 | } | |
10750 | else | |
10751 | { | |
10752 | if (opts.addressprint || b->source_file == NULL) | |
10753 | { | |
10754 | printf_filtered (" at "); | |
10755 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
10756 | gdb_stdout); | |
10757 | } | |
10758 | if (b->source_file) | |
10759 | printf_filtered (": file %s, line %d.", | |
10760 | b->source_file, b->line_number); | |
10761 | ||
10762 | if (b->loc->next) | |
10763 | { | |
10764 | struct bp_location *loc = b->loc; | |
10765 | int n = 0; | |
10766 | for (; loc; loc = loc->next) | |
10767 | ++n; | |
10768 | printf_filtered (" (%d locations)", n); | |
10769 | } | |
10770 | } | |
10771 | } | |
10772 | ||
348d480f PA |
10773 | /* Default bp_location_ops methods. */ |
10774 | ||
10775 | static void | |
10776 | bp_location_dtor (struct bp_location *self) | |
10777 | { | |
10778 | xfree (self->cond); | |
10779 | xfree (self->function_name); | |
10780 | } | |
10781 | ||
10782 | static const struct bp_location_ops bp_location_ops = | |
10783 | { | |
10784 | bp_location_dtor | |
10785 | }; | |
10786 | ||
2060206e PA |
10787 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
10788 | inherit from. */ | |
348d480f | 10789 | |
2060206e PA |
10790 | static void |
10791 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
10792 | { |
10793 | decref_counted_command_line (&self->commands); | |
10794 | xfree (self->cond_string); | |
348d480f PA |
10795 | xfree (self->addr_string); |
10796 | xfree (self->addr_string_range_end); | |
348d480f PA |
10797 | xfree (self->source_file); |
10798 | } | |
10799 | ||
2060206e PA |
10800 | static struct bp_location * |
10801 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
10802 | { |
10803 | struct bp_location *loc; | |
10804 | ||
10805 | loc = XNEW (struct bp_location); | |
10806 | init_bp_location (loc, &bp_location_ops, self); | |
10807 | return loc; | |
10808 | } | |
10809 | ||
2060206e PA |
10810 | static void |
10811 | base_breakpoint_re_set (struct breakpoint *b) | |
10812 | { | |
10813 | /* Nothing to re-set. */ | |
10814 | } | |
10815 | ||
10816 | #define internal_error_pure_virtual_called() \ | |
10817 | gdb_assert_not_reached ("pure virtual function called") | |
10818 | ||
10819 | static int | |
10820 | base_breakpoint_insert_location (struct bp_location *bl) | |
10821 | { | |
10822 | internal_error_pure_virtual_called (); | |
10823 | } | |
10824 | ||
10825 | static int | |
10826 | base_breakpoint_remove_location (struct bp_location *bl) | |
10827 | { | |
10828 | internal_error_pure_virtual_called (); | |
10829 | } | |
10830 | ||
10831 | static int | |
10832 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
10833 | struct address_space *aspace, | |
10834 | CORE_ADDR bp_addr) | |
10835 | { | |
10836 | internal_error_pure_virtual_called (); | |
10837 | } | |
10838 | ||
10839 | static void | |
10840 | base_breakpoint_check_status (bpstat bs) | |
10841 | { | |
10842 | /* Always stop. */ | |
10843 | } | |
10844 | ||
10845 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
10846 | errors. */ | |
10847 | ||
10848 | static int | |
10849 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
10850 | { | |
10851 | internal_error_pure_virtual_called (); | |
10852 | } | |
10853 | ||
10854 | /* A "resources_needed" breakpoint_ops method that just internal | |
10855 | errors. */ | |
10856 | ||
10857 | static int | |
10858 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
10859 | { | |
10860 | internal_error_pure_virtual_called (); | |
10861 | } | |
10862 | ||
10863 | static enum print_stop_action | |
10864 | base_breakpoint_print_it (bpstat bs) | |
10865 | { | |
10866 | internal_error_pure_virtual_called (); | |
10867 | } | |
10868 | ||
10869 | static void | |
10870 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
10871 | struct ui_out *uiout) | |
10872 | { | |
10873 | /* nothing */ | |
10874 | } | |
10875 | ||
10876 | static void | |
10877 | base_breakpoint_print_mention (struct breakpoint *b) | |
10878 | { | |
10879 | internal_error_pure_virtual_called (); | |
10880 | } | |
10881 | ||
10882 | static void | |
10883 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
10884 | { | |
10885 | internal_error_pure_virtual_called (); | |
10886 | } | |
10887 | ||
10888 | static struct breakpoint_ops base_breakpoint_ops = | |
10889 | { | |
10890 | base_breakpoint_dtor, | |
10891 | base_breakpoint_allocate_location, | |
10892 | base_breakpoint_re_set, | |
10893 | base_breakpoint_insert_location, | |
10894 | base_breakpoint_remove_location, | |
10895 | base_breakpoint_breakpoint_hit, | |
10896 | base_breakpoint_check_status, | |
10897 | base_breakpoint_resources_needed, | |
10898 | base_breakpoint_works_in_software_mode, | |
10899 | base_breakpoint_print_it, | |
10900 | NULL, | |
10901 | base_breakpoint_print_one_detail, | |
10902 | base_breakpoint_print_mention, | |
10903 | base_breakpoint_print_recreate | |
10904 | }; | |
10905 | ||
10906 | /* Default breakpoint_ops methods. */ | |
10907 | ||
10908 | static void | |
348d480f PA |
10909 | bkpt_re_set (struct breakpoint *b) |
10910 | { | |
06edf0c0 PA |
10911 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
10912 | if (b->enable_state == bp_startup_disabled) | |
10913 | return; | |
348d480f | 10914 | |
06edf0c0 PA |
10915 | /* FIXME: is this still reachable? */ |
10916 | if (b->addr_string == NULL) | |
10917 | { | |
10918 | /* Anything without a string can't be re-set. */ | |
348d480f | 10919 | delete_breakpoint (b); |
06edf0c0 | 10920 | return; |
348d480f | 10921 | } |
06edf0c0 PA |
10922 | |
10923 | breakpoint_re_set_default (b); | |
348d480f PA |
10924 | } |
10925 | ||
2060206e | 10926 | static int |
348d480f PA |
10927 | bkpt_insert_location (struct bp_location *bl) |
10928 | { | |
10929 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
10930 | return target_insert_hw_breakpoint (bl->gdbarch, | |
10931 | &bl->target_info); | |
10932 | else | |
10933 | return target_insert_breakpoint (bl->gdbarch, | |
10934 | &bl->target_info); | |
10935 | } | |
10936 | ||
2060206e | 10937 | static int |
348d480f PA |
10938 | bkpt_remove_location (struct bp_location *bl) |
10939 | { | |
10940 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
10941 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
10942 | else | |
10943 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
10944 | } | |
10945 | ||
2060206e | 10946 | static int |
348d480f PA |
10947 | bkpt_breakpoint_hit (const struct bp_location *bl, |
10948 | struct address_space *aspace, CORE_ADDR bp_addr) | |
10949 | { | |
10950 | struct breakpoint *b = bl->owner; | |
10951 | ||
10952 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, | |
10953 | aspace, bp_addr)) | |
10954 | return 0; | |
10955 | ||
10956 | if (overlay_debugging /* unmapped overlay section */ | |
10957 | && section_is_overlay (bl->section) | |
10958 | && !section_is_mapped (bl->section)) | |
10959 | return 0; | |
10960 | ||
10961 | return 1; | |
10962 | } | |
10963 | ||
2060206e | 10964 | static int |
348d480f PA |
10965 | bkpt_resources_needed (const struct bp_location *bl) |
10966 | { | |
10967 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
10968 | ||
10969 | return 1; | |
10970 | } | |
10971 | ||
2060206e | 10972 | static enum print_stop_action |
348d480f PA |
10973 | bkpt_print_it (bpstat bs) |
10974 | { | |
348d480f PA |
10975 | struct breakpoint *b; |
10976 | const struct bp_location *bl; | |
001c8c33 | 10977 | int bp_temp; |
79a45e25 | 10978 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10979 | |
10980 | gdb_assert (bs->bp_location_at != NULL); | |
10981 | ||
10982 | bl = bs->bp_location_at; | |
10983 | b = bs->breakpoint_at; | |
10984 | ||
001c8c33 PA |
10985 | bp_temp = b->disposition == disp_del; |
10986 | if (bl->address != bl->requested_address) | |
10987 | breakpoint_adjustment_warning (bl->requested_address, | |
10988 | bl->address, | |
10989 | b->number, 1); | |
10990 | annotate_breakpoint (b->number); | |
10991 | if (bp_temp) | |
10992 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
10993 | else | |
10994 | ui_out_text (uiout, "\nBreakpoint "); | |
10995 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 10996 | { |
001c8c33 PA |
10997 | ui_out_field_string (uiout, "reason", |
10998 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10999 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 11000 | } |
001c8c33 PA |
11001 | ui_out_field_int (uiout, "bkptno", b->number); |
11002 | ui_out_text (uiout, ", "); | |
06edf0c0 | 11003 | |
001c8c33 | 11004 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
11005 | } |
11006 | ||
2060206e | 11007 | static void |
06edf0c0 PA |
11008 | bkpt_print_mention (struct breakpoint *b) |
11009 | { | |
79a45e25 | 11010 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
11011 | return; |
11012 | ||
11013 | switch (b->type) | |
11014 | { | |
11015 | case bp_breakpoint: | |
11016 | case bp_gnu_ifunc_resolver: | |
11017 | if (b->disposition == disp_del) | |
11018 | printf_filtered (_("Temporary breakpoint")); | |
11019 | else | |
11020 | printf_filtered (_("Breakpoint")); | |
11021 | printf_filtered (_(" %d"), b->number); | |
11022 | if (b->type == bp_gnu_ifunc_resolver) | |
11023 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
11024 | break; | |
11025 | case bp_hardware_breakpoint: | |
11026 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
11027 | break; | |
11028 | } | |
11029 | ||
11030 | say_where (b); | |
11031 | } | |
11032 | ||
2060206e | 11033 | static void |
06edf0c0 PA |
11034 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
11035 | { | |
11036 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
11037 | fprintf_unfiltered (fp, "tbreak"); | |
11038 | else if (tp->type == bp_breakpoint) | |
11039 | fprintf_unfiltered (fp, "break"); | |
11040 | else if (tp->type == bp_hardware_breakpoint | |
11041 | && tp->disposition == disp_del) | |
11042 | fprintf_unfiltered (fp, "thbreak"); | |
11043 | else if (tp->type == bp_hardware_breakpoint) | |
11044 | fprintf_unfiltered (fp, "hbreak"); | |
11045 | else | |
11046 | internal_error (__FILE__, __LINE__, | |
11047 | _("unhandled breakpoint type %d"), (int) tp->type); | |
11048 | ||
2060206e | 11049 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
dd11a36c | 11050 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
11051 | } |
11052 | ||
06edf0c0 PA |
11053 | /* Virtual table for internal breakpoints. */ |
11054 | ||
11055 | static void | |
11056 | internal_bkpt_re_set (struct breakpoint *b) | |
11057 | { | |
11058 | switch (b->type) | |
11059 | { | |
11060 | /* Delete overlay event and longjmp master breakpoints; they | |
11061 | will be reset later by breakpoint_re_set. */ | |
11062 | case bp_overlay_event: | |
11063 | case bp_longjmp_master: | |
11064 | case bp_std_terminate_master: | |
11065 | case bp_exception_master: | |
11066 | delete_breakpoint (b); | |
11067 | break; | |
11068 | ||
11069 | /* This breakpoint is special, it's set up when the inferior | |
11070 | starts and we really don't want to touch it. */ | |
11071 | case bp_shlib_event: | |
11072 | ||
11073 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
11074 | it is set up, we do not want to touch it. */ | |
11075 | case bp_thread_event: | |
11076 | break; | |
11077 | } | |
11078 | } | |
11079 | ||
11080 | static void | |
11081 | internal_bkpt_check_status (bpstat bs) | |
11082 | { | |
11083 | /* We do not stop for these. */ | |
11084 | bs->stop = 0; | |
11085 | } | |
11086 | ||
11087 | static enum print_stop_action | |
11088 | internal_bkpt_print_it (bpstat bs) | |
11089 | { | |
06edf0c0 | 11090 | struct breakpoint *b; |
06edf0c0 | 11091 | |
06edf0c0 PA |
11092 | b = bs->breakpoint_at; |
11093 | ||
06edf0c0 PA |
11094 | switch (b->type) |
11095 | { | |
348d480f PA |
11096 | case bp_shlib_event: |
11097 | /* Did we stop because the user set the stop_on_solib_events | |
11098 | variable? (If so, we report this as a generic, "Stopped due | |
11099 | to shlib event" message.) */ | |
11100 | printf_filtered (_("Stopped due to shared library event\n")); | |
348d480f PA |
11101 | break; |
11102 | ||
11103 | case bp_thread_event: | |
11104 | /* Not sure how we will get here. | |
11105 | GDB should not stop for these breakpoints. */ | |
11106 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11107 | break; |
11108 | ||
11109 | case bp_overlay_event: | |
11110 | /* By analogy with the thread event, GDB should not stop for these. */ | |
11111 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11112 | break; |
11113 | ||
11114 | case bp_longjmp_master: | |
11115 | /* These should never be enabled. */ | |
11116 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11117 | break; |
11118 | ||
11119 | case bp_std_terminate_master: | |
11120 | /* These should never be enabled. */ | |
11121 | printf_filtered (_("std::terminate Master Breakpoint: " | |
11122 | "gdb should not stop!\n")); | |
348d480f PA |
11123 | break; |
11124 | ||
11125 | case bp_exception_master: | |
11126 | /* These should never be enabled. */ | |
11127 | printf_filtered (_("Exception Master Breakpoint: " | |
11128 | "gdb should not stop!\n")); | |
06edf0c0 PA |
11129 | break; |
11130 | } | |
11131 | ||
001c8c33 | 11132 | return PRINT_NOTHING; |
06edf0c0 PA |
11133 | } |
11134 | ||
11135 | static void | |
11136 | internal_bkpt_print_mention (struct breakpoint *b) | |
11137 | { | |
11138 | /* Nothing to mention. These breakpoints are internal. */ | |
11139 | } | |
11140 | ||
06edf0c0 PA |
11141 | /* Virtual table for momentary breakpoints */ |
11142 | ||
11143 | static void | |
11144 | momentary_bkpt_re_set (struct breakpoint *b) | |
11145 | { | |
11146 | /* Keep temporary breakpoints, which can be encountered when we step | |
11147 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
11148 | Otherwise these should have been blown away via the cleanup chain | |
11149 | or by breakpoint_init_inferior when we rerun the executable. */ | |
11150 | } | |
11151 | ||
11152 | static void | |
11153 | momentary_bkpt_check_status (bpstat bs) | |
11154 | { | |
11155 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
11156 | } | |
11157 | ||
11158 | static enum print_stop_action | |
11159 | momentary_bkpt_print_it (bpstat bs) | |
11160 | { | |
79a45e25 PA |
11161 | struct ui_out *uiout = current_uiout; |
11162 | ||
001c8c33 | 11163 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 11164 | { |
001c8c33 | 11165 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 11166 | |
001c8c33 PA |
11167 | switch (b->type) |
11168 | { | |
11169 | case bp_finish: | |
11170 | ui_out_field_string | |
11171 | (uiout, "reason", | |
11172 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
11173 | break; | |
348d480f | 11174 | |
001c8c33 PA |
11175 | case bp_until: |
11176 | ui_out_field_string | |
11177 | (uiout, "reason", | |
11178 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
11179 | break; | |
11180 | } | |
348d480f PA |
11181 | } |
11182 | ||
001c8c33 | 11183 | return PRINT_UNKNOWN; |
348d480f PA |
11184 | } |
11185 | ||
06edf0c0 PA |
11186 | static void |
11187 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 11188 | { |
06edf0c0 | 11189 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
11190 | } |
11191 | ||
348d480f | 11192 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 11193 | |
348d480f PA |
11194 | static void |
11195 | tracepoint_re_set (struct breakpoint *b) | |
11196 | { | |
11197 | breakpoint_re_set_default (b); | |
11198 | } | |
876fa593 | 11199 | |
348d480f PA |
11200 | static int |
11201 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
11202 | struct address_space *aspace, CORE_ADDR bp_addr) | |
11203 | { | |
11204 | /* By definition, the inferior does not report stops at | |
11205 | tracepoints. */ | |
11206 | return 0; | |
74960c60 VP |
11207 | } |
11208 | ||
11209 | static void | |
348d480f PA |
11210 | tracepoint_print_one_detail (const struct breakpoint *self, |
11211 | struct ui_out *uiout) | |
74960c60 | 11212 | { |
d9b3f62e PA |
11213 | struct tracepoint *tp = (struct tracepoint *) self; |
11214 | if (tp->static_trace_marker_id) | |
348d480f PA |
11215 | { |
11216 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 11217 | |
348d480f PA |
11218 | ui_out_text (uiout, "\tmarker id is "); |
11219 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 11220 | tp->static_trace_marker_id); |
348d480f PA |
11221 | ui_out_text (uiout, "\n"); |
11222 | } | |
0d381245 VP |
11223 | } |
11224 | ||
a474d7c2 | 11225 | static void |
348d480f | 11226 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 11227 | { |
79a45e25 | 11228 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 11229 | return; |
cc59ec59 | 11230 | |
348d480f PA |
11231 | switch (b->type) |
11232 | { | |
11233 | case bp_tracepoint: | |
11234 | printf_filtered (_("Tracepoint")); | |
11235 | printf_filtered (_(" %d"), b->number); | |
11236 | break; | |
11237 | case bp_fast_tracepoint: | |
11238 | printf_filtered (_("Fast tracepoint")); | |
11239 | printf_filtered (_(" %d"), b->number); | |
11240 | break; | |
11241 | case bp_static_tracepoint: | |
11242 | printf_filtered (_("Static tracepoint")); | |
11243 | printf_filtered (_(" %d"), b->number); | |
11244 | break; | |
11245 | default: | |
11246 | internal_error (__FILE__, __LINE__, | |
11247 | _("unhandled tracepoint type %d"), (int) b->type); | |
11248 | } | |
11249 | ||
11250 | say_where (b); | |
a474d7c2 PA |
11251 | } |
11252 | ||
348d480f | 11253 | static void |
d9b3f62e | 11254 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 11255 | { |
d9b3f62e PA |
11256 | struct tracepoint *tp = (struct tracepoint *) self; |
11257 | ||
11258 | if (self->type == bp_fast_tracepoint) | |
348d480f | 11259 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 11260 | if (self->type == bp_static_tracepoint) |
348d480f | 11261 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 11262 | else if (self->type == bp_tracepoint) |
348d480f PA |
11263 | fprintf_unfiltered (fp, "trace"); |
11264 | else | |
11265 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 11266 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 11267 | |
d9b3f62e PA |
11268 | fprintf_unfiltered (fp, " %s", self->addr_string); |
11269 | print_recreate_thread (self, fp); | |
11270 | ||
11271 | if (tp->pass_count) | |
11272 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
11273 | } |
11274 | ||
2060206e | 11275 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 11276 | |
53a5351d | 11277 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 11278 | structures. */ |
c906108c SS |
11279 | |
11280 | void | |
fba45db2 | 11281 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 11282 | { |
52f0bd74 | 11283 | struct breakpoint *b; |
c906108c | 11284 | |
8a3fe4f8 | 11285 | gdb_assert (bpt != NULL); |
c906108c | 11286 | |
4a64f543 MS |
11287 | /* Has this bp already been deleted? This can happen because |
11288 | multiple lists can hold pointers to bp's. bpstat lists are | |
11289 | especial culprits. | |
11290 | ||
11291 | One example of this happening is a watchpoint's scope bp. When | |
11292 | the scope bp triggers, we notice that the watchpoint is out of | |
11293 | scope, and delete it. We also delete its scope bp. But the | |
11294 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
11295 | That bpstat is then checked for auto-deleting bp's, which are | |
11296 | deleted. | |
11297 | ||
11298 | A real solution to this problem might involve reference counts in | |
11299 | bp's, and/or giving them pointers back to their referencing | |
11300 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
11301 | storage when no more references were extent. A cheaper bandaid | |
11302 | was chosen. */ | |
c906108c SS |
11303 | if (bpt->type == bp_none) |
11304 | return; | |
11305 | ||
4a64f543 MS |
11306 | /* At least avoid this stale reference until the reference counting |
11307 | of breakpoints gets resolved. */ | |
d0fb5eae | 11308 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 11309 | { |
d0fb5eae | 11310 | struct breakpoint *related; |
3a5c3e22 | 11311 | struct watchpoint *w; |
d0fb5eae JK |
11312 | |
11313 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 11314 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 11315 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
11316 | w = (struct watchpoint *) bpt; |
11317 | else | |
11318 | w = NULL; | |
11319 | if (w != NULL) | |
11320 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
11321 | |
11322 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
11323 | for (related = bpt; related->related_breakpoint != bpt; | |
11324 | related = related->related_breakpoint); | |
11325 | related->related_breakpoint = bpt->related_breakpoint; | |
11326 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
11327 | } |
11328 | ||
a9634178 TJB |
11329 | /* watch_command_1 creates a watchpoint but only sets its number if |
11330 | update_watchpoint succeeds in creating its bp_locations. If there's | |
11331 | a problem in that process, we'll be asked to delete the half-created | |
11332 | watchpoint. In that case, don't announce the deletion. */ | |
11333 | if (bpt->number) | |
11334 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 11335 | |
c906108c SS |
11336 | if (breakpoint_chain == bpt) |
11337 | breakpoint_chain = bpt->next; | |
11338 | ||
c906108c SS |
11339 | ALL_BREAKPOINTS (b) |
11340 | if (b->next == bpt) | |
c5aa993b JM |
11341 | { |
11342 | b->next = bpt->next; | |
11343 | break; | |
11344 | } | |
c906108c | 11345 | |
f431efe5 PA |
11346 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
11347 | been freed. */ | |
11348 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 11349 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
11350 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
11351 | commands are associated with the bpstat; if we remove it here, | |
11352 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
11353 | event-top.c won't do anything, and temporary breakpoints with | |
11354 | commands won't work. */ | |
11355 | ||
11356 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
11357 | ||
4a64f543 MS |
11358 | /* Now that breakpoint is removed from breakpoint list, update the |
11359 | global location list. This will remove locations that used to | |
11360 | belong to this breakpoint. Do this before freeing the breakpoint | |
11361 | itself, since remove_breakpoint looks at location's owner. It | |
11362 | might be better design to have location completely | |
11363 | self-contained, but it's not the case now. */ | |
b60e7edf | 11364 | update_global_location_list (0); |
74960c60 | 11365 | |
348d480f | 11366 | bpt->ops->dtor (bpt); |
4a64f543 MS |
11367 | /* On the chance that someone will soon try again to delete this |
11368 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 11369 | bpt->type = bp_none; |
b8c9b27d | 11370 | xfree (bpt); |
c906108c SS |
11371 | } |
11372 | ||
4d6140d9 AC |
11373 | static void |
11374 | do_delete_breakpoint_cleanup (void *b) | |
11375 | { | |
11376 | delete_breakpoint (b); | |
11377 | } | |
11378 | ||
11379 | struct cleanup * | |
11380 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
11381 | { | |
11382 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
11383 | } | |
11384 | ||
51be5b68 PA |
11385 | /* Iterator function to call a user-provided callback function once |
11386 | for each of B and its related breakpoints. */ | |
11387 | ||
11388 | static void | |
11389 | iterate_over_related_breakpoints (struct breakpoint *b, | |
11390 | void (*function) (struct breakpoint *, | |
11391 | void *), | |
11392 | void *data) | |
11393 | { | |
11394 | struct breakpoint *related; | |
11395 | ||
11396 | related = b; | |
11397 | do | |
11398 | { | |
11399 | struct breakpoint *next; | |
11400 | ||
11401 | /* FUNCTION may delete RELATED. */ | |
11402 | next = related->related_breakpoint; | |
11403 | ||
11404 | if (next == related) | |
11405 | { | |
11406 | /* RELATED is the last ring entry. */ | |
11407 | function (related, data); | |
11408 | ||
11409 | /* FUNCTION may have deleted it, so we'd never reach back to | |
11410 | B. There's nothing left to do anyway, so just break | |
11411 | out. */ | |
11412 | break; | |
11413 | } | |
11414 | else | |
11415 | function (related, data); | |
11416 | ||
11417 | related = next; | |
11418 | } | |
11419 | while (related != b); | |
11420 | } | |
95a42b64 TT |
11421 | |
11422 | static void | |
11423 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11424 | { | |
11425 | delete_breakpoint (b); | |
11426 | } | |
11427 | ||
51be5b68 PA |
11428 | /* A callback for map_breakpoint_numbers that calls |
11429 | delete_breakpoint. */ | |
11430 | ||
11431 | static void | |
11432 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11433 | { | |
11434 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
11435 | } | |
11436 | ||
c906108c | 11437 | void |
fba45db2 | 11438 | delete_command (char *arg, int from_tty) |
c906108c | 11439 | { |
35df4500 | 11440 | struct breakpoint *b, *b_tmp; |
c906108c | 11441 | |
ea9365bb TT |
11442 | dont_repeat (); |
11443 | ||
c906108c SS |
11444 | if (arg == 0) |
11445 | { | |
11446 | int breaks_to_delete = 0; | |
11447 | ||
46c6471b PA |
11448 | /* Delete all breakpoints if no argument. Do not delete |
11449 | internal breakpoints, these have to be deleted with an | |
11450 | explicit breakpoint number argument. */ | |
c5aa993b | 11451 | ALL_BREAKPOINTS (b) |
46c6471b | 11452 | if (user_breakpoint_p (b)) |
973d738b DJ |
11453 | { |
11454 | breaks_to_delete = 1; | |
11455 | break; | |
11456 | } | |
c906108c SS |
11457 | |
11458 | /* Ask user only if there are some breakpoints to delete. */ | |
11459 | if (!from_tty | |
e2e0b3e5 | 11460 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 11461 | { |
35df4500 | 11462 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 11463 | if (user_breakpoint_p (b)) |
c5aa993b | 11464 | delete_breakpoint (b); |
c906108c SS |
11465 | } |
11466 | } | |
11467 | else | |
51be5b68 | 11468 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
11469 | } |
11470 | ||
0d381245 VP |
11471 | static int |
11472 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 11473 | { |
0d381245 VP |
11474 | for (; loc; loc = loc->next) |
11475 | if (!loc->shlib_disabled) | |
11476 | return 0; | |
11477 | return 1; | |
fe3f5fa8 VP |
11478 | } |
11479 | ||
776592bf DE |
11480 | /* Subroutine of update_breakpoint_locations to simplify it. |
11481 | Return non-zero if multiple fns in list LOC have the same name. | |
11482 | Null names are ignored. */ | |
11483 | ||
11484 | static int | |
11485 | ambiguous_names_p (struct bp_location *loc) | |
11486 | { | |
11487 | struct bp_location *l; | |
11488 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
11489 | (int (*) (const void *, |
11490 | const void *)) streq, | |
776592bf DE |
11491 | NULL, xcalloc, xfree); |
11492 | ||
11493 | for (l = loc; l != NULL; l = l->next) | |
11494 | { | |
11495 | const char **slot; | |
11496 | const char *name = l->function_name; | |
11497 | ||
11498 | /* Allow for some names to be NULL, ignore them. */ | |
11499 | if (name == NULL) | |
11500 | continue; | |
11501 | ||
11502 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
11503 | INSERT); | |
4a64f543 MS |
11504 | /* NOTE: We can assume slot != NULL here because xcalloc never |
11505 | returns NULL. */ | |
776592bf DE |
11506 | if (*slot != NULL) |
11507 | { | |
11508 | htab_delete (htab); | |
11509 | return 1; | |
11510 | } | |
11511 | *slot = name; | |
11512 | } | |
11513 | ||
11514 | htab_delete (htab); | |
11515 | return 0; | |
11516 | } | |
11517 | ||
0fb4aa4b PA |
11518 | /* When symbols change, it probably means the sources changed as well, |
11519 | and it might mean the static tracepoint markers are no longer at | |
11520 | the same address or line numbers they used to be at last we | |
11521 | checked. Losing your static tracepoints whenever you rebuild is | |
11522 | undesirable. This function tries to resync/rematch gdb static | |
11523 | tracepoints with the markers on the target, for static tracepoints | |
11524 | that have not been set by marker id. Static tracepoint that have | |
11525 | been set by marker id are reset by marker id in breakpoint_re_set. | |
11526 | The heuristic is: | |
11527 | ||
11528 | 1) For a tracepoint set at a specific address, look for a marker at | |
11529 | the old PC. If one is found there, assume to be the same marker. | |
11530 | If the name / string id of the marker found is different from the | |
11531 | previous known name, assume that means the user renamed the marker | |
11532 | in the sources, and output a warning. | |
11533 | ||
11534 | 2) For a tracepoint set at a given line number, look for a marker | |
11535 | at the new address of the old line number. If one is found there, | |
11536 | assume to be the same marker. If the name / string id of the | |
11537 | marker found is different from the previous known name, assume that | |
11538 | means the user renamed the marker in the sources, and output a | |
11539 | warning. | |
11540 | ||
11541 | 3) If a marker is no longer found at the same address or line, it | |
11542 | may mean the marker no longer exists. But it may also just mean | |
11543 | the code changed a bit. Maybe the user added a few lines of code | |
11544 | that made the marker move up or down (in line number terms). Ask | |
11545 | the target for info about the marker with the string id as we knew | |
11546 | it. If found, update line number and address in the matching | |
11547 | static tracepoint. This will get confused if there's more than one | |
11548 | marker with the same ID (possible in UST, although unadvised | |
11549 | precisely because it confuses tools). */ | |
11550 | ||
11551 | static struct symtab_and_line | |
11552 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
11553 | { | |
d9b3f62e | 11554 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
11555 | struct static_tracepoint_marker marker; |
11556 | CORE_ADDR pc; | |
11557 | int i; | |
11558 | ||
11559 | pc = sal.pc; | |
11560 | if (sal.line) | |
11561 | find_line_pc (sal.symtab, sal.line, &pc); | |
11562 | ||
11563 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
11564 | { | |
d9b3f62e | 11565 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
11566 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
11567 | b->number, | |
d9b3f62e | 11568 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 11569 | |
d9b3f62e PA |
11570 | xfree (tp->static_trace_marker_id); |
11571 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
11572 | release_static_tracepoint_marker (&marker); |
11573 | ||
11574 | return sal; | |
11575 | } | |
11576 | ||
11577 | /* Old marker wasn't found on target at lineno. Try looking it up | |
11578 | by string ID. */ | |
11579 | if (!sal.explicit_pc | |
11580 | && sal.line != 0 | |
11581 | && sal.symtab != NULL | |
d9b3f62e | 11582 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
11583 | { |
11584 | VEC(static_tracepoint_marker_p) *markers; | |
11585 | ||
11586 | markers | |
d9b3f62e | 11587 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
11588 | |
11589 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
11590 | { | |
11591 | struct symtab_and_line sal; | |
11592 | struct symbol *sym; | |
11593 | struct static_tracepoint_marker *marker; | |
79a45e25 | 11594 | struct ui_out *uiout = current_uiout; |
0fb4aa4b PA |
11595 | |
11596 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
11597 | ||
d9b3f62e PA |
11598 | xfree (tp->static_trace_marker_id); |
11599 | tp->static_trace_marker_id = xstrdup (marker->str_id); | |
0fb4aa4b PA |
11600 | |
11601 | warning (_("marker for static tracepoint %d (%s) not " | |
11602 | "found at previous line number"), | |
d9b3f62e | 11603 | b->number, tp->static_trace_marker_id); |
0fb4aa4b PA |
11604 | |
11605 | init_sal (&sal); | |
11606 | ||
11607 | sal.pc = marker->address; | |
11608 | ||
11609 | sal = find_pc_line (marker->address, 0); | |
11610 | sym = find_pc_sect_function (marker->address, NULL); | |
11611 | ui_out_text (uiout, "Now in "); | |
11612 | if (sym) | |
11613 | { | |
11614 | ui_out_field_string (uiout, "func", | |
11615 | SYMBOL_PRINT_NAME (sym)); | |
11616 | ui_out_text (uiout, " at "); | |
11617 | } | |
11618 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
11619 | ui_out_text (uiout, ":"); | |
11620 | ||
11621 | if (ui_out_is_mi_like_p (uiout)) | |
11622 | { | |
11623 | char *fullname = symtab_to_fullname (sal.symtab); | |
11624 | ||
11625 | if (fullname) | |
11626 | ui_out_field_string (uiout, "fullname", fullname); | |
11627 | } | |
11628 | ||
11629 | ui_out_field_int (uiout, "line", sal.line); | |
11630 | ui_out_text (uiout, "\n"); | |
11631 | ||
11632 | b->line_number = sal.line; | |
11633 | ||
11634 | xfree (b->source_file); | |
11635 | if (sym) | |
11636 | b->source_file = xstrdup (sal.symtab->filename); | |
11637 | else | |
11638 | b->source_file = NULL; | |
11639 | ||
11640 | xfree (b->addr_string); | |
11641 | b->addr_string = xstrprintf ("%s:%d", | |
11642 | sal.symtab->filename, b->line_number); | |
11643 | ||
11644 | /* Might be nice to check if function changed, and warn if | |
11645 | so. */ | |
11646 | ||
11647 | release_static_tracepoint_marker (marker); | |
11648 | } | |
11649 | } | |
11650 | return sal; | |
11651 | } | |
11652 | ||
8d3788bd VP |
11653 | /* Returns 1 iff locations A and B are sufficiently same that |
11654 | we don't need to report breakpoint as changed. */ | |
11655 | ||
11656 | static int | |
11657 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
11658 | { | |
11659 | while (a && b) | |
11660 | { | |
11661 | if (a->address != b->address) | |
11662 | return 0; | |
11663 | ||
11664 | if (a->shlib_disabled != b->shlib_disabled) | |
11665 | return 0; | |
11666 | ||
11667 | if (a->enabled != b->enabled) | |
11668 | return 0; | |
11669 | ||
11670 | a = a->next; | |
11671 | b = b->next; | |
11672 | } | |
11673 | ||
11674 | if ((a == NULL) != (b == NULL)) | |
11675 | return 0; | |
11676 | ||
11677 | return 1; | |
11678 | } | |
11679 | ||
f1310107 TJB |
11680 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
11681 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
11682 | a ranged breakpoint. */ | |
11683 | ||
0e30163f | 11684 | void |
0d381245 | 11685 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
11686 | struct symtabs_and_lines sals, |
11687 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
11688 | { |
11689 | int i; | |
0d381245 VP |
11690 | struct bp_location *existing_locations = b->loc; |
11691 | ||
f1310107 TJB |
11692 | /* Ranged breakpoints have only one start location and one end location. */ |
11693 | gdb_assert (sals_end.nelts == 0 || (sals.nelts == 1 && sals_end.nelts == 1)); | |
11694 | ||
4a64f543 MS |
11695 | /* If there's no new locations, and all existing locations are |
11696 | pending, don't do anything. This optimizes the common case where | |
11697 | all locations are in the same shared library, that was unloaded. | |
11698 | We'd like to retain the location, so that when the library is | |
11699 | loaded again, we don't loose the enabled/disabled status of the | |
11700 | individual locations. */ | |
0d381245 | 11701 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
11702 | return; |
11703 | ||
fe3f5fa8 VP |
11704 | b->loc = NULL; |
11705 | ||
0d381245 | 11706 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 11707 | { |
0d381245 | 11708 | struct bp_location *new_loc = |
39d61571 | 11709 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 11710 | |
0d381245 VP |
11711 | /* Reparse conditions, they might contain references to the |
11712 | old symtab. */ | |
11713 | if (b->cond_string != NULL) | |
11714 | { | |
f1310107 | 11715 | char *s; |
0d381245 | 11716 | struct gdb_exception e; |
fe3f5fa8 | 11717 | |
0d381245 VP |
11718 | s = b->cond_string; |
11719 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11720 | { | |
11721 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
11722 | 0); | |
11723 | } | |
11724 | if (e.reason < 0) | |
11725 | { | |
3e43a32a MS |
11726 | warning (_("failed to reevaluate condition " |
11727 | "for breakpoint %d: %s"), | |
0d381245 VP |
11728 | b->number, e.message); |
11729 | new_loc->enabled = 0; | |
11730 | } | |
11731 | } | |
fe3f5fa8 | 11732 | |
0d381245 VP |
11733 | if (b->source_file != NULL) |
11734 | xfree (b->source_file); | |
11735 | if (sals.sals[i].symtab == NULL) | |
11736 | b->source_file = NULL; | |
11737 | else | |
1b36a34b | 11738 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 11739 | |
0d381245 VP |
11740 | if (b->line_number == 0) |
11741 | b->line_number = sals.sals[i].line; | |
f1310107 TJB |
11742 | |
11743 | if (sals_end.nelts) | |
11744 | { | |
11745 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
11746 | ||
11747 | new_loc->length = end - sals.sals[0].pc + 1; | |
11748 | } | |
0d381245 | 11749 | } |
fe3f5fa8 | 11750 | |
514f746b AR |
11751 | /* Update locations of permanent breakpoints. */ |
11752 | if (b->enable_state == bp_permanent) | |
11753 | make_breakpoint_permanent (b); | |
11754 | ||
4a64f543 MS |
11755 | /* If possible, carry over 'disable' status from existing |
11756 | breakpoints. */ | |
0d381245 VP |
11757 | { |
11758 | struct bp_location *e = existing_locations; | |
776592bf DE |
11759 | /* If there are multiple breakpoints with the same function name, |
11760 | e.g. for inline functions, comparing function names won't work. | |
11761 | Instead compare pc addresses; this is just a heuristic as things | |
11762 | may have moved, but in practice it gives the correct answer | |
11763 | often enough until a better solution is found. */ | |
11764 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
11765 | ||
0d381245 VP |
11766 | for (; e; e = e->next) |
11767 | { | |
11768 | if (!e->enabled && e->function_name) | |
11769 | { | |
11770 | struct bp_location *l = b->loc; | |
776592bf DE |
11771 | if (have_ambiguous_names) |
11772 | { | |
11773 | for (; l; l = l->next) | |
f1310107 | 11774 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
11775 | { |
11776 | l->enabled = 0; | |
11777 | break; | |
11778 | } | |
11779 | } | |
11780 | else | |
11781 | { | |
11782 | for (; l; l = l->next) | |
11783 | if (l->function_name | |
11784 | && strcmp (e->function_name, l->function_name) == 0) | |
11785 | { | |
11786 | l->enabled = 0; | |
11787 | break; | |
11788 | } | |
11789 | } | |
0d381245 VP |
11790 | } |
11791 | } | |
11792 | } | |
fe3f5fa8 | 11793 | |
8d3788bd VP |
11794 | if (!locations_are_equal (existing_locations, b->loc)) |
11795 | observer_notify_breakpoint_modified (b); | |
11796 | ||
b60e7edf | 11797 | update_global_location_list (1); |
fe3f5fa8 VP |
11798 | } |
11799 | ||
ef23e705 TJB |
11800 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
11801 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
11802 | ||
11803 | static struct symtabs_and_lines | |
11804 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
11805 | { | |
11806 | char *s; | |
58438ac1 | 11807 | int marker_spec; |
02d20e4a | 11808 | struct symtabs_and_lines sals = {0}; |
ef23e705 TJB |
11809 | struct gdb_exception e; |
11810 | ||
11811 | s = addr_string; | |
11812 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); | |
11813 | ||
11814 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11815 | { | |
11816 | if (marker_spec) | |
11817 | { | |
d9b3f62e PA |
11818 | struct tracepoint *tp = (struct tracepoint *) b; |
11819 | ||
ef23e705 | 11820 | sals = decode_static_tracepoint_spec (&s); |
d9b3f62e | 11821 | if (sals.nelts > tp->static_trace_marker_id_idx) |
ef23e705 | 11822 | { |
d9b3f62e | 11823 | sals.sals[0] = sals.sals[tp->static_trace_marker_id_idx]; |
ef23e705 TJB |
11824 | sals.nelts = 1; |
11825 | } | |
11826 | else | |
d9b3f62e | 11827 | error (_("marker %s not found"), tp->static_trace_marker_id); |
ef23e705 TJB |
11828 | } |
11829 | else | |
58438ac1 | 11830 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, NULL); |
ef23e705 TJB |
11831 | } |
11832 | if (e.reason < 0) | |
11833 | { | |
11834 | int not_found_and_ok = 0; | |
11835 | /* For pending breakpoints, it's expected that parsing will | |
11836 | fail until the right shared library is loaded. User has | |
11837 | already told to create pending breakpoints and don't need | |
11838 | extra messages. If breakpoint is in bp_shlib_disabled | |
11839 | state, then user already saw the message about that | |
11840 | breakpoint being disabled, and don't want to see more | |
11841 | errors. */ | |
58438ac1 | 11842 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
11843 | && (b->condition_not_parsed |
11844 | || (b->loc && b->loc->shlib_disabled) | |
11845 | || b->enable_state == bp_disabled)) | |
11846 | not_found_and_ok = 1; | |
11847 | ||
11848 | if (!not_found_and_ok) | |
11849 | { | |
11850 | /* We surely don't want to warn about the same breakpoint | |
11851 | 10 times. One solution, implemented here, is disable | |
11852 | the breakpoint on error. Another solution would be to | |
11853 | have separate 'warning emitted' flag. Since this | |
11854 | happens only when a binary has changed, I don't know | |
11855 | which approach is better. */ | |
11856 | b->enable_state = bp_disabled; | |
11857 | throw_exception (e); | |
11858 | } | |
11859 | } | |
11860 | ||
58438ac1 | 11861 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 TJB |
11862 | { |
11863 | gdb_assert (sals.nelts == 1); | |
11864 | ||
11865 | resolve_sal_pc (&sals.sals[0]); | |
11866 | if (b->condition_not_parsed && s && s[0]) | |
11867 | { | |
11868 | char *cond_string = 0; | |
11869 | int thread = -1; | |
11870 | int task = 0; | |
11871 | ||
11872 | find_condition_and_thread (s, sals.sals[0].pc, | |
11873 | &cond_string, &thread, &task); | |
11874 | if (cond_string) | |
11875 | b->cond_string = cond_string; | |
11876 | b->thread = thread; | |
11877 | b->task = task; | |
11878 | b->condition_not_parsed = 0; | |
11879 | } | |
11880 | ||
11881 | if (b->type == bp_static_tracepoint && !marker_spec) | |
11882 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
ef23e705 | 11883 | |
58438ac1 TT |
11884 | *found = 1; |
11885 | } | |
11886 | else | |
11887 | *found = 0; | |
ef23e705 TJB |
11888 | |
11889 | return sals; | |
11890 | } | |
11891 | ||
348d480f PA |
11892 | /* The default re_set method, for typical hardware or software |
11893 | breakpoints. Reevaluate the breakpoint and recreate its | |
11894 | locations. */ | |
11895 | ||
11896 | static void | |
28010a5d | 11897 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
11898 | { |
11899 | int found; | |
f1310107 | 11900 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 11901 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 11902 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
11903 | |
11904 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
11905 | if (found) | |
11906 | { | |
11907 | make_cleanup (xfree, sals.sals); | |
11908 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
11909 | } | |
11910 | ||
f1310107 TJB |
11911 | if (b->addr_string_range_end) |
11912 | { | |
11913 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
11914 | if (found) | |
11915 | { | |
11916 | make_cleanup (xfree, sals_end.sals); | |
11917 | expanded_end = expand_line_sal_maybe (sals_end.sals[0]); | |
11918 | } | |
11919 | } | |
11920 | ||
11921 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
11922 | } |
11923 | ||
11924 | /* Prepare the global context for a re-set of breakpoint B. */ | |
11925 | ||
11926 | static struct cleanup * | |
11927 | prepare_re_set_context (struct breakpoint *b) | |
11928 | { | |
11929 | struct cleanup *cleanups; | |
11930 | ||
11931 | input_radix = b->input_radix; | |
11932 | cleanups = save_current_space_and_thread (); | |
11933 | switch_to_program_space_and_thread (b->pspace); | |
11934 | set_language (b->language); | |
11935 | ||
11936 | return cleanups; | |
ef23e705 TJB |
11937 | } |
11938 | ||
c906108c SS |
11939 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
11940 | The value we return ends up being the return value from catch_errors. | |
11941 | Unused in this case. */ | |
11942 | ||
11943 | static int | |
4efb68b1 | 11944 | breakpoint_re_set_one (void *bint) |
c906108c | 11945 | { |
4a64f543 | 11946 | /* Get past catch_errs. */ |
53a5351d | 11947 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 11948 | struct cleanup *cleanups; |
c906108c | 11949 | |
348d480f PA |
11950 | cleanups = prepare_re_set_context (b); |
11951 | b->ops->re_set (b); | |
11952 | do_cleanups (cleanups); | |
c906108c SS |
11953 | return 0; |
11954 | } | |
11955 | ||
69de3c6a | 11956 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 11957 | void |
69de3c6a | 11958 | breakpoint_re_set (void) |
c906108c | 11959 | { |
35df4500 | 11960 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11961 | enum language save_language; |
11962 | int save_input_radix; | |
6c95b8df | 11963 | struct cleanup *old_chain; |
c5aa993b | 11964 | |
c906108c SS |
11965 | save_language = current_language->la_language; |
11966 | save_input_radix = input_radix; | |
6c95b8df PA |
11967 | old_chain = save_current_program_space (); |
11968 | ||
35df4500 | 11969 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11970 | { |
4a64f543 | 11971 | /* Format possible error msg. */ |
fe3f5fa8 | 11972 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
11973 | b->number); |
11974 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 11975 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 11976 | do_cleanups (cleanups); |
c5aa993b | 11977 | } |
c906108c SS |
11978 | set_language (save_language); |
11979 | input_radix = save_input_radix; | |
e62c965a | 11980 | |
0756c555 | 11981 | jit_breakpoint_re_set (); |
4efc6507 | 11982 | |
6c95b8df PA |
11983 | do_cleanups (old_chain); |
11984 | ||
af02033e PP |
11985 | create_overlay_event_breakpoint (); |
11986 | create_longjmp_master_breakpoint (); | |
11987 | create_std_terminate_master_breakpoint (); | |
186c406b | 11988 | create_exception_master_breakpoint (); |
c906108c SS |
11989 | } |
11990 | \f | |
c906108c SS |
11991 | /* Reset the thread number of this breakpoint: |
11992 | ||
11993 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 11994 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 11995 | void |
fba45db2 | 11996 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
11997 | { |
11998 | if (b->thread != -1) | |
11999 | { | |
39f77062 KB |
12000 | if (in_thread_list (inferior_ptid)) |
12001 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
12002 | |
12003 | /* We're being called after following a fork. The new fork is | |
12004 | selected as current, and unless this was a vfork will have a | |
12005 | different program space from the original thread. Reset that | |
12006 | as well. */ | |
12007 | b->loc->pspace = current_program_space; | |
c906108c SS |
12008 | } |
12009 | } | |
12010 | ||
03ac34d5 MS |
12011 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
12012 | If from_tty is nonzero, it prints a message to that effect, | |
12013 | which ends with a period (no newline). */ | |
12014 | ||
c906108c | 12015 | void |
fba45db2 | 12016 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 12017 | { |
52f0bd74 | 12018 | struct breakpoint *b; |
c906108c SS |
12019 | |
12020 | if (count < 0) | |
12021 | count = 0; | |
12022 | ||
12023 | ALL_BREAKPOINTS (b) | |
12024 | if (b->number == bptnum) | |
c5aa993b | 12025 | { |
d77f58be SS |
12026 | if (is_tracepoint (b)) |
12027 | { | |
12028 | if (from_tty && count != 0) | |
12029 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
12030 | bptnum); | |
12031 | return; | |
12032 | } | |
12033 | ||
c5aa993b | 12034 | b->ignore_count = count; |
221ea385 KS |
12035 | if (from_tty) |
12036 | { | |
12037 | if (count == 0) | |
3e43a32a MS |
12038 | printf_filtered (_("Will stop next time " |
12039 | "breakpoint %d is reached."), | |
221ea385 KS |
12040 | bptnum); |
12041 | else if (count == 1) | |
a3f17187 | 12042 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
12043 | bptnum); |
12044 | else | |
3e43a32a MS |
12045 | printf_filtered (_("Will ignore next %d " |
12046 | "crossings of breakpoint %d."), | |
221ea385 KS |
12047 | count, bptnum); |
12048 | } | |
c5aa993b | 12049 | breakpoints_changed (); |
8d3788bd | 12050 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
12051 | return; |
12052 | } | |
c906108c | 12053 | |
8a3fe4f8 | 12054 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
12055 | } |
12056 | ||
c906108c SS |
12057 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
12058 | ||
12059 | static void | |
fba45db2 | 12060 | ignore_command (char *args, int from_tty) |
c906108c SS |
12061 | { |
12062 | char *p = args; | |
52f0bd74 | 12063 | int num; |
c906108c SS |
12064 | |
12065 | if (p == 0) | |
e2e0b3e5 | 12066 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 12067 | |
c906108c | 12068 | num = get_number (&p); |
5c44784c | 12069 | if (num == 0) |
8a3fe4f8 | 12070 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 12071 | if (*p == 0) |
8a3fe4f8 | 12072 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
12073 | |
12074 | set_ignore_count (num, | |
12075 | longest_to_int (value_as_long (parse_and_eval (p))), | |
12076 | from_tty); | |
221ea385 KS |
12077 | if (from_tty) |
12078 | printf_filtered ("\n"); | |
c906108c SS |
12079 | } |
12080 | \f | |
12081 | /* Call FUNCTION on each of the breakpoints | |
12082 | whose numbers are given in ARGS. */ | |
12083 | ||
12084 | static void | |
95a42b64 TT |
12085 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
12086 | void *), | |
12087 | void *data) | |
c906108c | 12088 | { |
52f0bd74 AC |
12089 | int num; |
12090 | struct breakpoint *b, *tmp; | |
11cf8741 | 12091 | int match; |
197f0a60 | 12092 | struct get_number_or_range_state state; |
c906108c | 12093 | |
197f0a60 | 12094 | if (args == 0) |
e2e0b3e5 | 12095 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 12096 | |
197f0a60 TT |
12097 | init_number_or_range (&state, args); |
12098 | ||
12099 | while (!state.finished) | |
c906108c | 12100 | { |
197f0a60 TT |
12101 | char *p = state.string; |
12102 | ||
11cf8741 | 12103 | match = 0; |
c5aa993b | 12104 | |
197f0a60 | 12105 | num = get_number_or_range (&state); |
5c44784c | 12106 | if (num == 0) |
c5aa993b | 12107 | { |
8a3fe4f8 | 12108 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
12109 | } |
12110 | else | |
12111 | { | |
12112 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
12113 | if (b->number == num) | |
12114 | { | |
11cf8741 | 12115 | match = 1; |
cdac0397 | 12116 | function (b, data); |
11cf8741 | 12117 | break; |
5c44784c | 12118 | } |
11cf8741 | 12119 | if (match == 0) |
a3f17187 | 12120 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 12121 | } |
c906108c SS |
12122 | } |
12123 | } | |
12124 | ||
0d381245 VP |
12125 | static struct bp_location * |
12126 | find_location_by_number (char *number) | |
12127 | { | |
12128 | char *dot = strchr (number, '.'); | |
12129 | char *p1; | |
12130 | int bp_num; | |
12131 | int loc_num; | |
12132 | struct breakpoint *b; | |
12133 | struct bp_location *loc; | |
12134 | ||
12135 | *dot = '\0'; | |
12136 | ||
12137 | p1 = number; | |
197f0a60 | 12138 | bp_num = get_number (&p1); |
0d381245 VP |
12139 | if (bp_num == 0) |
12140 | error (_("Bad breakpoint number '%s'"), number); | |
12141 | ||
12142 | ALL_BREAKPOINTS (b) | |
12143 | if (b->number == bp_num) | |
12144 | { | |
12145 | break; | |
12146 | } | |
12147 | ||
12148 | if (!b || b->number != bp_num) | |
12149 | error (_("Bad breakpoint number '%s'"), number); | |
12150 | ||
12151 | p1 = dot+1; | |
197f0a60 | 12152 | loc_num = get_number (&p1); |
0d381245 VP |
12153 | if (loc_num == 0) |
12154 | error (_("Bad breakpoint location number '%s'"), number); | |
12155 | ||
12156 | --loc_num; | |
12157 | loc = b->loc; | |
12158 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
12159 | ; | |
12160 | if (!loc) | |
12161 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
12162 | ||
12163 | return loc; | |
12164 | } | |
12165 | ||
12166 | ||
1900040c MS |
12167 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
12168 | If from_tty is nonzero, it prints a message to that effect, | |
12169 | which ends with a period (no newline). */ | |
12170 | ||
c906108c | 12171 | void |
fba45db2 | 12172 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
12173 | { |
12174 | /* Never disable a watchpoint scope breakpoint; we want to | |
12175 | hit them when we leave scope so we can delete both the | |
12176 | watchpoint and its scope breakpoint at that time. */ | |
12177 | if (bpt->type == bp_watchpoint_scope) | |
12178 | return; | |
12179 | ||
c2c6d25f | 12180 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 12181 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
12182 | return; |
12183 | ||
b5de0fa7 | 12184 | bpt->enable_state = bp_disabled; |
c906108c | 12185 | |
d248b706 KY |
12186 | if (target_supports_enable_disable_tracepoint () |
12187 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12188 | { | |
12189 | struct bp_location *location; | |
12190 | ||
12191 | for (location = bpt->loc; location; location = location->next) | |
12192 | target_disable_tracepoint (location); | |
12193 | } | |
12194 | ||
b60e7edf | 12195 | update_global_location_list (0); |
c906108c | 12196 | |
8d3788bd | 12197 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12198 | } |
12199 | ||
51be5b68 PA |
12200 | /* A callback for iterate_over_related_breakpoints. */ |
12201 | ||
12202 | static void | |
12203 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12204 | { | |
12205 | disable_breakpoint (b); | |
12206 | } | |
12207 | ||
95a42b64 TT |
12208 | /* A callback for map_breakpoint_numbers that calls |
12209 | disable_breakpoint. */ | |
12210 | ||
12211 | static void | |
12212 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12213 | { | |
51be5b68 | 12214 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
12215 | } |
12216 | ||
c906108c | 12217 | static void |
fba45db2 | 12218 | disable_command (char *args, int from_tty) |
c906108c | 12219 | { |
c906108c | 12220 | if (args == 0) |
46c6471b PA |
12221 | { |
12222 | struct breakpoint *bpt; | |
12223 | ||
12224 | ALL_BREAKPOINTS (bpt) | |
12225 | if (user_breakpoint_p (bpt)) | |
12226 | disable_breakpoint (bpt); | |
12227 | } | |
0d381245 VP |
12228 | else if (strchr (args, '.')) |
12229 | { | |
12230 | struct bp_location *loc = find_location_by_number (args); | |
12231 | if (loc) | |
d248b706 KY |
12232 | { |
12233 | loc->enabled = 0; | |
12234 | if (target_supports_enable_disable_tracepoint () | |
12235 | && current_trace_status ()->running && loc->owner | |
12236 | && is_tracepoint (loc->owner)) | |
12237 | target_disable_tracepoint (loc); | |
12238 | } | |
b60e7edf | 12239 | update_global_location_list (0); |
0d381245 | 12240 | } |
c906108c | 12241 | else |
95a42b64 | 12242 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
12243 | } |
12244 | ||
12245 | static void | |
51be5b68 | 12246 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 12247 | { |
afe38095 | 12248 | int target_resources_ok; |
c906108c SS |
12249 | |
12250 | if (bpt->type == bp_hardware_breakpoint) | |
12251 | { | |
12252 | int i; | |
c5aa993b | 12253 | i = hw_breakpoint_used_count (); |
53a5351d | 12254 | target_resources_ok = |
d92524f1 | 12255 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 12256 | i + 1, 0); |
c906108c | 12257 | if (target_resources_ok == 0) |
8a3fe4f8 | 12258 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 12259 | else if (target_resources_ok < 0) |
8a3fe4f8 | 12260 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
12261 | } |
12262 | ||
cc60f2e3 | 12263 | if (is_watchpoint (bpt)) |
c906108c | 12264 | { |
d07205c2 JK |
12265 | /* Initialize it just to avoid a GCC false warning. */ |
12266 | enum enable_state orig_enable_state = 0; | |
dde02812 ES |
12267 | struct gdb_exception e; |
12268 | ||
12269 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 12270 | { |
3a5c3e22 PA |
12271 | struct watchpoint *w = (struct watchpoint *) bpt; |
12272 | ||
1e718ff1 TJB |
12273 | orig_enable_state = bpt->enable_state; |
12274 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 12275 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 12276 | } |
dde02812 | 12277 | if (e.reason < 0) |
c5aa993b | 12278 | { |
1e718ff1 | 12279 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
12280 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
12281 | bpt->number); | |
12282 | return; | |
c5aa993b | 12283 | } |
c906108c | 12284 | } |
0101ce28 | 12285 | |
b4c291bb KH |
12286 | if (bpt->enable_state != bp_permanent) |
12287 | bpt->enable_state = bp_enabled; | |
d248b706 KY |
12288 | |
12289 | if (target_supports_enable_disable_tracepoint () | |
12290 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12291 | { | |
12292 | struct bp_location *location; | |
12293 | ||
12294 | for (location = bpt->loc; location; location = location->next) | |
12295 | target_enable_tracepoint (location); | |
12296 | } | |
12297 | ||
b4c291bb | 12298 | bpt->disposition = disposition; |
b60e7edf | 12299 | update_global_location_list (1); |
b4c291bb KH |
12300 | breakpoints_changed (); |
12301 | ||
8d3788bd | 12302 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12303 | } |
12304 | ||
fe3f5fa8 | 12305 | |
c906108c | 12306 | void |
fba45db2 | 12307 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 12308 | { |
51be5b68 PA |
12309 | enable_breakpoint_disp (bpt, bpt->disposition); |
12310 | } | |
12311 | ||
12312 | static void | |
12313 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
12314 | { | |
12315 | enable_breakpoint (bpt); | |
c906108c SS |
12316 | } |
12317 | ||
95a42b64 TT |
12318 | /* A callback for map_breakpoint_numbers that calls |
12319 | enable_breakpoint. */ | |
12320 | ||
12321 | static void | |
12322 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
12323 | { | |
51be5b68 | 12324 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
12325 | } |
12326 | ||
c906108c SS |
12327 | /* The enable command enables the specified breakpoints (or all defined |
12328 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 12329 | in stopping the inferior. */ |
c906108c | 12330 | |
c906108c | 12331 | static void |
fba45db2 | 12332 | enable_command (char *args, int from_tty) |
c906108c | 12333 | { |
c906108c | 12334 | if (args == 0) |
46c6471b PA |
12335 | { |
12336 | struct breakpoint *bpt; | |
12337 | ||
12338 | ALL_BREAKPOINTS (bpt) | |
12339 | if (user_breakpoint_p (bpt)) | |
12340 | enable_breakpoint (bpt); | |
12341 | } | |
0d381245 VP |
12342 | else if (strchr (args, '.')) |
12343 | { | |
12344 | struct bp_location *loc = find_location_by_number (args); | |
12345 | if (loc) | |
d248b706 KY |
12346 | { |
12347 | loc->enabled = 1; | |
12348 | if (target_supports_enable_disable_tracepoint () | |
12349 | && current_trace_status ()->running && loc->owner | |
12350 | && is_tracepoint (loc->owner)) | |
12351 | target_enable_tracepoint (loc); | |
12352 | } | |
b60e7edf | 12353 | update_global_location_list (1); |
0d381245 | 12354 | } |
c906108c | 12355 | else |
95a42b64 | 12356 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
12357 | } |
12358 | ||
12359 | static void | |
51be5b68 PA |
12360 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
12361 | { | |
12362 | enum bpdisp disp = *(enum bpdisp *) arg; | |
12363 | ||
12364 | enable_breakpoint_disp (bpt, disp); | |
12365 | } | |
12366 | ||
12367 | static void | |
12368 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 12369 | { |
51be5b68 PA |
12370 | enum bpdisp disp = disp_disable; |
12371 | ||
12372 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12373 | } |
12374 | ||
c906108c | 12375 | static void |
fba45db2 | 12376 | enable_once_command (char *args, int from_tty) |
c906108c | 12377 | { |
51be5b68 | 12378 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
12379 | } |
12380 | ||
12381 | static void | |
51be5b68 | 12382 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 12383 | { |
51be5b68 PA |
12384 | enum bpdisp disp = disp_del; |
12385 | ||
12386 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12387 | } |
12388 | ||
c906108c | 12389 | static void |
fba45db2 | 12390 | enable_delete_command (char *args, int from_tty) |
c906108c | 12391 | { |
51be5b68 | 12392 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
12393 | } |
12394 | \f | |
fa8d40ab JJ |
12395 | static void |
12396 | set_breakpoint_cmd (char *args, int from_tty) | |
12397 | { | |
12398 | } | |
12399 | ||
12400 | static void | |
12401 | show_breakpoint_cmd (char *args, int from_tty) | |
12402 | { | |
12403 | } | |
12404 | ||
1f3b5d1b PP |
12405 | /* Invalidate last known value of any hardware watchpoint if |
12406 | the memory which that value represents has been written to by | |
12407 | GDB itself. */ | |
12408 | ||
12409 | static void | |
12410 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
12411 | const bfd_byte *data) | |
12412 | { | |
12413 | struct breakpoint *bp; | |
12414 | ||
12415 | ALL_BREAKPOINTS (bp) | |
12416 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 12417 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 12418 | { |
3a5c3e22 | 12419 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 12420 | |
3a5c3e22 PA |
12421 | if (wp->val_valid && wp->val) |
12422 | { | |
12423 | struct bp_location *loc; | |
12424 | ||
12425 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
12426 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
12427 | && loc->address + loc->length > addr | |
12428 | && addr + len > loc->address) | |
12429 | { | |
12430 | value_free (wp->val); | |
12431 | wp->val = NULL; | |
12432 | wp->val_valid = 0; | |
12433 | } | |
12434 | } | |
1f3b5d1b PP |
12435 | } |
12436 | } | |
12437 | ||
c906108c SS |
12438 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
12439 | ||
12440 | struct symtabs_and_lines | |
fba45db2 | 12441 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
12442 | { |
12443 | struct symtabs_and_lines sals; | |
cc59ec59 | 12444 | |
c906108c | 12445 | if (string == 0) |
8a3fe4f8 | 12446 | error (_("Empty line specification.")); |
c906108c SS |
12447 | if (default_breakpoint_valid) |
12448 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
12449 | default_breakpoint_symtab, |
12450 | default_breakpoint_line, | |
58438ac1 | 12451 | NULL); |
c906108c SS |
12452 | else |
12453 | sals = decode_line_1 (&string, funfirstline, | |
58438ac1 | 12454 | (struct symtab *) NULL, 0, NULL); |
c906108c | 12455 | if (*string) |
8a3fe4f8 | 12456 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
12457 | return sals; |
12458 | } | |
8181d85f DJ |
12459 | |
12460 | /* Create and insert a raw software breakpoint at PC. Return an | |
12461 | identifier, which should be used to remove the breakpoint later. | |
12462 | In general, places which call this should be using something on the | |
12463 | breakpoint chain instead; this function should be eliminated | |
12464 | someday. */ | |
12465 | ||
12466 | void * | |
6c95b8df PA |
12467 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
12468 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
12469 | { |
12470 | struct bp_target_info *bp_tgt; | |
12471 | ||
6c95b8df | 12472 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 12473 | |
6c95b8df | 12474 | bp_tgt->placed_address_space = aspace; |
8181d85f | 12475 | bp_tgt->placed_address = pc; |
6c95b8df | 12476 | |
a6d9a66e | 12477 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
12478 | { |
12479 | /* Could not insert the breakpoint. */ | |
12480 | xfree (bp_tgt); | |
12481 | return NULL; | |
12482 | } | |
12483 | ||
12484 | return bp_tgt; | |
12485 | } | |
12486 | ||
4a64f543 MS |
12487 | /* Remove a breakpoint BP inserted by |
12488 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
12489 | |
12490 | int | |
a6d9a66e | 12491 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
12492 | { |
12493 | struct bp_target_info *bp_tgt = bp; | |
12494 | int ret; | |
12495 | ||
a6d9a66e | 12496 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
12497 | xfree (bp_tgt); |
12498 | ||
12499 | return ret; | |
12500 | } | |
12501 | ||
4a64f543 MS |
12502 | /* One (or perhaps two) breakpoints used for software single |
12503 | stepping. */ | |
8181d85f DJ |
12504 | |
12505 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 12506 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
12507 | |
12508 | /* Create and insert a breakpoint for software single step. */ | |
12509 | ||
12510 | void | |
6c95b8df | 12511 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
12512 | struct address_space *aspace, |
12513 | CORE_ADDR next_pc) | |
8181d85f DJ |
12514 | { |
12515 | void **bpt_p; | |
12516 | ||
12517 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
12518 | { |
12519 | bpt_p = &single_step_breakpoints[0]; | |
12520 | single_step_gdbarch[0] = gdbarch; | |
12521 | } | |
8181d85f DJ |
12522 | else |
12523 | { | |
12524 | gdb_assert (single_step_breakpoints[1] == NULL); | |
12525 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 12526 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
12527 | } |
12528 | ||
4a64f543 MS |
12529 | /* NOTE drow/2006-04-11: A future improvement to this function would |
12530 | be to only create the breakpoints once, and actually put them on | |
12531 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
12532 | We could adjust the addresses each time they were needed. Doing | |
12533 | this requires corresponding changes elsewhere where single step | |
12534 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 12535 | |
6c95b8df | 12536 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 12537 | if (*bpt_p == NULL) |
5af949e3 UW |
12538 | error (_("Could not insert single-step breakpoint at %s"), |
12539 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
12540 | } |
12541 | ||
f02253f1 HZ |
12542 | /* Check if the breakpoints used for software single stepping |
12543 | were inserted or not. */ | |
12544 | ||
12545 | int | |
12546 | single_step_breakpoints_inserted (void) | |
12547 | { | |
12548 | return (single_step_breakpoints[0] != NULL | |
12549 | || single_step_breakpoints[1] != NULL); | |
12550 | } | |
12551 | ||
8181d85f DJ |
12552 | /* Remove and delete any breakpoints used for software single step. */ |
12553 | ||
12554 | void | |
12555 | remove_single_step_breakpoints (void) | |
12556 | { | |
12557 | gdb_assert (single_step_breakpoints[0] != NULL); | |
12558 | ||
12559 | /* See insert_single_step_breakpoint for more about this deprecated | |
12560 | call. */ | |
a6d9a66e UW |
12561 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
12562 | single_step_breakpoints[0]); | |
12563 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
12564 | single_step_breakpoints[0] = NULL; |
12565 | ||
12566 | if (single_step_breakpoints[1] != NULL) | |
12567 | { | |
a6d9a66e UW |
12568 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
12569 | single_step_breakpoints[1]); | |
12570 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
12571 | single_step_breakpoints[1] = NULL; |
12572 | } | |
12573 | } | |
12574 | ||
d03285ec UW |
12575 | /* Delete software single step breakpoints without removing them from |
12576 | the inferior. This is intended to be used if the inferior's address | |
12577 | space where they were inserted is already gone, e.g. after exit or | |
12578 | exec. */ | |
12579 | ||
12580 | void | |
12581 | cancel_single_step_breakpoints (void) | |
12582 | { | |
12583 | int i; | |
12584 | ||
12585 | for (i = 0; i < 2; i++) | |
12586 | if (single_step_breakpoints[i]) | |
12587 | { | |
12588 | xfree (single_step_breakpoints[i]); | |
12589 | single_step_breakpoints[i] = NULL; | |
12590 | single_step_gdbarch[i] = NULL; | |
12591 | } | |
12592 | } | |
12593 | ||
12594 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
12595 | removing them. */ | |
12596 | ||
12597 | static void | |
12598 | detach_single_step_breakpoints (void) | |
12599 | { | |
12600 | int i; | |
12601 | ||
12602 | for (i = 0; i < 2; i++) | |
12603 | if (single_step_breakpoints[i]) | |
12604 | target_remove_breakpoint (single_step_gdbarch[i], | |
12605 | single_step_breakpoints[i]); | |
12606 | } | |
12607 | ||
4a64f543 MS |
12608 | /* Check whether a software single-step breakpoint is inserted at |
12609 | PC. */ | |
1aafd4da UW |
12610 | |
12611 | static int | |
cc59ec59 MS |
12612 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
12613 | CORE_ADDR pc) | |
1aafd4da UW |
12614 | { |
12615 | int i; | |
12616 | ||
12617 | for (i = 0; i < 2; i++) | |
12618 | { | |
12619 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
12620 | if (bp_tgt |
12621 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
12622 | bp_tgt->placed_address, | |
12623 | aspace, pc)) | |
1aafd4da UW |
12624 | return 1; |
12625 | } | |
12626 | ||
12627 | return 0; | |
12628 | } | |
12629 | ||
a96d9b2e SDJ |
12630 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
12631 | non-zero otherwise. */ | |
12632 | static int | |
12633 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
12634 | { | |
12635 | if (syscall_catchpoint_p (bp) | |
12636 | && bp->enable_state != bp_disabled | |
12637 | && bp->enable_state != bp_call_disabled) | |
12638 | return 1; | |
12639 | else | |
12640 | return 0; | |
12641 | } | |
12642 | ||
12643 | int | |
12644 | catch_syscall_enabled (void) | |
12645 | { | |
12646 | struct inferior *inf = current_inferior (); | |
12647 | ||
12648 | return inf->total_syscalls_count != 0; | |
12649 | } | |
12650 | ||
12651 | int | |
12652 | catching_syscall_number (int syscall_number) | |
12653 | { | |
12654 | struct breakpoint *bp; | |
12655 | ||
12656 | ALL_BREAKPOINTS (bp) | |
12657 | if (is_syscall_catchpoint_enabled (bp)) | |
12658 | { | |
be5c67c1 PA |
12659 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
12660 | ||
12661 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
12662 | { |
12663 | int i, iter; | |
12664 | for (i = 0; | |
be5c67c1 | 12665 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
12666 | i++) |
12667 | if (syscall_number == iter) | |
12668 | return 1; | |
12669 | } | |
12670 | else | |
12671 | return 1; | |
12672 | } | |
12673 | ||
12674 | return 0; | |
12675 | } | |
12676 | ||
12677 | /* Complete syscall names. Used by "catch syscall". */ | |
12678 | static char ** | |
12679 | catch_syscall_completer (struct cmd_list_element *cmd, | |
12680 | char *text, char *word) | |
12681 | { | |
12682 | const char **list = get_syscall_names (); | |
c38eea1a MS |
12683 | char **retlist |
12684 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 12685 | |
c38eea1a MS |
12686 | xfree (list); |
12687 | return retlist; | |
a96d9b2e SDJ |
12688 | } |
12689 | ||
1042e4c0 SS |
12690 | /* Tracepoint-specific operations. */ |
12691 | ||
12692 | /* Set tracepoint count to NUM. */ | |
12693 | static void | |
12694 | set_tracepoint_count (int num) | |
12695 | { | |
12696 | tracepoint_count = num; | |
4fa62494 | 12697 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
12698 | } |
12699 | ||
12700 | void | |
12701 | trace_command (char *arg, int from_tty) | |
12702 | { | |
8cdf0e15 VP |
12703 | if (create_breakpoint (get_current_arch (), |
12704 | arg, | |
12705 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12706 | 0 /* tempflag */, |
12707 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12708 | 0 /* Ignore count */, |
12709 | pending_break_support, | |
348d480f | 12710 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12711 | from_tty, |
84f4c1fe PM |
12712 | 1 /* enabled */, |
12713 | 0 /* internal */)) | |
fd9b8c24 | 12714 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
12715 | } |
12716 | ||
7a697b8d SS |
12717 | void |
12718 | ftrace_command (char *arg, int from_tty) | |
12719 | { | |
8cdf0e15 VP |
12720 | if (create_breakpoint (get_current_arch (), |
12721 | arg, | |
12722 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12723 | 0 /* tempflag */, |
12724 | bp_fast_tracepoint /* type_wanted */, | |
12725 | 0 /* Ignore count */, | |
12726 | pending_break_support, | |
348d480f | 12727 | &tracepoint_breakpoint_ops, |
0fb4aa4b | 12728 | from_tty, |
84f4c1fe PM |
12729 | 1 /* enabled */, |
12730 | 0 /* internal */)) | |
0fb4aa4b PA |
12731 | set_tracepoint_count (breakpoint_count); |
12732 | } | |
12733 | ||
12734 | /* strace command implementation. Creates a static tracepoint. */ | |
12735 | ||
12736 | void | |
12737 | strace_command (char *arg, int from_tty) | |
12738 | { | |
12739 | if (create_breakpoint (get_current_arch (), | |
12740 | arg, | |
12741 | NULL, 0, 1 /* parse arg */, | |
12742 | 0 /* tempflag */, | |
12743 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12744 | 0 /* Ignore count */, |
12745 | pending_break_support, | |
348d480f | 12746 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12747 | from_tty, |
84f4c1fe PM |
12748 | 1 /* enabled */, |
12749 | 0 /* internal */)) | |
fd9b8c24 | 12750 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
12751 | } |
12752 | ||
409873ef SS |
12753 | /* Set up a fake reader function that gets command lines from a linked |
12754 | list that was acquired during tracepoint uploading. */ | |
12755 | ||
12756 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 12757 | static int next_cmd; |
409873ef SS |
12758 | |
12759 | static char * | |
12760 | read_uploaded_action (void) | |
12761 | { | |
12762 | char *rslt; | |
12763 | ||
3149d8c1 | 12764 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 12765 | |
3149d8c1 | 12766 | next_cmd++; |
409873ef SS |
12767 | |
12768 | return rslt; | |
12769 | } | |
12770 | ||
00bf0b85 SS |
12771 | /* Given information about a tracepoint as recorded on a target (which |
12772 | can be either a live system or a trace file), attempt to create an | |
12773 | equivalent GDB tracepoint. This is not a reliable process, since | |
12774 | the target does not necessarily have all the information used when | |
12775 | the tracepoint was originally defined. */ | |
12776 | ||
d9b3f62e | 12777 | struct tracepoint * |
00bf0b85 | 12778 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 12779 | { |
409873ef | 12780 | char *addr_str, small_buf[100]; |
d9b3f62e | 12781 | struct tracepoint *tp; |
fd9b8c24 | 12782 | |
409873ef SS |
12783 | if (utp->at_string) |
12784 | addr_str = utp->at_string; | |
12785 | else | |
12786 | { | |
12787 | /* In the absence of a source location, fall back to raw | |
12788 | address. Since there is no way to confirm that the address | |
12789 | means the same thing as when the trace was started, warn the | |
12790 | user. */ | |
3e43a32a MS |
12791 | warning (_("Uploaded tracepoint %d has no " |
12792 | "source location, using raw address"), | |
409873ef SS |
12793 | utp->number); |
12794 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
12795 | addr_str = small_buf; | |
12796 | } | |
12797 | ||
12798 | /* There's not much we can do with a sequence of bytecodes. */ | |
12799 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
12800 | warning (_("Uploaded tracepoint %d condition " |
12801 | "has no source form, ignoring it"), | |
409873ef | 12802 | utp->number); |
d5551862 | 12803 | |
8cdf0e15 | 12804 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
12805 | addr_str, |
12806 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 12807 | 0 /* tempflag */, |
0fb4aa4b | 12808 | utp->type /* type_wanted */, |
8cdf0e15 VP |
12809 | 0 /* Ignore count */, |
12810 | pending_break_support, | |
348d480f | 12811 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12812 | 0 /* from_tty */, |
84f4c1fe PM |
12813 | utp->enabled /* enabled */, |
12814 | 0 /* internal */)) | |
fd9b8c24 PA |
12815 | return NULL; |
12816 | ||
00bf0b85 SS |
12817 | set_tracepoint_count (breakpoint_count); |
12818 | ||
409873ef | 12819 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
12820 | tp = get_tracepoint (tracepoint_count); |
12821 | gdb_assert (tp != NULL); | |
d5551862 | 12822 | |
00bf0b85 SS |
12823 | if (utp->pass > 0) |
12824 | { | |
d9b3f62e | 12825 | sprintf (small_buf, "%d %d", utp->pass, tp->base.number); |
00bf0b85 | 12826 | |
409873ef | 12827 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
12828 | } |
12829 | ||
409873ef SS |
12830 | /* If we have uploaded versions of the original commands, set up a |
12831 | special-purpose "reader" function and call the usual command line | |
12832 | reader, then pass the result to the breakpoint command-setting | |
12833 | function. */ | |
3149d8c1 | 12834 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 12835 | { |
409873ef | 12836 | struct command_line *cmd_list; |
00bf0b85 | 12837 | |
409873ef | 12838 | this_utp = utp; |
3149d8c1 | 12839 | next_cmd = 0; |
d5551862 | 12840 | |
409873ef SS |
12841 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
12842 | ||
d9b3f62e | 12843 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 12844 | } |
3149d8c1 SS |
12845 | else if (!VEC_empty (char_ptr, utp->actions) |
12846 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
12847 | warning (_("Uploaded tracepoint %d actions " |
12848 | "have no source form, ignoring them"), | |
409873ef | 12849 | utp->number); |
00bf0b85 SS |
12850 | |
12851 | return tp; | |
d9b3f62e | 12852 | } |
00bf0b85 | 12853 | |
1042e4c0 SS |
12854 | /* Print information on tracepoint number TPNUM_EXP, or all if |
12855 | omitted. */ | |
12856 | ||
12857 | static void | |
e5a67952 | 12858 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 12859 | { |
79a45e25 | 12860 | struct ui_out *uiout = current_uiout; |
e5a67952 | 12861 | int num_printed; |
1042e4c0 | 12862 | |
e5a67952 | 12863 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
12864 | |
12865 | if (num_printed == 0) | |
1042e4c0 | 12866 | { |
e5a67952 | 12867 | if (args == NULL || *args == '\0') |
d77f58be SS |
12868 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
12869 | else | |
e5a67952 | 12870 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 12871 | } |
ad443146 SS |
12872 | |
12873 | default_collect_info (); | |
1042e4c0 SS |
12874 | } |
12875 | ||
4a64f543 | 12876 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
12877 | Not supported by all targets. */ |
12878 | static void | |
12879 | enable_trace_command (char *args, int from_tty) | |
12880 | { | |
12881 | enable_command (args, from_tty); | |
12882 | } | |
12883 | ||
4a64f543 | 12884 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
12885 | Not supported by all targets. */ |
12886 | static void | |
12887 | disable_trace_command (char *args, int from_tty) | |
12888 | { | |
12889 | disable_command (args, from_tty); | |
12890 | } | |
12891 | ||
4a64f543 | 12892 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
12893 | static void |
12894 | delete_trace_command (char *arg, int from_tty) | |
12895 | { | |
35df4500 | 12896 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
12897 | |
12898 | dont_repeat (); | |
12899 | ||
12900 | if (arg == 0) | |
12901 | { | |
12902 | int breaks_to_delete = 0; | |
12903 | ||
12904 | /* Delete all breakpoints if no argument. | |
12905 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
12906 | have to be deleted with an explicit breakpoint number |
12907 | argument. */ | |
1042e4c0 | 12908 | ALL_TRACEPOINTS (b) |
46c6471b | 12909 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
12910 | { |
12911 | breaks_to_delete = 1; | |
12912 | break; | |
12913 | } | |
1042e4c0 SS |
12914 | |
12915 | /* Ask user only if there are some breakpoints to delete. */ | |
12916 | if (!from_tty | |
12917 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
12918 | { | |
35df4500 | 12919 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 12920 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 12921 | delete_breakpoint (b); |
1042e4c0 SS |
12922 | } |
12923 | } | |
12924 | else | |
51be5b68 | 12925 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
12926 | } |
12927 | ||
197f0a60 TT |
12928 | /* Helper function for trace_pass_command. */ |
12929 | ||
12930 | static void | |
d9b3f62e | 12931 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 12932 | { |
d9b3f62e PA |
12933 | tp->pass_count = count; |
12934 | observer_notify_tracepoint_modified (tp->base.number); | |
197f0a60 TT |
12935 | if (from_tty) |
12936 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 12937 | tp->base.number, count); |
197f0a60 TT |
12938 | } |
12939 | ||
1042e4c0 SS |
12940 | /* Set passcount for tracepoint. |
12941 | ||
12942 | First command argument is passcount, second is tracepoint number. | |
12943 | If tracepoint number omitted, apply to most recently defined. | |
12944 | Also accepts special argument "all". */ | |
12945 | ||
12946 | static void | |
12947 | trace_pass_command (char *args, int from_tty) | |
12948 | { | |
d9b3f62e | 12949 | struct tracepoint *t1; |
1042e4c0 | 12950 | unsigned int count; |
1042e4c0 SS |
12951 | |
12952 | if (args == 0 || *args == 0) | |
3e43a32a MS |
12953 | error (_("passcount command requires an " |
12954 | "argument (count + optional TP num)")); | |
1042e4c0 | 12955 | |
4a64f543 | 12956 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
12957 | |
12958 | while (*args && isspace ((int) *args)) | |
12959 | args++; | |
12960 | ||
12961 | if (*args && strncasecmp (args, "all", 3) == 0) | |
12962 | { | |
d9b3f62e PA |
12963 | struct breakpoint *b; |
12964 | ||
1042e4c0 | 12965 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
12966 | if (*args) |
12967 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 12968 | |
d9b3f62e | 12969 | ALL_TRACEPOINTS (b) |
197f0a60 | 12970 | { |
d9b3f62e | 12971 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
12972 | trace_pass_set_count (t1, count, from_tty); |
12973 | } | |
12974 | } | |
12975 | else if (*args == '\0') | |
1042e4c0 | 12976 | { |
197f0a60 | 12977 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 12978 | if (t1) |
197f0a60 TT |
12979 | trace_pass_set_count (t1, count, from_tty); |
12980 | } | |
12981 | else | |
12982 | { | |
12983 | struct get_number_or_range_state state; | |
12984 | ||
12985 | init_number_or_range (&state, args); | |
12986 | while (!state.finished) | |
1042e4c0 | 12987 | { |
197f0a60 TT |
12988 | t1 = get_tracepoint_by_number (&args, &state, 1); |
12989 | if (t1) | |
12990 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
12991 | } |
12992 | } | |
1042e4c0 SS |
12993 | } |
12994 | ||
d9b3f62e | 12995 | struct tracepoint * |
1042e4c0 SS |
12996 | get_tracepoint (int num) |
12997 | { | |
12998 | struct breakpoint *t; | |
12999 | ||
13000 | ALL_TRACEPOINTS (t) | |
13001 | if (t->number == num) | |
d9b3f62e | 13002 | return (struct tracepoint *) t; |
1042e4c0 SS |
13003 | |
13004 | return NULL; | |
13005 | } | |
13006 | ||
d5551862 SS |
13007 | /* Find the tracepoint with the given target-side number (which may be |
13008 | different from the tracepoint number after disconnecting and | |
13009 | reconnecting). */ | |
13010 | ||
d9b3f62e | 13011 | struct tracepoint * |
d5551862 SS |
13012 | get_tracepoint_by_number_on_target (int num) |
13013 | { | |
d9b3f62e | 13014 | struct breakpoint *b; |
d5551862 | 13015 | |
d9b3f62e PA |
13016 | ALL_TRACEPOINTS (b) |
13017 | { | |
13018 | struct tracepoint *t = (struct tracepoint *) b; | |
13019 | ||
13020 | if (t->number_on_target == num) | |
13021 | return t; | |
13022 | } | |
d5551862 SS |
13023 | |
13024 | return NULL; | |
13025 | } | |
13026 | ||
1042e4c0 | 13027 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
13028 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
13029 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 13030 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 13031 | struct tracepoint * |
197f0a60 TT |
13032 | get_tracepoint_by_number (char **arg, |
13033 | struct get_number_or_range_state *state, | |
13034 | int optional_p) | |
1042e4c0 SS |
13035 | { |
13036 | extern int tracepoint_count; | |
13037 | struct breakpoint *t; | |
13038 | int tpnum; | |
13039 | char *instring = arg == NULL ? NULL : *arg; | |
13040 | ||
197f0a60 TT |
13041 | if (state) |
13042 | { | |
13043 | gdb_assert (!state->finished); | |
13044 | tpnum = get_number_or_range (state); | |
13045 | } | |
13046 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
13047 | { |
13048 | if (optional_p) | |
13049 | tpnum = tracepoint_count; | |
13050 | else | |
13051 | error_no_arg (_("tracepoint number")); | |
13052 | } | |
13053 | else | |
197f0a60 | 13054 | tpnum = get_number (arg); |
1042e4c0 SS |
13055 | |
13056 | if (tpnum <= 0) | |
13057 | { | |
13058 | if (instring && *instring) | |
13059 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
13060 | instring); | |
13061 | else | |
3e43a32a MS |
13062 | printf_filtered (_("Tracepoint argument missing " |
13063 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
13064 | return NULL; |
13065 | } | |
13066 | ||
13067 | ALL_TRACEPOINTS (t) | |
13068 | if (t->number == tpnum) | |
13069 | { | |
d9b3f62e | 13070 | return (struct tracepoint *) t; |
1042e4c0 SS |
13071 | } |
13072 | ||
1042e4c0 SS |
13073 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
13074 | return NULL; | |
13075 | } | |
13076 | ||
d9b3f62e PA |
13077 | void |
13078 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
13079 | { | |
13080 | if (b->thread != -1) | |
13081 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
13082 | ||
13083 | if (b->task != 0) | |
13084 | fprintf_unfiltered (fp, " task %d", b->task); | |
13085 | ||
13086 | fprintf_unfiltered (fp, "\n"); | |
13087 | } | |
13088 | ||
6149aea9 PA |
13089 | /* Save information on user settable breakpoints (watchpoints, etc) to |
13090 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
13091 | on each breakpoint and only include the ones for which it returns | |
13092 | non-zero. */ | |
13093 | ||
1042e4c0 | 13094 | static void |
6149aea9 PA |
13095 | save_breakpoints (char *filename, int from_tty, |
13096 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
13097 | { |
13098 | struct breakpoint *tp; | |
6149aea9 | 13099 | int any = 0; |
a7bdde9e | 13100 | char *pathname; |
1042e4c0 | 13101 | struct cleanup *cleanup; |
a7bdde9e | 13102 | struct ui_file *fp; |
6149aea9 | 13103 | int extra_trace_bits = 0; |
1042e4c0 | 13104 | |
6149aea9 PA |
13105 | if (filename == 0 || *filename == 0) |
13106 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
13107 | |
13108 | /* See if we have anything to save. */ | |
6149aea9 | 13109 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13110 | { |
6149aea9 | 13111 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13112 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
13113 | continue; |
13114 | ||
13115 | /* If we have a filter, only save the breakpoints it accepts. */ | |
13116 | if (filter && !filter (tp)) | |
13117 | continue; | |
13118 | ||
13119 | any = 1; | |
13120 | ||
13121 | if (is_tracepoint (tp)) | |
13122 | { | |
13123 | extra_trace_bits = 1; | |
13124 | ||
13125 | /* We can stop searching. */ | |
13126 | break; | |
13127 | } | |
1042e4c0 | 13128 | } |
6149aea9 PA |
13129 | |
13130 | if (!any) | |
1042e4c0 | 13131 | { |
6149aea9 | 13132 | warning (_("Nothing to save.")); |
1042e4c0 SS |
13133 | return; |
13134 | } | |
13135 | ||
6149aea9 | 13136 | pathname = tilde_expand (filename); |
1042e4c0 | 13137 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 13138 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 13139 | if (!fp) |
6149aea9 PA |
13140 | error (_("Unable to open file '%s' for saving (%s)"), |
13141 | filename, safe_strerror (errno)); | |
a7bdde9e | 13142 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 13143 | |
6149aea9 PA |
13144 | if (extra_trace_bits) |
13145 | save_trace_state_variables (fp); | |
8bf6485c | 13146 | |
6149aea9 | 13147 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13148 | { |
6149aea9 | 13149 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13150 | if (!user_breakpoint_p (tp)) |
6149aea9 | 13151 | continue; |
8bf6485c | 13152 | |
6149aea9 PA |
13153 | /* If we have a filter, only save the breakpoints it accepts. */ |
13154 | if (filter && !filter (tp)) | |
13155 | continue; | |
13156 | ||
348d480f | 13157 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 13158 | |
6149aea9 PA |
13159 | /* Note, we can't rely on tp->number for anything, as we can't |
13160 | assume the recreated breakpoint numbers will match. Use $bpnum | |
13161 | instead. */ | |
13162 | ||
13163 | if (tp->cond_string) | |
13164 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
13165 | ||
13166 | if (tp->ignore_count) | |
13167 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
13168 | ||
a7bdde9e | 13169 | if (tp->commands) |
1042e4c0 | 13170 | { |
a7bdde9e VP |
13171 | volatile struct gdb_exception ex; |
13172 | ||
6149aea9 | 13173 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 13174 | |
79a45e25 | 13175 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 13176 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 13177 | { |
79a45e25 | 13178 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 13179 | } |
79a45e25 | 13180 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 13181 | |
a7bdde9e VP |
13182 | if (ex.reason < 0) |
13183 | throw_exception (ex); | |
1042e4c0 | 13184 | |
a7bdde9e | 13185 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 13186 | } |
6149aea9 PA |
13187 | |
13188 | if (tp->enable_state == bp_disabled) | |
13189 | fprintf_unfiltered (fp, "disable\n"); | |
13190 | ||
13191 | /* If this is a multi-location breakpoint, check if the locations | |
13192 | should be individually disabled. Watchpoint locations are | |
13193 | special, and not user visible. */ | |
13194 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
13195 | { | |
13196 | struct bp_location *loc; | |
13197 | int n = 1; | |
13198 | ||
13199 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
13200 | if (!loc->enabled) | |
13201 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
13202 | } | |
1042e4c0 | 13203 | } |
8bf6485c | 13204 | |
6149aea9 | 13205 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
13206 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
13207 | ||
1042e4c0 SS |
13208 | do_cleanups (cleanup); |
13209 | if (from_tty) | |
6149aea9 PA |
13210 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
13211 | } | |
13212 | ||
13213 | /* The `save breakpoints' command. */ | |
13214 | ||
13215 | static void | |
13216 | save_breakpoints_command (char *args, int from_tty) | |
13217 | { | |
13218 | save_breakpoints (args, from_tty, NULL); | |
13219 | } | |
13220 | ||
13221 | /* The `save tracepoints' command. */ | |
13222 | ||
13223 | static void | |
13224 | save_tracepoints_command (char *args, int from_tty) | |
13225 | { | |
13226 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
13227 | } |
13228 | ||
13229 | /* Create a vector of all tracepoints. */ | |
13230 | ||
13231 | VEC(breakpoint_p) * | |
eeae04df | 13232 | all_tracepoints (void) |
1042e4c0 SS |
13233 | { |
13234 | VEC(breakpoint_p) *tp_vec = 0; | |
13235 | struct breakpoint *tp; | |
13236 | ||
13237 | ALL_TRACEPOINTS (tp) | |
13238 | { | |
13239 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
13240 | } | |
13241 | ||
13242 | return tp_vec; | |
13243 | } | |
13244 | ||
c906108c | 13245 | \f |
4a64f543 MS |
13246 | /* This help string is used for the break, hbreak, tbreak and thbreak |
13247 | commands. It is defined as a macro to prevent duplication. | |
13248 | COMMAND should be a string constant containing the name of the | |
13249 | command. */ | |
31e2b00f AS |
13250 | #define BREAK_ARGS_HELP(command) \ |
13251 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
13252 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
13253 | If a line number is specified, break at start of code for that line.\n\ | |
13254 | If a function is specified, break at start of code for that function.\n\ | |
13255 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
13256 | With no LOCATION, uses current execution address of the selected\n\ |
13257 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
13258 | \n\ |
13259 | THREADNUM is the number from \"info threads\".\n\ | |
13260 | CONDITION is a boolean expression.\n\ | |
13261 | \n\ | |
d41c0fc8 PA |
13262 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
13263 | conditions are different.\n\ | |
31e2b00f AS |
13264 | \n\ |
13265 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
13266 | ||
44feb3ce TT |
13267 | /* List of subcommands for "catch". */ |
13268 | static struct cmd_list_element *catch_cmdlist; | |
13269 | ||
13270 | /* List of subcommands for "tcatch". */ | |
13271 | static struct cmd_list_element *tcatch_cmdlist; | |
13272 | ||
9ac4176b | 13273 | void |
44feb3ce TT |
13274 | add_catch_command (char *name, char *docstring, |
13275 | void (*sfunc) (char *args, int from_tty, | |
13276 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
13277 | char **(*completer) (struct cmd_list_element *cmd, |
13278 | char *text, char *word), | |
44feb3ce TT |
13279 | void *user_data_catch, |
13280 | void *user_data_tcatch) | |
13281 | { | |
13282 | struct cmd_list_element *command; | |
13283 | ||
13284 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13285 | &catch_cmdlist); | |
13286 | set_cmd_sfunc (command, sfunc); | |
13287 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 13288 | set_cmd_completer (command, completer); |
44feb3ce TT |
13289 | |
13290 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13291 | &tcatch_cmdlist); | |
13292 | set_cmd_sfunc (command, sfunc); | |
13293 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 13294 | set_cmd_completer (command, completer); |
44feb3ce TT |
13295 | } |
13296 | ||
6c95b8df | 13297 | static void |
a79b8f6e | 13298 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 13299 | { |
6c95b8df PA |
13300 | inf->total_syscalls_count = 0; |
13301 | inf->any_syscall_count = 0; | |
13302 | VEC_free (int, inf->syscalls_counts); | |
13303 | } | |
13304 | ||
6149aea9 PA |
13305 | static void |
13306 | save_command (char *arg, int from_tty) | |
13307 | { | |
3e43a32a MS |
13308 | printf_unfiltered (_("\"save\" must be followed by " |
13309 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
13310 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
13311 | } | |
13312 | ||
84f4c1fe PM |
13313 | struct breakpoint * |
13314 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
13315 | void *data) | |
13316 | { | |
35df4500 | 13317 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 13318 | |
35df4500 | 13319 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
13320 | { |
13321 | if ((*callback) (b, data)) | |
13322 | return b; | |
13323 | } | |
13324 | ||
13325 | return NULL; | |
13326 | } | |
13327 | ||
0574c78f GB |
13328 | /* Zero if any of the breakpoint's locations could be a location where |
13329 | functions have been inlined, nonzero otherwise. */ | |
13330 | ||
13331 | static int | |
13332 | is_non_inline_function (struct breakpoint *b) | |
13333 | { | |
13334 | /* The shared library event breakpoint is set on the address of a | |
13335 | non-inline function. */ | |
13336 | if (b->type == bp_shlib_event) | |
13337 | return 1; | |
13338 | ||
13339 | return 0; | |
13340 | } | |
13341 | ||
13342 | /* Nonzero if the specified PC cannot be a location where functions | |
13343 | have been inlined. */ | |
13344 | ||
13345 | int | |
13346 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc) | |
13347 | { | |
13348 | struct breakpoint *b; | |
13349 | struct bp_location *bl; | |
13350 | ||
13351 | ALL_BREAKPOINTS (b) | |
13352 | { | |
13353 | if (!is_non_inline_function (b)) | |
13354 | continue; | |
13355 | ||
13356 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
13357 | { | |
13358 | if (!bl->shlib_disabled | |
13359 | && bpstat_check_location (bl, aspace, pc)) | |
13360 | return 1; | |
13361 | } | |
13362 | } | |
13363 | ||
13364 | return 0; | |
13365 | } | |
13366 | ||
2060206e PA |
13367 | void |
13368 | initialize_breakpoint_ops (void) | |
13369 | { | |
13370 | static int initialized = 0; | |
13371 | ||
13372 | struct breakpoint_ops *ops; | |
13373 | ||
13374 | if (initialized) | |
13375 | return; | |
13376 | initialized = 1; | |
13377 | ||
13378 | /* The breakpoint_ops structure to be inherit by all kinds of | |
13379 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
13380 | internal and momentary breakpoints, etc.). */ | |
13381 | ops = &bkpt_base_breakpoint_ops; | |
13382 | *ops = base_breakpoint_ops; | |
13383 | ops->re_set = bkpt_re_set; | |
13384 | ops->insert_location = bkpt_insert_location; | |
13385 | ops->remove_location = bkpt_remove_location; | |
13386 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
13387 | ||
13388 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
13389 | ops = &bkpt_breakpoint_ops; | |
13390 | *ops = bkpt_base_breakpoint_ops; | |
13391 | ops->re_set = bkpt_re_set; | |
13392 | ops->resources_needed = bkpt_resources_needed; | |
13393 | ops->print_it = bkpt_print_it; | |
13394 | ops->print_mention = bkpt_print_mention; | |
13395 | ops->print_recreate = bkpt_print_recreate; | |
13396 | ||
13397 | /* Ranged breakpoints. */ | |
13398 | ops = &ranged_breakpoint_ops; | |
13399 | *ops = bkpt_breakpoint_ops; | |
13400 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
13401 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
13402 | ops->print_it = print_it_ranged_breakpoint; | |
13403 | ops->print_one = print_one_ranged_breakpoint; | |
13404 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
13405 | ops->print_mention = print_mention_ranged_breakpoint; | |
13406 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
13407 | ||
13408 | /* Internal breakpoints. */ | |
13409 | ops = &internal_breakpoint_ops; | |
13410 | *ops = bkpt_base_breakpoint_ops; | |
13411 | ops->re_set = internal_bkpt_re_set; | |
13412 | ops->check_status = internal_bkpt_check_status; | |
13413 | ops->print_it = internal_bkpt_print_it; | |
13414 | ops->print_mention = internal_bkpt_print_mention; | |
13415 | ||
13416 | /* Momentary breakpoints. */ | |
13417 | ops = &momentary_breakpoint_ops; | |
13418 | *ops = bkpt_base_breakpoint_ops; | |
13419 | ops->re_set = momentary_bkpt_re_set; | |
13420 | ops->check_status = momentary_bkpt_check_status; | |
13421 | ops->print_it = momentary_bkpt_print_it; | |
13422 | ops->print_mention = momentary_bkpt_print_mention; | |
13423 | ||
13424 | /* GNU v3 exception catchpoints. */ | |
13425 | ops = &gnu_v3_exception_catchpoint_ops; | |
13426 | *ops = bkpt_breakpoint_ops; | |
13427 | ops->print_it = print_it_exception_catchpoint; | |
13428 | ops->print_one = print_one_exception_catchpoint; | |
13429 | ops->print_mention = print_mention_exception_catchpoint; | |
13430 | ops->print_recreate = print_recreate_exception_catchpoint; | |
13431 | ||
13432 | /* Watchpoints. */ | |
13433 | ops = &watchpoint_breakpoint_ops; | |
13434 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 13435 | ops->dtor = dtor_watchpoint; |
2060206e PA |
13436 | ops->re_set = re_set_watchpoint; |
13437 | ops->insert_location = insert_watchpoint; | |
13438 | ops->remove_location = remove_watchpoint; | |
13439 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
13440 | ops->check_status = check_status_watchpoint; | |
13441 | ops->resources_needed = resources_needed_watchpoint; | |
13442 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
13443 | ops->print_it = print_it_watchpoint; | |
13444 | ops->print_mention = print_mention_watchpoint; | |
13445 | ops->print_recreate = print_recreate_watchpoint; | |
13446 | ||
13447 | /* Masked watchpoints. */ | |
13448 | ops = &masked_watchpoint_breakpoint_ops; | |
13449 | *ops = watchpoint_breakpoint_ops; | |
13450 | ops->insert_location = insert_masked_watchpoint; | |
13451 | ops->remove_location = remove_masked_watchpoint; | |
13452 | ops->resources_needed = resources_needed_masked_watchpoint; | |
13453 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
13454 | ops->print_it = print_it_masked_watchpoint; | |
13455 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
13456 | ops->print_mention = print_mention_masked_watchpoint; | |
13457 | ops->print_recreate = print_recreate_masked_watchpoint; | |
13458 | ||
13459 | /* Tracepoints. */ | |
13460 | ops = &tracepoint_breakpoint_ops; | |
13461 | *ops = base_breakpoint_ops; | |
13462 | ops->re_set = tracepoint_re_set; | |
13463 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
13464 | ops->print_one_detail = tracepoint_print_one_detail; | |
13465 | ops->print_mention = tracepoint_print_mention; | |
13466 | ops->print_recreate = tracepoint_print_recreate; | |
13467 | ||
13468 | /* Fork catchpoints. */ | |
13469 | ops = &catch_fork_breakpoint_ops; | |
13470 | *ops = base_breakpoint_ops; | |
13471 | ops->insert_location = insert_catch_fork; | |
13472 | ops->remove_location = remove_catch_fork; | |
13473 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
13474 | ops->print_it = print_it_catch_fork; | |
13475 | ops->print_one = print_one_catch_fork; | |
13476 | ops->print_mention = print_mention_catch_fork; | |
13477 | ops->print_recreate = print_recreate_catch_fork; | |
13478 | ||
13479 | /* Vfork catchpoints. */ | |
13480 | ops = &catch_vfork_breakpoint_ops; | |
13481 | *ops = base_breakpoint_ops; | |
13482 | ops->insert_location = insert_catch_vfork; | |
13483 | ops->remove_location = remove_catch_vfork; | |
13484 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
13485 | ops->print_it = print_it_catch_vfork; | |
13486 | ops->print_one = print_one_catch_vfork; | |
13487 | ops->print_mention = print_mention_catch_vfork; | |
13488 | ops->print_recreate = print_recreate_catch_vfork; | |
13489 | ||
13490 | /* Exec catchpoints. */ | |
13491 | ops = &catch_exec_breakpoint_ops; | |
13492 | *ops = base_breakpoint_ops; | |
13493 | ops->dtor = dtor_catch_exec; | |
13494 | ops->insert_location = insert_catch_exec; | |
13495 | ops->remove_location = remove_catch_exec; | |
13496 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
13497 | ops->print_it = print_it_catch_exec; | |
13498 | ops->print_one = print_one_catch_exec; | |
13499 | ops->print_mention = print_mention_catch_exec; | |
13500 | ops->print_recreate = print_recreate_catch_exec; | |
13501 | ||
13502 | /* Syscall catchpoints. */ | |
13503 | ops = &catch_syscall_breakpoint_ops; | |
13504 | *ops = base_breakpoint_ops; | |
13505 | ops->dtor = dtor_catch_syscall; | |
13506 | ops->insert_location = insert_catch_syscall; | |
13507 | ops->remove_location = remove_catch_syscall; | |
13508 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
13509 | ops->print_it = print_it_catch_syscall; | |
13510 | ops->print_one = print_one_catch_syscall; | |
13511 | ops->print_mention = print_mention_catch_syscall; | |
13512 | ops->print_recreate = print_recreate_catch_syscall; | |
13513 | } | |
13514 | ||
c906108c | 13515 | void |
fba45db2 | 13516 | _initialize_breakpoint (void) |
c906108c SS |
13517 | { |
13518 | struct cmd_list_element *c; | |
13519 | ||
2060206e PA |
13520 | initialize_breakpoint_ops (); |
13521 | ||
84acb35a | 13522 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 13523 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 13524 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 13525 | |
17450429 PP |
13526 | breakpoint_objfile_key = register_objfile_data (); |
13527 | ||
c906108c SS |
13528 | breakpoint_chain = 0; |
13529 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
13530 | before a breakpoint is set. */ | |
13531 | breakpoint_count = 0; | |
13532 | ||
1042e4c0 SS |
13533 | tracepoint_count = 0; |
13534 | ||
1bedd215 AC |
13535 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
13536 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
13537 | Usage is `ignore N COUNT'.")); | |
c906108c | 13538 | if (xdb_commands) |
c5aa993b | 13539 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 13540 | |
1bedd215 AC |
13541 | add_com ("commands", class_breakpoint, commands_command, _("\ |
13542 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
13543 | Give breakpoint number as argument after \"commands\".\n\ |
13544 | With no argument, the targeted breakpoint is the last one set.\n\ | |
13545 | The commands themselves follow starting on the next line.\n\ | |
13546 | Type a line containing \"end\" to indicate the end of them.\n\ | |
13547 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 13548 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 13549 | |
1bedd215 AC |
13550 | add_com ("condition", class_breakpoint, condition_command, _("\ |
13551 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 13552 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 13553 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 13554 | |
1bedd215 | 13555 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 13556 | Set a temporary breakpoint.\n\ |
c906108c SS |
13557 | Like \"break\" except the breakpoint is only temporary,\n\ |
13558 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
13559 | by using \"enable delete\" on the breakpoint number.\n\ |
13560 | \n" | |
13561 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 13562 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13563 | |
1bedd215 | 13564 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 13565 | Set a hardware assisted breakpoint.\n\ |
c906108c | 13566 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
13567 | some target hardware may not have this support.\n\ |
13568 | \n" | |
13569 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 13570 | set_cmd_completer (c, location_completer); |
c906108c | 13571 | |
1bedd215 | 13572 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 13573 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 13574 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
13575 | so it will be deleted when hit.\n\ |
13576 | \n" | |
13577 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 13578 | set_cmd_completer (c, location_completer); |
c906108c | 13579 | |
1bedd215 AC |
13580 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
13581 | Enable some breakpoints.\n\ | |
c906108c SS |
13582 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13583 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13584 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13585 | With a subcommand you can enable temporarily."), |
c906108c SS |
13586 | &enablelist, "enable ", 1, &cmdlist); |
13587 | if (xdb_commands) | |
1bedd215 AC |
13588 | add_com ("ab", class_breakpoint, enable_command, _("\ |
13589 | Enable some breakpoints.\n\ | |
c906108c SS |
13590 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13591 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13592 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13593 | With a subcommand you can enable temporarily.")); |
c906108c SS |
13594 | |
13595 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
13596 | ||
84951ab5 | 13597 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 13598 | Enable some breakpoints.\n\ |
c906108c SS |
13599 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13600 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13601 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 13602 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 13603 | |
1a966eab AC |
13604 | add_cmd ("once", no_class, enable_once_command, _("\ |
13605 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13606 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13607 | &enablebreaklist); |
13608 | ||
1a966eab AC |
13609 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13610 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13611 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13612 | &enablebreaklist); |
13613 | ||
1a966eab AC |
13614 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13615 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13616 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13617 | &enablelist); |
13618 | ||
1a966eab AC |
13619 | add_cmd ("once", no_class, enable_once_command, _("\ |
13620 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13621 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13622 | &enablelist); |
13623 | ||
1bedd215 AC |
13624 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
13625 | Disable some breakpoints.\n\ | |
c906108c SS |
13626 | Arguments are breakpoint numbers with spaces in between.\n\ |
13627 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13628 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
13629 | &disablelist, "disable ", 1, &cmdlist); |
13630 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
13631 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
13632 | if (xdb_commands) | |
1bedd215 AC |
13633 | add_com ("sb", class_breakpoint, disable_command, _("\ |
13634 | Disable some breakpoints.\n\ | |
c906108c SS |
13635 | Arguments are breakpoint numbers with spaces in between.\n\ |
13636 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13637 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 13638 | |
1a966eab AC |
13639 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
13640 | Disable some breakpoints.\n\ | |
c906108c SS |
13641 | Arguments are breakpoint numbers with spaces in between.\n\ |
13642 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13643 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 13644 | This command may be abbreviated \"disable\"."), |
c906108c SS |
13645 | &disablelist); |
13646 | ||
1bedd215 AC |
13647 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
13648 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13649 | Arguments are breakpoint numbers with spaces in between.\n\ |
13650 | To delete all breakpoints, give no argument.\n\ | |
13651 | \n\ | |
13652 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 13653 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
13654 | &deletelist, "delete ", 1, &cmdlist); |
13655 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 13656 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 13657 | if (xdb_commands) |
1bedd215 AC |
13658 | add_com ("db", class_breakpoint, delete_command, _("\ |
13659 | Delete some breakpoints.\n\ | |
c906108c | 13660 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 13661 | To delete all breakpoints, give no argument.\n")); |
c906108c | 13662 | |
1a966eab AC |
13663 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
13664 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13665 | Arguments are breakpoint numbers with spaces in between.\n\ |
13666 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 13667 | This command may be abbreviated \"delete\"."), |
c906108c SS |
13668 | &deletelist); |
13669 | ||
1bedd215 AC |
13670 | add_com ("clear", class_breakpoint, clear_command, _("\ |
13671 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
13672 | Argument may be line number, function name, or \"*\" and an address.\n\ |
13673 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
13674 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
13675 | If an address is specified, breakpoints at that address are cleared.\n\ |
13676 | \n\ | |
13677 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
13678 | is executing in.\n\ |
13679 | \n\ | |
1bedd215 | 13680 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 13681 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 13682 | |
1bedd215 | 13683 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
13684 | Set breakpoint at specified line or function.\n" |
13685 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 13686 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13687 | |
c906108c SS |
13688 | add_com_alias ("b", "break", class_run, 1); |
13689 | add_com_alias ("br", "break", class_run, 1); | |
13690 | add_com_alias ("bre", "break", class_run, 1); | |
13691 | add_com_alias ("brea", "break", class_run, 1); | |
13692 | ||
7681d515 PM |
13693 | if (xdb_commands) |
13694 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
13695 | |
13696 | if (dbx_commands) | |
13697 | { | |
1bedd215 AC |
13698 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
13699 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
13700 | &stoplist, "stop ", 1, &cmdlist); |
13701 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 13702 | _("Break in function or address."), &stoplist); |
c5aa993b | 13703 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 13704 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
13705 | add_com ("status", class_info, breakpoints_info, _("\ |
13706 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13707 | The \"Type\" column indicates one of:\n\ |
13708 | \tbreakpoint - normal breakpoint\n\ | |
13709 | \twatchpoint - watchpoint\n\ | |
13710 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13711 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13712 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13713 | address and file/line number respectively.\n\ |
13714 | \n\ | |
13715 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13716 | are set to the address of the last breakpoint listed unless the command\n\ |
13717 | is prefixed with \"server \".\n\n\ | |
c906108c | 13718 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13719 | breakpoint set.")); |
c906108c SS |
13720 | } |
13721 | ||
1bedd215 | 13722 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 13723 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
13724 | The \"Type\" column indicates one of:\n\ |
13725 | \tbreakpoint - normal breakpoint\n\ | |
13726 | \twatchpoint - watchpoint\n\ | |
13727 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13728 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13729 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13730 | address and file/line number respectively.\n\ |
13731 | \n\ | |
13732 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13733 | are set to the address of the last breakpoint listed unless the command\n\ |
13734 | is prefixed with \"server \".\n\n\ | |
c906108c | 13735 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13736 | breakpoint set.")); |
c906108c | 13737 | |
6b04bdb7 MS |
13738 | add_info_alias ("b", "breakpoints", 1); |
13739 | ||
c906108c | 13740 | if (xdb_commands) |
1bedd215 AC |
13741 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
13742 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13743 | The \"Type\" column indicates one of:\n\ |
13744 | \tbreakpoint - normal breakpoint\n\ | |
13745 | \twatchpoint - watchpoint\n\ | |
13746 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13747 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13748 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13749 | address and file/line number respectively.\n\ |
13750 | \n\ | |
13751 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13752 | are set to the address of the last breakpoint listed unless the command\n\ |
13753 | is prefixed with \"server \".\n\n\ | |
c906108c | 13754 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13755 | breakpoint set.")); |
c906108c | 13756 | |
1a966eab AC |
13757 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
13758 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13759 | The \"Type\" column indicates one of:\n\ |
13760 | \tbreakpoint - normal breakpoint\n\ | |
13761 | \twatchpoint - watchpoint\n\ | |
13762 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
13763 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
13764 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
13765 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
13766 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
13767 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
13768 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
13769 | address and file/line number respectively.\n\ |
13770 | \n\ | |
13771 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13772 | are set to the address of the last breakpoint listed unless the command\n\ |
13773 | is prefixed with \"server \".\n\n\ | |
c906108c | 13774 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 13775 | breakpoint set."), |
c906108c SS |
13776 | &maintenanceinfolist); |
13777 | ||
44feb3ce TT |
13778 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
13779 | Set catchpoints to catch events."), | |
13780 | &catch_cmdlist, "catch ", | |
13781 | 0/*allow-unknown*/, &cmdlist); | |
13782 | ||
13783 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
13784 | Set temporary catchpoints to catch events."), | |
13785 | &tcatch_cmdlist, "tcatch ", | |
13786 | 0/*allow-unknown*/, &cmdlist); | |
13787 | ||
13788 | /* Add catch and tcatch sub-commands. */ | |
13789 | add_catch_command ("catch", _("\ | |
13790 | Catch an exception, when caught.\n\ | |
13791 | With an argument, catch only exceptions with the given name."), | |
13792 | catch_catch_command, | |
a96d9b2e | 13793 | NULL, |
44feb3ce TT |
13794 | CATCH_PERMANENT, |
13795 | CATCH_TEMPORARY); | |
13796 | add_catch_command ("throw", _("\ | |
13797 | Catch an exception, when thrown.\n\ | |
13798 | With an argument, catch only exceptions with the given name."), | |
13799 | catch_throw_command, | |
a96d9b2e | 13800 | NULL, |
44feb3ce TT |
13801 | CATCH_PERMANENT, |
13802 | CATCH_TEMPORARY); | |
13803 | add_catch_command ("fork", _("Catch calls to fork."), | |
13804 | catch_fork_command_1, | |
a96d9b2e | 13805 | NULL, |
44feb3ce TT |
13806 | (void *) (uintptr_t) catch_fork_permanent, |
13807 | (void *) (uintptr_t) catch_fork_temporary); | |
13808 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
13809 | catch_fork_command_1, | |
a96d9b2e | 13810 | NULL, |
44feb3ce TT |
13811 | (void *) (uintptr_t) catch_vfork_permanent, |
13812 | (void *) (uintptr_t) catch_vfork_temporary); | |
13813 | add_catch_command ("exec", _("Catch calls to exec."), | |
13814 | catch_exec_command_1, | |
a96d9b2e SDJ |
13815 | NULL, |
13816 | CATCH_PERMANENT, | |
13817 | CATCH_TEMPORARY); | |
13818 | add_catch_command ("syscall", _("\ | |
13819 | Catch system calls by their names and/or numbers.\n\ | |
13820 | Arguments say which system calls to catch. If no arguments\n\ | |
13821 | are given, every system call will be caught.\n\ | |
13822 | Arguments, if given, should be one or more system call names\n\ | |
13823 | (if your system supports that), or system call numbers."), | |
13824 | catch_syscall_command_1, | |
13825 | catch_syscall_completer, | |
44feb3ce TT |
13826 | CATCH_PERMANENT, |
13827 | CATCH_TEMPORARY); | |
c5aa993b | 13828 | |
1bedd215 AC |
13829 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
13830 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13831 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 13832 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13833 | an expression changes.\n\ |
13834 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13835 | the memory to which it refers.")); | |
65d12d83 | 13836 | set_cmd_completer (c, expression_completer); |
c906108c | 13837 | |
1bedd215 AC |
13838 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
13839 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 13840 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 13841 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13842 | an expression is read.\n\ |
13843 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13844 | the memory to which it refers.")); | |
65d12d83 | 13845 | set_cmd_completer (c, expression_completer); |
c906108c | 13846 | |
1bedd215 AC |
13847 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
13848 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13849 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 13850 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13851 | an expression is either read or written.\n\ |
13852 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13853 | the memory to which it refers.")); | |
65d12d83 | 13854 | set_cmd_completer (c, expression_completer); |
c906108c | 13855 | |
d77f58be | 13856 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 13857 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 13858 | |
920d2a44 AC |
13859 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
13860 | respond to changes - contrary to the description. */ | |
85c07804 AC |
13861 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
13862 | &can_use_hw_watchpoints, _("\ | |
13863 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
13864 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
13865 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
13866 | such is available. (However, any hardware watchpoints that were\n\ | |
13867 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
13868 | hardware.)"), |
13869 | NULL, | |
920d2a44 | 13870 | show_can_use_hw_watchpoints, |
85c07804 | 13871 | &setlist, &showlist); |
c906108c SS |
13872 | |
13873 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 13874 | |
1042e4c0 SS |
13875 | /* Tracepoint manipulation commands. */ |
13876 | ||
13877 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
13878 | Set a tracepoint at specified line or function.\n\ | |
13879 | \n" | |
13880 | BREAK_ARGS_HELP ("trace") "\n\ | |
13881 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13882 | set_cmd_completer (c, location_completer); | |
13883 | ||
13884 | add_com_alias ("tp", "trace", class_alias, 0); | |
13885 | add_com_alias ("tr", "trace", class_alias, 1); | |
13886 | add_com_alias ("tra", "trace", class_alias, 1); | |
13887 | add_com_alias ("trac", "trace", class_alias, 1); | |
13888 | ||
7a697b8d SS |
13889 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
13890 | Set a fast tracepoint at specified line or function.\n\ | |
13891 | \n" | |
13892 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
13893 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13894 | set_cmd_completer (c, location_completer); | |
13895 | ||
0fb4aa4b PA |
13896 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
13897 | Set a static tracepoint at specified line, function or marker.\n\ | |
13898 | \n\ | |
13899 | strace [LOCATION] [if CONDITION]\n\ | |
13900 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
13901 | or -m MARKER_ID.\n\ | |
13902 | If a line number is specified, probe the marker at start of code\n\ | |
13903 | for that line. If a function is specified, probe the marker at start\n\ | |
13904 | of code for that function. If an address is specified, probe the marker\n\ | |
13905 | at that exact address. If a marker id is specified, probe the marker\n\ | |
13906 | with that name. With no LOCATION, uses current execution address of\n\ | |
13907 | the selected stack frame.\n\ | |
13908 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
13909 | This collects arbitrary user data passed in the probe point call to the\n\ | |
13910 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
13911 | by printing the $_sdata variable like any other convenience variable.\n\ | |
13912 | \n\ | |
13913 | CONDITION is a boolean expression.\n\ | |
13914 | \n\ | |
d41c0fc8 PA |
13915 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
13916 | conditions are different.\n\ | |
0fb4aa4b PA |
13917 | \n\ |
13918 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
13919 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13920 | set_cmd_completer (c, location_completer); | |
13921 | ||
1042e4c0 | 13922 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 13923 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
13924 | Convenience variable \"$tpnum\" contains the number of the\n\ |
13925 | last tracepoint set.")); | |
13926 | ||
13927 | add_info_alias ("tp", "tracepoints", 1); | |
13928 | ||
13929 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
13930 | Delete specified tracepoints.\n\ | |
13931 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13932 | No argument means delete all tracepoints."), | |
13933 | &deletelist); | |
13934 | ||
13935 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
13936 | Disable specified tracepoints.\n\ | |
13937 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13938 | No argument means disable all tracepoints."), | |
13939 | &disablelist); | |
13940 | deprecate_cmd (c, "disable"); | |
13941 | ||
13942 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
13943 | Enable specified tracepoints.\n\ | |
13944 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13945 | No argument means enable all tracepoints."), | |
13946 | &enablelist); | |
13947 | deprecate_cmd (c, "enable"); | |
13948 | ||
13949 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
13950 | Set the passcount for a tracepoint.\n\ | |
13951 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
13952 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
13953 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
13954 | ||
6149aea9 PA |
13955 | add_prefix_cmd ("save", class_breakpoint, save_command, |
13956 | _("Save breakpoint definitions as a script."), | |
13957 | &save_cmdlist, "save ", | |
13958 | 0/*allow-unknown*/, &cmdlist); | |
13959 | ||
13960 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
13961 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 13962 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
13963 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
13964 | session to restore them."), | |
13965 | &save_cmdlist); | |
13966 | set_cmd_completer (c, filename_completer); | |
13967 | ||
13968 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 13969 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
13970 | Use the 'source' command in another debug session to restore them."), |
13971 | &save_cmdlist); | |
1042e4c0 SS |
13972 | set_cmd_completer (c, filename_completer); |
13973 | ||
6149aea9 PA |
13974 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
13975 | deprecate_cmd (c, "save tracepoints"); | |
13976 | ||
1bedd215 | 13977 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
13978 | Breakpoint specific settings\n\ |
13979 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 13980 | pending breakpoint behavior"), |
fa8d40ab JJ |
13981 | &breakpoint_set_cmdlist, "set breakpoint ", |
13982 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 13983 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
13984 | Breakpoint specific settings\n\ |
13985 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 13986 | pending breakpoint behavior"), |
fa8d40ab JJ |
13987 | &breakpoint_show_cmdlist, "show breakpoint ", |
13988 | 0/*allow-unknown*/, &showlist); | |
13989 | ||
7915a72c AC |
13990 | add_setshow_auto_boolean_cmd ("pending", no_class, |
13991 | &pending_break_support, _("\ | |
13992 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
13993 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
13994 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
13995 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
13996 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 13997 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 13998 | NULL, |
920d2a44 | 13999 | show_pending_break_support, |
6e1d7d6c AC |
14000 | &breakpoint_set_cmdlist, |
14001 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
14002 | |
14003 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
14004 | |
14005 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
14006 | &automatic_hardware_breakpoints, _("\ | |
14007 | Set automatic usage of hardware breakpoints."), _("\ | |
14008 | Show automatic usage of hardware breakpoints."), _("\ | |
14009 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
14010 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
14011 | a warning will be emitted for such breakpoints."), | |
14012 | NULL, | |
14013 | show_automatic_hardware_breakpoints, | |
14014 | &breakpoint_set_cmdlist, | |
14015 | &breakpoint_show_cmdlist); | |
74960c60 | 14016 | |
33e5cbd6 PA |
14017 | add_setshow_enum_cmd ("always-inserted", class_support, |
14018 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
14019 | Set mode for inserting breakpoints."), _("\ |
14020 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
14021 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
14022 | resumed, and removed when execution stops. When this mode is on,\n\ | |
14023 | breakpoints are inserted immediately and removed only when the user\n\ | |
14024 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
14025 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
14026 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
14027 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
14028 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
14029 | NULL, |
14030 | &show_always_inserted_mode, | |
14031 | &breakpoint_set_cmdlist, | |
14032 | &breakpoint_show_cmdlist); | |
f1310107 TJB |
14033 | |
14034 | add_com ("break-range", class_breakpoint, break_range_command, _("\ | |
14035 | Set a breakpoint for an address range.\n\ | |
14036 | break-range START-LOCATION, END-LOCATION\n\ | |
14037 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
14038 | LINENUM, for that line in the current file,\n\ | |
14039 | FILE:LINENUM, for that line in that file,\n\ | |
14040 | +OFFSET, for that number of lines after the current line\n\ | |
14041 | or the start of the range\n\ | |
14042 | FUNCTION, for the first line in that function,\n\ | |
14043 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
14044 | *ADDRESS, for the instruction at that address.\n\ | |
14045 | \n\ | |
14046 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
14047 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
14048 | range (including START-LOCATION and END-LOCATION).")); | |
14049 | ||
765dc015 | 14050 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
14051 | |
14052 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 14053 | } |