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 | |
a14ed312 | 179 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 180 | |
a14ed312 | 181 | static void hbreak_command (char *, int); |
c906108c | 182 | |
a14ed312 | 183 | static void thbreak_command (char *, int); |
c906108c | 184 | |
51be5b68 | 185 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp); |
c906108c | 186 | |
a14ed312 | 187 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 188 | |
a14ed312 | 189 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 190 | |
a14ed312 | 191 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 192 | |
a14ed312 | 193 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 194 | |
d85310f7 MS |
195 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
196 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 197 | |
a14ed312 | 198 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 199 | |
d03285ec UW |
200 | static void detach_single_step_breakpoints (void); |
201 | ||
6c95b8df PA |
202 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
203 | CORE_ADDR pc); | |
1aafd4da | 204 | |
fe3f5fa8 | 205 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
206 | static void incref_bp_location (struct bp_location *loc); |
207 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 208 | |
39d61571 | 209 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 210 | |
b60e7edf | 211 | static void update_global_location_list (int); |
a5606eee | 212 | |
b60e7edf | 213 | static void update_global_location_list_nothrow (int); |
74960c60 | 214 | |
d77f58be | 215 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
216 | |
217 | static void insert_breakpoint_locations (void); | |
a5606eee | 218 | |
a96d9b2e SDJ |
219 | static int syscall_catchpoint_p (struct breakpoint *b); |
220 | ||
1042e4c0 SS |
221 | static void tracepoints_info (char *, int); |
222 | ||
223 | static void delete_trace_command (char *, int); | |
224 | ||
225 | static void enable_trace_command (char *, int); | |
226 | ||
227 | static void disable_trace_command (char *, int); | |
228 | ||
229 | static void trace_pass_command (char *, int); | |
230 | ||
9c06b0b4 TJB |
231 | static int is_masked_watchpoint (const struct breakpoint *b); |
232 | ||
0fb4aa4b PA |
233 | /* Assuming we're creating a static tracepoint, does S look like a |
234 | static tracepoint marker spec ("-m MARKER_ID")? */ | |
235 | #define is_marker_spec(s) \ | |
f5a8e22b | 236 | (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t')) |
0fb4aa4b | 237 | |
2060206e PA |
238 | /* The abstract base class all breakpoint_ops structures inherit |
239 | from. */ | |
240 | static struct breakpoint_ops base_breakpoint_ops; | |
241 | ||
242 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
243 | that are implemented on top of software or hardware breakpoints | |
244 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
245 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
246 | ||
247 | /* Internal breakpoints class type. */ | |
06edf0c0 | 248 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
249 | |
250 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
251 | static struct breakpoint_ops momentary_breakpoint_ops; |
252 | ||
2060206e PA |
253 | /* The breakpoint_ops structure to be used in regular user created |
254 | breakpoints. */ | |
255 | struct breakpoint_ops bkpt_breakpoint_ops; | |
256 | ||
5cea2a26 PA |
257 | /* A reference-counted struct command_line. This lets multiple |
258 | breakpoints share a single command list. */ | |
259 | struct counted_command_line | |
260 | { | |
261 | /* The reference count. */ | |
262 | int refc; | |
263 | ||
264 | /* The command list. */ | |
265 | struct command_line *commands; | |
266 | }; | |
267 | ||
268 | struct command_line * | |
269 | breakpoint_commands (struct breakpoint *b) | |
270 | { | |
271 | return b->commands ? b->commands->commands : NULL; | |
272 | } | |
3daf8fe5 | 273 | |
f3b1572e PA |
274 | /* Flag indicating that a command has proceeded the inferior past the |
275 | current breakpoint. */ | |
276 | ||
277 | static int breakpoint_proceeded; | |
278 | ||
956a9fb9 | 279 | const char * |
2cec12e5 AR |
280 | bpdisp_text (enum bpdisp disp) |
281 | { | |
4a64f543 MS |
282 | /* NOTE: the following values are a part of MI protocol and |
283 | represent values of 'disp' field returned when inferior stops at | |
284 | a breakpoint. */ | |
bc043ef3 | 285 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 286 | |
2cec12e5 AR |
287 | return bpdisps[(int) disp]; |
288 | } | |
c906108c | 289 | |
4a64f543 | 290 | /* Prototypes for exported functions. */ |
c906108c | 291 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 292 | if such is available. */ |
c906108c SS |
293 | static int can_use_hw_watchpoints; |
294 | ||
920d2a44 AC |
295 | static void |
296 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
297 | struct cmd_list_element *c, | |
298 | const char *value) | |
299 | { | |
3e43a32a MS |
300 | fprintf_filtered (file, |
301 | _("Debugger's willingness to use " | |
302 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
303 | value); |
304 | } | |
305 | ||
fa8d40ab JJ |
306 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
307 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 308 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
309 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
310 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
311 | static void |
312 | show_pending_break_support (struct ui_file *file, int from_tty, | |
313 | struct cmd_list_element *c, | |
314 | const char *value) | |
315 | { | |
3e43a32a MS |
316 | fprintf_filtered (file, |
317 | _("Debugger's behavior regarding " | |
318 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
319 | value); |
320 | } | |
fa8d40ab | 321 | |
765dc015 | 322 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 323 | set with "break" but falling in read-only memory. |
765dc015 VP |
324 | If 0, gdb will warn about such breakpoints, but won't automatically |
325 | use hardware breakpoints. */ | |
326 | static int automatic_hardware_breakpoints; | |
327 | static void | |
328 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
329 | struct cmd_list_element *c, | |
330 | const char *value) | |
331 | { | |
3e43a32a MS |
332 | fprintf_filtered (file, |
333 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
334 | value); |
335 | } | |
336 | ||
33e5cbd6 PA |
337 | /* If on, gdb will keep breakpoints inserted even as inferior is |
338 | stopped, and immediately insert any new breakpoints. If off, gdb | |
339 | will insert breakpoints into inferior only when resuming it, and | |
340 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
341 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
342 | ||
343 | static const char always_inserted_auto[] = "auto"; | |
344 | static const char always_inserted_on[] = "on"; | |
345 | static const char always_inserted_off[] = "off"; | |
346 | static const char *always_inserted_enums[] = { | |
347 | always_inserted_auto, | |
348 | always_inserted_off, | |
349 | always_inserted_on, | |
350 | NULL | |
351 | }; | |
352 | static const char *always_inserted_mode = always_inserted_auto; | |
353 | static void | |
74960c60 | 354 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 355 | struct cmd_list_element *c, const char *value) |
74960c60 | 356 | { |
33e5cbd6 | 357 | if (always_inserted_mode == always_inserted_auto) |
3e43a32a MS |
358 | fprintf_filtered (file, |
359 | _("Always inserted breakpoint " | |
360 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
361 | value, |
362 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
363 | else | |
3e43a32a MS |
364 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
365 | value); | |
74960c60 VP |
366 | } |
367 | ||
33e5cbd6 PA |
368 | int |
369 | breakpoints_always_inserted_mode (void) | |
370 | { | |
371 | return (always_inserted_mode == always_inserted_on | |
372 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
373 | } | |
765dc015 | 374 | |
a14ed312 | 375 | void _initialize_breakpoint (void); |
c906108c | 376 | |
c906108c SS |
377 | /* Are we executing breakpoint commands? */ |
378 | static int executing_breakpoint_commands; | |
379 | ||
c02f5703 MS |
380 | /* Are overlay event breakpoints enabled? */ |
381 | static int overlay_events_enabled; | |
382 | ||
e09342b5 TJB |
383 | /* See description in breakpoint.h. */ |
384 | int target_exact_watchpoints = 0; | |
385 | ||
c906108c | 386 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 387 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 388 | current breakpoint. */ |
c906108c | 389 | |
5c44784c | 390 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 391 | |
5c44784c JM |
392 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
393 | for (B = breakpoint_chain; \ | |
394 | B ? (TMP=B->next, 1): 0; \ | |
395 | B = TMP) | |
c906108c | 396 | |
4a64f543 MS |
397 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
398 | not provided so update_global_location_list must not be called | |
399 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 400 | |
876fa593 JK |
401 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
402 | for (BP_TMP = bp_location; \ | |
403 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
404 | BP_TMP++) | |
7cc221ef | 405 | |
1042e4c0 SS |
406 | /* Iterator for tracepoints only. */ |
407 | ||
408 | #define ALL_TRACEPOINTS(B) \ | |
409 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 410 | if (is_tracepoint (B)) |
1042e4c0 | 411 | |
7cc221ef | 412 | /* Chains of all breakpoints defined. */ |
c906108c SS |
413 | |
414 | struct breakpoint *breakpoint_chain; | |
415 | ||
876fa593 JK |
416 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
417 | ||
418 | static struct bp_location **bp_location; | |
419 | ||
420 | /* Number of elements of BP_LOCATION. */ | |
421 | ||
422 | static unsigned bp_location_count; | |
423 | ||
4a64f543 MS |
424 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
425 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
426 | result from bp_location_has_shadow. You can use it for roughly | |
427 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
428 | an address you need to read. */ | |
876fa593 JK |
429 | |
430 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
431 | ||
4a64f543 MS |
432 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
433 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
434 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
435 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
436 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
437 | |
438 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 439 | |
4a64f543 MS |
440 | /* The locations that no longer correspond to any breakpoint, unlinked |
441 | from bp_location array, but for which a hit may still be reported | |
442 | by a target. */ | |
20874c92 VP |
443 | VEC(bp_location_p) *moribund_locations = NULL; |
444 | ||
c906108c SS |
445 | /* Number of last breakpoint made. */ |
446 | ||
95a42b64 TT |
447 | static int breakpoint_count; |
448 | ||
86b17b60 PA |
449 | /* The value of `breakpoint_count' before the last command that |
450 | created breakpoints. If the last (break-like) command created more | |
451 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
452 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
453 | static int prev_breakpoint_count; | |
c906108c | 454 | |
1042e4c0 SS |
455 | /* Number of last tracepoint made. */ |
456 | ||
95a42b64 | 457 | static int tracepoint_count; |
1042e4c0 | 458 | |
6149aea9 PA |
459 | static struct cmd_list_element *breakpoint_set_cmdlist; |
460 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 461 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 462 | |
468d015d JJ |
463 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
464 | static int | |
465 | breakpoint_enabled (struct breakpoint *b) | |
466 | { | |
0d381245 | 467 | return (b->enable_state == bp_enabled); |
468d015d JJ |
468 | } |
469 | ||
c906108c SS |
470 | /* Set breakpoint count to NUM. */ |
471 | ||
95a42b64 | 472 | static void |
fba45db2 | 473 | set_breakpoint_count (int num) |
c906108c | 474 | { |
86b17b60 | 475 | prev_breakpoint_count = breakpoint_count; |
c906108c | 476 | breakpoint_count = num; |
4fa62494 | 477 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
478 | } |
479 | ||
86b17b60 PA |
480 | /* Used by `start_rbreak_breakpoints' below, to record the current |
481 | breakpoint count before "rbreak" creates any breakpoint. */ | |
482 | static int rbreak_start_breakpoint_count; | |
483 | ||
95a42b64 TT |
484 | /* Called at the start an "rbreak" command to record the first |
485 | breakpoint made. */ | |
86b17b60 | 486 | |
95a42b64 TT |
487 | void |
488 | start_rbreak_breakpoints (void) | |
489 | { | |
86b17b60 | 490 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
491 | } |
492 | ||
493 | /* Called at the end of an "rbreak" command to record the last | |
494 | breakpoint made. */ | |
86b17b60 | 495 | |
95a42b64 TT |
496 | void |
497 | end_rbreak_breakpoints (void) | |
498 | { | |
86b17b60 | 499 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
500 | } |
501 | ||
4a64f543 | 502 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
503 | |
504 | void | |
fba45db2 | 505 | clear_breakpoint_hit_counts (void) |
c906108c SS |
506 | { |
507 | struct breakpoint *b; | |
508 | ||
509 | ALL_BREAKPOINTS (b) | |
510 | b->hit_count = 0; | |
511 | } | |
512 | ||
9add0f1b TT |
513 | /* Allocate a new counted_command_line with reference count of 1. |
514 | The new structure owns COMMANDS. */ | |
515 | ||
516 | static struct counted_command_line * | |
517 | alloc_counted_command_line (struct command_line *commands) | |
518 | { | |
519 | struct counted_command_line *result | |
520 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 521 | |
9add0f1b TT |
522 | result->refc = 1; |
523 | result->commands = commands; | |
524 | return result; | |
525 | } | |
526 | ||
527 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
528 | ||
529 | static void | |
530 | incref_counted_command_line (struct counted_command_line *cmd) | |
531 | { | |
532 | if (cmd) | |
533 | ++cmd->refc; | |
534 | } | |
535 | ||
536 | /* Decrement reference count. If the reference count reaches 0, | |
537 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
538 | nothing if *CMDP is NULL. */ | |
539 | ||
540 | static void | |
541 | decref_counted_command_line (struct counted_command_line **cmdp) | |
542 | { | |
543 | if (*cmdp) | |
544 | { | |
545 | if (--(*cmdp)->refc == 0) | |
546 | { | |
547 | free_command_lines (&(*cmdp)->commands); | |
548 | xfree (*cmdp); | |
549 | } | |
550 | *cmdp = NULL; | |
551 | } | |
552 | } | |
553 | ||
554 | /* A cleanup function that calls decref_counted_command_line. */ | |
555 | ||
556 | static void | |
557 | do_cleanup_counted_command_line (void *arg) | |
558 | { | |
559 | decref_counted_command_line (arg); | |
560 | } | |
561 | ||
562 | /* Create a cleanup that calls decref_counted_command_line on the | |
563 | argument. */ | |
564 | ||
565 | static struct cleanup * | |
566 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
567 | { | |
568 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
569 | } | |
570 | ||
c906108c SS |
571 | /* Default address, symtab and line to put a breakpoint at |
572 | for "break" command with no arg. | |
4a64f543 | 573 | If default_breakpoint_valid is zero, the other three are |
c906108c SS |
574 | not valid, and "break" with no arg is an error. |
575 | ||
576 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
577 | ||
578 | int default_breakpoint_valid; | |
579 | CORE_ADDR default_breakpoint_address; | |
580 | struct symtab *default_breakpoint_symtab; | |
581 | int default_breakpoint_line; | |
6c95b8df PA |
582 | struct program_space *default_breakpoint_pspace; |
583 | ||
c906108c | 584 | \f |
48cb2d85 VP |
585 | /* Return the breakpoint with the specified number, or NULL |
586 | if the number does not refer to an existing breakpoint. */ | |
587 | ||
588 | struct breakpoint * | |
589 | get_breakpoint (int num) | |
590 | { | |
591 | struct breakpoint *b; | |
592 | ||
593 | ALL_BREAKPOINTS (b) | |
594 | if (b->number == num) | |
595 | return b; | |
596 | ||
597 | return NULL; | |
598 | } | |
5c44784c | 599 | |
c906108c | 600 | \f |
adc36818 PM |
601 | |
602 | void | |
603 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
604 | int from_tty) | |
605 | { | |
3a5c3e22 PA |
606 | xfree (b->cond_string); |
607 | b->cond_string = NULL; | |
adc36818 | 608 | |
3a5c3e22 | 609 | if (is_watchpoint (b)) |
adc36818 | 610 | { |
3a5c3e22 PA |
611 | struct watchpoint *w = (struct watchpoint *) b; |
612 | ||
613 | xfree (w->cond_exp); | |
614 | w->cond_exp = NULL; | |
615 | } | |
616 | else | |
617 | { | |
618 | struct bp_location *loc; | |
619 | ||
620 | for (loc = b->loc; loc; loc = loc->next) | |
621 | { | |
622 | xfree (loc->cond); | |
623 | loc->cond = NULL; | |
624 | } | |
adc36818 | 625 | } |
adc36818 PM |
626 | |
627 | if (*exp == 0) | |
628 | { | |
629 | if (from_tty) | |
630 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
631 | } | |
632 | else | |
633 | { | |
634 | char *arg = exp; | |
cc59ec59 | 635 | |
adc36818 PM |
636 | /* I don't know if it matters whether this is the string the user |
637 | typed in or the decompiled expression. */ | |
638 | b->cond_string = xstrdup (arg); | |
639 | b->condition_not_parsed = 0; | |
640 | ||
641 | if (is_watchpoint (b)) | |
642 | { | |
3a5c3e22 PA |
643 | struct watchpoint *w = (struct watchpoint *) b; |
644 | ||
adc36818 PM |
645 | innermost_block = NULL; |
646 | arg = exp; | |
3a5c3e22 | 647 | w->cond_exp = parse_exp_1 (&arg, 0, 0); |
adc36818 PM |
648 | if (*arg) |
649 | error (_("Junk at end of expression")); | |
3a5c3e22 | 650 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
651 | } |
652 | else | |
653 | { | |
3a5c3e22 PA |
654 | struct bp_location *loc; |
655 | ||
adc36818 PM |
656 | for (loc = b->loc; loc; loc = loc->next) |
657 | { | |
658 | arg = exp; | |
659 | loc->cond = | |
660 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
661 | if (*arg) | |
662 | error (_("Junk at end of expression")); | |
663 | } | |
664 | } | |
665 | } | |
666 | breakpoints_changed (); | |
8d3788bd | 667 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
668 | } |
669 | ||
c906108c SS |
670 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
671 | ||
672 | static void | |
fba45db2 | 673 | condition_command (char *arg, int from_tty) |
c906108c | 674 | { |
52f0bd74 | 675 | struct breakpoint *b; |
c906108c | 676 | char *p; |
52f0bd74 | 677 | int bnum; |
c906108c SS |
678 | |
679 | if (arg == 0) | |
e2e0b3e5 | 680 | error_no_arg (_("breakpoint number")); |
c906108c SS |
681 | |
682 | p = arg; | |
683 | bnum = get_number (&p); | |
5c44784c | 684 | if (bnum == 0) |
8a3fe4f8 | 685 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
686 | |
687 | ALL_BREAKPOINTS (b) | |
688 | if (b->number == bnum) | |
2f069f6f | 689 | { |
7371cf6d PM |
690 | /* Check if this breakpoint has a Python object assigned to |
691 | it, and if it has a definition of the "stop" | |
692 | method. This method and conditions entered into GDB from | |
693 | the CLI are mutually exclusive. */ | |
694 | if (b->py_bp_object | |
695 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
696 | error (_("Cannot set a condition where a Python 'stop' " | |
697 | "method has been defined in the breakpoint.")); | |
2566ad2d | 698 | set_breakpoint_condition (b, p, from_tty); |
2f069f6f JB |
699 | return; |
700 | } | |
c906108c | 701 | |
8a3fe4f8 | 702 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
703 | } |
704 | ||
a7bdde9e VP |
705 | /* Check that COMMAND do not contain commands that are suitable |
706 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
707 | Throw if any such commands is found. */ |
708 | ||
a7bdde9e VP |
709 | static void |
710 | check_no_tracepoint_commands (struct command_line *commands) | |
711 | { | |
712 | struct command_line *c; | |
cc59ec59 | 713 | |
a7bdde9e VP |
714 | for (c = commands; c; c = c->next) |
715 | { | |
716 | int i; | |
717 | ||
718 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
719 | error (_("The 'while-stepping' command can " |
720 | "only be used for tracepoints")); | |
a7bdde9e VP |
721 | |
722 | for (i = 0; i < c->body_count; ++i) | |
723 | check_no_tracepoint_commands ((c->body_list)[i]); | |
724 | ||
725 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 726 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
727 | command directly. */ |
728 | if (strstr (c->line, "collect ") == c->line) | |
729 | error (_("The 'collect' command can only be used for tracepoints")); | |
730 | ||
51661e93 VP |
731 | if (strstr (c->line, "teval ") == c->line) |
732 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
733 | } |
734 | } | |
735 | ||
d77f58be SS |
736 | /* Encapsulate tests for different types of tracepoints. */ |
737 | ||
d9b3f62e PA |
738 | static int |
739 | is_tracepoint_type (enum bptype type) | |
740 | { | |
741 | return (type == bp_tracepoint | |
742 | || type == bp_fast_tracepoint | |
743 | || type == bp_static_tracepoint); | |
744 | } | |
745 | ||
a7bdde9e | 746 | int |
d77f58be | 747 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 748 | { |
d9b3f62e | 749 | return is_tracepoint_type (b->type); |
a7bdde9e | 750 | } |
d9b3f62e | 751 | |
e5dd4106 | 752 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
753 | breakpoint. This function will throw an exception if a problem is |
754 | found. */ | |
48cb2d85 | 755 | |
95a42b64 TT |
756 | static void |
757 | validate_commands_for_breakpoint (struct breakpoint *b, | |
758 | struct command_line *commands) | |
48cb2d85 | 759 | { |
d77f58be | 760 | if (is_tracepoint (b)) |
a7bdde9e | 761 | { |
4a64f543 MS |
762 | /* We need to verify that each top-level element of commands is |
763 | valid for tracepoints, that there's at most one | |
764 | while-stepping element, and that while-stepping's body has | |
765 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
766 | struct command_line *c; |
767 | struct command_line *while_stepping = 0; | |
768 | for (c = commands; c; c = c->next) | |
769 | { | |
a7bdde9e VP |
770 | if (c->control_type == while_stepping_control) |
771 | { | |
772 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
773 | error (_("The 'while-stepping' command " |
774 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 775 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
776 | error (_("The 'while-stepping' command " |
777 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
778 | |
779 | if (while_stepping) | |
3e43a32a MS |
780 | error (_("The 'while-stepping' command " |
781 | "can be used only once")); | |
a7bdde9e VP |
782 | else |
783 | while_stepping = c; | |
784 | } | |
785 | } | |
786 | if (while_stepping) | |
787 | { | |
788 | struct command_line *c2; | |
789 | ||
790 | gdb_assert (while_stepping->body_count == 1); | |
791 | c2 = while_stepping->body_list[0]; | |
792 | for (; c2; c2 = c2->next) | |
793 | { | |
a7bdde9e VP |
794 | if (c2->control_type == while_stepping_control) |
795 | error (_("The 'while-stepping' command cannot be nested")); | |
796 | } | |
797 | } | |
798 | } | |
799 | else | |
800 | { | |
801 | check_no_tracepoint_commands (commands); | |
802 | } | |
95a42b64 TT |
803 | } |
804 | ||
0fb4aa4b PA |
805 | /* Return a vector of all the static tracepoints set at ADDR. The |
806 | caller is responsible for releasing the vector. */ | |
807 | ||
808 | VEC(breakpoint_p) * | |
809 | static_tracepoints_here (CORE_ADDR addr) | |
810 | { | |
811 | struct breakpoint *b; | |
812 | VEC(breakpoint_p) *found = 0; | |
813 | struct bp_location *loc; | |
814 | ||
815 | ALL_BREAKPOINTS (b) | |
816 | if (b->type == bp_static_tracepoint) | |
817 | { | |
818 | for (loc = b->loc; loc; loc = loc->next) | |
819 | if (loc->address == addr) | |
820 | VEC_safe_push(breakpoint_p, found, b); | |
821 | } | |
822 | ||
823 | return found; | |
824 | } | |
825 | ||
95a42b64 | 826 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 827 | validate that only allowed commands are included. */ |
95a42b64 TT |
828 | |
829 | void | |
4a64f543 MS |
830 | breakpoint_set_commands (struct breakpoint *b, |
831 | struct command_line *commands) | |
95a42b64 TT |
832 | { |
833 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 834 | |
9add0f1b TT |
835 | decref_counted_command_line (&b->commands); |
836 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 | 837 | breakpoints_changed (); |
8d3788bd | 838 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
839 | } |
840 | ||
45a43567 TT |
841 | /* Set the internal `silent' flag on the breakpoint. Note that this |
842 | is not the same as the "silent" that may appear in the breakpoint's | |
843 | commands. */ | |
844 | ||
845 | void | |
846 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
847 | { | |
848 | int old_silent = b->silent; | |
849 | ||
850 | b->silent = silent; | |
851 | if (old_silent != silent) | |
8d3788bd | 852 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
853 | } |
854 | ||
855 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
856 | breakpoint work for any thread. */ | |
857 | ||
858 | void | |
859 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
860 | { | |
861 | int old_thread = b->thread; | |
862 | ||
863 | b->thread = thread; | |
864 | if (old_thread != thread) | |
8d3788bd | 865 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
866 | } |
867 | ||
868 | /* Set the task for this breakpoint. If TASK is 0, make the | |
869 | breakpoint work for any task. */ | |
870 | ||
871 | void | |
872 | breakpoint_set_task (struct breakpoint *b, int task) | |
873 | { | |
874 | int old_task = b->task; | |
875 | ||
876 | b->task = task; | |
877 | if (old_task != task) | |
8d3788bd | 878 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
879 | } |
880 | ||
95a42b64 TT |
881 | void |
882 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
883 | { |
884 | struct breakpoint *b = closure; | |
cc59ec59 | 885 | |
a7bdde9e VP |
886 | validate_actionline (&line, b); |
887 | } | |
888 | ||
95a42b64 TT |
889 | /* A structure used to pass information through |
890 | map_breakpoint_numbers. */ | |
891 | ||
892 | struct commands_info | |
893 | { | |
894 | /* True if the command was typed at a tty. */ | |
895 | int from_tty; | |
86b17b60 PA |
896 | |
897 | /* The breakpoint range spec. */ | |
898 | char *arg; | |
899 | ||
95a42b64 TT |
900 | /* Non-NULL if the body of the commands are being read from this |
901 | already-parsed command. */ | |
902 | struct command_line *control; | |
86b17b60 | 903 | |
95a42b64 TT |
904 | /* The command lines read from the user, or NULL if they have not |
905 | yet been read. */ | |
906 | struct counted_command_line *cmd; | |
907 | }; | |
908 | ||
909 | /* A callback for map_breakpoint_numbers that sets the commands for | |
910 | commands_command. */ | |
911 | ||
c906108c | 912 | static void |
95a42b64 | 913 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 914 | { |
95a42b64 | 915 | struct commands_info *info = data; |
c906108c | 916 | |
95a42b64 TT |
917 | if (info->cmd == NULL) |
918 | { | |
919 | struct command_line *l; | |
5c44784c | 920 | |
95a42b64 TT |
921 | if (info->control != NULL) |
922 | l = copy_command_lines (info->control->body_list[0]); | |
923 | else | |
86b17b60 PA |
924 | { |
925 | struct cleanup *old_chain; | |
926 | char *str; | |
c5aa993b | 927 | |
3e43a32a MS |
928 | str = xstrprintf (_("Type commands for breakpoint(s) " |
929 | "%s, one per line."), | |
86b17b60 PA |
930 | info->arg); |
931 | ||
932 | old_chain = make_cleanup (xfree, str); | |
933 | ||
934 | l = read_command_lines (str, | |
935 | info->from_tty, 1, | |
d77f58be | 936 | (is_tracepoint (b) |
86b17b60 PA |
937 | ? check_tracepoint_command : 0), |
938 | b); | |
939 | ||
940 | do_cleanups (old_chain); | |
941 | } | |
a7bdde9e | 942 | |
95a42b64 TT |
943 | info->cmd = alloc_counted_command_line (l); |
944 | } | |
945 | ||
946 | /* If a breakpoint was on the list more than once, we don't need to | |
947 | do anything. */ | |
948 | if (b->commands != info->cmd) | |
949 | { | |
950 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
951 | incref_counted_command_line (info->cmd); | |
952 | decref_counted_command_line (&b->commands); | |
953 | b->commands = info->cmd; | |
954 | breakpoints_changed (); | |
8d3788bd | 955 | observer_notify_breakpoint_modified (b); |
c5aa993b | 956 | } |
95a42b64 TT |
957 | } |
958 | ||
959 | static void | |
4a64f543 MS |
960 | commands_command_1 (char *arg, int from_tty, |
961 | struct command_line *control) | |
95a42b64 TT |
962 | { |
963 | struct cleanup *cleanups; | |
964 | struct commands_info info; | |
965 | ||
966 | info.from_tty = from_tty; | |
967 | info.control = control; | |
968 | info.cmd = NULL; | |
969 | /* If we read command lines from the user, then `info' will hold an | |
970 | extra reference to the commands that we must clean up. */ | |
971 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
972 | ||
973 | if (arg == NULL || !*arg) | |
974 | { | |
86b17b60 | 975 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
976 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
977 | breakpoint_count); | |
95a42b64 TT |
978 | else if (breakpoint_count > 0) |
979 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
980 | else |
981 | { | |
982 | /* So that we don't try to free the incoming non-NULL | |
983 | argument in the cleanup below. Mapping breakpoint | |
984 | numbers will fail in this case. */ | |
985 | arg = NULL; | |
986 | } | |
95a42b64 | 987 | } |
9766ced4 SS |
988 | else |
989 | /* The command loop has some static state, so we need to preserve | |
990 | our argument. */ | |
991 | arg = xstrdup (arg); | |
86b17b60 PA |
992 | |
993 | if (arg != NULL) | |
994 | make_cleanup (xfree, arg); | |
995 | ||
996 | info.arg = arg; | |
95a42b64 TT |
997 | |
998 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
999 | ||
1000 | if (info.cmd == NULL) | |
1001 | error (_("No breakpoints specified.")); | |
1002 | ||
1003 | do_cleanups (cleanups); | |
1004 | } | |
1005 | ||
1006 | static void | |
1007 | commands_command (char *arg, int from_tty) | |
1008 | { | |
1009 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1010 | } |
40c03ae8 EZ |
1011 | |
1012 | /* Like commands_command, but instead of reading the commands from | |
1013 | input stream, takes them from an already parsed command structure. | |
1014 | ||
1015 | This is used by cli-script.c to DTRT with breakpoint commands | |
1016 | that are part of if and while bodies. */ | |
1017 | enum command_control_type | |
1018 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1019 | { | |
95a42b64 TT |
1020 | commands_command_1 (arg, 0, cmd); |
1021 | return simple_control; | |
40c03ae8 | 1022 | } |
876fa593 JK |
1023 | |
1024 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1025 | ||
1026 | static int | |
1027 | bp_location_has_shadow (struct bp_location *bl) | |
1028 | { | |
1029 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1030 | return 0; | |
1031 | if (!bl->inserted) | |
1032 | return 0; | |
1033 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1034 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1035 | return 0; |
1036 | return 1; | |
1037 | } | |
1038 | ||
8defab1a | 1039 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1040 | by replacing any memory breakpoints with their shadowed contents. |
1041 | ||
1042 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
1043 | bl->address - bp_location_placed_address_before_address_max |
1044 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1045 | The range we were requested to resolve shadows for is: |
1046 | memaddr ... memaddr + len | |
1047 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1048 | memaddr + len <= (bl->address |
1049 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1050 | and: |
35df4500 | 1051 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1052 | |
8defab1a DJ |
1053 | void |
1054 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1055 | { |
4a64f543 MS |
1056 | /* Left boundary, right boundary and median element of our binary |
1057 | search. */ | |
876fa593 JK |
1058 | unsigned bc_l, bc_r, bc; |
1059 | ||
4a64f543 MS |
1060 | /* Find BC_L which is a leftmost element which may affect BUF |
1061 | content. It is safe to report lower value but a failure to | |
1062 | report higher one. */ | |
876fa593 JK |
1063 | |
1064 | bc_l = 0; | |
1065 | bc_r = bp_location_count; | |
1066 | while (bc_l + 1 < bc_r) | |
1067 | { | |
35df4500 | 1068 | struct bp_location *bl; |
876fa593 JK |
1069 | |
1070 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1071 | bl = bp_location[bc]; |
876fa593 | 1072 | |
4a64f543 MS |
1073 | /* Check first BL->ADDRESS will not overflow due to the added |
1074 | constant. Then advance the left boundary only if we are sure | |
1075 | the BC element can in no way affect the BUF content (MEMADDR | |
1076 | to MEMADDR + LEN range). | |
876fa593 | 1077 | |
4a64f543 MS |
1078 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1079 | offset so that we cannot miss a breakpoint with its shadow | |
1080 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1081 | |
35df4500 TJB |
1082 | if ((bl->address + bp_location_shadow_len_after_address_max |
1083 | >= bl->address) | |
1084 | && (bl->address + bp_location_shadow_len_after_address_max | |
1085 | <= memaddr)) | |
876fa593 JK |
1086 | bc_l = bc; |
1087 | else | |
1088 | bc_r = bc; | |
1089 | } | |
1090 | ||
128070bb PA |
1091 | /* Due to the binary search above, we need to make sure we pick the |
1092 | first location that's at BC_L's address. E.g., if there are | |
1093 | multiple locations at the same address, BC_L may end up pointing | |
1094 | at a duplicate location, and miss the "master"/"inserted" | |
1095 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1096 | B: | |
1097 | ||
1098 | L1@A, L2@A, L3@B, ... | |
1099 | ||
1100 | BC_L could end up pointing at location L2, while the "master" | |
1101 | location could be L1. Since the `loc->inserted' flag is only set | |
1102 | on "master" locations, we'd forget to restore the shadow of L1 | |
1103 | and L2. */ | |
1104 | while (bc_l > 0 | |
1105 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1106 | bc_l--; | |
1107 | ||
876fa593 JK |
1108 | /* Now do full processing of the found relevant range of elements. */ |
1109 | ||
1110 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1111 | { |
35df4500 | 1112 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1113 | CORE_ADDR bp_addr = 0; |
1114 | int bp_size = 0; | |
1115 | int bptoffset = 0; | |
1116 | ||
35df4500 TJB |
1117 | /* bp_location array has BL->OWNER always non-NULL. */ |
1118 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1119 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1120 | bl->owner->number); |
ffce0d52 | 1121 | |
e5dd4106 | 1122 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1123 | content. */ |
1124 | ||
35df4500 TJB |
1125 | if (bl->address >= bp_location_placed_address_before_address_max |
1126 | && memaddr + len <= (bl->address | |
1127 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1128 | break; |
1129 | ||
35df4500 | 1130 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1131 | continue; |
35df4500 | 1132 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1133 | current_program_space->aspace, 0)) |
1134 | continue; | |
1135 | ||
c5aa993b JM |
1136 | /* Addresses and length of the part of the breakpoint that |
1137 | we need to copy. */ | |
35df4500 TJB |
1138 | bp_addr = bl->target_info.placed_address; |
1139 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1140 | |
c5aa993b JM |
1141 | if (bp_addr + bp_size <= memaddr) |
1142 | /* The breakpoint is entirely before the chunk of memory we | |
1143 | are reading. */ | |
1144 | continue; | |
8defab1a | 1145 | |
c5aa993b JM |
1146 | if (bp_addr >= memaddr + len) |
1147 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1148 | reading. */ |
c5aa993b | 1149 | continue; |
c5aa993b | 1150 | |
8defab1a DJ |
1151 | /* Offset within shadow_contents. */ |
1152 | if (bp_addr < memaddr) | |
1153 | { | |
1154 | /* Only copy the second part of the breakpoint. */ | |
1155 | bp_size -= memaddr - bp_addr; | |
1156 | bptoffset = memaddr - bp_addr; | |
1157 | bp_addr = memaddr; | |
1158 | } | |
c5aa993b | 1159 | |
8defab1a DJ |
1160 | if (bp_addr + bp_size > memaddr + len) |
1161 | { | |
1162 | /* Only copy the first part of the breakpoint. */ | |
1163 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1164 | } | |
c5aa993b | 1165 | |
8defab1a | 1166 | memcpy (buf + bp_addr - memaddr, |
35df4500 | 1167 | bl->target_info.shadow_contents + bptoffset, bp_size); |
c5aa993b | 1168 | } |
c906108c | 1169 | } |
c906108c | 1170 | \f |
c5aa993b | 1171 | |
60e1c644 PA |
1172 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1173 | ||
a5606eee | 1174 | static int |
d77f58be | 1175 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1176 | { |
1177 | return (bpt->type == bp_hardware_watchpoint | |
1178 | || bpt->type == bp_read_watchpoint | |
1179 | || bpt->type == bp_access_watchpoint); | |
1180 | } | |
7270d8f2 | 1181 | |
60e1c644 PA |
1182 | /* Return true if BPT is of any watchpoint kind, hardware or |
1183 | software. */ | |
1184 | ||
3a5c3e22 | 1185 | int |
d77f58be | 1186 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1187 | { |
1188 | return (is_hardware_watchpoint (bpt) | |
1189 | || bpt->type == bp_watchpoint); | |
1190 | } | |
1191 | ||
3a5c3e22 PA |
1192 | /* Returns true if the current thread and its running state are safe |
1193 | to evaluate or update watchpoint B. Watchpoints on local | |
1194 | expressions need to be evaluated in the context of the thread that | |
1195 | was current when the watchpoint was created, and, that thread needs | |
1196 | to be stopped to be able to select the correct frame context. | |
1197 | Watchpoints on global expressions can be evaluated on any thread, | |
1198 | and in any state. It is presently left to the target allowing | |
1199 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1200 | |
1201 | static int | |
3a5c3e22 | 1202 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 PA |
1203 | { |
1204 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1205 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1206 | && !is_executing (inferior_ptid))); | |
1207 | } | |
1208 | ||
d0fb5eae JK |
1209 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1210 | associated bp_watchpoint_scope breakpoint. */ | |
1211 | ||
1212 | static void | |
3a5c3e22 | 1213 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1214 | { |
3a5c3e22 | 1215 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1216 | |
1217 | if (b->related_breakpoint != b) | |
1218 | { | |
1219 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1220 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1221 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1222 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1223 | b->related_breakpoint = b; | |
1224 | } | |
1225 | b->disposition = disp_del_at_next_stop; | |
1226 | } | |
1227 | ||
567e1b4e JB |
1228 | /* Assuming that B is a watchpoint: |
1229 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1230 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1231 | - Evaluate the condition if there is one, and store the result |
1232 | in b->loc->cond. | |
a5606eee VP |
1233 | - Update the list of values that must be watched in B->loc. |
1234 | ||
4a64f543 MS |
1235 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1236 | nothing. If this is local watchpoint that is out of scope, delete | |
1237 | it. | |
1238 | ||
1239 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1240 | removed + inserted on each stop here. Normal breakpoints must | |
1241 | never be removed because they might be missed by a running thread | |
1242 | when debugging in non-stop mode. On the other hand, hardware | |
1243 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1244 | to each LWP since they are stored in each LWP's hardware debug | |
1245 | registers. Therefore, such LWP must be stopped first in order to | |
1246 | be able to modify its hardware watchpoints. | |
1247 | ||
1248 | Hardware watchpoints must be reset exactly once after being | |
1249 | presented to the user. It cannot be done sooner, because it would | |
1250 | reset the data used to present the watchpoint hit to the user. And | |
1251 | it must not be done later because it could display the same single | |
1252 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1253 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1254 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1255 | not user-visible - its hit is suppressed if the memory content has | |
1256 | not changed. | |
1257 | ||
1258 | The following constraints influence the location where we can reset | |
1259 | hardware watchpoints: | |
1260 | ||
1261 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1262 | called several times when GDB stops. | |
1263 | ||
1264 | [linux] | |
1265 | * Multiple hardware watchpoints can be hit at the same time, | |
1266 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1267 | hit at a time as the reason for stopping, and all the other hits | |
1268 | are presented later, one after the other, each time the user | |
1269 | requests the execution to be resumed. Execution is not resumed | |
1270 | for the threads still having pending hit event stored in | |
1271 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1272 | the inferior on the first stop the thread hit event is kept being | |
1273 | reported from its cached value by linux_nat_stopped_data_address | |
1274 | until the real thread resume happens after the watchpoint gets | |
1275 | presented and thus its LWP_INFO->STATUS gets reset. | |
1276 | ||
1277 | Therefore the hardware watchpoint hit can get safely reset on the | |
1278 | watchpoint removal from inferior. */ | |
a79d3c27 | 1279 | |
b40ce68a | 1280 | static void |
3a5c3e22 | 1281 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1282 | { |
a5606eee | 1283 | int within_current_scope; |
a5606eee | 1284 | struct frame_id saved_frame_id; |
66076460 | 1285 | int frame_saved; |
a5606eee | 1286 | |
f6bc2008 PA |
1287 | /* If this is a local watchpoint, we only want to check if the |
1288 | watchpoint frame is in scope if the current thread is the thread | |
1289 | that was used to create the watchpoint. */ | |
1290 | if (!watchpoint_in_thread_scope (b)) | |
1291 | return; | |
1292 | ||
3a5c3e22 | 1293 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1294 | return; |
1295 | ||
66076460 | 1296 | frame_saved = 0; |
a5606eee VP |
1297 | |
1298 | /* Determine if the watchpoint is within scope. */ | |
1299 | if (b->exp_valid_block == NULL) | |
1300 | within_current_scope = 1; | |
1301 | else | |
1302 | { | |
b5db5dfc UW |
1303 | struct frame_info *fi = get_current_frame (); |
1304 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1305 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1306 | ||
1307 | /* If we're in a function epilogue, unwinding may not work | |
1308 | properly, so do not attempt to recreate locations at this | |
1309 | point. See similar comments in watchpoint_check. */ | |
1310 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1311 | return; | |
66076460 DJ |
1312 | |
1313 | /* Save the current frame's ID so we can restore it after | |
1314 | evaluating the watchpoint expression on its own frame. */ | |
1315 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1316 | took a frame parameter, so that we didn't have to change the | |
1317 | selected frame. */ | |
1318 | frame_saved = 1; | |
1319 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1320 | ||
a5606eee VP |
1321 | fi = frame_find_by_id (b->watchpoint_frame); |
1322 | within_current_scope = (fi != NULL); | |
1323 | if (within_current_scope) | |
1324 | select_frame (fi); | |
1325 | } | |
1326 | ||
b5db5dfc UW |
1327 | /* We don't free locations. They are stored in the bp_location array |
1328 | and update_global_location_list will eventually delete them and | |
1329 | remove breakpoints if needed. */ | |
3a5c3e22 | 1330 | b->base.loc = NULL; |
b5db5dfc | 1331 | |
a5606eee VP |
1332 | if (within_current_scope && reparse) |
1333 | { | |
1334 | char *s; | |
d63d0675 | 1335 | |
a5606eee VP |
1336 | if (b->exp) |
1337 | { | |
1338 | xfree (b->exp); | |
1339 | b->exp = NULL; | |
1340 | } | |
d63d0675 | 1341 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1342 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1343 | /* If the meaning of expression itself changed, the old value is | |
1344 | no longer relevant. We don't want to report a watchpoint hit | |
1345 | to the user when the old value and the new value may actually | |
1346 | be completely different objects. */ | |
1347 | value_free (b->val); | |
fa4727a6 DJ |
1348 | b->val = NULL; |
1349 | b->val_valid = 0; | |
60e1c644 PA |
1350 | |
1351 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1352 | expression is stored in the breakpoint object, not in the | |
1353 | locations (re)created below. */ | |
3a5c3e22 | 1354 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1355 | { |
1356 | if (b->cond_exp != NULL) | |
1357 | { | |
1358 | xfree (b->cond_exp); | |
1359 | b->cond_exp = NULL; | |
1360 | } | |
1361 | ||
3a5c3e22 | 1362 | s = b->base.cond_string; |
60e1c644 PA |
1363 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); |
1364 | } | |
a5606eee | 1365 | } |
a5606eee VP |
1366 | |
1367 | /* If we failed to parse the expression, for example because | |
1368 | it refers to a global variable in a not-yet-loaded shared library, | |
1369 | don't try to insert watchpoint. We don't automatically delete | |
1370 | such watchpoint, though, since failure to parse expression | |
1371 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1372 | if ( !target_has_execution) |
1373 | { | |
1374 | /* Without execution, memory can't change. No use to try and | |
1375 | set watchpoint locations. The watchpoint will be reset when | |
1376 | the target gains execution, through breakpoint_re_set. */ | |
1377 | } | |
1378 | else if (within_current_scope && b->exp) | |
a5606eee | 1379 | { |
0cf6dd15 | 1380 | int pc = 0; |
fa4727a6 | 1381 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1382 | struct program_space *frame_pspace; |
a5606eee | 1383 | |
0cf6dd15 | 1384 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1385 | |
a5606eee VP |
1386 | /* Avoid setting b->val if it's already set. The meaning of |
1387 | b->val is 'the last value' user saw, and we should update | |
1388 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1389 | happens, the code that reports it updates b->val directly. |
1390 | We don't keep track of the memory value for masked | |
1391 | watchpoints. */ | |
3a5c3e22 | 1392 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1393 | { |
1394 | b->val = v; | |
1395 | b->val_valid = 1; | |
1396 | } | |
a5606eee | 1397 | |
2d134ed3 PA |
1398 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1399 | ||
a5606eee | 1400 | /* Look at each value on the value chain. */ |
9fa40276 | 1401 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1402 | { |
1403 | /* If it's a memory location, and GDB actually needed | |
1404 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1405 | must watch it. If the first value returned is |
1406 | still lazy, that means an error occurred reading it; | |
1407 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1408 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1409 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1410 | { |
1411 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1412 | |
a5606eee VP |
1413 | /* We only watch structs and arrays if user asked |
1414 | for it explicitly, never if they just happen to | |
1415 | appear in the middle of some value chain. */ | |
fa4727a6 | 1416 | if (v == result |
a5606eee VP |
1417 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1418 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1419 | { | |
1420 | CORE_ADDR addr; | |
1421 | int len, type; | |
1422 | struct bp_location *loc, **tmp; | |
1423 | ||
42ae5230 | 1424 | addr = value_address (v); |
a5606eee VP |
1425 | len = TYPE_LENGTH (value_type (v)); |
1426 | type = hw_write; | |
3a5c3e22 | 1427 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1428 | type = hw_read; |
3a5c3e22 | 1429 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1430 | type = hw_access; |
3a5c3e22 PA |
1431 | |
1432 | loc = allocate_bp_location (&b->base); | |
1433 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1434 | ; |
1435 | *tmp = loc; | |
a6d9a66e | 1436 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1437 | |
1438 | loc->pspace = frame_pspace; | |
a5606eee VP |
1439 | loc->address = addr; |
1440 | loc->length = len; | |
1441 | loc->watchpoint_type = type; | |
1442 | } | |
1443 | } | |
9fa40276 TJB |
1444 | } |
1445 | ||
1446 | /* Change the type of breakpoint between hardware assisted or | |
1447 | an ordinary watchpoint depending on the hardware support | |
1448 | and free hardware slots. REPARSE is set when the inferior | |
1449 | is started. */ | |
a9634178 | 1450 | if (reparse) |
9fa40276 | 1451 | { |
e09342b5 | 1452 | int reg_cnt; |
9fa40276 TJB |
1453 | enum bp_loc_type loc_type; |
1454 | struct bp_location *bl; | |
a5606eee | 1455 | |
a9634178 | 1456 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1457 | |
1458 | if (reg_cnt) | |
9fa40276 TJB |
1459 | { |
1460 | int i, target_resources_ok, other_type_used; | |
1461 | ||
a9634178 TJB |
1462 | /* Use an exact watchpoint when there's only one memory region to be |
1463 | watched, and only one debug register is needed to watch it. */ | |
1464 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1465 | ||
9fa40276 | 1466 | /* We need to determine how many resources are already |
e09342b5 TJB |
1467 | used for all other hardware watchpoints plus this one |
1468 | to see if we still have enough resources to also fit | |
1469 | this watchpoint in as well. To guarantee the | |
1470 | hw_watchpoint_used_count call below counts this | |
1471 | watchpoint, make sure that it is marked as a hardware | |
1472 | watchpoint. */ | |
3a5c3e22 PA |
1473 | if (b->base.type == bp_watchpoint) |
1474 | b->base.type = bp_hardware_watchpoint; | |
9fa40276 | 1475 | |
3a5c3e22 | 1476 | i = hw_watchpoint_used_count (b->base.type, &other_type_used); |
e09342b5 | 1477 | target_resources_ok = target_can_use_hardware_watchpoint |
3a5c3e22 | 1478 | (b->base.type, i, other_type_used); |
e09342b5 | 1479 | if (target_resources_ok <= 0) |
a9634178 | 1480 | { |
3a5c3e22 | 1481 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1482 | |
1483 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1484 | error (_("Target does not support this type of " |
1485 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1486 | else if (target_resources_ok < 0 && !sw_mode) |
1487 | error (_("There are not enough available hardware " | |
1488 | "resources for this watchpoint.")); | |
a9634178 | 1489 | else |
3a5c3e22 | 1490 | b->base.type = bp_watchpoint; |
a9634178 | 1491 | } |
9fa40276 | 1492 | } |
3a5c3e22 | 1493 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
a9634178 TJB |
1494 | error (_("Expression cannot be implemented with " |
1495 | "read/access watchpoint.")); | |
9fa40276 | 1496 | else |
3a5c3e22 | 1497 | b->base.type = bp_watchpoint; |
9fa40276 | 1498 | |
3a5c3e22 | 1499 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1500 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1501 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1502 | bl->loc_type = loc_type; |
1503 | } | |
1504 | ||
1505 | for (v = val_chain; v; v = next) | |
1506 | { | |
a5606eee VP |
1507 | next = value_next (v); |
1508 | if (v != b->val) | |
1509 | value_free (v); | |
1510 | } | |
1511 | ||
c7437ca6 PA |
1512 | /* If a software watchpoint is not watching any memory, then the |
1513 | above left it without any location set up. But, | |
1514 | bpstat_stop_status requires a location to be able to report | |
1515 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1516 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1517 | { |
3a5c3e22 PA |
1518 | struct breakpoint *base = &b->base; |
1519 | base->loc = allocate_bp_location (base); | |
1520 | base->loc->pspace = frame_pspace; | |
1521 | base->loc->address = -1; | |
1522 | base->loc->length = -1; | |
1523 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1524 | } |
a5606eee VP |
1525 | } |
1526 | else if (!within_current_scope) | |
7270d8f2 | 1527 | { |
ac74f770 MS |
1528 | printf_filtered (_("\ |
1529 | Watchpoint %d deleted because the program has left the block\n\ | |
1530 | in which its expression is valid.\n"), | |
3a5c3e22 | 1531 | b->base.number); |
d0fb5eae | 1532 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1533 | } |
a5606eee VP |
1534 | |
1535 | /* Restore the selected frame. */ | |
66076460 DJ |
1536 | if (frame_saved) |
1537 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1538 | } |
1539 | ||
a5606eee | 1540 | |
74960c60 VP |
1541 | /* Returns 1 iff breakpoint location should be |
1542 | inserted in the inferior. */ | |
1543 | static int | |
35df4500 | 1544 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1545 | { |
35df4500 | 1546 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1547 | return 0; |
1548 | ||
35df4500 | 1549 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1550 | return 0; |
1551 | ||
35df4500 | 1552 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1553 | return 0; |
1554 | ||
56710373 PA |
1555 | /* This is set for example, when we're attached to the parent of a |
1556 | vfork, and have detached from the child. The child is running | |
1557 | free, and we expect it to do an exec or exit, at which point the | |
1558 | OS makes the parent schedulable again (and the target reports | |
1559 | that the vfork is done). Until the child is done with the shared | |
1560 | memory region, do not insert breakpoints in the parent, otherwise | |
1561 | the child could still trip on the parent's breakpoints. Since | |
1562 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1563 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1564 | return 0; |
1565 | ||
1042e4c0 SS |
1566 | /* Tracepoints are inserted by the target at a time of its choosing, |
1567 | not by us. */ | |
35df4500 | 1568 | if (is_tracepoint (bl->owner)) |
1042e4c0 SS |
1569 | return 0; |
1570 | ||
74960c60 VP |
1571 | return 1; |
1572 | } | |
1573 | ||
934709f0 PW |
1574 | /* Same as should_be_inserted but does the check assuming |
1575 | that the location is not duplicated. */ | |
1576 | ||
1577 | static int | |
1578 | unduplicated_should_be_inserted (struct bp_location *bl) | |
1579 | { | |
1580 | int result; | |
1581 | const int save_duplicate = bl->duplicate; | |
1582 | ||
1583 | bl->duplicate = 0; | |
1584 | result = should_be_inserted (bl); | |
1585 | bl->duplicate = save_duplicate; | |
1586 | return result; | |
1587 | } | |
1588 | ||
35df4500 TJB |
1589 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
1590 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 1591 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
1592 | Returns 0 for success, 1 if the bp_location type is not supported or |
1593 | -1 for failure. | |
879bfdc2 | 1594 | |
4a64f543 MS |
1595 | NOTE drow/2003-09-09: This routine could be broken down to an |
1596 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1597 | static int |
35df4500 | 1598 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 1599 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 1600 | int *disabled_breaks, |
26bb91f3 | 1601 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1602 | { |
1603 | int val = 0; | |
1604 | ||
35df4500 | 1605 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1606 | return 0; |
1607 | ||
8181d85f | 1608 | /* Initialize the target-specific information. */ |
35df4500 TJB |
1609 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
1610 | bl->target_info.placed_address = bl->address; | |
1611 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 1612 | bl->target_info.length = bl->length; |
8181d85f | 1613 | |
35df4500 TJB |
1614 | if (bl->loc_type == bp_loc_software_breakpoint |
1615 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 1616 | { |
35df4500 | 1617 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
1618 | { |
1619 | /* If the explicitly specified breakpoint type | |
1620 | is not hardware breakpoint, check the memory map to see | |
1621 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 1622 | |
765dc015 VP |
1623 | Two important cases are: |
1624 | - location type is not hardware breakpoint, memory | |
1625 | is readonly. We change the type of the location to | |
1626 | hardware breakpoint. | |
4a64f543 MS |
1627 | - location type is hardware breakpoint, memory is |
1628 | read-write. This means we've previously made the | |
1629 | location hardware one, but then the memory map changed, | |
1630 | so we undo. | |
765dc015 | 1631 | |
4a64f543 MS |
1632 | When breakpoints are removed, remove_breakpoints will use |
1633 | location types we've just set here, the only possible | |
1634 | problem is that memory map has changed during running | |
1635 | program, but it's not going to work anyway with current | |
1636 | gdb. */ | |
765dc015 | 1637 | struct mem_region *mr |
35df4500 | 1638 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
1639 | |
1640 | if (mr) | |
1641 | { | |
1642 | if (automatic_hardware_breakpoints) | |
1643 | { | |
765dc015 VP |
1644 | enum bp_loc_type new_type; |
1645 | ||
1646 | if (mr->attrib.mode != MEM_RW) | |
1647 | new_type = bp_loc_hardware_breakpoint; | |
1648 | else | |
1649 | new_type = bp_loc_software_breakpoint; | |
1650 | ||
35df4500 | 1651 | if (new_type != bl->loc_type) |
765dc015 VP |
1652 | { |
1653 | static int said = 0; | |
cc59ec59 | 1654 | |
35df4500 | 1655 | bl->loc_type = new_type; |
765dc015 VP |
1656 | if (!said) |
1657 | { | |
3e43a32a MS |
1658 | fprintf_filtered (gdb_stdout, |
1659 | _("Note: automatically using " | |
1660 | "hardware breakpoints for " | |
1661 | "read-only addresses.\n")); | |
765dc015 VP |
1662 | said = 1; |
1663 | } | |
1664 | } | |
1665 | } | |
35df4500 | 1666 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 1667 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
1668 | warning (_("cannot set software breakpoint " |
1669 | "at readonly address %s"), | |
35df4500 | 1670 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
1671 | } |
1672 | } | |
1673 | ||
879bfdc2 DJ |
1674 | /* First check to see if we have to handle an overlay. */ |
1675 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
1676 | || bl->section == NULL |
1677 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
1678 | { |
1679 | /* No overlay handling: just set the breakpoint. */ | |
1680 | ||
348d480f | 1681 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
1682 | } |
1683 | else | |
1684 | { | |
4a64f543 | 1685 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
1686 | Shall we set a breakpoint at the LMA? */ |
1687 | if (!overlay_events_enabled) | |
1688 | { | |
1689 | /* Yes -- overlay event support is not active, | |
1690 | so we must try to set a breakpoint at the LMA. | |
1691 | This will not work for a hardware breakpoint. */ | |
35df4500 | 1692 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 1693 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 1694 | bl->owner->number); |
879bfdc2 DJ |
1695 | else |
1696 | { | |
35df4500 TJB |
1697 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
1698 | bl->section); | |
879bfdc2 | 1699 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
1700 | bl->overlay_target_info = bl->target_info; |
1701 | bl->overlay_target_info.placed_address = addr; | |
1702 | val = target_insert_breakpoint (bl->gdbarch, | |
1703 | &bl->overlay_target_info); | |
879bfdc2 | 1704 | if (val != 0) |
99361f52 | 1705 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1706 | "Overlay breakpoint %d " |
1707 | "failed: in ROM?\n", | |
35df4500 | 1708 | bl->owner->number); |
879bfdc2 DJ |
1709 | } |
1710 | } | |
1711 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 1712 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
1713 | { |
1714 | /* Yes. This overlay section is mapped into memory. */ | |
348d480f | 1715 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
1716 | } |
1717 | else | |
1718 | { | |
1719 | /* No. This breakpoint will not be inserted. | |
1720 | No error, but do not mark the bp as 'inserted'. */ | |
1721 | return 0; | |
1722 | } | |
1723 | } | |
1724 | ||
1725 | if (val) | |
1726 | { | |
1727 | /* Can't set the breakpoint. */ | |
35df4500 | 1728 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 1729 | { |
4a64f543 | 1730 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 1731 | val = 0; |
35df4500 | 1732 | bl->shlib_disabled = 1; |
8d3788bd | 1733 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
1734 | if (!*disabled_breaks) |
1735 | { | |
1736 | fprintf_unfiltered (tmp_error_stream, | |
1737 | "Cannot insert breakpoint %d.\n", | |
1738 | bl->owner->number); | |
1739 | fprintf_unfiltered (tmp_error_stream, | |
1740 | "Temporarily disabling shared " | |
1741 | "library breakpoints:\n"); | |
1742 | } | |
1743 | *disabled_breaks = 1; | |
879bfdc2 | 1744 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 1745 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
1746 | } |
1747 | else | |
879bfdc2 | 1748 | { |
35df4500 | 1749 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
1750 | { |
1751 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
1752 | fprintf_unfiltered (tmp_error_stream, |
1753 | "Cannot insert hardware " | |
1754 | "breakpoint %d.\n", | |
35df4500 | 1755 | bl->owner->number); |
879bfdc2 DJ |
1756 | } |
1757 | else | |
1758 | { | |
1759 | fprintf_unfiltered (tmp_error_stream, | |
1760 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1761 | bl->owner->number); |
879bfdc2 DJ |
1762 | fprintf_filtered (tmp_error_stream, |
1763 | "Error accessing memory address "); | |
35df4500 | 1764 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 1765 | tmp_error_stream); |
879bfdc2 DJ |
1766 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1767 | safe_strerror (val)); | |
1768 | } | |
1769 | ||
1770 | } | |
1771 | } | |
1772 | else | |
35df4500 | 1773 | bl->inserted = 1; |
879bfdc2 DJ |
1774 | |
1775 | return val; | |
1776 | } | |
1777 | ||
35df4500 | 1778 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 1779 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 1780 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 1781 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 1782 | { |
77b06cd7 TJB |
1783 | gdb_assert (bl->owner->ops != NULL |
1784 | && bl->owner->ops->insert_location != NULL); | |
1785 | ||
1786 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
1787 | |
1788 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1789 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 1790 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
1791 | { |
1792 | struct bp_location *loc, **loc_temp; | |
1793 | ||
1794 | /* But don't try to insert it, if there's already another | |
1795 | hw_access location that would be considered a duplicate | |
1796 | of this one. */ | |
1797 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 1798 | if (loc != bl |
85d721b8 | 1799 | && loc->watchpoint_type == hw_access |
35df4500 | 1800 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 1801 | { |
35df4500 TJB |
1802 | bl->duplicate = 1; |
1803 | bl->inserted = 1; | |
1804 | bl->target_info = loc->target_info; | |
1805 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
1806 | val = 0; |
1807 | break; | |
1808 | } | |
1809 | ||
1810 | if (val == 1) | |
1811 | { | |
77b06cd7 TJB |
1812 | bl->watchpoint_type = hw_access; |
1813 | val = bl->owner->ops->insert_location (bl); | |
1814 | ||
1815 | if (val) | |
1816 | /* Back to the original value. */ | |
1817 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
1818 | } |
1819 | } | |
1820 | ||
35df4500 | 1821 | bl->inserted = (val == 0); |
879bfdc2 DJ |
1822 | } |
1823 | ||
35df4500 | 1824 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 1825 | { |
77b06cd7 TJB |
1826 | gdb_assert (bl->owner->ops != NULL |
1827 | && bl->owner->ops->insert_location != NULL); | |
1828 | ||
1829 | val = bl->owner->ops->insert_location (bl); | |
1830 | if (val) | |
1831 | { | |
1832 | bl->owner->enable_state = bp_disabled; | |
1833 | ||
1834 | if (val == 1) | |
1835 | warning (_("\ | |
1836 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
1837 | of catchpoint."), bl->owner->number); | |
1838 | else | |
1839 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
1840 | } | |
1841 | ||
1842 | bl->inserted = (val == 0); | |
1640b821 DJ |
1843 | |
1844 | /* We've already printed an error message if there was a problem | |
1845 | inserting this catchpoint, and we've disabled the catchpoint, | |
1846 | so just return success. */ | |
1847 | return 0; | |
879bfdc2 DJ |
1848 | } |
1849 | ||
1850 | return 0; | |
1851 | } | |
1852 | ||
6c95b8df PA |
1853 | /* This function is called when program space PSPACE is about to be |
1854 | deleted. It takes care of updating breakpoints to not reference | |
1855 | PSPACE anymore. */ | |
1856 | ||
1857 | void | |
1858 | breakpoint_program_space_exit (struct program_space *pspace) | |
1859 | { | |
1860 | struct breakpoint *b, *b_temp; | |
876fa593 | 1861 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1862 | |
1863 | /* Remove any breakpoint that was set through this program space. */ | |
1864 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1865 | { | |
1866 | if (b->pspace == pspace) | |
1867 | delete_breakpoint (b); | |
1868 | } | |
1869 | ||
1870 | /* Breakpoints set through other program spaces could have locations | |
1871 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1872 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1873 | { |
1874 | struct bp_location *tmp; | |
1875 | ||
1876 | if (loc->pspace == pspace) | |
1877 | { | |
2bdf28a0 | 1878 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1879 | if (loc->owner->loc == loc) |
1880 | loc->owner->loc = loc->next; | |
1881 | else | |
1882 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1883 | if (tmp->next == loc) | |
1884 | { | |
1885 | tmp->next = loc->next; | |
1886 | break; | |
1887 | } | |
1888 | } | |
1889 | } | |
1890 | ||
1891 | /* Now update the global location list to permanently delete the | |
1892 | removed locations above. */ | |
1893 | update_global_location_list (0); | |
1894 | } | |
1895 | ||
74960c60 VP |
1896 | /* Make sure all breakpoints are inserted in inferior. |
1897 | Throws exception on any error. | |
1898 | A breakpoint that is already inserted won't be inserted | |
1899 | again, so calling this function twice is safe. */ | |
1900 | void | |
1901 | insert_breakpoints (void) | |
1902 | { | |
1903 | struct breakpoint *bpt; | |
1904 | ||
1905 | ALL_BREAKPOINTS (bpt) | |
1906 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
1907 | { |
1908 | struct watchpoint *w = (struct watchpoint *) bpt; | |
1909 | ||
1910 | update_watchpoint (w, 0 /* don't reparse. */); | |
1911 | } | |
74960c60 | 1912 | |
b60e7edf | 1913 | update_global_location_list (1); |
74960c60 | 1914 | |
c35b1492 PA |
1915 | /* update_global_location_list does not insert breakpoints when |
1916 | always_inserted_mode is not enabled. Explicitly insert them | |
1917 | now. */ | |
1918 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1919 | insert_breakpoint_locations (); |
1920 | } | |
1921 | ||
c30eee59 | 1922 | /* Used when starting or continuing the program. */ |
c906108c | 1923 | |
74960c60 VP |
1924 | static void |
1925 | insert_breakpoint_locations (void) | |
c906108c | 1926 | { |
a5606eee | 1927 | struct breakpoint *bpt; |
35df4500 | 1928 | struct bp_location *bl, **blp_tmp; |
e236ba44 | 1929 | int error = 0; |
c906108c | 1930 | int val = 0; |
3fbb6ffa | 1931 | int disabled_breaks = 0; |
81d0cc19 | 1932 | int hw_breakpoint_error = 0; |
c906108c | 1933 | |
81d0cc19 | 1934 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1935 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1936 | |
81d0cc19 GS |
1937 | /* Explicitly mark the warning -- this will only be printed if |
1938 | there was an error. */ | |
1939 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1940 | |
1941 | save_current_space_and_thread (); | |
1942 | ||
35df4500 | 1943 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 1944 | { |
35df4500 | 1945 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1946 | continue; |
1947 | ||
4a64f543 MS |
1948 | /* There is no point inserting thread-specific breakpoints if |
1949 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
1950 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
1951 | if (bl->owner->thread != -1 |
1952 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
1953 | continue; |
1954 | ||
35df4500 | 1955 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
1956 | |
1957 | /* For targets that support global breakpoints, there's no need | |
1958 | to select an inferior to insert breakpoint to. In fact, even | |
1959 | if we aren't attached to any process yet, we should still | |
1960 | insert breakpoints. */ | |
1961 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1962 | && ptid_equal (inferior_ptid, null_ptid)) | |
1963 | continue; | |
1964 | ||
3fbb6ffa TJB |
1965 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
1966 | &hw_breakpoint_error); | |
879bfdc2 | 1967 | if (val) |
e236ba44 | 1968 | error = val; |
879bfdc2 | 1969 | } |
c906108c | 1970 | |
4a64f543 MS |
1971 | /* If we failed to insert all locations of a watchpoint, remove |
1972 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
1973 | ALL_BREAKPOINTS (bpt) |
1974 | { | |
1975 | int some_failed = 0; | |
1976 | struct bp_location *loc; | |
1977 | ||
1978 | if (!is_hardware_watchpoint (bpt)) | |
1979 | continue; | |
1980 | ||
d6b74ac4 | 1981 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1982 | continue; |
74960c60 VP |
1983 | |
1984 | if (bpt->disposition == disp_del_at_next_stop) | |
1985 | continue; | |
a5606eee VP |
1986 | |
1987 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1988 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1989 | { |
1990 | some_failed = 1; | |
1991 | break; | |
1992 | } | |
1993 | if (some_failed) | |
1994 | { | |
1995 | for (loc = bpt->loc; loc; loc = loc->next) | |
1996 | if (loc->inserted) | |
1997 | remove_breakpoint (loc, mark_uninserted); | |
1998 | ||
1999 | hw_breakpoint_error = 1; | |
2000 | fprintf_unfiltered (tmp_error_stream, | |
2001 | "Could not insert hardware watchpoint %d.\n", | |
2002 | bpt->number); | |
2003 | error = -1; | |
2004 | } | |
2005 | } | |
2006 | ||
e236ba44 | 2007 | if (error) |
81d0cc19 GS |
2008 | { |
2009 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2010 | message about possibly exhausted resources. */ | |
879bfdc2 | 2011 | if (hw_breakpoint_error) |
81d0cc19 | 2012 | { |
c6510018 MS |
2013 | fprintf_unfiltered (tmp_error_stream, |
2014 | "Could not insert hardware breakpoints:\n\ | |
2015 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2016 | } |
81d0cc19 GS |
2017 | target_terminal_ours_for_output (); |
2018 | error_stream (tmp_error_stream); | |
2019 | } | |
f7545552 TT |
2020 | |
2021 | do_cleanups (cleanups); | |
c906108c SS |
2022 | } |
2023 | ||
c30eee59 TJB |
2024 | /* Used when the program stops. |
2025 | Returns zero if successful, or non-zero if there was a problem | |
2026 | removing a breakpoint location. */ | |
2027 | ||
c906108c | 2028 | int |
fba45db2 | 2029 | remove_breakpoints (void) |
c906108c | 2030 | { |
35df4500 | 2031 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2032 | int val = 0; |
c906108c | 2033 | |
35df4500 | 2034 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2035 | { |
35df4500 TJB |
2036 | if (bl->inserted) |
2037 | val |= remove_breakpoint (bl, mark_uninserted); | |
c5aa993b | 2038 | } |
3a1bae8e | 2039 | return val; |
c906108c SS |
2040 | } |
2041 | ||
6c95b8df PA |
2042 | /* Remove breakpoints of process PID. */ |
2043 | ||
2044 | int | |
2045 | remove_breakpoints_pid (int pid) | |
2046 | { | |
35df4500 | 2047 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2048 | int val; |
2049 | struct inferior *inf = find_inferior_pid (pid); | |
2050 | ||
35df4500 | 2051 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2052 | { |
35df4500 | 2053 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2054 | continue; |
2055 | ||
35df4500 | 2056 | if (bl->inserted) |
6c95b8df | 2057 | { |
35df4500 | 2058 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2059 | if (val != 0) |
2060 | return val; | |
2061 | } | |
2062 | } | |
2063 | return 0; | |
2064 | } | |
2065 | ||
c906108c | 2066 | int |
fba45db2 | 2067 | reattach_breakpoints (int pid) |
c906108c | 2068 | { |
6c95b8df | 2069 | struct cleanup *old_chain; |
35df4500 | 2070 | struct bp_location *bl, **blp_tmp; |
c906108c | 2071 | int val; |
86b887df | 2072 | struct ui_file *tmp_error_stream; |
3fbb6ffa | 2073 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2074 | struct inferior *inf; |
2075 | struct thread_info *tp; | |
2076 | ||
2077 | tp = any_live_thread_of_process (pid); | |
2078 | if (tp == NULL) | |
2079 | return 1; | |
2080 | ||
2081 | inf = find_inferior_pid (pid); | |
2082 | old_chain = save_inferior_ptid (); | |
2083 | ||
2084 | inferior_ptid = tp->ptid; | |
a4954f26 | 2085 | |
86b887df | 2086 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2087 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2088 | |
35df4500 | 2089 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2090 | { |
35df4500 | 2091 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2092 | continue; |
2093 | ||
35df4500 | 2094 | if (bl->inserted) |
c5aa993b | 2095 | { |
35df4500 | 2096 | bl->inserted = 0; |
3fbb6ffa | 2097 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); |
c5aa993b JM |
2098 | if (val != 0) |
2099 | { | |
ce696e05 | 2100 | do_cleanups (old_chain); |
c5aa993b JM |
2101 | return val; |
2102 | } | |
2103 | } | |
2104 | } | |
ce696e05 | 2105 | do_cleanups (old_chain); |
c906108c SS |
2106 | return 0; |
2107 | } | |
2108 | ||
e58b0e63 PA |
2109 | static int internal_breakpoint_number = -1; |
2110 | ||
84f4c1fe PM |
2111 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2112 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2113 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 2114 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
2115 | breakpoint_count and that value incremented. Internal breakpoints |
2116 | do not set the internal var bpnum. */ | |
2117 | static void | |
2118 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2119 | { | |
2120 | if (internal) | |
2121 | b->number = internal_breakpoint_number--; | |
2122 | else | |
2123 | { | |
2124 | set_breakpoint_count (breakpoint_count + 1); | |
2125 | b->number = breakpoint_count; | |
2126 | } | |
2127 | } | |
2128 | ||
e62c965a | 2129 | static struct breakpoint * |
a6d9a66e | 2130 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 2131 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 2132 | const struct breakpoint_ops *ops) |
e62c965a | 2133 | { |
e62c965a PP |
2134 | struct symtab_and_line sal; |
2135 | struct breakpoint *b; | |
2136 | ||
4a64f543 | 2137 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2138 | |
2139 | sal.pc = address; | |
2140 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2141 | sal.pspace = current_program_space; |
e62c965a | 2142 | |
06edf0c0 | 2143 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
2144 | b->number = internal_breakpoint_number--; |
2145 | b->disposition = disp_donttouch; | |
2146 | ||
2147 | return b; | |
2148 | } | |
2149 | ||
17450429 PP |
2150 | static const char *const longjmp_names[] = |
2151 | { | |
2152 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2153 | }; | |
2154 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2155 | ||
2156 | /* Per-objfile data private to breakpoint.c. */ | |
2157 | struct breakpoint_objfile_data | |
2158 | { | |
2159 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2160 | struct minimal_symbol *overlay_msym; | |
2161 | ||
2162 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2163 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2164 | ||
2165 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2166 | struct minimal_symbol *terminate_msym; | |
2167 | ||
2168 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2169 | struct minimal_symbol *exception_msym; | |
2170 | }; | |
2171 | ||
2172 | static const struct objfile_data *breakpoint_objfile_key; | |
2173 | ||
2174 | /* Minimal symbol not found sentinel. */ | |
2175 | static struct minimal_symbol msym_not_found; | |
2176 | ||
2177 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2178 | ||
2179 | static int | |
2180 | msym_not_found_p (const struct minimal_symbol *msym) | |
2181 | { | |
2182 | return msym == &msym_not_found; | |
2183 | } | |
2184 | ||
2185 | /* Return per-objfile data needed by breakpoint.c. | |
2186 | Allocate the data if necessary. */ | |
2187 | ||
2188 | static struct breakpoint_objfile_data * | |
2189 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2190 | { | |
2191 | struct breakpoint_objfile_data *bp_objfile_data; | |
2192 | ||
2193 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2194 | if (bp_objfile_data == NULL) | |
2195 | { | |
2196 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2197 | sizeof (*bp_objfile_data)); | |
2198 | ||
2199 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2200 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2201 | } | |
2202 | return bp_objfile_data; | |
2203 | } | |
2204 | ||
e62c965a | 2205 | static void |
af02033e | 2206 | create_overlay_event_breakpoint (void) |
e62c965a | 2207 | { |
69de3c6a | 2208 | struct objfile *objfile; |
af02033e | 2209 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2210 | |
69de3c6a PP |
2211 | ALL_OBJFILES (objfile) |
2212 | { | |
2213 | struct breakpoint *b; | |
17450429 PP |
2214 | struct breakpoint_objfile_data *bp_objfile_data; |
2215 | CORE_ADDR addr; | |
69de3c6a | 2216 | |
17450429 PP |
2217 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2218 | ||
2219 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2220 | continue; | |
2221 | ||
2222 | if (bp_objfile_data->overlay_msym == NULL) | |
2223 | { | |
2224 | struct minimal_symbol *m; | |
2225 | ||
2226 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2227 | if (m == NULL) | |
2228 | { | |
2229 | /* Avoid future lookups in this objfile. */ | |
2230 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2231 | continue; | |
2232 | } | |
2233 | bp_objfile_data->overlay_msym = m; | |
2234 | } | |
e62c965a | 2235 | |
17450429 PP |
2236 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2237 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2238 | bp_overlay_event, |
2239 | &internal_breakpoint_ops); | |
69de3c6a | 2240 | b->addr_string = xstrdup (func_name); |
e62c965a | 2241 | |
69de3c6a PP |
2242 | if (overlay_debugging == ovly_auto) |
2243 | { | |
2244 | b->enable_state = bp_enabled; | |
2245 | overlay_events_enabled = 1; | |
2246 | } | |
2247 | else | |
2248 | { | |
2249 | b->enable_state = bp_disabled; | |
2250 | overlay_events_enabled = 0; | |
2251 | } | |
e62c965a PP |
2252 | } |
2253 | update_global_location_list (1); | |
2254 | } | |
2255 | ||
0fd8e87f | 2256 | static void |
af02033e | 2257 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2258 | { |
6c95b8df | 2259 | struct program_space *pspace; |
6c95b8df PA |
2260 | struct cleanup *old_chain; |
2261 | ||
2262 | old_chain = save_current_program_space (); | |
0fd8e87f | 2263 | |
6c95b8df | 2264 | ALL_PSPACES (pspace) |
af02033e PP |
2265 | { |
2266 | struct objfile *objfile; | |
2267 | ||
2268 | set_current_program_space (pspace); | |
2269 | ||
2270 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2271 | { |
af02033e PP |
2272 | int i; |
2273 | struct gdbarch *gdbarch; | |
17450429 | 2274 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2275 | |
af02033e PP |
2276 | gdbarch = get_objfile_arch (objfile); |
2277 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2278 | continue; |
2279 | ||
17450429 PP |
2280 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2281 | ||
2282 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2283 | { |
2284 | struct breakpoint *b; | |
af02033e | 2285 | const char *func_name; |
17450429 | 2286 | CORE_ADDR addr; |
6c95b8df | 2287 | |
17450429 | 2288 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2289 | continue; |
0fd8e87f | 2290 | |
17450429 PP |
2291 | func_name = longjmp_names[i]; |
2292 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2293 | { | |
2294 | struct minimal_symbol *m; | |
2295 | ||
2296 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2297 | if (m == NULL) | |
2298 | { | |
2299 | /* Prevent future lookups in this objfile. */ | |
2300 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2301 | continue; | |
2302 | } | |
2303 | bp_objfile_data->longjmp_msym[i] = m; | |
2304 | } | |
2305 | ||
2306 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
06edf0c0 PA |
2307 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
2308 | &internal_breakpoint_ops); | |
af02033e PP |
2309 | b->addr_string = xstrdup (func_name); |
2310 | b->enable_state = bp_disabled; | |
2311 | } | |
0fd8e87f | 2312 | } |
af02033e | 2313 | } |
0fd8e87f | 2314 | update_global_location_list (1); |
6c95b8df PA |
2315 | |
2316 | do_cleanups (old_chain); | |
0fd8e87f UW |
2317 | } |
2318 | ||
af02033e | 2319 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2320 | static void |
af02033e | 2321 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2322 | { |
2323 | struct program_space *pspace; | |
aa7d318d | 2324 | struct cleanup *old_chain; |
af02033e | 2325 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2326 | |
2327 | old_chain = save_current_program_space (); | |
2328 | ||
2329 | ALL_PSPACES (pspace) | |
17450429 PP |
2330 | { |
2331 | struct objfile *objfile; | |
2332 | CORE_ADDR addr; | |
2333 | ||
2334 | set_current_program_space (pspace); | |
2335 | ||
aa7d318d TT |
2336 | ALL_OBJFILES (objfile) |
2337 | { | |
2338 | struct breakpoint *b; | |
17450429 | 2339 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2340 | |
17450429 | 2341 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2342 | |
17450429 PP |
2343 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2344 | continue; | |
2345 | ||
2346 | if (bp_objfile_data->terminate_msym == NULL) | |
2347 | { | |
2348 | struct minimal_symbol *m; | |
2349 | ||
2350 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2351 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2352 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2353 | { | |
2354 | /* Prevent future lookups in this objfile. */ | |
2355 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2356 | continue; | |
2357 | } | |
2358 | bp_objfile_data->terminate_msym = m; | |
2359 | } | |
aa7d318d | 2360 | |
17450429 PP |
2361 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2362 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2363 | bp_std_terminate_master, |
2364 | &internal_breakpoint_ops); | |
aa7d318d TT |
2365 | b->addr_string = xstrdup (func_name); |
2366 | b->enable_state = bp_disabled; | |
2367 | } | |
17450429 PP |
2368 | } |
2369 | ||
aa7d318d TT |
2370 | update_global_location_list (1); |
2371 | ||
2372 | do_cleanups (old_chain); | |
2373 | } | |
2374 | ||
186c406b TT |
2375 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2376 | ||
2377 | void | |
2378 | create_exception_master_breakpoint (void) | |
2379 | { | |
2380 | struct objfile *objfile; | |
17450429 | 2381 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2382 | |
2383 | ALL_OBJFILES (objfile) | |
2384 | { | |
17450429 PP |
2385 | struct breakpoint *b; |
2386 | struct gdbarch *gdbarch; | |
2387 | struct breakpoint_objfile_data *bp_objfile_data; | |
2388 | CORE_ADDR addr; | |
2389 | ||
2390 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2391 | ||
2392 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2393 | continue; | |
2394 | ||
2395 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2396 | |
17450429 | 2397 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2398 | { |
17450429 | 2399 | struct minimal_symbol *debug_hook; |
186c406b | 2400 | |
17450429 PP |
2401 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2402 | if (debug_hook == NULL) | |
2403 | { | |
2404 | bp_objfile_data->exception_msym = &msym_not_found; | |
2405 | continue; | |
2406 | } | |
2407 | ||
2408 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2409 | } |
17450429 PP |
2410 | |
2411 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2412 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2413 | ¤t_target); | |
06edf0c0 PA |
2414 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
2415 | &internal_breakpoint_ops); | |
17450429 PP |
2416 | b->addr_string = xstrdup (func_name); |
2417 | b->enable_state = bp_disabled; | |
186c406b TT |
2418 | } |
2419 | ||
2420 | update_global_location_list (1); | |
2421 | } | |
2422 | ||
c906108c | 2423 | void |
fba45db2 | 2424 | update_breakpoints_after_exec (void) |
c906108c | 2425 | { |
35df4500 | 2426 | struct breakpoint *b, *b_tmp; |
876fa593 | 2427 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2428 | |
25b22b0a PA |
2429 | /* We're about to delete breakpoints from GDB's lists. If the |
2430 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2431 | writing the breakpoints' "shadow contents" back into memory. The | |
2432 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2433 | do that. Instead, the target is responsible from marking | |
2434 | breakpoints out as soon as it detects an exec. We don't do that | |
2435 | here instead, because there may be other attempts to delete | |
2436 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2437 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2438 | if (bploc->pspace == current_program_space) |
2439 | gdb_assert (!bploc->inserted); | |
c906108c | 2440 | |
35df4500 | 2441 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2442 | { |
6c95b8df PA |
2443 | if (b->pspace != current_program_space) |
2444 | continue; | |
2445 | ||
4a64f543 | 2446 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2447 | if (b->type == bp_shlib_event) |
2448 | { | |
2449 | delete_breakpoint (b); | |
2450 | continue; | |
2451 | } | |
c906108c | 2452 | |
4a64f543 | 2453 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2454 | if (b->type == bp_jit_event) |
2455 | { | |
2456 | delete_breakpoint (b); | |
2457 | continue; | |
2458 | } | |
2459 | ||
1900040c | 2460 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2461 | as must overlay event and longjmp master breakpoints. */ |
2462 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2463 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2464 | || b->type == bp_exception_master) | |
c4093a6a JM |
2465 | { |
2466 | delete_breakpoint (b); | |
2467 | continue; | |
2468 | } | |
2469 | ||
4a64f543 | 2470 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 2471 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
2472 | { |
2473 | delete_breakpoint (b); | |
2474 | continue; | |
2475 | } | |
2476 | ||
611c83ae PA |
2477 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2478 | after an exec. */ | |
186c406b TT |
2479 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2480 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2481 | { |
2482 | delete_breakpoint (b); | |
2483 | continue; | |
2484 | } | |
2485 | ||
ce78b96d JB |
2486 | if (b->type == bp_catchpoint) |
2487 | { | |
2488 | /* For now, none of the bp_catchpoint breakpoints need to | |
2489 | do anything at this point. In the future, if some of | |
2490 | the catchpoints need to something, we will need to add | |
2491 | a new method, and call this method from here. */ | |
2492 | continue; | |
2493 | } | |
2494 | ||
c5aa993b JM |
2495 | /* bp_finish is a special case. The only way we ought to be able |
2496 | to see one of these when an exec() has happened, is if the user | |
2497 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2498 | carries them to the call-site of the current callee, by setting | |
2499 | a temporary bp there and resuming. But in this case, the finish | |
2500 | will carry them entirely through the vfork & exec. | |
2501 | ||
2502 | We don't want to allow a bp_finish to remain inserted now. But | |
2503 | we can't safely delete it, 'cause finish_command has a handle to | |
2504 | the bp on a bpstat, and will later want to delete it. There's a | |
2505 | chance (and I've seen it happen) that if we delete the bp_finish | |
2506 | here, that its storage will get reused by the time finish_command | |
2507 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2508 | We really must allow finish_command to delete a bp_finish. | |
2509 | ||
e5dd4106 | 2510 | In the absence of a general solution for the "how do we know |
53a5351d JM |
2511 | it's safe to delete something others may have handles to?" |
2512 | problem, what we'll do here is just uninsert the bp_finish, and | |
2513 | let finish_command delete it. | |
2514 | ||
2515 | (We know the bp_finish is "doomed" in the sense that it's | |
2516 | momentary, and will be deleted as soon as finish_command sees | |
2517 | the inferior stopped. So it doesn't matter that the bp's | |
2518 | address is probably bogus in the new a.out, unlike e.g., the | |
2519 | solib breakpoints.) */ | |
c5aa993b | 2520 | |
c5aa993b JM |
2521 | if (b->type == bp_finish) |
2522 | { | |
2523 | continue; | |
2524 | } | |
2525 | ||
2526 | /* Without a symbolic address, we have little hope of the | |
2527 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2528 | a.out. */ |
c5aa993b JM |
2529 | if (b->addr_string == NULL) |
2530 | { | |
2531 | delete_breakpoint (b); | |
2532 | continue; | |
2533 | } | |
c5aa993b | 2534 | } |
1900040c | 2535 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
2536 | create_overlay_event_breakpoint (); |
2537 | create_longjmp_master_breakpoint (); | |
2538 | create_std_terminate_master_breakpoint (); | |
186c406b | 2539 | create_exception_master_breakpoint (); |
c906108c SS |
2540 | } |
2541 | ||
2542 | int | |
fba45db2 | 2543 | detach_breakpoints (int pid) |
c906108c | 2544 | { |
35df4500 | 2545 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2546 | int val = 0; |
ce696e05 | 2547 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2548 | struct inferior *inf = current_inferior (); |
c5aa993b | 2549 | |
39f77062 | 2550 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2551 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2552 | |
6c95b8df | 2553 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2554 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2555 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2556 | { |
35df4500 | 2557 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2558 | continue; |
2559 | ||
35df4500 TJB |
2560 | if (bl->inserted) |
2561 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2562 | } |
d03285ec UW |
2563 | |
2564 | /* Detach single-step breakpoints as well. */ | |
2565 | detach_single_step_breakpoints (); | |
2566 | ||
ce696e05 | 2567 | do_cleanups (old_chain); |
3a1bae8e | 2568 | return val; |
c906108c SS |
2569 | } |
2570 | ||
35df4500 | 2571 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2572 | Note that this is used to detach breakpoints from a child fork. |
2573 | When we get here, the child isn't in the inferior list, and neither | |
2574 | do we have objects to represent its address space --- we should | |
35df4500 | 2575 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2576 | |
c906108c | 2577 | static int |
35df4500 | 2578 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2579 | { |
2580 | int val; | |
c5aa993b | 2581 | |
35df4500 TJB |
2582 | /* BL is never in moribund_locations by our callers. */ |
2583 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2584 | |
35df4500 | 2585 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2586 | /* Permanent breakpoints cannot be inserted or removed. */ |
2587 | return 0; | |
2588 | ||
74960c60 VP |
2589 | /* The type of none suggests that owner is actually deleted. |
2590 | This should not ever happen. */ | |
35df4500 | 2591 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2592 | |
35df4500 TJB |
2593 | if (bl->loc_type == bp_loc_software_breakpoint |
2594 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2595 | { |
c02f5703 MS |
2596 | /* "Normal" instruction breakpoint: either the standard |
2597 | trap-instruction bp (bp_breakpoint), or a | |
2598 | bp_hardware_breakpoint. */ | |
2599 | ||
2600 | /* First check to see if we have to handle an overlay. */ | |
2601 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2602 | || bl->section == NULL |
2603 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2604 | { |
2605 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 2606 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 2607 | } |
c906108c SS |
2608 | else |
2609 | { | |
4a64f543 | 2610 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2611 | Did we set a breakpoint at the LMA? */ |
2612 | if (!overlay_events_enabled) | |
2613 | { | |
2614 | /* Yes -- overlay event support is not active, so we | |
2615 | should have set a breakpoint at the LMA. Remove it. | |
2616 | */ | |
c02f5703 MS |
2617 | /* Ignore any failures: if the LMA is in ROM, we will |
2618 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2619 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2620 | target_remove_hw_breakpoint (bl->gdbarch, | |
2621 | &bl->overlay_target_info); | |
c02f5703 | 2622 | else |
35df4500 TJB |
2623 | target_remove_breakpoint (bl->gdbarch, |
2624 | &bl->overlay_target_info); | |
c02f5703 MS |
2625 | } |
2626 | /* Did we set a breakpoint at the VMA? | |
2627 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2628 | if (bl->inserted) |
c906108c | 2629 | { |
c02f5703 MS |
2630 | /* Yes -- remove it. Previously we did not bother to |
2631 | remove the breakpoint if the section had been | |
2632 | unmapped, but let's not rely on that being safe. We | |
2633 | don't know what the overlay manager might do. */ | |
aa67235e UW |
2634 | |
2635 | /* However, we should remove *software* breakpoints only | |
2636 | if the section is still mapped, or else we overwrite | |
2637 | wrong code with the saved shadow contents. */ | |
348d480f PA |
2638 | if (bl->loc_type == bp_loc_hardware_breakpoint |
2639 | || section_is_mapped (bl->section)) | |
2640 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
2641 | else |
2642 | val = 0; | |
c906108c | 2643 | } |
c02f5703 MS |
2644 | else |
2645 | { | |
2646 | /* No -- not inserted, so no need to remove. No error. */ | |
2647 | val = 0; | |
2648 | } | |
c906108c | 2649 | } |
879d1e6b UW |
2650 | |
2651 | /* In some cases, we might not be able to remove a breakpoint | |
2652 | in a shared library that has already been removed, but we | |
2653 | have not yet processed the shlib unload event. */ | |
35df4500 | 2654 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2655 | val = 0; |
2656 | ||
c906108c SS |
2657 | if (val) |
2658 | return val; | |
35df4500 | 2659 | bl->inserted = (is == mark_inserted); |
c906108c | 2660 | } |
35df4500 | 2661 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2662 | { |
77b06cd7 TJB |
2663 | gdb_assert (bl->owner->ops != NULL |
2664 | && bl->owner->ops->remove_location != NULL); | |
2665 | ||
35df4500 | 2666 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2667 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2668 | |
c906108c | 2669 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2670 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2671 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2672 | bl->owner->number); |
c906108c | 2673 | } |
35df4500 TJB |
2674 | else if (bl->owner->type == bp_catchpoint |
2675 | && breakpoint_enabled (bl->owner) | |
2676 | && !bl->duplicate) | |
ce78b96d | 2677 | { |
77b06cd7 TJB |
2678 | gdb_assert (bl->owner->ops != NULL |
2679 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2680 | |
77b06cd7 | 2681 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2682 | if (val) |
2683 | return val; | |
77b06cd7 | 2684 | |
35df4500 | 2685 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2686 | } |
c906108c SS |
2687 | |
2688 | return 0; | |
2689 | } | |
2690 | ||
6c95b8df | 2691 | static int |
35df4500 | 2692 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2693 | { |
2694 | int ret; | |
2695 | struct cleanup *old_chain; | |
2696 | ||
35df4500 TJB |
2697 | /* BL is never in moribund_locations by our callers. */ |
2698 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2699 | |
35df4500 | 2700 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2701 | /* Permanent breakpoints cannot be inserted or removed. */ |
2702 | return 0; | |
2703 | ||
2704 | /* The type of none suggests that owner is actually deleted. | |
2705 | This should not ever happen. */ | |
35df4500 | 2706 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2707 | |
2708 | old_chain = save_current_space_and_thread (); | |
2709 | ||
35df4500 | 2710 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2711 | |
35df4500 | 2712 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2713 | |
2714 | do_cleanups (old_chain); | |
2715 | return ret; | |
2716 | } | |
2717 | ||
c906108c SS |
2718 | /* Clear the "inserted" flag in all breakpoints. */ |
2719 | ||
25b22b0a | 2720 | void |
fba45db2 | 2721 | mark_breakpoints_out (void) |
c906108c | 2722 | { |
35df4500 | 2723 | struct bp_location *bl, **blp_tmp; |
c906108c | 2724 | |
35df4500 TJB |
2725 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2726 | if (bl->pspace == current_program_space) | |
2727 | bl->inserted = 0; | |
c906108c SS |
2728 | } |
2729 | ||
53a5351d JM |
2730 | /* Clear the "inserted" flag in all breakpoints and delete any |
2731 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2732 | |
2733 | Plus other such housekeeping that has to be done for breakpoints | |
2734 | between runs. | |
2735 | ||
53a5351d JM |
2736 | Note: this function gets called at the end of a run (by |
2737 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2738 | init_wait_for_inferior). */ |
c906108c SS |
2739 | |
2740 | ||
2741 | ||
2742 | void | |
fba45db2 | 2743 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2744 | { |
35df4500 TJB |
2745 | struct breakpoint *b, *b_tmp; |
2746 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2747 | int ix; |
6c95b8df | 2748 | struct program_space *pspace = current_program_space; |
c906108c | 2749 | |
50c71eaf PA |
2750 | /* If breakpoint locations are shared across processes, then there's |
2751 | nothing to do. */ | |
2567c7d9 | 2752 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2753 | return; |
2754 | ||
35df4500 | 2755 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2756 | { |
35df4500 TJB |
2757 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2758 | if (bl->pspace == pspace | |
2759 | && bl->owner->enable_state != bp_permanent) | |
2760 | bl->inserted = 0; | |
6c95b8df | 2761 | } |
075f6582 | 2762 | |
35df4500 | 2763 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2764 | { |
6c95b8df PA |
2765 | if (b->loc && b->loc->pspace != pspace) |
2766 | continue; | |
2767 | ||
c5aa993b JM |
2768 | switch (b->type) |
2769 | { | |
2770 | case bp_call_dummy: | |
c906108c | 2771 | |
c5aa993b | 2772 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2773 | cause problems when the inferior is rerun, so we better get |
2774 | rid of it. */ | |
2775 | ||
2776 | case bp_watchpoint_scope: | |
2777 | ||
2778 | /* Also get rid of scope breakpoints. */ | |
2779 | ||
2780 | case bp_shlib_event: | |
2781 | ||
2782 | /* Also remove solib event breakpoints. Their addresses may | |
2783 | have changed since the last time we ran the program. | |
2784 | Actually we may now be debugging against different target; | |
2785 | and so the solib backend that installed this breakpoint may | |
2786 | not be used in by the target. E.g., | |
2787 | ||
2788 | (gdb) file prog-linux | |
2789 | (gdb) run # native linux target | |
2790 | ... | |
2791 | (gdb) kill | |
2792 | (gdb) file prog-win.exe | |
2793 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2794 | */ | |
c906108c | 2795 | |
c5aa993b JM |
2796 | delete_breakpoint (b); |
2797 | break; | |
c906108c | 2798 | |
c5aa993b JM |
2799 | case bp_watchpoint: |
2800 | case bp_hardware_watchpoint: | |
2801 | case bp_read_watchpoint: | |
2802 | case bp_access_watchpoint: | |
3a5c3e22 PA |
2803 | { |
2804 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 2805 | |
3a5c3e22 PA |
2806 | /* Likewise for watchpoints on local expressions. */ |
2807 | if (w->exp_valid_block != NULL) | |
2808 | delete_breakpoint (b); | |
2809 | else if (context == inf_starting) | |
2810 | { | |
2811 | /* Reset val field to force reread of starting value in | |
2812 | insert_breakpoints. */ | |
2813 | if (w->val) | |
2814 | value_free (w->val); | |
2815 | w->val = NULL; | |
2816 | w->val_valid = 0; | |
c860120c | 2817 | } |
3a5c3e22 | 2818 | } |
c5aa993b JM |
2819 | break; |
2820 | default: | |
c5aa993b JM |
2821 | break; |
2822 | } | |
2823 | } | |
1c5cfe86 PA |
2824 | |
2825 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2826 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2827 | decref_bp_location (&bl); | |
1c5cfe86 | 2828 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2829 | } |
2830 | ||
6c95b8df PA |
2831 | /* These functions concern about actual breakpoints inserted in the |
2832 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2833 | we need to hop over the bkpt --- so we check for address space | |
2834 | match, not program space. */ | |
2835 | ||
c2c6d25f JM |
2836 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2837 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2838 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2839 | permanent breakpoint. | |
2840 | - When continuing from a location with an ordinary breakpoint, we | |
2841 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 2842 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
2843 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
2844 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2845 | |
c2c6d25f | 2846 | enum breakpoint_here |
6c95b8df | 2847 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2848 | { |
35df4500 | 2849 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2850 | int any_breakpoint_here = 0; |
c906108c | 2851 | |
35df4500 | 2852 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2853 | { |
35df4500 TJB |
2854 | if (bl->loc_type != bp_loc_software_breakpoint |
2855 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2856 | continue; |
2857 | ||
f1310107 | 2858 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
2859 | if ((breakpoint_enabled (bl->owner) |
2860 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 2861 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2862 | { |
2863 | if (overlay_debugging | |
35df4500 TJB |
2864 | && section_is_overlay (bl->section) |
2865 | && !section_is_mapped (bl->section)) | |
075f6582 | 2866 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2867 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2868 | return permanent_breakpoint_here; |
2869 | else | |
2870 | any_breakpoint_here = 1; | |
2871 | } | |
2872 | } | |
c906108c | 2873 | |
c2c6d25f | 2874 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2875 | } |
2876 | ||
1c5cfe86 PA |
2877 | /* Return true if there's a moribund breakpoint at PC. */ |
2878 | ||
2879 | int | |
6c95b8df | 2880 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2881 | { |
2882 | struct bp_location *loc; | |
2883 | int ix; | |
2884 | ||
2885 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 2886 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
2887 | return 1; |
2888 | ||
2889 | return 0; | |
2890 | } | |
c2c6d25f | 2891 | |
c36b740a | 2892 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2893 | inserted using regular breakpoint_chain / bp_location array |
2894 | mechanism. This does not check for single-step breakpoints, which | |
2895 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2896 | |
2897 | int | |
4a64f543 MS |
2898 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2899 | CORE_ADDR pc) | |
c906108c | 2900 | { |
35df4500 | 2901 | struct bp_location *bl, **blp_tmp; |
c906108c | 2902 | |
35df4500 | 2903 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2904 | { |
35df4500 TJB |
2905 | if (bl->loc_type != bp_loc_software_breakpoint |
2906 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2907 | continue; |
2908 | ||
35df4500 | 2909 | if (bl->inserted |
f1310107 | 2910 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2911 | { |
2912 | if (overlay_debugging | |
35df4500 TJB |
2913 | && section_is_overlay (bl->section) |
2914 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2915 | continue; /* unmapped overlay -- can't be a match */ |
2916 | else | |
2917 | return 1; | |
2918 | } | |
c5aa993b | 2919 | } |
c36b740a VP |
2920 | return 0; |
2921 | } | |
2922 | ||
2923 | /* Returns non-zero iff there's either regular breakpoint | |
2924 | or a single step breakpoint inserted at PC. */ | |
2925 | ||
2926 | int | |
6c95b8df | 2927 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2928 | { |
6c95b8df | 2929 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2930 | return 1; |
c906108c | 2931 | |
6c95b8df | 2932 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2933 | return 1; |
2934 | ||
c906108c SS |
2935 | return 0; |
2936 | } | |
2937 | ||
4fa8626c DJ |
2938 | /* This function returns non-zero iff there is a software breakpoint |
2939 | inserted at PC. */ | |
2940 | ||
2941 | int | |
3e43a32a MS |
2942 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
2943 | CORE_ADDR pc) | |
4fa8626c | 2944 | { |
35df4500 | 2945 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 2946 | |
35df4500 | 2947 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 2948 | { |
35df4500 | 2949 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
2950 | continue; |
2951 | ||
35df4500 TJB |
2952 | if (bl->inserted |
2953 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2954 | aspace, pc)) |
4fa8626c DJ |
2955 | { |
2956 | if (overlay_debugging | |
35df4500 TJB |
2957 | && section_is_overlay (bl->section) |
2958 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
2959 | continue; /* unmapped overlay -- can't be a match */ |
2960 | else | |
2961 | return 1; | |
2962 | } | |
2963 | } | |
2964 | ||
1aafd4da | 2965 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2966 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2967 | return 1; |
2968 | ||
4fa8626c DJ |
2969 | return 0; |
2970 | } | |
2971 | ||
9093389c PA |
2972 | int |
2973 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2974 | CORE_ADDR addr, ULONGEST len) | |
2975 | { | |
2976 | struct breakpoint *bpt; | |
2977 | ||
2978 | ALL_BREAKPOINTS (bpt) | |
2979 | { | |
2980 | struct bp_location *loc; | |
2981 | ||
2982 | if (bpt->type != bp_hardware_watchpoint | |
2983 | && bpt->type != bp_access_watchpoint) | |
2984 | continue; | |
2985 | ||
2986 | if (!breakpoint_enabled (bpt)) | |
2987 | continue; | |
2988 | ||
2989 | for (loc = bpt->loc; loc; loc = loc->next) | |
2990 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2991 | { | |
2992 | CORE_ADDR l, h; | |
2993 | ||
2994 | /* Check for intersection. */ | |
2995 | l = max (loc->address, addr); | |
2996 | h = min (loc->address + loc->length, addr + len); | |
2997 | if (l < h) | |
2998 | return 1; | |
2999 | } | |
3000 | } | |
3001 | return 0; | |
3002 | } | |
3003 | ||
075f6582 DJ |
3004 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
3005 | PC is valid for process/thread PTID. */ | |
c906108c SS |
3006 | |
3007 | int | |
6c95b8df PA |
3008 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
3009 | ptid_t ptid) | |
c906108c | 3010 | { |
35df4500 | 3011 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 3012 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 3013 | int thread = -1; |
4a306c9a | 3014 | int task = 0; |
a6f1cd96 | 3015 | |
35df4500 | 3016 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3017 | { |
35df4500 TJB |
3018 | if (bl->loc_type != bp_loc_software_breakpoint |
3019 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3020 | continue; |
3021 | ||
35df4500 TJB |
3022 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
3023 | if (!breakpoint_enabled (bl->owner) | |
3024 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
3025 | continue; |
3026 | ||
f1310107 | 3027 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
3028 | continue; |
3029 | ||
35df4500 | 3030 | if (bl->owner->thread != -1) |
075f6582 | 3031 | { |
a6f1cd96 JB |
3032 | /* This is a thread-specific breakpoint. Check that ptid |
3033 | matches that thread. If thread hasn't been computed yet, | |
3034 | it is now time to do so. */ | |
3035 | if (thread == -1) | |
3036 | thread = pid_to_thread_id (ptid); | |
35df4500 | 3037 | if (bl->owner->thread != thread) |
a6f1cd96 | 3038 | continue; |
075f6582 | 3039 | } |
a6f1cd96 | 3040 | |
35df4500 | 3041 | if (bl->owner->task != 0) |
4a306c9a JB |
3042 | { |
3043 | /* This is a task-specific breakpoint. Check that ptid | |
3044 | matches that task. If task hasn't been computed yet, | |
3045 | it is now time to do so. */ | |
3046 | if (task == 0) | |
3047 | task = ada_get_task_number (ptid); | |
35df4500 | 3048 | if (bl->owner->task != task) |
4a306c9a JB |
3049 | continue; |
3050 | } | |
3051 | ||
a6f1cd96 | 3052 | if (overlay_debugging |
35df4500 TJB |
3053 | && section_is_overlay (bl->section) |
3054 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
3055 | continue; /* unmapped overlay -- can't be a match */ |
3056 | ||
3057 | return 1; | |
c5aa993b | 3058 | } |
c906108c SS |
3059 | |
3060 | return 0; | |
3061 | } | |
c906108c | 3062 | \f |
c5aa993b | 3063 | |
c906108c SS |
3064 | /* bpstat stuff. External routines' interfaces are documented |
3065 | in breakpoint.h. */ | |
3066 | ||
3067 | int | |
fba45db2 | 3068 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3069 | { |
533be4dd | 3070 | return (ep->type == bp_catchpoint); |
c906108c SS |
3071 | } |
3072 | ||
f431efe5 PA |
3073 | /* Frees any storage that is part of a bpstat. Does not walk the |
3074 | 'next' chain. */ | |
3075 | ||
3076 | static void | |
198757a8 VP |
3077 | bpstat_free (bpstat bs) |
3078 | { | |
3079 | if (bs->old_val != NULL) | |
3080 | value_free (bs->old_val); | |
9add0f1b | 3081 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3082 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3083 | xfree (bs); |
3084 | } | |
3085 | ||
c906108c SS |
3086 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3087 | Also free any storage that is part of a bpstat. */ | |
3088 | ||
3089 | void | |
fba45db2 | 3090 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3091 | { |
3092 | bpstat p; | |
3093 | bpstat q; | |
3094 | ||
3095 | if (bsp == 0) | |
3096 | return; | |
3097 | p = *bsp; | |
3098 | while (p != NULL) | |
3099 | { | |
3100 | q = p->next; | |
198757a8 | 3101 | bpstat_free (p); |
c906108c SS |
3102 | p = q; |
3103 | } | |
3104 | *bsp = NULL; | |
3105 | } | |
3106 | ||
3107 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3108 | is part of the bpstat is copied as well. */ | |
3109 | ||
3110 | bpstat | |
fba45db2 | 3111 | bpstat_copy (bpstat bs) |
c906108c SS |
3112 | { |
3113 | bpstat p = NULL; | |
3114 | bpstat tmp; | |
3115 | bpstat retval = NULL; | |
3116 | ||
3117 | if (bs == NULL) | |
3118 | return bs; | |
3119 | ||
3120 | for (; bs != NULL; bs = bs->next) | |
3121 | { | |
3122 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3123 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3124 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3125 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3126 | if (bs->old_val != NULL) |
3c3185ac JK |
3127 | { |
3128 | tmp->old_val = value_copy (bs->old_val); | |
3129 | release_value (tmp->old_val); | |
3130 | } | |
31cc81e9 | 3131 | |
c906108c SS |
3132 | if (p == NULL) |
3133 | /* This is the first thing in the chain. */ | |
3134 | retval = tmp; | |
3135 | else | |
3136 | p->next = tmp; | |
3137 | p = tmp; | |
3138 | } | |
3139 | p->next = NULL; | |
3140 | return retval; | |
3141 | } | |
3142 | ||
4a64f543 | 3143 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3144 | |
3145 | bpstat | |
fba45db2 | 3146 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3147 | { |
c5aa993b JM |
3148 | if (bsp == NULL) |
3149 | return NULL; | |
c906108c | 3150 | |
c5aa993b JM |
3151 | for (; bsp != NULL; bsp = bsp->next) |
3152 | { | |
f431efe5 | 3153 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3154 | return bsp; |
3155 | } | |
c906108c SS |
3156 | return NULL; |
3157 | } | |
3158 | ||
4a64f543 MS |
3159 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3160 | stopped at. *BSP upon return is a bpstat which points to the | |
3161 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3162 | good for anything but further calls to bpstat_num). | |
3163 | ||
8671a17b PA |
3164 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3165 | Return -1 if stopped at a breakpoint that has been deleted since | |
3166 | we set it. | |
3167 | Return 1 otherwise. */ | |
c906108c SS |
3168 | |
3169 | int | |
8671a17b | 3170 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3171 | { |
3172 | struct breakpoint *b; | |
3173 | ||
3174 | if ((*bsp) == NULL) | |
3175 | return 0; /* No more breakpoint values */ | |
8671a17b | 3176 | |
4a64f543 MS |
3177 | /* We assume we'll never have several bpstats that correspond to a |
3178 | single breakpoint -- otherwise, this function might return the | |
3179 | same number more than once and this will look ugly. */ | |
f431efe5 | 3180 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3181 | *bsp = (*bsp)->next; |
3182 | if (b == NULL) | |
3183 | return -1; /* breakpoint that's been deleted since */ | |
3184 | ||
3185 | *num = b->number; /* We have its number */ | |
3186 | return 1; | |
c906108c SS |
3187 | } |
3188 | ||
3189 | /* Modify BS so that the actions will not be performed. */ | |
3190 | ||
3191 | void | |
fba45db2 | 3192 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
3193 | { |
3194 | for (; bs != NULL; bs = bs->next) | |
3195 | { | |
9add0f1b | 3196 | decref_counted_command_line (&bs->commands); |
dde2d684 | 3197 | bs->commands_left = NULL; |
c906108c SS |
3198 | if (bs->old_val != NULL) |
3199 | { | |
3200 | value_free (bs->old_val); | |
3201 | bs->old_val = NULL; | |
3202 | } | |
3203 | } | |
3204 | } | |
3205 | ||
f3b1572e PA |
3206 | /* Called when a command is about to proceed the inferior. */ |
3207 | ||
3208 | static void | |
3209 | breakpoint_about_to_proceed (void) | |
3210 | { | |
3211 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3212 | { | |
3213 | struct thread_info *tp = inferior_thread (); | |
3214 | ||
3215 | /* Allow inferior function calls in breakpoint commands to not | |
3216 | interrupt the command list. When the call finishes | |
3217 | successfully, the inferior will be standing at the same | |
3218 | breakpoint as if nothing happened. */ | |
16c381f0 | 3219 | if (tp->control.in_infcall) |
f3b1572e PA |
3220 | return; |
3221 | } | |
3222 | ||
3223 | breakpoint_proceeded = 1; | |
3224 | } | |
3225 | ||
4a64f543 MS |
3226 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3227 | command. */ | |
c906108c | 3228 | static void |
4efb68b1 | 3229 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3230 | { |
3231 | executing_breakpoint_commands = 0; | |
3232 | } | |
3233 | ||
4a64f543 MS |
3234 | /* Execute all the commands associated with all the breakpoints at |
3235 | this location. Any of these commands could cause the process to | |
3236 | proceed beyond this point, etc. We look out for such changes by | |
3237 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3238 | |
347bddb7 PA |
3239 | Returns true if a breakpoint command resumed the inferior. In that |
3240 | case, it is the caller's responsibility to recall it again with the | |
3241 | bpstat of the current thread. */ | |
3242 | ||
3243 | static int | |
3244 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3245 | { |
3246 | bpstat bs; | |
3247 | struct cleanup *old_chain; | |
347bddb7 | 3248 | int again = 0; |
c906108c SS |
3249 | |
3250 | /* Avoid endless recursion if a `source' command is contained | |
3251 | in bs->commands. */ | |
3252 | if (executing_breakpoint_commands) | |
347bddb7 | 3253 | return 0; |
c906108c SS |
3254 | |
3255 | executing_breakpoint_commands = 1; | |
3256 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3257 | ||
cf6c5ffb TT |
3258 | prevent_dont_repeat (); |
3259 | ||
4a64f543 | 3260 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3261 | bs = *bsp; |
3262 | ||
3263 | breakpoint_proceeded = 0; | |
3264 | for (; bs != NULL; bs = bs->next) | |
3265 | { | |
9add0f1b | 3266 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3267 | struct command_line *cmd; |
3268 | struct cleanup *this_cmd_tree_chain; | |
3269 | ||
3270 | /* Take ownership of the BSP's command tree, if it has one. | |
3271 | ||
3272 | The command tree could legitimately contain commands like | |
3273 | 'step' and 'next', which call clear_proceed_status, which | |
3274 | frees stop_bpstat's command tree. To make sure this doesn't | |
3275 | free the tree we're executing out from under us, we need to | |
3276 | take ownership of the tree ourselves. Since a given bpstat's | |
3277 | commands are only executed once, we don't need to copy it; we | |
3278 | can clear the pointer in the bpstat, and make sure we free | |
3279 | the tree when we're done. */ | |
9add0f1b TT |
3280 | ccmd = bs->commands; |
3281 | bs->commands = NULL; | |
3282 | this_cmd_tree_chain | |
3283 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3284 | cmd = bs->commands_left; | |
3285 | bs->commands_left = NULL; | |
6c50ab1c | 3286 | |
c906108c SS |
3287 | while (cmd != NULL) |
3288 | { | |
3289 | execute_control_command (cmd); | |
3290 | ||
3291 | if (breakpoint_proceeded) | |
3292 | break; | |
3293 | else | |
3294 | cmd = cmd->next; | |
3295 | } | |
6c50ab1c JB |
3296 | |
3297 | /* We can free this command tree now. */ | |
3298 | do_cleanups (this_cmd_tree_chain); | |
3299 | ||
c906108c | 3300 | if (breakpoint_proceeded) |
32c1e744 VP |
3301 | { |
3302 | if (target_can_async_p ()) | |
347bddb7 PA |
3303 | /* If we are in async mode, then the target might be still |
3304 | running, not stopped at any breakpoint, so nothing for | |
3305 | us to do here -- just return to the event loop. */ | |
3306 | ; | |
32c1e744 VP |
3307 | else |
3308 | /* In sync mode, when execute_control_command returns | |
3309 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3310 | Breakpoint commands for that stop were not run, since |
3311 | execute_command does not run breakpoint commands -- | |
3312 | only command_line_handler does, but that one is not | |
3313 | involved in execution of breakpoint commands. So, we | |
3314 | can now execute breakpoint commands. It should be | |
3315 | noted that making execute_command do bpstat actions is | |
3316 | not an option -- in this case we'll have recursive | |
3317 | invocation of bpstat for each breakpoint with a | |
3318 | command, and can easily blow up GDB stack. Instead, we | |
3319 | return true, which will trigger the caller to recall us | |
3320 | with the new stop_bpstat. */ | |
3321 | again = 1; | |
3322 | break; | |
32c1e744 | 3323 | } |
c906108c | 3324 | } |
c2b8ed2c | 3325 | do_cleanups (old_chain); |
347bddb7 PA |
3326 | return again; |
3327 | } | |
3328 | ||
3329 | void | |
3330 | bpstat_do_actions (void) | |
3331 | { | |
3332 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3333 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3334 | && target_has_execution | |
3335 | && !is_exited (inferior_ptid) | |
3336 | && !is_executing (inferior_ptid)) | |
3337 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3338 | and only return when it is stopped at the next breakpoint, we | |
3339 | keep doing breakpoint actions until it returns false to | |
3340 | indicate the inferior was not resumed. */ | |
16c381f0 | 3341 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3342 | break; |
c906108c SS |
3343 | } |
3344 | ||
fa4727a6 DJ |
3345 | /* Print out the (old or new) value associated with a watchpoint. */ |
3346 | ||
3347 | static void | |
3348 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3349 | { | |
3350 | if (val == NULL) | |
3351 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3352 | else | |
79a45b7d TT |
3353 | { |
3354 | struct value_print_options opts; | |
3355 | get_user_print_options (&opts); | |
3356 | value_print (val, stream, &opts); | |
3357 | } | |
fa4727a6 DJ |
3358 | } |
3359 | ||
e514a9d6 | 3360 | /* Generic routine for printing messages indicating why we |
4a64f543 | 3361 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3362 | 'print_it' in the bpstat structure. Under some circumstances we |
3363 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3364 | normal_stop(). */ |
e514a9d6 JM |
3365 | |
3366 | static enum print_stop_action | |
3367 | print_bp_stop_message (bpstat bs) | |
3368 | { | |
3369 | switch (bs->print_it) | |
3370 | { | |
3371 | case print_it_noop: | |
4a64f543 | 3372 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3373 | return PRINT_UNKNOWN; |
3374 | break; | |
3375 | ||
3376 | case print_it_done: | |
3377 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3378 | relevant messages. */ |
e514a9d6 JM |
3379 | return PRINT_SRC_AND_LOC; |
3380 | break; | |
3381 | ||
3382 | case print_it_normal: | |
4f8d1dc6 | 3383 | { |
f431efe5 PA |
3384 | struct breakpoint *b = bs->breakpoint_at; |
3385 | ||
1a6a67de TJB |
3386 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3387 | which has since been deleted. */ | |
3388 | if (b == NULL) | |
3389 | return PRINT_UNKNOWN; | |
3390 | ||
348d480f PA |
3391 | /* Normal case. Call the breakpoint's print_it method. */ |
3392 | return b->ops->print_it (bs); | |
4f8d1dc6 | 3393 | } |
348d480f | 3394 | break; |
3086aeae | 3395 | |
e514a9d6 | 3396 | default: |
8e65ff28 | 3397 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3398 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3399 | break; |
c906108c | 3400 | } |
c906108c SS |
3401 | } |
3402 | ||
e514a9d6 JM |
3403 | /* Print a message indicating what happened. This is called from |
3404 | normal_stop(). The input to this routine is the head of the bpstat | |
3405 | list - a list of the eventpoints that caused this stop. This | |
3406 | routine calls the generic print routine for printing a message | |
3407 | about reasons for stopping. This will print (for example) the | |
3408 | "Breakpoint n," part of the output. The return value of this | |
3409 | routine is one of: | |
c906108c | 3410 | |
4a64f543 | 3411 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3412 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3413 | code to print the location. An example is |
c5aa993b JM |
3414 | "Breakpoint 1, " which should be followed by |
3415 | the location. | |
917317f4 | 3416 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3417 | to also print the location part of the message. |
3418 | An example is the catch/throw messages, which | |
4a64f543 | 3419 | don't require a location appended to the end. |
917317f4 | 3420 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3421 | further info to be printed. */ |
c906108c | 3422 | |
917317f4 | 3423 | enum print_stop_action |
fba45db2 | 3424 | bpstat_print (bpstat bs) |
c906108c SS |
3425 | { |
3426 | int val; | |
c5aa993b | 3427 | |
c906108c | 3428 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3429 | (Currently all watchpoints go on the bpstat whether hit or not. |
3430 | That probably could (should) be changed, provided care is taken | |
c906108c | 3431 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3432 | for (; bs; bs = bs->next) |
3433 | { | |
3434 | val = print_bp_stop_message (bs); | |
3435 | if (val == PRINT_SRC_ONLY | |
3436 | || val == PRINT_SRC_AND_LOC | |
3437 | || val == PRINT_NOTHING) | |
3438 | return val; | |
3439 | } | |
c906108c | 3440 | |
e514a9d6 | 3441 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3442 | with and nothing was printed. */ |
917317f4 | 3443 | return PRINT_UNKNOWN; |
c906108c SS |
3444 | } |
3445 | ||
4a64f543 MS |
3446 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3447 | used inside a catch_errors to evaluate the breakpoint condition. | |
3448 | The argument is a "struct expression *" that has been cast to a | |
3449 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3450 | |
3451 | static int | |
4efb68b1 | 3452 | breakpoint_cond_eval (void *exp) |
c906108c | 3453 | { |
278cd55f | 3454 | struct value *mark = value_mark (); |
c5aa993b | 3455 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3456 | |
c906108c SS |
3457 | value_free_to_mark (mark); |
3458 | return i; | |
3459 | } | |
3460 | ||
5760d0ab | 3461 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3462 | |
3463 | static bpstat | |
5760d0ab | 3464 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3465 | { |
3466 | bpstat bs; | |
3467 | ||
3468 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3469 | bs->next = NULL; |
3470 | **bs_link_pointer = bs; | |
3471 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3472 | bs->breakpoint_at = bl->owner; |
3473 | bs->bp_location_at = bl; | |
3474 | incref_bp_location (bl); | |
c906108c SS |
3475 | /* If the condition is false, etc., don't do the commands. */ |
3476 | bs->commands = NULL; | |
9add0f1b | 3477 | bs->commands_left = NULL; |
c906108c SS |
3478 | bs->old_val = NULL; |
3479 | bs->print_it = print_it_normal; | |
3480 | return bs; | |
3481 | } | |
3482 | \f | |
d983da9c DJ |
3483 | /* The target has stopped with waitstatus WS. Check if any hardware |
3484 | watchpoints have triggered, according to the target. */ | |
3485 | ||
3486 | int | |
3487 | watchpoints_triggered (struct target_waitstatus *ws) | |
3488 | { | |
d92524f1 | 3489 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3490 | CORE_ADDR addr; |
3491 | struct breakpoint *b; | |
3492 | ||
3493 | if (!stopped_by_watchpoint) | |
3494 | { | |
3495 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3496 | as not triggered. */ | |
3497 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3498 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3499 | { |
3500 | struct watchpoint *w = (struct watchpoint *) b; | |
3501 | ||
3502 | w->watchpoint_triggered = watch_triggered_no; | |
3503 | } | |
d983da9c DJ |
3504 | |
3505 | return 0; | |
3506 | } | |
3507 | ||
3508 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3509 | { | |
3510 | /* We were stopped by a watchpoint, but we don't know where. | |
3511 | Mark all watchpoints as unknown. */ | |
3512 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3513 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3514 | { |
3515 | struct watchpoint *w = (struct watchpoint *) b; | |
3516 | ||
3517 | w->watchpoint_triggered = watch_triggered_unknown; | |
3518 | } | |
d983da9c DJ |
3519 | |
3520 | return stopped_by_watchpoint; | |
3521 | } | |
3522 | ||
3523 | /* The target could report the data address. Mark watchpoints | |
3524 | affected by this data address as triggered, and all others as not | |
3525 | triggered. */ | |
3526 | ||
3527 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3528 | if (is_hardware_watchpoint (b)) |
d983da9c | 3529 | { |
3a5c3e22 | 3530 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 3531 | struct bp_location *loc; |
d983da9c | 3532 | |
3a5c3e22 | 3533 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 3534 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 3535 | { |
3a5c3e22 | 3536 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 3537 | { |
3a5c3e22 PA |
3538 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
3539 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
3540 | |
3541 | if (newaddr == start) | |
3542 | { | |
3a5c3e22 | 3543 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3544 | break; |
3545 | } | |
3546 | } | |
3547 | /* Exact match not required. Within range is sufficient. */ | |
3548 | else if (target_watchpoint_addr_within_range (¤t_target, | |
3549 | addr, loc->address, | |
3550 | loc->length)) | |
3551 | { | |
3a5c3e22 | 3552 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3553 | break; |
3554 | } | |
3555 | } | |
d983da9c DJ |
3556 | } |
3557 | ||
3558 | return 1; | |
3559 | } | |
3560 | ||
c906108c SS |
3561 | /* Possible return values for watchpoint_check (this can't be an enum |
3562 | because of check_errors). */ | |
3563 | /* The watchpoint has been deleted. */ | |
3564 | #define WP_DELETED 1 | |
3565 | /* The value has changed. */ | |
3566 | #define WP_VALUE_CHANGED 2 | |
3567 | /* The value has not changed. */ | |
3568 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3569 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3570 | #define WP_IGNORE 4 | |
c906108c SS |
3571 | |
3572 | #define BP_TEMPFLAG 1 | |
3573 | #define BP_HARDWAREFLAG 2 | |
3574 | ||
4a64f543 MS |
3575 | /* Evaluate watchpoint condition expression and check if its value |
3576 | changed. | |
553e4c11 JB |
3577 | |
3578 | P should be a pointer to struct bpstat, but is defined as a void * | |
3579 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3580 | |
3581 | static int | |
4efb68b1 | 3582 | watchpoint_check (void *p) |
c906108c SS |
3583 | { |
3584 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 3585 | struct watchpoint *b; |
c906108c SS |
3586 | struct frame_info *fr; |
3587 | int within_current_scope; | |
3588 | ||
f431efe5 | 3589 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3590 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 3591 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 3592 | |
f6bc2008 PA |
3593 | /* If this is a local watchpoint, we only want to check if the |
3594 | watchpoint frame is in scope if the current thread is the thread | |
3595 | that was used to create the watchpoint. */ | |
3596 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3597 | return WP_IGNORE; |
f6bc2008 | 3598 | |
c906108c SS |
3599 | if (b->exp_valid_block == NULL) |
3600 | within_current_scope = 1; | |
3601 | else | |
3602 | { | |
edb3359d DJ |
3603 | struct frame_info *frame = get_current_frame (); |
3604 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3605 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3606 | ||
4a64f543 MS |
3607 | /* in_function_epilogue_p() returns a non-zero value if we're |
3608 | still in the function but the stack frame has already been | |
3609 | invalidated. Since we can't rely on the values of local | |
3610 | variables after the stack has been destroyed, we are treating | |
3611 | the watchpoint in that state as `not changed' without further | |
3612 | checking. Don't mark watchpoints as changed if the current | |
3613 | frame is in an epilogue - even if they are in some other | |
3614 | frame, our view of the stack is likely to be wrong and | |
3615 | frame_find_by_id could error out. */ | |
a0f49112 | 3616 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3617 | return WP_IGNORE; |
a0f49112 | 3618 | |
101dcfbe | 3619 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3620 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3621 | |
3622 | /* If we've gotten confused in the unwinder, we might have | |
3623 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3624 | if (within_current_scope) |
3625 | { | |
3626 | struct symbol *function; | |
3627 | ||
3628 | function = get_frame_function (fr); | |
3629 | if (function == NULL | |
3630 | || !contained_in (b->exp_valid_block, | |
3631 | SYMBOL_BLOCK_VALUE (function))) | |
3632 | within_current_scope = 0; | |
3633 | } | |
69fbadd5 | 3634 | |
edb3359d | 3635 | if (within_current_scope) |
c906108c SS |
3636 | /* If we end up stopping, the current frame will get selected |
3637 | in normal_stop. So this call to select_frame won't affect | |
3638 | the user. */ | |
0f7d239c | 3639 | select_frame (fr); |
c906108c | 3640 | } |
c5aa993b | 3641 | |
c906108c SS |
3642 | if (within_current_scope) |
3643 | { | |
4a64f543 MS |
3644 | /* We use value_{,free_to_}mark because it could be a *long* |
3645 | time before we return to the command level and call | |
3646 | free_all_values. We can't call free_all_values because we | |
3647 | might be in the middle of evaluating a function call. */ | |
c906108c | 3648 | |
0cf6dd15 | 3649 | int pc = 0; |
9c06b0b4 | 3650 | struct value *mark; |
fa4727a6 DJ |
3651 | struct value *new_val; |
3652 | ||
3a5c3e22 | 3653 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
3654 | /* Since we don't know the exact trigger address (from |
3655 | stopped_data_address), just tell the user we've triggered | |
3656 | a mask watchpoint. */ | |
3657 | return WP_VALUE_CHANGED; | |
3658 | ||
3659 | mark = value_mark (); | |
0cf6dd15 | 3660 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3661 | |
4a64f543 MS |
3662 | /* We use value_equal_contents instead of value_equal because |
3663 | the latter coerces an array to a pointer, thus comparing just | |
3664 | the address of the array instead of its contents. This is | |
3665 | not what we want. */ | |
fa4727a6 | 3666 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3667 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3668 | { |
fa4727a6 DJ |
3669 | if (new_val != NULL) |
3670 | { | |
3671 | release_value (new_val); | |
3672 | value_free_to_mark (mark); | |
3673 | } | |
c906108c SS |
3674 | bs->old_val = b->val; |
3675 | b->val = new_val; | |
fa4727a6 | 3676 | b->val_valid = 1; |
c906108c SS |
3677 | return WP_VALUE_CHANGED; |
3678 | } | |
3679 | else | |
3680 | { | |
60e1c644 | 3681 | /* Nothing changed. */ |
c906108c | 3682 | value_free_to_mark (mark); |
c906108c SS |
3683 | return WP_VALUE_NOT_CHANGED; |
3684 | } | |
3685 | } | |
3686 | else | |
3687 | { | |
79a45e25 PA |
3688 | struct ui_out *uiout = current_uiout; |
3689 | ||
c906108c | 3690 | /* This seems like the only logical thing to do because |
c5aa993b JM |
3691 | if we temporarily ignored the watchpoint, then when |
3692 | we reenter the block in which it is valid it contains | |
3693 | garbage (in the case of a function, it may have two | |
3694 | garbage values, one before and one after the prologue). | |
3695 | So we can't even detect the first assignment to it and | |
3696 | watch after that (since the garbage may or may not equal | |
3697 | the first value assigned). */ | |
348d480f PA |
3698 | /* We print all the stop information in |
3699 | breakpoint_ops->print_it, but in this case, by the time we | |
3700 | call breakpoint_ops->print_it this bp will be deleted | |
3701 | already. So we have no choice but print the information | |
3702 | here. */ | |
9dc5e2a9 | 3703 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3704 | ui_out_field_string |
3705 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3706 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 3707 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
3708 | ui_out_text (uiout, |
3709 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3710 | which its expression is valid.\n"); |
4ce44c66 | 3711 | |
cdac0397 | 3712 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 3713 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 3714 | watchpoint_del_at_next_stop (b); |
c906108c SS |
3715 | |
3716 | return WP_DELETED; | |
3717 | } | |
3718 | } | |
3719 | ||
18a18393 | 3720 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
3721 | breakpoint location BL. This function does not check if we should |
3722 | stop, only if BL explains the stop. */ | |
3723 | ||
18a18393 | 3724 | static int |
6c95b8df PA |
3725 | bpstat_check_location (const struct bp_location *bl, |
3726 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3727 | { |
3728 | struct breakpoint *b = bl->owner; | |
3729 | ||
348d480f | 3730 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
3731 | gdb_assert (b != NULL); |
3732 | ||
348d480f | 3733 | return b->ops->breakpoint_hit (bl, aspace, bp_addr); |
18a18393 VP |
3734 | } |
3735 | ||
3a5c3e22 PA |
3736 | /* Determine if the watched values have actually changed, and we |
3737 | should stop. If not, set BS->stop to 0. */ | |
3738 | ||
18a18393 VP |
3739 | static void |
3740 | bpstat_check_watchpoint (bpstat bs) | |
3741 | { | |
2bdf28a0 | 3742 | const struct bp_location *bl; |
3a5c3e22 | 3743 | struct watchpoint *b; |
2bdf28a0 JK |
3744 | |
3745 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3746 | bl = bs->bp_location_at; |
2bdf28a0 | 3747 | gdb_assert (bl != NULL); |
3a5c3e22 | 3748 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 3749 | gdb_assert (b != NULL); |
18a18393 | 3750 | |
18a18393 | 3751 | { |
18a18393 VP |
3752 | int must_check_value = 0; |
3753 | ||
3a5c3e22 | 3754 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
3755 | /* For a software watchpoint, we must always check the |
3756 | watched value. */ | |
3757 | must_check_value = 1; | |
3758 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3759 | /* We have a hardware watchpoint (read, write, or access) | |
3760 | and the target earlier reported an address watched by | |
3761 | this watchpoint. */ | |
3762 | must_check_value = 1; | |
3763 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 3764 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
3765 | /* We were stopped by a hardware watchpoint, but the target could |
3766 | not report the data address. We must check the watchpoint's | |
3767 | value. Access and read watchpoints are out of luck; without | |
3768 | a data address, we can't figure it out. */ | |
3769 | must_check_value = 1; | |
3a5c3e22 | 3770 | |
18a18393 VP |
3771 | if (must_check_value) |
3772 | { | |
3e43a32a MS |
3773 | char *message |
3774 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 3775 | b->base.number); |
18a18393 VP |
3776 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3777 | int e = catch_errors (watchpoint_check, bs, message, | |
3778 | RETURN_MASK_ALL); | |
3779 | do_cleanups (cleanups); | |
3780 | switch (e) | |
3781 | { | |
3782 | case WP_DELETED: | |
3783 | /* We've already printed what needs to be printed. */ | |
3784 | bs->print_it = print_it_done; | |
3785 | /* Stop. */ | |
3786 | break; | |
60e1c644 PA |
3787 | case WP_IGNORE: |
3788 | bs->print_it = print_it_noop; | |
3789 | bs->stop = 0; | |
3790 | break; | |
18a18393 | 3791 | case WP_VALUE_CHANGED: |
3a5c3e22 | 3792 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 3793 | { |
85d721b8 PA |
3794 | /* There are two cases to consider here: |
3795 | ||
4a64f543 | 3796 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3797 | In that case, trust the target, and always report |
3798 | the watchpoint hit to the user. Even though | |
3799 | reads don't cause value changes, the value may | |
3800 | have changed since the last time it was read, and | |
3801 | since we're not trapping writes, we will not see | |
3802 | those, and as such we should ignore our notion of | |
3803 | old value. | |
3804 | ||
4a64f543 | 3805 | 2. We're watching the triggered memory for both |
85d721b8 PA |
3806 | reads and writes. There are two ways this may |
3807 | happen: | |
3808 | ||
4a64f543 | 3809 | 2.1. This is a target that can't break on data |
85d721b8 PA |
3810 | reads only, but can break on accesses (reads or |
3811 | writes), such as e.g., x86. We detect this case | |
3812 | at the time we try to insert read watchpoints. | |
3813 | ||
4a64f543 | 3814 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
3815 | watchpoints, but, the user set an access or write |
3816 | watchpoint watching the same memory as this read | |
3817 | watchpoint. | |
3818 | ||
3819 | If we're watching memory writes as well as reads, | |
3820 | ignore watchpoint hits when we find that the | |
3821 | value hasn't changed, as reads don't cause | |
3822 | changes. This still gives false positives when | |
3823 | the program writes the same value to memory as | |
3824 | what there was already in memory (we will confuse | |
3825 | it for a read), but it's much better than | |
3826 | nothing. */ | |
3827 | ||
3828 | int other_write_watchpoint = 0; | |
3829 | ||
3830 | if (bl->watchpoint_type == hw_read) | |
3831 | { | |
3832 | struct breakpoint *other_b; | |
3833 | ||
3834 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
3835 | if (other_b->type == bp_hardware_watchpoint |
3836 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 3837 | { |
3a5c3e22 PA |
3838 | struct watchpoint *other_w = |
3839 | (struct watchpoint *) other_b; | |
3840 | ||
3841 | if (other_w->watchpoint_triggered | |
3842 | == watch_triggered_yes) | |
3843 | { | |
3844 | other_write_watchpoint = 1; | |
3845 | break; | |
3846 | } | |
85d721b8 PA |
3847 | } |
3848 | } | |
3849 | ||
3850 | if (other_write_watchpoint | |
3851 | || bl->watchpoint_type == hw_access) | |
3852 | { | |
3853 | /* We're watching the same memory for writes, | |
3854 | and the value changed since the last time we | |
3855 | updated it, so this trap must be for a write. | |
3856 | Ignore it. */ | |
3857 | bs->print_it = print_it_noop; | |
3858 | bs->stop = 0; | |
3859 | } | |
18a18393 VP |
3860 | } |
3861 | break; | |
3862 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
3863 | if (b->base.type == bp_hardware_watchpoint |
3864 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
3865 | { |
3866 | /* Don't stop: write watchpoints shouldn't fire if | |
3867 | the value hasn't changed. */ | |
3868 | bs->print_it = print_it_noop; | |
3869 | bs->stop = 0; | |
3870 | } | |
3871 | /* Stop. */ | |
3872 | break; | |
3873 | default: | |
3874 | /* Can't happen. */ | |
3875 | case 0: | |
3876 | /* Error from catch_errors. */ | |
3a5c3e22 | 3877 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 3878 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
3879 | /* We've already printed what needs to be printed. */ |
3880 | bs->print_it = print_it_done; | |
3881 | break; | |
3882 | } | |
3883 | } | |
3884 | else /* must_check_value == 0 */ | |
3885 | { | |
3886 | /* This is a case where some watchpoint(s) triggered, but | |
3887 | not at the address of this watchpoint, or else no | |
3888 | watchpoint triggered after all. So don't print | |
3889 | anything for this watchpoint. */ | |
3890 | bs->print_it = print_it_noop; | |
3891 | bs->stop = 0; | |
3892 | } | |
3893 | } | |
3894 | } | |
3895 | ||
3896 | ||
3897 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3898 | of breakpoint referred to by BS. If we should not stop for this | |
3899 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 3900 | |
18a18393 VP |
3901 | static void |
3902 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3903 | { | |
3904 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
3905 | const struct bp_location *bl; |
3906 | struct breakpoint *b; | |
3907 | ||
3908 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3909 | bl = bs->bp_location_at; |
2bdf28a0 | 3910 | gdb_assert (bl != NULL); |
f431efe5 | 3911 | b = bs->breakpoint_at; |
2bdf28a0 | 3912 | gdb_assert (b != NULL); |
18a18393 VP |
3913 | |
3914 | if (frame_id_p (b->frame_id) | |
edb3359d | 3915 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3916 | bs->stop = 0; |
3917 | else if (bs->stop) | |
3918 | { | |
3919 | int value_is_zero = 0; | |
60e1c644 PA |
3920 | struct expression *cond; |
3921 | ||
7371cf6d PM |
3922 | /* Evaluate Python breakpoints that have a "stop" |
3923 | method implemented. */ | |
3924 | if (b->py_bp_object) | |
3925 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
3926 | ||
60e1c644 | 3927 | if (is_watchpoint (b)) |
3a5c3e22 PA |
3928 | { |
3929 | struct watchpoint *w = (struct watchpoint *) b; | |
3930 | ||
3931 | cond = w->cond_exp; | |
3932 | } | |
60e1c644 PA |
3933 | else |
3934 | cond = bl->cond; | |
3935 | ||
f431efe5 | 3936 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 3937 | { |
60e1c644 | 3938 | int within_current_scope = 1; |
3a5c3e22 | 3939 | struct watchpoint * w; |
60e1c644 | 3940 | |
c5bc3a77 DJ |
3941 | /* We use value_mark and value_free_to_mark because it could |
3942 | be a long time before we return to the command level and | |
3943 | call free_all_values. We can't call free_all_values | |
3944 | because we might be in the middle of evaluating a | |
3945 | function call. */ | |
3946 | struct value *mark = value_mark (); | |
3947 | ||
3a5c3e22 PA |
3948 | if (is_watchpoint (b)) |
3949 | w = (struct watchpoint *) b; | |
3950 | else | |
3951 | w = NULL; | |
3952 | ||
edb3359d DJ |
3953 | /* Need to select the frame, with all that implies so that |
3954 | the conditions will have the right context. Because we | |
3955 | use the frame, we will not see an inlined function's | |
3956 | variables when we arrive at a breakpoint at the start | |
3957 | of the inlined function; the current frame will be the | |
3958 | call site. */ | |
3a5c3e22 | 3959 | if (w == NULL || w->cond_exp_valid_block == NULL) |
60e1c644 PA |
3960 | select_frame (get_current_frame ()); |
3961 | else | |
3962 | { | |
3963 | struct frame_info *frame; | |
3964 | ||
3965 | /* For local watchpoint expressions, which particular | |
3966 | instance of a local is being watched matters, so we | |
3967 | keep track of the frame to evaluate the expression | |
3968 | in. To evaluate the condition however, it doesn't | |
3969 | really matter which instantiation of the function | |
3970 | where the condition makes sense triggers the | |
3971 | watchpoint. This allows an expression like "watch | |
3972 | global if q > 10" set in `func', catch writes to | |
3973 | global on all threads that call `func', or catch | |
3974 | writes on all recursive calls of `func' by a single | |
3975 | thread. We simply always evaluate the condition in | |
3976 | the innermost frame that's executing where it makes | |
3977 | sense to evaluate the condition. It seems | |
3978 | intuitive. */ | |
3a5c3e22 | 3979 | frame = block_innermost_frame (w->cond_exp_valid_block); |
60e1c644 PA |
3980 | if (frame != NULL) |
3981 | select_frame (frame); | |
3982 | else | |
3983 | within_current_scope = 0; | |
3984 | } | |
3985 | if (within_current_scope) | |
3986 | value_is_zero | |
3987 | = catch_errors (breakpoint_cond_eval, cond, | |
3988 | "Error in testing breakpoint condition:\n", | |
3989 | RETURN_MASK_ALL); | |
3990 | else | |
3991 | { | |
3992 | warning (_("Watchpoint condition cannot be tested " | |
3993 | "in the current scope")); | |
3994 | /* If we failed to set the right context for this | |
3995 | watchpoint, unconditionally report it. */ | |
3996 | value_is_zero = 0; | |
3997 | } | |
4a64f543 | 3998 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 3999 | value_free_to_mark (mark); |
18a18393 | 4000 | } |
60e1c644 PA |
4001 | |
4002 | if (cond && value_is_zero) | |
18a18393 VP |
4003 | { |
4004 | bs->stop = 0; | |
4005 | } | |
4006 | else if (b->thread != -1 && b->thread != thread_id) | |
4007 | { | |
4008 | bs->stop = 0; | |
4009 | } | |
4010 | else if (b->ignore_count > 0) | |
4011 | { | |
4012 | b->ignore_count--; | |
4013 | annotate_ignore_count_change (); | |
4014 | bs->stop = 0; | |
4a64f543 | 4015 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 4016 | ++(b->hit_count); |
8d3788bd | 4017 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
4018 | } |
4019 | } | |
4020 | } | |
4021 | ||
4022 | ||
9709f61c | 4023 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4024 | BP_ADDR in thread PTID. |
c906108c | 4025 | |
d983da9c | 4026 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4027 | don't understand this stop. Result is a chain of bpstat's such |
4028 | that: | |
c906108c | 4029 | |
c5aa993b | 4030 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4031 | |
c5aa993b | 4032 | if we understand why we stopped, the result is not null. |
c906108c | 4033 | |
c5aa993b JM |
4034 | Each element of the chain refers to a particular breakpoint or |
4035 | watchpoint at which we have stopped. (We may have stopped for | |
4036 | several reasons concurrently.) | |
c906108c | 4037 | |
c5aa993b JM |
4038 | Each element of the chain has valid next, breakpoint_at, |
4039 | commands, FIXME??? fields. */ | |
c906108c SS |
4040 | |
4041 | bpstat | |
6c95b8df PA |
4042 | bpstat_stop_status (struct address_space *aspace, |
4043 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4044 | { |
0d381245 | 4045 | struct breakpoint *b = NULL; |
afe38095 | 4046 | struct bp_location *bl; |
20874c92 | 4047 | struct bp_location *loc; |
5760d0ab JK |
4048 | /* First item of allocated bpstat's. */ |
4049 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4050 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4051 | bpstat bs; |
20874c92 | 4052 | int ix; |
429374b8 | 4053 | int need_remove_insert; |
f431efe5 | 4054 | int removed_any; |
c906108c | 4055 | |
f431efe5 PA |
4056 | /* First, build the bpstat chain with locations that explain a |
4057 | target stop, while being careful to not set the target running, | |
4058 | as that may invalidate locations (in particular watchpoint | |
4059 | locations are recreated). Resuming will happen here with | |
4060 | breakpoint conditions or watchpoint expressions that include | |
4061 | inferior function calls. */ | |
c5aa993b | 4062 | |
429374b8 JK |
4063 | ALL_BREAKPOINTS (b) |
4064 | { | |
4065 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4066 | continue; | |
a5606eee | 4067 | |
429374b8 JK |
4068 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4069 | { | |
4a64f543 MS |
4070 | /* For hardware watchpoints, we look only at the first |
4071 | location. The watchpoint_check function will work on the | |
4072 | entire expression, not the individual locations. For | |
4073 | read watchpoints, the watchpoints_triggered function has | |
4074 | checked all locations already. */ | |
429374b8 JK |
4075 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4076 | break; | |
18a18393 | 4077 | |
429374b8 JK |
4078 | if (bl->shlib_disabled) |
4079 | continue; | |
c5aa993b | 4080 | |
429374b8 JK |
4081 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4082 | continue; | |
c5aa993b | 4083 | |
4a64f543 MS |
4084 | /* Come here if it's a watchpoint, or if the break address |
4085 | matches. */ | |
c5aa993b | 4086 | |
4a64f543 MS |
4087 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4088 | explain stop. */ | |
c5aa993b | 4089 | |
f431efe5 PA |
4090 | /* Assume we stop. Should we find a watchpoint that is not |
4091 | actually triggered, or if the condition of the breakpoint | |
4092 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4093 | bs->stop = 1; |
4094 | bs->print = 1; | |
d983da9c | 4095 | |
f431efe5 PA |
4096 | /* If this is a scope breakpoint, mark the associated |
4097 | watchpoint as triggered so that we will handle the | |
4098 | out-of-scope event. We'll get to the watchpoint next | |
4099 | iteration. */ | |
d0fb5eae | 4100 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
4101 | { |
4102 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
4103 | ||
4104 | w->watchpoint_triggered = watch_triggered_yes; | |
4105 | } | |
f431efe5 PA |
4106 | } |
4107 | } | |
4108 | ||
4109 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4110 | { | |
f1310107 | 4111 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 4112 | { |
5760d0ab | 4113 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4114 | /* For hits of moribund locations, we should just proceed. */ |
4115 | bs->stop = 0; | |
4116 | bs->print = 0; | |
4117 | bs->print_it = print_it_noop; | |
4118 | } | |
4119 | } | |
4120 | ||
f431efe5 PA |
4121 | /* Now go through the locations that caused the target to stop, and |
4122 | check whether we're interested in reporting this stop to higher | |
4123 | layers, or whether we should resume the target transparently. */ | |
4124 | ||
4125 | removed_any = 0; | |
4126 | ||
5760d0ab | 4127 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4128 | { |
4129 | if (!bs->stop) | |
4130 | continue; | |
4131 | ||
f431efe5 | 4132 | b = bs->breakpoint_at; |
348d480f PA |
4133 | b->ops->check_status (bs); |
4134 | if (bs->stop) | |
28010a5d | 4135 | { |
348d480f | 4136 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 4137 | |
429374b8 JK |
4138 | if (bs->stop) |
4139 | { | |
4140 | ++(b->hit_count); | |
8d3788bd | 4141 | observer_notify_breakpoint_modified (b); |
c906108c | 4142 | |
4a64f543 | 4143 | /* We will stop here. */ |
429374b8 JK |
4144 | if (b->disposition == disp_disable) |
4145 | { | |
4146 | if (b->enable_state != bp_permanent) | |
4147 | b->enable_state = bp_disabled; | |
f431efe5 | 4148 | removed_any = 1; |
429374b8 JK |
4149 | } |
4150 | if (b->silent) | |
4151 | bs->print = 0; | |
4152 | bs->commands = b->commands; | |
9add0f1b TT |
4153 | incref_counted_command_line (bs->commands); |
4154 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4155 | if (bs->commands_left | |
4156 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4157 | || (xdb_commands | |
4158 | && strcmp ("Q", | |
4159 | bs->commands_left->line) == 0))) | |
429374b8 | 4160 | { |
9add0f1b | 4161 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4162 | bs->print = 0; |
4163 | } | |
429374b8 JK |
4164 | } |
4165 | ||
e5dd4106 | 4166 | /* Print nothing for this entry if we don't stop or don't print. */ |
429374b8 JK |
4167 | if (bs->stop == 0 || bs->print == 0) |
4168 | bs->print_it = print_it_noop; | |
348d480f | 4169 | } |
429374b8 | 4170 | } |
876fa593 | 4171 | |
d983da9c DJ |
4172 | /* If we aren't stopping, the value of some hardware watchpoint may |
4173 | not have changed, but the intermediate memory locations we are | |
4174 | watching may have. Don't bother if we're stopping; this will get | |
4175 | done later. */ | |
d832cb68 | 4176 | need_remove_insert = 0; |
5760d0ab JK |
4177 | if (! bpstat_causes_stop (bs_head)) |
4178 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4179 | if (!bs->stop |
f431efe5 PA |
4180 | && bs->breakpoint_at |
4181 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4182 | { |
3a5c3e22 PA |
4183 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
4184 | ||
4185 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 4186 | need_remove_insert = 1; |
d983da9c DJ |
4187 | } |
4188 | ||
d832cb68 | 4189 | if (need_remove_insert) |
2d134ed3 | 4190 | update_global_location_list (1); |
f431efe5 PA |
4191 | else if (removed_any) |
4192 | update_global_location_list (0); | |
d832cb68 | 4193 | |
5760d0ab | 4194 | return bs_head; |
c906108c | 4195 | } |
628fe4e4 JK |
4196 | |
4197 | static void | |
4198 | handle_jit_event (void) | |
4199 | { | |
4200 | struct frame_info *frame; | |
4201 | struct gdbarch *gdbarch; | |
4202 | ||
4203 | /* Switch terminal for any messages produced by | |
4204 | breakpoint_re_set. */ | |
4205 | target_terminal_ours_for_output (); | |
4206 | ||
4207 | frame = get_current_frame (); | |
4208 | gdbarch = get_frame_arch (frame); | |
4209 | ||
4210 | jit_event_handler (gdbarch); | |
4211 | ||
4212 | target_terminal_inferior (); | |
4213 | } | |
4214 | ||
4215 | /* Prepare WHAT final decision for infrun. */ | |
4216 | ||
4217 | /* Decide what infrun needs to do with this bpstat. */ | |
4218 | ||
c906108c | 4219 | struct bpstat_what |
0e30163f | 4220 | bpstat_what (bpstat bs_head) |
c906108c | 4221 | { |
c906108c | 4222 | struct bpstat_what retval; |
628fe4e4 JK |
4223 | /* We need to defer calling `solib_add', as adding new symbols |
4224 | resets breakpoints, which in turn deletes breakpoint locations, | |
4225 | and hence may clear unprocessed entries in the BS chain. */ | |
4226 | int shlib_event = 0; | |
4227 | int jit_event = 0; | |
0e30163f | 4228 | bpstat bs; |
c906108c | 4229 | |
628fe4e4 | 4230 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4231 | retval.call_dummy = STOP_NONE; |
186c406b | 4232 | retval.is_longjmp = 0; |
628fe4e4 | 4233 | |
0e30163f | 4234 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 4235 | { |
628fe4e4 JK |
4236 | /* Extract this BS's action. After processing each BS, we check |
4237 | if its action overrides all we've seem so far. */ | |
4238 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4239 | enum bptype bptype; | |
4240 | ||
c906108c | 4241 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4242 | { |
4243 | /* I suspect this can happen if it was a momentary | |
4244 | breakpoint which has since been deleted. */ | |
4245 | bptype = bp_none; | |
4246 | } | |
20874c92 | 4247 | else |
f431efe5 | 4248 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4249 | |
4250 | switch (bptype) | |
c906108c SS |
4251 | { |
4252 | case bp_none: | |
628fe4e4 | 4253 | break; |
c906108c SS |
4254 | case bp_breakpoint: |
4255 | case bp_hardware_breakpoint: | |
4256 | case bp_until: | |
4257 | case bp_finish: | |
4258 | if (bs->stop) | |
4259 | { | |
4260 | if (bs->print) | |
628fe4e4 | 4261 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4262 | else |
628fe4e4 | 4263 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4264 | } |
4265 | else | |
628fe4e4 | 4266 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4267 | break; |
4268 | case bp_watchpoint: | |
4269 | case bp_hardware_watchpoint: | |
4270 | case bp_read_watchpoint: | |
4271 | case bp_access_watchpoint: | |
4272 | if (bs->stop) | |
4273 | { | |
4274 | if (bs->print) | |
628fe4e4 | 4275 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4276 | else |
628fe4e4 | 4277 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4278 | } |
4279 | else | |
628fe4e4 JK |
4280 | { |
4281 | /* There was a watchpoint, but we're not stopping. | |
4282 | This requires no further action. */ | |
4283 | } | |
c906108c SS |
4284 | break; |
4285 | case bp_longjmp: | |
186c406b | 4286 | case bp_exception: |
628fe4e4 | 4287 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4288 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4289 | break; |
4290 | case bp_longjmp_resume: | |
186c406b | 4291 | case bp_exception_resume: |
628fe4e4 | 4292 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4293 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4294 | break; |
4295 | case bp_step_resume: | |
4296 | if (bs->stop) | |
628fe4e4 JK |
4297 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4298 | else | |
c906108c | 4299 | { |
628fe4e4 JK |
4300 | /* It is for the wrong frame. */ |
4301 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4302 | } |
c906108c | 4303 | break; |
2c03e5be PA |
4304 | case bp_hp_step_resume: |
4305 | if (bs->stop) | |
4306 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
4307 | else | |
4308 | { | |
4309 | /* It is for the wrong frame. */ | |
4310 | this_action = BPSTAT_WHAT_SINGLE; | |
4311 | } | |
4312 | break; | |
c906108c | 4313 | case bp_watchpoint_scope: |
c4093a6a | 4314 | case bp_thread_event: |
1900040c | 4315 | case bp_overlay_event: |
0fd8e87f | 4316 | case bp_longjmp_master: |
aa7d318d | 4317 | case bp_std_terminate_master: |
186c406b | 4318 | case bp_exception_master: |
628fe4e4 | 4319 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4320 | break; |
ce78b96d | 4321 | case bp_catchpoint: |
c5aa993b JM |
4322 | if (bs->stop) |
4323 | { | |
4324 | if (bs->print) | |
628fe4e4 | 4325 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4326 | else |
628fe4e4 | 4327 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4328 | } |
4329 | else | |
628fe4e4 JK |
4330 | { |
4331 | /* There was a catchpoint, but we're not stopping. | |
4332 | This requires no further action. */ | |
4333 | } | |
4334 | break; | |
4335 | case bp_shlib_event: | |
4336 | shlib_event = 1; | |
4337 | ||
4338 | /* If requested, stop when the dynamic linker notifies GDB | |
4339 | of events. This allows the user to get control and place | |
4340 | breakpoints in initializer routines for dynamically | |
4341 | loaded objects (among other things). */ | |
4342 | if (stop_on_solib_events) | |
4343 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4344 | else | |
4345 | this_action = BPSTAT_WHAT_SINGLE; | |
4346 | break; | |
4347 | case bp_jit_event: | |
4348 | jit_event = 1; | |
4349 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4350 | break; |
c906108c | 4351 | case bp_call_dummy: |
53a5351d JM |
4352 | /* Make sure the action is stop (silent or noisy), |
4353 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4354 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4355 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4356 | break; |
4357 | case bp_std_terminate: | |
4358 | /* Make sure the action is stop (silent or noisy), | |
4359 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4360 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4361 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4362 | break; |
1042e4c0 | 4363 | case bp_tracepoint: |
7a697b8d | 4364 | case bp_fast_tracepoint: |
0fb4aa4b | 4365 | case bp_static_tracepoint: |
1042e4c0 SS |
4366 | /* Tracepoint hits should not be reported back to GDB, and |
4367 | if one got through somehow, it should have been filtered | |
4368 | out already. */ | |
4369 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4370 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
4371 | break; |
4372 | case bp_gnu_ifunc_resolver: | |
4373 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
4374 | this_action = BPSTAT_WHAT_SINGLE; | |
4375 | break; | |
4376 | case bp_gnu_ifunc_resolver_return: | |
4377 | /* The breakpoint will be removed, execution will restart from the | |
4378 | PC of the former breakpoint. */ | |
4379 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4380 | break; | |
628fe4e4 JK |
4381 | default: |
4382 | internal_error (__FILE__, __LINE__, | |
4383 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4384 | } |
628fe4e4 JK |
4385 | |
4386 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4387 | } |
628fe4e4 | 4388 | |
0e30163f JK |
4389 | /* These operations may affect the bs->breakpoint_at state so they are |
4390 | delayed after MAIN_ACTION is decided above. */ | |
4391 | ||
628fe4e4 JK |
4392 | if (shlib_event) |
4393 | { | |
4394 | if (debug_infrun) | |
4395 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4396 | ||
4397 | /* Check for any newly added shared libraries if we're supposed | |
4398 | to be adding them automatically. */ | |
4399 | ||
4400 | /* Switch terminal for any messages produced by | |
4401 | breakpoint_re_set. */ | |
4402 | target_terminal_ours_for_output (); | |
4403 | ||
4404 | #ifdef SOLIB_ADD | |
4405 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4406 | #else | |
4407 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4408 | #endif | |
4409 | ||
4410 | target_terminal_inferior (); | |
4411 | } | |
4412 | ||
4413 | if (jit_event) | |
4414 | { | |
4415 | if (debug_infrun) | |
4416 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4417 | ||
4418 | handle_jit_event (); | |
4419 | } | |
4420 | ||
0e30163f JK |
4421 | for (bs = bs_head; bs != NULL; bs = bs->next) |
4422 | { | |
4423 | struct breakpoint *b = bs->breakpoint_at; | |
4424 | ||
4425 | if (b == NULL) | |
4426 | continue; | |
4427 | switch (b->type) | |
4428 | { | |
4429 | case bp_gnu_ifunc_resolver: | |
4430 | gnu_ifunc_resolver_stop (b); | |
4431 | break; | |
4432 | case bp_gnu_ifunc_resolver_return: | |
4433 | gnu_ifunc_resolver_return_stop (b); | |
4434 | break; | |
4435 | } | |
4436 | } | |
4437 | ||
c906108c SS |
4438 | return retval; |
4439 | } | |
4440 | ||
4441 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4442 | without hardware support). This isn't related to a specific bpstat, | |
4443 | just to things like whether watchpoints are set. */ | |
4444 | ||
c5aa993b | 4445 | int |
fba45db2 | 4446 | bpstat_should_step (void) |
c906108c SS |
4447 | { |
4448 | struct breakpoint *b; | |
cc59ec59 | 4449 | |
c906108c | 4450 | ALL_BREAKPOINTS (b) |
717a8278 | 4451 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4452 | return 1; |
c906108c SS |
4453 | return 0; |
4454 | } | |
4455 | ||
67822962 PA |
4456 | int |
4457 | bpstat_causes_stop (bpstat bs) | |
4458 | { | |
4459 | for (; bs != NULL; bs = bs->next) | |
4460 | if (bs->stop) | |
4461 | return 1; | |
4462 | ||
4463 | return 0; | |
4464 | } | |
4465 | ||
c906108c | 4466 | \f |
c5aa993b | 4467 | |
170b53b2 UW |
4468 | /* Compute a string of spaces suitable to indent the next line |
4469 | so it starts at the position corresponding to the table column | |
4470 | named COL_NAME in the currently active table of UIOUT. */ | |
4471 | ||
4472 | static char * | |
4473 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
4474 | { | |
4475 | static char wrap_indent[80]; | |
4476 | int i, total_width, width, align; | |
4477 | char *text; | |
4478 | ||
4479 | total_width = 0; | |
4480 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
4481 | { | |
4482 | if (strcmp (text, col_name) == 0) | |
4483 | { | |
4484 | gdb_assert (total_width < sizeof wrap_indent); | |
4485 | memset (wrap_indent, ' ', total_width); | |
4486 | wrap_indent[total_width] = 0; | |
4487 | ||
4488 | return wrap_indent; | |
4489 | } | |
4490 | ||
4491 | total_width += width + 1; | |
4492 | } | |
4493 | ||
4494 | return NULL; | |
4495 | } | |
4496 | ||
859825b8 JK |
4497 | /* Print the LOC location out of the list of B->LOC locations. */ |
4498 | ||
170b53b2 UW |
4499 | static void |
4500 | print_breakpoint_location (struct breakpoint *b, | |
4501 | struct bp_location *loc) | |
0d381245 | 4502 | { |
79a45e25 | 4503 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
4504 | struct cleanup *old_chain = save_current_program_space (); |
4505 | ||
859825b8 JK |
4506 | if (loc != NULL && loc->shlib_disabled) |
4507 | loc = NULL; | |
4508 | ||
6c95b8df PA |
4509 | if (loc != NULL) |
4510 | set_current_program_space (loc->pspace); | |
4511 | ||
56435ebe TT |
4512 | if (b->display_canonical) |
4513 | ui_out_field_string (uiout, "what", b->addr_string); | |
4514 | else if (b->source_file && loc) | |
0d381245 VP |
4515 | { |
4516 | struct symbol *sym | |
4517 | = find_pc_sect_function (loc->address, loc->section); | |
4518 | if (sym) | |
4519 | { | |
4520 | ui_out_text (uiout, "in "); | |
4521 | ui_out_field_string (uiout, "func", | |
4522 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
4523 | ui_out_text (uiout, " "); |
4524 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
4525 | ui_out_text (uiout, "at "); | |
0d381245 VP |
4526 | } |
4527 | ui_out_field_string (uiout, "file", b->source_file); | |
4528 | ui_out_text (uiout, ":"); | |
4529 | ||
4530 | if (ui_out_is_mi_like_p (uiout)) | |
4531 | { | |
4532 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4533 | char *fullname = symtab_to_fullname (sal.symtab); | |
4534 | ||
4535 | if (fullname) | |
4536 | ui_out_field_string (uiout, "fullname", fullname); | |
4537 | } | |
4538 | ||
4539 | ui_out_field_int (uiout, "line", b->line_number); | |
4540 | } | |
859825b8 | 4541 | else if (loc) |
0d381245 | 4542 | { |
170b53b2 UW |
4543 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4544 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
4545 | ||
22e722e1 DJ |
4546 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4547 | demangle, ""); | |
0d381245 | 4548 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
4549 | |
4550 | do_cleanups (stb_chain); | |
0d381245 | 4551 | } |
859825b8 JK |
4552 | else |
4553 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4554 | |
4555 | do_cleanups (old_chain); | |
0d381245 VP |
4556 | } |
4557 | ||
269b11a2 PA |
4558 | static const char * |
4559 | bptype_string (enum bptype type) | |
c906108c | 4560 | { |
c4093a6a JM |
4561 | struct ep_type_description |
4562 | { | |
4563 | enum bptype type; | |
4564 | char *description; | |
4565 | }; | |
4566 | static struct ep_type_description bptypes[] = | |
c906108c | 4567 | { |
c5aa993b JM |
4568 | {bp_none, "?deleted?"}, |
4569 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4570 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4571 | {bp_until, "until"}, |
4572 | {bp_finish, "finish"}, | |
4573 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4574 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4575 | {bp_read_watchpoint, "read watchpoint"}, |
4576 | {bp_access_watchpoint, "acc watchpoint"}, | |
4577 | {bp_longjmp, "longjmp"}, | |
4578 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4579 | {bp_exception, "exception"}, |
4580 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4581 | {bp_step_resume, "step resume"}, |
2c03e5be | 4582 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
4583 | {bp_watchpoint_scope, "watchpoint scope"}, |
4584 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4585 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4586 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4587 | {bp_thread_event, "thread events"}, |
1900040c | 4588 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4589 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4590 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4591 | {bp_exception_master, "exception master"}, |
ce78b96d | 4592 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4593 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4594 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4595 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4596 | {bp_jit_event, "jit events"}, |
0e30163f JK |
4597 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
4598 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 4599 | }; |
269b11a2 PA |
4600 | |
4601 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4602 | || ((int) type != bptypes[(int) type].type)) | |
4603 | internal_error (__FILE__, __LINE__, | |
4604 | _("bptypes table does not describe type #%d."), | |
4605 | (int) type); | |
4606 | ||
4607 | return bptypes[(int) type].description; | |
4608 | } | |
4609 | ||
4610 | /* Print B to gdb_stdout. */ | |
4611 | ||
4612 | static void | |
4613 | print_one_breakpoint_location (struct breakpoint *b, | |
4614 | struct bp_location *loc, | |
4615 | int loc_number, | |
4616 | struct bp_location **last_loc, | |
269b11a2 PA |
4617 | int allflag) |
4618 | { | |
4619 | struct command_line *l; | |
c2c6d25f | 4620 | static char bpenables[] = "nynny"; |
c906108c | 4621 | |
79a45e25 | 4622 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
4623 | int header_of_multiple = 0; |
4624 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4625 | struct value_print_options opts; |
4626 | ||
4627 | get_user_print_options (&opts); | |
0d381245 VP |
4628 | |
4629 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4630 | /* See comment in print_one_breakpoint concerning treatment of |
4631 | breakpoints with single disabled location. */ | |
0d381245 VP |
4632 | if (loc == NULL |
4633 | && (b->loc != NULL | |
4634 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4635 | header_of_multiple = 1; | |
4636 | if (loc == NULL) | |
4637 | loc = b->loc; | |
4638 | ||
c4093a6a JM |
4639 | annotate_record (); |
4640 | ||
4641 | /* 1 */ | |
4642 | annotate_field (0); | |
0d381245 VP |
4643 | if (part_of_multiple) |
4644 | { | |
4645 | char *formatted; | |
0c6773c1 | 4646 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4647 | ui_out_field_string (uiout, "number", formatted); |
4648 | xfree (formatted); | |
4649 | } | |
4650 | else | |
4651 | { | |
4652 | ui_out_field_int (uiout, "number", b->number); | |
4653 | } | |
c4093a6a JM |
4654 | |
4655 | /* 2 */ | |
4656 | annotate_field (1); | |
0d381245 VP |
4657 | if (part_of_multiple) |
4658 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4659 | else |
4660 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4661 | |
4662 | /* 3 */ | |
4663 | annotate_field (2); | |
0d381245 VP |
4664 | if (part_of_multiple) |
4665 | ui_out_field_skip (uiout, "disp"); | |
4666 | else | |
2cec12e5 | 4667 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4668 | |
c4093a6a JM |
4669 | |
4670 | /* 4 */ | |
4671 | annotate_field (3); | |
0d381245 | 4672 | if (part_of_multiple) |
54e52265 | 4673 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4674 | else |
4a64f543 MS |
4675 | ui_out_field_fmt (uiout, "enabled", "%c", |
4676 | bpenables[(int) b->enable_state]); | |
54e52265 | 4677 | ui_out_spaces (uiout, 2); |
0d381245 | 4678 | |
c4093a6a JM |
4679 | |
4680 | /* 5 and 6 */ | |
3086aeae | 4681 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4682 | { |
4a64f543 MS |
4683 | /* Although the print_one can possibly print all locations, |
4684 | calling it here is not likely to get any nice result. So, | |
4685 | make sure there's just one location. */ | |
0d381245 | 4686 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4687 | b->ops->print_one (b, last_loc); |
0d381245 | 4688 | } |
3086aeae DJ |
4689 | else |
4690 | switch (b->type) | |
4691 | { | |
4692 | case bp_none: | |
4693 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4694 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4695 | break; |
c906108c | 4696 | |
3086aeae DJ |
4697 | case bp_watchpoint: |
4698 | case bp_hardware_watchpoint: | |
4699 | case bp_read_watchpoint: | |
4700 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4701 | { |
4702 | struct watchpoint *w = (struct watchpoint *) b; | |
4703 | ||
4704 | /* Field 4, the address, is omitted (which makes the columns | |
4705 | not line up too nicely with the headers, but the effect | |
4706 | is relatively readable). */ | |
4707 | if (opts.addressprint) | |
4708 | ui_out_field_skip (uiout, "addr"); | |
4709 | annotate_field (5); | |
4710 | ui_out_field_string (uiout, "what", w->exp_string); | |
4711 | } | |
3086aeae DJ |
4712 | break; |
4713 | ||
3086aeae DJ |
4714 | case bp_breakpoint: |
4715 | case bp_hardware_breakpoint: | |
4716 | case bp_until: | |
4717 | case bp_finish: | |
4718 | case bp_longjmp: | |
4719 | case bp_longjmp_resume: | |
186c406b TT |
4720 | case bp_exception: |
4721 | case bp_exception_resume: | |
3086aeae | 4722 | case bp_step_resume: |
2c03e5be | 4723 | case bp_hp_step_resume: |
3086aeae DJ |
4724 | case bp_watchpoint_scope: |
4725 | case bp_call_dummy: | |
aa7d318d | 4726 | case bp_std_terminate: |
3086aeae DJ |
4727 | case bp_shlib_event: |
4728 | case bp_thread_event: | |
4729 | case bp_overlay_event: | |
0fd8e87f | 4730 | case bp_longjmp_master: |
aa7d318d | 4731 | case bp_std_terminate_master: |
186c406b | 4732 | case bp_exception_master: |
1042e4c0 | 4733 | case bp_tracepoint: |
7a697b8d | 4734 | case bp_fast_tracepoint: |
0fb4aa4b | 4735 | case bp_static_tracepoint: |
4efc6507 | 4736 | case bp_jit_event: |
0e30163f JK |
4737 | case bp_gnu_ifunc_resolver: |
4738 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 4739 | if (opts.addressprint) |
3086aeae DJ |
4740 | { |
4741 | annotate_field (4); | |
54e52265 | 4742 | if (header_of_multiple) |
0d381245 | 4743 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4744 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4745 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4746 | else |
5af949e3 UW |
4747 | ui_out_field_core_addr (uiout, "addr", |
4748 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4749 | } |
4750 | annotate_field (5); | |
0d381245 | 4751 | if (!header_of_multiple) |
170b53b2 | 4752 | print_breakpoint_location (b, loc); |
0d381245 | 4753 | if (b->loc) |
a6d9a66e | 4754 | *last_loc = b->loc; |
3086aeae DJ |
4755 | break; |
4756 | } | |
c906108c | 4757 | |
6c95b8df PA |
4758 | |
4759 | /* For backward compatibility, don't display inferiors unless there | |
4760 | are several. */ | |
4761 | if (loc != NULL | |
4762 | && !header_of_multiple | |
4763 | && (allflag | |
4764 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4765 | && (number_of_program_spaces () > 1 | |
4766 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4767 | /* LOC is for existing B, it cannot be in |
4768 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4769 | && loc->owner->type != bp_catchpoint))) |
4770 | { | |
4771 | struct inferior *inf; | |
4772 | int first = 1; | |
4773 | ||
4774 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4775 | { | |
4776 | if (inf->pspace == loc->pspace) | |
4777 | { | |
4778 | if (first) | |
4779 | { | |
4780 | first = 0; | |
4781 | ui_out_text (uiout, " inf "); | |
4782 | } | |
4783 | else | |
4784 | ui_out_text (uiout, ", "); | |
4785 | ui_out_text (uiout, plongest (inf->num)); | |
4786 | } | |
4787 | } | |
4788 | } | |
4789 | ||
4a306c9a | 4790 | if (!part_of_multiple) |
c4093a6a | 4791 | { |
4a306c9a JB |
4792 | if (b->thread != -1) |
4793 | { | |
4794 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4795 | "stop only in" line a little further down. */ |
4a306c9a JB |
4796 | ui_out_text (uiout, " thread "); |
4797 | ui_out_field_int (uiout, "thread", b->thread); | |
4798 | } | |
4799 | else if (b->task != 0) | |
4800 | { | |
4801 | ui_out_text (uiout, " task "); | |
4802 | ui_out_field_int (uiout, "task", b->task); | |
4803 | } | |
c4093a6a | 4804 | } |
f1310107 | 4805 | |
8b93c638 | 4806 | ui_out_text (uiout, "\n"); |
f1310107 | 4807 | |
348d480f | 4808 | if (!part_of_multiple) |
f1310107 TJB |
4809 | b->ops->print_one_detail (b, uiout); |
4810 | ||
0d381245 | 4811 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4812 | { |
4813 | annotate_field (6); | |
8b93c638 | 4814 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 4815 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 4816 | the frame ID. */ |
5af949e3 UW |
4817 | ui_out_field_core_addr (uiout, "frame", |
4818 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4819 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4820 | } |
4821 | ||
28010a5d | 4822 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
4823 | { |
4824 | annotate_field (7); | |
d77f58be | 4825 | if (is_tracepoint (b)) |
1042e4c0 SS |
4826 | ui_out_text (uiout, "\ttrace only if "); |
4827 | else | |
4828 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4829 | ui_out_field_string (uiout, "cond", b->cond_string); |
4830 | ui_out_text (uiout, "\n"); | |
4831 | } | |
4832 | ||
0d381245 | 4833 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 4834 | { |
4a64f543 | 4835 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4836 | ui_out_text (uiout, "\tstop only in thread "); |
4837 | ui_out_field_int (uiout, "thread", b->thread); | |
4838 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4839 | } |
4840 | ||
63c715c6 | 4841 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 4842 | { |
4a64f543 | 4843 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4844 | if (ep_is_catchpoint (b)) |
4845 | ui_out_text (uiout, "\tcatchpoint"); | |
4846 | else | |
4847 | ui_out_text (uiout, "\tbreakpoint"); | |
4848 | ui_out_text (uiout, " already hit "); | |
4849 | ui_out_field_int (uiout, "times", b->hit_count); | |
4850 | if (b->hit_count == 1) | |
4851 | ui_out_text (uiout, " time\n"); | |
4852 | else | |
4853 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4854 | } |
4855 | ||
4a64f543 MS |
4856 | /* Output the count also if it is zero, but only if this is mi. |
4857 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4858 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4859 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4860 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4861 | |
0d381245 | 4862 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4863 | { |
4864 | annotate_field (8); | |
8b93c638 JM |
4865 | ui_out_text (uiout, "\tignore next "); |
4866 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4867 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4868 | } |
059fb39f | 4869 | |
9add0f1b | 4870 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4871 | if (!part_of_multiple && l) |
c4093a6a | 4872 | { |
3b31d625 EZ |
4873 | struct cleanup *script_chain; |
4874 | ||
c4093a6a | 4875 | annotate_field (9); |
3b31d625 | 4876 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4877 | print_command_lines (uiout, l, 4); |
3b31d625 | 4878 | do_cleanups (script_chain); |
c4093a6a | 4879 | } |
d24317b4 | 4880 | |
d9b3f62e | 4881 | if (is_tracepoint (b)) |
1042e4c0 | 4882 | { |
d9b3f62e PA |
4883 | struct tracepoint *t = (struct tracepoint *) b; |
4884 | ||
4885 | if (!part_of_multiple && t->pass_count) | |
4886 | { | |
4887 | annotate_field (10); | |
4888 | ui_out_text (uiout, "\tpass count "); | |
4889 | ui_out_field_int (uiout, "pass", t->pass_count); | |
4890 | ui_out_text (uiout, " \n"); | |
4891 | } | |
1042e4c0 SS |
4892 | } |
4893 | ||
d24317b4 VP |
4894 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4895 | { | |
3a5c3e22 PA |
4896 | if (is_watchpoint (b)) |
4897 | { | |
4898 | struct watchpoint *w = (struct watchpoint *) b; | |
4899 | ||
4900 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
4901 | } | |
4902 | else if (b->addr_string) | |
d24317b4 | 4903 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 4904 | } |
c4093a6a | 4905 | } |
c5aa993b | 4906 | |
0d381245 VP |
4907 | static void |
4908 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 4909 | struct bp_location **last_loc, |
6c95b8df | 4910 | int allflag) |
0d381245 | 4911 | { |
8d3788bd | 4912 | struct cleanup *bkpt_chain; |
79a45e25 | 4913 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
4914 | |
4915 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
4916 | ||
12c5a436 | 4917 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 4918 | do_cleanups (bkpt_chain); |
0d381245 VP |
4919 | |
4920 | /* If this breakpoint has custom print function, | |
4921 | it's already printed. Otherwise, print individual | |
4922 | locations, if any. */ | |
4923 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4924 | { | |
4a64f543 MS |
4925 | /* If breakpoint has a single location that is disabled, we |
4926 | print it as if it had several locations, since otherwise it's | |
4927 | hard to represent "breakpoint enabled, location disabled" | |
4928 | situation. | |
4929 | ||
4930 | Note that while hardware watchpoints have several locations | |
a3be7890 | 4931 | internally, that's not a property exposed to user. */ |
0d381245 | 4932 | if (b->loc |
a5606eee | 4933 | && !is_hardware_watchpoint (b) |
8d3788bd | 4934 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
4935 | { |
4936 | struct bp_location *loc; | |
4937 | int n = 1; | |
8d3788bd | 4938 | |
0d381245 | 4939 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
4940 | { |
4941 | struct cleanup *inner2 = | |
4942 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
4943 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
4944 | do_cleanups (inner2); | |
4945 | } | |
0d381245 VP |
4946 | } |
4947 | } | |
4948 | } | |
4949 | ||
a6d9a66e UW |
4950 | static int |
4951 | breakpoint_address_bits (struct breakpoint *b) | |
4952 | { | |
4953 | int print_address_bits = 0; | |
4954 | struct bp_location *loc; | |
4955 | ||
4956 | for (loc = b->loc; loc; loc = loc->next) | |
4957 | { | |
c7437ca6 PA |
4958 | int addr_bit; |
4959 | ||
4960 | /* Software watchpoints that aren't watching memory don't have | |
4961 | an address to print. */ | |
4962 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
4963 | continue; | |
4964 | ||
4965 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
4966 | if (addr_bit > print_address_bits) |
4967 | print_address_bits = addr_bit; | |
4968 | } | |
4969 | ||
4970 | return print_address_bits; | |
4971 | } | |
0d381245 | 4972 | |
c4093a6a JM |
4973 | struct captured_breakpoint_query_args |
4974 | { | |
4975 | int bnum; | |
4976 | }; | |
c5aa993b | 4977 | |
c4093a6a | 4978 | static int |
2b65245e | 4979 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4980 | { |
4981 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4982 | struct breakpoint *b; |
a6d9a66e | 4983 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 4984 | |
c4093a6a JM |
4985 | ALL_BREAKPOINTS (b) |
4986 | { | |
4987 | if (args->bnum == b->number) | |
c5aa993b | 4988 | { |
12c5a436 | 4989 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 4990 | return GDB_RC_OK; |
c5aa993b | 4991 | } |
c4093a6a JM |
4992 | } |
4993 | return GDB_RC_NONE; | |
4994 | } | |
c5aa993b | 4995 | |
c4093a6a | 4996 | enum gdb_rc |
4a64f543 MS |
4997 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
4998 | char **error_message) | |
c4093a6a JM |
4999 | { |
5000 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5001 | |
c4093a6a JM |
5002 | args.bnum = bnum; |
5003 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5004 | an error. */ |
b0b13bb4 DJ |
5005 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5006 | error_message, RETURN_MASK_ALL) < 0) | |
5007 | return GDB_RC_FAIL; | |
5008 | else | |
5009 | return GDB_RC_OK; | |
c4093a6a | 5010 | } |
c5aa993b | 5011 | |
09d682a4 TT |
5012 | /* Return true if this breakpoint was set by the user, false if it is |
5013 | internal or momentary. */ | |
5014 | ||
5015 | int | |
5016 | user_breakpoint_p (struct breakpoint *b) | |
5017 | { | |
46c6471b | 5018 | return b->number > 0; |
09d682a4 TT |
5019 | } |
5020 | ||
7f3b0473 | 5021 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5022 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5023 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5024 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5025 | ones for which it returns non-zero. Return the total number of | |
5026 | breakpoints listed. */ | |
c906108c | 5027 | |
d77f58be | 5028 | static int |
e5a67952 | 5029 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5030 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5031 | { |
52f0bd74 | 5032 | struct breakpoint *b; |
a6d9a66e | 5033 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5034 | int nr_printable_breakpoints; |
3b31d625 | 5035 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5036 | struct value_print_options opts; |
a6d9a66e | 5037 | int print_address_bits = 0; |
269b11a2 | 5038 | int print_type_col_width = 14; |
79a45e25 | 5039 | struct ui_out *uiout = current_uiout; |
269b11a2 | 5040 | |
79a45b7d TT |
5041 | get_user_print_options (&opts); |
5042 | ||
4a64f543 MS |
5043 | /* Compute the number of rows in the table, as well as the size |
5044 | required for address fields. */ | |
7f3b0473 AC |
5045 | nr_printable_breakpoints = 0; |
5046 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5047 | { |
5048 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5049 | if (filter && !filter (b)) | |
5050 | continue; | |
5051 | ||
5052 | /* If we have an "args" string, it is a list of breakpoints to | |
5053 | accept. Skip the others. */ | |
5054 | if (args != NULL && *args != '\0') | |
5055 | { | |
5056 | if (allflag && parse_and_eval_long (args) != b->number) | |
5057 | continue; | |
5058 | if (!allflag && !number_is_in_list (args, b->number)) | |
5059 | continue; | |
5060 | } | |
269b11a2 | 5061 | |
e5a67952 MS |
5062 | if (allflag || user_breakpoint_p (b)) |
5063 | { | |
5064 | int addr_bit, type_len; | |
a6d9a66e | 5065 | |
e5a67952 MS |
5066 | addr_bit = breakpoint_address_bits (b); |
5067 | if (addr_bit > print_address_bits) | |
5068 | print_address_bits = addr_bit; | |
269b11a2 | 5069 | |
e5a67952 MS |
5070 | type_len = strlen (bptype_string (b->type)); |
5071 | if (type_len > print_type_col_width) | |
5072 | print_type_col_width = type_len; | |
5073 | ||
5074 | nr_printable_breakpoints++; | |
5075 | } | |
5076 | } | |
7f3b0473 | 5077 | |
79a45b7d | 5078 | if (opts.addressprint) |
3b31d625 | 5079 | bkpttbl_chain |
3e43a32a MS |
5080 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5081 | nr_printable_breakpoints, | |
3b31d625 | 5082 | "BreakpointTable"); |
8b93c638 | 5083 | else |
3b31d625 | 5084 | bkpttbl_chain |
3e43a32a MS |
5085 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5086 | nr_printable_breakpoints, | |
3b31d625 | 5087 | "BreakpointTable"); |
8b93c638 | 5088 | |
7f3b0473 | 5089 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5090 | annotate_breakpoints_headers (); |
5091 | if (nr_printable_breakpoints > 0) | |
5092 | annotate_field (0); | |
4a64f543 | 5093 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5094 | if (nr_printable_breakpoints > 0) |
5095 | annotate_field (1); | |
269b11a2 | 5096 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5097 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5098 | if (nr_printable_breakpoints > 0) |
5099 | annotate_field (2); | |
4a64f543 | 5100 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5101 | if (nr_printable_breakpoints > 0) |
5102 | annotate_field (3); | |
54e52265 | 5103 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5104 | if (opts.addressprint) |
e5a67952 MS |
5105 | { |
5106 | if (nr_printable_breakpoints > 0) | |
5107 | annotate_field (4); | |
5108 | if (print_address_bits <= 32) | |
5109 | ui_out_table_header (uiout, 10, ui_left, | |
5110 | "addr", "Address"); /* 5 */ | |
5111 | else | |
5112 | ui_out_table_header (uiout, 18, ui_left, | |
5113 | "addr", "Address"); /* 5 */ | |
5114 | } | |
d7faa9e7 AC |
5115 | if (nr_printable_breakpoints > 0) |
5116 | annotate_field (5); | |
5117 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5118 | ui_out_table_body (uiout); | |
5119 | if (nr_printable_breakpoints > 0) | |
5120 | annotate_breakpoints_table (); | |
7f3b0473 | 5121 | |
c4093a6a | 5122 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5123 | { |
5124 | QUIT; | |
5125 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5126 | if (filter && !filter (b)) | |
5127 | continue; | |
5128 | ||
5129 | /* If we have an "args" string, it is a list of breakpoints to | |
5130 | accept. Skip the others. */ | |
5131 | ||
5132 | if (args != NULL && *args != '\0') | |
5133 | { | |
5134 | if (allflag) /* maintenance info breakpoint */ | |
5135 | { | |
5136 | if (parse_and_eval_long (args) != b->number) | |
5137 | continue; | |
5138 | } | |
5139 | else /* all others */ | |
5140 | { | |
5141 | if (!number_is_in_list (args, b->number)) | |
5142 | continue; | |
5143 | } | |
5144 | } | |
5145 | /* We only print out user settable breakpoints unless the | |
5146 | allflag is set. */ | |
5147 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5148 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5149 | } |
5150 | ||
3b31d625 | 5151 | do_cleanups (bkpttbl_chain); |
698384cd | 5152 | |
7f3b0473 | 5153 | if (nr_printable_breakpoints == 0) |
c906108c | 5154 | { |
4a64f543 MS |
5155 | /* If there's a filter, let the caller decide how to report |
5156 | empty list. */ | |
d77f58be SS |
5157 | if (!filter) |
5158 | { | |
e5a67952 | 5159 | if (args == NULL || *args == '\0') |
d77f58be SS |
5160 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5161 | else | |
4a64f543 | 5162 | ui_out_message (uiout, 0, |
e5a67952 MS |
5163 | "No breakpoint or watchpoint matching '%s'.\n", |
5164 | args); | |
d77f58be | 5165 | } |
c906108c SS |
5166 | } |
5167 | else | |
c4093a6a | 5168 | { |
a6d9a66e UW |
5169 | if (last_loc && !server_command) |
5170 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5171 | } |
c906108c | 5172 | |
4a64f543 | 5173 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5174 | there have been breakpoints? */ |
c906108c | 5175 | annotate_breakpoints_table_end (); |
d77f58be SS |
5176 | |
5177 | return nr_printable_breakpoints; | |
c906108c SS |
5178 | } |
5179 | ||
ad443146 SS |
5180 | /* Display the value of default-collect in a way that is generally |
5181 | compatible with the breakpoint list. */ | |
5182 | ||
5183 | static void | |
5184 | default_collect_info (void) | |
5185 | { | |
79a45e25 PA |
5186 | struct ui_out *uiout = current_uiout; |
5187 | ||
ad443146 SS |
5188 | /* If it has no value (which is frequently the case), say nothing; a |
5189 | message like "No default-collect." gets in user's face when it's | |
5190 | not wanted. */ | |
5191 | if (!*default_collect) | |
5192 | return; | |
5193 | ||
5194 | /* The following phrase lines up nicely with per-tracepoint collect | |
5195 | actions. */ | |
5196 | ui_out_text (uiout, "default collect "); | |
5197 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5198 | ui_out_text (uiout, " \n"); | |
5199 | } | |
5200 | ||
c906108c | 5201 | static void |
e5a67952 | 5202 | breakpoints_info (char *args, int from_tty) |
c906108c | 5203 | { |
e5a67952 | 5204 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5205 | |
5206 | default_collect_info (); | |
d77f58be SS |
5207 | } |
5208 | ||
5209 | static void | |
e5a67952 | 5210 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5211 | { |
e5a67952 | 5212 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 5213 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
5214 | |
5215 | if (num_printed == 0) | |
5216 | { | |
e5a67952 | 5217 | if (args == NULL || *args == '\0') |
d77f58be SS |
5218 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5219 | else | |
e5a67952 | 5220 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5221 | } |
c906108c SS |
5222 | } |
5223 | ||
7a292a7a | 5224 | static void |
e5a67952 | 5225 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5226 | { |
e5a67952 | 5227 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5228 | |
5229 | default_collect_info (); | |
c906108c SS |
5230 | } |
5231 | ||
0d381245 | 5232 | static int |
714835d5 | 5233 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5234 | struct program_space *pspace, |
714835d5 | 5235 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5236 | { |
5237 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5238 | |
0d381245 VP |
5239 | for (; bl; bl = bl->next) |
5240 | { | |
6c95b8df PA |
5241 | if (bl->pspace == pspace |
5242 | && bl->address == pc | |
0d381245 VP |
5243 | && (!overlay_debugging || bl->section == section)) |
5244 | return 1; | |
5245 | } | |
5246 | return 0; | |
5247 | } | |
5248 | ||
6c95b8df PA |
5249 | /* Print a message describing any breakpoints set at PC. This |
5250 | concerns with logical breakpoints, so we match program spaces, not | |
5251 | address spaces. */ | |
c906108c SS |
5252 | |
5253 | static void | |
6c95b8df PA |
5254 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5255 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5256 | struct obj_section *section, int thread) |
c906108c | 5257 | { |
52f0bd74 AC |
5258 | int others = 0; |
5259 | struct breakpoint *b; | |
c906108c SS |
5260 | |
5261 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5262 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5263 | if (others > 0) |
5264 | { | |
a3f17187 AC |
5265 | if (others == 1) |
5266 | printf_filtered (_("Note: breakpoint ")); | |
5267 | else /* if (others == ???) */ | |
5268 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5269 | ALL_BREAKPOINTS (b) |
6c95b8df | 5270 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5271 | { |
5272 | others--; | |
5273 | printf_filtered ("%d", b->number); | |
5274 | if (b->thread == -1 && thread != -1) | |
5275 | printf_filtered (" (all threads)"); | |
5276 | else if (b->thread != -1) | |
5277 | printf_filtered (" (thread %d)", b->thread); | |
5278 | printf_filtered ("%s%s ", | |
059fb39f | 5279 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5280 | || b->enable_state == bp_call_disabled |
5281 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5282 | ? " (disabled)" |
5283 | : b->enable_state == bp_permanent | |
5284 | ? " (permanent)" | |
5285 | : ""), | |
5286 | (others > 1) ? "," | |
5287 | : ((others == 1) ? " and" : "")); | |
5288 | } | |
a3f17187 | 5289 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5290 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5291 | printf_filtered (".\n"); |
5292 | } | |
5293 | } | |
5294 | \f | |
5295 | /* Set the default place to put a breakpoint | |
5296 | for the `break' command with no arguments. */ | |
5297 | ||
5298 | void | |
6c95b8df PA |
5299 | set_default_breakpoint (int valid, struct program_space *pspace, |
5300 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5301 | int line) |
c906108c SS |
5302 | { |
5303 | default_breakpoint_valid = valid; | |
6c95b8df | 5304 | default_breakpoint_pspace = pspace; |
c906108c SS |
5305 | default_breakpoint_address = addr; |
5306 | default_breakpoint_symtab = symtab; | |
5307 | default_breakpoint_line = line; | |
5308 | } | |
5309 | ||
e4f237da KB |
5310 | /* Return true iff it is meaningful to use the address member of |
5311 | BPT. For some breakpoint types, the address member is irrelevant | |
5312 | and it makes no sense to attempt to compare it to other addresses | |
5313 | (or use it for any other purpose either). | |
5314 | ||
4a64f543 MS |
5315 | More specifically, each of the following breakpoint types will |
5316 | always have a zero valued address and we don't want to mark | |
5317 | breakpoints of any of these types to be a duplicate of an actual | |
5318 | breakpoint at address zero: | |
e4f237da KB |
5319 | |
5320 | bp_watchpoint | |
2d134ed3 PA |
5321 | bp_catchpoint |
5322 | ||
5323 | */ | |
e4f237da KB |
5324 | |
5325 | static int | |
5326 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5327 | { | |
5328 | enum bptype type = bpt->type; | |
5329 | ||
2d134ed3 PA |
5330 | return (type != bp_watchpoint && type != bp_catchpoint); |
5331 | } | |
5332 | ||
5333 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5334 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5335 | ||
5336 | static int | |
4a64f543 MS |
5337 | watchpoint_locations_match (struct bp_location *loc1, |
5338 | struct bp_location *loc2) | |
2d134ed3 | 5339 | { |
3a5c3e22 PA |
5340 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
5341 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
5342 | ||
5343 | /* Both of them must exist. */ | |
5344 | gdb_assert (w1 != NULL); | |
5345 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 5346 | |
4a64f543 MS |
5347 | /* If the target can evaluate the condition expression in hardware, |
5348 | then we we need to insert both watchpoints even if they are at | |
5349 | the same place. Otherwise the watchpoint will only trigger when | |
5350 | the condition of whichever watchpoint was inserted evaluates to | |
5351 | true, not giving a chance for GDB to check the condition of the | |
5352 | other watchpoint. */ | |
3a5c3e22 | 5353 | if ((w1->cond_exp |
4a64f543 MS |
5354 | && target_can_accel_watchpoint_condition (loc1->address, |
5355 | loc1->length, | |
0cf6dd15 | 5356 | loc1->watchpoint_type, |
3a5c3e22 PA |
5357 | w1->cond_exp)) |
5358 | || (w2->cond_exp | |
4a64f543 MS |
5359 | && target_can_accel_watchpoint_condition (loc2->address, |
5360 | loc2->length, | |
0cf6dd15 | 5361 | loc2->watchpoint_type, |
3a5c3e22 | 5362 | w2->cond_exp))) |
0cf6dd15 TJB |
5363 | return 0; |
5364 | ||
85d721b8 PA |
5365 | /* Note that this checks the owner's type, not the location's. In |
5366 | case the target does not support read watchpoints, but does | |
5367 | support access watchpoints, we'll have bp_read_watchpoint | |
5368 | watchpoints with hw_access locations. Those should be considered | |
5369 | duplicates of hw_read locations. The hw_read locations will | |
5370 | become hw_access locations later. */ | |
2d134ed3 PA |
5371 | return (loc1->owner->type == loc2->owner->type |
5372 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5373 | && loc1->address == loc2->address | |
5374 | && loc1->length == loc2->length); | |
e4f237da KB |
5375 | } |
5376 | ||
6c95b8df PA |
5377 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5378 | same breakpoint location. In most targets, this can only be true | |
5379 | if ASPACE1 matches ASPACE2. On targets that have global | |
5380 | breakpoints, the address space doesn't really matter. */ | |
5381 | ||
5382 | static int | |
5383 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5384 | struct address_space *aspace2, CORE_ADDR addr2) | |
5385 | { | |
5386 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5387 | || aspace1 == aspace2) | |
5388 | && addr1 == addr2); | |
5389 | } | |
5390 | ||
f1310107 TJB |
5391 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
5392 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
5393 | matches ASPACE2. On targets that have global breakpoints, the address | |
5394 | space doesn't really matter. */ | |
5395 | ||
5396 | static int | |
5397 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
5398 | int len1, struct address_space *aspace2, | |
5399 | CORE_ADDR addr2) | |
5400 | { | |
5401 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5402 | || aspace1 == aspace2) | |
5403 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
5404 | } | |
5405 | ||
5406 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
5407 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
5408 | matches the breakpoint's address space. On targets that have global | |
5409 | breakpoints, the address space doesn't really matter. */ | |
5410 | ||
5411 | static int | |
5412 | breakpoint_location_address_match (struct bp_location *bl, | |
5413 | struct address_space *aspace, | |
5414 | CORE_ADDR addr) | |
5415 | { | |
5416 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
5417 | aspace, addr) | |
5418 | || (bl->length | |
5419 | && breakpoint_address_match_range (bl->pspace->aspace, | |
5420 | bl->address, bl->length, | |
5421 | aspace, addr))); | |
5422 | } | |
5423 | ||
2d134ed3 PA |
5424 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5425 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5426 | represent the same location. */ | |
5427 | ||
5428 | static int | |
4a64f543 MS |
5429 | breakpoint_locations_match (struct bp_location *loc1, |
5430 | struct bp_location *loc2) | |
2d134ed3 | 5431 | { |
2bdf28a0 JK |
5432 | int hw_point1, hw_point2; |
5433 | ||
5434 | /* Both of them must not be in moribund_locations. */ | |
5435 | gdb_assert (loc1->owner != NULL); | |
5436 | gdb_assert (loc2->owner != NULL); | |
5437 | ||
5438 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5439 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5440 | |
5441 | if (hw_point1 != hw_point2) | |
5442 | return 0; | |
5443 | else if (hw_point1) | |
5444 | return watchpoint_locations_match (loc1, loc2); | |
5445 | else | |
f1310107 TJB |
5446 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
5447 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5448 | loc2->pspace->aspace, loc2->address) | |
5449 | && loc1->length == loc2->length); | |
2d134ed3 PA |
5450 | } |
5451 | ||
76897487 KB |
5452 | static void |
5453 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5454 | int bnum, int have_bnum) | |
5455 | { | |
f63fbe86 MS |
5456 | /* The longest string possibly returned by hex_string_custom |
5457 | is 50 chars. These must be at least that big for safety. */ | |
5458 | char astr1[64]; | |
5459 | char astr2[64]; | |
76897487 | 5460 | |
bb599908 PH |
5461 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5462 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5463 | if (have_bnum) |
8a3fe4f8 | 5464 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5465 | bnum, astr1, astr2); |
5466 | else | |
8a3fe4f8 | 5467 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5468 | } |
5469 | ||
4a64f543 MS |
5470 | /* Adjust a breakpoint's address to account for architectural |
5471 | constraints on breakpoint placement. Return the adjusted address. | |
5472 | Note: Very few targets require this kind of adjustment. For most | |
5473 | targets, this function is simply the identity function. */ | |
76897487 KB |
5474 | |
5475 | static CORE_ADDR | |
a6d9a66e UW |
5476 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5477 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5478 | { |
a6d9a66e | 5479 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5480 | { |
5481 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5482 | return bpaddr; | |
5483 | } | |
88f7da05 KB |
5484 | else if (bptype == bp_watchpoint |
5485 | || bptype == bp_hardware_watchpoint | |
5486 | || bptype == bp_read_watchpoint | |
5487 | || bptype == bp_access_watchpoint | |
fe798b75 | 5488 | || bptype == bp_catchpoint) |
88f7da05 KB |
5489 | { |
5490 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5491 | have their addresses modified. */ | |
5492 | return bpaddr; | |
5493 | } | |
76897487 KB |
5494 | else |
5495 | { | |
5496 | CORE_ADDR adjusted_bpaddr; | |
5497 | ||
5498 | /* Some targets have architectural constraints on the placement | |
5499 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5500 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5501 | |
5502 | /* An adjusted breakpoint address can significantly alter | |
5503 | a user's expectations. Print a warning if an adjustment | |
5504 | is required. */ | |
5505 | if (adjusted_bpaddr != bpaddr) | |
5506 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5507 | ||
5508 | return adjusted_bpaddr; | |
5509 | } | |
5510 | } | |
5511 | ||
28010a5d PA |
5512 | void |
5513 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
5514 | struct breakpoint *owner) | |
7cc221ef | 5515 | { |
7cc221ef DJ |
5516 | memset (loc, 0, sizeof (*loc)); |
5517 | ||
348d480f PA |
5518 | gdb_assert (ops != NULL); |
5519 | ||
28010a5d PA |
5520 | loc->ops = ops; |
5521 | loc->owner = owner; | |
511a6cd4 | 5522 | loc->cond = NULL; |
0d381245 VP |
5523 | loc->shlib_disabled = 0; |
5524 | loc->enabled = 1; | |
e049a4b5 | 5525 | |
28010a5d | 5526 | switch (owner->type) |
e049a4b5 DJ |
5527 | { |
5528 | case bp_breakpoint: | |
5529 | case bp_until: | |
5530 | case bp_finish: | |
5531 | case bp_longjmp: | |
5532 | case bp_longjmp_resume: | |
186c406b TT |
5533 | case bp_exception: |
5534 | case bp_exception_resume: | |
e049a4b5 | 5535 | case bp_step_resume: |
2c03e5be | 5536 | case bp_hp_step_resume: |
e049a4b5 DJ |
5537 | case bp_watchpoint_scope: |
5538 | case bp_call_dummy: | |
aa7d318d | 5539 | case bp_std_terminate: |
e049a4b5 DJ |
5540 | case bp_shlib_event: |
5541 | case bp_thread_event: | |
5542 | case bp_overlay_event: | |
4efc6507 | 5543 | case bp_jit_event: |
0fd8e87f | 5544 | case bp_longjmp_master: |
aa7d318d | 5545 | case bp_std_terminate_master: |
186c406b | 5546 | case bp_exception_master: |
0e30163f JK |
5547 | case bp_gnu_ifunc_resolver: |
5548 | case bp_gnu_ifunc_resolver_return: | |
e049a4b5 DJ |
5549 | loc->loc_type = bp_loc_software_breakpoint; |
5550 | break; | |
5551 | case bp_hardware_breakpoint: | |
5552 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5553 | break; | |
5554 | case bp_hardware_watchpoint: | |
5555 | case bp_read_watchpoint: | |
5556 | case bp_access_watchpoint: | |
5557 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5558 | break; | |
5559 | case bp_watchpoint: | |
ce78b96d | 5560 | case bp_catchpoint: |
15c3d785 PA |
5561 | case bp_tracepoint: |
5562 | case bp_fast_tracepoint: | |
0fb4aa4b | 5563 | case bp_static_tracepoint: |
e049a4b5 DJ |
5564 | loc->loc_type = bp_loc_other; |
5565 | break; | |
5566 | default: | |
e2e0b3e5 | 5567 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5568 | } |
5569 | ||
f431efe5 | 5570 | loc->refc = 1; |
28010a5d PA |
5571 | } |
5572 | ||
5573 | /* Allocate a struct bp_location. */ | |
5574 | ||
5575 | static struct bp_location * | |
5576 | allocate_bp_location (struct breakpoint *bpt) | |
5577 | { | |
348d480f PA |
5578 | return bpt->ops->allocate_location (bpt); |
5579 | } | |
7cc221ef | 5580 | |
f431efe5 PA |
5581 | static void |
5582 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 5583 | { |
348d480f | 5584 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
5585 | xfree (loc); |
5586 | } | |
5587 | ||
f431efe5 PA |
5588 | /* Increment reference count. */ |
5589 | ||
5590 | static void | |
5591 | incref_bp_location (struct bp_location *bl) | |
5592 | { | |
5593 | ++bl->refc; | |
5594 | } | |
5595 | ||
5596 | /* Decrement reference count. If the reference count reaches 0, | |
5597 | destroy the bp_location. Sets *BLP to NULL. */ | |
5598 | ||
5599 | static void | |
5600 | decref_bp_location (struct bp_location **blp) | |
5601 | { | |
0807b50c PA |
5602 | gdb_assert ((*blp)->refc > 0); |
5603 | ||
f431efe5 PA |
5604 | if (--(*blp)->refc == 0) |
5605 | free_bp_location (*blp); | |
5606 | *blp = NULL; | |
5607 | } | |
5608 | ||
346774a9 | 5609 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 5610 | |
346774a9 PA |
5611 | static void |
5612 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 5613 | { |
346774a9 | 5614 | struct breakpoint *b1; |
c906108c | 5615 | |
346774a9 PA |
5616 | /* Add this breakpoint to the end of the chain so that a list of |
5617 | breakpoints will come out in order of increasing numbers. */ | |
5618 | ||
5619 | b1 = breakpoint_chain; | |
5620 | if (b1 == 0) | |
5621 | breakpoint_chain = b; | |
5622 | else | |
5623 | { | |
5624 | while (b1->next) | |
5625 | b1 = b1->next; | |
5626 | b1->next = b; | |
5627 | } | |
5628 | } | |
5629 | ||
5630 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
5631 | ||
5632 | static void | |
5633 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
5634 | struct gdbarch *gdbarch, | |
28010a5d | 5635 | enum bptype bptype, |
c0a91b2b | 5636 | const struct breakpoint_ops *ops) |
346774a9 | 5637 | { |
c906108c | 5638 | memset (b, 0, sizeof (*b)); |
2219d63c | 5639 | |
348d480f PA |
5640 | gdb_assert (ops != NULL); |
5641 | ||
28010a5d | 5642 | b->ops = ops; |
4d28f7a8 | 5643 | b->type = bptype; |
a6d9a66e | 5644 | b->gdbarch = gdbarch; |
c906108c SS |
5645 | b->language = current_language->la_language; |
5646 | b->input_radix = input_radix; | |
5647 | b->thread = -1; | |
b5de0fa7 | 5648 | b->enable_state = bp_enabled; |
c906108c SS |
5649 | b->next = 0; |
5650 | b->silent = 0; | |
5651 | b->ignore_count = 0; | |
5652 | b->commands = NULL; | |
818dd999 | 5653 | b->frame_id = null_frame_id; |
0d381245 | 5654 | b->condition_not_parsed = 0; |
84f4c1fe | 5655 | b->py_bp_object = NULL; |
d0fb5eae | 5656 | b->related_breakpoint = b; |
346774a9 PA |
5657 | } |
5658 | ||
5659 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
5660 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
5661 | |
5662 | static struct breakpoint * | |
5663 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 5664 | enum bptype bptype, |
c0a91b2b | 5665 | const struct breakpoint_ops *ops) |
346774a9 PA |
5666 | { |
5667 | struct breakpoint *b = XNEW (struct breakpoint); | |
5668 | ||
348d480f | 5669 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 5670 | add_to_breakpoint_chain (b); |
0d381245 VP |
5671 | return b; |
5672 | } | |
5673 | ||
0e30163f JK |
5674 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
5675 | resolutions should be made as the user specified the location explicitly | |
5676 | enough. */ | |
5677 | ||
0d381245 | 5678 | static void |
0e30163f | 5679 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 5680 | { |
2bdf28a0 JK |
5681 | gdb_assert (loc->owner != NULL); |
5682 | ||
0d381245 | 5683 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5684 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5685 | || is_tracepoint (loc->owner)) |
0d381245 | 5686 | { |
0e30163f JK |
5687 | int is_gnu_ifunc; |
5688 | ||
5689 | find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name, | |
5690 | NULL, NULL, &is_gnu_ifunc); | |
5691 | ||
5692 | if (is_gnu_ifunc && !explicit_loc) | |
5693 | { | |
5694 | struct breakpoint *b = loc->owner; | |
5695 | ||
5696 | gdb_assert (loc->pspace == current_program_space); | |
5697 | if (gnu_ifunc_resolve_name (loc->function_name, | |
5698 | &loc->requested_address)) | |
5699 | { | |
5700 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
5701 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
5702 | loc->requested_address, | |
5703 | b->type); | |
5704 | } | |
5705 | else if (b->type == bp_breakpoint && b->loc == loc | |
5706 | && loc->next == NULL && b->related_breakpoint == b) | |
5707 | { | |
5708 | /* Create only the whole new breakpoint of this type but do not | |
5709 | mess more complicated breakpoints with multiple locations. */ | |
5710 | b->type = bp_gnu_ifunc_resolver; | |
5711 | } | |
5712 | } | |
5713 | ||
0d381245 VP |
5714 | if (loc->function_name) |
5715 | loc->function_name = xstrdup (loc->function_name); | |
5716 | } | |
5717 | } | |
5718 | ||
a6d9a66e UW |
5719 | /* Attempt to determine architecture of location identified by SAL. */ |
5720 | static struct gdbarch * | |
5721 | get_sal_arch (struct symtab_and_line sal) | |
5722 | { | |
5723 | if (sal.section) | |
5724 | return get_objfile_arch (sal.section->objfile); | |
5725 | if (sal.symtab) | |
5726 | return get_objfile_arch (sal.symtab->objfile); | |
5727 | ||
5728 | return NULL; | |
5729 | } | |
5730 | ||
346774a9 PA |
5731 | /* Low level routine for partially initializing a breakpoint of type |
5732 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 5733 | file name, and line number are provided by SAL. |
0d381245 VP |
5734 | |
5735 | It is expected that the caller will complete the initialization of | |
5736 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 5737 | information regarding the creation of a new breakpoint. */ |
0d381245 | 5738 | |
346774a9 PA |
5739 | static void |
5740 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 5741 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5742 | const struct breakpoint_ops *ops) |
0d381245 | 5743 | { |
0d381245 | 5744 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5745 | struct gdbarch *loc_gdbarch; |
5746 | ||
28010a5d | 5747 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 5748 | |
a6d9a66e UW |
5749 | loc_gdbarch = get_sal_arch (sal); |
5750 | if (!loc_gdbarch) | |
5751 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5752 | |
6c95b8df PA |
5753 | if (bptype != bp_catchpoint) |
5754 | gdb_assert (sal.pspace != NULL); | |
5755 | ||
0d381245 VP |
5756 | /* Adjust the breakpoint's address prior to allocating a location. |
5757 | Once we call allocate_bp_location(), that mostly uninitialized | |
5758 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5759 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5760 | not want its scan of the location chain to find a breakpoint and |
5761 | location that's only been partially initialized. */ | |
4a64f543 MS |
5762 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
5763 | sal.pc, b->type); | |
0d381245 | 5764 | |
39d61571 | 5765 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5766 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5767 | b->loc->requested_address = sal.pc; |
5768 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5769 | b->loc->pspace = sal.pspace; |
5770 | ||
5771 | /* Store the program space that was used to set the breakpoint, for | |
5772 | breakpoint resetting. */ | |
5773 | b->pspace = sal.pspace; | |
0d381245 VP |
5774 | |
5775 | if (sal.symtab == NULL) | |
5776 | b->source_file = NULL; | |
5777 | else | |
1b36a34b | 5778 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5779 | b->loc->section = sal.section; |
5780 | b->line_number = sal.line; | |
5781 | ||
0e30163f JK |
5782 | set_breakpoint_location_function (b->loc, |
5783 | sal.explicit_pc || sal.explicit_line); | |
c906108c | 5784 | |
c906108c | 5785 | breakpoints_changed (); |
346774a9 | 5786 | } |
c906108c | 5787 | |
346774a9 PA |
5788 | /* set_raw_breakpoint is a low level routine for allocating and |
5789 | partially initializing a breakpoint of type BPTYPE. The newly | |
5790 | created breakpoint's address, section, source file name, and line | |
5791 | number are provided by SAL. The newly created and partially | |
5792 | initialized breakpoint is added to the breakpoint chain and | |
5793 | is also returned as the value of this function. | |
5794 | ||
5795 | It is expected that the caller will complete the initialization of | |
5796 | the newly created breakpoint struct as well as output any status | |
5797 | information regarding the creation of a new breakpoint. In | |
5798 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5799 | number! Care should be taken to not allow an error to occur | |
5800 | prior to completing the initialization of the breakpoint. If this | |
5801 | should happen, a bogus breakpoint will be left on the chain. */ | |
5802 | ||
5803 | struct breakpoint * | |
5804 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 5805 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5806 | const struct breakpoint_ops *ops) |
346774a9 PA |
5807 | { |
5808 | struct breakpoint *b = XNEW (struct breakpoint); | |
5809 | ||
348d480f | 5810 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 5811 | add_to_breakpoint_chain (b); |
c906108c SS |
5812 | return b; |
5813 | } | |
5814 | ||
c2c6d25f JM |
5815 | |
5816 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5817 | instruction, hard-wired into the inferior's code. */ | |
5818 | void | |
5819 | make_breakpoint_permanent (struct breakpoint *b) | |
5820 | { | |
0d381245 | 5821 | struct bp_location *bl; |
cc59ec59 | 5822 | |
b5de0fa7 | 5823 | b->enable_state = bp_permanent; |
c2c6d25f | 5824 | |
4a64f543 MS |
5825 | /* By definition, permanent breakpoints are already present in the |
5826 | code. Mark all locations as inserted. For now, | |
5827 | make_breakpoint_permanent is called in just one place, so it's | |
5828 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 5829 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
5830 | for (bl = b->loc; bl; bl = bl->next) |
5831 | bl->inserted = 1; | |
c2c6d25f JM |
5832 | } |
5833 | ||
53a5351d | 5834 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5835 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5836 | initiated the operation. */ | |
c906108c SS |
5837 | |
5838 | void | |
186c406b | 5839 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5840 | { |
35df4500 | 5841 | struct breakpoint *b, *b_tmp; |
186c406b | 5842 | int thread = tp->num; |
0fd8e87f UW |
5843 | |
5844 | /* To avoid having to rescan all objfile symbols at every step, | |
5845 | we maintain a list of continually-inserted but always disabled | |
5846 | longjmp "master" breakpoints. Here, we simply create momentary | |
5847 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5848 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5849 | if (b->pspace == current_program_space |
186c406b TT |
5850 | && (b->type == bp_longjmp_master |
5851 | || b->type == bp_exception_master)) | |
0fd8e87f | 5852 | { |
06edf0c0 PA |
5853 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
5854 | struct breakpoint *clone; | |
cc59ec59 | 5855 | |
06edf0c0 PA |
5856 | clone = momentary_breakpoint_from_master (b, type, |
5857 | &momentary_breakpoint_ops); | |
0fd8e87f UW |
5858 | clone->thread = thread; |
5859 | } | |
186c406b TT |
5860 | |
5861 | tp->initiating_frame = frame; | |
c906108c SS |
5862 | } |
5863 | ||
611c83ae | 5864 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5865 | void |
611c83ae | 5866 | delete_longjmp_breakpoint (int thread) |
c906108c | 5867 | { |
35df4500 | 5868 | struct breakpoint *b, *b_tmp; |
c906108c | 5869 | |
35df4500 | 5870 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 5871 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
5872 | { |
5873 | if (b->thread == thread) | |
5874 | delete_breakpoint (b); | |
5875 | } | |
c906108c SS |
5876 | } |
5877 | ||
1900040c MS |
5878 | void |
5879 | enable_overlay_breakpoints (void) | |
5880 | { | |
52f0bd74 | 5881 | struct breakpoint *b; |
1900040c MS |
5882 | |
5883 | ALL_BREAKPOINTS (b) | |
5884 | if (b->type == bp_overlay_event) | |
5885 | { | |
5886 | b->enable_state = bp_enabled; | |
b60e7edf | 5887 | update_global_location_list (1); |
c02f5703 | 5888 | overlay_events_enabled = 1; |
1900040c MS |
5889 | } |
5890 | } | |
5891 | ||
5892 | void | |
5893 | disable_overlay_breakpoints (void) | |
5894 | { | |
52f0bd74 | 5895 | struct breakpoint *b; |
1900040c MS |
5896 | |
5897 | ALL_BREAKPOINTS (b) | |
5898 | if (b->type == bp_overlay_event) | |
5899 | { | |
5900 | b->enable_state = bp_disabled; | |
b60e7edf | 5901 | update_global_location_list (0); |
c02f5703 | 5902 | overlay_events_enabled = 0; |
1900040c MS |
5903 | } |
5904 | } | |
5905 | ||
aa7d318d TT |
5906 | /* Set an active std::terminate breakpoint for each std::terminate |
5907 | master breakpoint. */ | |
5908 | void | |
5909 | set_std_terminate_breakpoint (void) | |
5910 | { | |
35df4500 | 5911 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5912 | |
35df4500 | 5913 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5914 | if (b->pspace == current_program_space |
5915 | && b->type == bp_std_terminate_master) | |
5916 | { | |
06edf0c0 PA |
5917 | momentary_breakpoint_from_master (b, bp_std_terminate, |
5918 | &momentary_breakpoint_ops); | |
aa7d318d TT |
5919 | } |
5920 | } | |
5921 | ||
5922 | /* Delete all the std::terminate breakpoints. */ | |
5923 | void | |
5924 | delete_std_terminate_breakpoint (void) | |
5925 | { | |
35df4500 | 5926 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5927 | |
35df4500 | 5928 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5929 | if (b->type == bp_std_terminate) |
5930 | delete_breakpoint (b); | |
5931 | } | |
5932 | ||
c4093a6a | 5933 | struct breakpoint * |
a6d9a66e | 5934 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5935 | { |
5936 | struct breakpoint *b; | |
c4093a6a | 5937 | |
06edf0c0 PA |
5938 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
5939 | &internal_breakpoint_ops); | |
5940 | ||
b5de0fa7 | 5941 | b->enable_state = bp_enabled; |
c4093a6a | 5942 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5943 | b->addr_string |
5944 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5945 | |
b60e7edf | 5946 | update_global_location_list_nothrow (1); |
74960c60 | 5947 | |
c4093a6a JM |
5948 | return b; |
5949 | } | |
5950 | ||
5951 | void | |
5952 | remove_thread_event_breakpoints (void) | |
5953 | { | |
35df4500 | 5954 | struct breakpoint *b, *b_tmp; |
c4093a6a | 5955 | |
35df4500 | 5956 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5957 | if (b->type == bp_thread_event |
5958 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5959 | delete_breakpoint (b); |
5960 | } | |
5961 | ||
0101ce28 JJ |
5962 | struct lang_and_radix |
5963 | { | |
5964 | enum language lang; | |
5965 | int radix; | |
5966 | }; | |
5967 | ||
4efc6507 DE |
5968 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5969 | ||
5970 | struct breakpoint * | |
5971 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5972 | { | |
5973 | struct breakpoint *b; | |
5974 | ||
06edf0c0 PA |
5975 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
5976 | &internal_breakpoint_ops); | |
4efc6507 DE |
5977 | update_global_location_list_nothrow (1); |
5978 | return b; | |
5979 | } | |
0101ce28 | 5980 | |
03673fc7 PP |
5981 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
5982 | ||
5983 | void | |
5984 | remove_jit_event_breakpoints (void) | |
5985 | { | |
5986 | struct breakpoint *b, *b_tmp; | |
5987 | ||
5988 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5989 | if (b->type == bp_jit_event | |
5990 | && b->loc->pspace == current_program_space) | |
5991 | delete_breakpoint (b); | |
5992 | } | |
5993 | ||
cae688ec JJ |
5994 | void |
5995 | remove_solib_event_breakpoints (void) | |
5996 | { | |
35df4500 | 5997 | struct breakpoint *b, *b_tmp; |
cae688ec | 5998 | |
35df4500 | 5999 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6000 | if (b->type == bp_shlib_event |
6001 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6002 | delete_breakpoint (b); |
6003 | } | |
6004 | ||
6005 | struct breakpoint * | |
a6d9a66e | 6006 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6007 | { |
6008 | struct breakpoint *b; | |
6009 | ||
06edf0c0 PA |
6010 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
6011 | &internal_breakpoint_ops); | |
b60e7edf | 6012 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6013 | return b; |
6014 | } | |
6015 | ||
6016 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6017 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6018 | ||
6019 | void | |
cb851954 | 6020 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6021 | { |
876fa593 | 6022 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6023 | |
876fa593 | 6024 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6025 | { |
2bdf28a0 | 6026 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6027 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6028 | |
4a64f543 MS |
6029 | /* We apply the check to all breakpoints, including disabled for |
6030 | those with loc->duplicate set. This is so that when breakpoint | |
6031 | becomes enabled, or the duplicate is removed, gdb will try to | |
6032 | insert all breakpoints. If we don't set shlib_disabled here, | |
6033 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6034 | if (((b->type == bp_breakpoint) |
508ccb1f | 6035 | || (b->type == bp_jit_event) |
1042e4c0 | 6036 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6037 | || (is_tracepoint (b))) |
6c95b8df | 6038 | && loc->pspace == current_program_space |
0d381245 | 6039 | && !loc->shlib_disabled |
a77053c2 | 6040 | #ifdef PC_SOLIB |
0d381245 | 6041 | && PC_SOLIB (loc->address) |
a77053c2 | 6042 | #else |
6c95b8df | 6043 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6044 | #endif |
6045 | ) | |
0d381245 VP |
6046 | { |
6047 | loc->shlib_disabled = 1; | |
6048 | } | |
cae688ec JJ |
6049 | } |
6050 | } | |
6051 | ||
7a9dd1b2 | 6052 | /* Disable any breakpoints that are in an unloaded shared library. |
4a64f543 MS |
6053 | Only apply to enabled breakpoints, disabled ones can just stay |
6054 | disabled. */ | |
84acb35a | 6055 | |
75149521 | 6056 | static void |
84acb35a JJ |
6057 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6058 | { | |
876fa593 | 6059 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6060 | int disabled_shlib_breaks = 0; |
6061 | ||
c86cf029 VP |
6062 | /* SunOS a.out shared libraries are always mapped, so do not |
6063 | disable breakpoints; they will only be reported as unloaded | |
6064 | through clear_solib when GDB discards its shared library | |
6065 | list. See clear_solib for more information. */ | |
6066 | if (exec_bfd != NULL | |
6067 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6068 | return; | |
6069 | ||
876fa593 | 6070 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6071 | { |
2bdf28a0 | 6072 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6073 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6074 | |
0d381245 VP |
6075 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
6076 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 6077 | && solib->pspace == loc->pspace |
e2dd7057 | 6078 | && !loc->shlib_disabled |
508ccb1f TT |
6079 | && (b->type == bp_breakpoint |
6080 | || b->type == bp_jit_event | |
6081 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 6082 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6083 | { |
e2dd7057 PP |
6084 | loc->shlib_disabled = 1; |
6085 | /* At this point, we cannot rely on remove_breakpoint | |
6086 | succeeding so we must mark the breakpoint as not inserted | |
6087 | to prevent future errors occurring in remove_breakpoints. */ | |
6088 | loc->inserted = 0; | |
8d3788bd VP |
6089 | |
6090 | /* This may cause duplicate notifications for the same breakpoint. */ | |
6091 | observer_notify_breakpoint_modified (b); | |
6092 | ||
e2dd7057 PP |
6093 | if (!disabled_shlib_breaks) |
6094 | { | |
6095 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6096 | warning (_("Temporarily disabling breakpoints " |
6097 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6098 | solib->so_name); |
84acb35a | 6099 | } |
e2dd7057 | 6100 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6101 | } |
6102 | } | |
84acb35a JJ |
6103 | } |
6104 | ||
ce78b96d JB |
6105 | /* FORK & VFORK catchpoints. */ |
6106 | ||
e29a4733 PA |
6107 | /* An instance of this type is used to represent a fork or vfork |
6108 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
6109 | class; users downcast to "struct breakpoint *" when needed. A | |
6110 | breakpoint is really of this type iff its ops pointer points to | |
6111 | CATCH_FORK_BREAKPOINT_OPS. */ | |
6112 | ||
6113 | struct fork_catchpoint | |
6114 | { | |
6115 | /* The base class. */ | |
6116 | struct breakpoint base; | |
6117 | ||
6118 | /* Process id of a child process whose forking triggered this | |
6119 | catchpoint. This field is only valid immediately after this | |
6120 | catchpoint has triggered. */ | |
6121 | ptid_t forked_inferior_pid; | |
6122 | }; | |
6123 | ||
4a64f543 MS |
6124 | /* Implement the "insert" breakpoint_ops method for fork |
6125 | catchpoints. */ | |
ce78b96d | 6126 | |
77b06cd7 TJB |
6127 | static int |
6128 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6129 | { |
77b06cd7 | 6130 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6131 | } |
6132 | ||
4a64f543 MS |
6133 | /* Implement the "remove" breakpoint_ops method for fork |
6134 | catchpoints. */ | |
ce78b96d JB |
6135 | |
6136 | static int | |
77b06cd7 | 6137 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6138 | { |
6139 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6140 | } | |
6141 | ||
6142 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6143 | catchpoints. */ | |
6144 | ||
6145 | static int | |
f1310107 TJB |
6146 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
6147 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6148 | { |
e29a4733 PA |
6149 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6150 | ||
6151 | return inferior_has_forked (inferior_ptid, &c->forked_inferior_pid); | |
ce78b96d JB |
6152 | } |
6153 | ||
4a64f543 MS |
6154 | /* Implement the "print_it" breakpoint_ops method for fork |
6155 | catchpoints. */ | |
ce78b96d JB |
6156 | |
6157 | static enum print_stop_action | |
348d480f | 6158 | print_it_catch_fork (bpstat bs) |
ce78b96d | 6159 | { |
348d480f PA |
6160 | struct breakpoint *b = bs->breakpoint_at; |
6161 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 6162 | |
ce78b96d JB |
6163 | annotate_catchpoint (b->number); |
6164 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
e29a4733 | 6165 | b->number, ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6166 | return PRINT_SRC_AND_LOC; |
6167 | } | |
6168 | ||
4a64f543 MS |
6169 | /* Implement the "print_one" breakpoint_ops method for fork |
6170 | catchpoints. */ | |
ce78b96d JB |
6171 | |
6172 | static void | |
a6d9a66e | 6173 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6174 | { |
e29a4733 | 6175 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6176 | struct value_print_options opts; |
79a45e25 | 6177 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6178 | |
6179 | get_user_print_options (&opts); | |
6180 | ||
4a64f543 MS |
6181 | /* Field 4, the address, is omitted (which makes the columns not |
6182 | line up too nicely with the headers, but the effect is relatively | |
6183 | readable). */ | |
79a45b7d | 6184 | if (opts.addressprint) |
ce78b96d JB |
6185 | ui_out_field_skip (uiout, "addr"); |
6186 | annotate_field (5); | |
6187 | ui_out_text (uiout, "fork"); | |
e29a4733 | 6188 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6189 | { |
6190 | ui_out_text (uiout, ", process "); | |
6191 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6192 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6193 | ui_out_spaces (uiout, 1); |
6194 | } | |
6195 | } | |
6196 | ||
6197 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6198 | catchpoints. */ | |
6199 | ||
6200 | static void | |
6201 | print_mention_catch_fork (struct breakpoint *b) | |
6202 | { | |
6203 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6204 | } | |
6205 | ||
6149aea9 PA |
6206 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6207 | catchpoints. */ | |
6208 | ||
6209 | static void | |
6210 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6211 | { | |
6212 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 6213 | print_recreate_thread (b, fp); |
6149aea9 PA |
6214 | } |
6215 | ||
ce78b96d JB |
6216 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6217 | ||
2060206e | 6218 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 6219 | |
4a64f543 MS |
6220 | /* Implement the "insert" breakpoint_ops method for vfork |
6221 | catchpoints. */ | |
ce78b96d | 6222 | |
77b06cd7 TJB |
6223 | static int |
6224 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6225 | { |
77b06cd7 | 6226 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6227 | } |
6228 | ||
4a64f543 MS |
6229 | /* Implement the "remove" breakpoint_ops method for vfork |
6230 | catchpoints. */ | |
ce78b96d JB |
6231 | |
6232 | static int | |
77b06cd7 | 6233 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6234 | { |
6235 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6236 | } | |
6237 | ||
6238 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6239 | catchpoints. */ | |
6240 | ||
6241 | static int | |
f1310107 TJB |
6242 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
6243 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6244 | { |
e29a4733 PA |
6245 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6246 | ||
6247 | return inferior_has_vforked (inferior_ptid, &c->forked_inferior_pid); | |
ce78b96d JB |
6248 | } |
6249 | ||
4a64f543 MS |
6250 | /* Implement the "print_it" breakpoint_ops method for vfork |
6251 | catchpoints. */ | |
ce78b96d JB |
6252 | |
6253 | static enum print_stop_action | |
348d480f | 6254 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 6255 | { |
348d480f | 6256 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
6257 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
6258 | ||
ce78b96d JB |
6259 | annotate_catchpoint (b->number); |
6260 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
e29a4733 | 6261 | b->number, ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6262 | return PRINT_SRC_AND_LOC; |
6263 | } | |
6264 | ||
4a64f543 MS |
6265 | /* Implement the "print_one" breakpoint_ops method for vfork |
6266 | catchpoints. */ | |
ce78b96d JB |
6267 | |
6268 | static void | |
a6d9a66e | 6269 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6270 | { |
e29a4733 | 6271 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6272 | struct value_print_options opts; |
79a45e25 | 6273 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6274 | |
6275 | get_user_print_options (&opts); | |
4a64f543 MS |
6276 | /* Field 4, the address, is omitted (which makes the columns not |
6277 | line up too nicely with the headers, but the effect is relatively | |
6278 | readable). */ | |
79a45b7d | 6279 | if (opts.addressprint) |
ce78b96d JB |
6280 | ui_out_field_skip (uiout, "addr"); |
6281 | annotate_field (5); | |
6282 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 6283 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6284 | { |
6285 | ui_out_text (uiout, ", process "); | |
6286 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6287 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6288 | ui_out_spaces (uiout, 1); |
6289 | } | |
6290 | } | |
6291 | ||
6292 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6293 | catchpoints. */ | |
6294 | ||
6295 | static void | |
6296 | print_mention_catch_vfork (struct breakpoint *b) | |
6297 | { | |
6298 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6299 | } | |
6300 | ||
6149aea9 PA |
6301 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6302 | catchpoints. */ | |
6303 | ||
6304 | static void | |
6305 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6306 | { | |
6307 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 6308 | print_recreate_thread (b, fp); |
6149aea9 PA |
6309 | } |
6310 | ||
ce78b96d JB |
6311 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6312 | ||
2060206e | 6313 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 6314 | |
be5c67c1 PA |
6315 | /* An instance of this type is used to represent a syscall catchpoint. |
6316 | It includes a "struct breakpoint" as a kind of base class; users | |
6317 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6318 | really of this type iff its ops pointer points to | |
6319 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
6320 | ||
6321 | struct syscall_catchpoint | |
6322 | { | |
6323 | /* The base class. */ | |
6324 | struct breakpoint base; | |
6325 | ||
6326 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
6327 | syscall has been specified for filtering, its value is NULL. | |
6328 | Otherwise, it holds a list of all syscalls to be caught. The | |
6329 | list elements are allocated with xmalloc. */ | |
6330 | VEC(int) *syscalls_to_be_caught; | |
6331 | }; | |
6332 | ||
6333 | /* Implement the "dtor" breakpoint_ops method for syscall | |
6334 | catchpoints. */ | |
6335 | ||
6336 | static void | |
6337 | dtor_catch_syscall (struct breakpoint *b) | |
6338 | { | |
6339 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
6340 | ||
6341 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 6342 | |
2060206e | 6343 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
6344 | } |
6345 | ||
a96d9b2e SDJ |
6346 | /* Implement the "insert" breakpoint_ops method for syscall |
6347 | catchpoints. */ | |
6348 | ||
77b06cd7 TJB |
6349 | static int |
6350 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 6351 | { |
be5c67c1 | 6352 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6353 | struct inferior *inf = current_inferior (); |
6354 | ||
6355 | ++inf->total_syscalls_count; | |
be5c67c1 | 6356 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6357 | ++inf->any_syscall_count; |
6358 | else | |
6359 | { | |
6360 | int i, iter; | |
cc59ec59 | 6361 | |
a96d9b2e | 6362 | for (i = 0; |
be5c67c1 | 6363 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6364 | i++) |
6365 | { | |
6366 | int elem; | |
cc59ec59 | 6367 | |
a96d9b2e SDJ |
6368 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6369 | { | |
6370 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6371 | uintptr_t vec_addr_offset |
6372 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6373 | uintptr_t vec_addr; |
6374 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6375 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6376 | vec_addr_offset; | |
6377 | memset ((void *) vec_addr, 0, | |
6378 | (iter + 1 - old_size) * sizeof (int)); | |
6379 | } | |
6380 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6381 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6382 | } | |
6383 | } | |
6384 | ||
77b06cd7 TJB |
6385 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6386 | inf->total_syscalls_count != 0, | |
6387 | inf->any_syscall_count, | |
6388 | VEC_length (int, inf->syscalls_counts), | |
6389 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6390 | } |
6391 | ||
6392 | /* Implement the "remove" breakpoint_ops method for syscall | |
6393 | catchpoints. */ | |
6394 | ||
6395 | static int | |
77b06cd7 | 6396 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 6397 | { |
be5c67c1 | 6398 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6399 | struct inferior *inf = current_inferior (); |
6400 | ||
6401 | --inf->total_syscalls_count; | |
be5c67c1 | 6402 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6403 | --inf->any_syscall_count; |
6404 | else | |
6405 | { | |
6406 | int i, iter; | |
cc59ec59 | 6407 | |
a96d9b2e | 6408 | for (i = 0; |
be5c67c1 | 6409 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6410 | i++) |
6411 | { | |
6412 | int elem; | |
6413 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6414 | /* Shouldn't happen. */ | |
6415 | continue; | |
6416 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6417 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6418 | } | |
6419 | } | |
6420 | ||
6421 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6422 | inf->total_syscalls_count != 0, | |
6423 | inf->any_syscall_count, | |
6424 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6425 | VEC_address (int, |
6426 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6427 | } |
6428 | ||
6429 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6430 | catchpoints. */ | |
6431 | ||
6432 | static int | |
f1310107 TJB |
6433 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
6434 | struct address_space *aspace, CORE_ADDR bp_addr) | |
a96d9b2e | 6435 | { |
4a64f543 MS |
6436 | /* We must check if we are catching specific syscalls in this |
6437 | breakpoint. If we are, then we must guarantee that the called | |
6438 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 6439 | int syscall_number = 0; |
be5c67c1 PA |
6440 | const struct syscall_catchpoint *c |
6441 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e SDJ |
6442 | |
6443 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6444 | return 0; | |
6445 | ||
6446 | /* Now, checking if the syscall is the same. */ | |
be5c67c1 | 6447 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6448 | { |
6449 | int i, iter; | |
cc59ec59 | 6450 | |
a96d9b2e | 6451 | for (i = 0; |
be5c67c1 | 6452 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6453 | i++) |
6454 | if (syscall_number == iter) | |
6455 | break; | |
6456 | /* Not the same. */ | |
6457 | if (!iter) | |
6458 | return 0; | |
6459 | } | |
6460 | ||
6461 | return 1; | |
6462 | } | |
6463 | ||
6464 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6465 | catchpoints. */ | |
6466 | ||
6467 | static enum print_stop_action | |
348d480f | 6468 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 6469 | { |
348d480f | 6470 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
6471 | /* These are needed because we want to know in which state a |
6472 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6473 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6474 | must print "called syscall" or "returned from syscall". */ | |
6475 | ptid_t ptid; | |
6476 | struct target_waitstatus last; | |
6477 | struct syscall s; | |
6478 | struct cleanup *old_chain; | |
6479 | char *syscall_id; | |
6480 | ||
6481 | get_last_target_status (&ptid, &last); | |
6482 | ||
6483 | get_syscall_by_number (last.value.syscall_number, &s); | |
6484 | ||
6485 | annotate_catchpoint (b->number); | |
6486 | ||
6487 | if (s.name == NULL) | |
6488 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6489 | else | |
6490 | syscall_id = xstrprintf ("'%s'", s.name); | |
6491 | ||
6492 | old_chain = make_cleanup (xfree, syscall_id); | |
6493 | ||
6494 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6495 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6496 | b->number, syscall_id); | |
6497 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6498 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6499 | b->number, syscall_id); | |
6500 | ||
6501 | do_cleanups (old_chain); | |
6502 | ||
6503 | return PRINT_SRC_AND_LOC; | |
6504 | } | |
6505 | ||
6506 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6507 | catchpoints. */ | |
6508 | ||
6509 | static void | |
6510 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 6511 | struct bp_location **last_loc) |
a96d9b2e | 6512 | { |
be5c67c1 | 6513 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 6514 | struct value_print_options opts; |
79a45e25 | 6515 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
6516 | |
6517 | get_user_print_options (&opts); | |
4a64f543 MS |
6518 | /* Field 4, the address, is omitted (which makes the columns not |
6519 | line up too nicely with the headers, but the effect is relatively | |
6520 | readable). */ | |
a96d9b2e SDJ |
6521 | if (opts.addressprint) |
6522 | ui_out_field_skip (uiout, "addr"); | |
6523 | annotate_field (5); | |
6524 | ||
be5c67c1 PA |
6525 | if (c->syscalls_to_be_caught |
6526 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
6527 | ui_out_text (uiout, "syscalls \""); |
6528 | else | |
6529 | ui_out_text (uiout, "syscall \""); | |
6530 | ||
be5c67c1 | 6531 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6532 | { |
6533 | int i, iter; | |
6534 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6535 | |
a96d9b2e | 6536 | for (i = 0; |
be5c67c1 | 6537 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6538 | i++) |
6539 | { | |
6540 | char *x = text; | |
6541 | struct syscall s; | |
6542 | get_syscall_by_number (iter, &s); | |
6543 | ||
6544 | if (s.name != NULL) | |
6545 | text = xstrprintf ("%s%s, ", text, s.name); | |
6546 | else | |
6547 | text = xstrprintf ("%s%d, ", text, iter); | |
6548 | ||
6549 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 6550 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
6551 | on every call. */ |
6552 | xfree (x); | |
6553 | } | |
6554 | /* Remove the last comma. */ | |
6555 | text[strlen (text) - 2] = '\0'; | |
6556 | ui_out_field_string (uiout, "what", text); | |
6557 | } | |
6558 | else | |
6559 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6560 | ui_out_text (uiout, "\" "); | |
6561 | } | |
6562 | ||
6563 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6564 | catchpoints. */ | |
6565 | ||
6566 | static void | |
6567 | print_mention_catch_syscall (struct breakpoint *b) | |
6568 | { | |
be5c67c1 PA |
6569 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6570 | ||
6571 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
6572 | { |
6573 | int i, iter; | |
6574 | ||
be5c67c1 | 6575 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
6576 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
6577 | else | |
6578 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6579 | ||
6580 | for (i = 0; | |
be5c67c1 | 6581 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6582 | i++) |
6583 | { | |
6584 | struct syscall s; | |
6585 | get_syscall_by_number (iter, &s); | |
6586 | ||
6587 | if (s.name) | |
6588 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6589 | else | |
6590 | printf_filtered (" %d", s.number); | |
6591 | } | |
6592 | printf_filtered (")"); | |
6593 | } | |
6594 | else | |
6595 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6596 | b->number); | |
6597 | } | |
6598 | ||
6149aea9 PA |
6599 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6600 | catchpoints. */ | |
6601 | ||
6602 | static void | |
6603 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6604 | { | |
be5c67c1 PA |
6605 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6606 | ||
6149aea9 PA |
6607 | fprintf_unfiltered (fp, "catch syscall"); |
6608 | ||
be5c67c1 | 6609 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
6610 | { |
6611 | int i, iter; | |
6612 | ||
6613 | for (i = 0; | |
be5c67c1 | 6614 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
6615 | i++) |
6616 | { | |
6617 | struct syscall s; | |
6618 | ||
6619 | get_syscall_by_number (iter, &s); | |
6620 | if (s.name) | |
6621 | fprintf_unfiltered (fp, " %s", s.name); | |
6622 | else | |
6623 | fprintf_unfiltered (fp, " %d", s.number); | |
6624 | } | |
6625 | } | |
d9b3f62e | 6626 | print_recreate_thread (b, fp); |
6149aea9 PA |
6627 | } |
6628 | ||
a96d9b2e SDJ |
6629 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6630 | ||
2060206e | 6631 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
6632 | |
6633 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6634 | ||
6635 | static int | |
6636 | syscall_catchpoint_p (struct breakpoint *b) | |
6637 | { | |
6638 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6639 | } | |
6640 | ||
346774a9 PA |
6641 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
6642 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
6643 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
6644 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 6645 | |
346774a9 PA |
6646 | static void |
6647 | init_catchpoint (struct breakpoint *b, | |
6648 | struct gdbarch *gdbarch, int tempflag, | |
6649 | char *cond_string, | |
c0a91b2b | 6650 | const struct breakpoint_ops *ops) |
c906108c | 6651 | { |
c5aa993b | 6652 | struct symtab_and_line sal; |
346774a9 | 6653 | |
fe39c653 | 6654 | init_sal (&sal); |
6c95b8df | 6655 | sal.pspace = current_program_space; |
c5aa993b | 6656 | |
28010a5d | 6657 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 6658 | |
1b36a34b | 6659 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 6660 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
6661 | } |
6662 | ||
28010a5d | 6663 | void |
3a5c3e22 | 6664 | install_breakpoint (int internal, struct breakpoint *b) |
c56053d2 PA |
6665 | { |
6666 | add_to_breakpoint_chain (b); | |
3a5c3e22 PA |
6667 | set_breakpoint_number (internal, b); |
6668 | if (!internal) | |
6669 | mention (b); | |
c56053d2 PA |
6670 | observer_notify_breakpoint_created (b); |
6671 | update_global_location_list (1); | |
6672 | } | |
6673 | ||
9b70b993 | 6674 | static void |
a6d9a66e UW |
6675 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6676 | int tempflag, char *cond_string, | |
c0a91b2b | 6677 | const struct breakpoint_ops *ops) |
c906108c | 6678 | { |
e29a4733 | 6679 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 6680 | |
e29a4733 PA |
6681 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
6682 | ||
6683 | c->forked_inferior_pid = null_ptid; | |
6684 | ||
3a5c3e22 | 6685 | install_breakpoint (0, &c->base); |
c906108c SS |
6686 | } |
6687 | ||
fe798b75 JB |
6688 | /* Exec catchpoints. */ |
6689 | ||
b4d90040 PA |
6690 | /* An instance of this type is used to represent an exec catchpoint. |
6691 | It includes a "struct breakpoint" as a kind of base class; users | |
6692 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6693 | really of this type iff its ops pointer points to | |
6694 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
6695 | ||
6696 | struct exec_catchpoint | |
6697 | { | |
6698 | /* The base class. */ | |
6699 | struct breakpoint base; | |
6700 | ||
6701 | /* Filename of a program whose exec triggered this catchpoint. | |
6702 | This field is only valid immediately after this catchpoint has | |
6703 | triggered. */ | |
6704 | char *exec_pathname; | |
6705 | }; | |
6706 | ||
6707 | /* Implement the "dtor" breakpoint_ops method for exec | |
6708 | catchpoints. */ | |
6709 | ||
6710 | static void | |
6711 | dtor_catch_exec (struct breakpoint *b) | |
6712 | { | |
6713 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
6714 | ||
6715 | xfree (c->exec_pathname); | |
348d480f | 6716 | |
2060206e | 6717 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
6718 | } |
6719 | ||
77b06cd7 TJB |
6720 | static int |
6721 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6722 | { |
77b06cd7 | 6723 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6724 | } |
c906108c | 6725 | |
fe798b75 | 6726 | static int |
77b06cd7 | 6727 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6728 | { |
6729 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6730 | } | |
c906108c | 6731 | |
fe798b75 | 6732 | static int |
f1310107 TJB |
6733 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
6734 | struct address_space *aspace, CORE_ADDR bp_addr) | |
fe798b75 | 6735 | { |
b4d90040 PA |
6736 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
6737 | ||
6738 | return inferior_has_execd (inferior_ptid, &c->exec_pathname); | |
fe798b75 | 6739 | } |
c906108c | 6740 | |
fe798b75 | 6741 | static enum print_stop_action |
348d480f | 6742 | print_it_catch_exec (bpstat bs) |
fe798b75 | 6743 | { |
348d480f | 6744 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
6745 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
6746 | ||
fe798b75 JB |
6747 | annotate_catchpoint (b->number); |
6748 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
b4d90040 | 6749 | c->exec_pathname); |
fe798b75 | 6750 | return PRINT_SRC_AND_LOC; |
c906108c SS |
6751 | } |
6752 | ||
fe798b75 | 6753 | static void |
a6d9a66e | 6754 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 6755 | { |
b4d90040 | 6756 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 6757 | struct value_print_options opts; |
79a45e25 | 6758 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
6759 | |
6760 | get_user_print_options (&opts); | |
6761 | ||
6762 | /* Field 4, the address, is omitted (which makes the columns | |
6763 | not line up too nicely with the headers, but the effect | |
6764 | is relatively readable). */ | |
6765 | if (opts.addressprint) | |
6766 | ui_out_field_skip (uiout, "addr"); | |
6767 | annotate_field (5); | |
6768 | ui_out_text (uiout, "exec"); | |
b4d90040 | 6769 | if (c->exec_pathname != NULL) |
fe798b75 JB |
6770 | { |
6771 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 6772 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
6773 | ui_out_text (uiout, "\" "); |
6774 | } | |
6775 | } | |
6776 | ||
6777 | static void | |
6778 | print_mention_catch_exec (struct breakpoint *b) | |
6779 | { | |
6780 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6781 | } | |
6782 | ||
6149aea9 PA |
6783 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6784 | catchpoints. */ | |
6785 | ||
6786 | static void | |
6787 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6788 | { | |
6789 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 6790 | print_recreate_thread (b, fp); |
6149aea9 PA |
6791 | } |
6792 | ||
2060206e | 6793 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 6794 | |
a96d9b2e SDJ |
6795 | static void |
6796 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 6797 | const struct breakpoint_ops *ops) |
a96d9b2e | 6798 | { |
be5c67c1 | 6799 | struct syscall_catchpoint *c; |
a96d9b2e | 6800 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 6801 | |
be5c67c1 PA |
6802 | c = XNEW (struct syscall_catchpoint); |
6803 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
6804 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 6805 | |
3a5c3e22 | 6806 | install_breakpoint (0, &c->base); |
a96d9b2e SDJ |
6807 | } |
6808 | ||
c906108c | 6809 | static int |
fba45db2 | 6810 | hw_breakpoint_used_count (void) |
c906108c | 6811 | { |
c906108c | 6812 | int i = 0; |
f1310107 TJB |
6813 | struct breakpoint *b; |
6814 | struct bp_location *bl; | |
c906108c SS |
6815 | |
6816 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6817 | { |
d6b74ac4 | 6818 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
6819 | for (bl = b->loc; bl; bl = bl->next) |
6820 | { | |
6821 | /* Special types of hardware breakpoints may use more than | |
6822 | one register. */ | |
348d480f | 6823 | i += b->ops->resources_needed (bl); |
f1310107 | 6824 | } |
c5aa993b | 6825 | } |
c906108c SS |
6826 | |
6827 | return i; | |
6828 | } | |
6829 | ||
6830 | static int | |
fba45db2 | 6831 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6832 | { |
c906108c | 6833 | int i = 0; |
e09342b5 TJB |
6834 | struct breakpoint *b; |
6835 | struct bp_location *bl; | |
c906108c SS |
6836 | |
6837 | *other_type_used = 0; | |
6838 | ALL_BREAKPOINTS (b) | |
e09342b5 TJB |
6839 | { |
6840 | if (!breakpoint_enabled (b)) | |
6841 | continue; | |
6842 | ||
c5aa993b | 6843 | if (b->type == type) |
e09342b5 TJB |
6844 | for (bl = b->loc; bl; bl = bl->next) |
6845 | { | |
6846 | /* Special types of hardware watchpoints may use more than | |
6847 | one register. */ | |
348d480f | 6848 | i += b->ops->resources_needed (bl); |
e09342b5 | 6849 | } |
cc60f2e3 | 6850 | else if (is_hardware_watchpoint (b)) |
c5aa993b | 6851 | *other_type_used = 1; |
e09342b5 TJB |
6852 | } |
6853 | ||
c906108c SS |
6854 | return i; |
6855 | } | |
6856 | ||
c906108c | 6857 | void |
fba45db2 | 6858 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6859 | { |
c5aa993b | 6860 | struct breakpoint *b; |
c906108c SS |
6861 | |
6862 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6863 | { |
cc60f2e3 | 6864 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6865 | { |
b5de0fa7 | 6866 | b->enable_state = bp_call_disabled; |
b60e7edf | 6867 | update_global_location_list (0); |
c5aa993b JM |
6868 | } |
6869 | } | |
c906108c SS |
6870 | } |
6871 | ||
6872 | void | |
fba45db2 | 6873 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6874 | { |
c5aa993b | 6875 | struct breakpoint *b; |
c906108c SS |
6876 | |
6877 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6878 | { |
cc60f2e3 | 6879 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6880 | { |
b5de0fa7 | 6881 | b->enable_state = bp_enabled; |
b60e7edf | 6882 | update_global_location_list (1); |
c5aa993b JM |
6883 | } |
6884 | } | |
c906108c SS |
6885 | } |
6886 | ||
8bea4e01 UW |
6887 | void |
6888 | disable_breakpoints_before_startup (void) | |
6889 | { | |
6890 | struct breakpoint *b; | |
6891 | int found = 0; | |
6892 | ||
6893 | ALL_BREAKPOINTS (b) | |
6894 | { | |
6c95b8df PA |
6895 | if (b->pspace != current_program_space) |
6896 | continue; | |
6897 | ||
8bea4e01 UW |
6898 | if ((b->type == bp_breakpoint |
6899 | || b->type == bp_hardware_breakpoint) | |
6900 | && breakpoint_enabled (b)) | |
6901 | { | |
6902 | b->enable_state = bp_startup_disabled; | |
6903 | found = 1; | |
6904 | } | |
6905 | } | |
6906 | ||
6907 | if (found) | |
6908 | update_global_location_list (0); | |
6909 | ||
6c95b8df | 6910 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6911 | } |
6912 | ||
6913 | void | |
6914 | enable_breakpoints_after_startup (void) | |
6915 | { | |
6916 | struct breakpoint *b; | |
6917 | int found = 0; | |
6918 | ||
6c95b8df | 6919 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6920 | |
6921 | ALL_BREAKPOINTS (b) | |
6922 | { | |
6c95b8df PA |
6923 | if (b->pspace != current_program_space) |
6924 | continue; | |
6925 | ||
8bea4e01 UW |
6926 | if ((b->type == bp_breakpoint |
6927 | || b->type == bp_hardware_breakpoint) | |
6928 | && b->enable_state == bp_startup_disabled) | |
6929 | { | |
6930 | b->enable_state = bp_enabled; | |
6931 | found = 1; | |
6932 | } | |
6933 | } | |
6934 | ||
6935 | if (found) | |
6936 | breakpoint_re_set (); | |
6937 | } | |
6938 | ||
c906108c SS |
6939 | |
6940 | /* Set a breakpoint that will evaporate an end of command | |
6941 | at address specified by SAL. | |
6942 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6943 | ||
6944 | struct breakpoint * | |
a6d9a66e UW |
6945 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6946 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6947 | { |
52f0bd74 | 6948 | struct breakpoint *b; |
edb3359d DJ |
6949 | |
6950 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6951 | one. */ | |
6952 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6953 | ||
06edf0c0 | 6954 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
6955 | b->enable_state = bp_enabled; |
6956 | b->disposition = disp_donttouch; | |
818dd999 | 6957 | b->frame_id = frame_id; |
c906108c | 6958 | |
4a64f543 MS |
6959 | /* If we're debugging a multi-threaded program, then we want |
6960 | momentary breakpoints to be active in only a single thread of | |
6961 | control. */ | |
39f77062 KB |
6962 | if (in_thread_list (inferior_ptid)) |
6963 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6964 | |
b60e7edf | 6965 | update_global_location_list_nothrow (1); |
74960c60 | 6966 | |
c906108c SS |
6967 | return b; |
6968 | } | |
611c83ae | 6969 | |
06edf0c0 PA |
6970 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
6971 | The new breakpoint will have type TYPE, and use OPS as it | |
6972 | breakpoint_ops. */ | |
e58b0e63 | 6973 | |
06edf0c0 PA |
6974 | static struct breakpoint * |
6975 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
6976 | enum bptype type, | |
c0a91b2b | 6977 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
6978 | { |
6979 | struct breakpoint *copy; | |
6980 | ||
06edf0c0 | 6981 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 6982 | copy->loc = allocate_bp_location (copy); |
0e30163f | 6983 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 6984 | |
a6d9a66e | 6985 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6986 | copy->loc->requested_address = orig->loc->requested_address; |
6987 | copy->loc->address = orig->loc->address; | |
6988 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6989 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6990 | |
6991 | if (orig->source_file == NULL) | |
6992 | copy->source_file = NULL; | |
6993 | else | |
6994 | copy->source_file = xstrdup (orig->source_file); | |
6995 | ||
6996 | copy->line_number = orig->line_number; | |
6997 | copy->frame_id = orig->frame_id; | |
6998 | copy->thread = orig->thread; | |
6c95b8df | 6999 | copy->pspace = orig->pspace; |
e58b0e63 PA |
7000 | |
7001 | copy->enable_state = bp_enabled; | |
7002 | copy->disposition = disp_donttouch; | |
7003 | copy->number = internal_breakpoint_number--; | |
7004 | ||
7005 | update_global_location_list_nothrow (0); | |
7006 | return copy; | |
7007 | } | |
7008 | ||
06edf0c0 PA |
7009 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
7010 | ORIG is NULL. */ | |
7011 | ||
7012 | struct breakpoint * | |
7013 | clone_momentary_breakpoint (struct breakpoint *orig) | |
7014 | { | |
7015 | /* If there's nothing to clone, then return nothing. */ | |
7016 | if (orig == NULL) | |
7017 | return NULL; | |
7018 | ||
7019 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
7020 | } | |
7021 | ||
611c83ae | 7022 | struct breakpoint * |
a6d9a66e UW |
7023 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
7024 | enum bptype type) | |
611c83ae PA |
7025 | { |
7026 | struct symtab_and_line sal; | |
7027 | ||
7028 | sal = find_pc_line (pc, 0); | |
7029 | sal.pc = pc; | |
7030 | sal.section = find_pc_overlay (pc); | |
7031 | sal.explicit_pc = 1; | |
7032 | ||
a6d9a66e | 7033 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 7034 | } |
c906108c | 7035 | \f |
c5aa993b | 7036 | |
c906108c SS |
7037 | /* Tell the user we have just set a breakpoint B. */ |
7038 | ||
7039 | static void | |
fba45db2 | 7040 | mention (struct breakpoint *b) |
c906108c | 7041 | { |
348d480f | 7042 | b->ops->print_mention (b); |
79a45e25 | 7043 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 7044 | return; |
c906108c SS |
7045 | printf_filtered ("\n"); |
7046 | } | |
c906108c | 7047 | \f |
c5aa993b | 7048 | |
0d381245 | 7049 | static struct bp_location * |
39d61571 | 7050 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7051 | const struct symtab_and_line *sal) |
7052 | { | |
7053 | struct bp_location *loc, **tmp; | |
7054 | ||
39d61571 | 7055 | loc = allocate_bp_location (b); |
0d381245 VP |
7056 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7057 | ; | |
7058 | *tmp = loc; | |
a6d9a66e UW |
7059 | loc->gdbarch = get_sal_arch (*sal); |
7060 | if (!loc->gdbarch) | |
7061 | loc->gdbarch = b->gdbarch; | |
0d381245 | 7062 | loc->requested_address = sal->pc; |
a6d9a66e UW |
7063 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
7064 | loc->requested_address, b->type); | |
6c95b8df PA |
7065 | loc->pspace = sal->pspace; |
7066 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
7067 | loc->section = sal->section; |
7068 | ||
0e30163f JK |
7069 | set_breakpoint_location_function (loc, |
7070 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
7071 | return loc; |
7072 | } | |
514f746b AR |
7073 | \f |
7074 | ||
7075 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7076 | return 0 otherwise. */ | |
7077 | ||
7078 | static int | |
7079 | bp_loc_is_permanent (struct bp_location *loc) | |
7080 | { | |
7081 | int len; | |
7082 | CORE_ADDR addr; | |
7083 | const gdb_byte *brk; | |
7084 | gdb_byte *target_mem; | |
939c61fa JK |
7085 | struct cleanup *cleanup; |
7086 | int retval = 0; | |
514f746b AR |
7087 | |
7088 | gdb_assert (loc != NULL); | |
7089 | ||
7090 | addr = loc->address; | |
a6d9a66e | 7091 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7092 | |
939c61fa JK |
7093 | /* Software breakpoints unsupported? */ |
7094 | if (brk == NULL) | |
7095 | return 0; | |
7096 | ||
514f746b AR |
7097 | target_mem = alloca (len); |
7098 | ||
939c61fa JK |
7099 | /* Enable the automatic memory restoration from breakpoints while |
7100 | we read the memory. Otherwise we could say about our temporary | |
7101 | breakpoints they are permanent. */ | |
6c95b8df PA |
7102 | cleanup = save_current_space_and_thread (); |
7103 | ||
7104 | switch_to_program_space_and_thread (loc->pspace); | |
7105 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7106 | |
514f746b AR |
7107 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7108 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7109 | retval = 1; |
514f746b | 7110 | |
939c61fa JK |
7111 | do_cleanups (cleanup); |
7112 | ||
7113 | return retval; | |
514f746b AR |
7114 | } |
7115 | ||
7116 | ||
c3f6f71d | 7117 | |
018d34a4 VP |
7118 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7119 | as textual description of the location, and COND_STRING | |
db107f19 | 7120 | as condition expression. */ |
018d34a4 VP |
7121 | |
7122 | static void | |
d9b3f62e PA |
7123 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
7124 | struct symtabs_and_lines sals, char *addr_string, | |
7125 | char *cond_string, | |
7126 | enum bptype type, enum bpdisp disposition, | |
7127 | int thread, int task, int ignore_count, | |
c0a91b2b | 7128 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e | 7129 | int enabled, int internal, int display_canonical) |
018d34a4 | 7130 | { |
0d381245 | 7131 | int i; |
018d34a4 VP |
7132 | |
7133 | if (type == bp_hardware_breakpoint) | |
7134 | { | |
7135 | int i = hw_breakpoint_used_count (); | |
7136 | int target_resources_ok = | |
d92524f1 | 7137 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
7138 | i + 1, 0); |
7139 | if (target_resources_ok == 0) | |
7140 | error (_("No hardware breakpoint support in the target.")); | |
7141 | else if (target_resources_ok < 0) | |
7142 | error (_("Hardware breakpoints used exceeds limit.")); | |
7143 | } | |
7144 | ||
6c95b8df PA |
7145 | gdb_assert (sals.nelts > 0); |
7146 | ||
0d381245 VP |
7147 | for (i = 0; i < sals.nelts; ++i) |
7148 | { | |
7149 | struct symtab_and_line sal = sals.sals[i]; | |
7150 | struct bp_location *loc; | |
7151 | ||
7152 | if (from_tty) | |
5af949e3 UW |
7153 | { |
7154 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7155 | if (!loc_gdbarch) | |
7156 | loc_gdbarch = gdbarch; | |
7157 | ||
7158 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7159 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7160 | } |
0d381245 VP |
7161 | |
7162 | if (i == 0) | |
7163 | { | |
d9b3f62e | 7164 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 7165 | b->thread = thread; |
4a306c9a | 7166 | b->task = task; |
018d34a4 | 7167 | |
0d381245 VP |
7168 | b->cond_string = cond_string; |
7169 | b->ignore_count = ignore_count; | |
41447f92 | 7170 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7171 | b->disposition = disposition; |
6c95b8df PA |
7172 | b->pspace = sals.sals[0].pspace; |
7173 | ||
0fb4aa4b PA |
7174 | if (type == bp_static_tracepoint) |
7175 | { | |
d9b3f62e | 7176 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
7177 | struct static_tracepoint_marker marker; |
7178 | ||
7179 | if (is_marker_spec (addr_string)) | |
7180 | { | |
7181 | /* We already know the marker exists, otherwise, we | |
7182 | wouldn't see a sal for it. */ | |
7183 | char *p = &addr_string[3]; | |
7184 | char *endp; | |
7185 | char *marker_str; | |
7186 | int i; | |
7187 | ||
e9cafbcc | 7188 | p = skip_spaces (p); |
0fb4aa4b | 7189 | |
e9cafbcc | 7190 | endp = skip_to_space (p); |
0fb4aa4b PA |
7191 | |
7192 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 7193 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 7194 | |
3e43a32a MS |
7195 | printf_filtered (_("Probed static tracepoint " |
7196 | "marker \"%s\"\n"), | |
d9b3f62e | 7197 | t->static_trace_marker_id); |
0fb4aa4b PA |
7198 | } |
7199 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7200 | { | |
d9b3f62e | 7201 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
7202 | release_static_tracepoint_marker (&marker); |
7203 | ||
3e43a32a MS |
7204 | printf_filtered (_("Probed static tracepoint " |
7205 | "marker \"%s\"\n"), | |
d9b3f62e | 7206 | t->static_trace_marker_id); |
0fb4aa4b PA |
7207 | } |
7208 | else | |
3e43a32a MS |
7209 | warning (_("Couldn't determine the static " |
7210 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7211 | } |
7212 | ||
6c95b8df | 7213 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7214 | && (b->type == bp_breakpoint |
7215 | || b->type == bp_hardware_breakpoint)) | |
7216 | b->enable_state = bp_startup_disabled; | |
7217 | ||
0d381245 VP |
7218 | loc = b->loc; |
7219 | } | |
7220 | else | |
018d34a4 | 7221 | { |
39d61571 | 7222 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7223 | } |
7224 | ||
514f746b AR |
7225 | if (bp_loc_is_permanent (loc)) |
7226 | make_breakpoint_permanent (b); | |
7227 | ||
0d381245 VP |
7228 | if (b->cond_string) |
7229 | { | |
7230 | char *arg = b->cond_string; | |
d32a6982 | 7231 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7232 | if (*arg) |
db107f19 | 7233 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7234 | } |
0d381245 | 7235 | } |
018d34a4 | 7236 | |
56435ebe | 7237 | b->display_canonical = display_canonical; |
018d34a4 VP |
7238 | if (addr_string) |
7239 | b->addr_string = addr_string; | |
7240 | else | |
7241 | /* addr_string has to be used or breakpoint_re_set will delete | |
7242 | me. */ | |
5af949e3 UW |
7243 | b->addr_string |
7244 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
d9b3f62e | 7245 | } |
018d34a4 | 7246 | |
d9b3f62e PA |
7247 | static void |
7248 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
7249 | struct symtabs_and_lines sals, char *addr_string, | |
7250 | char *cond_string, | |
7251 | enum bptype type, enum bpdisp disposition, | |
7252 | int thread, int task, int ignore_count, | |
c0a91b2b | 7253 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e PA |
7254 | int enabled, int internal, int display_canonical) |
7255 | { | |
7256 | struct breakpoint *b; | |
7257 | struct cleanup *old_chain; | |
7258 | ||
7259 | if (is_tracepoint_type (type)) | |
7260 | { | |
7261 | struct tracepoint *t; | |
7262 | ||
7263 | t = XCNEW (struct tracepoint); | |
7264 | b = &t->base; | |
7265 | } | |
7266 | else | |
7267 | b = XNEW (struct breakpoint); | |
7268 | ||
7269 | old_chain = make_cleanup (xfree, b); | |
7270 | ||
7271 | init_breakpoint_sal (b, gdbarch, | |
7272 | sals, addr_string, | |
7273 | cond_string, | |
7274 | type, disposition, | |
7275 | thread, task, ignore_count, | |
7276 | ops, from_tty, | |
7277 | enabled, internal, display_canonical); | |
7278 | discard_cleanups (old_chain); | |
7279 | ||
7280 | install_breakpoint (internal, b); | |
018d34a4 VP |
7281 | } |
7282 | ||
ed0616c6 VP |
7283 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7284 | elements to fill the void space. */ | |
2c0b251b PA |
7285 | static void |
7286 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7287 | { |
7288 | int i = index_to_remove+1; | |
7289 | int last_index = sal->nelts-1; | |
7290 | ||
7291 | for (;i <= last_index; ++i) | |
7292 | sal->sals[i-1] = sal->sals[i]; | |
7293 | ||
7294 | --(sal->nelts); | |
7295 | } | |
7296 | ||
6c95b8df PA |
7297 | /* If appropriate, obtains all sals that correspond to the same file |
7298 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7299 | will want to set a breakpoint at foo.c:line, and not really care | |
7300 | about program spaces. This is done only if SAL does not have | |
7301 | explicit PC and has line and file information. If we got just a | |
7302 | single expanded sal, return the original. | |
ed0616c6 | 7303 | |
6c95b8df PA |
7304 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7305 | which the name of enclosing function is different from SAL. This | |
7306 | makes sure that if we have breakpoint originally set in template | |
7307 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7308 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7309 | |
2c0b251b | 7310 | static struct symtabs_and_lines |
ed0616c6 VP |
7311 | expand_line_sal_maybe (struct symtab_and_line sal) |
7312 | { | |
7313 | struct symtabs_and_lines expanded; | |
7314 | CORE_ADDR original_pc = sal.pc; | |
7315 | char *original_function = NULL; | |
7316 | int found; | |
7317 | int i; | |
6c95b8df | 7318 | struct cleanup *old_chain; |
ed0616c6 VP |
7319 | |
7320 | /* If we have explicit pc, don't expand. | |
7321 | If we have no line number, we can't expand. */ | |
7322 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7323 | { | |
7324 | expanded.nelts = 1; | |
7325 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7326 | expanded.sals[0] = sal; | |
7327 | return expanded; | |
7328 | } | |
7329 | ||
7330 | sal.pc = 0; | |
6c95b8df PA |
7331 | |
7332 | old_chain = save_current_space_and_thread (); | |
7333 | ||
7334 | switch_to_program_space_and_thread (sal.pspace); | |
7335 | ||
ed0616c6 | 7336 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7337 | |
7338 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7339 | expanded = expand_line_sal (sal); |
6c95b8df | 7340 | |
ed0616c6 VP |
7341 | if (expanded.nelts == 1) |
7342 | { | |
3dba1c98 JB |
7343 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7344 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7345 | xfree (expanded.sals); |
7346 | expanded.nelts = 1; | |
7347 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7348 | sal.pc = original_pc; | |
7349 | expanded.sals[0] = sal; | |
3dba1c98 | 7350 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7351 | do_cleanups (old_chain); |
ed0616c6 VP |
7352 | return expanded; |
7353 | } | |
7354 | ||
7355 | if (!sal.explicit_line) | |
7356 | { | |
7357 | CORE_ADDR func_addr, func_end; | |
7358 | for (i = 0; i < expanded.nelts; ++i) | |
7359 | { | |
7360 | CORE_ADDR pc = expanded.sals[i].pc; | |
7361 | char *this_function; | |
6c95b8df PA |
7362 | |
7363 | /* We need to switch threads as well since we're about to | |
7364 | read memory. */ | |
7365 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7366 | ||
ed0616c6 VP |
7367 | if (find_pc_partial_function (pc, &this_function, |
7368 | &func_addr, &func_end)) | |
7369 | { | |
059fb39f PM |
7370 | if (this_function |
7371 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7372 | { |
7373 | remove_sal (&expanded, i); | |
7374 | --i; | |
7375 | } | |
ed0616c6 VP |
7376 | } |
7377 | } | |
7378 | } | |
059acae7 UW |
7379 | |
7380 | /* Skip the function prologue if necessary. */ | |
7381 | for (i = 0; i < expanded.nelts; ++i) | |
7382 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7383 | |
6c95b8df PA |
7384 | do_cleanups (old_chain); |
7385 | ||
ed0616c6 VP |
7386 | if (expanded.nelts <= 1) |
7387 | { | |
e5dd4106 | 7388 | /* This is an ugly workaround. If we get zero expanded sals |
4a64f543 MS |
7389 | then something is really wrong. Fix that by returning the |
7390 | original sal. */ | |
7391 | ||
ed0616c6 VP |
7392 | xfree (expanded.sals); |
7393 | expanded.nelts = 1; | |
7394 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7395 | sal.pc = original_pc; | |
7396 | expanded.sals[0] = sal; | |
7397 | return expanded; | |
7398 | } | |
7399 | ||
7400 | if (original_pc) | |
7401 | { | |
7402 | found = 0; | |
7403 | for (i = 0; i < expanded.nelts; ++i) | |
7404 | if (expanded.sals[i].pc == original_pc) | |
7405 | { | |
7406 | found = 1; | |
7407 | break; | |
7408 | } | |
7409 | gdb_assert (found); | |
7410 | } | |
7411 | ||
7412 | return expanded; | |
7413 | } | |
7414 | ||
018d34a4 VP |
7415 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7416 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7417 | value. COND_STRING, if not NULL, specified the condition to be | |
7418 | used for all breakpoints. Essentially the only case where | |
7419 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7420 | function. In that case, it's still not possible to specify | |
7421 | separate conditions for different overloaded functions, so | |
7422 | we take just a single condition string. | |
7423 | ||
c3f6f71d | 7424 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7425 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7426 | array contents). If the function fails (error() is called), the |
7427 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7428 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7429 | |
7430 | static void | |
8cdf0e15 | 7431 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 TT |
7432 | struct symtabs_and_lines sals, |
7433 | struct linespec_result *canonical, | |
8cdf0e15 VP |
7434 | char *cond_string, |
7435 | enum bptype type, enum bpdisp disposition, | |
7436 | int thread, int task, int ignore_count, | |
c0a91b2b | 7437 | const struct breakpoint_ops *ops, int from_tty, |
84f4c1fe | 7438 | int enabled, int internal) |
c906108c | 7439 | { |
018d34a4 | 7440 | int i; |
cc59ec59 | 7441 | |
018d34a4 | 7442 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7443 | { |
ed0616c6 VP |
7444 | struct symtabs_and_lines expanded = |
7445 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7446 | |
7efd8fc2 | 7447 | create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i], |
8cdf0e15 | 7448 | cond_string, type, disposition, |
84f4c1fe | 7449 | thread, task, ignore_count, ops, |
56435ebe TT |
7450 | from_tty, enabled, internal, |
7451 | canonical->special_display); | |
c3f6f71d | 7452 | } |
c3f6f71d | 7453 | } |
c906108c | 7454 | |
9998af43 | 7455 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7456 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7457 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7458 | address strings. ADDRESS points to the end of the SAL. |
7459 | ||
7460 | The array and the line spec strings are allocated on the heap, it is | |
7461 | the caller's responsibility to free them. */ | |
c906108c | 7462 | |
b9362cc7 | 7463 | static void |
c3f6f71d JM |
7464 | parse_breakpoint_sals (char **address, |
7465 | struct symtabs_and_lines *sals, | |
58438ac1 | 7466 | struct linespec_result *canonical) |
c3f6f71d JM |
7467 | { |
7468 | char *addr_start = *address; | |
cc59ec59 | 7469 | |
c3f6f71d | 7470 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 7471 | breakpoint. */ |
c3f6f71d JM |
7472 | if ((*address) == NULL |
7473 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7474 | { |
7475 | if (default_breakpoint_valid) | |
7476 | { | |
c3f6f71d | 7477 | struct symtab_and_line sal; |
cc59ec59 | 7478 | |
4a64f543 | 7479 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7480 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7481 | xmalloc (sizeof (struct symtab_and_line)); |
7482 | sal.pc = default_breakpoint_address; | |
7483 | sal.line = default_breakpoint_line; | |
7484 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7485 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7486 | sal.section = find_pc_overlay (sal.pc); |
00903456 | 7487 | |
4a64f543 MS |
7488 | /* "break" without arguments is equivalent to "break *PC" |
7489 | where PC is the default_breakpoint_address. So make sure | |
7490 | to set sal.explicit_pc to prevent GDB from trying to | |
7491 | expand the list of sals to include all other instances | |
7492 | with the same symtab and line. */ | |
00903456 JK |
7493 | sal.explicit_pc = 1; |
7494 | ||
c3f6f71d JM |
7495 | sals->sals[0] = sal; |
7496 | sals->nelts = 1; | |
c906108c SS |
7497 | } |
7498 | else | |
8a3fe4f8 | 7499 | error (_("No default breakpoint address now.")); |
c906108c SS |
7500 | } |
7501 | else | |
7502 | { | |
c906108c | 7503 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7504 | current_source_symtab (which is decode_line_1's default). |
7505 | This should produce the results we want almost all of the | |
7506 | time while leaving default_breakpoint_* alone. | |
7507 | ||
1aeae86e AF |
7508 | ObjC: However, don't match an Objective-C method name which |
7509 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7510 | |
c214a6fd | 7511 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7512 | |
c906108c | 7513 | if (default_breakpoint_valid |
0378c332 | 7514 | && (!cursal.symtab |
1aeae86e AF |
7515 | || ((strchr ("+-", (*address)[0]) != NULL) |
7516 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7517 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
58438ac1 | 7518 | default_breakpoint_line, canonical); |
c906108c | 7519 | else |
0101ce28 | 7520 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
58438ac1 | 7521 | canonical); |
c906108c | 7522 | } |
4a64f543 | 7523 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7efd8fc2 | 7524 | if (sals->nelts > 0 && canonical->canonical == NULL) |
38a714bb | 7525 | canonical->canonical = xcalloc (sals->nelts, sizeof (char *)); |
c3f6f71d | 7526 | if (addr_start != (*address)) |
c906108c | 7527 | { |
c3f6f71d | 7528 | int i; |
cc59ec59 | 7529 | |
c3f6f71d | 7530 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7531 | { |
4a64f543 | 7532 | /* Add the string if not present. */ |
7efd8fc2 TT |
7533 | if (canonical->canonical[i] == NULL) |
7534 | canonical->canonical[i] = savestring (addr_start, | |
7535 | (*address) - addr_start); | |
c906108c SS |
7536 | } |
7537 | } | |
c3f6f71d | 7538 | } |
c906108c | 7539 | |
c906108c | 7540 | |
c3f6f71d | 7541 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7542 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7543 | |
b9362cc7 | 7544 | static void |
23e7acfb | 7545 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7546 | { |
7547 | int i; | |
cc59ec59 | 7548 | |
c3f6f71d | 7549 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7550 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7551 | } |
7552 | ||
7a697b8d SS |
7553 | /* Fast tracepoints may have restrictions on valid locations. For |
7554 | instance, a fast tracepoint using a jump instead of a trap will | |
7555 | likely have to overwrite more bytes than a trap would, and so can | |
7556 | only be placed where the instruction is longer than the jump, or a | |
7557 | multi-instruction sequence does not have a jump into the middle of | |
7558 | it, etc. */ | |
7559 | ||
7560 | static void | |
7561 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7562 | struct symtabs_and_lines *sals) | |
7563 | { | |
7564 | int i, rslt; | |
7565 | struct symtab_and_line *sal; | |
7566 | char *msg; | |
7567 | struct cleanup *old_chain; | |
7568 | ||
7569 | for (i = 0; i < sals->nelts; i++) | |
7570 | { | |
7571 | sal = &sals->sals[i]; | |
7572 | ||
7573 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7574 | NULL, &msg); | |
7575 | old_chain = make_cleanup (xfree, msg); | |
7576 | ||
7577 | if (!rslt) | |
7578 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7579 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7580 | ||
7581 | do_cleanups (old_chain); | |
7582 | } | |
7583 | } | |
7584 | ||
018d34a4 VP |
7585 | /* Given TOK, a string specification of condition and thread, as |
7586 | accepted by the 'break' command, extract the condition | |
7587 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7588 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7589 | If no condition is found, *COND_STRING is set to NULL. |
7590 | If no thread is found, *THREAD is set to -1. */ | |
7591 | static void | |
7592 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7593 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7594 | { |
7595 | *cond_string = NULL; | |
7596 | *thread = -1; | |
7597 | while (tok && *tok) | |
7598 | { | |
7599 | char *end_tok; | |
7600 | int toklen; | |
7601 | char *cond_start = NULL; | |
7602 | char *cond_end = NULL; | |
cc59ec59 | 7603 | |
e9cafbcc | 7604 | tok = skip_spaces (tok); |
018d34a4 | 7605 | |
e9cafbcc | 7606 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7607 | |
7608 | toklen = end_tok - tok; | |
7609 | ||
7610 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7611 | { | |
f7545552 TT |
7612 | struct expression *expr; |
7613 | ||
018d34a4 | 7614 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7615 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7616 | xfree (expr); | |
018d34a4 VP |
7617 | cond_end = tok; |
7618 | *cond_string = savestring (cond_start, | |
7619 | cond_end - cond_start); | |
7620 | } | |
7621 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7622 | { | |
7623 | char *tmptok; | |
7624 | ||
7625 | tok = end_tok + 1; | |
7626 | tmptok = tok; | |
7627 | *thread = strtol (tok, &tok, 0); | |
7628 | if (tok == tmptok) | |
7629 | error (_("Junk after thread keyword.")); | |
7630 | if (!valid_thread_id (*thread)) | |
7631 | error (_("Unknown thread %d."), *thread); | |
7632 | } | |
4a306c9a JB |
7633 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7634 | { | |
7635 | char *tmptok; | |
7636 | ||
7637 | tok = end_tok + 1; | |
7638 | tmptok = tok; | |
7639 | *task = strtol (tok, &tok, 0); | |
7640 | if (tok == tmptok) | |
7641 | error (_("Junk after task keyword.")); | |
7642 | if (!valid_task_id (*task)) | |
b6199126 | 7643 | error (_("Unknown task %d."), *task); |
4a306c9a | 7644 | } |
018d34a4 VP |
7645 | else |
7646 | error (_("Junk at end of arguments.")); | |
7647 | } | |
7648 | } | |
7649 | ||
0fb4aa4b PA |
7650 | /* Decode a static tracepoint marker spec. */ |
7651 | ||
7652 | static struct symtabs_and_lines | |
7653 | decode_static_tracepoint_spec (char **arg_p) | |
7654 | { | |
7655 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7656 | struct symtabs_and_lines sals; | |
7657 | struct symtab_and_line sal; | |
7658 | struct symbol *sym; | |
7659 | struct cleanup *old_chain; | |
7660 | char *p = &(*arg_p)[3]; | |
7661 | char *endp; | |
7662 | char *marker_str; | |
7663 | int i; | |
7664 | ||
e9cafbcc | 7665 | p = skip_spaces (p); |
0fb4aa4b | 7666 | |
e9cafbcc | 7667 | endp = skip_to_space (p); |
0fb4aa4b PA |
7668 | |
7669 | marker_str = savestring (p, endp - p); | |
7670 | old_chain = make_cleanup (xfree, marker_str); | |
7671 | ||
7672 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7673 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7674 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7675 | ||
7676 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7677 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7678 | ||
7679 | for (i = 0; i < sals.nelts; i++) | |
7680 | { | |
7681 | struct static_tracepoint_marker *marker; | |
7682 | ||
7683 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7684 | ||
7685 | init_sal (&sals.sals[i]); | |
7686 | ||
7687 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7688 | sals.sals[i].pc = marker->address; | |
7689 | ||
7690 | release_static_tracepoint_marker (marker); | |
7691 | } | |
7692 | ||
7693 | do_cleanups (old_chain); | |
7694 | ||
7695 | *arg_p = endp; | |
7696 | return sals; | |
7697 | } | |
7698 | ||
fd9b8c24 PA |
7699 | /* Set a breakpoint. This function is shared between CLI and MI |
7700 | functions for setting a breakpoint. This function has two major | |
7701 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7702 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7703 | breakpoint location, address and thread. Otherwise, ARG is just |
7704 | the location of breakpoint, with condition and thread specified by | |
7705 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7706 | the breakpoint number will be allocated from the internal | |
7707 | breakpoint count. Returns true if any breakpoint was created; | |
7708 | false otherwise. */ | |
0101ce28 | 7709 | |
8cdf0e15 VP |
7710 | int |
7711 | create_breakpoint (struct gdbarch *gdbarch, | |
7712 | char *arg, char *cond_string, int thread, | |
7713 | int parse_condition_and_thread, | |
0fb4aa4b | 7714 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7715 | int ignore_count, |
7716 | enum auto_boolean pending_break_support, | |
c0a91b2b | 7717 | const struct breakpoint_ops *ops, |
84f4c1fe | 7718 | int from_tty, int enabled, int internal) |
c3f6f71d | 7719 | { |
b78a6381 | 7720 | volatile struct gdb_exception e; |
c3f6f71d | 7721 | struct symtabs_and_lines sals; |
0101ce28 | 7722 | struct symtab_and_line pending_sal; |
0101ce28 | 7723 | char *copy_arg; |
c3f6f71d | 7724 | char *addr_start = arg; |
7efd8fc2 | 7725 | struct linespec_result canonical; |
c3f6f71d | 7726 | struct cleanup *old_chain; |
80c99de1 | 7727 | struct cleanup *bkpt_chain = NULL; |
05ff989b | 7728 | int i; |
0101ce28 | 7729 | int pending = 0; |
4a306c9a | 7730 | int task = 0; |
86b17b60 | 7731 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7732 | |
348d480f PA |
7733 | gdb_assert (ops != NULL); |
7734 | ||
c3f6f71d JM |
7735 | sals.sals = NULL; |
7736 | sals.nelts = 0; | |
7efd8fc2 | 7737 | init_linespec_result (&canonical); |
c3f6f71d | 7738 | |
0fb4aa4b PA |
7739 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7740 | { | |
7741 | int i; | |
7742 | ||
7743 | sals = decode_static_tracepoint_spec (&arg); | |
7744 | ||
7745 | copy_arg = savestring (addr_start, arg - addr_start); | |
38a714bb | 7746 | canonical.canonical = xcalloc (sals.nelts, sizeof (char *)); |
0fb4aa4b | 7747 | for (i = 0; i < sals.nelts; i++) |
7efd8fc2 | 7748 | canonical.canonical[i] = xstrdup (copy_arg); |
0fb4aa4b PA |
7749 | goto done; |
7750 | } | |
7751 | ||
b78a6381 TT |
7752 | TRY_CATCH (e, RETURN_MASK_ALL) |
7753 | { | |
58438ac1 | 7754 | parse_breakpoint_sals (&arg, &sals, &canonical); |
b78a6381 | 7755 | } |
0101ce28 JJ |
7756 | |
7757 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7758 | switch (e.reason) |
0101ce28 | 7759 | { |
05ff989b | 7760 | case RETURN_QUIT: |
98deb0da | 7761 | throw_exception (e); |
05ff989b AC |
7762 | case RETURN_ERROR: |
7763 | switch (e.error) | |
0101ce28 | 7764 | { |
05ff989b | 7765 | case NOT_FOUND_ERROR: |
0101ce28 | 7766 | |
05ff989b AC |
7767 | /* If pending breakpoint support is turned off, throw |
7768 | error. */ | |
fa8d40ab JJ |
7769 | |
7770 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7771 | throw_exception (e); |
7772 | ||
7773 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7774 | |
05ff989b AC |
7775 | /* If pending breakpoint support is auto query and the user |
7776 | selects no, then simply return the error code. */ | |
059fb39f | 7777 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
3e43a32a MS |
7778 | && !nquery (_("Make breakpoint pending on " |
7779 | "future shared library load? "))) | |
fd9b8c24 | 7780 | return 0; |
fa8d40ab | 7781 | |
05ff989b AC |
7782 | /* At this point, either the user was queried about setting |
7783 | a pending breakpoint and selected yes, or pending | |
7784 | breakpoint behavior is on and thus a pending breakpoint | |
7785 | is defaulted on behalf of the user. */ | |
0101ce28 | 7786 | copy_arg = xstrdup (addr_start); |
7efd8fc2 | 7787 | canonical.canonical = ©_arg; |
0101ce28 JJ |
7788 | sals.nelts = 1; |
7789 | sals.sals = &pending_sal; | |
7790 | pending_sal.pc = 0; | |
7791 | pending = 1; | |
05ff989b AC |
7792 | break; |
7793 | default: | |
98deb0da | 7794 | throw_exception (e); |
0101ce28 | 7795 | } |
2abae994 | 7796 | break; |
05ff989b AC |
7797 | default: |
7798 | if (!sals.nelts) | |
fd9b8c24 | 7799 | return 0; |
0101ce28 | 7800 | } |
c3f6f71d | 7801 | |
0fb4aa4b PA |
7802 | done: |
7803 | ||
4a64f543 | 7804 | /* Create a chain of things that always need to be cleaned up. */ |
c3f6f71d JM |
7805 | old_chain = make_cleanup (null_cleanup, 0); |
7806 | ||
0101ce28 JJ |
7807 | if (!pending) |
7808 | { | |
7809 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7810 | make_cleanup (xfree, sals.sals); | |
7811 | ||
7efd8fc2 TT |
7812 | /* Cleanup the canonical array but not its contents. */ |
7813 | make_cleanup (xfree, canonical.canonical); | |
0101ce28 | 7814 | } |
c3f6f71d | 7815 | |
c3f6f71d JM |
7816 | /* ----------------------------- SNIP ----------------------------- |
7817 | Anything added to the cleanup chain beyond this point is assumed | |
7818 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7819 | then the memory is not reclaimed. */ |
7820 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 7821 | |
7efd8fc2 | 7822 | /* Mark the contents of the canonical for cleanup. These go on |
80c99de1 | 7823 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7824 | for (i = 0; i < sals.nelts; i++) |
7825 | { | |
7efd8fc2 TT |
7826 | if (canonical.canonical[i] != NULL) |
7827 | make_cleanup (xfree, canonical.canonical[i]); | |
c3f6f71d JM |
7828 | } |
7829 | ||
7830 | /* Resolve all line numbers to PC's and verify that the addresses | |
7831 | are ok for the target. */ | |
0101ce28 | 7832 | if (!pending) |
23e7acfb | 7833 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 7834 | |
7a697b8d SS |
7835 | /* Fast tracepoints may have additional restrictions on location. */ |
7836 | if (type_wanted == bp_fast_tracepoint) | |
7837 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7838 | ||
c3f6f71d JM |
7839 | /* Verify that condition can be parsed, before setting any |
7840 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 7841 | breakpoint. */ |
0101ce28 | 7842 | if (!pending) |
c3f6f71d | 7843 | { |
2f069f6f | 7844 | if (parse_condition_and_thread) |
72b2ff0e VP |
7845 | { |
7846 | /* Here we only parse 'arg' to separate condition | |
7847 | from thread number, so parsing in context of first | |
7848 | sal is OK. When setting the breakpoint we'll | |
7849 | re-parse it in context of each sal. */ | |
7850 | cond_string = NULL; | |
7851 | thread = -1; | |
4a306c9a JB |
7852 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7853 | &thread, &task); | |
72b2ff0e VP |
7854 | if (cond_string) |
7855 | make_cleanup (xfree, cond_string); | |
7856 | } | |
2f069f6f | 7857 | else |
72b2ff0e VP |
7858 | { |
7859 | /* Create a private copy of condition string. */ | |
7860 | if (cond_string) | |
7861 | { | |
7862 | cond_string = xstrdup (cond_string); | |
7863 | make_cleanup (xfree, cond_string); | |
7864 | } | |
7865 | } | |
0fb4aa4b PA |
7866 | |
7867 | /* If the user is creating a static tracepoint by marker id | |
7868 | (strace -m MARKER_ID), then store the sals index, so that | |
7869 | breakpoint_re_set can try to match up which of the newly | |
7870 | found markers corresponds to this one, and, don't try to | |
7871 | expand multiple locations for each sal, given than SALS | |
7872 | already should contain all sals for MARKER_ID. */ | |
7873 | if (type_wanted == bp_static_tracepoint | |
7efd8fc2 | 7874 | && is_marker_spec (canonical.canonical[0])) |
0fb4aa4b PA |
7875 | { |
7876 | int i; | |
7877 | ||
7878 | for (i = 0; i < sals.nelts; ++i) | |
7879 | { | |
7880 | struct symtabs_and_lines expanded; | |
d9b3f62e | 7881 | struct tracepoint *tp; |
0fb4aa4b PA |
7882 | struct cleanup *old_chain; |
7883 | ||
7884 | expanded.nelts = 1; | |
7885 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7886 | expanded.sals[0] = sals.sals[i]; | |
7887 | old_chain = make_cleanup (xfree, expanded.sals); | |
7888 | ||
d9b3f62e PA |
7889 | tp = XCNEW (struct tracepoint); |
7890 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
7891 | canonical.canonical[i], | |
7892 | cond_string, type_wanted, | |
7893 | tempflag ? disp_del : disp_donttouch, | |
7894 | thread, task, ignore_count, ops, | |
7895 | from_tty, enabled, internal, | |
7896 | canonical.special_display); | |
0fb4aa4b PA |
7897 | /* Given that its possible to have multiple markers with |
7898 | the same string id, if the user is creating a static | |
7899 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
7900 | store the sals index, so that breakpoint_re_set can | |
7901 | try to match up which of the newly found markers | |
7902 | corresponds to this one */ | |
7903 | tp->static_trace_marker_id_idx = i; | |
d9b3f62e PA |
7904 | |
7905 | install_breakpoint (internal, &tp->base); | |
7906 | ||
7907 | do_cleanups (old_chain); | |
0fb4aa4b PA |
7908 | } |
7909 | } | |
7910 | else | |
7efd8fc2 | 7911 | create_breakpoints_sal (gdbarch, sals, &canonical, cond_string, |
3e43a32a MS |
7912 | type_wanted, |
7913 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 7914 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 7915 | enabled, internal); |
c906108c | 7916 | } |
0101ce28 JJ |
7917 | else |
7918 | { | |
0101ce28 JJ |
7919 | struct breakpoint *b; |
7920 | ||
0101ce28 JJ |
7921 | make_cleanup (xfree, copy_arg); |
7922 | ||
348d480f | 7923 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted, ops); |
84f4c1fe | 7924 | set_breakpoint_number (internal, b); |
72b2ff0e | 7925 | b->thread = -1; |
7efd8fc2 | 7926 | b->addr_string = canonical.canonical[0]; |
72b2ff0e | 7927 | b->cond_string = NULL; |
0101ce28 | 7928 | b->ignore_count = ignore_count; |
0101ce28 | 7929 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7930 | b->condition_not_parsed = 1; |
41447f92 | 7931 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 7932 | b->pspace = current_program_space; |
84f4c1fe | 7933 | b->py_bp_object = NULL; |
74960c60 | 7934 | |
6c95b8df | 7935 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7936 | && (b->type == bp_breakpoint |
7937 | || b->type == bp_hardware_breakpoint)) | |
7938 | b->enable_state = bp_startup_disabled; | |
7939 | ||
8d3788bd | 7940 | if (!internal) |
84f4c1fe PM |
7941 | /* Do not mention breakpoints with a negative number, |
7942 | but do notify observers. */ | |
8d3788bd VP |
7943 | mention (b); |
7944 | observer_notify_breakpoint_created (b); | |
0101ce28 JJ |
7945 | } |
7946 | ||
c3f6f71d | 7947 | if (sals.nelts > 1) |
95a42b64 | 7948 | { |
3e43a32a MS |
7949 | warning (_("Multiple breakpoints were set.\nUse the " |
7950 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 7951 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
7952 | } |
7953 | ||
80c99de1 PA |
7954 | /* That's it. Discard the cleanups for data inserted into the |
7955 | breakpoint. */ | |
7956 | discard_cleanups (bkpt_chain); | |
7957 | /* But cleanup everything else. */ | |
c3f6f71d | 7958 | do_cleanups (old_chain); |
217dc9e2 | 7959 | |
80c99de1 | 7960 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 7961 | update_global_location_list (1); |
fd9b8c24 PA |
7962 | |
7963 | return 1; | |
c3f6f71d | 7964 | } |
c906108c | 7965 | |
348d480f | 7966 | /* Set a breakpoint. |
72b2ff0e VP |
7967 | ARG is a string describing breakpoint address, |
7968 | condition, and thread. | |
7969 | FLAG specifies if a breakpoint is hardware on, | |
7970 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
7971 | and BP_TEMPFLAG. */ | |
348d480f | 7972 | |
98deb0da | 7973 | static void |
72b2ff0e | 7974 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 7975 | { |
72b2ff0e | 7976 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
7977 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
7978 | ? bp_hardware_breakpoint | |
7979 | : bp_breakpoint); | |
c3f6f71d | 7980 | |
8cdf0e15 VP |
7981 | create_breakpoint (get_current_arch (), |
7982 | arg, | |
7983 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 7984 | tempflag, type_wanted, |
8cdf0e15 VP |
7985 | 0 /* Ignore count */, |
7986 | pending_break_support, | |
348d480f | 7987 | &bkpt_breakpoint_ops, |
8cdf0e15 | 7988 | from_tty, |
84f4c1fe PM |
7989 | 1 /* enabled */, |
7990 | 0 /* internal */); | |
c906108c SS |
7991 | } |
7992 | ||
c906108c SS |
7993 | /* Helper function for break_command_1 and disassemble_command. */ |
7994 | ||
7995 | void | |
fba45db2 | 7996 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
7997 | { |
7998 | CORE_ADDR pc; | |
7999 | ||
8000 | if (sal->pc == 0 && sal->symtab != NULL) | |
8001 | { | |
8002 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8003 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8004 | sal->line, sal->symtab->filename); |
8005 | sal->pc = pc; | |
6a048695 | 8006 | |
4a64f543 MS |
8007 | /* If this SAL corresponds to a breakpoint inserted using a line |
8008 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8009 | if (sal->explicit_line) |
059acae7 | 8010 | skip_prologue_sal (sal); |
c906108c SS |
8011 | } |
8012 | ||
8013 | if (sal->section == 0 && sal->symtab != NULL) | |
8014 | { | |
8015 | struct blockvector *bv; | |
c5aa993b JM |
8016 | struct block *b; |
8017 | struct symbol *sym; | |
c906108c | 8018 | |
801e3a5b | 8019 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8020 | if (bv != NULL) |
8021 | { | |
7f0df278 | 8022 | sym = block_linkage_function (b); |
c906108c SS |
8023 | if (sym != NULL) |
8024 | { | |
8025 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8026 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8027 | } |
8028 | else | |
8029 | { | |
4a64f543 MS |
8030 | /* It really is worthwhile to have the section, so we'll |
8031 | just have to look harder. This case can be executed | |
8032 | if we have line numbers but no functions (as can | |
8033 | happen in assembly source). */ | |
c906108c | 8034 | |
c5aa993b | 8035 | struct minimal_symbol *msym; |
6c95b8df PA |
8036 | struct cleanup *old_chain = save_current_space_and_thread (); |
8037 | ||
8038 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8039 | |
8040 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8041 | if (msym) | |
714835d5 | 8042 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8043 | |
8044 | do_cleanups (old_chain); | |
c906108c SS |
8045 | } |
8046 | } | |
8047 | } | |
8048 | } | |
8049 | ||
8050 | void | |
fba45db2 | 8051 | break_command (char *arg, int from_tty) |
c906108c | 8052 | { |
db107f19 | 8053 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8054 | } |
8055 | ||
c906108c | 8056 | void |
fba45db2 | 8057 | tbreak_command (char *arg, int from_tty) |
c906108c | 8058 | { |
db107f19 | 8059 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8060 | } |
8061 | ||
c906108c | 8062 | static void |
fba45db2 | 8063 | hbreak_command (char *arg, int from_tty) |
c906108c | 8064 | { |
db107f19 | 8065 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8066 | } |
8067 | ||
8068 | static void | |
fba45db2 | 8069 | thbreak_command (char *arg, int from_tty) |
c906108c | 8070 | { |
db107f19 | 8071 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8072 | } |
8073 | ||
8074 | static void | |
fba45db2 | 8075 | stop_command (char *arg, int from_tty) |
c906108c | 8076 | { |
a3f17187 | 8077 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8078 | Usage: stop in <function | address>\n\ |
a3f17187 | 8079 | stop at <line>\n")); |
c906108c SS |
8080 | } |
8081 | ||
8082 | static void | |
fba45db2 | 8083 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8084 | { |
8085 | int badInput = 0; | |
8086 | ||
c5aa993b | 8087 | if (arg == (char *) NULL) |
c906108c SS |
8088 | badInput = 1; |
8089 | else if (*arg != '*') | |
8090 | { | |
8091 | char *argptr = arg; | |
8092 | int hasColon = 0; | |
8093 | ||
4a64f543 | 8094 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8095 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8096 | function/method name. */ |
c906108c | 8097 | while (*argptr && !hasColon) |
c5aa993b JM |
8098 | { |
8099 | hasColon = (*argptr == ':'); | |
8100 | argptr++; | |
8101 | } | |
c906108c SS |
8102 | |
8103 | if (hasColon) | |
c5aa993b | 8104 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8105 | else |
c5aa993b | 8106 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8107 | } |
8108 | ||
8109 | if (badInput) | |
a3f17187 | 8110 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8111 | else |
db107f19 | 8112 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8113 | } |
8114 | ||
8115 | static void | |
fba45db2 | 8116 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8117 | { |
8118 | int badInput = 0; | |
8119 | ||
c5aa993b | 8120 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8121 | badInput = 1; |
8122 | else | |
8123 | { | |
8124 | char *argptr = arg; | |
8125 | int hasColon = 0; | |
8126 | ||
4a64f543 MS |
8127 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8128 | it is probably a line number. */ | |
c906108c | 8129 | while (*argptr && !hasColon) |
c5aa993b JM |
8130 | { |
8131 | hasColon = (*argptr == ':'); | |
8132 | argptr++; | |
8133 | } | |
c906108c SS |
8134 | |
8135 | if (hasColon) | |
c5aa993b | 8136 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8137 | else |
c5aa993b | 8138 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8139 | } |
8140 | ||
8141 | if (badInput) | |
a3f17187 | 8142 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8143 | else |
db107f19 | 8144 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8145 | } |
8146 | ||
f1310107 TJB |
8147 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
8148 | ranged breakpoints. */ | |
8149 | ||
8150 | static int | |
8151 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
8152 | struct address_space *aspace, | |
8153 | CORE_ADDR bp_addr) | |
8154 | { | |
8155 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, | |
8156 | bl->length, aspace, bp_addr); | |
8157 | } | |
8158 | ||
8159 | /* Implement the "resources_needed" breakpoint_ops method for | |
8160 | ranged breakpoints. */ | |
8161 | ||
8162 | static int | |
8163 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
8164 | { | |
8165 | return target_ranged_break_num_registers (); | |
8166 | } | |
8167 | ||
8168 | /* Implement the "print_it" breakpoint_ops method for | |
8169 | ranged breakpoints. */ | |
8170 | ||
8171 | static enum print_stop_action | |
348d480f | 8172 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 8173 | { |
348d480f | 8174 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 8175 | struct bp_location *bl = b->loc; |
79a45e25 | 8176 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8177 | |
8178 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8179 | ||
8180 | /* Ranged breakpoints have only one location. */ | |
8181 | gdb_assert (bl && bl->next == NULL); | |
8182 | ||
8183 | annotate_breakpoint (b->number); | |
8184 | if (b->disposition == disp_del) | |
8185 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
8186 | else | |
8187 | ui_out_text (uiout, "\nRanged breakpoint "); | |
8188 | if (ui_out_is_mi_like_p (uiout)) | |
8189 | { | |
8190 | ui_out_field_string (uiout, "reason", | |
8191 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8192 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8193 | } | |
8194 | ui_out_field_int (uiout, "bkptno", b->number); | |
8195 | ui_out_text (uiout, ", "); | |
8196 | ||
8197 | return PRINT_SRC_AND_LOC; | |
8198 | } | |
8199 | ||
8200 | /* Implement the "print_one" breakpoint_ops method for | |
8201 | ranged breakpoints. */ | |
8202 | ||
8203 | static void | |
8204 | print_one_ranged_breakpoint (struct breakpoint *b, | |
8205 | struct bp_location **last_loc) | |
8206 | { | |
8207 | struct bp_location *bl = b->loc; | |
8208 | struct value_print_options opts; | |
79a45e25 | 8209 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8210 | |
8211 | /* Ranged breakpoints have only one location. */ | |
8212 | gdb_assert (bl && bl->next == NULL); | |
8213 | ||
8214 | get_user_print_options (&opts); | |
8215 | ||
8216 | if (opts.addressprint) | |
8217 | /* We don't print the address range here, it will be printed later | |
8218 | by print_one_detail_ranged_breakpoint. */ | |
8219 | ui_out_field_skip (uiout, "addr"); | |
8220 | annotate_field (5); | |
8221 | print_breakpoint_location (b, bl); | |
8222 | *last_loc = bl; | |
8223 | } | |
8224 | ||
8225 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8226 | ranged breakpoints. */ | |
8227 | ||
8228 | static void | |
8229 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
8230 | struct ui_out *uiout) | |
8231 | { | |
8232 | CORE_ADDR address_start, address_end; | |
8233 | struct bp_location *bl = b->loc; | |
8234 | struct ui_stream *stb = ui_out_stream_new (uiout); | |
8235 | struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb); | |
8236 | ||
8237 | gdb_assert (bl); | |
8238 | ||
8239 | address_start = bl->address; | |
8240 | address_end = address_start + bl->length - 1; | |
8241 | ||
8242 | ui_out_text (uiout, "\taddress range: "); | |
8243 | fprintf_unfiltered (stb->stream, "[%s, %s]", | |
8244 | print_core_address (bl->gdbarch, address_start), | |
8245 | print_core_address (bl->gdbarch, address_end)); | |
8246 | ui_out_field_stream (uiout, "addr", stb); | |
8247 | ui_out_text (uiout, "\n"); | |
8248 | ||
8249 | do_cleanups (cleanup); | |
8250 | } | |
8251 | ||
8252 | /* Implement the "print_mention" breakpoint_ops method for | |
8253 | ranged breakpoints. */ | |
8254 | ||
8255 | static void | |
8256 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
8257 | { | |
8258 | struct bp_location *bl = b->loc; | |
79a45e25 | 8259 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8260 | |
8261 | gdb_assert (bl); | |
8262 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8263 | ||
8264 | if (ui_out_is_mi_like_p (uiout)) | |
8265 | return; | |
8266 | ||
8267 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
8268 | b->number, paddress (bl->gdbarch, bl->address), | |
8269 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
8270 | } | |
8271 | ||
8272 | /* Implement the "print_recreate" breakpoint_ops method for | |
8273 | ranged breakpoints. */ | |
8274 | ||
8275 | static void | |
8276 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
8277 | { | |
8278 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
8279 | b->addr_string_range_end); | |
d9b3f62e | 8280 | print_recreate_thread (b, fp); |
f1310107 TJB |
8281 | } |
8282 | ||
8283 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
8284 | ||
2060206e | 8285 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
8286 | |
8287 | /* Find the address where the end of the breakpoint range should be | |
8288 | placed, given the SAL of the end of the range. This is so that if | |
8289 | the user provides a line number, the end of the range is set to the | |
8290 | last instruction of the given line. */ | |
8291 | ||
8292 | static CORE_ADDR | |
8293 | find_breakpoint_range_end (struct symtab_and_line sal) | |
8294 | { | |
8295 | CORE_ADDR end; | |
8296 | ||
8297 | /* If the user provided a PC value, use it. Otherwise, | |
8298 | find the address of the end of the given location. */ | |
8299 | if (sal.explicit_pc) | |
8300 | end = sal.pc; | |
8301 | else | |
8302 | { | |
8303 | int ret; | |
8304 | CORE_ADDR start; | |
8305 | ||
8306 | ret = find_line_pc_range (sal, &start, &end); | |
8307 | if (!ret) | |
8308 | error (_("Could not find location of the end of the range.")); | |
8309 | ||
8310 | /* find_line_pc_range returns the start of the next line. */ | |
8311 | end--; | |
8312 | } | |
8313 | ||
8314 | return end; | |
8315 | } | |
8316 | ||
8317 | /* Implement the "break-range" CLI command. */ | |
8318 | ||
8319 | static void | |
8320 | break_range_command (char *arg, int from_tty) | |
8321 | { | |
8322 | char *arg_start, *addr_string_start, *addr_string_end; | |
8323 | struct linespec_result canonical_start, canonical_end; | |
8324 | int bp_count, can_use_bp, length; | |
8325 | CORE_ADDR end; | |
8326 | struct breakpoint *b; | |
8327 | struct symtab_and_line sal_start, sal_end; | |
8328 | struct symtabs_and_lines sals_start, sals_end; | |
8329 | struct cleanup *cleanup_bkpt; | |
8330 | ||
8331 | /* We don't support software ranged breakpoints. */ | |
8332 | if (target_ranged_break_num_registers () < 0) | |
8333 | error (_("This target does not support hardware ranged breakpoints.")); | |
8334 | ||
8335 | bp_count = hw_breakpoint_used_count (); | |
8336 | bp_count += target_ranged_break_num_registers (); | |
8337 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
8338 | bp_count, 0); | |
8339 | if (can_use_bp < 0) | |
8340 | error (_("Hardware breakpoints used exceeds limit.")); | |
8341 | ||
8342 | if (arg == NULL || arg[0] == '\0') | |
8343 | error(_("No address range specified.")); | |
8344 | ||
8345 | sals_start.sals = NULL; | |
8346 | sals_start.nelts = 0; | |
8347 | init_linespec_result (&canonical_start); | |
8348 | ||
8349 | while (*arg == ' ' || *arg == '\t') | |
8350 | arg++; | |
8351 | ||
58438ac1 | 8352 | parse_breakpoint_sals (&arg, &sals_start, &canonical_start); |
f1310107 TJB |
8353 | |
8354 | sal_start = sals_start.sals[0]; | |
8355 | addr_string_start = canonical_start.canonical[0]; | |
8356 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); | |
8357 | xfree (sals_start.sals); | |
8358 | xfree (canonical_start.canonical); | |
8359 | ||
8360 | if (arg[0] != ',') | |
8361 | error (_("Too few arguments.")); | |
8362 | else if (sals_start.nelts == 0) | |
8363 | error (_("Could not find location of the beginning of the range.")); | |
8364 | else if (sals_start.nelts != 1) | |
8365 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8366 | ||
8367 | resolve_sal_pc (&sal_start); | |
8368 | ||
8369 | arg++; /* Skip the comma. */ | |
8370 | while (*arg == ' ' || *arg == '\t') | |
8371 | arg++; | |
8372 | ||
8373 | /* Parse the end location. */ | |
8374 | ||
8375 | sals_end.sals = NULL; | |
8376 | sals_end.nelts = 0; | |
8377 | init_linespec_result (&canonical_end); | |
8378 | arg_start = arg; | |
8379 | ||
423f41a5 | 8380 | /* We call decode_line_1 directly here instead of using |
f1310107 TJB |
8381 | parse_breakpoint_sals because we need to specify the start location's |
8382 | symtab and line as the default symtab and line for the end of the | |
8383 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
8384 | where +14 means 14 lines from the start location. */ | |
8385 | sals_end = decode_line_1 (&arg, 1, sal_start.symtab, sal_start.line, | |
58438ac1 | 8386 | &canonical_end); |
f1310107 TJB |
8387 | |
8388 | /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */ | |
8389 | if (canonical_end.canonical == NULL) | |
38a714bb | 8390 | canonical_end.canonical = xcalloc (1, sizeof (char *)); |
f1310107 TJB |
8391 | /* Add the string if not present. */ |
8392 | if (arg_start != arg && canonical_end.canonical[0] == NULL) | |
8393 | canonical_end.canonical[0] = savestring (arg_start, arg - arg_start); | |
8394 | ||
8395 | sal_end = sals_end.sals[0]; | |
8396 | addr_string_end = canonical_end.canonical[0]; | |
8397 | make_cleanup (xfree, addr_string_end); | |
8398 | xfree (sals_end.sals); | |
8399 | xfree (canonical_end.canonical); | |
8400 | ||
8401 | if (sals_end.nelts == 0) | |
8402 | error (_("Could not find location of the end of the range.")); | |
8403 | else if (sals_end.nelts != 1) | |
8404 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8405 | ||
8406 | resolve_sal_pc (&sal_end); | |
8407 | ||
8408 | end = find_breakpoint_range_end (sal_end); | |
8409 | if (sal_start.pc > end) | |
177b42fe | 8410 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
8411 | |
8412 | length = end - sal_start.pc + 1; | |
8413 | if (length < 0) | |
8414 | /* Length overflowed. */ | |
8415 | error (_("Address range too large.")); | |
8416 | else if (length == 1) | |
8417 | { | |
8418 | /* This range is simple enough to be handled by | |
8419 | the `hbreak' command. */ | |
8420 | hbreak_command (addr_string_start, 1); | |
8421 | ||
8422 | do_cleanups (cleanup_bkpt); | |
8423 | ||
8424 | return; | |
8425 | } | |
8426 | ||
8427 | /* Now set up the breakpoint. */ | |
8428 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 8429 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
8430 | set_breakpoint_count (breakpoint_count + 1); |
8431 | b->number = breakpoint_count; | |
8432 | b->disposition = disp_donttouch; | |
8433 | b->addr_string = addr_string_start; | |
8434 | b->addr_string_range_end = addr_string_end; | |
f1310107 TJB |
8435 | b->loc->length = length; |
8436 | ||
8437 | discard_cleanups (cleanup_bkpt); | |
8438 | ||
8439 | mention (b); | |
8d3788bd | 8440 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
8441 | update_global_location_list (1); |
8442 | } | |
8443 | ||
4a64f543 MS |
8444 | /* Return non-zero if EXP is verified as constant. Returned zero |
8445 | means EXP is variable. Also the constant detection may fail for | |
8446 | some constant expressions and in such case still falsely return | |
8447 | zero. */ | |
65d79d4b SDJ |
8448 | static int |
8449 | watchpoint_exp_is_const (const struct expression *exp) | |
8450 | { | |
8451 | int i = exp->nelts; | |
8452 | ||
8453 | while (i > 0) | |
8454 | { | |
8455 | int oplenp, argsp; | |
8456 | ||
8457 | /* We are only interested in the descriptor of each element. */ | |
8458 | operator_length (exp, i, &oplenp, &argsp); | |
8459 | i -= oplenp; | |
8460 | ||
8461 | switch (exp->elts[i].opcode) | |
8462 | { | |
8463 | case BINOP_ADD: | |
8464 | case BINOP_SUB: | |
8465 | case BINOP_MUL: | |
8466 | case BINOP_DIV: | |
8467 | case BINOP_REM: | |
8468 | case BINOP_MOD: | |
8469 | case BINOP_LSH: | |
8470 | case BINOP_RSH: | |
8471 | case BINOP_LOGICAL_AND: | |
8472 | case BINOP_LOGICAL_OR: | |
8473 | case BINOP_BITWISE_AND: | |
8474 | case BINOP_BITWISE_IOR: | |
8475 | case BINOP_BITWISE_XOR: | |
8476 | case BINOP_EQUAL: | |
8477 | case BINOP_NOTEQUAL: | |
8478 | case BINOP_LESS: | |
8479 | case BINOP_GTR: | |
8480 | case BINOP_LEQ: | |
8481 | case BINOP_GEQ: | |
8482 | case BINOP_REPEAT: | |
8483 | case BINOP_COMMA: | |
8484 | case BINOP_EXP: | |
8485 | case BINOP_MIN: | |
8486 | case BINOP_MAX: | |
8487 | case BINOP_INTDIV: | |
8488 | case BINOP_CONCAT: | |
8489 | case BINOP_IN: | |
8490 | case BINOP_RANGE: | |
8491 | case TERNOP_COND: | |
8492 | case TERNOP_SLICE: | |
8493 | case TERNOP_SLICE_COUNT: | |
8494 | ||
8495 | case OP_LONG: | |
8496 | case OP_DOUBLE: | |
8497 | case OP_DECFLOAT: | |
8498 | case OP_LAST: | |
8499 | case OP_COMPLEX: | |
8500 | case OP_STRING: | |
8501 | case OP_BITSTRING: | |
8502 | case OP_ARRAY: | |
8503 | case OP_TYPE: | |
8504 | case OP_NAME: | |
8505 | case OP_OBJC_NSSTRING: | |
8506 | ||
8507 | case UNOP_NEG: | |
8508 | case UNOP_LOGICAL_NOT: | |
8509 | case UNOP_COMPLEMENT: | |
8510 | case UNOP_ADDR: | |
8511 | case UNOP_HIGH: | |
4a64f543 MS |
8512 | /* Unary, binary and ternary operators: We have to check |
8513 | their operands. If they are constant, then so is the | |
8514 | result of that operation. For instance, if A and B are | |
8515 | determined to be constants, then so is "A + B". | |
8516 | ||
8517 | UNOP_IND is one exception to the rule above, because the | |
8518 | value of *ADDR is not necessarily a constant, even when | |
8519 | ADDR is. */ | |
65d79d4b SDJ |
8520 | break; |
8521 | ||
8522 | case OP_VAR_VALUE: | |
8523 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8524 | |
65d79d4b | 8525 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8526 | possible that a buggy compiler could mark a variable as |
8527 | constant even when it is not, and TYPE_CONST would return | |
8528 | true in this case, while SYMBOL_CLASS wouldn't. | |
8529 | ||
8530 | We also have to check for function symbols because they | |
8531 | are always constant. */ | |
65d79d4b SDJ |
8532 | { |
8533 | struct symbol *s = exp->elts[i + 2].symbol; | |
8534 | ||
8535 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8536 | && SYMBOL_CLASS (s) != LOC_CONST | |
8537 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8538 | return 0; | |
8539 | break; | |
8540 | } | |
8541 | ||
8542 | /* The default action is to return 0 because we are using | |
8543 | the optimistic approach here: If we don't know something, | |
8544 | then it is not a constant. */ | |
8545 | default: | |
8546 | return 0; | |
8547 | } | |
8548 | } | |
8549 | ||
8550 | return 1; | |
8551 | } | |
8552 | ||
3a5c3e22 PA |
8553 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
8554 | ||
8555 | static void | |
8556 | dtor_watchpoint (struct breakpoint *self) | |
8557 | { | |
8558 | struct watchpoint *w = (struct watchpoint *) self; | |
8559 | ||
8560 | xfree (w->cond_exp); | |
8561 | xfree (w->exp); | |
8562 | xfree (w->exp_string); | |
8563 | xfree (w->exp_string_reparse); | |
8564 | value_free (w->val); | |
8565 | ||
8566 | base_breakpoint_ops.dtor (self); | |
8567 | } | |
8568 | ||
348d480f PA |
8569 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
8570 | ||
8571 | static void | |
8572 | re_set_watchpoint (struct breakpoint *b) | |
8573 | { | |
3a5c3e22 PA |
8574 | struct watchpoint *w = (struct watchpoint *) b; |
8575 | ||
348d480f PA |
8576 | /* Watchpoint can be either on expression using entirely global |
8577 | variables, or it can be on local variables. | |
8578 | ||
8579 | Watchpoints of the first kind are never auto-deleted, and even | |
8580 | persist across program restarts. Since they can use variables | |
8581 | from shared libraries, we need to reparse expression as libraries | |
8582 | are loaded and unloaded. | |
8583 | ||
8584 | Watchpoints on local variables can also change meaning as result | |
8585 | of solib event. For example, if a watchpoint uses both a local | |
8586 | and a global variables in expression, it's a local watchpoint, | |
8587 | but unloading of a shared library will make the expression | |
8588 | invalid. This is not a very common use case, but we still | |
8589 | re-evaluate expression, to avoid surprises to the user. | |
8590 | ||
8591 | Note that for local watchpoints, we re-evaluate it only if | |
8592 | watchpoints frame id is still valid. If it's not, it means the | |
8593 | watchpoint is out of scope and will be deleted soon. In fact, | |
8594 | I'm not sure we'll ever be called in this case. | |
8595 | ||
8596 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 8597 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 8598 | |
3a5c3e22 PA |
8599 | Don't do anything about disabled watchpoints, since they will be |
8600 | reevaluated again when enabled. */ | |
8601 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
8602 | } |
8603 | ||
77b06cd7 TJB |
8604 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8605 | ||
8606 | static int | |
8607 | insert_watchpoint (struct bp_location *bl) | |
8608 | { | |
3a5c3e22 PA |
8609 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8610 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8611 | |
8612 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8613 | w->cond_exp); |
77b06cd7 TJB |
8614 | } |
8615 | ||
8616 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8617 | ||
8618 | static int | |
8619 | remove_watchpoint (struct bp_location *bl) | |
8620 | { | |
3a5c3e22 PA |
8621 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8622 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8623 | |
8624 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8625 | w->cond_exp); |
e09342b5 TJB |
8626 | } |
8627 | ||
e09342b5 | 8628 | static int |
348d480f PA |
8629 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
8630 | struct address_space *aspace, CORE_ADDR bp_addr) | |
e09342b5 | 8631 | { |
348d480f | 8632 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 8633 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 8634 | |
348d480f PA |
8635 | /* Continuable hardware watchpoints are treated as non-existent if the |
8636 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
8637 | some data address). Otherwise gdb won't stop on a break instruction | |
8638 | in the code (not from a breakpoint) when a hardware watchpoint has | |
8639 | been defined. Also skip watchpoints which we know did not trigger | |
8640 | (did not match the data address). */ | |
8641 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 8642 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 8643 | return 0; |
9c06b0b4 | 8644 | |
348d480f | 8645 | return 1; |
9c06b0b4 TJB |
8646 | } |
8647 | ||
348d480f PA |
8648 | static void |
8649 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 8650 | { |
348d480f | 8651 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 8652 | |
348d480f | 8653 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
8654 | } |
8655 | ||
8656 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 8657 | hardware watchpoints. */ |
9c06b0b4 TJB |
8658 | |
8659 | static int | |
348d480f | 8660 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 8661 | { |
3a5c3e22 PA |
8662 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8663 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
8664 | |
8665 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
8666 | } |
8667 | ||
8668 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 8669 | hardware watchpoints. */ |
9c06b0b4 TJB |
8670 | |
8671 | static int | |
348d480f | 8672 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 8673 | { |
efa80663 PA |
8674 | /* Read and access watchpoints only work with hardware support. */ |
8675 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
8676 | } |
8677 | ||
9c06b0b4 | 8678 | static enum print_stop_action |
348d480f | 8679 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 8680 | { |
348d480f PA |
8681 | struct cleanup *old_chain; |
8682 | struct breakpoint *b; | |
8683 | const struct bp_location *bl; | |
8684 | struct ui_stream *stb; | |
8685 | enum print_stop_action result; | |
3a5c3e22 | 8686 | struct watchpoint *w; |
79a45e25 | 8687 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8688 | |
8689 | gdb_assert (bs->bp_location_at != NULL); | |
8690 | ||
8691 | bl = bs->bp_location_at; | |
8692 | b = bs->breakpoint_at; | |
3a5c3e22 | 8693 | w = (struct watchpoint *) b; |
348d480f PA |
8694 | |
8695 | stb = ui_out_stream_new (uiout); | |
8696 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
9c06b0b4 TJB |
8697 | |
8698 | switch (b->type) | |
8699 | { | |
348d480f | 8700 | case bp_watchpoint: |
9c06b0b4 TJB |
8701 | case bp_hardware_watchpoint: |
8702 | annotate_watchpoint (b->number); | |
8703 | if (ui_out_is_mi_like_p (uiout)) | |
8704 | ui_out_field_string | |
8705 | (uiout, "reason", | |
8706 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
8707 | mention (b); |
8708 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8709 | ui_out_text (uiout, "\nOld value = "); | |
8710 | watchpoint_value_print (bs->old_val, stb->stream); | |
8711 | ui_out_field_stream (uiout, "old", stb); | |
8712 | ui_out_text (uiout, "\nNew value = "); | |
3a5c3e22 | 8713 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8714 | ui_out_field_stream (uiout, "new", stb); |
8715 | ui_out_text (uiout, "\n"); | |
8716 | /* More than one watchpoint may have been triggered. */ | |
8717 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8718 | break; |
8719 | ||
8720 | case bp_read_watchpoint: | |
8721 | if (ui_out_is_mi_like_p (uiout)) | |
8722 | ui_out_field_string | |
8723 | (uiout, "reason", | |
8724 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
8725 | mention (b); |
8726 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8727 | ui_out_text (uiout, "\nValue = "); | |
3a5c3e22 | 8728 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8729 | ui_out_field_stream (uiout, "value", stb); |
8730 | ui_out_text (uiout, "\n"); | |
8731 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8732 | break; |
8733 | ||
8734 | case bp_access_watchpoint: | |
348d480f PA |
8735 | if (bs->old_val != NULL) |
8736 | { | |
8737 | annotate_watchpoint (b->number); | |
8738 | if (ui_out_is_mi_like_p (uiout)) | |
8739 | ui_out_field_string | |
8740 | (uiout, "reason", | |
8741 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8742 | mention (b); | |
8743 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8744 | ui_out_text (uiout, "\nOld value = "); | |
8745 | watchpoint_value_print (bs->old_val, stb->stream); | |
8746 | ui_out_field_stream (uiout, "old", stb); | |
8747 | ui_out_text (uiout, "\nNew value = "); | |
8748 | } | |
8749 | else | |
8750 | { | |
8751 | mention (b); | |
8752 | if (ui_out_is_mi_like_p (uiout)) | |
8753 | ui_out_field_string | |
8754 | (uiout, "reason", | |
8755 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8756 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8757 | ui_out_text (uiout, "\nValue = "); | |
8758 | } | |
3a5c3e22 | 8759 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8760 | ui_out_field_stream (uiout, "new", stb); |
8761 | ui_out_text (uiout, "\n"); | |
8762 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8763 | break; |
8764 | default: | |
348d480f | 8765 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
8766 | } |
8767 | ||
348d480f PA |
8768 | do_cleanups (old_chain); |
8769 | return result; | |
8770 | } | |
8771 | ||
8772 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
8773 | watchpoints. */ | |
8774 | ||
8775 | static void | |
8776 | print_mention_watchpoint (struct breakpoint *b) | |
8777 | { | |
8778 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 8779 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 8780 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8781 | |
8782 | switch (b->type) | |
8783 | { | |
8784 | case bp_watchpoint: | |
8785 | ui_out_text (uiout, "Watchpoint "); | |
8786 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8787 | break; | |
8788 | case bp_hardware_watchpoint: | |
8789 | ui_out_text (uiout, "Hardware watchpoint "); | |
8790 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8791 | break; | |
8792 | case bp_read_watchpoint: | |
8793 | ui_out_text (uiout, "Hardware read watchpoint "); | |
8794 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
8795 | break; | |
8796 | case bp_access_watchpoint: | |
8797 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
8798 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
8799 | break; | |
8800 | default: | |
8801 | internal_error (__FILE__, __LINE__, | |
8802 | _("Invalid hardware watchpoint type.")); | |
8803 | } | |
8804 | ||
8805 | ui_out_field_int (uiout, "number", b->number); | |
8806 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 8807 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
8808 | do_cleanups (ui_out_chain); |
8809 | } | |
8810 | ||
8811 | /* Implement the "print_recreate" breakpoint_ops method for | |
8812 | watchpoints. */ | |
8813 | ||
8814 | static void | |
8815 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
8816 | { | |
3a5c3e22 PA |
8817 | struct watchpoint *w = (struct watchpoint *) b; |
8818 | ||
348d480f PA |
8819 | switch (b->type) |
8820 | { | |
8821 | case bp_watchpoint: | |
8822 | case bp_hardware_watchpoint: | |
8823 | fprintf_unfiltered (fp, "watch"); | |
8824 | break; | |
8825 | case bp_read_watchpoint: | |
8826 | fprintf_unfiltered (fp, "rwatch"); | |
8827 | break; | |
8828 | case bp_access_watchpoint: | |
8829 | fprintf_unfiltered (fp, "awatch"); | |
8830 | break; | |
8831 | default: | |
8832 | internal_error (__FILE__, __LINE__, | |
8833 | _("Invalid watchpoint type.")); | |
8834 | } | |
8835 | ||
3a5c3e22 | 8836 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 8837 | print_recreate_thread (b, fp); |
348d480f PA |
8838 | } |
8839 | ||
8840 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
8841 | ||
2060206e | 8842 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
8843 | |
8844 | /* Implement the "insert" breakpoint_ops method for | |
8845 | masked hardware watchpoints. */ | |
8846 | ||
8847 | static int | |
8848 | insert_masked_watchpoint (struct bp_location *bl) | |
8849 | { | |
3a5c3e22 PA |
8850 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8851 | ||
8852 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
8853 | bl->watchpoint_type); |
8854 | } | |
8855 | ||
8856 | /* Implement the "remove" breakpoint_ops method for | |
8857 | masked hardware watchpoints. */ | |
8858 | ||
8859 | static int | |
8860 | remove_masked_watchpoint (struct bp_location *bl) | |
8861 | { | |
3a5c3e22 PA |
8862 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8863 | ||
8864 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
8865 | bl->watchpoint_type); |
8866 | } | |
8867 | ||
8868 | /* Implement the "resources_needed" breakpoint_ops method for | |
8869 | masked hardware watchpoints. */ | |
8870 | ||
8871 | static int | |
8872 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
8873 | { | |
3a5c3e22 PA |
8874 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8875 | ||
8876 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
8877 | } |
8878 | ||
8879 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
8880 | masked hardware watchpoints. */ | |
8881 | ||
8882 | static int | |
8883 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
8884 | { | |
8885 | return 0; | |
8886 | } | |
8887 | ||
8888 | /* Implement the "print_it" breakpoint_ops method for | |
8889 | masked hardware watchpoints. */ | |
8890 | ||
8891 | static enum print_stop_action | |
8892 | print_it_masked_watchpoint (bpstat bs) | |
8893 | { | |
8894 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 8895 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8896 | |
8897 | /* Masked watchpoints have only one location. */ | |
8898 | gdb_assert (b->loc && b->loc->next == NULL); | |
8899 | ||
8900 | switch (b->type) | |
8901 | { | |
8902 | case bp_hardware_watchpoint: | |
8903 | annotate_watchpoint (b->number); | |
8904 | if (ui_out_is_mi_like_p (uiout)) | |
8905 | ui_out_field_string | |
8906 | (uiout, "reason", | |
8907 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
8908 | break; | |
8909 | ||
8910 | case bp_read_watchpoint: | |
8911 | if (ui_out_is_mi_like_p (uiout)) | |
8912 | ui_out_field_string | |
8913 | (uiout, "reason", | |
8914 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
8915 | break; | |
8916 | ||
8917 | case bp_access_watchpoint: | |
8918 | if (ui_out_is_mi_like_p (uiout)) | |
8919 | ui_out_field_string | |
8920 | (uiout, "reason", | |
8921 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8922 | break; | |
8923 | default: | |
8924 | internal_error (__FILE__, __LINE__, | |
8925 | _("Invalid hardware watchpoint type.")); | |
8926 | } | |
8927 | ||
8928 | mention (b); | |
9c06b0b4 TJB |
8929 | ui_out_text (uiout, _("\n\ |
8930 | Check the underlying instruction at PC for the memory\n\ | |
8931 | address and value which triggered this watchpoint.\n")); | |
8932 | ui_out_text (uiout, "\n"); | |
8933 | ||
8934 | /* More than one watchpoint may have been triggered. */ | |
8935 | return PRINT_UNKNOWN; | |
8936 | } | |
8937 | ||
8938 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8939 | masked hardware watchpoints. */ | |
8940 | ||
8941 | static void | |
8942 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
8943 | struct ui_out *uiout) | |
8944 | { | |
3a5c3e22 PA |
8945 | struct watchpoint *w = (struct watchpoint *) b; |
8946 | ||
9c06b0b4 TJB |
8947 | /* Masked watchpoints have only one location. */ |
8948 | gdb_assert (b->loc && b->loc->next == NULL); | |
8949 | ||
8950 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 8951 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
8952 | ui_out_text (uiout, "\n"); |
8953 | } | |
8954 | ||
8955 | /* Implement the "print_mention" breakpoint_ops method for | |
8956 | masked hardware watchpoints. */ | |
8957 | ||
8958 | static void | |
8959 | print_mention_masked_watchpoint (struct breakpoint *b) | |
8960 | { | |
3a5c3e22 | 8961 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 8962 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
8963 | struct cleanup *ui_out_chain; |
8964 | ||
8965 | switch (b->type) | |
8966 | { | |
8967 | case bp_hardware_watchpoint: | |
8968 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
8969 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8970 | break; | |
8971 | case bp_read_watchpoint: | |
8972 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
8973 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
8974 | break; | |
8975 | case bp_access_watchpoint: | |
8976 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
8977 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
8978 | break; | |
8979 | default: | |
8980 | internal_error (__FILE__, __LINE__, | |
8981 | _("Invalid hardware watchpoint type.")); | |
8982 | } | |
8983 | ||
8984 | ui_out_field_int (uiout, "number", b->number); | |
8985 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 8986 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
8987 | do_cleanups (ui_out_chain); |
8988 | } | |
8989 | ||
8990 | /* Implement the "print_recreate" breakpoint_ops method for | |
8991 | masked hardware watchpoints. */ | |
8992 | ||
8993 | static void | |
8994 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
8995 | { | |
3a5c3e22 | 8996 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
8997 | char tmp[40]; |
8998 | ||
8999 | switch (b->type) | |
9000 | { | |
9001 | case bp_hardware_watchpoint: | |
9002 | fprintf_unfiltered (fp, "watch"); | |
9003 | break; | |
9004 | case bp_read_watchpoint: | |
9005 | fprintf_unfiltered (fp, "rwatch"); | |
9006 | break; | |
9007 | case bp_access_watchpoint: | |
9008 | fprintf_unfiltered (fp, "awatch"); | |
9009 | break; | |
9010 | default: | |
9011 | internal_error (__FILE__, __LINE__, | |
9012 | _("Invalid hardware watchpoint type.")); | |
9013 | } | |
9014 | ||
3a5c3e22 PA |
9015 | sprintf_vma (tmp, w->hw_wp_mask); |
9016 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 9017 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
9018 | } |
9019 | ||
9020 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
9021 | ||
2060206e | 9022 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
9023 | |
9024 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
9025 | ||
9026 | static int | |
9027 | is_masked_watchpoint (const struct breakpoint *b) | |
9028 | { | |
9029 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
9030 | } | |
9031 | ||
53a5351d JM |
9032 | /* accessflag: hw_write: watch write, |
9033 | hw_read: watch read, | |
9034 | hw_access: watch access (read or write) */ | |
c906108c | 9035 | static void |
84f4c1fe PM |
9036 | watch_command_1 (char *arg, int accessflag, int from_tty, |
9037 | int just_location, int internal) | |
c906108c | 9038 | { |
a9634178 | 9039 | volatile struct gdb_exception e; |
d983da9c | 9040 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 9041 | struct expression *exp; |
60e1c644 | 9042 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 9043 | struct value *val, *mark, *result; |
c906108c | 9044 | struct frame_info *frame; |
c906108c SS |
9045 | char *exp_start = NULL; |
9046 | char *exp_end = NULL; | |
9c06b0b4 TJB |
9047 | char *tok, *end_tok; |
9048 | int toklen = -1; | |
c906108c SS |
9049 | char *cond_start = NULL; |
9050 | char *cond_end = NULL; | |
c906108c | 9051 | enum bptype bp_type; |
37e4754d | 9052 | int thread = -1; |
0cf6dd15 | 9053 | int pc = 0; |
9c06b0b4 TJB |
9054 | /* Flag to indicate whether we are going to use masks for |
9055 | the hardware watchpoint. */ | |
9056 | int use_mask = 0; | |
9057 | CORE_ADDR mask = 0; | |
3a5c3e22 | 9058 | struct watchpoint *w; |
c906108c | 9059 | |
37e4754d LM |
9060 | /* Make sure that we actually have parameters to parse. */ |
9061 | if (arg != NULL && arg[0] != '\0') | |
9062 | { | |
9c06b0b4 | 9063 | char *value_start; |
37e4754d | 9064 | |
9c06b0b4 TJB |
9065 | /* Look for "parameter value" pairs at the end |
9066 | of the arguments string. */ | |
9067 | for (tok = arg + strlen (arg) - 1; tok > arg; tok--) | |
9068 | { | |
9069 | /* Skip whitespace at the end of the argument list. */ | |
9070 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9071 | tok--; | |
9072 | ||
9073 | /* Find the beginning of the last token. | |
9074 | This is the value of the parameter. */ | |
9075 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9076 | tok--; | |
9077 | value_start = tok + 1; | |
9078 | ||
9079 | /* Skip whitespace. */ | |
9080 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9081 | tok--; | |
9082 | ||
9083 | end_tok = tok; | |
9084 | ||
9085 | /* Find the beginning of the second to last token. | |
9086 | This is the parameter itself. */ | |
9087 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9088 | tok--; | |
9089 | tok++; | |
9090 | toklen = end_tok - tok + 1; | |
9091 | ||
9092 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
9093 | { | |
9094 | /* At this point we've found a "thread" token, which means | |
9095 | the user is trying to set a watchpoint that triggers | |
9096 | only in a specific thread. */ | |
9097 | char *endp; | |
37e4754d | 9098 | |
9c06b0b4 TJB |
9099 | if (thread != -1) |
9100 | error(_("You can specify only one thread.")); | |
37e4754d | 9101 | |
9c06b0b4 TJB |
9102 | /* Extract the thread ID from the next token. */ |
9103 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 9104 | |
9c06b0b4 TJB |
9105 | /* Check if the user provided a valid numeric value for the |
9106 | thread ID. */ | |
9107 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
9108 | error (_("Invalid thread ID specification %s."), value_start); | |
9109 | ||
9110 | /* Check if the thread actually exists. */ | |
9111 | if (!valid_thread_id (thread)) | |
9112 | error (_("Unknown thread %d."), thread); | |
9113 | } | |
9114 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
9115 | { | |
9116 | /* We've found a "mask" token, which means the user wants to | |
9117 | create a hardware watchpoint that is going to have the mask | |
9118 | facility. */ | |
9119 | struct value *mask_value, *mark; | |
37e4754d | 9120 | |
9c06b0b4 TJB |
9121 | if (use_mask) |
9122 | error(_("You can specify only one mask.")); | |
37e4754d | 9123 | |
9c06b0b4 | 9124 | use_mask = just_location = 1; |
37e4754d | 9125 | |
9c06b0b4 TJB |
9126 | mark = value_mark (); |
9127 | mask_value = parse_to_comma_and_eval (&value_start); | |
9128 | mask = value_as_address (mask_value); | |
9129 | value_free_to_mark (mark); | |
9130 | } | |
9131 | else | |
9132 | /* We didn't recognize what we found. We should stop here. */ | |
9133 | break; | |
37e4754d | 9134 | |
9c06b0b4 TJB |
9135 | /* Truncate the string and get rid of the "parameter value" pair before |
9136 | the arguments string is parsed by the parse_exp_1 function. */ | |
9137 | *tok = '\0'; | |
9138 | } | |
37e4754d LM |
9139 | } |
9140 | ||
9141 | /* Parse the rest of the arguments. */ | |
c906108c SS |
9142 | innermost_block = NULL; |
9143 | exp_start = arg; | |
9144 | exp = parse_exp_1 (&arg, 0, 0); | |
9145 | exp_end = arg; | |
fa8a61dc TT |
9146 | /* Remove trailing whitespace from the expression before saving it. |
9147 | This makes the eventual display of the expression string a bit | |
9148 | prettier. */ | |
9149 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
9150 | --exp_end; | |
9151 | ||
65d79d4b SDJ |
9152 | /* Checking if the expression is not constant. */ |
9153 | if (watchpoint_exp_is_const (exp)) | |
9154 | { | |
9155 | int len; | |
9156 | ||
9157 | len = exp_end - exp_start; | |
9158 | while (len > 0 && isspace (exp_start[len - 1])) | |
9159 | len--; | |
9160 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
9161 | } | |
9162 | ||
c906108c SS |
9163 | exp_valid_block = innermost_block; |
9164 | mark = value_mark (); | |
a1442452 | 9165 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
9166 | |
9167 | if (just_location) | |
9168 | { | |
9c06b0b4 TJB |
9169 | int ret; |
9170 | ||
06a64a0b | 9171 | exp_valid_block = NULL; |
a1442452 | 9172 | val = value_addr (result); |
06a64a0b TT |
9173 | release_value (val); |
9174 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
9175 | |
9176 | if (use_mask) | |
9177 | { | |
9178 | ret = target_masked_watch_num_registers (value_as_address (val), | |
9179 | mask); | |
9180 | if (ret == -1) | |
9181 | error (_("This target does not support masked watchpoints.")); | |
9182 | else if (ret == -2) | |
9183 | error (_("Invalid mask or memory region.")); | |
9184 | } | |
06a64a0b TT |
9185 | } |
9186 | else if (val != NULL) | |
fa4727a6 | 9187 | release_value (val); |
c906108c | 9188 | |
e9cafbcc TT |
9189 | tok = skip_spaces (arg); |
9190 | end_tok = skip_to_space (tok); | |
c906108c SS |
9191 | |
9192 | toklen = end_tok - tok; | |
9193 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
9194 | { | |
2d134ed3 PA |
9195 | struct expression *cond; |
9196 | ||
60e1c644 | 9197 | innermost_block = NULL; |
c906108c SS |
9198 | tok = cond_start = end_tok + 1; |
9199 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
9200 | |
9201 | /* The watchpoint expression may not be local, but the condition | |
9202 | may still be. E.g.: `watch global if local > 0'. */ | |
9203 | cond_exp_valid_block = innermost_block; | |
9204 | ||
2d134ed3 | 9205 | xfree (cond); |
c906108c SS |
9206 | cond_end = tok; |
9207 | } | |
9208 | if (*tok) | |
8a3fe4f8 | 9209 | error (_("Junk at end of command.")); |
c906108c | 9210 | |
53a5351d | 9211 | if (accessflag == hw_read) |
c5aa993b | 9212 | bp_type = bp_read_watchpoint; |
53a5351d | 9213 | else if (accessflag == hw_access) |
c5aa993b JM |
9214 | bp_type = bp_access_watchpoint; |
9215 | else | |
9216 | bp_type = bp_hardware_watchpoint; | |
c906108c | 9217 | |
d983da9c | 9218 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
9219 | |
9220 | /* If the expression is "local", then set up a "watchpoint scope" | |
9221 | breakpoint at the point where we've left the scope of the watchpoint | |
9222 | expression. Create the scope breakpoint before the watchpoint, so | |
9223 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 9224 | if (exp_valid_block && frame) |
d983da9c | 9225 | { |
edb3359d DJ |
9226 | if (frame_id_p (frame_unwind_caller_id (frame))) |
9227 | { | |
9228 | scope_breakpoint | |
a6d9a66e UW |
9229 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
9230 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
9231 | bp_watchpoint_scope, |
9232 | &momentary_breakpoint_ops); | |
d983da9c | 9233 | |
edb3359d | 9234 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 9235 | |
edb3359d DJ |
9236 | /* Automatically delete the breakpoint when it hits. */ |
9237 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 9238 | |
edb3359d DJ |
9239 | /* Only break in the proper frame (help with recursion). */ |
9240 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 9241 | |
edb3359d | 9242 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
9243 | scope_breakpoint->loc->gdbarch |
9244 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
9245 | scope_breakpoint->loc->requested_address |
9246 | = frame_unwind_caller_pc (frame); | |
9247 | scope_breakpoint->loc->address | |
a6d9a66e UW |
9248 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
9249 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
9250 | scope_breakpoint->type); |
9251 | } | |
d983da9c DJ |
9252 | } |
9253 | ||
c906108c | 9254 | /* Now set up the breakpoint. */ |
3a5c3e22 PA |
9255 | |
9256 | w = XCNEW (struct watchpoint); | |
9257 | b = &w->base; | |
348d480f | 9258 | if (use_mask) |
3a5c3e22 PA |
9259 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9260 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 9261 | else |
3a5c3e22 PA |
9262 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9263 | &watchpoint_breakpoint_ops); | |
37e4754d | 9264 | b->thread = thread; |
b5de0fa7 | 9265 | b->disposition = disp_donttouch; |
348d480f | 9266 | b->pspace = current_program_space; |
3a5c3e22 PA |
9267 | w->exp = exp; |
9268 | w->exp_valid_block = exp_valid_block; | |
9269 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
9270 | if (just_location) |
9271 | { | |
9272 | struct type *t = value_type (val); | |
9273 | CORE_ADDR addr = value_as_address (val); | |
9274 | char *name; | |
9275 | ||
9276 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
9277 | name = type_to_string (t); | |
9278 | ||
3a5c3e22 | 9279 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 9280 | core_addr_to_string (addr)); |
06a64a0b TT |
9281 | xfree (name); |
9282 | ||
3a5c3e22 | 9283 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
9284 | (int) (exp_end - exp_start), exp_start); |
9285 | ||
06a64a0b TT |
9286 | /* The above expression is in C. */ |
9287 | b->language = language_c; | |
9288 | } | |
9289 | else | |
3a5c3e22 | 9290 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
9291 | |
9292 | if (use_mask) | |
9293 | { | |
3a5c3e22 | 9294 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
9295 | } |
9296 | else | |
9297 | { | |
3a5c3e22 PA |
9298 | w->val = val; |
9299 | w->val_valid = 1; | |
9c06b0b4 | 9300 | } |
77b06cd7 | 9301 | |
c906108c SS |
9302 | if (cond_start) |
9303 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
9304 | else | |
9305 | b->cond_string = 0; | |
c5aa993b | 9306 | |
c906108c | 9307 | if (frame) |
f6bc2008 | 9308 | { |
3a5c3e22 PA |
9309 | w->watchpoint_frame = get_frame_id (frame); |
9310 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 9311 | } |
c906108c | 9312 | else |
f6bc2008 | 9313 | { |
3a5c3e22 PA |
9314 | w->watchpoint_frame = null_frame_id; |
9315 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 9316 | } |
c906108c | 9317 | |
d983da9c | 9318 | if (scope_breakpoint != NULL) |
c906108c | 9319 | { |
d983da9c DJ |
9320 | /* The scope breakpoint is related to the watchpoint. We will |
9321 | need to act on them together. */ | |
9322 | b->related_breakpoint = scope_breakpoint; | |
9323 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 9324 | } |
d983da9c | 9325 | |
06a64a0b TT |
9326 | if (!just_location) |
9327 | value_free_to_mark (mark); | |
2d134ed3 | 9328 | |
a9634178 TJB |
9329 | TRY_CATCH (e, RETURN_MASK_ALL) |
9330 | { | |
9331 | /* Finally update the new watchpoint. This creates the locations | |
9332 | that should be inserted. */ | |
3a5c3e22 | 9333 | update_watchpoint (w, 1); |
a9634178 TJB |
9334 | } |
9335 | if (e.reason < 0) | |
9336 | { | |
9337 | delete_breakpoint (b); | |
9338 | throw_exception (e); | |
9339 | } | |
9340 | ||
3a5c3e22 | 9341 | install_breakpoint (internal, b); |
c906108c SS |
9342 | } |
9343 | ||
e09342b5 | 9344 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 9345 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 9346 | |
c906108c | 9347 | static int |
a9634178 | 9348 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
9349 | { |
9350 | int found_memory_cnt = 0; | |
2e70b7b9 | 9351 | struct value *head = v; |
c906108c SS |
9352 | |
9353 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 9354 | if (!can_use_hw_watchpoints) |
c906108c | 9355 | return 0; |
c5aa993b | 9356 | |
5c44784c JM |
9357 | /* Make sure that the value of the expression depends only upon |
9358 | memory contents, and values computed from them within GDB. If we | |
9359 | find any register references or function calls, we can't use a | |
9360 | hardware watchpoint. | |
9361 | ||
9362 | The idea here is that evaluating an expression generates a series | |
9363 | of values, one holding the value of every subexpression. (The | |
9364 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
9365 | a*b+c.) GDB's values hold almost enough information to establish | |
9366 | the criteria given above --- they identify memory lvalues, | |
9367 | register lvalues, computed values, etcetera. So we can evaluate | |
9368 | the expression, and then scan the chain of values that leaves | |
9369 | behind to decide whether we can detect any possible change to the | |
9370 | expression's final value using only hardware watchpoints. | |
9371 | ||
9372 | However, I don't think that the values returned by inferior | |
9373 | function calls are special in any way. So this function may not | |
9374 | notice that an expression involving an inferior function call | |
9375 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 9376 | for (; v; v = value_next (v)) |
c906108c | 9377 | { |
5c44784c | 9378 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 9379 | { |
8464be76 DJ |
9380 | if (v != head && value_lazy (v)) |
9381 | /* A lazy memory lvalue in the chain is one that GDB never | |
9382 | needed to fetch; we either just used its address (e.g., | |
9383 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
9384 | in `a,b'). This doesn't apply to HEAD; if that is | |
9385 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 9386 | ; |
53a5351d | 9387 | else |
5c44784c JM |
9388 | { |
9389 | /* Ahh, memory we actually used! Check if we can cover | |
9390 | it with hardware watchpoints. */ | |
df407dfe | 9391 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
9392 | |
9393 | /* We only watch structs and arrays if user asked for it | |
9394 | explicitly, never if they just happen to appear in a | |
9395 | middle of some value chain. */ | |
9396 | if (v == head | |
9397 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
9398 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
9399 | { | |
42ae5230 | 9400 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
9401 | int len; |
9402 | int num_regs; | |
9403 | ||
a9634178 | 9404 | len = (target_exact_watchpoints |
e09342b5 TJB |
9405 | && is_scalar_type_recursive (vtype))? |
9406 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 9407 | |
e09342b5 TJB |
9408 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
9409 | if (!num_regs) | |
2e70b7b9 MS |
9410 | return 0; |
9411 | else | |
e09342b5 | 9412 | found_memory_cnt += num_regs; |
2e70b7b9 | 9413 | } |
5c44784c | 9414 | } |
c5aa993b | 9415 | } |
5086187c AC |
9416 | else if (VALUE_LVAL (v) != not_lval |
9417 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 9418 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 9419 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 9420 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
9421 | } |
9422 | ||
9423 | /* The expression itself looks suitable for using a hardware | |
9424 | watchpoint, but give the target machine a chance to reject it. */ | |
9425 | return found_memory_cnt; | |
9426 | } | |
9427 | ||
8b93c638 | 9428 | void |
84f4c1fe | 9429 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9430 | { |
84f4c1fe | 9431 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
9432 | } |
9433 | ||
9434 | /* A helper function that looks for an argument at the start of a | |
9435 | string. The argument must also either be at the end of the string, | |
9436 | or be followed by whitespace. Returns 1 if it finds the argument, | |
9437 | 0 otherwise. If the argument is found, it updates *STR. */ | |
9438 | ||
9439 | static int | |
9440 | check_for_argument (char **str, char *arg, int arg_len) | |
9441 | { | |
9442 | if (strncmp (*str, arg, arg_len) == 0 | |
9443 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
9444 | { | |
9445 | *str += arg_len; | |
9446 | return 1; | |
9447 | } | |
9448 | return 0; | |
9449 | } | |
9450 | ||
9451 | /* A helper function that looks for the "-location" argument and then | |
9452 | calls watch_command_1. */ | |
9453 | ||
9454 | static void | |
9455 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
9456 | { | |
9457 | int just_location = 0; | |
9458 | ||
9459 | if (arg | |
9460 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
9461 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
9462 | { | |
e9cafbcc | 9463 | arg = skip_spaces (arg); |
06a64a0b TT |
9464 | just_location = 1; |
9465 | } | |
9466 | ||
84f4c1fe | 9467 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 9468 | } |
8926118c | 9469 | |
c5aa993b | 9470 | static void |
fba45db2 | 9471 | watch_command (char *arg, int from_tty) |
c906108c | 9472 | { |
06a64a0b | 9473 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
9474 | } |
9475 | ||
8b93c638 | 9476 | void |
84f4c1fe | 9477 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9478 | { |
84f4c1fe | 9479 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 9480 | } |
8926118c | 9481 | |
c5aa993b | 9482 | static void |
fba45db2 | 9483 | rwatch_command (char *arg, int from_tty) |
c906108c | 9484 | { |
06a64a0b | 9485 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
9486 | } |
9487 | ||
8b93c638 | 9488 | void |
84f4c1fe | 9489 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9490 | { |
84f4c1fe | 9491 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 9492 | } |
8926118c | 9493 | |
c5aa993b | 9494 | static void |
fba45db2 | 9495 | awatch_command (char *arg, int from_tty) |
c906108c | 9496 | { |
06a64a0b | 9497 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 9498 | } |
c906108c | 9499 | \f |
c5aa993b | 9500 | |
43ff13b4 | 9501 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
9502 | because it uses the mechanisms of breakpoints. */ |
9503 | ||
bfec99b2 PA |
9504 | struct until_break_command_continuation_args |
9505 | { | |
9506 | struct breakpoint *breakpoint; | |
9507 | struct breakpoint *breakpoint2; | |
186c406b | 9508 | int thread_num; |
bfec99b2 PA |
9509 | }; |
9510 | ||
43ff13b4 | 9511 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 9512 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 9513 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 9514 | command. */ |
c2c6d25f | 9515 | static void |
fa4cd53f | 9516 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 9517 | { |
bfec99b2 PA |
9518 | struct until_break_command_continuation_args *a = arg; |
9519 | ||
9520 | delete_breakpoint (a->breakpoint); | |
9521 | if (a->breakpoint2) | |
9522 | delete_breakpoint (a->breakpoint2); | |
186c406b | 9523 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
9524 | } |
9525 | ||
c906108c | 9526 | void |
ae66c1fc | 9527 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
9528 | { |
9529 | struct symtabs_and_lines sals; | |
9530 | struct symtab_and_line sal; | |
206415a3 | 9531 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 9532 | struct breakpoint *breakpoint; |
f107f563 | 9533 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 9534 | struct cleanup *old_chain; |
186c406b TT |
9535 | int thread; |
9536 | struct thread_info *tp; | |
c906108c SS |
9537 | |
9538 | clear_proceed_status (); | |
9539 | ||
9540 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 9541 | this function. */ |
c5aa993b | 9542 | |
c906108c SS |
9543 | if (default_breakpoint_valid) |
9544 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
58438ac1 | 9545 | default_breakpoint_line, NULL); |
c906108c | 9546 | else |
58438ac1 | 9547 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL); |
c5aa993b | 9548 | |
c906108c | 9549 | if (sals.nelts != 1) |
8a3fe4f8 | 9550 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 9551 | |
c906108c | 9552 | sal = sals.sals[0]; |
4a64f543 | 9553 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 9554 | |
c906108c | 9555 | if (*arg) |
8a3fe4f8 | 9556 | error (_("Junk at end of arguments.")); |
c5aa993b | 9557 | |
c906108c | 9558 | resolve_sal_pc (&sal); |
c5aa993b | 9559 | |
ae66c1fc EZ |
9560 | if (anywhere) |
9561 | /* If the user told us to continue until a specified location, | |
9562 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
9563 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9564 | null_frame_id, bp_until); | |
ae66c1fc | 9565 | else |
4a64f543 MS |
9566 | /* Otherwise, specify the selected frame, because we want to stop |
9567 | only at the very same frame. */ | |
a6d9a66e UW |
9568 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9569 | get_stack_frame_id (frame), | |
ae66c1fc | 9570 | bp_until); |
c5aa993b | 9571 | |
f107f563 | 9572 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 9573 | |
186c406b TT |
9574 | tp = inferior_thread (); |
9575 | thread = tp->num; | |
9576 | ||
ae66c1fc EZ |
9577 | /* Keep within the current frame, or in frames called by the current |
9578 | one. */ | |
edb3359d DJ |
9579 | |
9580 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 9581 | { |
edb3359d DJ |
9582 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
9583 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
9584 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
9585 | sal, | |
edb3359d | 9586 | frame_unwind_caller_id (frame), |
f107f563 VP |
9587 | bp_until); |
9588 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
9589 | |
9590 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
9591 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 9592 | } |
c5aa993b | 9593 | |
c906108c | 9594 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 9595 | |
4a64f543 MS |
9596 | /* If we are running asynchronously, and proceed call above has |
9597 | actually managed to start the target, arrange for breakpoints to | |
9598 | be deleted when the target stops. Otherwise, we're already | |
9599 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 9600 | |
8ea051c5 | 9601 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 9602 | { |
bfec99b2 PA |
9603 | struct until_break_command_continuation_args *args; |
9604 | args = xmalloc (sizeof (*args)); | |
f107f563 | 9605 | |
bfec99b2 PA |
9606 | args->breakpoint = breakpoint; |
9607 | args->breakpoint2 = breakpoint2; | |
186c406b | 9608 | args->thread_num = thread; |
f107f563 VP |
9609 | |
9610 | discard_cleanups (old_chain); | |
95e54da7 PA |
9611 | add_continuation (inferior_thread (), |
9612 | until_break_command_continuation, args, | |
604ead4a | 9613 | xfree); |
f107f563 VP |
9614 | } |
9615 | else | |
c5aa993b | 9616 | do_cleanups (old_chain); |
c906108c | 9617 | } |
ae66c1fc | 9618 | |
c906108c SS |
9619 | /* This function attempts to parse an optional "if <cond>" clause |
9620 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 9621 | |
c906108c SS |
9622 | Else, it returns a pointer to the condition string. (It does not |
9623 | attempt to evaluate the string against a particular block.) And, | |
9624 | it updates arg to point to the first character following the parsed | |
4a64f543 | 9625 | if clause in the arg string. */ |
53a5351d | 9626 | |
c906108c | 9627 | static char * |
fba45db2 | 9628 | ep_parse_optional_if_clause (char **arg) |
c906108c | 9629 | { |
c5aa993b JM |
9630 | char *cond_string; |
9631 | ||
9632 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 9633 | return NULL; |
c5aa993b | 9634 | |
4a64f543 | 9635 | /* Skip the "if" keyword. */ |
c906108c | 9636 | (*arg) += 2; |
c5aa993b | 9637 | |
c906108c | 9638 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 9639 | condition string. */ |
e9cafbcc | 9640 | *arg = skip_spaces (*arg); |
c906108c | 9641 | cond_string = *arg; |
c5aa993b | 9642 | |
4a64f543 MS |
9643 | /* Assume that the condition occupies the remainder of the arg |
9644 | string. */ | |
c906108c | 9645 | (*arg) += strlen (cond_string); |
c5aa993b | 9646 | |
c906108c SS |
9647 | return cond_string; |
9648 | } | |
c5aa993b | 9649 | |
c906108c SS |
9650 | /* Commands to deal with catching events, such as signals, exceptions, |
9651 | process start/exit, etc. */ | |
c5aa993b JM |
9652 | |
9653 | typedef enum | |
9654 | { | |
44feb3ce TT |
9655 | catch_fork_temporary, catch_vfork_temporary, |
9656 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
9657 | } |
9658 | catch_fork_kind; | |
9659 | ||
c906108c | 9660 | static void |
cc59ec59 MS |
9661 | catch_fork_command_1 (char *arg, int from_tty, |
9662 | struct cmd_list_element *command) | |
c906108c | 9663 | { |
a6d9a66e | 9664 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 9665 | char *cond_string = NULL; |
44feb3ce TT |
9666 | catch_fork_kind fork_kind; |
9667 | int tempflag; | |
9668 | ||
9669 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
9670 | tempflag = (fork_kind == catch_fork_temporary | |
9671 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 9672 | |
44feb3ce TT |
9673 | if (!arg) |
9674 | arg = ""; | |
e9cafbcc | 9675 | arg = skip_spaces (arg); |
c5aa993b | 9676 | |
c906108c | 9677 | /* The allowed syntax is: |
c5aa993b JM |
9678 | catch [v]fork |
9679 | catch [v]fork if <cond> | |
9680 | ||
4a64f543 | 9681 | First, check if there's an if clause. */ |
c906108c | 9682 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 9683 | |
c906108c | 9684 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9685 | error (_("Junk at end of arguments.")); |
c5aa993b | 9686 | |
c906108c | 9687 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9688 | and enable reporting of such events. */ |
c5aa993b JM |
9689 | switch (fork_kind) |
9690 | { | |
44feb3ce TT |
9691 | case catch_fork_temporary: |
9692 | case catch_fork_permanent: | |
a6d9a66e | 9693 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9694 | &catch_fork_breakpoint_ops); |
c906108c | 9695 | break; |
44feb3ce TT |
9696 | case catch_vfork_temporary: |
9697 | case catch_vfork_permanent: | |
a6d9a66e | 9698 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9699 | &catch_vfork_breakpoint_ops); |
c906108c | 9700 | break; |
c5aa993b | 9701 | default: |
8a3fe4f8 | 9702 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 9703 | break; |
c5aa993b | 9704 | } |
c906108c SS |
9705 | } |
9706 | ||
9707 | static void | |
cc59ec59 MS |
9708 | catch_exec_command_1 (char *arg, int from_tty, |
9709 | struct cmd_list_element *command) | |
c906108c | 9710 | { |
b4d90040 | 9711 | struct exec_catchpoint *c; |
a6d9a66e | 9712 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9713 | int tempflag; |
c5aa993b | 9714 | char *cond_string = NULL; |
c906108c | 9715 | |
44feb3ce TT |
9716 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9717 | ||
9718 | if (!arg) | |
9719 | arg = ""; | |
e9cafbcc | 9720 | arg = skip_spaces (arg); |
c906108c SS |
9721 | |
9722 | /* The allowed syntax is: | |
c5aa993b JM |
9723 | catch exec |
9724 | catch exec if <cond> | |
c906108c | 9725 | |
4a64f543 | 9726 | First, check if there's an if clause. */ |
c906108c SS |
9727 | cond_string = ep_parse_optional_if_clause (&arg); |
9728 | ||
9729 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9730 | error (_("Junk at end of arguments.")); |
c906108c | 9731 | |
b4d90040 PA |
9732 | c = XNEW (struct exec_catchpoint); |
9733 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
9734 | &catch_exec_breakpoint_ops); | |
9735 | c->exec_pathname = NULL; | |
9736 | ||
3a5c3e22 | 9737 | install_breakpoint (0, &c->base); |
c906108c | 9738 | } |
c5aa993b | 9739 | |
3086aeae | 9740 | static enum print_stop_action |
348d480f | 9741 | print_it_exception_catchpoint (bpstat bs) |
3086aeae | 9742 | { |
79a45e25 | 9743 | struct ui_out *uiout = current_uiout; |
348d480f | 9744 | struct breakpoint *b = bs->breakpoint_at; |
ade92717 | 9745 | int bp_temp, bp_throw; |
3086aeae | 9746 | |
ade92717 | 9747 | annotate_catchpoint (b->number); |
3086aeae | 9748 | |
ade92717 AR |
9749 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9750 | if (b->loc->address != b->loc->requested_address) | |
9751 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9752 | b->loc->address, | |
9753 | b->number, 1); | |
df2b6d2d | 9754 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9755 | ui_out_text (uiout, |
9756 | bp_temp ? "Temporary catchpoint " | |
9757 | : "Catchpoint "); | |
9758 | if (!ui_out_is_mi_like_p (uiout)) | |
9759 | ui_out_field_int (uiout, "bkptno", b->number); | |
9760 | ui_out_text (uiout, | |
c0b37c48 AR |
9761 | bp_throw ? " (exception thrown), " |
9762 | : " (exception caught), "); | |
ade92717 AR |
9763 | if (ui_out_is_mi_like_p (uiout)) |
9764 | { | |
9765 | ui_out_field_string (uiout, "reason", | |
9766 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9767 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9768 | ui_out_field_int (uiout, "bkptno", b->number); | |
9769 | } | |
3086aeae DJ |
9770 | return PRINT_SRC_AND_LOC; |
9771 | } | |
9772 | ||
9773 | static void | |
cc59ec59 MS |
9774 | print_one_exception_catchpoint (struct breakpoint *b, |
9775 | struct bp_location **last_loc) | |
3086aeae | 9776 | { |
79a45b7d | 9777 | struct value_print_options opts; |
79a45e25 | 9778 | struct ui_out *uiout = current_uiout; |
cc59ec59 | 9779 | |
79a45b7d TT |
9780 | get_user_print_options (&opts); |
9781 | if (opts.addressprint) | |
3086aeae DJ |
9782 | { |
9783 | annotate_field (4); | |
604133b5 AR |
9784 | if (b->loc == NULL || b->loc->shlib_disabled) |
9785 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9786 | else | |
5af949e3 UW |
9787 | ui_out_field_core_addr (uiout, "addr", |
9788 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9789 | } |
9790 | annotate_field (5); | |
604133b5 | 9791 | if (b->loc) |
a6d9a66e | 9792 | *last_loc = b->loc; |
3086aeae DJ |
9793 | if (strstr (b->addr_string, "throw") != NULL) |
9794 | ui_out_field_string (uiout, "what", "exception throw"); | |
9795 | else | |
9796 | ui_out_field_string (uiout, "what", "exception catch"); | |
9797 | } | |
9798 | ||
9799 | static void | |
9800 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9801 | { | |
79a45e25 | 9802 | struct ui_out *uiout = current_uiout; |
ade92717 AR |
9803 | int bp_temp; |
9804 | int bp_throw; | |
9805 | ||
df2b6d2d | 9806 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9807 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9808 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9809 | : _("Catchpoint ")); | |
9810 | ui_out_field_int (uiout, "bkptno", b->number); | |
9811 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9812 | : _(" (catch)")); | |
3086aeae DJ |
9813 | } |
9814 | ||
6149aea9 PA |
9815 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9816 | catch catchpoints. */ | |
9817 | ||
9818 | static void | |
4a64f543 MS |
9819 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9820 | struct ui_file *fp) | |
6149aea9 PA |
9821 | { |
9822 | int bp_temp; | |
9823 | int bp_throw; | |
9824 | ||
9825 | bp_temp = b->disposition == disp_del; | |
9826 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9827 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9828 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
d9b3f62e | 9829 | print_recreate_thread (b, fp); |
6149aea9 PA |
9830 | } |
9831 | ||
2060206e | 9832 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; |
3086aeae DJ |
9833 | |
9834 | static int | |
9835 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9836 | enum exception_event_kind ex_event, int from_tty) | |
9837 | { | |
604133b5 AR |
9838 | char *trigger_func_name; |
9839 | ||
3086aeae | 9840 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9841 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9842 | else |
604133b5 | 9843 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9844 | |
8cdf0e15 VP |
9845 | create_breakpoint (get_current_arch (), |
9846 | trigger_func_name, cond_string, -1, | |
9847 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9848 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9849 | 0, |
9850 | AUTO_BOOLEAN_TRUE /* pending */, | |
9851 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9852 | 1 /* enabled */, |
9853 | 0 /* internal */); | |
3086aeae | 9854 | |
3086aeae DJ |
9855 | return 1; |
9856 | } | |
9857 | ||
4a64f543 | 9858 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9859 | |
9860 | static void | |
fba45db2 KB |
9861 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9862 | int tempflag, int from_tty) | |
c906108c | 9863 | { |
c5aa993b | 9864 | char *cond_string = NULL; |
c5aa993b | 9865 | |
44feb3ce TT |
9866 | if (!arg) |
9867 | arg = ""; | |
e9cafbcc | 9868 | arg = skip_spaces (arg); |
c5aa993b | 9869 | |
c906108c SS |
9870 | cond_string = ep_parse_optional_if_clause (&arg); |
9871 | ||
9872 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9873 | error (_("Junk at end of arguments.")); |
c906108c | 9874 | |
059fb39f PM |
9875 | if (ex_event != EX_EVENT_THROW |
9876 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 9877 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 9878 | |
3086aeae DJ |
9879 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
9880 | return; | |
9881 | ||
8a3fe4f8 | 9882 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
9883 | } |
9884 | ||
44feb3ce TT |
9885 | /* Implementation of "catch catch" command. */ |
9886 | ||
9887 | static void | |
9888 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9889 | { | |
9890 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9891 | |
44feb3ce TT |
9892 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
9893 | } | |
9894 | ||
9895 | /* Implementation of "catch throw" command. */ | |
9896 | ||
9897 | static void | |
9898 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9899 | { | |
9900 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9901 | |
44feb3ce TT |
9902 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
9903 | } | |
9904 | ||
9ac4176b | 9905 | void |
28010a5d PA |
9906 | init_ada_exception_breakpoint (struct breakpoint *b, |
9907 | struct gdbarch *gdbarch, | |
9908 | struct symtab_and_line sal, | |
9909 | char *addr_string, | |
c0a91b2b | 9910 | const struct breakpoint_ops *ops, |
28010a5d PA |
9911 | int tempflag, |
9912 | int from_tty) | |
f7f9143b | 9913 | { |
f7f9143b JB |
9914 | if (from_tty) |
9915 | { | |
5af949e3 UW |
9916 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
9917 | if (!loc_gdbarch) | |
9918 | loc_gdbarch = gdbarch; | |
9919 | ||
6c95b8df PA |
9920 | describe_other_breakpoints (loc_gdbarch, |
9921 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
9922 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
9923 | version for exception catchpoints, because two catchpoints | |
9924 | used for different exception names will use the same address. | |
9925 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 9926 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 9927 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
9928 | the user what type of catchpoint it is. The above is good |
9929 | enough for now, though. */ | |
9930 | } | |
9931 | ||
28010a5d | 9932 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b JB |
9933 | |
9934 | b->enable_state = bp_enabled; | |
9935 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
f7f9143b JB |
9936 | b->addr_string = addr_string; |
9937 | b->language = language_ada; | |
f7f9143b JB |
9938 | } |
9939 | ||
a96d9b2e SDJ |
9940 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
9941 | filter list, or NULL if no filtering is required. */ | |
9942 | static VEC(int) * | |
9943 | catch_syscall_split_args (char *arg) | |
9944 | { | |
9945 | VEC(int) *result = NULL; | |
29d0bb3d | 9946 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
9947 | |
9948 | while (*arg != '\0') | |
9949 | { | |
9950 | int i, syscall_number; | |
9951 | char *endptr; | |
9952 | char cur_name[128]; | |
9953 | struct syscall s; | |
9954 | ||
9955 | /* Skip whitespace. */ | |
9956 | while (isspace (*arg)) | |
9957 | arg++; | |
9958 | ||
9959 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
9960 | cur_name[i] = arg[i]; | |
9961 | cur_name[i] = '\0'; | |
9962 | arg += i; | |
9963 | ||
9964 | /* Check if the user provided a syscall name or a number. */ | |
9965 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
9966 | if (*endptr == '\0') | |
bccd0dd2 | 9967 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
9968 | else |
9969 | { | |
9970 | /* We have a name. Let's check if it's valid and convert it | |
9971 | to a number. */ | |
9972 | get_syscall_by_name (cur_name, &s); | |
9973 | ||
9974 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
9975 | /* Here we have to issue an error instead of a warning, |
9976 | because GDB cannot do anything useful if there's no | |
9977 | syscall number to be caught. */ | |
a96d9b2e SDJ |
9978 | error (_("Unknown syscall name '%s'."), cur_name); |
9979 | } | |
9980 | ||
9981 | /* Ok, it's valid. */ | |
9982 | VEC_safe_push (int, result, s.number); | |
9983 | } | |
9984 | ||
9985 | discard_cleanups (cleanup); | |
9986 | return result; | |
9987 | } | |
9988 | ||
9989 | /* Implement the "catch syscall" command. */ | |
9990 | ||
9991 | static void | |
cc59ec59 MS |
9992 | catch_syscall_command_1 (char *arg, int from_tty, |
9993 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
9994 | { |
9995 | int tempflag; | |
9996 | VEC(int) *filter; | |
9997 | struct syscall s; | |
9998 | struct gdbarch *gdbarch = get_current_arch (); | |
9999 | ||
10000 | /* Checking if the feature if supported. */ | |
10001 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
10002 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 10003 | this architecture yet.")); |
a96d9b2e SDJ |
10004 | |
10005 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
10006 | ||
e9cafbcc | 10007 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
10008 | |
10009 | /* We need to do this first "dummy" translation in order | |
10010 | to get the syscall XML file loaded or, most important, | |
10011 | to display a warning to the user if there's no XML file | |
10012 | for his/her architecture. */ | |
10013 | get_syscall_by_number (0, &s); | |
10014 | ||
10015 | /* The allowed syntax is: | |
10016 | catch syscall | |
10017 | catch syscall <name | number> [<name | number> ... <name | number>] | |
10018 | ||
10019 | Let's check if there's a syscall name. */ | |
10020 | ||
10021 | if (arg != NULL) | |
10022 | filter = catch_syscall_split_args (arg); | |
10023 | else | |
10024 | filter = NULL; | |
10025 | ||
10026 | create_syscall_event_catchpoint (tempflag, filter, | |
10027 | &catch_syscall_breakpoint_ops); | |
10028 | } | |
10029 | ||
c906108c | 10030 | static void |
fba45db2 | 10031 | catch_command (char *arg, int from_tty) |
c906108c | 10032 | { |
44feb3ce | 10033 | error (_("Catch requires an event name.")); |
c906108c SS |
10034 | } |
10035 | \f | |
10036 | ||
10037 | static void | |
fba45db2 | 10038 | tcatch_command (char *arg, int from_tty) |
c906108c | 10039 | { |
44feb3ce | 10040 | error (_("Catch requires an event name.")); |
c906108c SS |
10041 | } |
10042 | ||
80f8a6eb | 10043 | /* Delete breakpoints by address or line. */ |
c906108c SS |
10044 | |
10045 | static void | |
fba45db2 | 10046 | clear_command (char *arg, int from_tty) |
c906108c | 10047 | { |
d6e956e5 VP |
10048 | struct breakpoint *b; |
10049 | VEC(breakpoint_p) *found = 0; | |
10050 | int ix; | |
c906108c SS |
10051 | int default_match; |
10052 | struct symtabs_and_lines sals; | |
10053 | struct symtab_and_line sal; | |
c906108c SS |
10054 | int i; |
10055 | ||
10056 | if (arg) | |
10057 | { | |
10058 | sals = decode_line_spec (arg, 1); | |
10059 | default_match = 0; | |
10060 | } | |
10061 | else | |
10062 | { | |
c5aa993b | 10063 | sals.sals = (struct symtab_and_line *) |
c906108c | 10064 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 10065 | make_cleanup (xfree, sals.sals); |
4a64f543 | 10066 | init_sal (&sal); /* Initialize to zeroes. */ |
c906108c SS |
10067 | sal.line = default_breakpoint_line; |
10068 | sal.symtab = default_breakpoint_symtab; | |
10069 | sal.pc = default_breakpoint_address; | |
6c95b8df | 10070 | sal.pspace = default_breakpoint_pspace; |
c906108c | 10071 | if (sal.symtab == 0) |
8a3fe4f8 | 10072 | error (_("No source file specified.")); |
c906108c SS |
10073 | |
10074 | sals.sals[0] = sal; | |
10075 | sals.nelts = 1; | |
10076 | ||
10077 | default_match = 1; | |
10078 | } | |
10079 | ||
4a64f543 MS |
10080 | /* We don't call resolve_sal_pc here. That's not as bad as it |
10081 | seems, because all existing breakpoints typically have both | |
10082 | file/line and pc set. So, if clear is given file/line, we can | |
10083 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
10084 | |
10085 | We only support clearing given the address explicitly | |
10086 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 10087 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 10088 | due to optimization, all in one block. |
4a64f543 MS |
10089 | |
10090 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
10091 | PC corresponding to the same file:line, the breakpoint won't |
10092 | be cleared. We probably can still clear the breakpoint, but | |
10093 | since the other PC value is never presented to user, user | |
10094 | can only find it by guessing, and it does not seem important | |
10095 | to support that. */ | |
10096 | ||
4a64f543 MS |
10097 | /* For each line spec given, delete bps which correspond to it. Do |
10098 | it in two passes, solely to preserve the current behavior that | |
10099 | from_tty is forced true if we delete more than one | |
10100 | breakpoint. */ | |
c906108c | 10101 | |
80f8a6eb | 10102 | found = NULL; |
c906108c SS |
10103 | for (i = 0; i < sals.nelts; i++) |
10104 | { | |
10105 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
10106 | If line given (pc == 0), clear all bpts on specified line. |
10107 | If defaulting, clear all bpts on default line | |
c906108c | 10108 | or at default pc. |
c5aa993b JM |
10109 | |
10110 | defaulting sal.pc != 0 tests to do | |
10111 | ||
10112 | 0 1 pc | |
10113 | 1 1 pc _and_ line | |
10114 | 0 0 line | |
10115 | 1 0 <can't happen> */ | |
c906108c SS |
10116 | |
10117 | sal = sals.sals[i]; | |
c906108c | 10118 | |
4a64f543 | 10119 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 10120 | ALL_BREAKPOINTS (b) |
c5aa993b | 10121 | { |
0d381245 | 10122 | int match = 0; |
4a64f543 | 10123 | /* Are we going to delete b? */ |
cc60f2e3 | 10124 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
10125 | { |
10126 | struct bp_location *loc = b->loc; | |
10127 | for (; loc; loc = loc->next) | |
10128 | { | |
6c95b8df PA |
10129 | int pc_match = sal.pc |
10130 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
10131 | && (loc->address == sal.pc) |
10132 | && (!section_is_overlay (loc->section) | |
10133 | || loc->section == sal.section); | |
10134 | int line_match = ((default_match || (0 == sal.pc)) | |
10135 | && b->source_file != NULL | |
10136 | && sal.symtab != NULL | |
6c95b8df | 10137 | && sal.pspace == loc->pspace |
0ba1096a KT |
10138 | && filename_cmp (b->source_file, |
10139 | sal.symtab->filename) == 0 | |
0d381245 VP |
10140 | && b->line_number == sal.line); |
10141 | if (pc_match || line_match) | |
10142 | { | |
10143 | match = 1; | |
10144 | break; | |
10145 | } | |
10146 | } | |
10147 | } | |
10148 | ||
10149 | if (match) | |
d6e956e5 | 10150 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 10151 | } |
80f8a6eb MS |
10152 | } |
10153 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 10154 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
10155 | { |
10156 | if (arg) | |
8a3fe4f8 | 10157 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 10158 | else |
8a3fe4f8 | 10159 | error (_("No breakpoint at this line.")); |
80f8a6eb | 10160 | } |
c906108c | 10161 | |
d6e956e5 | 10162 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 10163 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 10164 | if (from_tty) |
a3f17187 | 10165 | { |
d6e956e5 | 10166 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
10167 | printf_unfiltered (_("Deleted breakpoint ")); |
10168 | else | |
10169 | printf_unfiltered (_("Deleted breakpoints ")); | |
10170 | } | |
80f8a6eb | 10171 | breakpoints_changed (); |
d6e956e5 VP |
10172 | |
10173 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 10174 | { |
c5aa993b | 10175 | if (from_tty) |
d6e956e5 VP |
10176 | printf_unfiltered ("%d ", b->number); |
10177 | delete_breakpoint (b); | |
c906108c | 10178 | } |
80f8a6eb MS |
10179 | if (from_tty) |
10180 | putchar_unfiltered ('\n'); | |
c906108c SS |
10181 | } |
10182 | \f | |
10183 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
10184 | all breakpoints that are marked for deletion, whether hit or not. | |
10185 | This is called after any breakpoint is hit, or after errors. */ | |
10186 | ||
10187 | void | |
fba45db2 | 10188 | breakpoint_auto_delete (bpstat bs) |
c906108c | 10189 | { |
35df4500 | 10190 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10191 | |
10192 | for (; bs; bs = bs->next) | |
f431efe5 PA |
10193 | if (bs->breakpoint_at |
10194 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 10195 | && bs->stop) |
f431efe5 | 10196 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 10197 | |
35df4500 | 10198 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10199 | { |
b5de0fa7 | 10200 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
10201 | delete_breakpoint (b); |
10202 | } | |
c906108c SS |
10203 | } |
10204 | ||
4a64f543 MS |
10205 | /* A comparison function for bp_location AP and BP being interfaced to |
10206 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
10207 | does breakpoint_address_is_meaningful say for its OWNER), | |
10208 | secondarily by ordering first bp_permanent OWNERed elements and | |
10209 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 10210 | qsort being an unstable algorithm. */ |
876fa593 JK |
10211 | |
10212 | static int | |
494cfb0f | 10213 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 10214 | { |
494cfb0f JK |
10215 | struct bp_location *a = *(void **) ap; |
10216 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 10217 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
10218 | int a_perm = a->owner->enable_state == bp_permanent; |
10219 | int b_perm = b->owner->enable_state == bp_permanent; | |
10220 | ||
10221 | if (a->address != b->address) | |
10222 | return (a->address > b->address) - (a->address < b->address); | |
10223 | ||
10224 | /* Sort permanent breakpoints first. */ | |
10225 | if (a_perm != b_perm) | |
10226 | return (a_perm < b_perm) - (a_perm > b_perm); | |
10227 | ||
4a64f543 MS |
10228 | /* Make the user-visible order stable across GDB runs. Locations of |
10229 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
10230 | |
10231 | if (a->owner->number != b->owner->number) | |
10232 | return (a->owner->number > b->owner->number) | |
10233 | - (a->owner->number < b->owner->number); | |
10234 | ||
10235 | return (a > b) - (a < b); | |
10236 | } | |
10237 | ||
876fa593 | 10238 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
10239 | bp_location_shadow_len_after_address_max according to the current |
10240 | content of the bp_location array. */ | |
f7545552 TT |
10241 | |
10242 | static void | |
876fa593 | 10243 | bp_location_target_extensions_update (void) |
f7545552 | 10244 | { |
876fa593 JK |
10245 | struct bp_location *bl, **blp_tmp; |
10246 | ||
10247 | bp_location_placed_address_before_address_max = 0; | |
10248 | bp_location_shadow_len_after_address_max = 0; | |
10249 | ||
10250 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10251 | { | |
10252 | CORE_ADDR start, end, addr; | |
10253 | ||
10254 | if (!bp_location_has_shadow (bl)) | |
10255 | continue; | |
10256 | ||
10257 | start = bl->target_info.placed_address; | |
10258 | end = start + bl->target_info.shadow_len; | |
10259 | ||
10260 | gdb_assert (bl->address >= start); | |
10261 | addr = bl->address - start; | |
10262 | if (addr > bp_location_placed_address_before_address_max) | |
10263 | bp_location_placed_address_before_address_max = addr; | |
10264 | ||
10265 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
10266 | ||
10267 | gdb_assert (bl->address < end); | |
10268 | addr = end - bl->address; | |
10269 | if (addr > bp_location_shadow_len_after_address_max) | |
10270 | bp_location_shadow_len_after_address_max = addr; | |
10271 | } | |
f7545552 TT |
10272 | } |
10273 | ||
934709f0 PW |
10274 | /* Swap the insertion/duplication state between two locations. */ |
10275 | ||
10276 | static void | |
10277 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
10278 | { | |
10279 | const int left_inserted = left->inserted; | |
10280 | const int left_duplicate = left->duplicate; | |
10281 | const struct bp_target_info left_target_info = left->target_info; | |
10282 | ||
10283 | left->inserted = right->inserted; | |
10284 | left->duplicate = right->duplicate; | |
10285 | left->target_info = right->target_info; | |
10286 | right->inserted = left_inserted; | |
10287 | right->duplicate = left_duplicate; | |
10288 | right->target_info = left_target_info; | |
10289 | } | |
10290 | ||
4cd9bd08 | 10291 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
10292 | into the inferior, only remove already-inserted locations that no |
10293 | longer should be inserted. Functions that delete a breakpoint or | |
10294 | breakpoints should pass false, so that deleting a breakpoint | |
10295 | doesn't have the side effect of inserting the locations of other | |
10296 | breakpoints that are marked not-inserted, but should_be_inserted | |
10297 | returns true on them. | |
10298 | ||
10299 | This behaviour is useful is situations close to tear-down -- e.g., | |
10300 | after an exec, while the target still has execution, but breakpoint | |
10301 | shadows of the previous executable image should *NOT* be restored | |
10302 | to the new image; or before detaching, where the target still has | |
10303 | execution and wants to delete breakpoints from GDB's lists, and all | |
10304 | breakpoints had already been removed from the inferior. */ | |
10305 | ||
0d381245 | 10306 | static void |
b60e7edf | 10307 | update_global_location_list (int should_insert) |
0d381245 | 10308 | { |
74960c60 | 10309 | struct breakpoint *b; |
876fa593 | 10310 | struct bp_location **locp, *loc; |
f7545552 TT |
10311 | struct cleanup *cleanups; |
10312 | ||
2d134ed3 PA |
10313 | /* Used in the duplicates detection below. When iterating over all |
10314 | bp_locations, points to the first bp_location of a given address. | |
10315 | Breakpoints and watchpoints of different types are never | |
10316 | duplicates of each other. Keep one pointer for each type of | |
10317 | breakpoint/watchpoint, so we only need to loop over all locations | |
10318 | once. */ | |
10319 | struct bp_location *bp_loc_first; /* breakpoint */ | |
10320 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
10321 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
10322 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 10323 | |
4a64f543 MS |
10324 | /* Saved former bp_location array which we compare against the newly |
10325 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
10326 | struct bp_location **old_location, **old_locp; |
10327 | unsigned old_location_count; | |
10328 | ||
10329 | old_location = bp_location; | |
10330 | old_location_count = bp_location_count; | |
10331 | bp_location = NULL; | |
10332 | bp_location_count = 0; | |
10333 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 10334 | |
74960c60 | 10335 | ALL_BREAKPOINTS (b) |
876fa593 JK |
10336 | for (loc = b->loc; loc; loc = loc->next) |
10337 | bp_location_count++; | |
10338 | ||
10339 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
10340 | locp = bp_location; | |
10341 | ALL_BREAKPOINTS (b) | |
10342 | for (loc = b->loc; loc; loc = loc->next) | |
10343 | *locp++ = loc; | |
10344 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 10345 | bp_location_compare); |
876fa593 JK |
10346 | |
10347 | bp_location_target_extensions_update (); | |
74960c60 | 10348 | |
4a64f543 MS |
10349 | /* Identify bp_location instances that are no longer present in the |
10350 | new list, and therefore should be freed. Note that it's not | |
10351 | necessary that those locations should be removed from inferior -- | |
10352 | if there's another location at the same address (previously | |
10353 | marked as duplicate), we don't need to remove/insert the | |
10354 | location. | |
876fa593 | 10355 | |
4a64f543 MS |
10356 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
10357 | and former bp_location array state respectively. */ | |
876fa593 JK |
10358 | |
10359 | locp = bp_location; | |
10360 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
10361 | old_locp++) | |
74960c60 | 10362 | { |
876fa593 | 10363 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 10364 | struct bp_location **loc2p; |
876fa593 | 10365 | |
e5dd4106 | 10366 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 10367 | not, we have to free it. */ |
c7d46a38 | 10368 | int found_object = 0; |
20874c92 VP |
10369 | /* Tells if the location should remain inserted in the target. */ |
10370 | int keep_in_target = 0; | |
10371 | int removed = 0; | |
876fa593 | 10372 | |
4a64f543 MS |
10373 | /* Skip LOCP entries which will definitely never be needed. |
10374 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 10375 | while (locp < bp_location + bp_location_count |
c7d46a38 | 10376 | && (*locp)->address < old_loc->address) |
876fa593 | 10377 | locp++; |
c7d46a38 PA |
10378 | |
10379 | for (loc2p = locp; | |
10380 | (loc2p < bp_location + bp_location_count | |
10381 | && (*loc2p)->address == old_loc->address); | |
10382 | loc2p++) | |
10383 | { | |
10384 | if (*loc2p == old_loc) | |
10385 | { | |
10386 | found_object = 1; | |
10387 | break; | |
10388 | } | |
10389 | } | |
74960c60 | 10390 | |
4a64f543 MS |
10391 | /* If this location is no longer present, and inserted, look if |
10392 | there's maybe a new location at the same address. If so, | |
10393 | mark that one inserted, and don't remove this one. This is | |
10394 | needed so that we don't have a time window where a breakpoint | |
10395 | at certain location is not inserted. */ | |
74960c60 | 10396 | |
876fa593 | 10397 | if (old_loc->inserted) |
0d381245 | 10398 | { |
4a64f543 MS |
10399 | /* If the location is inserted now, we might have to remove |
10400 | it. */ | |
74960c60 | 10401 | |
876fa593 | 10402 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 10403 | { |
4a64f543 MS |
10404 | /* The location is still present in the location list, |
10405 | and still should be inserted. Don't do anything. */ | |
20874c92 | 10406 | keep_in_target = 1; |
74960c60 VP |
10407 | } |
10408 | else | |
10409 | { | |
4a64f543 MS |
10410 | /* The location is either no longer present, or got |
10411 | disabled. See if there's another location at the | |
10412 | same address, in which case we don't need to remove | |
10413 | this one from the target. */ | |
876fa593 | 10414 | |
2bdf28a0 | 10415 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
10416 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
10417 | { | |
876fa593 | 10418 | for (loc2p = locp; |
c7d46a38 PA |
10419 | (loc2p < bp_location + bp_location_count |
10420 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
10421 | loc2p++) |
10422 | { | |
10423 | struct bp_location *loc2 = *loc2p; | |
10424 | ||
2d134ed3 | 10425 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 10426 | { |
85d721b8 PA |
10427 | /* Read watchpoint locations are switched to |
10428 | access watchpoints, if the former are not | |
10429 | supported, but the latter are. */ | |
10430 | if (is_hardware_watchpoint (old_loc->owner)) | |
10431 | { | |
10432 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
10433 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
10434 | } | |
10435 | ||
934709f0 PW |
10436 | /* loc2 is a duplicated location. We need to check |
10437 | if it should be inserted in case it will be | |
10438 | unduplicated. */ | |
10439 | if (loc2 != old_loc | |
10440 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 10441 | { |
934709f0 | 10442 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
10443 | keep_in_target = 1; |
10444 | break; | |
10445 | } | |
876fa593 JK |
10446 | } |
10447 | } | |
10448 | } | |
74960c60 VP |
10449 | } |
10450 | ||
20874c92 VP |
10451 | if (!keep_in_target) |
10452 | { | |
876fa593 | 10453 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 10454 | { |
4a64f543 MS |
10455 | /* This is just about all we can do. We could keep |
10456 | this location on the global list, and try to | |
10457 | remove it next time, but there's no particular | |
10458 | reason why we will succeed next time. | |
20874c92 | 10459 | |
4a64f543 MS |
10460 | Note that at this point, old_loc->owner is still |
10461 | valid, as delete_breakpoint frees the breakpoint | |
10462 | only after calling us. */ | |
3e43a32a MS |
10463 | printf_filtered (_("warning: Error removing " |
10464 | "breakpoint %d\n"), | |
876fa593 | 10465 | old_loc->owner->number); |
20874c92 VP |
10466 | } |
10467 | removed = 1; | |
10468 | } | |
0d381245 | 10469 | } |
74960c60 VP |
10470 | |
10471 | if (!found_object) | |
1c5cfe86 | 10472 | { |
db82e815 PA |
10473 | if (removed && non_stop |
10474 | && breakpoint_address_is_meaningful (old_loc->owner) | |
10475 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 10476 | { |
db82e815 PA |
10477 | /* This location was removed from the target. In |
10478 | non-stop mode, a race condition is possible where | |
10479 | we've removed a breakpoint, but stop events for that | |
10480 | breakpoint are already queued and will arrive later. | |
10481 | We apply an heuristic to be able to distinguish such | |
10482 | SIGTRAPs from other random SIGTRAPs: we keep this | |
10483 | breakpoint location for a bit, and will retire it | |
10484 | after we see some number of events. The theory here | |
10485 | is that reporting of events should, "on the average", | |
10486 | be fair, so after a while we'll see events from all | |
10487 | threads that have anything of interest, and no longer | |
10488 | need to keep this breakpoint location around. We | |
10489 | don't hold locations forever so to reduce chances of | |
10490 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
10491 | SIGTRAP. | |
10492 | ||
10493 | The heuristic failing can be disastrous on | |
10494 | decr_pc_after_break targets. | |
10495 | ||
10496 | On decr_pc_after_break targets, like e.g., x86-linux, | |
10497 | if we fail to recognize a late breakpoint SIGTRAP, | |
10498 | because events_till_retirement has reached 0 too | |
10499 | soon, we'll fail to do the PC adjustment, and report | |
10500 | a random SIGTRAP to the user. When the user resumes | |
10501 | the inferior, it will most likely immediately crash | |
2dec564e | 10502 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
10503 | corrupted, because of being resumed e.g., in the |
10504 | middle of a multi-byte instruction, or skipped a | |
10505 | one-byte instruction. This was actually seen happen | |
10506 | on native x86-linux, and should be less rare on | |
10507 | targets that do not support new thread events, like | |
10508 | remote, due to the heuristic depending on | |
10509 | thread_count. | |
10510 | ||
10511 | Mistaking a random SIGTRAP for a breakpoint trap | |
10512 | causes similar symptoms (PC adjustment applied when | |
10513 | it shouldn't), but then again, playing with SIGTRAPs | |
10514 | behind the debugger's back is asking for trouble. | |
10515 | ||
10516 | Since hardware watchpoint traps are always | |
10517 | distinguishable from other traps, so we don't need to | |
10518 | apply keep hardware watchpoint moribund locations | |
10519 | around. We simply always ignore hardware watchpoint | |
10520 | traps we can no longer explain. */ | |
10521 | ||
876fa593 JK |
10522 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
10523 | old_loc->owner = NULL; | |
20874c92 | 10524 | |
876fa593 | 10525 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
10526 | } |
10527 | else | |
f431efe5 PA |
10528 | { |
10529 | old_loc->owner = NULL; | |
10530 | decref_bp_location (&old_loc); | |
10531 | } | |
20874c92 | 10532 | } |
74960c60 | 10533 | } |
1c5cfe86 | 10534 | |
348d480f PA |
10535 | /* Rescan breakpoints at the same address and section, marking the |
10536 | first one as "first" and any others as "duplicates". This is so | |
10537 | that the bpt instruction is only inserted once. If we have a | |
10538 | permanent breakpoint at the same place as BPT, make that one the | |
10539 | official one, and the rest as duplicates. Permanent breakpoints | |
10540 | are sorted first for the same address. | |
10541 | ||
10542 | Do the same for hardware watchpoints, but also considering the | |
10543 | watchpoint's type (regular/access/read) and length. */ | |
10544 | ||
10545 | bp_loc_first = NULL; | |
10546 | wp_loc_first = NULL; | |
10547 | awp_loc_first = NULL; | |
10548 | rwp_loc_first = NULL; | |
10549 | ALL_BP_LOCATIONS (loc, locp) | |
10550 | { | |
10551 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
10552 | non-NULL. */ | |
10553 | struct breakpoint *b = loc->owner; | |
10554 | struct bp_location **loc_first_p; | |
10555 | ||
10556 | if (b->enable_state == bp_disabled | |
10557 | || b->enable_state == bp_call_disabled | |
10558 | || b->enable_state == bp_startup_disabled | |
10559 | || !loc->enabled | |
10560 | || loc->shlib_disabled | |
10561 | || !breakpoint_address_is_meaningful (b) | |
10562 | || is_tracepoint (b)) | |
10563 | continue; | |
10564 | ||
10565 | /* Permanent breakpoint should always be inserted. */ | |
10566 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
10567 | internal_error (__FILE__, __LINE__, | |
10568 | _("allegedly permanent breakpoint is not " | |
10569 | "actually inserted")); | |
10570 | ||
10571 | if (b->type == bp_hardware_watchpoint) | |
10572 | loc_first_p = &wp_loc_first; | |
10573 | else if (b->type == bp_read_watchpoint) | |
10574 | loc_first_p = &rwp_loc_first; | |
10575 | else if (b->type == bp_access_watchpoint) | |
10576 | loc_first_p = &awp_loc_first; | |
10577 | else | |
10578 | loc_first_p = &bp_loc_first; | |
10579 | ||
10580 | if (*loc_first_p == NULL | |
10581 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
10582 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
10583 | { | |
10584 | *loc_first_p = loc; | |
10585 | loc->duplicate = 0; | |
10586 | continue; | |
10587 | } | |
10588 | ||
934709f0 PW |
10589 | |
10590 | /* This and the above ensure the invariant that the first location | |
10591 | is not duplicated, and is the inserted one. | |
10592 | All following are marked as duplicated, and are not inserted. */ | |
10593 | if (loc->inserted) | |
10594 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
10595 | loc->duplicate = 1; |
10596 | ||
10597 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted | |
10598 | && b->enable_state != bp_permanent) | |
10599 | internal_error (__FILE__, __LINE__, | |
10600 | _("another breakpoint was inserted on top of " | |
10601 | "a permanent breakpoint")); | |
10602 | } | |
10603 | ||
10604 | if (breakpoints_always_inserted_mode () && should_insert | |
10605 | && (have_live_inferiors () | |
10606 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) | |
10607 | insert_breakpoint_locations (); | |
10608 | ||
10609 | do_cleanups (cleanups); | |
10610 | } | |
10611 | ||
10612 | void | |
10613 | breakpoint_retire_moribund (void) | |
10614 | { | |
10615 | struct bp_location *loc; | |
10616 | int ix; | |
10617 | ||
10618 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
10619 | if (--(loc->events_till_retirement) == 0) | |
10620 | { | |
10621 | decref_bp_location (&loc); | |
10622 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
10623 | --ix; | |
10624 | } | |
10625 | } | |
10626 | ||
10627 | static void | |
10628 | update_global_location_list_nothrow (int inserting) | |
10629 | { | |
10630 | struct gdb_exception e; | |
10631 | ||
10632 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
10633 | update_global_location_list (inserting); | |
10634 | } | |
10635 | ||
10636 | /* Clear BKP from a BPS. */ | |
10637 | ||
10638 | static void | |
10639 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
10640 | { | |
10641 | bpstat bs; | |
10642 | ||
10643 | for (bs = bps; bs; bs = bs->next) | |
10644 | if (bs->breakpoint_at == bpt) | |
10645 | { | |
10646 | bs->breakpoint_at = NULL; | |
10647 | bs->old_val = NULL; | |
10648 | /* bs->commands will be freed later. */ | |
10649 | } | |
10650 | } | |
10651 | ||
10652 | /* Callback for iterate_over_threads. */ | |
10653 | static int | |
10654 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
10655 | { | |
10656 | struct breakpoint *bpt = data; | |
10657 | ||
10658 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
10659 | return 0; | |
10660 | } | |
10661 | ||
10662 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
10663 | callbacks. */ | |
10664 | ||
10665 | static void | |
10666 | say_where (struct breakpoint *b) | |
10667 | { | |
79a45e25 | 10668 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10669 | struct value_print_options opts; |
10670 | ||
10671 | get_user_print_options (&opts); | |
10672 | ||
10673 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
10674 | single string. */ | |
10675 | if (b->loc == NULL) | |
10676 | { | |
10677 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
10678 | } | |
10679 | else | |
10680 | { | |
10681 | if (opts.addressprint || b->source_file == NULL) | |
10682 | { | |
10683 | printf_filtered (" at "); | |
10684 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
10685 | gdb_stdout); | |
10686 | } | |
10687 | if (b->source_file) | |
10688 | printf_filtered (": file %s, line %d.", | |
10689 | b->source_file, b->line_number); | |
10690 | ||
10691 | if (b->loc->next) | |
10692 | { | |
10693 | struct bp_location *loc = b->loc; | |
10694 | int n = 0; | |
10695 | for (; loc; loc = loc->next) | |
10696 | ++n; | |
10697 | printf_filtered (" (%d locations)", n); | |
10698 | } | |
10699 | } | |
10700 | } | |
10701 | ||
348d480f PA |
10702 | /* Default bp_location_ops methods. */ |
10703 | ||
10704 | static void | |
10705 | bp_location_dtor (struct bp_location *self) | |
10706 | { | |
10707 | xfree (self->cond); | |
10708 | xfree (self->function_name); | |
10709 | } | |
10710 | ||
10711 | static const struct bp_location_ops bp_location_ops = | |
10712 | { | |
10713 | bp_location_dtor | |
10714 | }; | |
10715 | ||
2060206e PA |
10716 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
10717 | inherit from. */ | |
348d480f | 10718 | |
2060206e PA |
10719 | static void |
10720 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
10721 | { |
10722 | decref_counted_command_line (&self->commands); | |
10723 | xfree (self->cond_string); | |
348d480f PA |
10724 | xfree (self->addr_string); |
10725 | xfree (self->addr_string_range_end); | |
348d480f PA |
10726 | xfree (self->source_file); |
10727 | } | |
10728 | ||
2060206e PA |
10729 | static struct bp_location * |
10730 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
10731 | { |
10732 | struct bp_location *loc; | |
10733 | ||
10734 | loc = XNEW (struct bp_location); | |
10735 | init_bp_location (loc, &bp_location_ops, self); | |
10736 | return loc; | |
10737 | } | |
10738 | ||
2060206e PA |
10739 | static void |
10740 | base_breakpoint_re_set (struct breakpoint *b) | |
10741 | { | |
10742 | /* Nothing to re-set. */ | |
10743 | } | |
10744 | ||
10745 | #define internal_error_pure_virtual_called() \ | |
10746 | gdb_assert_not_reached ("pure virtual function called") | |
10747 | ||
10748 | static int | |
10749 | base_breakpoint_insert_location (struct bp_location *bl) | |
10750 | { | |
10751 | internal_error_pure_virtual_called (); | |
10752 | } | |
10753 | ||
10754 | static int | |
10755 | base_breakpoint_remove_location (struct bp_location *bl) | |
10756 | { | |
10757 | internal_error_pure_virtual_called (); | |
10758 | } | |
10759 | ||
10760 | static int | |
10761 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
10762 | struct address_space *aspace, | |
10763 | CORE_ADDR bp_addr) | |
10764 | { | |
10765 | internal_error_pure_virtual_called (); | |
10766 | } | |
10767 | ||
10768 | static void | |
10769 | base_breakpoint_check_status (bpstat bs) | |
10770 | { | |
10771 | /* Always stop. */ | |
10772 | } | |
10773 | ||
10774 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
10775 | errors. */ | |
10776 | ||
10777 | static int | |
10778 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
10779 | { | |
10780 | internal_error_pure_virtual_called (); | |
10781 | } | |
10782 | ||
10783 | /* A "resources_needed" breakpoint_ops method that just internal | |
10784 | errors. */ | |
10785 | ||
10786 | static int | |
10787 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
10788 | { | |
10789 | internal_error_pure_virtual_called (); | |
10790 | } | |
10791 | ||
10792 | static enum print_stop_action | |
10793 | base_breakpoint_print_it (bpstat bs) | |
10794 | { | |
10795 | internal_error_pure_virtual_called (); | |
10796 | } | |
10797 | ||
10798 | static void | |
10799 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
10800 | struct ui_out *uiout) | |
10801 | { | |
10802 | /* nothing */ | |
10803 | } | |
10804 | ||
10805 | static void | |
10806 | base_breakpoint_print_mention (struct breakpoint *b) | |
10807 | { | |
10808 | internal_error_pure_virtual_called (); | |
10809 | } | |
10810 | ||
10811 | static void | |
10812 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
10813 | { | |
10814 | internal_error_pure_virtual_called (); | |
10815 | } | |
10816 | ||
10817 | static struct breakpoint_ops base_breakpoint_ops = | |
10818 | { | |
10819 | base_breakpoint_dtor, | |
10820 | base_breakpoint_allocate_location, | |
10821 | base_breakpoint_re_set, | |
10822 | base_breakpoint_insert_location, | |
10823 | base_breakpoint_remove_location, | |
10824 | base_breakpoint_breakpoint_hit, | |
10825 | base_breakpoint_check_status, | |
10826 | base_breakpoint_resources_needed, | |
10827 | base_breakpoint_works_in_software_mode, | |
10828 | base_breakpoint_print_it, | |
10829 | NULL, | |
10830 | base_breakpoint_print_one_detail, | |
10831 | base_breakpoint_print_mention, | |
10832 | base_breakpoint_print_recreate | |
10833 | }; | |
10834 | ||
10835 | /* Default breakpoint_ops methods. */ | |
10836 | ||
10837 | static void | |
348d480f PA |
10838 | bkpt_re_set (struct breakpoint *b) |
10839 | { | |
06edf0c0 PA |
10840 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
10841 | if (b->enable_state == bp_startup_disabled) | |
10842 | return; | |
348d480f | 10843 | |
06edf0c0 PA |
10844 | /* FIXME: is this still reachable? */ |
10845 | if (b->addr_string == NULL) | |
10846 | { | |
10847 | /* Anything without a string can't be re-set. */ | |
348d480f | 10848 | delete_breakpoint (b); |
06edf0c0 | 10849 | return; |
348d480f | 10850 | } |
06edf0c0 PA |
10851 | |
10852 | breakpoint_re_set_default (b); | |
348d480f PA |
10853 | } |
10854 | ||
2060206e | 10855 | static int |
348d480f PA |
10856 | bkpt_insert_location (struct bp_location *bl) |
10857 | { | |
10858 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
10859 | return target_insert_hw_breakpoint (bl->gdbarch, | |
10860 | &bl->target_info); | |
10861 | else | |
10862 | return target_insert_breakpoint (bl->gdbarch, | |
10863 | &bl->target_info); | |
10864 | } | |
10865 | ||
2060206e | 10866 | static int |
348d480f PA |
10867 | bkpt_remove_location (struct bp_location *bl) |
10868 | { | |
10869 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
10870 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
10871 | else | |
10872 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
10873 | } | |
10874 | ||
2060206e | 10875 | static int |
348d480f PA |
10876 | bkpt_breakpoint_hit (const struct bp_location *bl, |
10877 | struct address_space *aspace, CORE_ADDR bp_addr) | |
10878 | { | |
10879 | struct breakpoint *b = bl->owner; | |
10880 | ||
10881 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, | |
10882 | aspace, bp_addr)) | |
10883 | return 0; | |
10884 | ||
10885 | if (overlay_debugging /* unmapped overlay section */ | |
10886 | && section_is_overlay (bl->section) | |
10887 | && !section_is_mapped (bl->section)) | |
10888 | return 0; | |
10889 | ||
10890 | return 1; | |
10891 | } | |
10892 | ||
2060206e | 10893 | static int |
348d480f PA |
10894 | bkpt_resources_needed (const struct bp_location *bl) |
10895 | { | |
10896 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
10897 | ||
10898 | return 1; | |
10899 | } | |
10900 | ||
2060206e | 10901 | static enum print_stop_action |
348d480f PA |
10902 | bkpt_print_it (bpstat bs) |
10903 | { | |
348d480f PA |
10904 | struct breakpoint *b; |
10905 | const struct bp_location *bl; | |
001c8c33 | 10906 | int bp_temp; |
79a45e25 | 10907 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10908 | |
10909 | gdb_assert (bs->bp_location_at != NULL); | |
10910 | ||
10911 | bl = bs->bp_location_at; | |
10912 | b = bs->breakpoint_at; | |
10913 | ||
001c8c33 PA |
10914 | bp_temp = b->disposition == disp_del; |
10915 | if (bl->address != bl->requested_address) | |
10916 | breakpoint_adjustment_warning (bl->requested_address, | |
10917 | bl->address, | |
10918 | b->number, 1); | |
10919 | annotate_breakpoint (b->number); | |
10920 | if (bp_temp) | |
10921 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
10922 | else | |
10923 | ui_out_text (uiout, "\nBreakpoint "); | |
10924 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 10925 | { |
001c8c33 PA |
10926 | ui_out_field_string (uiout, "reason", |
10927 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10928 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 10929 | } |
001c8c33 PA |
10930 | ui_out_field_int (uiout, "bkptno", b->number); |
10931 | ui_out_text (uiout, ", "); | |
06edf0c0 | 10932 | |
001c8c33 | 10933 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
10934 | } |
10935 | ||
2060206e | 10936 | static void |
06edf0c0 PA |
10937 | bkpt_print_mention (struct breakpoint *b) |
10938 | { | |
79a45e25 | 10939 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
10940 | return; |
10941 | ||
10942 | switch (b->type) | |
10943 | { | |
10944 | case bp_breakpoint: | |
10945 | case bp_gnu_ifunc_resolver: | |
10946 | if (b->disposition == disp_del) | |
10947 | printf_filtered (_("Temporary breakpoint")); | |
10948 | else | |
10949 | printf_filtered (_("Breakpoint")); | |
10950 | printf_filtered (_(" %d"), b->number); | |
10951 | if (b->type == bp_gnu_ifunc_resolver) | |
10952 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
10953 | break; | |
10954 | case bp_hardware_breakpoint: | |
10955 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
10956 | break; | |
10957 | } | |
10958 | ||
10959 | say_where (b); | |
10960 | } | |
10961 | ||
2060206e | 10962 | static void |
06edf0c0 PA |
10963 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
10964 | { | |
10965 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
10966 | fprintf_unfiltered (fp, "tbreak"); | |
10967 | else if (tp->type == bp_breakpoint) | |
10968 | fprintf_unfiltered (fp, "break"); | |
10969 | else if (tp->type == bp_hardware_breakpoint | |
10970 | && tp->disposition == disp_del) | |
10971 | fprintf_unfiltered (fp, "thbreak"); | |
10972 | else if (tp->type == bp_hardware_breakpoint) | |
10973 | fprintf_unfiltered (fp, "hbreak"); | |
10974 | else | |
10975 | internal_error (__FILE__, __LINE__, | |
10976 | _("unhandled breakpoint type %d"), (int) tp->type); | |
10977 | ||
2060206e | 10978 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
06edf0c0 PA |
10979 | } |
10980 | ||
06edf0c0 PA |
10981 | /* Virtual table for internal breakpoints. */ |
10982 | ||
10983 | static void | |
10984 | internal_bkpt_re_set (struct breakpoint *b) | |
10985 | { | |
10986 | switch (b->type) | |
10987 | { | |
10988 | /* Delete overlay event and longjmp master breakpoints; they | |
10989 | will be reset later by breakpoint_re_set. */ | |
10990 | case bp_overlay_event: | |
10991 | case bp_longjmp_master: | |
10992 | case bp_std_terminate_master: | |
10993 | case bp_exception_master: | |
10994 | delete_breakpoint (b); | |
10995 | break; | |
10996 | ||
10997 | /* This breakpoint is special, it's set up when the inferior | |
10998 | starts and we really don't want to touch it. */ | |
10999 | case bp_shlib_event: | |
11000 | ||
11001 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
11002 | it is set up, we do not want to touch it. */ | |
11003 | case bp_thread_event: | |
11004 | break; | |
11005 | } | |
11006 | } | |
11007 | ||
11008 | static void | |
11009 | internal_bkpt_check_status (bpstat bs) | |
11010 | { | |
11011 | /* We do not stop for these. */ | |
11012 | bs->stop = 0; | |
11013 | } | |
11014 | ||
11015 | static enum print_stop_action | |
11016 | internal_bkpt_print_it (bpstat bs) | |
11017 | { | |
06edf0c0 | 11018 | struct breakpoint *b; |
06edf0c0 | 11019 | |
06edf0c0 PA |
11020 | b = bs->breakpoint_at; |
11021 | ||
06edf0c0 PA |
11022 | switch (b->type) |
11023 | { | |
348d480f PA |
11024 | case bp_shlib_event: |
11025 | /* Did we stop because the user set the stop_on_solib_events | |
11026 | variable? (If so, we report this as a generic, "Stopped due | |
11027 | to shlib event" message.) */ | |
11028 | printf_filtered (_("Stopped due to shared library event\n")); | |
348d480f PA |
11029 | break; |
11030 | ||
11031 | case bp_thread_event: | |
11032 | /* Not sure how we will get here. | |
11033 | GDB should not stop for these breakpoints. */ | |
11034 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11035 | break; |
11036 | ||
11037 | case bp_overlay_event: | |
11038 | /* By analogy with the thread event, GDB should not stop for these. */ | |
11039 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11040 | break; |
11041 | ||
11042 | case bp_longjmp_master: | |
11043 | /* These should never be enabled. */ | |
11044 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11045 | break; |
11046 | ||
11047 | case bp_std_terminate_master: | |
11048 | /* These should never be enabled. */ | |
11049 | printf_filtered (_("std::terminate Master Breakpoint: " | |
11050 | "gdb should not stop!\n")); | |
348d480f PA |
11051 | break; |
11052 | ||
11053 | case bp_exception_master: | |
11054 | /* These should never be enabled. */ | |
11055 | printf_filtered (_("Exception Master Breakpoint: " | |
11056 | "gdb should not stop!\n")); | |
06edf0c0 PA |
11057 | break; |
11058 | } | |
11059 | ||
001c8c33 | 11060 | return PRINT_NOTHING; |
06edf0c0 PA |
11061 | } |
11062 | ||
11063 | static void | |
11064 | internal_bkpt_print_mention (struct breakpoint *b) | |
11065 | { | |
11066 | /* Nothing to mention. These breakpoints are internal. */ | |
11067 | } | |
11068 | ||
06edf0c0 PA |
11069 | /* Virtual table for momentary breakpoints */ |
11070 | ||
11071 | static void | |
11072 | momentary_bkpt_re_set (struct breakpoint *b) | |
11073 | { | |
11074 | /* Keep temporary breakpoints, which can be encountered when we step | |
11075 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
11076 | Otherwise these should have been blown away via the cleanup chain | |
11077 | or by breakpoint_init_inferior when we rerun the executable. */ | |
11078 | } | |
11079 | ||
11080 | static void | |
11081 | momentary_bkpt_check_status (bpstat bs) | |
11082 | { | |
11083 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
11084 | } | |
11085 | ||
11086 | static enum print_stop_action | |
11087 | momentary_bkpt_print_it (bpstat bs) | |
11088 | { | |
79a45e25 PA |
11089 | struct ui_out *uiout = current_uiout; |
11090 | ||
001c8c33 | 11091 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 11092 | { |
001c8c33 | 11093 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 11094 | |
001c8c33 PA |
11095 | switch (b->type) |
11096 | { | |
11097 | case bp_finish: | |
11098 | ui_out_field_string | |
11099 | (uiout, "reason", | |
11100 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
11101 | break; | |
348d480f | 11102 | |
001c8c33 PA |
11103 | case bp_until: |
11104 | ui_out_field_string | |
11105 | (uiout, "reason", | |
11106 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
11107 | break; | |
11108 | } | |
348d480f PA |
11109 | } |
11110 | ||
001c8c33 | 11111 | return PRINT_UNKNOWN; |
348d480f PA |
11112 | } |
11113 | ||
06edf0c0 PA |
11114 | static void |
11115 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 11116 | { |
06edf0c0 | 11117 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
11118 | } |
11119 | ||
348d480f | 11120 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 11121 | |
348d480f PA |
11122 | static void |
11123 | tracepoint_re_set (struct breakpoint *b) | |
11124 | { | |
11125 | breakpoint_re_set_default (b); | |
11126 | } | |
876fa593 | 11127 | |
348d480f PA |
11128 | static int |
11129 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
11130 | struct address_space *aspace, CORE_ADDR bp_addr) | |
11131 | { | |
11132 | /* By definition, the inferior does not report stops at | |
11133 | tracepoints. */ | |
11134 | return 0; | |
74960c60 VP |
11135 | } |
11136 | ||
11137 | static void | |
348d480f PA |
11138 | tracepoint_print_one_detail (const struct breakpoint *self, |
11139 | struct ui_out *uiout) | |
74960c60 | 11140 | { |
d9b3f62e PA |
11141 | struct tracepoint *tp = (struct tracepoint *) self; |
11142 | if (tp->static_trace_marker_id) | |
348d480f PA |
11143 | { |
11144 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 11145 | |
348d480f PA |
11146 | ui_out_text (uiout, "\tmarker id is "); |
11147 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 11148 | tp->static_trace_marker_id); |
348d480f PA |
11149 | ui_out_text (uiout, "\n"); |
11150 | } | |
0d381245 VP |
11151 | } |
11152 | ||
a474d7c2 | 11153 | static void |
348d480f | 11154 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 11155 | { |
79a45e25 | 11156 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 11157 | return; |
cc59ec59 | 11158 | |
348d480f PA |
11159 | switch (b->type) |
11160 | { | |
11161 | case bp_tracepoint: | |
11162 | printf_filtered (_("Tracepoint")); | |
11163 | printf_filtered (_(" %d"), b->number); | |
11164 | break; | |
11165 | case bp_fast_tracepoint: | |
11166 | printf_filtered (_("Fast tracepoint")); | |
11167 | printf_filtered (_(" %d"), b->number); | |
11168 | break; | |
11169 | case bp_static_tracepoint: | |
11170 | printf_filtered (_("Static tracepoint")); | |
11171 | printf_filtered (_(" %d"), b->number); | |
11172 | break; | |
11173 | default: | |
11174 | internal_error (__FILE__, __LINE__, | |
11175 | _("unhandled tracepoint type %d"), (int) b->type); | |
11176 | } | |
11177 | ||
11178 | say_where (b); | |
a474d7c2 PA |
11179 | } |
11180 | ||
348d480f | 11181 | static void |
d9b3f62e | 11182 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 11183 | { |
d9b3f62e PA |
11184 | struct tracepoint *tp = (struct tracepoint *) self; |
11185 | ||
11186 | if (self->type == bp_fast_tracepoint) | |
348d480f | 11187 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 11188 | if (self->type == bp_static_tracepoint) |
348d480f | 11189 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 11190 | else if (self->type == bp_tracepoint) |
348d480f PA |
11191 | fprintf_unfiltered (fp, "trace"); |
11192 | else | |
11193 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 11194 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 11195 | |
d9b3f62e PA |
11196 | fprintf_unfiltered (fp, " %s", self->addr_string); |
11197 | print_recreate_thread (self, fp); | |
11198 | ||
11199 | if (tp->pass_count) | |
11200 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
11201 | } |
11202 | ||
2060206e | 11203 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 11204 | |
53a5351d | 11205 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 11206 | structures. */ |
c906108c SS |
11207 | |
11208 | void | |
fba45db2 | 11209 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 11210 | { |
52f0bd74 | 11211 | struct breakpoint *b; |
c906108c | 11212 | |
8a3fe4f8 | 11213 | gdb_assert (bpt != NULL); |
c906108c | 11214 | |
4a64f543 MS |
11215 | /* Has this bp already been deleted? This can happen because |
11216 | multiple lists can hold pointers to bp's. bpstat lists are | |
11217 | especial culprits. | |
11218 | ||
11219 | One example of this happening is a watchpoint's scope bp. When | |
11220 | the scope bp triggers, we notice that the watchpoint is out of | |
11221 | scope, and delete it. We also delete its scope bp. But the | |
11222 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
11223 | That bpstat is then checked for auto-deleting bp's, which are | |
11224 | deleted. | |
11225 | ||
11226 | A real solution to this problem might involve reference counts in | |
11227 | bp's, and/or giving them pointers back to their referencing | |
11228 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
11229 | storage when no more references were extent. A cheaper bandaid | |
11230 | was chosen. */ | |
c906108c SS |
11231 | if (bpt->type == bp_none) |
11232 | return; | |
11233 | ||
4a64f543 MS |
11234 | /* At least avoid this stale reference until the reference counting |
11235 | of breakpoints gets resolved. */ | |
d0fb5eae | 11236 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 11237 | { |
d0fb5eae | 11238 | struct breakpoint *related; |
3a5c3e22 | 11239 | struct watchpoint *w; |
d0fb5eae JK |
11240 | |
11241 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 11242 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 11243 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
11244 | w = (struct watchpoint *) bpt; |
11245 | else | |
11246 | w = NULL; | |
11247 | if (w != NULL) | |
11248 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
11249 | |
11250 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
11251 | for (related = bpt; related->related_breakpoint != bpt; | |
11252 | related = related->related_breakpoint); | |
11253 | related->related_breakpoint = bpt->related_breakpoint; | |
11254 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
11255 | } |
11256 | ||
a9634178 TJB |
11257 | /* watch_command_1 creates a watchpoint but only sets its number if |
11258 | update_watchpoint succeeds in creating its bp_locations. If there's | |
11259 | a problem in that process, we'll be asked to delete the half-created | |
11260 | watchpoint. In that case, don't announce the deletion. */ | |
11261 | if (bpt->number) | |
11262 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 11263 | |
c906108c SS |
11264 | if (breakpoint_chain == bpt) |
11265 | breakpoint_chain = bpt->next; | |
11266 | ||
c906108c SS |
11267 | ALL_BREAKPOINTS (b) |
11268 | if (b->next == bpt) | |
c5aa993b JM |
11269 | { |
11270 | b->next = bpt->next; | |
11271 | break; | |
11272 | } | |
c906108c | 11273 | |
f431efe5 PA |
11274 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
11275 | been freed. */ | |
11276 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 11277 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
11278 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
11279 | commands are associated with the bpstat; if we remove it here, | |
11280 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
11281 | event-top.c won't do anything, and temporary breakpoints with | |
11282 | commands won't work. */ | |
11283 | ||
11284 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
11285 | ||
4a64f543 MS |
11286 | /* Now that breakpoint is removed from breakpoint list, update the |
11287 | global location list. This will remove locations that used to | |
11288 | belong to this breakpoint. Do this before freeing the breakpoint | |
11289 | itself, since remove_breakpoint looks at location's owner. It | |
11290 | might be better design to have location completely | |
11291 | self-contained, but it's not the case now. */ | |
b60e7edf | 11292 | update_global_location_list (0); |
74960c60 | 11293 | |
348d480f | 11294 | bpt->ops->dtor (bpt); |
4a64f543 MS |
11295 | /* On the chance that someone will soon try again to delete this |
11296 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 11297 | bpt->type = bp_none; |
b8c9b27d | 11298 | xfree (bpt); |
c906108c SS |
11299 | } |
11300 | ||
4d6140d9 AC |
11301 | static void |
11302 | do_delete_breakpoint_cleanup (void *b) | |
11303 | { | |
11304 | delete_breakpoint (b); | |
11305 | } | |
11306 | ||
11307 | struct cleanup * | |
11308 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
11309 | { | |
11310 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
11311 | } | |
11312 | ||
51be5b68 PA |
11313 | /* Iterator function to call a user-provided callback function once |
11314 | for each of B and its related breakpoints. */ | |
11315 | ||
11316 | static void | |
11317 | iterate_over_related_breakpoints (struct breakpoint *b, | |
11318 | void (*function) (struct breakpoint *, | |
11319 | void *), | |
11320 | void *data) | |
11321 | { | |
11322 | struct breakpoint *related; | |
11323 | ||
11324 | related = b; | |
11325 | do | |
11326 | { | |
11327 | struct breakpoint *next; | |
11328 | ||
11329 | /* FUNCTION may delete RELATED. */ | |
11330 | next = related->related_breakpoint; | |
11331 | ||
11332 | if (next == related) | |
11333 | { | |
11334 | /* RELATED is the last ring entry. */ | |
11335 | function (related, data); | |
11336 | ||
11337 | /* FUNCTION may have deleted it, so we'd never reach back to | |
11338 | B. There's nothing left to do anyway, so just break | |
11339 | out. */ | |
11340 | break; | |
11341 | } | |
11342 | else | |
11343 | function (related, data); | |
11344 | ||
11345 | related = next; | |
11346 | } | |
11347 | while (related != b); | |
11348 | } | |
95a42b64 TT |
11349 | |
11350 | static void | |
11351 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11352 | { | |
11353 | delete_breakpoint (b); | |
11354 | } | |
11355 | ||
51be5b68 PA |
11356 | /* A callback for map_breakpoint_numbers that calls |
11357 | delete_breakpoint. */ | |
11358 | ||
11359 | static void | |
11360 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11361 | { | |
11362 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
11363 | } | |
11364 | ||
c906108c | 11365 | void |
fba45db2 | 11366 | delete_command (char *arg, int from_tty) |
c906108c | 11367 | { |
35df4500 | 11368 | struct breakpoint *b, *b_tmp; |
c906108c | 11369 | |
ea9365bb TT |
11370 | dont_repeat (); |
11371 | ||
c906108c SS |
11372 | if (arg == 0) |
11373 | { | |
11374 | int breaks_to_delete = 0; | |
11375 | ||
46c6471b PA |
11376 | /* Delete all breakpoints if no argument. Do not delete |
11377 | internal breakpoints, these have to be deleted with an | |
11378 | explicit breakpoint number argument. */ | |
c5aa993b | 11379 | ALL_BREAKPOINTS (b) |
46c6471b | 11380 | if (user_breakpoint_p (b)) |
973d738b DJ |
11381 | { |
11382 | breaks_to_delete = 1; | |
11383 | break; | |
11384 | } | |
c906108c SS |
11385 | |
11386 | /* Ask user only if there are some breakpoints to delete. */ | |
11387 | if (!from_tty | |
e2e0b3e5 | 11388 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 11389 | { |
35df4500 | 11390 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 11391 | if (user_breakpoint_p (b)) |
c5aa993b | 11392 | delete_breakpoint (b); |
c906108c SS |
11393 | } |
11394 | } | |
11395 | else | |
51be5b68 | 11396 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
11397 | } |
11398 | ||
0d381245 VP |
11399 | static int |
11400 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 11401 | { |
0d381245 VP |
11402 | for (; loc; loc = loc->next) |
11403 | if (!loc->shlib_disabled) | |
11404 | return 0; | |
11405 | return 1; | |
fe3f5fa8 VP |
11406 | } |
11407 | ||
776592bf DE |
11408 | /* Subroutine of update_breakpoint_locations to simplify it. |
11409 | Return non-zero if multiple fns in list LOC have the same name. | |
11410 | Null names are ignored. */ | |
11411 | ||
11412 | static int | |
11413 | ambiguous_names_p (struct bp_location *loc) | |
11414 | { | |
11415 | struct bp_location *l; | |
11416 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
11417 | (int (*) (const void *, |
11418 | const void *)) streq, | |
776592bf DE |
11419 | NULL, xcalloc, xfree); |
11420 | ||
11421 | for (l = loc; l != NULL; l = l->next) | |
11422 | { | |
11423 | const char **slot; | |
11424 | const char *name = l->function_name; | |
11425 | ||
11426 | /* Allow for some names to be NULL, ignore them. */ | |
11427 | if (name == NULL) | |
11428 | continue; | |
11429 | ||
11430 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
11431 | INSERT); | |
4a64f543 MS |
11432 | /* NOTE: We can assume slot != NULL here because xcalloc never |
11433 | returns NULL. */ | |
776592bf DE |
11434 | if (*slot != NULL) |
11435 | { | |
11436 | htab_delete (htab); | |
11437 | return 1; | |
11438 | } | |
11439 | *slot = name; | |
11440 | } | |
11441 | ||
11442 | htab_delete (htab); | |
11443 | return 0; | |
11444 | } | |
11445 | ||
0fb4aa4b PA |
11446 | /* When symbols change, it probably means the sources changed as well, |
11447 | and it might mean the static tracepoint markers are no longer at | |
11448 | the same address or line numbers they used to be at last we | |
11449 | checked. Losing your static tracepoints whenever you rebuild is | |
11450 | undesirable. This function tries to resync/rematch gdb static | |
11451 | tracepoints with the markers on the target, for static tracepoints | |
11452 | that have not been set by marker id. Static tracepoint that have | |
11453 | been set by marker id are reset by marker id in breakpoint_re_set. | |
11454 | The heuristic is: | |
11455 | ||
11456 | 1) For a tracepoint set at a specific address, look for a marker at | |
11457 | the old PC. If one is found there, assume to be the same marker. | |
11458 | If the name / string id of the marker found is different from the | |
11459 | previous known name, assume that means the user renamed the marker | |
11460 | in the sources, and output a warning. | |
11461 | ||
11462 | 2) For a tracepoint set at a given line number, look for a marker | |
11463 | at the new address of the old line number. If one is found there, | |
11464 | assume to be the same marker. If the name / string id of the | |
11465 | marker found is different from the previous known name, assume that | |
11466 | means the user renamed the marker in the sources, and output a | |
11467 | warning. | |
11468 | ||
11469 | 3) If a marker is no longer found at the same address or line, it | |
11470 | may mean the marker no longer exists. But it may also just mean | |
11471 | the code changed a bit. Maybe the user added a few lines of code | |
11472 | that made the marker move up or down (in line number terms). Ask | |
11473 | the target for info about the marker with the string id as we knew | |
11474 | it. If found, update line number and address in the matching | |
11475 | static tracepoint. This will get confused if there's more than one | |
11476 | marker with the same ID (possible in UST, although unadvised | |
11477 | precisely because it confuses tools). */ | |
11478 | ||
11479 | static struct symtab_and_line | |
11480 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
11481 | { | |
d9b3f62e | 11482 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
11483 | struct static_tracepoint_marker marker; |
11484 | CORE_ADDR pc; | |
11485 | int i; | |
11486 | ||
11487 | pc = sal.pc; | |
11488 | if (sal.line) | |
11489 | find_line_pc (sal.symtab, sal.line, &pc); | |
11490 | ||
11491 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
11492 | { | |
d9b3f62e | 11493 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
11494 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
11495 | b->number, | |
d9b3f62e | 11496 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 11497 | |
d9b3f62e PA |
11498 | xfree (tp->static_trace_marker_id); |
11499 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
11500 | release_static_tracepoint_marker (&marker); |
11501 | ||
11502 | return sal; | |
11503 | } | |
11504 | ||
11505 | /* Old marker wasn't found on target at lineno. Try looking it up | |
11506 | by string ID. */ | |
11507 | if (!sal.explicit_pc | |
11508 | && sal.line != 0 | |
11509 | && sal.symtab != NULL | |
d9b3f62e | 11510 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
11511 | { |
11512 | VEC(static_tracepoint_marker_p) *markers; | |
11513 | ||
11514 | markers | |
d9b3f62e | 11515 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
11516 | |
11517 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
11518 | { | |
11519 | struct symtab_and_line sal; | |
11520 | struct symbol *sym; | |
11521 | struct static_tracepoint_marker *marker; | |
79a45e25 | 11522 | struct ui_out *uiout = current_uiout; |
0fb4aa4b PA |
11523 | |
11524 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
11525 | ||
d9b3f62e PA |
11526 | xfree (tp->static_trace_marker_id); |
11527 | tp->static_trace_marker_id = xstrdup (marker->str_id); | |
0fb4aa4b PA |
11528 | |
11529 | warning (_("marker for static tracepoint %d (%s) not " | |
11530 | "found at previous line number"), | |
d9b3f62e | 11531 | b->number, tp->static_trace_marker_id); |
0fb4aa4b PA |
11532 | |
11533 | init_sal (&sal); | |
11534 | ||
11535 | sal.pc = marker->address; | |
11536 | ||
11537 | sal = find_pc_line (marker->address, 0); | |
11538 | sym = find_pc_sect_function (marker->address, NULL); | |
11539 | ui_out_text (uiout, "Now in "); | |
11540 | if (sym) | |
11541 | { | |
11542 | ui_out_field_string (uiout, "func", | |
11543 | SYMBOL_PRINT_NAME (sym)); | |
11544 | ui_out_text (uiout, " at "); | |
11545 | } | |
11546 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
11547 | ui_out_text (uiout, ":"); | |
11548 | ||
11549 | if (ui_out_is_mi_like_p (uiout)) | |
11550 | { | |
11551 | char *fullname = symtab_to_fullname (sal.symtab); | |
11552 | ||
11553 | if (fullname) | |
11554 | ui_out_field_string (uiout, "fullname", fullname); | |
11555 | } | |
11556 | ||
11557 | ui_out_field_int (uiout, "line", sal.line); | |
11558 | ui_out_text (uiout, "\n"); | |
11559 | ||
11560 | b->line_number = sal.line; | |
11561 | ||
11562 | xfree (b->source_file); | |
11563 | if (sym) | |
11564 | b->source_file = xstrdup (sal.symtab->filename); | |
11565 | else | |
11566 | b->source_file = NULL; | |
11567 | ||
11568 | xfree (b->addr_string); | |
11569 | b->addr_string = xstrprintf ("%s:%d", | |
11570 | sal.symtab->filename, b->line_number); | |
11571 | ||
11572 | /* Might be nice to check if function changed, and warn if | |
11573 | so. */ | |
11574 | ||
11575 | release_static_tracepoint_marker (marker); | |
11576 | } | |
11577 | } | |
11578 | return sal; | |
11579 | } | |
11580 | ||
8d3788bd VP |
11581 | /* Returns 1 iff locations A and B are sufficiently same that |
11582 | we don't need to report breakpoint as changed. */ | |
11583 | ||
11584 | static int | |
11585 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
11586 | { | |
11587 | while (a && b) | |
11588 | { | |
11589 | if (a->address != b->address) | |
11590 | return 0; | |
11591 | ||
11592 | if (a->shlib_disabled != b->shlib_disabled) | |
11593 | return 0; | |
11594 | ||
11595 | if (a->enabled != b->enabled) | |
11596 | return 0; | |
11597 | ||
11598 | a = a->next; | |
11599 | b = b->next; | |
11600 | } | |
11601 | ||
11602 | if ((a == NULL) != (b == NULL)) | |
11603 | return 0; | |
11604 | ||
11605 | return 1; | |
11606 | } | |
11607 | ||
f1310107 TJB |
11608 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
11609 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
11610 | a ranged breakpoint. */ | |
11611 | ||
0e30163f | 11612 | void |
0d381245 | 11613 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
11614 | struct symtabs_and_lines sals, |
11615 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
11616 | { |
11617 | int i; | |
0d381245 VP |
11618 | struct bp_location *existing_locations = b->loc; |
11619 | ||
f1310107 TJB |
11620 | /* Ranged breakpoints have only one start location and one end location. */ |
11621 | gdb_assert (sals_end.nelts == 0 || (sals.nelts == 1 && sals_end.nelts == 1)); | |
11622 | ||
4a64f543 MS |
11623 | /* If there's no new locations, and all existing locations are |
11624 | pending, don't do anything. This optimizes the common case where | |
11625 | all locations are in the same shared library, that was unloaded. | |
11626 | We'd like to retain the location, so that when the library is | |
11627 | loaded again, we don't loose the enabled/disabled status of the | |
11628 | individual locations. */ | |
0d381245 | 11629 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
11630 | return; |
11631 | ||
fe3f5fa8 VP |
11632 | b->loc = NULL; |
11633 | ||
0d381245 | 11634 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 11635 | { |
0d381245 | 11636 | struct bp_location *new_loc = |
39d61571 | 11637 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 11638 | |
0d381245 VP |
11639 | /* Reparse conditions, they might contain references to the |
11640 | old symtab. */ | |
11641 | if (b->cond_string != NULL) | |
11642 | { | |
f1310107 | 11643 | char *s; |
0d381245 | 11644 | struct gdb_exception e; |
fe3f5fa8 | 11645 | |
0d381245 VP |
11646 | s = b->cond_string; |
11647 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11648 | { | |
11649 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
11650 | 0); | |
11651 | } | |
11652 | if (e.reason < 0) | |
11653 | { | |
3e43a32a MS |
11654 | warning (_("failed to reevaluate condition " |
11655 | "for breakpoint %d: %s"), | |
0d381245 VP |
11656 | b->number, e.message); |
11657 | new_loc->enabled = 0; | |
11658 | } | |
11659 | } | |
fe3f5fa8 | 11660 | |
0d381245 VP |
11661 | if (b->source_file != NULL) |
11662 | xfree (b->source_file); | |
11663 | if (sals.sals[i].symtab == NULL) | |
11664 | b->source_file = NULL; | |
11665 | else | |
1b36a34b | 11666 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 11667 | |
0d381245 VP |
11668 | if (b->line_number == 0) |
11669 | b->line_number = sals.sals[i].line; | |
f1310107 TJB |
11670 | |
11671 | if (sals_end.nelts) | |
11672 | { | |
11673 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
11674 | ||
11675 | new_loc->length = end - sals.sals[0].pc + 1; | |
11676 | } | |
0d381245 | 11677 | } |
fe3f5fa8 | 11678 | |
514f746b AR |
11679 | /* Update locations of permanent breakpoints. */ |
11680 | if (b->enable_state == bp_permanent) | |
11681 | make_breakpoint_permanent (b); | |
11682 | ||
4a64f543 MS |
11683 | /* If possible, carry over 'disable' status from existing |
11684 | breakpoints. */ | |
0d381245 VP |
11685 | { |
11686 | struct bp_location *e = existing_locations; | |
776592bf DE |
11687 | /* If there are multiple breakpoints with the same function name, |
11688 | e.g. for inline functions, comparing function names won't work. | |
11689 | Instead compare pc addresses; this is just a heuristic as things | |
11690 | may have moved, but in practice it gives the correct answer | |
11691 | often enough until a better solution is found. */ | |
11692 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
11693 | ||
0d381245 VP |
11694 | for (; e; e = e->next) |
11695 | { | |
11696 | if (!e->enabled && e->function_name) | |
11697 | { | |
11698 | struct bp_location *l = b->loc; | |
776592bf DE |
11699 | if (have_ambiguous_names) |
11700 | { | |
11701 | for (; l; l = l->next) | |
f1310107 | 11702 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
11703 | { |
11704 | l->enabled = 0; | |
11705 | break; | |
11706 | } | |
11707 | } | |
11708 | else | |
11709 | { | |
11710 | for (; l; l = l->next) | |
11711 | if (l->function_name | |
11712 | && strcmp (e->function_name, l->function_name) == 0) | |
11713 | { | |
11714 | l->enabled = 0; | |
11715 | break; | |
11716 | } | |
11717 | } | |
0d381245 VP |
11718 | } |
11719 | } | |
11720 | } | |
fe3f5fa8 | 11721 | |
8d3788bd VP |
11722 | if (!locations_are_equal (existing_locations, b->loc)) |
11723 | observer_notify_breakpoint_modified (b); | |
11724 | ||
b60e7edf | 11725 | update_global_location_list (1); |
fe3f5fa8 VP |
11726 | } |
11727 | ||
ef23e705 TJB |
11728 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
11729 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
11730 | ||
11731 | static struct symtabs_and_lines | |
11732 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
11733 | { | |
11734 | char *s; | |
58438ac1 | 11735 | int marker_spec; |
02d20e4a | 11736 | struct symtabs_and_lines sals = {0}; |
ef23e705 TJB |
11737 | struct gdb_exception e; |
11738 | ||
11739 | s = addr_string; | |
11740 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); | |
11741 | ||
11742 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11743 | { | |
11744 | if (marker_spec) | |
11745 | { | |
d9b3f62e PA |
11746 | struct tracepoint *tp = (struct tracepoint *) b; |
11747 | ||
ef23e705 | 11748 | sals = decode_static_tracepoint_spec (&s); |
d9b3f62e | 11749 | if (sals.nelts > tp->static_trace_marker_id_idx) |
ef23e705 | 11750 | { |
d9b3f62e | 11751 | sals.sals[0] = sals.sals[tp->static_trace_marker_id_idx]; |
ef23e705 TJB |
11752 | sals.nelts = 1; |
11753 | } | |
11754 | else | |
d9b3f62e | 11755 | error (_("marker %s not found"), tp->static_trace_marker_id); |
ef23e705 TJB |
11756 | } |
11757 | else | |
58438ac1 | 11758 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, NULL); |
ef23e705 TJB |
11759 | } |
11760 | if (e.reason < 0) | |
11761 | { | |
11762 | int not_found_and_ok = 0; | |
11763 | /* For pending breakpoints, it's expected that parsing will | |
11764 | fail until the right shared library is loaded. User has | |
11765 | already told to create pending breakpoints and don't need | |
11766 | extra messages. If breakpoint is in bp_shlib_disabled | |
11767 | state, then user already saw the message about that | |
11768 | breakpoint being disabled, and don't want to see more | |
11769 | errors. */ | |
58438ac1 | 11770 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
11771 | && (b->condition_not_parsed |
11772 | || (b->loc && b->loc->shlib_disabled) | |
11773 | || b->enable_state == bp_disabled)) | |
11774 | not_found_and_ok = 1; | |
11775 | ||
11776 | if (!not_found_and_ok) | |
11777 | { | |
11778 | /* We surely don't want to warn about the same breakpoint | |
11779 | 10 times. One solution, implemented here, is disable | |
11780 | the breakpoint on error. Another solution would be to | |
11781 | have separate 'warning emitted' flag. Since this | |
11782 | happens only when a binary has changed, I don't know | |
11783 | which approach is better. */ | |
11784 | b->enable_state = bp_disabled; | |
11785 | throw_exception (e); | |
11786 | } | |
11787 | } | |
11788 | ||
58438ac1 | 11789 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 TJB |
11790 | { |
11791 | gdb_assert (sals.nelts == 1); | |
11792 | ||
11793 | resolve_sal_pc (&sals.sals[0]); | |
11794 | if (b->condition_not_parsed && s && s[0]) | |
11795 | { | |
11796 | char *cond_string = 0; | |
11797 | int thread = -1; | |
11798 | int task = 0; | |
11799 | ||
11800 | find_condition_and_thread (s, sals.sals[0].pc, | |
11801 | &cond_string, &thread, &task); | |
11802 | if (cond_string) | |
11803 | b->cond_string = cond_string; | |
11804 | b->thread = thread; | |
11805 | b->task = task; | |
11806 | b->condition_not_parsed = 0; | |
11807 | } | |
11808 | ||
11809 | if (b->type == bp_static_tracepoint && !marker_spec) | |
11810 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
ef23e705 | 11811 | |
58438ac1 TT |
11812 | *found = 1; |
11813 | } | |
11814 | else | |
11815 | *found = 0; | |
ef23e705 TJB |
11816 | |
11817 | return sals; | |
11818 | } | |
11819 | ||
348d480f PA |
11820 | /* The default re_set method, for typical hardware or software |
11821 | breakpoints. Reevaluate the breakpoint and recreate its | |
11822 | locations. */ | |
11823 | ||
11824 | static void | |
28010a5d | 11825 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
11826 | { |
11827 | int found; | |
f1310107 | 11828 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 11829 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 11830 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
11831 | |
11832 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
11833 | if (found) | |
11834 | { | |
11835 | make_cleanup (xfree, sals.sals); | |
11836 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
11837 | } | |
11838 | ||
f1310107 TJB |
11839 | if (b->addr_string_range_end) |
11840 | { | |
11841 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
11842 | if (found) | |
11843 | { | |
11844 | make_cleanup (xfree, sals_end.sals); | |
11845 | expanded_end = expand_line_sal_maybe (sals_end.sals[0]); | |
11846 | } | |
11847 | } | |
11848 | ||
11849 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
11850 | } |
11851 | ||
11852 | /* Prepare the global context for a re-set of breakpoint B. */ | |
11853 | ||
11854 | static struct cleanup * | |
11855 | prepare_re_set_context (struct breakpoint *b) | |
11856 | { | |
11857 | struct cleanup *cleanups; | |
11858 | ||
11859 | input_radix = b->input_radix; | |
11860 | cleanups = save_current_space_and_thread (); | |
11861 | switch_to_program_space_and_thread (b->pspace); | |
11862 | set_language (b->language); | |
11863 | ||
11864 | return cleanups; | |
ef23e705 TJB |
11865 | } |
11866 | ||
c906108c SS |
11867 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
11868 | The value we return ends up being the return value from catch_errors. | |
11869 | Unused in this case. */ | |
11870 | ||
11871 | static int | |
4efb68b1 | 11872 | breakpoint_re_set_one (void *bint) |
c906108c | 11873 | { |
4a64f543 | 11874 | /* Get past catch_errs. */ |
53a5351d | 11875 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 11876 | struct cleanup *cleanups; |
c906108c | 11877 | |
348d480f PA |
11878 | cleanups = prepare_re_set_context (b); |
11879 | b->ops->re_set (b); | |
11880 | do_cleanups (cleanups); | |
c906108c SS |
11881 | return 0; |
11882 | } | |
11883 | ||
69de3c6a | 11884 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 11885 | void |
69de3c6a | 11886 | breakpoint_re_set (void) |
c906108c | 11887 | { |
35df4500 | 11888 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11889 | enum language save_language; |
11890 | int save_input_radix; | |
6c95b8df | 11891 | struct cleanup *old_chain; |
c5aa993b | 11892 | |
c906108c SS |
11893 | save_language = current_language->la_language; |
11894 | save_input_radix = input_radix; | |
6c95b8df PA |
11895 | old_chain = save_current_program_space (); |
11896 | ||
35df4500 | 11897 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11898 | { |
4a64f543 | 11899 | /* Format possible error msg. */ |
fe3f5fa8 | 11900 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
11901 | b->number); |
11902 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 11903 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 11904 | do_cleanups (cleanups); |
c5aa993b | 11905 | } |
c906108c SS |
11906 | set_language (save_language); |
11907 | input_radix = save_input_radix; | |
e62c965a | 11908 | |
0756c555 | 11909 | jit_breakpoint_re_set (); |
4efc6507 | 11910 | |
6c95b8df PA |
11911 | do_cleanups (old_chain); |
11912 | ||
af02033e PP |
11913 | create_overlay_event_breakpoint (); |
11914 | create_longjmp_master_breakpoint (); | |
11915 | create_std_terminate_master_breakpoint (); | |
186c406b | 11916 | create_exception_master_breakpoint (); |
c906108c SS |
11917 | } |
11918 | \f | |
c906108c SS |
11919 | /* Reset the thread number of this breakpoint: |
11920 | ||
11921 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 11922 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 11923 | void |
fba45db2 | 11924 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
11925 | { |
11926 | if (b->thread != -1) | |
11927 | { | |
39f77062 KB |
11928 | if (in_thread_list (inferior_ptid)) |
11929 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
11930 | |
11931 | /* We're being called after following a fork. The new fork is | |
11932 | selected as current, and unless this was a vfork will have a | |
11933 | different program space from the original thread. Reset that | |
11934 | as well. */ | |
11935 | b->loc->pspace = current_program_space; | |
c906108c SS |
11936 | } |
11937 | } | |
11938 | ||
03ac34d5 MS |
11939 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
11940 | If from_tty is nonzero, it prints a message to that effect, | |
11941 | which ends with a period (no newline). */ | |
11942 | ||
c906108c | 11943 | void |
fba45db2 | 11944 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 11945 | { |
52f0bd74 | 11946 | struct breakpoint *b; |
c906108c SS |
11947 | |
11948 | if (count < 0) | |
11949 | count = 0; | |
11950 | ||
11951 | ALL_BREAKPOINTS (b) | |
11952 | if (b->number == bptnum) | |
c5aa993b | 11953 | { |
d77f58be SS |
11954 | if (is_tracepoint (b)) |
11955 | { | |
11956 | if (from_tty && count != 0) | |
11957 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
11958 | bptnum); | |
11959 | return; | |
11960 | } | |
11961 | ||
c5aa993b | 11962 | b->ignore_count = count; |
221ea385 KS |
11963 | if (from_tty) |
11964 | { | |
11965 | if (count == 0) | |
3e43a32a MS |
11966 | printf_filtered (_("Will stop next time " |
11967 | "breakpoint %d is reached."), | |
221ea385 KS |
11968 | bptnum); |
11969 | else if (count == 1) | |
a3f17187 | 11970 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
11971 | bptnum); |
11972 | else | |
3e43a32a MS |
11973 | printf_filtered (_("Will ignore next %d " |
11974 | "crossings of breakpoint %d."), | |
221ea385 KS |
11975 | count, bptnum); |
11976 | } | |
c5aa993b | 11977 | breakpoints_changed (); |
8d3788bd | 11978 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
11979 | return; |
11980 | } | |
c906108c | 11981 | |
8a3fe4f8 | 11982 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
11983 | } |
11984 | ||
c906108c SS |
11985 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
11986 | ||
11987 | static void | |
fba45db2 | 11988 | ignore_command (char *args, int from_tty) |
c906108c SS |
11989 | { |
11990 | char *p = args; | |
52f0bd74 | 11991 | int num; |
c906108c SS |
11992 | |
11993 | if (p == 0) | |
e2e0b3e5 | 11994 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 11995 | |
c906108c | 11996 | num = get_number (&p); |
5c44784c | 11997 | if (num == 0) |
8a3fe4f8 | 11998 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 11999 | if (*p == 0) |
8a3fe4f8 | 12000 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
12001 | |
12002 | set_ignore_count (num, | |
12003 | longest_to_int (value_as_long (parse_and_eval (p))), | |
12004 | from_tty); | |
221ea385 KS |
12005 | if (from_tty) |
12006 | printf_filtered ("\n"); | |
c906108c SS |
12007 | } |
12008 | \f | |
12009 | /* Call FUNCTION on each of the breakpoints | |
12010 | whose numbers are given in ARGS. */ | |
12011 | ||
12012 | static void | |
95a42b64 TT |
12013 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
12014 | void *), | |
12015 | void *data) | |
c906108c | 12016 | { |
52f0bd74 AC |
12017 | int num; |
12018 | struct breakpoint *b, *tmp; | |
11cf8741 | 12019 | int match; |
197f0a60 | 12020 | struct get_number_or_range_state state; |
c906108c | 12021 | |
197f0a60 | 12022 | if (args == 0) |
e2e0b3e5 | 12023 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 12024 | |
197f0a60 TT |
12025 | init_number_or_range (&state, args); |
12026 | ||
12027 | while (!state.finished) | |
c906108c | 12028 | { |
197f0a60 TT |
12029 | char *p = state.string; |
12030 | ||
11cf8741 | 12031 | match = 0; |
c5aa993b | 12032 | |
197f0a60 | 12033 | num = get_number_or_range (&state); |
5c44784c | 12034 | if (num == 0) |
c5aa993b | 12035 | { |
8a3fe4f8 | 12036 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
12037 | } |
12038 | else | |
12039 | { | |
12040 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
12041 | if (b->number == num) | |
12042 | { | |
11cf8741 | 12043 | match = 1; |
cdac0397 | 12044 | function (b, data); |
11cf8741 | 12045 | break; |
5c44784c | 12046 | } |
11cf8741 | 12047 | if (match == 0) |
a3f17187 | 12048 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 12049 | } |
c906108c SS |
12050 | } |
12051 | } | |
12052 | ||
0d381245 VP |
12053 | static struct bp_location * |
12054 | find_location_by_number (char *number) | |
12055 | { | |
12056 | char *dot = strchr (number, '.'); | |
12057 | char *p1; | |
12058 | int bp_num; | |
12059 | int loc_num; | |
12060 | struct breakpoint *b; | |
12061 | struct bp_location *loc; | |
12062 | ||
12063 | *dot = '\0'; | |
12064 | ||
12065 | p1 = number; | |
197f0a60 | 12066 | bp_num = get_number (&p1); |
0d381245 VP |
12067 | if (bp_num == 0) |
12068 | error (_("Bad breakpoint number '%s'"), number); | |
12069 | ||
12070 | ALL_BREAKPOINTS (b) | |
12071 | if (b->number == bp_num) | |
12072 | { | |
12073 | break; | |
12074 | } | |
12075 | ||
12076 | if (!b || b->number != bp_num) | |
12077 | error (_("Bad breakpoint number '%s'"), number); | |
12078 | ||
12079 | p1 = dot+1; | |
197f0a60 | 12080 | loc_num = get_number (&p1); |
0d381245 VP |
12081 | if (loc_num == 0) |
12082 | error (_("Bad breakpoint location number '%s'"), number); | |
12083 | ||
12084 | --loc_num; | |
12085 | loc = b->loc; | |
12086 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
12087 | ; | |
12088 | if (!loc) | |
12089 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
12090 | ||
12091 | return loc; | |
12092 | } | |
12093 | ||
12094 | ||
1900040c MS |
12095 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
12096 | If from_tty is nonzero, it prints a message to that effect, | |
12097 | which ends with a period (no newline). */ | |
12098 | ||
c906108c | 12099 | void |
fba45db2 | 12100 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
12101 | { |
12102 | /* Never disable a watchpoint scope breakpoint; we want to | |
12103 | hit them when we leave scope so we can delete both the | |
12104 | watchpoint and its scope breakpoint at that time. */ | |
12105 | if (bpt->type == bp_watchpoint_scope) | |
12106 | return; | |
12107 | ||
c2c6d25f | 12108 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 12109 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
12110 | return; |
12111 | ||
b5de0fa7 | 12112 | bpt->enable_state = bp_disabled; |
c906108c | 12113 | |
d248b706 KY |
12114 | if (target_supports_enable_disable_tracepoint () |
12115 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12116 | { | |
12117 | struct bp_location *location; | |
12118 | ||
12119 | for (location = bpt->loc; location; location = location->next) | |
12120 | target_disable_tracepoint (location); | |
12121 | } | |
12122 | ||
b60e7edf | 12123 | update_global_location_list (0); |
c906108c | 12124 | |
8d3788bd | 12125 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12126 | } |
12127 | ||
51be5b68 PA |
12128 | /* A callback for iterate_over_related_breakpoints. */ |
12129 | ||
12130 | static void | |
12131 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12132 | { | |
12133 | disable_breakpoint (b); | |
12134 | } | |
12135 | ||
95a42b64 TT |
12136 | /* A callback for map_breakpoint_numbers that calls |
12137 | disable_breakpoint. */ | |
12138 | ||
12139 | static void | |
12140 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12141 | { | |
51be5b68 | 12142 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
12143 | } |
12144 | ||
c906108c | 12145 | static void |
fba45db2 | 12146 | disable_command (char *args, int from_tty) |
c906108c | 12147 | { |
c906108c | 12148 | if (args == 0) |
46c6471b PA |
12149 | { |
12150 | struct breakpoint *bpt; | |
12151 | ||
12152 | ALL_BREAKPOINTS (bpt) | |
12153 | if (user_breakpoint_p (bpt)) | |
12154 | disable_breakpoint (bpt); | |
12155 | } | |
0d381245 VP |
12156 | else if (strchr (args, '.')) |
12157 | { | |
12158 | struct bp_location *loc = find_location_by_number (args); | |
12159 | if (loc) | |
d248b706 KY |
12160 | { |
12161 | loc->enabled = 0; | |
12162 | if (target_supports_enable_disable_tracepoint () | |
12163 | && current_trace_status ()->running && loc->owner | |
12164 | && is_tracepoint (loc->owner)) | |
12165 | target_disable_tracepoint (loc); | |
12166 | } | |
b60e7edf | 12167 | update_global_location_list (0); |
0d381245 | 12168 | } |
c906108c | 12169 | else |
95a42b64 | 12170 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
12171 | } |
12172 | ||
12173 | static void | |
51be5b68 | 12174 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 12175 | { |
afe38095 | 12176 | int target_resources_ok; |
c906108c SS |
12177 | |
12178 | if (bpt->type == bp_hardware_breakpoint) | |
12179 | { | |
12180 | int i; | |
c5aa993b | 12181 | i = hw_breakpoint_used_count (); |
53a5351d | 12182 | target_resources_ok = |
d92524f1 | 12183 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 12184 | i + 1, 0); |
c906108c | 12185 | if (target_resources_ok == 0) |
8a3fe4f8 | 12186 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 12187 | else if (target_resources_ok < 0) |
8a3fe4f8 | 12188 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
12189 | } |
12190 | ||
cc60f2e3 | 12191 | if (is_watchpoint (bpt)) |
c906108c | 12192 | { |
d07205c2 JK |
12193 | /* Initialize it just to avoid a GCC false warning. */ |
12194 | enum enable_state orig_enable_state = 0; | |
dde02812 ES |
12195 | struct gdb_exception e; |
12196 | ||
12197 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 12198 | { |
3a5c3e22 PA |
12199 | struct watchpoint *w = (struct watchpoint *) bpt; |
12200 | ||
1e718ff1 TJB |
12201 | orig_enable_state = bpt->enable_state; |
12202 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 12203 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 12204 | } |
dde02812 | 12205 | if (e.reason < 0) |
c5aa993b | 12206 | { |
1e718ff1 | 12207 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
12208 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
12209 | bpt->number); | |
12210 | return; | |
c5aa993b | 12211 | } |
c906108c | 12212 | } |
0101ce28 | 12213 | |
b4c291bb KH |
12214 | if (bpt->enable_state != bp_permanent) |
12215 | bpt->enable_state = bp_enabled; | |
d248b706 KY |
12216 | |
12217 | if (target_supports_enable_disable_tracepoint () | |
12218 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12219 | { | |
12220 | struct bp_location *location; | |
12221 | ||
12222 | for (location = bpt->loc; location; location = location->next) | |
12223 | target_enable_tracepoint (location); | |
12224 | } | |
12225 | ||
b4c291bb | 12226 | bpt->disposition = disposition; |
b60e7edf | 12227 | update_global_location_list (1); |
b4c291bb KH |
12228 | breakpoints_changed (); |
12229 | ||
8d3788bd | 12230 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12231 | } |
12232 | ||
fe3f5fa8 | 12233 | |
c906108c | 12234 | void |
fba45db2 | 12235 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 12236 | { |
51be5b68 PA |
12237 | enable_breakpoint_disp (bpt, bpt->disposition); |
12238 | } | |
12239 | ||
12240 | static void | |
12241 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
12242 | { | |
12243 | enable_breakpoint (bpt); | |
c906108c SS |
12244 | } |
12245 | ||
95a42b64 TT |
12246 | /* A callback for map_breakpoint_numbers that calls |
12247 | enable_breakpoint. */ | |
12248 | ||
12249 | static void | |
12250 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
12251 | { | |
51be5b68 | 12252 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
12253 | } |
12254 | ||
c906108c SS |
12255 | /* The enable command enables the specified breakpoints (or all defined |
12256 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 12257 | in stopping the inferior. */ |
c906108c | 12258 | |
c906108c | 12259 | static void |
fba45db2 | 12260 | enable_command (char *args, int from_tty) |
c906108c | 12261 | { |
c906108c | 12262 | if (args == 0) |
46c6471b PA |
12263 | { |
12264 | struct breakpoint *bpt; | |
12265 | ||
12266 | ALL_BREAKPOINTS (bpt) | |
12267 | if (user_breakpoint_p (bpt)) | |
12268 | enable_breakpoint (bpt); | |
12269 | } | |
0d381245 VP |
12270 | else if (strchr (args, '.')) |
12271 | { | |
12272 | struct bp_location *loc = find_location_by_number (args); | |
12273 | if (loc) | |
d248b706 KY |
12274 | { |
12275 | loc->enabled = 1; | |
12276 | if (target_supports_enable_disable_tracepoint () | |
12277 | && current_trace_status ()->running && loc->owner | |
12278 | && is_tracepoint (loc->owner)) | |
12279 | target_enable_tracepoint (loc); | |
12280 | } | |
b60e7edf | 12281 | update_global_location_list (1); |
0d381245 | 12282 | } |
c906108c | 12283 | else |
95a42b64 | 12284 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
12285 | } |
12286 | ||
12287 | static void | |
51be5b68 PA |
12288 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
12289 | { | |
12290 | enum bpdisp disp = *(enum bpdisp *) arg; | |
12291 | ||
12292 | enable_breakpoint_disp (bpt, disp); | |
12293 | } | |
12294 | ||
12295 | static void | |
12296 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 12297 | { |
51be5b68 PA |
12298 | enum bpdisp disp = disp_disable; |
12299 | ||
12300 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12301 | } |
12302 | ||
c906108c | 12303 | static void |
fba45db2 | 12304 | enable_once_command (char *args, int from_tty) |
c906108c | 12305 | { |
51be5b68 | 12306 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
12307 | } |
12308 | ||
12309 | static void | |
51be5b68 | 12310 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 12311 | { |
51be5b68 PA |
12312 | enum bpdisp disp = disp_del; |
12313 | ||
12314 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12315 | } |
12316 | ||
c906108c | 12317 | static void |
fba45db2 | 12318 | enable_delete_command (char *args, int from_tty) |
c906108c | 12319 | { |
51be5b68 | 12320 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
12321 | } |
12322 | \f | |
fa8d40ab JJ |
12323 | static void |
12324 | set_breakpoint_cmd (char *args, int from_tty) | |
12325 | { | |
12326 | } | |
12327 | ||
12328 | static void | |
12329 | show_breakpoint_cmd (char *args, int from_tty) | |
12330 | { | |
12331 | } | |
12332 | ||
1f3b5d1b PP |
12333 | /* Invalidate last known value of any hardware watchpoint if |
12334 | the memory which that value represents has been written to by | |
12335 | GDB itself. */ | |
12336 | ||
12337 | static void | |
12338 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
12339 | const bfd_byte *data) | |
12340 | { | |
12341 | struct breakpoint *bp; | |
12342 | ||
12343 | ALL_BREAKPOINTS (bp) | |
12344 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 12345 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 12346 | { |
3a5c3e22 | 12347 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 12348 | |
3a5c3e22 PA |
12349 | if (wp->val_valid && wp->val) |
12350 | { | |
12351 | struct bp_location *loc; | |
12352 | ||
12353 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
12354 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
12355 | && loc->address + loc->length > addr | |
12356 | && addr + len > loc->address) | |
12357 | { | |
12358 | value_free (wp->val); | |
12359 | wp->val = NULL; | |
12360 | wp->val_valid = 0; | |
12361 | } | |
12362 | } | |
1f3b5d1b PP |
12363 | } |
12364 | } | |
12365 | ||
c906108c SS |
12366 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
12367 | ||
12368 | struct symtabs_and_lines | |
fba45db2 | 12369 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
12370 | { |
12371 | struct symtabs_and_lines sals; | |
cc59ec59 | 12372 | |
c906108c | 12373 | if (string == 0) |
8a3fe4f8 | 12374 | error (_("Empty line specification.")); |
c906108c SS |
12375 | if (default_breakpoint_valid) |
12376 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
12377 | default_breakpoint_symtab, |
12378 | default_breakpoint_line, | |
58438ac1 | 12379 | NULL); |
c906108c SS |
12380 | else |
12381 | sals = decode_line_1 (&string, funfirstline, | |
58438ac1 | 12382 | (struct symtab *) NULL, 0, NULL); |
c906108c | 12383 | if (*string) |
8a3fe4f8 | 12384 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
12385 | return sals; |
12386 | } | |
8181d85f DJ |
12387 | |
12388 | /* Create and insert a raw software breakpoint at PC. Return an | |
12389 | identifier, which should be used to remove the breakpoint later. | |
12390 | In general, places which call this should be using something on the | |
12391 | breakpoint chain instead; this function should be eliminated | |
12392 | someday. */ | |
12393 | ||
12394 | void * | |
6c95b8df PA |
12395 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
12396 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
12397 | { |
12398 | struct bp_target_info *bp_tgt; | |
12399 | ||
6c95b8df | 12400 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 12401 | |
6c95b8df | 12402 | bp_tgt->placed_address_space = aspace; |
8181d85f | 12403 | bp_tgt->placed_address = pc; |
6c95b8df | 12404 | |
a6d9a66e | 12405 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
12406 | { |
12407 | /* Could not insert the breakpoint. */ | |
12408 | xfree (bp_tgt); | |
12409 | return NULL; | |
12410 | } | |
12411 | ||
12412 | return bp_tgt; | |
12413 | } | |
12414 | ||
4a64f543 MS |
12415 | /* Remove a breakpoint BP inserted by |
12416 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
12417 | |
12418 | int | |
a6d9a66e | 12419 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
12420 | { |
12421 | struct bp_target_info *bp_tgt = bp; | |
12422 | int ret; | |
12423 | ||
a6d9a66e | 12424 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
12425 | xfree (bp_tgt); |
12426 | ||
12427 | return ret; | |
12428 | } | |
12429 | ||
4a64f543 MS |
12430 | /* One (or perhaps two) breakpoints used for software single |
12431 | stepping. */ | |
8181d85f DJ |
12432 | |
12433 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 12434 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
12435 | |
12436 | /* Create and insert a breakpoint for software single step. */ | |
12437 | ||
12438 | void | |
6c95b8df | 12439 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
12440 | struct address_space *aspace, |
12441 | CORE_ADDR next_pc) | |
8181d85f DJ |
12442 | { |
12443 | void **bpt_p; | |
12444 | ||
12445 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
12446 | { |
12447 | bpt_p = &single_step_breakpoints[0]; | |
12448 | single_step_gdbarch[0] = gdbarch; | |
12449 | } | |
8181d85f DJ |
12450 | else |
12451 | { | |
12452 | gdb_assert (single_step_breakpoints[1] == NULL); | |
12453 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 12454 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
12455 | } |
12456 | ||
4a64f543 MS |
12457 | /* NOTE drow/2006-04-11: A future improvement to this function would |
12458 | be to only create the breakpoints once, and actually put them on | |
12459 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
12460 | We could adjust the addresses each time they were needed. Doing | |
12461 | this requires corresponding changes elsewhere where single step | |
12462 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 12463 | |
6c95b8df | 12464 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 12465 | if (*bpt_p == NULL) |
5af949e3 UW |
12466 | error (_("Could not insert single-step breakpoint at %s"), |
12467 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
12468 | } |
12469 | ||
f02253f1 HZ |
12470 | /* Check if the breakpoints used for software single stepping |
12471 | were inserted or not. */ | |
12472 | ||
12473 | int | |
12474 | single_step_breakpoints_inserted (void) | |
12475 | { | |
12476 | return (single_step_breakpoints[0] != NULL | |
12477 | || single_step_breakpoints[1] != NULL); | |
12478 | } | |
12479 | ||
8181d85f DJ |
12480 | /* Remove and delete any breakpoints used for software single step. */ |
12481 | ||
12482 | void | |
12483 | remove_single_step_breakpoints (void) | |
12484 | { | |
12485 | gdb_assert (single_step_breakpoints[0] != NULL); | |
12486 | ||
12487 | /* See insert_single_step_breakpoint for more about this deprecated | |
12488 | call. */ | |
a6d9a66e UW |
12489 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
12490 | single_step_breakpoints[0]); | |
12491 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
12492 | single_step_breakpoints[0] = NULL; |
12493 | ||
12494 | if (single_step_breakpoints[1] != NULL) | |
12495 | { | |
a6d9a66e UW |
12496 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
12497 | single_step_breakpoints[1]); | |
12498 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
12499 | single_step_breakpoints[1] = NULL; |
12500 | } | |
12501 | } | |
12502 | ||
d03285ec UW |
12503 | /* Delete software single step breakpoints without removing them from |
12504 | the inferior. This is intended to be used if the inferior's address | |
12505 | space where they were inserted is already gone, e.g. after exit or | |
12506 | exec. */ | |
12507 | ||
12508 | void | |
12509 | cancel_single_step_breakpoints (void) | |
12510 | { | |
12511 | int i; | |
12512 | ||
12513 | for (i = 0; i < 2; i++) | |
12514 | if (single_step_breakpoints[i]) | |
12515 | { | |
12516 | xfree (single_step_breakpoints[i]); | |
12517 | single_step_breakpoints[i] = NULL; | |
12518 | single_step_gdbarch[i] = NULL; | |
12519 | } | |
12520 | } | |
12521 | ||
12522 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
12523 | removing them. */ | |
12524 | ||
12525 | static void | |
12526 | detach_single_step_breakpoints (void) | |
12527 | { | |
12528 | int i; | |
12529 | ||
12530 | for (i = 0; i < 2; i++) | |
12531 | if (single_step_breakpoints[i]) | |
12532 | target_remove_breakpoint (single_step_gdbarch[i], | |
12533 | single_step_breakpoints[i]); | |
12534 | } | |
12535 | ||
4a64f543 MS |
12536 | /* Check whether a software single-step breakpoint is inserted at |
12537 | PC. */ | |
1aafd4da UW |
12538 | |
12539 | static int | |
cc59ec59 MS |
12540 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
12541 | CORE_ADDR pc) | |
1aafd4da UW |
12542 | { |
12543 | int i; | |
12544 | ||
12545 | for (i = 0; i < 2; i++) | |
12546 | { | |
12547 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
12548 | if (bp_tgt |
12549 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
12550 | bp_tgt->placed_address, | |
12551 | aspace, pc)) | |
1aafd4da UW |
12552 | return 1; |
12553 | } | |
12554 | ||
12555 | return 0; | |
12556 | } | |
12557 | ||
a96d9b2e SDJ |
12558 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
12559 | non-zero otherwise. */ | |
12560 | static int | |
12561 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
12562 | { | |
12563 | if (syscall_catchpoint_p (bp) | |
12564 | && bp->enable_state != bp_disabled | |
12565 | && bp->enable_state != bp_call_disabled) | |
12566 | return 1; | |
12567 | else | |
12568 | return 0; | |
12569 | } | |
12570 | ||
12571 | int | |
12572 | catch_syscall_enabled (void) | |
12573 | { | |
12574 | struct inferior *inf = current_inferior (); | |
12575 | ||
12576 | return inf->total_syscalls_count != 0; | |
12577 | } | |
12578 | ||
12579 | int | |
12580 | catching_syscall_number (int syscall_number) | |
12581 | { | |
12582 | struct breakpoint *bp; | |
12583 | ||
12584 | ALL_BREAKPOINTS (bp) | |
12585 | if (is_syscall_catchpoint_enabled (bp)) | |
12586 | { | |
be5c67c1 PA |
12587 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
12588 | ||
12589 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
12590 | { |
12591 | int i, iter; | |
12592 | for (i = 0; | |
be5c67c1 | 12593 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
12594 | i++) |
12595 | if (syscall_number == iter) | |
12596 | return 1; | |
12597 | } | |
12598 | else | |
12599 | return 1; | |
12600 | } | |
12601 | ||
12602 | return 0; | |
12603 | } | |
12604 | ||
12605 | /* Complete syscall names. Used by "catch syscall". */ | |
12606 | static char ** | |
12607 | catch_syscall_completer (struct cmd_list_element *cmd, | |
12608 | char *text, char *word) | |
12609 | { | |
12610 | const char **list = get_syscall_names (); | |
c38eea1a MS |
12611 | char **retlist |
12612 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 12613 | |
c38eea1a MS |
12614 | xfree (list); |
12615 | return retlist; | |
a96d9b2e SDJ |
12616 | } |
12617 | ||
1042e4c0 SS |
12618 | /* Tracepoint-specific operations. */ |
12619 | ||
12620 | /* Set tracepoint count to NUM. */ | |
12621 | static void | |
12622 | set_tracepoint_count (int num) | |
12623 | { | |
12624 | tracepoint_count = num; | |
4fa62494 | 12625 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
12626 | } |
12627 | ||
12628 | void | |
12629 | trace_command (char *arg, int from_tty) | |
12630 | { | |
8cdf0e15 VP |
12631 | if (create_breakpoint (get_current_arch (), |
12632 | arg, | |
12633 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12634 | 0 /* tempflag */, |
12635 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12636 | 0 /* Ignore count */, |
12637 | pending_break_support, | |
348d480f | 12638 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12639 | from_tty, |
84f4c1fe PM |
12640 | 1 /* enabled */, |
12641 | 0 /* internal */)) | |
fd9b8c24 | 12642 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
12643 | } |
12644 | ||
7a697b8d SS |
12645 | void |
12646 | ftrace_command (char *arg, int from_tty) | |
12647 | { | |
8cdf0e15 VP |
12648 | if (create_breakpoint (get_current_arch (), |
12649 | arg, | |
12650 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12651 | 0 /* tempflag */, |
12652 | bp_fast_tracepoint /* type_wanted */, | |
12653 | 0 /* Ignore count */, | |
12654 | pending_break_support, | |
348d480f | 12655 | &tracepoint_breakpoint_ops, |
0fb4aa4b | 12656 | from_tty, |
84f4c1fe PM |
12657 | 1 /* enabled */, |
12658 | 0 /* internal */)) | |
0fb4aa4b PA |
12659 | set_tracepoint_count (breakpoint_count); |
12660 | } | |
12661 | ||
12662 | /* strace command implementation. Creates a static tracepoint. */ | |
12663 | ||
12664 | void | |
12665 | strace_command (char *arg, int from_tty) | |
12666 | { | |
12667 | if (create_breakpoint (get_current_arch (), | |
12668 | arg, | |
12669 | NULL, 0, 1 /* parse arg */, | |
12670 | 0 /* tempflag */, | |
12671 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12672 | 0 /* Ignore count */, |
12673 | pending_break_support, | |
348d480f | 12674 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12675 | from_tty, |
84f4c1fe PM |
12676 | 1 /* enabled */, |
12677 | 0 /* internal */)) | |
fd9b8c24 | 12678 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
12679 | } |
12680 | ||
409873ef SS |
12681 | /* Set up a fake reader function that gets command lines from a linked |
12682 | list that was acquired during tracepoint uploading. */ | |
12683 | ||
12684 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 12685 | static int next_cmd; |
409873ef SS |
12686 | |
12687 | static char * | |
12688 | read_uploaded_action (void) | |
12689 | { | |
12690 | char *rslt; | |
12691 | ||
3149d8c1 | 12692 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 12693 | |
3149d8c1 | 12694 | next_cmd++; |
409873ef SS |
12695 | |
12696 | return rslt; | |
12697 | } | |
12698 | ||
00bf0b85 SS |
12699 | /* Given information about a tracepoint as recorded on a target (which |
12700 | can be either a live system or a trace file), attempt to create an | |
12701 | equivalent GDB tracepoint. This is not a reliable process, since | |
12702 | the target does not necessarily have all the information used when | |
12703 | the tracepoint was originally defined. */ | |
12704 | ||
d9b3f62e | 12705 | struct tracepoint * |
00bf0b85 | 12706 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 12707 | { |
409873ef | 12708 | char *addr_str, small_buf[100]; |
d9b3f62e | 12709 | struct tracepoint *tp; |
fd9b8c24 | 12710 | |
409873ef SS |
12711 | if (utp->at_string) |
12712 | addr_str = utp->at_string; | |
12713 | else | |
12714 | { | |
12715 | /* In the absence of a source location, fall back to raw | |
12716 | address. Since there is no way to confirm that the address | |
12717 | means the same thing as when the trace was started, warn the | |
12718 | user. */ | |
3e43a32a MS |
12719 | warning (_("Uploaded tracepoint %d has no " |
12720 | "source location, using raw address"), | |
409873ef SS |
12721 | utp->number); |
12722 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
12723 | addr_str = small_buf; | |
12724 | } | |
12725 | ||
12726 | /* There's not much we can do with a sequence of bytecodes. */ | |
12727 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
12728 | warning (_("Uploaded tracepoint %d condition " |
12729 | "has no source form, ignoring it"), | |
409873ef | 12730 | utp->number); |
d5551862 | 12731 | |
8cdf0e15 | 12732 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
12733 | addr_str, |
12734 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 12735 | 0 /* tempflag */, |
0fb4aa4b | 12736 | utp->type /* type_wanted */, |
8cdf0e15 VP |
12737 | 0 /* Ignore count */, |
12738 | pending_break_support, | |
348d480f | 12739 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12740 | 0 /* from_tty */, |
84f4c1fe PM |
12741 | utp->enabled /* enabled */, |
12742 | 0 /* internal */)) | |
fd9b8c24 PA |
12743 | return NULL; |
12744 | ||
00bf0b85 SS |
12745 | set_tracepoint_count (breakpoint_count); |
12746 | ||
409873ef | 12747 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
12748 | tp = get_tracepoint (tracepoint_count); |
12749 | gdb_assert (tp != NULL); | |
d5551862 | 12750 | |
00bf0b85 SS |
12751 | if (utp->pass > 0) |
12752 | { | |
d9b3f62e | 12753 | sprintf (small_buf, "%d %d", utp->pass, tp->base.number); |
00bf0b85 | 12754 | |
409873ef | 12755 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
12756 | } |
12757 | ||
409873ef SS |
12758 | /* If we have uploaded versions of the original commands, set up a |
12759 | special-purpose "reader" function and call the usual command line | |
12760 | reader, then pass the result to the breakpoint command-setting | |
12761 | function. */ | |
3149d8c1 | 12762 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 12763 | { |
409873ef | 12764 | struct command_line *cmd_list; |
00bf0b85 | 12765 | |
409873ef | 12766 | this_utp = utp; |
3149d8c1 | 12767 | next_cmd = 0; |
d5551862 | 12768 | |
409873ef SS |
12769 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
12770 | ||
d9b3f62e | 12771 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 12772 | } |
3149d8c1 SS |
12773 | else if (!VEC_empty (char_ptr, utp->actions) |
12774 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
12775 | warning (_("Uploaded tracepoint %d actions " |
12776 | "have no source form, ignoring them"), | |
409873ef | 12777 | utp->number); |
00bf0b85 SS |
12778 | |
12779 | return tp; | |
d9b3f62e | 12780 | } |
00bf0b85 | 12781 | |
1042e4c0 SS |
12782 | /* Print information on tracepoint number TPNUM_EXP, or all if |
12783 | omitted. */ | |
12784 | ||
12785 | static void | |
e5a67952 | 12786 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 12787 | { |
79a45e25 | 12788 | struct ui_out *uiout = current_uiout; |
e5a67952 | 12789 | int num_printed; |
1042e4c0 | 12790 | |
e5a67952 | 12791 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
12792 | |
12793 | if (num_printed == 0) | |
1042e4c0 | 12794 | { |
e5a67952 | 12795 | if (args == NULL || *args == '\0') |
d77f58be SS |
12796 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
12797 | else | |
e5a67952 | 12798 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 12799 | } |
ad443146 SS |
12800 | |
12801 | default_collect_info (); | |
1042e4c0 SS |
12802 | } |
12803 | ||
4a64f543 | 12804 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
12805 | Not supported by all targets. */ |
12806 | static void | |
12807 | enable_trace_command (char *args, int from_tty) | |
12808 | { | |
12809 | enable_command (args, from_tty); | |
12810 | } | |
12811 | ||
4a64f543 | 12812 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
12813 | Not supported by all targets. */ |
12814 | static void | |
12815 | disable_trace_command (char *args, int from_tty) | |
12816 | { | |
12817 | disable_command (args, from_tty); | |
12818 | } | |
12819 | ||
4a64f543 | 12820 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
12821 | static void |
12822 | delete_trace_command (char *arg, int from_tty) | |
12823 | { | |
35df4500 | 12824 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
12825 | |
12826 | dont_repeat (); | |
12827 | ||
12828 | if (arg == 0) | |
12829 | { | |
12830 | int breaks_to_delete = 0; | |
12831 | ||
12832 | /* Delete all breakpoints if no argument. | |
12833 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
12834 | have to be deleted with an explicit breakpoint number |
12835 | argument. */ | |
1042e4c0 | 12836 | ALL_TRACEPOINTS (b) |
46c6471b | 12837 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
12838 | { |
12839 | breaks_to_delete = 1; | |
12840 | break; | |
12841 | } | |
1042e4c0 SS |
12842 | |
12843 | /* Ask user only if there are some breakpoints to delete. */ | |
12844 | if (!from_tty | |
12845 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
12846 | { | |
35df4500 | 12847 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 12848 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 12849 | delete_breakpoint (b); |
1042e4c0 SS |
12850 | } |
12851 | } | |
12852 | else | |
51be5b68 | 12853 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
12854 | } |
12855 | ||
197f0a60 TT |
12856 | /* Helper function for trace_pass_command. */ |
12857 | ||
12858 | static void | |
d9b3f62e | 12859 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 12860 | { |
d9b3f62e PA |
12861 | tp->pass_count = count; |
12862 | observer_notify_tracepoint_modified (tp->base.number); | |
197f0a60 TT |
12863 | if (from_tty) |
12864 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 12865 | tp->base.number, count); |
197f0a60 TT |
12866 | } |
12867 | ||
1042e4c0 SS |
12868 | /* Set passcount for tracepoint. |
12869 | ||
12870 | First command argument is passcount, second is tracepoint number. | |
12871 | If tracepoint number omitted, apply to most recently defined. | |
12872 | Also accepts special argument "all". */ | |
12873 | ||
12874 | static void | |
12875 | trace_pass_command (char *args, int from_tty) | |
12876 | { | |
d9b3f62e | 12877 | struct tracepoint *t1; |
1042e4c0 | 12878 | unsigned int count; |
1042e4c0 SS |
12879 | |
12880 | if (args == 0 || *args == 0) | |
3e43a32a MS |
12881 | error (_("passcount command requires an " |
12882 | "argument (count + optional TP num)")); | |
1042e4c0 | 12883 | |
4a64f543 | 12884 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
12885 | |
12886 | while (*args && isspace ((int) *args)) | |
12887 | args++; | |
12888 | ||
12889 | if (*args && strncasecmp (args, "all", 3) == 0) | |
12890 | { | |
d9b3f62e PA |
12891 | struct breakpoint *b; |
12892 | ||
1042e4c0 | 12893 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
12894 | if (*args) |
12895 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 12896 | |
d9b3f62e | 12897 | ALL_TRACEPOINTS (b) |
197f0a60 | 12898 | { |
d9b3f62e | 12899 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
12900 | trace_pass_set_count (t1, count, from_tty); |
12901 | } | |
12902 | } | |
12903 | else if (*args == '\0') | |
1042e4c0 | 12904 | { |
197f0a60 | 12905 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 12906 | if (t1) |
197f0a60 TT |
12907 | trace_pass_set_count (t1, count, from_tty); |
12908 | } | |
12909 | else | |
12910 | { | |
12911 | struct get_number_or_range_state state; | |
12912 | ||
12913 | init_number_or_range (&state, args); | |
12914 | while (!state.finished) | |
1042e4c0 | 12915 | { |
197f0a60 TT |
12916 | t1 = get_tracepoint_by_number (&args, &state, 1); |
12917 | if (t1) | |
12918 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
12919 | } |
12920 | } | |
1042e4c0 SS |
12921 | } |
12922 | ||
d9b3f62e | 12923 | struct tracepoint * |
1042e4c0 SS |
12924 | get_tracepoint (int num) |
12925 | { | |
12926 | struct breakpoint *t; | |
12927 | ||
12928 | ALL_TRACEPOINTS (t) | |
12929 | if (t->number == num) | |
d9b3f62e | 12930 | return (struct tracepoint *) t; |
1042e4c0 SS |
12931 | |
12932 | return NULL; | |
12933 | } | |
12934 | ||
d5551862 SS |
12935 | /* Find the tracepoint with the given target-side number (which may be |
12936 | different from the tracepoint number after disconnecting and | |
12937 | reconnecting). */ | |
12938 | ||
d9b3f62e | 12939 | struct tracepoint * |
d5551862 SS |
12940 | get_tracepoint_by_number_on_target (int num) |
12941 | { | |
d9b3f62e | 12942 | struct breakpoint *b; |
d5551862 | 12943 | |
d9b3f62e PA |
12944 | ALL_TRACEPOINTS (b) |
12945 | { | |
12946 | struct tracepoint *t = (struct tracepoint *) b; | |
12947 | ||
12948 | if (t->number_on_target == num) | |
12949 | return t; | |
12950 | } | |
d5551862 SS |
12951 | |
12952 | return NULL; | |
12953 | } | |
12954 | ||
1042e4c0 | 12955 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
12956 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
12957 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 12958 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 12959 | struct tracepoint * |
197f0a60 TT |
12960 | get_tracepoint_by_number (char **arg, |
12961 | struct get_number_or_range_state *state, | |
12962 | int optional_p) | |
1042e4c0 SS |
12963 | { |
12964 | extern int tracepoint_count; | |
12965 | struct breakpoint *t; | |
12966 | int tpnum; | |
12967 | char *instring = arg == NULL ? NULL : *arg; | |
12968 | ||
197f0a60 TT |
12969 | if (state) |
12970 | { | |
12971 | gdb_assert (!state->finished); | |
12972 | tpnum = get_number_or_range (state); | |
12973 | } | |
12974 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
12975 | { |
12976 | if (optional_p) | |
12977 | tpnum = tracepoint_count; | |
12978 | else | |
12979 | error_no_arg (_("tracepoint number")); | |
12980 | } | |
12981 | else | |
197f0a60 | 12982 | tpnum = get_number (arg); |
1042e4c0 SS |
12983 | |
12984 | if (tpnum <= 0) | |
12985 | { | |
12986 | if (instring && *instring) | |
12987 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
12988 | instring); | |
12989 | else | |
3e43a32a MS |
12990 | printf_filtered (_("Tracepoint argument missing " |
12991 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
12992 | return NULL; |
12993 | } | |
12994 | ||
12995 | ALL_TRACEPOINTS (t) | |
12996 | if (t->number == tpnum) | |
12997 | { | |
d9b3f62e | 12998 | return (struct tracepoint *) t; |
1042e4c0 SS |
12999 | } |
13000 | ||
1042e4c0 SS |
13001 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
13002 | return NULL; | |
13003 | } | |
13004 | ||
d9b3f62e PA |
13005 | void |
13006 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
13007 | { | |
13008 | if (b->thread != -1) | |
13009 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
13010 | ||
13011 | if (b->task != 0) | |
13012 | fprintf_unfiltered (fp, " task %d", b->task); | |
13013 | ||
13014 | fprintf_unfiltered (fp, "\n"); | |
13015 | } | |
13016 | ||
6149aea9 PA |
13017 | /* Save information on user settable breakpoints (watchpoints, etc) to |
13018 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
13019 | on each breakpoint and only include the ones for which it returns | |
13020 | non-zero. */ | |
13021 | ||
1042e4c0 | 13022 | static void |
6149aea9 PA |
13023 | save_breakpoints (char *filename, int from_tty, |
13024 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
13025 | { |
13026 | struct breakpoint *tp; | |
6149aea9 | 13027 | int any = 0; |
a7bdde9e | 13028 | char *pathname; |
1042e4c0 | 13029 | struct cleanup *cleanup; |
a7bdde9e | 13030 | struct ui_file *fp; |
6149aea9 | 13031 | int extra_trace_bits = 0; |
1042e4c0 | 13032 | |
6149aea9 PA |
13033 | if (filename == 0 || *filename == 0) |
13034 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
13035 | |
13036 | /* See if we have anything to save. */ | |
6149aea9 | 13037 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13038 | { |
6149aea9 | 13039 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13040 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
13041 | continue; |
13042 | ||
13043 | /* If we have a filter, only save the breakpoints it accepts. */ | |
13044 | if (filter && !filter (tp)) | |
13045 | continue; | |
13046 | ||
13047 | any = 1; | |
13048 | ||
13049 | if (is_tracepoint (tp)) | |
13050 | { | |
13051 | extra_trace_bits = 1; | |
13052 | ||
13053 | /* We can stop searching. */ | |
13054 | break; | |
13055 | } | |
1042e4c0 | 13056 | } |
6149aea9 PA |
13057 | |
13058 | if (!any) | |
1042e4c0 | 13059 | { |
6149aea9 | 13060 | warning (_("Nothing to save.")); |
1042e4c0 SS |
13061 | return; |
13062 | } | |
13063 | ||
6149aea9 | 13064 | pathname = tilde_expand (filename); |
1042e4c0 | 13065 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 13066 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 13067 | if (!fp) |
6149aea9 PA |
13068 | error (_("Unable to open file '%s' for saving (%s)"), |
13069 | filename, safe_strerror (errno)); | |
a7bdde9e | 13070 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 13071 | |
6149aea9 PA |
13072 | if (extra_trace_bits) |
13073 | save_trace_state_variables (fp); | |
8bf6485c | 13074 | |
6149aea9 | 13075 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13076 | { |
6149aea9 | 13077 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13078 | if (!user_breakpoint_p (tp)) |
6149aea9 | 13079 | continue; |
8bf6485c | 13080 | |
6149aea9 PA |
13081 | /* If we have a filter, only save the breakpoints it accepts. */ |
13082 | if (filter && !filter (tp)) | |
13083 | continue; | |
13084 | ||
348d480f | 13085 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 13086 | |
6149aea9 PA |
13087 | /* Note, we can't rely on tp->number for anything, as we can't |
13088 | assume the recreated breakpoint numbers will match. Use $bpnum | |
13089 | instead. */ | |
13090 | ||
13091 | if (tp->cond_string) | |
13092 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
13093 | ||
13094 | if (tp->ignore_count) | |
13095 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
13096 | ||
a7bdde9e | 13097 | if (tp->commands) |
1042e4c0 | 13098 | { |
a7bdde9e VP |
13099 | volatile struct gdb_exception ex; |
13100 | ||
6149aea9 | 13101 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 13102 | |
79a45e25 | 13103 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 13104 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 13105 | { |
79a45e25 | 13106 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 13107 | } |
79a45e25 | 13108 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 13109 | |
a7bdde9e VP |
13110 | if (ex.reason < 0) |
13111 | throw_exception (ex); | |
1042e4c0 | 13112 | |
a7bdde9e | 13113 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 13114 | } |
6149aea9 PA |
13115 | |
13116 | if (tp->enable_state == bp_disabled) | |
13117 | fprintf_unfiltered (fp, "disable\n"); | |
13118 | ||
13119 | /* If this is a multi-location breakpoint, check if the locations | |
13120 | should be individually disabled. Watchpoint locations are | |
13121 | special, and not user visible. */ | |
13122 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
13123 | { | |
13124 | struct bp_location *loc; | |
13125 | int n = 1; | |
13126 | ||
13127 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
13128 | if (!loc->enabled) | |
13129 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
13130 | } | |
1042e4c0 | 13131 | } |
8bf6485c | 13132 | |
6149aea9 | 13133 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
13134 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
13135 | ||
1042e4c0 SS |
13136 | do_cleanups (cleanup); |
13137 | if (from_tty) | |
6149aea9 PA |
13138 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
13139 | } | |
13140 | ||
13141 | /* The `save breakpoints' command. */ | |
13142 | ||
13143 | static void | |
13144 | save_breakpoints_command (char *args, int from_tty) | |
13145 | { | |
13146 | save_breakpoints (args, from_tty, NULL); | |
13147 | } | |
13148 | ||
13149 | /* The `save tracepoints' command. */ | |
13150 | ||
13151 | static void | |
13152 | save_tracepoints_command (char *args, int from_tty) | |
13153 | { | |
13154 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
13155 | } |
13156 | ||
13157 | /* Create a vector of all tracepoints. */ | |
13158 | ||
13159 | VEC(breakpoint_p) * | |
eeae04df | 13160 | all_tracepoints (void) |
1042e4c0 SS |
13161 | { |
13162 | VEC(breakpoint_p) *tp_vec = 0; | |
13163 | struct breakpoint *tp; | |
13164 | ||
13165 | ALL_TRACEPOINTS (tp) | |
13166 | { | |
13167 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
13168 | } | |
13169 | ||
13170 | return tp_vec; | |
13171 | } | |
13172 | ||
c906108c | 13173 | \f |
4a64f543 MS |
13174 | /* This help string is used for the break, hbreak, tbreak and thbreak |
13175 | commands. It is defined as a macro to prevent duplication. | |
13176 | COMMAND should be a string constant containing the name of the | |
13177 | command. */ | |
31e2b00f AS |
13178 | #define BREAK_ARGS_HELP(command) \ |
13179 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
13180 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
13181 | If a line number is specified, break at start of code for that line.\n\ | |
13182 | If a function is specified, break at start of code for that function.\n\ | |
13183 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
13184 | With no LOCATION, uses current execution address of the selected\n\ |
13185 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
13186 | \n\ |
13187 | THREADNUM is the number from \"info threads\".\n\ | |
13188 | CONDITION is a boolean expression.\n\ | |
13189 | \n\ | |
d41c0fc8 PA |
13190 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
13191 | conditions are different.\n\ | |
31e2b00f AS |
13192 | \n\ |
13193 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
13194 | ||
44feb3ce TT |
13195 | /* List of subcommands for "catch". */ |
13196 | static struct cmd_list_element *catch_cmdlist; | |
13197 | ||
13198 | /* List of subcommands for "tcatch". */ | |
13199 | static struct cmd_list_element *tcatch_cmdlist; | |
13200 | ||
9ac4176b | 13201 | void |
44feb3ce TT |
13202 | add_catch_command (char *name, char *docstring, |
13203 | void (*sfunc) (char *args, int from_tty, | |
13204 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
13205 | char **(*completer) (struct cmd_list_element *cmd, |
13206 | char *text, char *word), | |
44feb3ce TT |
13207 | void *user_data_catch, |
13208 | void *user_data_tcatch) | |
13209 | { | |
13210 | struct cmd_list_element *command; | |
13211 | ||
13212 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13213 | &catch_cmdlist); | |
13214 | set_cmd_sfunc (command, sfunc); | |
13215 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 13216 | set_cmd_completer (command, completer); |
44feb3ce TT |
13217 | |
13218 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13219 | &tcatch_cmdlist); | |
13220 | set_cmd_sfunc (command, sfunc); | |
13221 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 13222 | set_cmd_completer (command, completer); |
44feb3ce TT |
13223 | } |
13224 | ||
6c95b8df | 13225 | static void |
a79b8f6e | 13226 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 13227 | { |
6c95b8df PA |
13228 | inf->total_syscalls_count = 0; |
13229 | inf->any_syscall_count = 0; | |
13230 | VEC_free (int, inf->syscalls_counts); | |
13231 | } | |
13232 | ||
6149aea9 PA |
13233 | static void |
13234 | save_command (char *arg, int from_tty) | |
13235 | { | |
3e43a32a MS |
13236 | printf_unfiltered (_("\"save\" must be followed by " |
13237 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
13238 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
13239 | } | |
13240 | ||
84f4c1fe PM |
13241 | struct breakpoint * |
13242 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
13243 | void *data) | |
13244 | { | |
35df4500 | 13245 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 13246 | |
35df4500 | 13247 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
13248 | { |
13249 | if ((*callback) (b, data)) | |
13250 | return b; | |
13251 | } | |
13252 | ||
13253 | return NULL; | |
13254 | } | |
13255 | ||
2060206e PA |
13256 | void |
13257 | initialize_breakpoint_ops (void) | |
13258 | { | |
13259 | static int initialized = 0; | |
13260 | ||
13261 | struct breakpoint_ops *ops; | |
13262 | ||
13263 | if (initialized) | |
13264 | return; | |
13265 | initialized = 1; | |
13266 | ||
13267 | /* The breakpoint_ops structure to be inherit by all kinds of | |
13268 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
13269 | internal and momentary breakpoints, etc.). */ | |
13270 | ops = &bkpt_base_breakpoint_ops; | |
13271 | *ops = base_breakpoint_ops; | |
13272 | ops->re_set = bkpt_re_set; | |
13273 | ops->insert_location = bkpt_insert_location; | |
13274 | ops->remove_location = bkpt_remove_location; | |
13275 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
13276 | ||
13277 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
13278 | ops = &bkpt_breakpoint_ops; | |
13279 | *ops = bkpt_base_breakpoint_ops; | |
13280 | ops->re_set = bkpt_re_set; | |
13281 | ops->resources_needed = bkpt_resources_needed; | |
13282 | ops->print_it = bkpt_print_it; | |
13283 | ops->print_mention = bkpt_print_mention; | |
13284 | ops->print_recreate = bkpt_print_recreate; | |
13285 | ||
13286 | /* Ranged breakpoints. */ | |
13287 | ops = &ranged_breakpoint_ops; | |
13288 | *ops = bkpt_breakpoint_ops; | |
13289 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
13290 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
13291 | ops->print_it = print_it_ranged_breakpoint; | |
13292 | ops->print_one = print_one_ranged_breakpoint; | |
13293 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
13294 | ops->print_mention = print_mention_ranged_breakpoint; | |
13295 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
13296 | ||
13297 | /* Internal breakpoints. */ | |
13298 | ops = &internal_breakpoint_ops; | |
13299 | *ops = bkpt_base_breakpoint_ops; | |
13300 | ops->re_set = internal_bkpt_re_set; | |
13301 | ops->check_status = internal_bkpt_check_status; | |
13302 | ops->print_it = internal_bkpt_print_it; | |
13303 | ops->print_mention = internal_bkpt_print_mention; | |
13304 | ||
13305 | /* Momentary breakpoints. */ | |
13306 | ops = &momentary_breakpoint_ops; | |
13307 | *ops = bkpt_base_breakpoint_ops; | |
13308 | ops->re_set = momentary_bkpt_re_set; | |
13309 | ops->check_status = momentary_bkpt_check_status; | |
13310 | ops->print_it = momentary_bkpt_print_it; | |
13311 | ops->print_mention = momentary_bkpt_print_mention; | |
13312 | ||
13313 | /* GNU v3 exception catchpoints. */ | |
13314 | ops = &gnu_v3_exception_catchpoint_ops; | |
13315 | *ops = bkpt_breakpoint_ops; | |
13316 | ops->print_it = print_it_exception_catchpoint; | |
13317 | ops->print_one = print_one_exception_catchpoint; | |
13318 | ops->print_mention = print_mention_exception_catchpoint; | |
13319 | ops->print_recreate = print_recreate_exception_catchpoint; | |
13320 | ||
13321 | /* Watchpoints. */ | |
13322 | ops = &watchpoint_breakpoint_ops; | |
13323 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 13324 | ops->dtor = dtor_watchpoint; |
2060206e PA |
13325 | ops->re_set = re_set_watchpoint; |
13326 | ops->insert_location = insert_watchpoint; | |
13327 | ops->remove_location = remove_watchpoint; | |
13328 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
13329 | ops->check_status = check_status_watchpoint; | |
13330 | ops->resources_needed = resources_needed_watchpoint; | |
13331 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
13332 | ops->print_it = print_it_watchpoint; | |
13333 | ops->print_mention = print_mention_watchpoint; | |
13334 | ops->print_recreate = print_recreate_watchpoint; | |
13335 | ||
13336 | /* Masked watchpoints. */ | |
13337 | ops = &masked_watchpoint_breakpoint_ops; | |
13338 | *ops = watchpoint_breakpoint_ops; | |
13339 | ops->insert_location = insert_masked_watchpoint; | |
13340 | ops->remove_location = remove_masked_watchpoint; | |
13341 | ops->resources_needed = resources_needed_masked_watchpoint; | |
13342 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
13343 | ops->print_it = print_it_masked_watchpoint; | |
13344 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
13345 | ops->print_mention = print_mention_masked_watchpoint; | |
13346 | ops->print_recreate = print_recreate_masked_watchpoint; | |
13347 | ||
13348 | /* Tracepoints. */ | |
13349 | ops = &tracepoint_breakpoint_ops; | |
13350 | *ops = base_breakpoint_ops; | |
13351 | ops->re_set = tracepoint_re_set; | |
13352 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
13353 | ops->print_one_detail = tracepoint_print_one_detail; | |
13354 | ops->print_mention = tracepoint_print_mention; | |
13355 | ops->print_recreate = tracepoint_print_recreate; | |
13356 | ||
13357 | /* Fork catchpoints. */ | |
13358 | ops = &catch_fork_breakpoint_ops; | |
13359 | *ops = base_breakpoint_ops; | |
13360 | ops->insert_location = insert_catch_fork; | |
13361 | ops->remove_location = remove_catch_fork; | |
13362 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
13363 | ops->print_it = print_it_catch_fork; | |
13364 | ops->print_one = print_one_catch_fork; | |
13365 | ops->print_mention = print_mention_catch_fork; | |
13366 | ops->print_recreate = print_recreate_catch_fork; | |
13367 | ||
13368 | /* Vfork catchpoints. */ | |
13369 | ops = &catch_vfork_breakpoint_ops; | |
13370 | *ops = base_breakpoint_ops; | |
13371 | ops->insert_location = insert_catch_vfork; | |
13372 | ops->remove_location = remove_catch_vfork; | |
13373 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
13374 | ops->print_it = print_it_catch_vfork; | |
13375 | ops->print_one = print_one_catch_vfork; | |
13376 | ops->print_mention = print_mention_catch_vfork; | |
13377 | ops->print_recreate = print_recreate_catch_vfork; | |
13378 | ||
13379 | /* Exec catchpoints. */ | |
13380 | ops = &catch_exec_breakpoint_ops; | |
13381 | *ops = base_breakpoint_ops; | |
13382 | ops->dtor = dtor_catch_exec; | |
13383 | ops->insert_location = insert_catch_exec; | |
13384 | ops->remove_location = remove_catch_exec; | |
13385 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
13386 | ops->print_it = print_it_catch_exec; | |
13387 | ops->print_one = print_one_catch_exec; | |
13388 | ops->print_mention = print_mention_catch_exec; | |
13389 | ops->print_recreate = print_recreate_catch_exec; | |
13390 | ||
13391 | /* Syscall catchpoints. */ | |
13392 | ops = &catch_syscall_breakpoint_ops; | |
13393 | *ops = base_breakpoint_ops; | |
13394 | ops->dtor = dtor_catch_syscall; | |
13395 | ops->insert_location = insert_catch_syscall; | |
13396 | ops->remove_location = remove_catch_syscall; | |
13397 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
13398 | ops->print_it = print_it_catch_syscall; | |
13399 | ops->print_one = print_one_catch_syscall; | |
13400 | ops->print_mention = print_mention_catch_syscall; | |
13401 | ops->print_recreate = print_recreate_catch_syscall; | |
13402 | } | |
13403 | ||
c906108c | 13404 | void |
fba45db2 | 13405 | _initialize_breakpoint (void) |
c906108c SS |
13406 | { |
13407 | struct cmd_list_element *c; | |
13408 | ||
2060206e PA |
13409 | initialize_breakpoint_ops (); |
13410 | ||
84acb35a | 13411 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 13412 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 13413 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 13414 | |
17450429 PP |
13415 | breakpoint_objfile_key = register_objfile_data (); |
13416 | ||
c906108c SS |
13417 | breakpoint_chain = 0; |
13418 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
13419 | before a breakpoint is set. */ | |
13420 | breakpoint_count = 0; | |
13421 | ||
1042e4c0 SS |
13422 | tracepoint_count = 0; |
13423 | ||
1bedd215 AC |
13424 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
13425 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
13426 | Usage is `ignore N COUNT'.")); | |
c906108c | 13427 | if (xdb_commands) |
c5aa993b | 13428 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 13429 | |
1bedd215 AC |
13430 | add_com ("commands", class_breakpoint, commands_command, _("\ |
13431 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
13432 | Give breakpoint number as argument after \"commands\".\n\ |
13433 | With no argument, the targeted breakpoint is the last one set.\n\ | |
13434 | The commands themselves follow starting on the next line.\n\ | |
13435 | Type a line containing \"end\" to indicate the end of them.\n\ | |
13436 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 13437 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 13438 | |
1bedd215 AC |
13439 | add_com ("condition", class_breakpoint, condition_command, _("\ |
13440 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 13441 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 13442 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 13443 | |
1bedd215 | 13444 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 13445 | Set a temporary breakpoint.\n\ |
c906108c SS |
13446 | Like \"break\" except the breakpoint is only temporary,\n\ |
13447 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
13448 | by using \"enable delete\" on the breakpoint number.\n\ |
13449 | \n" | |
13450 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 13451 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13452 | |
1bedd215 | 13453 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 13454 | Set a hardware assisted breakpoint.\n\ |
c906108c | 13455 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
13456 | some target hardware may not have this support.\n\ |
13457 | \n" | |
13458 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 13459 | set_cmd_completer (c, location_completer); |
c906108c | 13460 | |
1bedd215 | 13461 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 13462 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 13463 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
13464 | so it will be deleted when hit.\n\ |
13465 | \n" | |
13466 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 13467 | set_cmd_completer (c, location_completer); |
c906108c | 13468 | |
1bedd215 AC |
13469 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
13470 | Enable some breakpoints.\n\ | |
c906108c SS |
13471 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13472 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13473 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13474 | With a subcommand you can enable temporarily."), |
c906108c SS |
13475 | &enablelist, "enable ", 1, &cmdlist); |
13476 | if (xdb_commands) | |
1bedd215 AC |
13477 | add_com ("ab", class_breakpoint, enable_command, _("\ |
13478 | Enable some breakpoints.\n\ | |
c906108c SS |
13479 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13480 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13481 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13482 | With a subcommand you can enable temporarily.")); |
c906108c SS |
13483 | |
13484 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
13485 | ||
84951ab5 | 13486 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 13487 | Enable some breakpoints.\n\ |
c906108c SS |
13488 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13489 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13490 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 13491 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 13492 | |
1a966eab AC |
13493 | add_cmd ("once", no_class, enable_once_command, _("\ |
13494 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13495 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13496 | &enablebreaklist); |
13497 | ||
1a966eab AC |
13498 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13499 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13500 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13501 | &enablebreaklist); |
13502 | ||
1a966eab AC |
13503 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13504 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13505 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13506 | &enablelist); |
13507 | ||
1a966eab AC |
13508 | add_cmd ("once", no_class, enable_once_command, _("\ |
13509 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13510 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13511 | &enablelist); |
13512 | ||
1bedd215 AC |
13513 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
13514 | Disable some breakpoints.\n\ | |
c906108c SS |
13515 | Arguments are breakpoint numbers with spaces in between.\n\ |
13516 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13517 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
13518 | &disablelist, "disable ", 1, &cmdlist); |
13519 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
13520 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
13521 | if (xdb_commands) | |
1bedd215 AC |
13522 | add_com ("sb", class_breakpoint, disable_command, _("\ |
13523 | Disable some breakpoints.\n\ | |
c906108c SS |
13524 | Arguments are breakpoint numbers with spaces in between.\n\ |
13525 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13526 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 13527 | |
1a966eab AC |
13528 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
13529 | Disable some breakpoints.\n\ | |
c906108c SS |
13530 | Arguments are breakpoint numbers with spaces in between.\n\ |
13531 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13532 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 13533 | This command may be abbreviated \"disable\"."), |
c906108c SS |
13534 | &disablelist); |
13535 | ||
1bedd215 AC |
13536 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
13537 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13538 | Arguments are breakpoint numbers with spaces in between.\n\ |
13539 | To delete all breakpoints, give no argument.\n\ | |
13540 | \n\ | |
13541 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 13542 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
13543 | &deletelist, "delete ", 1, &cmdlist); |
13544 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 13545 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 13546 | if (xdb_commands) |
1bedd215 AC |
13547 | add_com ("db", class_breakpoint, delete_command, _("\ |
13548 | Delete some breakpoints.\n\ | |
c906108c | 13549 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 13550 | To delete all breakpoints, give no argument.\n")); |
c906108c | 13551 | |
1a966eab AC |
13552 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
13553 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13554 | Arguments are breakpoint numbers with spaces in between.\n\ |
13555 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 13556 | This command may be abbreviated \"delete\"."), |
c906108c SS |
13557 | &deletelist); |
13558 | ||
1bedd215 AC |
13559 | add_com ("clear", class_breakpoint, clear_command, _("\ |
13560 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
13561 | Argument may be line number, function name, or \"*\" and an address.\n\ |
13562 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
13563 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
13564 | If an address is specified, breakpoints at that address are cleared.\n\ |
13565 | \n\ | |
13566 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
13567 | is executing in.\n\ |
13568 | \n\ | |
1bedd215 | 13569 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 13570 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 13571 | |
1bedd215 | 13572 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
13573 | Set breakpoint at specified line or function.\n" |
13574 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 13575 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13576 | |
c906108c SS |
13577 | add_com_alias ("b", "break", class_run, 1); |
13578 | add_com_alias ("br", "break", class_run, 1); | |
13579 | add_com_alias ("bre", "break", class_run, 1); | |
13580 | add_com_alias ("brea", "break", class_run, 1); | |
13581 | ||
7681d515 PM |
13582 | if (xdb_commands) |
13583 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
13584 | |
13585 | if (dbx_commands) | |
13586 | { | |
1bedd215 AC |
13587 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
13588 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
13589 | &stoplist, "stop ", 1, &cmdlist); |
13590 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 13591 | _("Break in function or address."), &stoplist); |
c5aa993b | 13592 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 13593 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
13594 | add_com ("status", class_info, breakpoints_info, _("\ |
13595 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13596 | The \"Type\" column indicates one of:\n\ |
13597 | \tbreakpoint - normal breakpoint\n\ | |
13598 | \twatchpoint - watchpoint\n\ | |
13599 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13600 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13601 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13602 | address and file/line number respectively.\n\ |
13603 | \n\ | |
13604 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13605 | are set to the address of the last breakpoint listed unless the command\n\ |
13606 | is prefixed with \"server \".\n\n\ | |
c906108c | 13607 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13608 | breakpoint set.")); |
c906108c SS |
13609 | } |
13610 | ||
1bedd215 | 13611 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 13612 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
13613 | The \"Type\" column indicates one of:\n\ |
13614 | \tbreakpoint - normal breakpoint\n\ | |
13615 | \twatchpoint - watchpoint\n\ | |
13616 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13617 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13618 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13619 | address and file/line number respectively.\n\ |
13620 | \n\ | |
13621 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13622 | are set to the address of the last breakpoint listed unless the command\n\ |
13623 | is prefixed with \"server \".\n\n\ | |
c906108c | 13624 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13625 | breakpoint set.")); |
c906108c | 13626 | |
6b04bdb7 MS |
13627 | add_info_alias ("b", "breakpoints", 1); |
13628 | ||
c906108c | 13629 | if (xdb_commands) |
1bedd215 AC |
13630 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
13631 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13632 | The \"Type\" column indicates one of:\n\ |
13633 | \tbreakpoint - normal breakpoint\n\ | |
13634 | \twatchpoint - watchpoint\n\ | |
13635 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13636 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13637 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13638 | address and file/line number respectively.\n\ |
13639 | \n\ | |
13640 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13641 | are set to the address of the last breakpoint listed unless the command\n\ |
13642 | is prefixed with \"server \".\n\n\ | |
c906108c | 13643 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13644 | breakpoint set.")); |
c906108c | 13645 | |
1a966eab AC |
13646 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
13647 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13648 | The \"Type\" column indicates one of:\n\ |
13649 | \tbreakpoint - normal breakpoint\n\ | |
13650 | \twatchpoint - watchpoint\n\ | |
13651 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
13652 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
13653 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
13654 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
13655 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
13656 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
13657 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
13658 | address and file/line number respectively.\n\ |
13659 | \n\ | |
13660 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13661 | are set to the address of the last breakpoint listed unless the command\n\ |
13662 | is prefixed with \"server \".\n\n\ | |
c906108c | 13663 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 13664 | breakpoint set."), |
c906108c SS |
13665 | &maintenanceinfolist); |
13666 | ||
44feb3ce TT |
13667 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
13668 | Set catchpoints to catch events."), | |
13669 | &catch_cmdlist, "catch ", | |
13670 | 0/*allow-unknown*/, &cmdlist); | |
13671 | ||
13672 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
13673 | Set temporary catchpoints to catch events."), | |
13674 | &tcatch_cmdlist, "tcatch ", | |
13675 | 0/*allow-unknown*/, &cmdlist); | |
13676 | ||
13677 | /* Add catch and tcatch sub-commands. */ | |
13678 | add_catch_command ("catch", _("\ | |
13679 | Catch an exception, when caught.\n\ | |
13680 | With an argument, catch only exceptions with the given name."), | |
13681 | catch_catch_command, | |
a96d9b2e | 13682 | NULL, |
44feb3ce TT |
13683 | CATCH_PERMANENT, |
13684 | CATCH_TEMPORARY); | |
13685 | add_catch_command ("throw", _("\ | |
13686 | Catch an exception, when thrown.\n\ | |
13687 | With an argument, catch only exceptions with the given name."), | |
13688 | catch_throw_command, | |
a96d9b2e | 13689 | NULL, |
44feb3ce TT |
13690 | CATCH_PERMANENT, |
13691 | CATCH_TEMPORARY); | |
13692 | add_catch_command ("fork", _("Catch calls to fork."), | |
13693 | catch_fork_command_1, | |
a96d9b2e | 13694 | NULL, |
44feb3ce TT |
13695 | (void *) (uintptr_t) catch_fork_permanent, |
13696 | (void *) (uintptr_t) catch_fork_temporary); | |
13697 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
13698 | catch_fork_command_1, | |
a96d9b2e | 13699 | NULL, |
44feb3ce TT |
13700 | (void *) (uintptr_t) catch_vfork_permanent, |
13701 | (void *) (uintptr_t) catch_vfork_temporary); | |
13702 | add_catch_command ("exec", _("Catch calls to exec."), | |
13703 | catch_exec_command_1, | |
a96d9b2e SDJ |
13704 | NULL, |
13705 | CATCH_PERMANENT, | |
13706 | CATCH_TEMPORARY); | |
13707 | add_catch_command ("syscall", _("\ | |
13708 | Catch system calls by their names and/or numbers.\n\ | |
13709 | Arguments say which system calls to catch. If no arguments\n\ | |
13710 | are given, every system call will be caught.\n\ | |
13711 | Arguments, if given, should be one or more system call names\n\ | |
13712 | (if your system supports that), or system call numbers."), | |
13713 | catch_syscall_command_1, | |
13714 | catch_syscall_completer, | |
44feb3ce TT |
13715 | CATCH_PERMANENT, |
13716 | CATCH_TEMPORARY); | |
c5aa993b | 13717 | |
1bedd215 AC |
13718 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
13719 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13720 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 13721 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13722 | an expression changes.\n\ |
13723 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13724 | the memory to which it refers.")); | |
65d12d83 | 13725 | set_cmd_completer (c, expression_completer); |
c906108c | 13726 | |
1bedd215 AC |
13727 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
13728 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 13729 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 13730 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13731 | an expression is read.\n\ |
13732 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13733 | the memory to which it refers.")); | |
65d12d83 | 13734 | set_cmd_completer (c, expression_completer); |
c906108c | 13735 | |
1bedd215 AC |
13736 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
13737 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13738 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 13739 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13740 | an expression is either read or written.\n\ |
13741 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13742 | the memory to which it refers.")); | |
65d12d83 | 13743 | set_cmd_completer (c, expression_completer); |
c906108c | 13744 | |
d77f58be | 13745 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 13746 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 13747 | |
920d2a44 AC |
13748 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
13749 | respond to changes - contrary to the description. */ | |
85c07804 AC |
13750 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
13751 | &can_use_hw_watchpoints, _("\ | |
13752 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
13753 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
13754 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
13755 | such is available. (However, any hardware watchpoints that were\n\ | |
13756 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
13757 | hardware.)"), |
13758 | NULL, | |
920d2a44 | 13759 | show_can_use_hw_watchpoints, |
85c07804 | 13760 | &setlist, &showlist); |
c906108c SS |
13761 | |
13762 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 13763 | |
1042e4c0 SS |
13764 | /* Tracepoint manipulation commands. */ |
13765 | ||
13766 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
13767 | Set a tracepoint at specified line or function.\n\ | |
13768 | \n" | |
13769 | BREAK_ARGS_HELP ("trace") "\n\ | |
13770 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13771 | set_cmd_completer (c, location_completer); | |
13772 | ||
13773 | add_com_alias ("tp", "trace", class_alias, 0); | |
13774 | add_com_alias ("tr", "trace", class_alias, 1); | |
13775 | add_com_alias ("tra", "trace", class_alias, 1); | |
13776 | add_com_alias ("trac", "trace", class_alias, 1); | |
13777 | ||
7a697b8d SS |
13778 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
13779 | Set a fast tracepoint at specified line or function.\n\ | |
13780 | \n" | |
13781 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
13782 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13783 | set_cmd_completer (c, location_completer); | |
13784 | ||
0fb4aa4b PA |
13785 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
13786 | Set a static tracepoint at specified line, function or marker.\n\ | |
13787 | \n\ | |
13788 | strace [LOCATION] [if CONDITION]\n\ | |
13789 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
13790 | or -m MARKER_ID.\n\ | |
13791 | If a line number is specified, probe the marker at start of code\n\ | |
13792 | for that line. If a function is specified, probe the marker at start\n\ | |
13793 | of code for that function. If an address is specified, probe the marker\n\ | |
13794 | at that exact address. If a marker id is specified, probe the marker\n\ | |
13795 | with that name. With no LOCATION, uses current execution address of\n\ | |
13796 | the selected stack frame.\n\ | |
13797 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
13798 | This collects arbitrary user data passed in the probe point call to the\n\ | |
13799 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
13800 | by printing the $_sdata variable like any other convenience variable.\n\ | |
13801 | \n\ | |
13802 | CONDITION is a boolean expression.\n\ | |
13803 | \n\ | |
d41c0fc8 PA |
13804 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
13805 | conditions are different.\n\ | |
0fb4aa4b PA |
13806 | \n\ |
13807 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
13808 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13809 | set_cmd_completer (c, location_completer); | |
13810 | ||
1042e4c0 | 13811 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 13812 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
13813 | Convenience variable \"$tpnum\" contains the number of the\n\ |
13814 | last tracepoint set.")); | |
13815 | ||
13816 | add_info_alias ("tp", "tracepoints", 1); | |
13817 | ||
13818 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
13819 | Delete specified tracepoints.\n\ | |
13820 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13821 | No argument means delete all tracepoints."), | |
13822 | &deletelist); | |
13823 | ||
13824 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
13825 | Disable specified tracepoints.\n\ | |
13826 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13827 | No argument means disable all tracepoints."), | |
13828 | &disablelist); | |
13829 | deprecate_cmd (c, "disable"); | |
13830 | ||
13831 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
13832 | Enable specified tracepoints.\n\ | |
13833 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13834 | No argument means enable all tracepoints."), | |
13835 | &enablelist); | |
13836 | deprecate_cmd (c, "enable"); | |
13837 | ||
13838 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
13839 | Set the passcount for a tracepoint.\n\ | |
13840 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
13841 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
13842 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
13843 | ||
6149aea9 PA |
13844 | add_prefix_cmd ("save", class_breakpoint, save_command, |
13845 | _("Save breakpoint definitions as a script."), | |
13846 | &save_cmdlist, "save ", | |
13847 | 0/*allow-unknown*/, &cmdlist); | |
13848 | ||
13849 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
13850 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 13851 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
13852 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
13853 | session to restore them."), | |
13854 | &save_cmdlist); | |
13855 | set_cmd_completer (c, filename_completer); | |
13856 | ||
13857 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 13858 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
13859 | Use the 'source' command in another debug session to restore them."), |
13860 | &save_cmdlist); | |
1042e4c0 SS |
13861 | set_cmd_completer (c, filename_completer); |
13862 | ||
6149aea9 PA |
13863 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
13864 | deprecate_cmd (c, "save tracepoints"); | |
13865 | ||
1bedd215 | 13866 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
13867 | Breakpoint specific settings\n\ |
13868 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 13869 | pending breakpoint behavior"), |
fa8d40ab JJ |
13870 | &breakpoint_set_cmdlist, "set breakpoint ", |
13871 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 13872 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
13873 | Breakpoint specific settings\n\ |
13874 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 13875 | pending breakpoint behavior"), |
fa8d40ab JJ |
13876 | &breakpoint_show_cmdlist, "show breakpoint ", |
13877 | 0/*allow-unknown*/, &showlist); | |
13878 | ||
7915a72c AC |
13879 | add_setshow_auto_boolean_cmd ("pending", no_class, |
13880 | &pending_break_support, _("\ | |
13881 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
13882 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
13883 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
13884 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
13885 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 13886 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 13887 | NULL, |
920d2a44 | 13888 | show_pending_break_support, |
6e1d7d6c AC |
13889 | &breakpoint_set_cmdlist, |
13890 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
13891 | |
13892 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
13893 | |
13894 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
13895 | &automatic_hardware_breakpoints, _("\ | |
13896 | Set automatic usage of hardware breakpoints."), _("\ | |
13897 | Show automatic usage of hardware breakpoints."), _("\ | |
13898 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
13899 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
13900 | a warning will be emitted for such breakpoints."), | |
13901 | NULL, | |
13902 | show_automatic_hardware_breakpoints, | |
13903 | &breakpoint_set_cmdlist, | |
13904 | &breakpoint_show_cmdlist); | |
74960c60 | 13905 | |
33e5cbd6 PA |
13906 | add_setshow_enum_cmd ("always-inserted", class_support, |
13907 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
13908 | Set mode for inserting breakpoints."), _("\ |
13909 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
13910 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
13911 | resumed, and removed when execution stops. When this mode is on,\n\ | |
13912 | breakpoints are inserted immediately and removed only when the user\n\ | |
13913 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
13914 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
13915 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
13916 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
13917 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
13918 | NULL, |
13919 | &show_always_inserted_mode, | |
13920 | &breakpoint_set_cmdlist, | |
13921 | &breakpoint_show_cmdlist); | |
f1310107 TJB |
13922 | |
13923 | add_com ("break-range", class_breakpoint, break_range_command, _("\ | |
13924 | Set a breakpoint for an address range.\n\ | |
13925 | break-range START-LOCATION, END-LOCATION\n\ | |
13926 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
13927 | LINENUM, for that line in the current file,\n\ | |
13928 | FILE:LINENUM, for that line in that file,\n\ | |
13929 | +OFFSET, for that number of lines after the current line\n\ | |
13930 | or the start of the range\n\ | |
13931 | FUNCTION, for the first line in that function,\n\ | |
13932 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
13933 | *ADDRESS, for the instruction at that address.\n\ | |
13934 | \n\ | |
13935 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
13936 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
13937 | range (including START-LOCATION and END-LOCATION).")); | |
13938 | ||
765dc015 | 13939 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
13940 | |
13941 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 13942 | } |